MEPP2 Project
topology_predicates.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 <boost/graph/graph_traits.hpp>
14 
15 namespace FEVV {
16 namespace Operators {
17 
31 template< typename FaceIncidentGraph >
32 static bool
34  const typename boost::graph_traits< FaceIncidentGraph >::edge_descriptor
35  edge1,
36  const typename boost::graph_traits< FaceIncidentGraph >::edge_descriptor
37  edge2,
38  const FaceIncidentGraph &g)
39 {
40  if(edge1 == edge2)
41  return true;
42  return (source(edge1, g) == source(edge2, g) &&
43  target(edge1, g) == target(edge2, g)) ||
44  (source(edge1, g) == target(edge2, g) &&
45  target(edge1, g) == source(edge2, g));
46 }
47 
60 template< typename FaceIncidentGraph >
61 static bool
64  v_to_keep,
65  const FaceIncidentGraph &g)
66 {
67  auto edges_range_pair = in_edges(v_to_keep, g);
68  auto iter_e = edges_range_pair.first;
69  for(; iter_e != edges_range_pair.second; ++iter_e)
70  {
71  auto iter_e_bis = iter_e;
72  ++iter_e_bis;
73  for(; iter_e_bis != edges_range_pair.second; ++iter_e_bis)
74  {
75  if(Operators::are_similar_edges(*iter_e, *iter_e_bis, g))
76  return true;
77  }
78  }
79  return false;
80 }
81 
97 template< typename FaceIncidentGraph >
98 static bool
100  const typename boost::graph_traits< FaceIncidentGraph >::face_descriptor f1,
101  const typename boost::graph_traits< FaceIncidentGraph >::face_descriptor f2,
102  const FaceIncidentGraph &g,
103  bool take_into_account_face_rientation =
104  false
105 )
108 {
109  if(degree(f1, g) == degree(f2, g))
110  {
111  auto edges_range_pair = out_edges(f1, g); // incident edges of f1
112  auto iter_e = edges_range_pair.first;
113  for(; iter_e != edges_range_pair.second; ++iter_e)
114  { // for each incident edge of the face f1
115  bool is_similar = false;
116  auto edges_range_pair2 = out_edges(f2, g); // incident edges of f2
117  auto iter_e2 = edges_range_pair2.first;
118  for(; iter_e2 != edges_range_pair2.second; ++iter_e2)
119  { // for each incident edge of the face f2
120  if(Operators::are_similar_edges(*iter_e, *iter_e2, g))
121  {
122  if(take_into_account_face_rientation)
123  { // the first time *iterE and *iterE2 are similar edges, we need to
124  // continue the comparison up to come back
125  auto iter_ee = iter_e;
126  do
127  {
128  ++iter_e;
129  if(iter_e == edges_range_pair.second)
130  iter_e = edges_range_pair.first;
131  ++iter_e2;
132  if(iter_e2 == edges_range_pair2.second)
133  iter_e2 = edges_range_pair2.first;
134 
136  *iter_e, *iter_e2, g))
137  return false;
138 
139  } while(iter_e != iter_ee);
140 
141  return true;
142  }
143  else
144  is_similar = true;
145  break;
146  }
147  }
148  if(!is_similar)
149  return false;
150  }
151  return true;
152  }
153 
154  return false;
155 }
156 
169 template< typename FaceIncidentGraph >
170 static bool
172  const typename boost::graph_traits< FaceIncidentGraph >::edge_descriptor
173  e_to_keep,
174  const FaceIncidentGraph &g)
175 {
176  auto face_range_pair = in_edges(e_to_keep, g);
177  auto iter_f = face_range_pair.first;
178  for(; iter_f != face_range_pair.second; ++iter_f)
179  {
180  auto iter_f_bis = iter_f;
181  ++iter_f_bis;
182  for(; iter_f_bis != face_range_pair.second; ++iter_f_bis)
183  {
184  if(Operators::are_similar_faces(*iter_f, *iter_f_bis, g))
185  return true;
186  }
187  }
188  return false;
189 }
190 
203 template< typename FaceIncidentGraph >
204 static bool
207  v_to_keep,
208  const FaceIncidentGraph &g)
209 {
210  auto edge_range_pair = in_edges(v_to_keep, g);
211  auto iter_e = edge_range_pair.first;
212  for(; iter_e != edge_range_pair.second; ++iter_e)
213  {
214  if(Operators::contains_similar_incident_faces<FaceIncidentGraph>(*iter_e, g))
215  return true;
216 
217  }
218  return false;
219 }
220 
232 template< typename IncidentMutableFaceGraph >
233 inline bool
235  const typename boost::graph_traits<
236  IncidentMutableFaceGraph >::edge_descriptor e,
237  const IncidentMutableFaceGraph &g)
238 {
239  auto face_range_pair = in_edges(e, g);
240  auto iter = face_range_pair.first;
241  for(; iter != face_range_pair.second; ++iter)
242  {
243  if(degree(*iter, g) != 3)
244  return false;
245  }
246  return true;
247 }
248 
249 } // namespace Operators
250 } // namespace FEVV
251 
FEVV::Operators::contains_similar_incident_faces
static bool contains_similar_incident_faces(const typename boost::graph_traits< FaceIncidentGraph >::edge_descriptor e_to_keep, const FaceIncidentGraph &g)
Function determining if a pair of similar/parallel faces exists among the incident faces of edge e_to...
Definition: topology_predicates.hpp:171
FEVV::DataStructures::AIF::degree
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::degree_size_type degree(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor u, const FEVV::DataStructures::AIF::AIFMesh &)
Definition: Graph_traits_aif.h:548
FEVV::Operators::are_similar_faces
static bool are_similar_faces(const typename boost::graph_traits< FaceIncidentGraph >::face_descriptor f1, const typename boost::graph_traits< FaceIncidentGraph >::face_descriptor f2, const FaceIncidentGraph &g, bool take_into_account_face_rientation=false)
Function determining if the arguments are similar faces (parallel faces).
Definition: topology_predicates.hpp:99
FEVV::DataStructures::AIF::out_edges
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::out_edge_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::out_edge_iterator > out_edges(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor u, const FEVV::DataStructures::AIF::AIFMesh &)
Definition: Graph_traits_aif.h:416
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
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Operators::has_only_incident_triangular_faces
bool has_only_incident_triangular_faces(const typename boost::graph_traits< IncidentMutableFaceGraph >::edge_descriptor e, const IncidentMutableFaceGraph &g)
Function determining if the incident faces to e are all triangles.
Definition: topology_predicates.hpp:234
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
FEVV::Operators::contains_similar_incident_edges
static bool contains_similar_incident_edges(const typename boost::graph_traits< FaceIncidentGraph >::vertex_descriptor v_to_keep, const FaceIncidentGraph &g)
Function determining if a pair of similar/parallel edges exists among the incident edges of vertex v_...
Definition: topology_predicates.hpp:62
FEVV::DataStructures::AIF::in_edges
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::in_edge_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::in_edge_iterator > in_edges(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor u, const FEVV::DataStructures::AIF::AIFMesh &)
Definition: Graph_traits_aif.h:451
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::Operators::are_similar_edges
static bool are_similar_edges(const typename boost::graph_traits< FaceIncidentGraph >::edge_descriptor edge1, const typename boost::graph_traits< FaceIncidentGraph >::edge_descriptor edge2, const FaceIncidentGraph &g)
Function determining if the arguments are similar edges (parallel edges).
Definition: topology_predicates.hpp:33