MEPP2 Project
k_ring.hpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 #include <map>
14 #include <vector>
15 
16 #include <boost/graph/graph_traits.hpp>
17 #include <boost/graph/properties.hpp>
18 #include <CGAL/boost/graph/helpers.h> // is_border
20 
21 namespace FEVV {
22 namespace Operators {
23 
38 template< typename FaceGraph,
39  typename GeometryTraits = FEVV::Geometry_traits< FaceGraph > >
40 void
43  const FaceGraph &g,
44  int k,
46  &qv)
47 {
48  typedef boost::graph_traits< FaceGraph > GraphTraits;
50  typedef typename GraphTraits::halfedge_descriptor halfedge_descriptor;
51  //typedef typename GraphTraits::face_descriptor face_descriptor;
52 
53  std::map< vertex_descriptor, int > d;
54  qv.push_back(v);
55  d[v] = 0;
56  std::size_t current_index = 0;
57  int dist_v;
58  while(current_index < qv.size() && (dist_v = d[qv[current_index]]) < k)
59  {
60  v = qv[current_index++];
61  halfedge_descriptor h = halfedge(v, g), hend = h;
62  // CGAL::Vertex_around_target_circulator<HalfedgeGraph> e(halfedge(v, g),
63  // g), e_end(e); // for surface mesh
64  // HalfedgeGraph::Halfedge_around_vertex_circulator e(v->vertex_begin()),
65  // e_end(e); // ok for polyhedron
66  do
67  {
68  vertex_descriptor new_v = source(h, g);
69  assert(v == target(h, g));
70  if(d.insert(std::make_pair(new_v, dist_v + 1)).second)
71  {
72  qv.push_back(new_v);
73  }
74  // There is a pb when the next edge is a border edge: we must take into
75  // account the vertices while updating correctly the next halfedge
76  if(face(opposite(next(h, g), g), g) ==
77  boost::graph_traits< FaceGraph >::null_face())
78  {
79  if(d.insert(std::make_pair(target(next(h, g), g), dist_v + 1)).second)
80  {
81  qv.push_back(target(next(h, g), g));
82  }
83  }
84  h = opposite(next(h, g), g);
85  } while(!(h == hend));
86  }
87  // debug
88  // std::cout << "qv.size() = " << qv.size() << std::endl;
89 }
90 
91 
104 template< typename FaceGraph >
105 void
108  const FaceGraph &g,
109  std::vector<
110  typename boost::graph_traits< FaceGraph >::halfedge_descriptor > &qh)
111 {
112  typedef boost::graph_traits< FaceGraph > GraphTraits;
113  //typedef typename GraphTraits::vertex_descriptor vertex_descriptor;
114  typedef typename GraphTraits::halfedge_descriptor halfedge_descriptor;
115  //typedef typename GraphTraits::face_descriptor face_descriptor;
116 
117  //std::size_t current_index = 0;
118 
119  halfedge_descriptor h = halfedge(v, g), hend = h;
120  do
121  {
122  // vertex_descriptor new_v = source(h, g), tardeb = target(h, g);
123  // assert(v == tardeb);
124  qh.push_back(h);
125  //vertex_descriptor vs = source(h, g), vt = target(h, g); // debug
126  // There is a pb when the next edge is a border edge: we must take into
127  // account the vertices while updating correctly the next halfedge
128  if(face(opposite(next(h, g), g), g) ==
129  boost::graph_traits< FaceGraph >::null_face())
130  {
131  if(opposite(next(h, g), g) == qh[0]) // Surface Mesh
132  {
133  qh.erase(qh.begin());
134  qh.push_back(opposite(halfedge(v, g), g));
135  break;
136  }
137  qh.push_back(next(h, g)); // border edges are put in the other direction
138  // (because the opposite halfedge was null for
139  // AIFMesh first release [no more the case])
140  // vs = source(next(h, g), g); vt = target(next(h, g), g); // debug
141  // halfedge_descriptor htmp = opposite(next(h, g), g);
142  if(!CGAL::is_border(
143  opposite(h, g),
144  g) // "not a border edge" for polyhedron, OpenMesh and AIF
145 
146  //&& !(opposite(h, g) ==
147  //boost::graph_traits<FaceGraph>::null_halfedge()) // no condition
148  //works properly with Surface Mesh
150  ) // manage the case where there is only one valid halfedge
151  {
152  halfedge_descriptor last = h;
153  // we try to reach the other border (simple, because we assume manifold
154  // configuration)
155  do
156  {
157  if(prev(opposite(h, g), g) == last) // for surface mesh...
158  break;
159  h = prev(opposite(h, g), g);
160  // vs = source(h, g); vt = target(h, g); // debug
161  } while(!CGAL::is_border(
162  opposite(h, g),
163  g) // works with polyhedron, OpenMesh and AIF
164  // !(opposite(h, g) ==
165  // boost::graph_traits<FaceGraph>::null_halfedge()) // no
166  // condition works properly with Surface Mesh
167  );
168  }
169  }
170  else
171  h = opposite(next(h, g), g);
172  } while(!(h == hend));
173  // debug
174  // std::cout << "qh.size() = " << qh.size() << std::endl;
175 }
176 
190 template< typename FaceGraph,
191  typename GeometryTraits = FEVV::Geometry_traits< FaceGraph > >
192 void
195  const FaceGraph &g,
197  &qv)
198 {
199  Operators::extract_k_ring< FaceGraph, GeometryTraits >(v, g, 1, qv);
200  qv.erase(qv.begin()); // the first element is v itself ant it must be removed
201 }
202 
203 } // namespace Operators
204 } // namespace FEVV
FEVV::DataStructures::AIF::next
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor next(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the next halfedge around its face.
Definition: Graph_traits_aif.h:599
FEVV::Operators::extract_1_ring_not_including_v
void extract_1_ring_not_including_v(typename boost::graph_traits< FaceGraph >::vertex_descriptor v, const FaceGraph &g, std::vector< typename boost::graph_traits< FaceGraph >::vertex_descriptor > &qv)
Extract vertices which are at exactly 1 far from vertex v in the graph of edges.
Definition: k_ring.hpp:193
FEVV::DataStructures::AIF::opposite
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor opposite(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the halfedge with source and target swapped.
Definition: Graph_traits_aif.h:625
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
FEVV::DataStructures::AIF::source
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor source(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the source vertex of e.
Definition: Graph_traits_aif.h:387
FEVV::Operators::extract_k_ring
void extract_k_ring(typename boost::graph_traits< FaceGraph >::vertex_descriptor v, const FaceGraph &g, int k, std::vector< typename boost::graph_traits< FaceGraph >::vertex_descriptor > &qv)
Extract vertices which are at most k (inclusive) far from vertex v in the graph of edges.
Definition: k_ring.hpp:41
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::DataStructures::AIF::halfedge
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor halfedge(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor v, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns a halfedge with target v.
Definition: Graph_traits_aif.h:296
FEVV::DataStructures::AIF::target
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor target(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the target vertex of e.
Definition: Graph_traits_aif.h:400
Geometry_traits.h
FEVV::DataStructures::AIF::prev
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor prev(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the previous halfedge around its face.
Definition: Graph_traits_aif.h:612
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::DataStructures::AIF::face
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_descriptor face(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the face incident to halfedge h.
Definition: Graph_traits_aif.h:664
FEVV::Operators::extract_vertex_star
void extract_vertex_star(typename boost::graph_traits< FaceGraph >::vertex_descriptor v, const FaceGraph &g, std::vector< typename boost::graph_traits< FaceGraph >::halfedge_descriptor > &qh)
Extract halfedges which have v as target vertex. All extracted halfedges are associated to a face,...
Definition: k_ring.hpp:106