MEPP2 Project
test_euler_add_center_vertex_openmesh.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.
11 #include "FEVV/Wrappings/Geometry_traits_openmesh.h" // Always in first position for MVS 4996 warnings
12 
13 #include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
14 #include <OpenMesh/Core/IO/MeshIO.hh>
15 
16 #include <CGAL/boost/graph/Euler_operations.h>
17 
18 // OpenMesh adaptors
19 #define CGAL_USE_OM_POINTS
20 #include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
21 #include <CGAL/boost/graph/properties_PolyMesh_ArrayKernelT.h>
22 
24 
25 #include <fstream>
26 #include <iostream>
27 
28 using namespace FEVV;
29 
30 //------------------------------------------------------------------------------
31 
32 const char *outputFileName = "add_center_vertex_openmesh_output.off";
33 
34 //------------------------------------------------------------------------------
35 
36 void
38 {
39  typedef OpenMesh::PolyMesh_ArrayKernelT<> Mesh;
40 
41  // load mesh
42 
43  Mesh m;
44  if(!OpenMesh::IO::read_mesh(m, filename))
45  {
46  std::cout << "failed to open file " << filename << "\n";
47  exit(EXIT_FAILURE);
48  }
49 
50  // divise the first face, change topology only
51 
52  typedef boost::graph_traits< Mesh > GraphTraits;
53  typedef typename GraphTraits::halfedge_descriptor halfedge_descriptor;
54  typedef typename GraphTraits::face_descriptor face_descriptor;
55 
56  face_descriptor f = *(faces(m).begin());
57  halfedge_descriptor h = halfedge(f, m);
58  if(h == GraphTraits::null_halfedge())
59  {
60  std::cout << "Failed to retrieve the first face halfedge. Exiting."
61  << std::endl;
62  exit(EXIT_FAILURE);
63  }
64 
65  std::cout << "Adding center vertex..." << std::endl;
66  halfedge_descriptor hnew = CGAL::Euler::add_center_vertex(h, m);
67 
68  // fix geometry
69 
71  vertex_descriptor vnew = target(hnew, m);
72 
73  typedef FEVV::Geometry_traits< Mesh > Geometry;
74  typedef Geometry::Point Point;
75  put(get(boost::vertex_point, m), vnew, Point(4.0f, 3.0f, 0.0f));
76 
77  // Write result to file
78 
79  m.garbage_collection();
80  // Required for the geometry to be cleaned before
81  // writing to file ; maybe this is a bug in OpenMesh
83 }
84 
85 //------------------------------------------------------------------------------
86 
87 int
88 main(int narg, char **argv)
89 {
90  if(narg < 2)
91  {
92  std::cout << "Usage: " << argv[0] << " mesh_file [reference_result_file]"
93  << std::endl;
94  std::cout << "Example: " << argv[0] << " airplane.off" << std::endl;
95  exit(EXIT_FAILURE);
96  }
97 
98  // run test
100 
101  // compare with reference result
102  if(narg == 3)
103  {
104  if(!are_meshes_equal(outputFileName, argv[2], false))
105  return 1; // test failed
106  }
107 
108  return 0;
109 }
Geometry_traits_openmesh.h
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
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
FEVV::Filters::read_mesh
void read_mesh(const std::string &filename, FEVV::CGALPointSet &g, PMapsContainer &pmaps, bool=false)
Load mesh from file.
Definition: cgal_point_set_reader.hpp:110
Mesh
FEVV::DataStructures::AIF::AIFMesh Mesh
Definition: test_complying_concepts_aif.cpp:18
FEVV::Filters::write_mesh
void write_mesh(const std::string &filename, FEVV::CGALPointSet &g, PMapsContainer &pmaps)
Write mesh to file.
Definition: cgal_point_set_writer.hpp:42
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
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_openmesh.cpp:88
outputFileName
const char * outputFileName
Definition: test_euler_add_center_vertex_openmesh.cpp:32
test_euler_add_center_vertex_open_mesh
void test_euler_add_center_vertex_open_mesh(std::string filename)
Definition: test_euler_add_center_vertex_openmesh.cpp:37