MEPP2 Project
test_split_edge_euler_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/Cartesian.h>
12 #include <CGAL/Polyhedron_3.h>
13 #include <CGAL/Polyhedron_items_with_id_3.h>
14 
15 // Graph traits adaptors
16 #include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
17 #include "FEVV/Wrappings/Geometry_traits_cgal_polyhedron_3.h" // Geometry adaptor
19 
20 #define USE_GENERIC_READER_WRITER // when activated you need to link to vtk
21  // libs if VTK is used
22 #ifdef USE_GENERIC_READER_WRITER
26 #else
27 #include <CGAL/IO/Polyhedron_iostream.h>
28 #endif
29 
30 #include <fstream>
31 #include <string> // std::stoi
32 
36 
37 using namespace FEVV;
38 using namespace FEVV::Operators;
39 
40 void
41 test_split_edge_polyhedron(std::string input_file_path,
42  int source_index,
43  int target_index,
44  const std::string &output_file_name)
45 {
46  typedef CGAL::Cartesian< double > Kernel;
47  typedef CGAL::Polyhedron_3< Kernel, CGAL::Polyhedron_items_with_id_3 >
48  Polyhedron;
49 
50  typedef boost::graph_traits< Polyhedron > GraphTraits;
51  typedef typename GraphTraits::halfedge_descriptor halfedge_descriptor;
52 
53  //---------------------------------------------------------------------
54  // Load a mesh
55  Polyhedron p;
56 #ifdef USE_GENERIC_READER_WRITER
58  FEVV::Filters::read_mesh(input_file_path, p, pmaps);
59 #else
60  std::ifstream toTreat(inputFilePath);
61  if(!toTreat)
62  {
63  std::cout << "Unable to read file " << inputFilePath << std::endl;
64  exit(EXIT_FAILURE);
65  }
66  toTreat >> P;
67  toTreat.close();
68 #endif
69 
70  //---------------------------------------------------------------------
71  halfedge_descriptor h = retrieve_halfedge(p, source_index, target_index);
72  if(h == GraphTraits::null_halfedge())
73  {
74  std::cout << "Failed to retrieve edge from " << source_index << " to "
75  << target_index << "." << std::endl;
76  std::cout << "Exiting";
77  exit(EXIT_FAILURE);
78  }
79 
80  std::cout << "Splitting edge " << source_index << " to " << target_index
81  << "." << std::endl;
82  split_edge_euler(p, get(boost::vertex_point, p), h);
83 #ifdef USE_GENERIC_READER_WRITER
84  FEVV::Filters::write_mesh(output_file_name, p, pmaps);
85 #else
86  std::ofstream os(outputFileName);
87  os << P;
88  os.close();
89 #endif
90 }
91 
92 //------------------------------------------------------------------------------
94 int
95 main(int narg, char **argv)
96 {
97  if(narg < 3 || narg > 5)
98  {
99  /*
100  0 --------- 1 --------- 2
101  |\ / \ /|\
102  | \ / \ / | \
103  | \ / \ / | \
104  | \ / \ / | \
105  | \ / \ / | \
106  | 3 --------- 4 | 5
107  | / \ / \ | /
108  | / \ / \ | /
109  | / \ / \ | /
110  | / \ / \ | /
111  |/ \ / \|/
112  6 --------- 7 --------- 8
113  */
114 
115  std::cout << "Usage: a.out filename_a splitting_case filename_b filename_c";
116  std::cout << " - filename_a filename of file to be treated (off format)"
117  << std::endl;
118  std::cout << " - splitting_case case: integer specifying the edge to delete"
119  << std::endl;
120  std::cout << " 0 for edge 1 --> 2" << std::endl;
121  std::cout << " 1 for edge 2 --> 1" << std::endl;
122  std::cout << " 2 for edge 3 --> 4" << std::endl;
123  std::cout << " 3 for edge 4 --> 3" << std::endl;
124  std::cout
125  << " - filename_b optional reference off file of output mesh result."
126  << std::endl;
127  std::cout << " - filename_c optional reference off file of valid result."
128  << std::endl;
129 
130  exit(EXIT_FAILURE);
131  }
132 
133  int splitting_case = std::stoi(std::string(argv[2]));
134  std::string output_file_name = std::string(argv[3]);
135 
136  if(splitting_case == 0)
137  {
138  // Whatever comes first
139  test_split_edge_polyhedron(argv[1], 1, 2, output_file_name);
140  }
141  else if(splitting_case == 1)
142  {
143  test_split_edge_polyhedron(argv[1], 2, 1, output_file_name);
144  }
145  else if(splitting_case == 2)
146  {
147  test_split_edge_polyhedron(argv[1], 3, 4, output_file_name);
148  }
149  else if(splitting_case == 3)
150  {
151  test_split_edge_polyhedron(argv[1], 4, 3, output_file_name);
152  }
153  else
154  {
155  std::cout << "Unknown deletation case " << argv[2] << std::endl;
156  }
157 
158  if(narg == 5)
159  {
160  if(!are_meshes_equal(output_file_name, argv[4], false))
161  return 1; // test failed
162  }
163 
164  return 0;
165 }
retrieve_halfedge
boost::graph_traits< MutableFaceGraph >::halfedge_descriptor retrieve_halfedge(MutableFaceGraph &g, int source_index, int target_index)
Definition: utils_retrieve_halfedge.h:30
utils_retrieve_halfedge.h
Polyhedron
CGAL::Polyhedron_3< Kernel, CGAL::Polyhedron_items_with_id_3 > Polyhedron
Definition: test_complying_concepts_polyhedron.cpp:22
generic_reader.hpp
main
int main(int narg, char **argv)
[Snippet Ctest Example]
Definition: test_split_edge_euler_polyhedron.cpp:95
are_meshes_equal
bool are_meshes_equal(std::string filename_a, std::string filename_b, bool verbose)
Definition: utils_are_meshes_identical.inl:925
split_edge_euler.hpp
FEVV::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
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
properties_polyhedron_3.h
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Operators::split_edge_euler
void split_edge_euler(MutableFaceGraph &g, PointMap pm, typename boost::graph_traits< MutableFaceGraph >::halfedge_descriptor &h)
Split an edge of the graph. The edge to split is given as a halfedge.
Definition: split_edge_euler.hpp:44
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
FEVV::Operators
Definition: collapse_edge.hpp:25
Graph_traits_extension_cgal_polyhedron_3.h
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
generic_writer.hpp
utils_are_meshes_identical.hpp
outputFileName
const char * outputFileName
Definition: test_euler_add_center_vertex_polyhedron.cpp:27
test_split_edge_polyhedron
void test_split_edge_polyhedron(std::string input_file_path, int source_index, int target_index, const std::string &output_file_name)
Definition: test_split_edge_euler_polyhedron.cpp:41