MEPP2 Project
test_helpers_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.
12 
13 #include <cassert>
14 
15 using namespace FEVV::DataStructures::AIF;
17 
18 /*
19  Example topology used in this test
20 
21  v2 ----------- v6
22  /|\ \
23  / | \ \
24  / | \ \
25  / | \ \
26  / | \ \
27  / | \ \
28  / | \ \
29  / | \ \
30  / | \ \ v9
31  / | \ \ / \
32  / | \ \ / \
33  / f4 | f3 \ f2 \ / \
34  / | \ \ / f5 \
35  / | \ \ / \
36 v1 ---------- v0 ----------- v3 v7 --------- v8
37  \ | | /
38  \ | | /
39  \ | | /
40  \ | | /
41  \ f0 | f1 | /
42  \ | | /
43  \ | | / v11
44 (isolated) \ | | /
45  \ | | /
46  \ | | /
47  \ | | /
48  \ | | /
49  \ | | /
50  \| |/
51  v5 ----------- v4 ----------- v10
52 */
53 
55 add_face_to_mesh(const std::vector< helpers::vertex_descriptor > &vertices,
57 {
58  typedef std::vector< helpers::vertex_descriptor >::const_iterator iterator;
59 
60  helpers::vertex_descriptor prev_vertex = vertices.back(), current_vertex;
61  helpers::edge_descriptor current_edge;
62  helpers::face_descriptor current_face = helpers::add_face(mesh);
63 
64  for(iterator it = vertices.cbegin(); it != vertices.cend(); ++it)
65  {
66  current_vertex = *it;
67 
68  // check if the 2 vertices ain't already link by an edge
69  helpers::edge_descriptor current_edge;
70  if((current_edge = helpers::common_edge(prev_vertex, current_vertex)) ==
72  {
73  // create the edge in the mesh
74  current_edge = helpers::add_edge(mesh);
75  // link the edge and the vertices
77  prev_vertex, current_edge, helpers::vertex_pos::FIRST);
79  current_vertex, current_edge, helpers::vertex_pos::SECOND);
80  }
81  // link the edge and the face
82  helpers::link_edge_and_face(current_edge, current_face);
83 
84  prev_vertex = current_vertex;
85  }
86 
87  return current_face;
88 }
89 
90 unsigned int nbAssert = 0;
91 void
92 test_assert(bool expr)
93 {
94  if(!expr)
95  throw std::runtime_error("Test Failed");
96  nbAssert++;
97 }
98 
99 int
100 main(void)
101 {
103 
105  const unsigned int nb_vertices = 12;
107 
108  for(unsigned int i = 0; i < nb_vertices; ++i)
109  vertices[i] = helpers::add_vertex(mesh);
110 
113  helpers::link_vertex_and_edge(vertices[4], dedge, helpers::vertex_pos::FIRST);
115  vertices[10], dedge, helpers::vertex_pos::SECOND);
116 
118  const unsigned int nb_faces = 6;
120 
121  std::vector< helpers::vertex_descriptor > face0 = {
122  vertices[0], vertices[5], vertices[1]};
123  faces[0] = add_face_to_mesh(face0, mesh);
124 
125  std::vector< helpers::vertex_descriptor > face1 = {
126  vertices[0], vertices[3], vertices[4], vertices[5]};
127  faces[1] = add_face_to_mesh(face1, mesh);
128 
129  std::vector< helpers::vertex_descriptor > face2 = {
130  vertices[6], vertices[7], vertices[4], vertices[3], vertices[2]};
131  faces[2] = add_face_to_mesh(face2, mesh);
132 
133  std::vector< helpers::vertex_descriptor > face3 = {
134  vertices[0], vertices[2], vertices[3]};
135  faces[3] = add_face_to_mesh(face3, mesh);
136 
137  std::vector< helpers::vertex_descriptor > face4 = {
138  vertices[0], vertices[1], vertices[2]};
139  faces[4] = add_face_to_mesh(face4, mesh);
140 
141  std::vector< helpers::vertex_descriptor > face5 = {
142  vertices[9], vertices[8], vertices[7]};
143  faces[5] = add_face_to_mesh(face5, mesh);
144 
146  try
147  {
151 
154 
157  // test_assert(helpers::is_cut_vertex(vertices[7]));
158 
163 
168 
171 
172  helpers::edge_descriptor common_edge =
174  test_assert(common_edge == helpers::null_edge());
175 
176  common_edge = helpers::common_edge(vertices[0], vertices[3]);
177  test_assert(common_edge != helpers::null_edge());
178 
179  test_assert(helpers::are_incident(vertices[0], common_edge));
180  test_assert(helpers::are_incident(vertices[3], common_edge));
181 
185 
191  // vertex
192 
193  typedef boost::iterator_range<
194  helpers::edge_container_in_vertex::const_iterator >
195  ve_range;
196  ve_range r1 = helpers::incident_edges(vertices[0]);
197 
198  std::vector< unsigned int > vv_vec = {1, 2, 3, 5};
199  for(std::vector< unsigned int >::iterator it = vv_vec.begin();
200  it != vv_vec.end();
201  ++it)
202  {
203  test_assert(std::find(r1.begin(),
204  r1.end(),
206  r1.end());
207  }
208 
210 
211  test_assert(
213  test_assert(
215  test_assert(
217 
226 
235 
244 
247  helpers::common_edge(vertices[4], vertices[7]))); // same edge
248  test_assert(
251  test_assert(
254 
261 
262  test_assert(
264  vertices[2]) != helpers::vertex_pos::FIRST);
265  test_assert(
267  vertices[3]) == helpers::vertex_pos::FIRST);
268  test_assert(
270  vertices[2]) == helpers::vertex_pos::SECOND);
271  test_assert(
273  vertices[3]) != helpers::vertex_pos::SECOND);
274 
275  test_assert(
277  vertices[3]) == vertices[4]);
278  test_assert(
280  vertices[4]) == vertices[3]);
281 
283 
284  test_assert(
286  vertices[3]) == vertices[4]);
287  test_assert(
289  vertices[4]) == vertices[3]);
290 
291  test_assert(
293  vertices[4]) == helpers::vertex_pos::FIRST);
294  test_assert(
296  vertices[3]) == helpers::vertex_pos::SECOND);
297 
299 
300  test_assert(
302  vertices[4]) == helpers::vertex_pos::SECOND);
303  test_assert(
305  vertices[3]) == helpers::vertex_pos::FIRST);
306 
308 
312 
313  test_assert(!helpers::are_adjacent(faces[0], faces[0])); // same face
318 
320 
321  test_assert(helpers::num_vertices(mesh) == 12);
322  test_assert(helpers::num_edges(mesh) == 16);
323  test_assert(helpers::num_faces(mesh) == 6);
324 
325  typedef boost::iterator_range< helpers::vertex_container::const_iterator >
326  v_range;
327  typedef boost::iterator_range< helpers::edge_container::const_iterator >
328  e_range;
329  typedef boost::iterator_range< helpers::face_container::const_iterator >
330  f_range;
331  //typedef helpers::vertex_container_in_edge ve_pair;
332  //typedef boost::iterator_range<
333  // helpers::face_container_in_edge::const_iterator >
334  // fe_range;
335  e_range r2 = helpers::edges(mesh);
336 
337  for(e_range::iterator it = r2.begin(); it != r2.end(); ++it)
338  {
341  }
342 
343  test_assert(helpers::num_vertices(mesh) == 12);
344  test_assert(helpers::num_edges(mesh) == 16);
345  test_assert(helpers::num_faces(mesh) == 6);
346 
347  v_range r3 = helpers::vertices(mesh);
348  e_range r4 = helpers::edges(mesh);
349  f_range r5 = helpers::faces(mesh);
350 
351  for(v_range::iterator it = r3.begin(); it != r3.end(); ++it)
352  test_assert(helpers::degree(*it) == 0);
353 
354  for(e_range::iterator it = r4.begin(); it != r4.end(); ++it)
355  {
357  test_assert(helpers::degree(*it) == 0);
358  }
359 
360  for(f_range::iterator it = r5.begin(); it != r5.end(); ++it)
361  test_assert(helpers::degree(*it) == 0);
362 
363  std::vector< helpers::vertex_descriptor > vertices_to_delete;
364  std::copy(
365  r3.begin(),
366  r3.end(),
367  std::back_inserter(vertices_to_delete)); // the pointers need to be
368  // copied to keep iterator valid
369  // std::vector<helpers::vertex_descriptor> verticesToDelete(r3.size()); //
370  // C++ recommends this solution std::copy(r3.begin(), r3.end(),
371  // verticesToDelete.begin()); // C++ recommends this solution
372  for(std::vector< helpers::vertex_descriptor >::const_iterator it =
373  vertices_to_delete.cbegin();
374  it != vertices_to_delete.cend();
375  ++it)
376  helpers::remove_vertex(*it, mesh);
377 
378  std::vector< helpers::edge_descriptor > edges_to_delete;
379  std::copy(
380  r4.begin(),
381  r4.end(),
382  std::back_inserter(edges_to_delete)); // the pointers need to be copied
383  // to keep iterator valid
384  // std::vector<helpers::edge_descriptor> edgesToDelete(r4.size()); // C++
385  // recommends this solution std::copy(r4.begin(), r4.end(),
386  // edgesToDelete.begin()); // C++ recommends this solution
387  for(std::vector< helpers::edge_descriptor >::const_iterator it =
388  edges_to_delete.cbegin();
389  it != edges_to_delete.cend();
390  ++it)
391  helpers::remove_edge(*it, mesh);
392 
393  std::vector< helpers::face_descriptor > faces_to_delete;
394  std::copy(
395  r5.begin(),
396  r5.end(),
397  std::back_inserter(faces_to_delete)); // the pointers need to be copied
398  // to keep iterator valid
399  // std::vector<helpers::face_descriptor> facesToDelete(r5.size()); // C++
400  // recommends this solution std::copy(r5.begin(), r5.end(),
401  // facesToDelete.begin()); // C++ recommends this solution
402  for(std::vector< helpers::face_descriptor >::const_iterator it =
403  faces_to_delete.cbegin();
404  it != faces_to_delete.cend();
405  ++it)
406  helpers::remove_face(*it, mesh);
407 
409  test_assert(helpers::num_edges(mesh) == 0);
410  test_assert(helpers::num_faces(mesh) == 0);
411  }
412  catch(std::runtime_error &e)
413  {
414  std::cout << e.what() << " (at assert #" << nbAssert << ")" << std::endl;
415  return -1;
416  }
417 
418  std::cout << "Test Successful" << std::endl;
419  return 0;
420 }
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_surface_interior_edge
static bool is_surface_interior_edge(edge_descriptor edge)
Definition: AIFTopologyHelpers.h:971
FEVV::DataStructures::AIF::vertices
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator > vertices(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the iterator range of the vertices of the mesh.
Definition: Graph_traits_aif.h:172
FEVV::DataStructures::AIF::AIFTopologyHelpers::unlink_all_faces
static void unlink_all_faces(edge_descriptor edge)
Definition: AIFTopologyHelpers.h:3261
nbAssert
unsigned int nbAssert
Definition: test_helpers_aif.cpp:90
FEVV::DataStructures::AIF::AIFTopologyHelpers::common_edge
static edge_descriptor common_edge(vertex_descriptor vertex1, vertex_descriptor vertex2)
Definition: AIFTopologyHelpers.h:458
helpers
AIFTopologyHelpers helpers
Definition: test_helpers_aif.cpp:16
test_assert
void test_assert(bool expr)
Definition: test_helpers_aif.cpp:92
FEVV::DataStructures::AIF::AIFTopologyHelpers::num_faces
static size_type num_faces(ptr_cmesh mesh)
Definition: AIFTopologyHelpers.h:2200
FEVV::DataStructures::AIF::AIFTopologyHelpers::add_face
static face_descriptor add_face(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2887
FEVV::DataStructures::AIF::AIFTopologyHelpers::opposite_vertex
static vertex_descriptor opposite_vertex(edge_descriptor edge, vertex_descriptor vertex)
Definition: AIFTopologyHelpers.h:1270
FEVV::DataStructures::AIF
Definition: AIFCellContainer.h:15
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::num_edges
static size_type num_edges(ptr_cmesh mesh)
Definition: AIFTopologyHelpers.h:2174
FEVV::DataStructures::AIF::AIFTopologyHelpers::remove_face
static void remove_face(face_descriptor face, ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:3120
FEVV::DataStructures::AIF::AIFTopologyHelpers::are_adjacent
static bool are_adjacent(vertex_descriptor vertex1, vertex_descriptor vertex2)
Definition: AIFTopologyHelpers.h:358
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::vertex_position
static vertex_pos vertex_position(edge_descriptor edge, vertex_descriptor vertex)
Definition: AIFTopologyHelpers.h:1252
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_surface_border_vertex
static bool is_surface_border_vertex(vertex_descriptor vertex)
Definition: AIFTopologyHelpers.h:264
FEVV::DataStructures::AIF::AIFTopologyHelpers::null_edge
static edge_descriptor null_edge()
Definition: AIFTopologyHelpers.h:113
FEVV::DataStructures::AIF::AIFTopologyHelpers::add_edge
static edge_descriptor add_edge(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2772
FEVV::DataStructures::AIF::AIFTopologyHelpers::swap_vertices
static void swap_vertices(edge_descriptor edge)
Definition: AIFTopologyHelpers.h:1286
FEVV::DataStructures::AIF::AIFTopologyHelpers::faces
static boost::iterator_range< face_container::const_iterator > faces(ptr_cmesh mesh)
Definition: AIFTopologyHelpers.h:2606
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_dangling_edge
static bool is_dangling_edge(edge_descriptor edge)
Definition: AIFTopologyHelpers.h:1009
FEVV::DataStructures::AIF::AIFTopologyHelpers::degree
static size_type degree(vertex_descriptor vertex)
Definition: AIFTopologyHelpers.h:148
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_cut_vertex
static bool is_cut_vertex(vertex_descriptor vertex)
Definition: AIFTopologyHelpers.h:173
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
add_face_to_mesh
helpers::face_descriptor add_face_to_mesh(const std::vector< helpers::vertex_descriptor > &vertices, helpers::smart_ptr_mesh mesh)
Definition: test_helpers_aif.cpp:55
FEVV::DataStructures::AIF::AIFTopologyHelpers::remove_edge
static void remove_edge(edge_descriptor edge, ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:3012
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_surface_border_edge
static bool is_surface_border_edge(edge_descriptor edge)
Definition: AIFTopologyHelpers.h:949
AIFMesh.hpp
FEVV::DataStructures::AIF::faces
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_iterator > faces(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns an iterator range over all faces of the mesh.
Definition: Graph_traits_aif.h:679
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_degenerated_edge
static bool is_degenerated_edge(edge_descriptor edge)
Definition: AIFTopologyHelpers.h:1034
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_isolated_vertex
static bool is_isolated_vertex(vertex_descriptor vertex)
Definition: AIFTopologyHelpers.h:159
FEVV::DataStructures::AIF::AIFTopologyHelpers::remove_vertex
static void remove_vertex(vertex_descriptor vertex, ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2960
FEVV::DataStructures::AIF::AIFTopologyHelpers::edges
static boost::iterator_range< edge_container::const_iterator > edges(ptr_cmesh mesh)
Definition: AIFTopologyHelpers.h:2261
FEVV::DataStructures::AIF::AIFTopologyHelpers::num_vertices
static size_type num_vertices(ptr_cmesh mesh)
Definition: AIFTopologyHelpers.h:2148
FEVV::DataStructures::AIF::AIFTopologyHelpers::unlink_all_vertices
static void unlink_all_vertices(edge_descriptor edge)
Definition: AIFTopologyHelpers.h:3204
FEVV::DataStructures::AIF::AIFTopologyHelpers::incident_edges
static boost::iterator_range< edge_container_in_vertex::const_iterator > incident_edges(vertex_descriptor vertex)
Definition: AIFTopologyHelpers.h:399
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::AIFTopologyHelpers::vertices
static boost::iterator_range< vertex_container::const_iterator > vertices(ptr_cmesh mesh)
Definition: AIFTopologyHelpers.h:2227
FEVV::DataStructures::AIF::AIFTopologyHelpers::add_vertex
static vertex_descriptor add_vertex(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2709
FEVV::DataStructures::AIF::AIFTopologyHelpers::is_surface_interior_vertex
static bool is_surface_interior_vertex(vertex_descriptor vertex)
Definition: AIFTopologyHelpers.h:288
FEVV::DataStructures::AIF::AIFTopologyHelpers::are_incident
static bool are_incident(vertex_descriptor vertex, edge_descriptor edge)
Function determining if the arguments share an incidence relation.
Definition: AIFTopologyHelpers.h:303
main
int main(void)
Definition: test_helpers_aif.cpp:100