MEPP2 Project
test_halfedge_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 // must be the last include to avoid side effect of disabling NDEBUG
15 #undef NDEBUG
16 #include <cassert>
17 
18 //------------------------------------------------------------------------------
19 
20 int
21 main(void)
22 {
24  //typedef FEVV::DataStructures::AIF::AIFVertex AIFVertex;
25  //typedef FEVV::DataStructures::AIF::AIFEdge AIFEdge;
26  //typedef FEVV::DataStructures::AIF::AIFFace AIFFace;
28  typedef helpers::AIFHalfEdge AIFHalfEdge;
29  typedef helpers::smart_ptr_mesh smart_ptr_mesh;
32  typedef helpers::face_descriptor face_descriptor;
33 
34 
35  /* build mesh
36 
37  v3
38  /|\
39  e3/ | \e2
40  v0 /f0|f1\ v2
41  \e4| /
42  e0\ | /e1
43  \|/
44  v1
45  */
46  smart_ptr_mesh m = AIFMesh::New();
47 
48  // add vertices
53 
54  // add edges
56  helpers::link_vertex_and_edge(v0, e0, helpers::vertex_pos::FIRST);
57  helpers::link_vertex_and_edge(v1, e0, helpers::vertex_pos::SECOND);
59  helpers::link_vertex_and_edge(v1, e1, helpers::vertex_pos::FIRST);
60  helpers::link_vertex_and_edge(v2, e1, helpers::vertex_pos::SECOND);
62  helpers::link_vertex_and_edge(v2, e2, helpers::vertex_pos::FIRST);
63  helpers::link_vertex_and_edge(v3, e2, helpers::vertex_pos::SECOND);
65  helpers::link_vertex_and_edge(v3, e3, helpers::vertex_pos::FIRST);
66  helpers::link_vertex_and_edge(v0, e3, helpers::vertex_pos::SECOND);
68  helpers::link_vertex_and_edge(v1, e4, helpers::vertex_pos::FIRST);
69  helpers::link_vertex_and_edge(v3, e4, helpers::vertex_pos::SECOND);
70 
71  // add faces
72  face_descriptor f0 = helpers::add_face(m);
76  face_descriptor f1 = helpers::add_face(m);
80 
81  // display mesh informations
82  std::cout << "Input mesh:\n";
83  m->Print();
84 
85  // define some halfedges
86  AIFHalfEdge h1(v0, v1, f0);
87  AIFHalfEdge h2(v1, v3, f0);
88  AIFHalfEdge h3(v1, v3, f1);
89 
90  try
91  {
92  AIFHalfEdge hbad(v0, v2, f0); // invalid halfedge, no edge between vertices
93  assert(false);
94  }
95  catch(const std::runtime_error &e)
96  {
97  assert(e.what() ==
98  std::string("In AIFHalfEdge::AIFHalfEdge(s, t, f): invalid "
99  "halfedge, no edge between the two vertices."));
100  }
101 
102  try
103  {
104  AIFHalfEdge hbad(v0, v1, f1); // invalid halfedge, v0v1 not incident to f1
105  assert(false);
106  }
107  catch(const std::runtime_error &e)
108  {
109  assert(e.what() ==
110  std::string("In AIFHalfEdge::AIFHalfEdge(s, t, f): invalid "
111  "halfedge, not incident to the face."));
112  }
113 
114  try
115  {
116  AIFHalfEdge hbad(v3, v2, f0); // invalid halfedge, v3v2 not incident to f0
117  assert(false);
118  }
119  catch(const std::runtime_error &e)
120  {
121  assert(e.what() ==
122  std::string("In AIFHalfEdge::AIFHalfEdge(s, t, f): invalid "
123  "halfedge, not incident to the face."));
124  }
125 
126  // test 1
127  AIFHalfEdge n;
128  n = next(h1, *m);
129  assert(n.get_source() == v1 && n.get_target() == v3);
130 
131  // test 2
132  n = next(h2, *m);
133  assert(n.get_source() == v3 && n.get_target() == v0);
134 
135  // test 3
136  n = next(h3, *m);
137  assert(n.get_source() == v3 && n.get_target() == v2);
138 
139  std::cout << "Test passed.\n";
140  return 0; // all tests passed
141 }
helpers
AIFTopologyHelpers helpers
Definition: test_helpers_aif.cpp:16
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::DataStructures::AIF::AIFTopologyHelpers::add_face
static face_descriptor add_face(ptr_mesh mesh)
Definition: AIFTopologyHelpers.h:2887
FEVV::DataStructures::AIF::AIFTopologyHelpers::AIFHalfEdge
Definition: AIFTopologyHelpers.h:4748
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
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
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
Graph_traits_aif.h
main
int main(void)
Definition: test_halfedge_aif.cpp:21
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