MEPP2 Project
test_euler_add_center_vertex_polyhedron.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 General Public License as published
6 // by the Free Software Foundation; either version 3 of the License,
7 // 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 #include <CGAL/Polyhedron_3.h>
12 #include <CGAL/Polyhedron_items_with_id_3.h>
13 #include <CGAL/IO/Polyhedron_iostream.h>
14 #include <CGAL/Cartesian.h>
15 #include <CGAL/boost/graph/Euler_operations.h>
16 
19 
20 #include <fstream>
21 #include <iostream>
22 
23 using namespace FEVV;
24 
25 //------------------------------------------------------------------------------
26 
27 const char *outputFileName = "add_center_vertex_polyhedron_output.off";
28 
29 //------------------------------------------------------------------------------
30 
31 void
33 {
34  typedef CGAL::Cartesian< double > Kernel;
35  typedef CGAL::Polyhedron_3< Kernel, CGAL::Polyhedron_items_with_id_3 > Mesh;
36 
37  // load mesh
38 
39  std::ifstream in(filename);
40  Mesh m;
41  in >> m;
42 
43  // divise the first face, change topology only
44 
45  typedef boost::graph_traits< Mesh > GraphTraits;
46  typedef typename GraphTraits::halfedge_descriptor halfedge_descriptor;
47  typedef typename GraphTraits::face_descriptor face_descriptor;
48 
49  face_descriptor f = *(faces(m).begin());
50  halfedge_descriptor h = halfedge(f, m);
51  if(h == GraphTraits::null_halfedge())
52  {
53  std::cout << "Failed to retrieve the first face halfedge. Exiting."
54  << std::endl;
55  exit(EXIT_FAILURE);
56  }
57 
58  std::cout << "Adding center vertex..." << std::endl;
59  halfedge_descriptor hnew = CGAL::Euler::add_center_vertex(h, m);
60 
61  // fix geometry
62 
64  vertex_descriptor vnew = target(hnew, m);
65 
66  typedef FEVV::Geometry_traits< Mesh > Geometry;
67  typedef Geometry::Point Point;
68  put(get(boost::vertex_point, m), vnew, Point(4.0f, 3.0f, 0.0f));
69 
70  // Write result to file
71 
72  std::ofstream out(outputFileName);
73  out << m;
74 }
75 
76 //------------------------------------------------------------------------------
77 
78 int
79 main(int narg, char **argv)
80 {
81  if(narg < 2)
82  {
83  std::cout << "Usage: " << argv[0] << " mesh_file [reference_result_file]"
84  << std::endl;
85  std::cout << "Example: " << argv[0] << " airplane.off" << std::endl;
86  exit(EXIT_FAILURE);
87  }
88 
89  // run test
91 
92  // compare with reference result
93  if(narg == 3)
94  {
95  if(!are_meshes_equal(outputFileName, argv[2], false))
96  return 1; // test failed
97  }
98 
99  return 0;
100 }
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
are_meshes_equal
bool are_meshes_equal(std::string filename_a, std::string filename_b, bool verbose)
Definition: utils_are_meshes_identical.inl:925
Kernel
CGAL::Cartesian< double > Kernel
Definition: test_complying_concepts_linear_cell_complex.cpp:22
Geometry_traits_cgal_polyhedron_3.h
FEVV::get
FEVV::PCLPointCloudPointMap::value_type get(const FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key)
Specialization of get(point_map, key) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:117
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
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::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
Mesh
FEVV::DataStructures::AIF::AIFMesh Mesh
Definition: test_complying_concepts_aif.cpp:18
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
utils_are_meshes_identical.hpp
FEVV::put
void put(FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key, const FEVV::PCLPointCloudPointMap::value_type &value)
Specialization of put(point_map, key, value) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:126
outputFileName
const char * outputFileName
Definition: test_euler_add_center_vertex_polyhedron.cpp:27
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
main
int main(int narg, char **argv)
Definition: test_euler_add_center_vertex_polyhedron.cpp:79
test_euler_add_center_vertex_polyhedron
void test_euler_add_center_vertex_polyhedron(std::string filename)
Definition: test_euler_add_center_vertex_polyhedron.cpp:32