MEPP2 Project
test_collapse_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/basic.h>
12 #include <CGAL/Kernel/global_functions.h>
13 #include <CGAL/Cartesian.h>
14 #include <CGAL/Polyhedron_3.h>
15 #include <CGAL/IO/Polyhedron_iostream.h>
16 #include <CGAL/Polyhedron_items_with_id_3.h>
17 
18 #include <CGAL/boost/graph/graph_traits_Polyhedron_3.h> // CGAL Graph traits wrapper
19 
20 #include <fstream>
21 #include <string> // std::stoi
22 
26 // DBG #include "FEVV/Filters/print_points.h"
27 
28 using namespace FEVV;
29 using namespace FEVV::Operators;
30 
31 /*
32  * \brief Tests the \link collapse_edge_keep_target test \endlink
33  * \param sourceIndex The index (position) of the source vertex of the edge
34  * that is seeked for deletion.
35  * \param targetIndex The index (position) of the destination vertex of the
36  * edge that is seeked for deletion.
37  */
38 void
40  int source_index,
41  int target_index,
42  const std::string &output_file_name)
43 {
44  typedef CGAL::Cartesian< double > Kernel;
45  typedef CGAL::Polyhedron_3< Kernel, CGAL::Polyhedron_items_with_id_3 >
46  Polyhedron;
47 
48  // Load a mesh
49  Polyhedron p;
50  in >> p;
51 
52  typedef boost::graph_traits< Polyhedron > GraphTraits;
53  typedef typename GraphTraits::halfedge_descriptor halfedge_descriptor;
54 
55  halfedge_descriptor h = retrieve_halfedge(p, source_index, target_index);
56  if(h == GraphTraits::null_halfedge())
57  {
58  std::cout << "Failed to retrieve edge from " << source_index << " to "
59  << target_index << "." << std::endl;
60  std::cout << "Exiting";
61  exit(EXIT_FAILURE);
62  }
63 
64  std::cout << "Collapsing edge " << source_index << " to " << target_index
65  << "." << std::endl;
66  // DBG FEVV::Filters::print_points(p, get(CGAL::vertex_point, p));
68  // DBG FEVV::Filters::print_points(p, get(CGAL::vertex_point, p));
69 
70  std::ofstream os(output_file_name);
71  os << p;
72 }
73 
74 //------------------------------------------------------------------------------
75 
76 int
77 main(int narg, char **argv)
78 {
79  if(narg < 3 || narg > 4)
80  {
81  /*
82  0 --------- 1 --------- 2
83  |\ / \ /|\
84  | \ / \ / | \
85  | \ / \ / | \
86  | \ / \ / | \
87  | \ / \ / | \
88  | 3 --------- 4 | 5
89  | / \ / \ | /
90  | / \ / \ | /
91  | / \ / \ | /
92  | / \ / \ | /
93  |/ \ / \|/
94  6 --------- 7 --------- 8
95  */
96 
97  std::cout << "Usage: a.out filename_a deletion_case filename_b";
98  std::cout << " - filename_a filename of file to be treated (off format)"
99  << std::endl;
100  std::cout << " - deletion case: integer specifying the edge to delete"
101  << std::endl;
102  std::cout << " 0 for unspecified edge" << std::endl;
103  std::cout << " 1 for edge 3 --> 4" << std::endl;
104  std::cout << " 2 for edge 4 --> 3" << std::endl;
105  std::cout << " 3 for edge 6 --> 3" << std::endl;
106  std::cout << " 4 for edge 6 --> 7" << std::endl;
107  std::cout << " - filename_b optional reference off file of valid result."
108  << std::endl;
109 
110  exit(EXIT_FAILURE);
111  }
112 
113 
114  std::ifstream to_treat(argv[1]);
115  if(!to_treat)
116  {
117  std::cout << "Unable to read file " << argv[1] << std::endl;
118  exit(EXIT_FAILURE);
119  }
120 
121  int deletion_case = std::stoi(std::string(argv[2]));
122  std::string output_file_name = std::string(argv[0]) + argv[2] + ".off";
123 
124  if(deletion_case == 0)
125  {
127  to_treat, 0, 1, output_file_name); // Whatever comes first
128  }
129  else if(deletion_case == 1)
130  {
131  test_collapse_edge_polyhedron(to_treat, 3, 4, output_file_name);
132  }
133  else if(deletion_case == 2)
134  {
135  test_collapse_edge_polyhedron(to_treat, 4, 3, output_file_name);
136  }
137  else if(deletion_case == 3)
138  {
139  test_collapse_edge_polyhedron(to_treat, 6, 3, output_file_name);
140  }
141  else if(deletion_case == 4)
142  {
143  test_collapse_edge_polyhedron(to_treat, 6, 7, output_file_name);
144  }
145  else
146  {
147  std::cout << "Unknown deletation case " << argv[2] << std::endl;
148  }
149 
150  to_treat.close();
151 
152  if(narg == 4)
153  {
154  if(!are_meshes_equal(output_file_name, argv[3], false))
155  return 1; // test failed
156  }
157 
158  return 0;
159 }
FEVV::Operators::collapse_edge_keep_target_euler
void collapse_edge_keep_target_euler(MutableFaceGraph &g, typename boost::graph_traits< MutableFaceGraph >::halfedge_descriptor &h)
Collapse an edge of the graph. The edge to collapse is given as a halfedge. The halfedge target verte...
Definition: collapse_edge_euler.hpp:67
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
main
int main(int narg, char **argv)
Definition: test_collapse_edge_polyhedron.cpp:77
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
test_collapse_edge_polyhedron
void test_collapse_edge_polyhedron(std::ifstream &in, int source_index, int target_index, const std::string &output_file_name)
Definition: test_collapse_edge_polyhedron.cpp:39
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::Operators
Definition: collapse_edge.hpp:25
utils_are_meshes_identical.hpp
collapse_edge_euler.hpp