/usr/include/CGAL/boost/graph/selection.h is in libcgal-dev 4.7-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | // Copyright (c) 2015 GeometryFactory (France). All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
//
// Author(s) : Sebastien Loriot
//
#ifndef CGAL_BOOST_GRAPH_KTH_SIMPLICIAL_NEIGHBORHOOD_H
#define CGAL_BOOST_GRAPH_KTH_SIMPLICIAL_NEIGHBORHOOD_H
#include <boost/graph/graph_traits.hpp>
#include <boost/foreach.hpp>
#include <CGAL/boost/graph/iterator.h>
namespace CGAL {
/// Operation on faces
namespace internal{
// extract edges in non-selected faces (boundary excluded but one)
template <class FaceRange, class FaceGraph, class IsFaceSelectedPMap, class OutputIterator>
OutputIterator
extract_selection_boundary(
FaceRange& face_range,
FaceGraph& graph,
IsFaceSelectedPMap is_selected,
OutputIterator out)
{
typedef boost::graph_traits<FaceGraph> GT;
typedef typename GT::face_descriptor face_descriptor;
typedef typename GT::halfedge_descriptor halfedge_descriptor;
BOOST_FOREACH(face_descriptor fd, face_range)
{
BOOST_FOREACH( halfedge_descriptor h,
halfedges_around_face(halfedge(fd, graph), graph) )
{
halfedge_descriptor opp_hd = opposite(h, graph);
face_descriptor opp_fd = face( opp_hd, graph );
if (opp_fd!=GT::null_face())
{
if ( !get(is_selected, opp_fd) )
*out++=opp_hd;
}
else{
opp_hd=opposite( next( opp_hd, graph), graph );
if ( !get( is_selected, face(opp_hd, graph) ) )
*out++=opp_hd;
}
}
}
return out;
}
} //end of namespace internal
template <class FaceRange, class FaceGraph, class IsFaceSelectedPMap, class OutputIterator>
OutputIterator
dilate_face_selection(
const FaceRange& selection,
FaceGraph& graph,
unsigned int k,
IsFaceSelectedPMap is_selected,
OutputIterator out)
{
typedef boost::graph_traits<FaceGraph> GT;
typedef typename GT::face_descriptor face_descriptor;
typedef typename GT::halfedge_descriptor halfedge_descriptor;
std::vector<face_descriptor> current_selection(selection.begin(), selection.end());
for (unsigned int i=0; i<k; ++i)
{
//extract faces on the boundary of the selection
std::vector<halfedge_descriptor> selection_boundary_halfedges;
internal::extract_selection_boundary(current_selection, graph, is_selected,
std::back_inserter(selection_boundary_halfedges));
if (selection_boundary_halfedges.empty()) break;
//collect faces around the target vertex of the selection boundary halfedges
std::set<face_descriptor> new_selection_set;
BOOST_FOREACH(halfedge_descriptor hd, selection_boundary_halfedges)
{
face_descriptor fd=face(hd, graph);
while( !get(is_selected,fd) )
{
new_selection_set.insert(fd);
hd=opposite( next(hd, graph), graph );
fd=face(hd, graph);
if ( face(hd, graph)==GT::null_face() ) break;
}
}
// extract unique selection
std::vector<face_descriptor> new_selection;
BOOST_FOREACH(face_descriptor fd, new_selection_set)
{
*out++=fd;
new_selection.push_back(fd);
put( is_selected, fd, true );
}
current_selection.swap(new_selection);
}
return out;
}
template <class FaceRange, class FaceGraph, class IsFaceSelectedPMap, class OutputIterator>
OutputIterator
erode_face_selection(
const FaceRange& selection,
FaceGraph& graph,
unsigned int k,
IsFaceSelectedPMap is_selected,
OutputIterator out)
{
typedef boost::graph_traits<FaceGraph> GT;
typedef typename GT::face_descriptor face_descriptor;
typedef typename GT::halfedge_descriptor halfedge_descriptor;
std::vector<face_descriptor> current_selection(selection.begin(), selection.end());
for (unsigned int i=0; i<k; ++i)
{
//extract faces on the boundary of the selection
std::vector<halfedge_descriptor> selection_boundary_halfedges;
internal::extract_selection_boundary(current_selection, graph, is_selected,
std::back_inserter(selection_boundary_halfedges));
if (selection_boundary_halfedges.empty()) break;
//collect faces around the target vertex of the selection boundary halfedges
std::set<face_descriptor> elements_to_remove;
BOOST_FOREACH(halfedge_descriptor hd, selection_boundary_halfedges)
{
hd = opposite(hd, graph);
face_descriptor fd=face( hd, graph );
while( face(hd, graph)!=GT::null_face() && get(is_selected,fd) )
{
elements_to_remove.insert(fd);
hd=opposite( next(hd, graph), graph );
fd=face(hd, graph);
}
}
/// update is-selected attribute and output iterator
BOOST_FOREACH(face_descriptor fd, elements_to_remove)
{
*out++=fd;
put( is_selected, fd, false );
}
// update the set of currently selected faces
std::vector<face_descriptor> new_selection;
BOOST_FOREACH(face_descriptor fd, current_selection)
if ( !elements_to_remove.count(fd) )
new_selection.push_back(fd);
current_selection.swap(new_selection);
}
return out;
}
// select all faces incident to the target vertex of halfedges in `hedges`
template <class HalfedgeRange, class FaceGraph, class OutputIterator>
OutputIterator
select_incident_faces(
const HalfedgeRange& hedges,
FaceGraph& graph,
OutputIterator out)
{
typedef boost::graph_traits<FaceGraph> GT;
typedef typename GT::face_descriptor face_descriptor;
typedef typename GT::halfedge_descriptor halfedge_descriptor;
//collect faces around the target vertex of the selection boundary halfedges
std::set<face_descriptor> selection_set;
BOOST_FOREACH(halfedge_descriptor hd, hedges)
{
halfedge_descriptor first = hd;
face_descriptor fd=face(hd, graph);
do
{
if ( face(hd, graph)!=GT::null_face() && selection_set.insert(fd).second)
*out++=fd;
hd=opposite( next(hd, graph), graph );
fd=face(hd, graph);
}while( hd!=first );
}
return out;
}
/// Operations on edges
template <class EdgeRange, class HalfedgeGraph, class IsEdgeSelectedPMap, class OutputIterator>
OutputIterator
dilate_edge_selection(
const EdgeRange& selection,
HalfedgeGraph& graph,
unsigned int k,
IsEdgeSelectedPMap is_selected,
OutputIterator out)
{
typedef boost::graph_traits<HalfedgeGraph> GT;
typedef typename GT::edge_descriptor edge_descriptor;
typedef typename GT::halfedge_descriptor halfedge_descriptor;
std::vector<edge_descriptor> current_selection(selection.begin(), selection.end());
for (unsigned int i=0; i<k; ++i)
{
if (current_selection.empty()) break;
//collect adjacent edges not already selected
std::set<edge_descriptor> new_selection_set;
BOOST_FOREACH(edge_descriptor ed, current_selection)
{
halfedge_descriptor hdi=halfedge(ed,graph);
BOOST_FOREACH(halfedge_descriptor hd, halfedges_around_source( hdi, graph))
{
edge_descriptor ned=edge(hd, graph);
if (!get(is_selected, ned)) new_selection_set.insert(ned);
}
BOOST_FOREACH(halfedge_descriptor hd, halfedges_around_target( hdi, graph))
{
edge_descriptor ned=edge(hd, graph);
if (!get(is_selected, ned)) new_selection_set.insert(ned);
}
}
// extract unique selection
std::vector<edge_descriptor> new_selection;
BOOST_FOREACH(edge_descriptor ed, new_selection_set)
{
*out++=ed;
new_selection.push_back(ed);
put( is_selected, ed, true );
}
current_selection.swap(new_selection);
}
return out;
}
template <class EdgeRange, class HalfedgeGraph, class IsEdgeSelectedPMap, class OutputIterator>
OutputIterator
erode_edge_selection(
const EdgeRange& selection ,
HalfedgeGraph& graph,
unsigned int k,
IsEdgeSelectedPMap is_selected,
OutputIterator out)
{
typedef boost::graph_traits<HalfedgeGraph> GT;
typedef typename GT::halfedge_descriptor halfedge_descriptor;
typedef typename GT::edge_descriptor edge_descriptor;
typedef typename GT::vertex_descriptor vertex_descriptor;
// extract the set of vertices on the border
std::set<vertex_descriptor> unique_vertex_set;
BOOST_FOREACH(edge_descriptor ed, selection)
{
halfedge_descriptor hd=halfedge(ed,graph);
BOOST_FOREACH(halfedge_descriptor nhd, halfedges_around_source( hd, graph))
{
edge_descriptor ned=edge(nhd, graph);
if (!get(is_selected, ned)){
unique_vertex_set.insert(source(hd,graph));
break;
}
}
BOOST_FOREACH(halfedge_descriptor nhd, halfedges_around_target( hd, graph))
{
edge_descriptor ned=edge(nhd, graph);
if (!get(is_selected, ned)){
unique_vertex_set.insert(target(hd,graph));
break;
}
}
}
std::vector<vertex_descriptor> current_selection_border(unique_vertex_set.begin(), unique_vertex_set.end());
for (unsigned int i=0; i<k; ++i)
{
if (current_selection_border.empty()) break;
//collect incident edges selected
std::set<edge_descriptor> edges_to_deselect;
unique_vertex_set.clear();
BOOST_FOREACH(vertex_descriptor vd, current_selection_border)
BOOST_FOREACH(halfedge_descriptor hd, halfedges_around_target( halfedge(vd,graph), graph))
{
edge_descriptor ed = edge(hd, graph);
if (get(is_selected, ed)){
edges_to_deselect.insert(ed);
unique_vertex_set.insert(source(hd, graph));
}
}
// extract unique selection
BOOST_FOREACH(edge_descriptor ed, edges_to_deselect)
{
*out++=ed;
put( is_selected, ed, false );
}
current_selection_border.assign(unique_vertex_set.begin(), unique_vertex_set.end());
}
return out;
}
/// Operations on vertices
template <class VertexRange, class HalfedgeGraph, class IsVertexSelectedPMap, class OutputIterator>
OutputIterator
dilate_vertex_selection(
const VertexRange& selection,
HalfedgeGraph& graph,
unsigned int k,
IsVertexSelectedPMap is_selected,
OutputIterator out)
{
typedef boost::graph_traits<HalfedgeGraph> GT;
typedef typename GT::vertex_descriptor vertex_descriptor;
std::vector<vertex_descriptor> current_selection(selection.begin(), selection.end());
for (unsigned int i=0; i<k; ++i)
{
if (current_selection.empty()) break;
//collect adjacent vertices not already selected
std::set<vertex_descriptor> new_selection_set;
BOOST_FOREACH(vertex_descriptor vd, current_selection)
BOOST_FOREACH(vertex_descriptor nvd, vertices_around_target( halfedge(vd,graph), graph))
if (!get(is_selected, nvd)) new_selection_set.insert(nvd);
// extract unique selection
std::vector<vertex_descriptor> new_selection;
BOOST_FOREACH(vertex_descriptor vd, new_selection_set)
{
*out++=vd;
new_selection.push_back(vd);
put( is_selected, vd, true );
}
current_selection.swap(new_selection);
}
return out;
}
template <class VertexRange, class HalfedgeGraph, class IsVertexSelectedPMap, class OutputIterator>
OutputIterator
erode_vertex_selection(
const VertexRange& selection,
HalfedgeGraph& graph,
unsigned int k,
IsVertexSelectedPMap is_selected,
OutputIterator out)
{
typedef boost::graph_traits<HalfedgeGraph> GT;
typedef typename GT::vertex_descriptor vertex_descriptor;
// collect vertices incident to a selected one
std::set<vertex_descriptor> unique_vertex_set;
BOOST_FOREACH(vertex_descriptor vd, selection)
BOOST_FOREACH(vertex_descriptor nvd, vertices_around_target( halfedge(vd,graph), graph))
if (!get(is_selected, nvd)) unique_vertex_set.insert(nvd);
std::vector<vertex_descriptor> current_selection_border(unique_vertex_set.begin(), unique_vertex_set.end());
for (unsigned int i=0; i<k; ++i)
{
if (current_selection_border.empty()) break;
//collect adjacent vertices selected
std::set<vertex_descriptor> vertices_to_deselect;
BOOST_FOREACH(vertex_descriptor vd, current_selection_border)
BOOST_FOREACH(vertex_descriptor nvd, vertices_around_target( halfedge(vd,graph), graph))
if (get(is_selected, nvd)) vertices_to_deselect.insert(nvd);
// extract unique selection
std::vector<vertex_descriptor> new_selection_border;
BOOST_FOREACH(vertex_descriptor vd, vertices_to_deselect)
{
*out++=vd;
new_selection_border.push_back(vd);
put( is_selected, vd, false );
}
current_selection_border.swap(new_selection_border);
}
return out;
}
} //end of namespace CGAL
#endif //CGAL_BOOST_GRAPH_KTH_SIMPLICIAL_NEIGHBORHOOD_H
|