MEPP2 Project
test_flip_edge_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 << "Flipping edge " << source_index << " to " << target_index << "."
81  << std::endl;
82  flip_edge(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  std::cout << "Usage: a.out filename_a splitting_case filename_b filename_c";
100  std::cout << " - filename_a filename of file to be treated (off format)"
101  << std::endl;
102  std::cout << " - splitting_case case: integer specifying the edge to delete"
103  << std::endl;
104  std::cout << " 0 for edge 1 --> 2" << std::endl;
105  std::cout << " 1 for edge 2 --> 1" << std::endl;
106  std::cout << " 2 for edge 3 --> 4" << std::endl;
107  std::cout << " 3 for edge 4 --> 3" << std::endl;
108  std::cout
109  << " - filename_b optional reference off file of output mesh result."
110  << std::endl;
111  std::cout << " - filename_c optional reference off file of valid result."
112  << std::endl;
113 
114  exit(EXIT_FAILURE);
115  }
116 
117  int splitting_case = std::stoi(std::string(argv[2]));
118  std::string output_file_name = std::string(argv[3]);
119 
120  if(splitting_case == 0)
121  {
122  // Whatever comes first
123  test_split_edge_polyhedron(argv[1], 1, 2, output_file_name);
124  }
125  else if(splitting_case == 1)
126  {
127  test_split_edge_polyhedron(argv[1], 2, 1, output_file_name);
128  }
129  else if(splitting_case == 2)
130  {
131  test_split_edge_polyhedron(argv[1], 3, 4, output_file_name);
132  }
133  else if(splitting_case == 3)
134  {
135  test_split_edge_polyhedron(argv[1], 4, 3, output_file_name);
136  }
137  else
138  {
139  std::cout << "Unknown deletation case " << argv[2] << std::endl;
140  }
141 
142  if(narg == 5)
143  {
144  if(!are_meshes_equal(output_file_name, argv[4], false))
145  return 1; // test failed
146  }
147 
148  return 0;
149 }
flip_edge.hpp
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
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_flip_edge_polyhedron.cpp:41
Polyhedron
CGAL::Polyhedron_3< Kernel, CGAL::Polyhedron_items_with_id_3 > Polyhedron
Definition: test_complying_concepts_polyhedron.cpp:22
generic_reader.hpp
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::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
properties_polyhedron_3.h
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
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
main
int main(int narg, char **argv)
[Snippet Ctest Example]
Definition: test_flip_edge_polyhedron.cpp:95
FEVV::Operators::flip_edge
void flip_edge(MutableFaceGraph &g, typename boost::graph_traits< MutableFaceGraph >::halfedge_descriptor &h)
Flip an edge of the graph. The edge to flip is given as a halfedge.
Definition: flip_edge.hpp:42