MEPP2 Project
test_complex_one_ring_aif.cpp
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.
13 
14 #include <algorithm>
15 
16 // must be the last include to avoid side effect of disabling NDEBUG
17 #undef NDEBUG
18 #include <cassert>
19 
20 //------------------------------------------------------------------------------
21 
22 /*
23  * Display container or range content.
24  */
25 template< typename T >
26 void
27 display_container(const T &container, const char *title)
28 {
29  std::cout << title << " =" << std::endl;
30  for(auto element : container)
31  std::cout << " " << element << std::endl;
32  std::cout << std::endl;
33 }
34 
35 //------------------------------------------------------------------------------
36 
37 const bool VERBOSE = false;
38 
39 /*
40  * Returns true if 2 containers are equal by rotation.
41  */
42 template< typename T >
43 bool
44 rotationally_equal(const T &v1, T v2, bool test_in_reverse_order_too = true)
45 {
46  bool are_equal = false;
47 
48  while(true)
49  {
50  for(size_t i = 0; i < v1.size(); i++)
51  {
52  if(VERBOSE)
53  {
54  std::cout << "rotate number = " << i << std::endl;
55  display_container(v1, "v1");
56  display_container(v2, "v2");
57  }
58 
59  if(v1 == v2)
60  {
61  if(VERBOSE)
62  std::cout << "v1 == v2" << std::endl;
63  are_equal = true;
64  break;
65  }
66  else
67  {
68  if(VERBOSE)
69  std::cout << "v1 != v2" << std::endl;
70  }
71 
72  // rotate v2 and test again
73  std::rotate(v2.begin(), v2.begin() + 1, v2.end());
74  }
75 
76  if(are_equal == false && test_in_reverse_order_too)
77  {
78  if(VERBOSE)
79  std::cout << "reverse v2" << std::endl;
80  std::reverse(v2.begin(), v2.end());
81  test_in_reverse_order_too = false;
82  }
83  else
84  break;
85  }
86 
87  return are_equal;
88 }
89 
90 //------------------------------------------------------------------------------
91 
92 int
93 main(void)
94 {
96  //typedef FEVV::DataStructures::AIF::AIFVertex AIFVertex;
97  //typedef FEVV::DataStructures::AIF::AIFEdge AIFEdge;
98  //typedef FEVV::DataStructures::AIF::AIFFace AIFFace;
100  //typedef helpers::AIFHalfEdge AIFHalfEdge;
101  typedef helpers::smart_ptr_mesh smart_ptr_mesh;
104  //typedef helpers::halfedge_descriptor halfedge_descriptor;
105  typedef helpers::face_descriptor face_descriptor;
106 
107 
108  // build mesh
109  /*
110  v2
111  /|\
112  / | \ v5
113  / | \ /|
114  / | \ / |
115  / | \ / |
116  e0/ |e7 \e1 / |
117  / | \ /e9 |
118  / | \/ f4 |
119  / | /\ |e8
120  / | f2 / \ |
121  / | / \ |
122  / f3 | / \ |
123  / | / \ |
124  / e6 | / e4 \|
125 v1 ---------- v0 ----------- v3
126  \ | /
127  \ | /
128  \ | /
129  \ | /
130  \ f0 | f1 /
131  \ | /
132  \ | /
133  e3\ |e5 / e2
134  \ | /
135  \ | /
136  \ | /
137  \ | /
138  \ | /
139  \|/
140  v4
141  */
142 
143  smart_ptr_mesh m = AIFMesh::New();
144 
145  // add vertices
152 
153  // add edges
155  helpers::link_vertex_and_edge(v1, e0, helpers::vertex_pos::FIRST);
156  helpers::link_vertex_and_edge(v2, e0, helpers::vertex_pos::SECOND);
158  helpers::link_vertex_and_edge(v2, e1, helpers::vertex_pos::FIRST);
159  helpers::link_vertex_and_edge(v3, e1, helpers::vertex_pos::SECOND);
161  helpers::link_vertex_and_edge(v3, e2, helpers::vertex_pos::FIRST);
162  helpers::link_vertex_and_edge(v4, e2, helpers::vertex_pos::SECOND);
164  helpers::link_vertex_and_edge(v1, e3, helpers::vertex_pos::FIRST);
165  helpers::link_vertex_and_edge(v4, e3, helpers::vertex_pos::SECOND);
167  helpers::link_vertex_and_edge(v0, e4, helpers::vertex_pos::FIRST);
168  helpers::link_vertex_and_edge(v3, e4, helpers::vertex_pos::SECOND);
170  helpers::link_vertex_and_edge(v4, e5, helpers::vertex_pos::FIRST);
171  helpers::link_vertex_and_edge(v0, e5, helpers::vertex_pos::SECOND);
173  helpers::link_vertex_and_edge(v1, e6, helpers::vertex_pos::FIRST);
174  helpers::link_vertex_and_edge(v0, e6, helpers::vertex_pos::SECOND);
176  helpers::link_vertex_and_edge(v0, e7, helpers::vertex_pos::FIRST);
177  helpers::link_vertex_and_edge(v2, e7, helpers::vertex_pos::SECOND);
179  helpers::link_vertex_and_edge(v3, e8, helpers::vertex_pos::FIRST);
180  helpers::link_vertex_and_edge(v5, e8, helpers::vertex_pos::SECOND);
182  helpers::link_vertex_and_edge(v0, e9, helpers::vertex_pos::FIRST);
183  helpers::link_vertex_and_edge(v5, e9, helpers::vertex_pos::SECOND);
184 
185  // add faces [counter-clockwise oriented]
186  face_descriptor f0 = helpers::add_face(m);
190  face_descriptor f1 = helpers::add_face(m);
194  face_descriptor f2 = helpers::add_face(m);
198  face_descriptor f3 = helpers::add_face(m);
202  face_descriptor f4 = helpers::add_face(m);
206 
207  // display mesh informations
208  std::cout << "Input mesh:\n";
209  m->Print();
210 
211  //---------------------- Tests ---------------------
212 
213  // unordered one ring edges of vertex
215  e0, helpers::get_unordered_one_ring_edges(v0)) == true);
217  e1, helpers::get_unordered_one_ring_edges(v0)) == false);
219  e1, helpers::get_unordered_one_ring_edges(v0), true) == true);
221  e2, helpers::get_unordered_one_ring_edges(v0)) == false);
223  e2, helpers::get_unordered_one_ring_edges(v0), true) == true);
225  e3, helpers::get_unordered_one_ring_edges(v0)) == true);
227  e8, helpers::get_unordered_one_ring_edges(v0)) == false);
229  e8, helpers::get_unordered_one_ring_edges(v0), true) == false);
230  std::cout << "testing get_ordered_one_ring_edges(v0)" << std::endl;
232  "helpers::get_ordered_one_ring_edges(v0)");
233  display_container(std::vector< edge_descriptor >{e2, e1, e0, e3, e8},
234  "std::vector<edge_descriptor>{e2, e1, e0, e3, e8}");
235  // auto c = helpers::get_ordered_one_ring_edges(v0);
236  assert(rotationally_equal(
238  std::vector< edge_descriptor >{e1, e8, e2, e3, e0}) // ok
239  );
240  // ordered one ring of vertices of vertex
241 
242  std::cout << "testing get_ordered_one_ring_vertices(v0)" << std::endl;
243  assert(rotationally_equal(
245  std::vector< vertex_descriptor >{v3, v5, v3, v4, v1, v2}) // ok
246  );
247 
248  std::cout << "testing get_ordered_one_ring_vertices(v1)" << std::endl;
250  std::vector< vertex_descriptor >{v2, v0, v4}));
251 
252  std::cout << "testing get_ordered_one_ring_vertices(v2)" << std::endl;
254  std::vector< vertex_descriptor >{v3, v0, v1}));
255 
256  // ordered one ring of adjacent vertices of vertex
257 
258  std::cout << "testing get_ordered_one_ring_of_adjacent_vertices(v0)"
259  << std::endl;
260  assert(rotationally_equal(
262  std::vector< vertex_descriptor >{v3, v5, v3, v4, v1, v2}) // ok
263  );
264 
265  //---------------------- Tests even more complex ---------------------
267 
269  helpers::link_vertex_and_edge(v0, e10, helpers::vertex_pos::FIRST);
270  helpers::link_vertex_and_edge(v6, e10, helpers::vertex_pos::SECOND);
272  helpers::link_vertex_and_edge(v1, e11, helpers::vertex_pos::FIRST);
273  helpers::link_vertex_and_edge(v6, e11, helpers::vertex_pos::SECOND);
274 
275  face_descriptor f5 = helpers::add_face(m);
279  // auto c = helpers::get_ordered_one_ring_edges(v0);
280  assert(rotationally_equal(
282  std::vector< edge_descriptor >{e1, e8, e2, e3, e11, e0}) // ok
283  );
284  // ordered one ring of vertices of vertex
285 
286  std::cout << "testing get_ordered_one_ring_vertices(v0)" << std::endl;
287  assert(rotationally_equal(
289  std::vector< vertex_descriptor >{v3, v5, v3, v4, v1, v6, v1, v2}) // ok
290  );
291 
292  // bellow the code is a work in progress, please let it here as it is
293 #if 0 // dangling one-ring polylines not yet managed
294  //---------------------- Tests even more complex ---------------------
296 
298  helpers::link_vertex_and_edge(v0, e12, helpers::vertex_pos::FIRST);
299  helpers::link_vertex_and_edge(v7, e12, helpers::vertex_pos::SECOND);
300 
302  helpers::link_vertex_and_edge(v5, e13, helpers::vertex_pos::FIRST);
303  helpers::link_vertex_and_edge(v7, e13, helpers::vertex_pos::SECOND);
304 
305  face_descriptor f6 = helpers::add_face(m);
311 std::vector<edge_descriptor>{e1, e8, e13, e2, e3, e11, e0}) // ok
312  );
313  // ordered one ring of vertices of vertex
314 
315  std::cout << "testing get_ordered_one_ring_vertices(v0)" << std::endl;
317 std::vector<vertex_descriptor>{v3, v5, v7, v5, v3, v4, v1, v6, v1, v2}) // ok
318  );
319 #else
321  helpers::link_vertex_and_edge(v5, e12, helpers::vertex_pos::FIRST);
322  helpers::link_vertex_and_edge(v6, e12, helpers::vertex_pos::SECOND);
323 
324  face_descriptor f6 = helpers::add_face(m);
328  //auto c = helpers::get_ordered_one_ring_edges(v0);
329  assert(rotationally_equal(helpers::get_ordered_one_ring_edges(v0), std::vector<edge_descriptor>{e11, e12, e3, e2, e8, e1, e0}) // ok
330  ||
331  rotationally_equal(helpers::get_ordered_one_ring_edges(v0), std::vector<edge_descriptor>{e12, e8, e2, e3, e11, e0, e1}) // ok
332  ||
333  rotationally_equal(helpers::get_ordered_one_ring_edges(v0), std::vector<edge_descriptor>{e12, e8, e1, e0, e11, e3, e2}) // ok
334  ||
335  rotationally_equal(helpers::get_ordered_one_ring_edges(v0), std::vector<edge_descriptor>{e0, e1, e8, e2, e3, e11, e12}) // ok
336  );
337  // ordered one ring of vertices of vertex
338 
339  //std::cout << "testing get_ordered_one_ring_vertices(v0)" << std::endl;
340  //assert(rotationally_equal(helpers::get_ordered_one_ring_vertices(v0), std::vector<vertex_descriptor>{v6, v5, v3, v2, v1, v4}) // not idea of expected result
341  // );
342 #endif
343 
344  return 0; // all tests passed
345 }
helpers
AIFTopologyHelpers helpers
Definition: test_helpers_aif.cpp:16
FEVV::DataStructures::AIF::AIFTopologyHelpers::add_face
static face_descriptor add_face(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2887
FEVV::DataStructures::AIF::AIFTopologyHelpers::link_edge_and_face
static void link_edge_and_face(edge_descriptor edge, face_descriptor face)
Definition: AIFTopologyHelpers.h:1305
FEVV::DataStructures::AIF::AIFTopologyHelpers::vertex_descriptor
vertex_type::ptr vertex_descriptor
Definition: AIFTopologyHelpers.h:70
FEVV::DataStructures::AIF::AIFTopologyHelpers::get_ordered_one_ring_edges
static edge_container_in_vertex get_ordered_one_ring_edges(vertex_descriptor v)
Definition: AIFTopologyHelpers.h:3644
main
int main(void)
Definition: test_complex_one_ring_aif.cpp:93
display_container
void display_container(const T &container, const char *title)
Definition: test_complex_one_ring_aif.cpp:27
GraphConcept::edge_descriptor
boost::graph_traits< G >::edge_descriptor edge_descriptor
Definition: test_boost_graph_concept_aif.cpp:23
FEVV::DataStructures::AIF::AIFTopologyHelpers::edge_descriptor
edge_type::ptr edge_descriptor
Definition: AIFTopologyHelpers.h:71
FEVV::DataStructures::AIF::AIFMesh::New
static ptr_mesh New()
Definition: AIFMesh.inl:720
FEVV::DataStructures::AIF::AIFTopologyHelpers::face_descriptor
face_type::ptr face_descriptor
Definition: AIFTopologyHelpers.h:72
FEVV::DataStructures::AIF::AIFTopologyHelpers::add_edge
static edge_descriptor add_edge(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2772
VERBOSE
const bool VERBOSE
Definition: test_complex_one_ring_aif.cpp:37
FEVV::DataStructures::AIF::AIFTopologyHelpers::link_vertex_and_edge
static void link_vertex_and_edge(vertex_descriptor vertex, edge_descriptor edge, vertex_pos position)
Definition: AIFTopologyHelpers.h:515
AIFMesh.hpp
rotationally_equal
bool rotationally_equal(const T &v1, T v2, bool test_in_reverse_order_too=true)
Definition: test_complex_one_ring_aif.cpp:44
Graph_traits_aif.h
FEVV::DataStructures::AIF::AIFTopologyHelpers::get_unordered_one_ring_edges
static std::set< edge_descriptor > get_unordered_one_ring_edges(vertex_descriptor v)
Definition: AIFTopologyHelpers.h:3481
FEVV::DataStructures::AIF::AIFTopologyHelpers::get_ordered_one_ring_vertices
static vertex_container_in_vertex get_ordered_one_ring_vertices(vertex_descriptor v)
Definition: AIFTopologyHelpers.h:4035
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_e_one_ring_connected
static bool is_e_one_ring_connected(edge_descriptor e, const T &container_of_edge_one_ring, bool allow_multiple_incident_edges=false, bool ensure_e_belongs_to_container=true)
Definition: AIFTopologyHelpers.h:3547
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::DataStructures::AIF::AIFTopologyHelpers::smart_ptr_mesh
mesh_type::ptr smart_ptr_mesh
Definition: AIFTopologyHelpers.h:64
FEVV::DataStructures::AIF::AIFTopologyHelpers
This class is an helper class associated to the AIFMesh structure. AIFTopologyHelpers implements all ...
Definition: AIFTopologyHelpers.h:57
FEVV::DataStructures::AIF::AIFMesh
This class represents an AIF structure. AIF structure can deal with both manifold and non-manifold su...
Definition: AIFMesh.hpp:47
FEVV::DataStructures::AIF::AIFTopologyHelpers::add_vertex
static vertex_descriptor add_vertex(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2709
AIFMesh
FEVV::DataStructures::AIF::AIFMesh AIFMesh
Definition: Graph_properties_aif.h:19
FEVV::DataStructures::AIF::AIFTopologyHelpers::get_ordered_one_ring_of_adjacent_vertices
static vertex_container_in_vertex get_ordered_one_ring_of_adjacent_vertices(vertex_descriptor v)
Definition: AIFTopologyHelpers.h:4305