MEPP2 Project
test_non_manifold_collapse_edge_aif.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.
14 
15 //#include "FEVV/Wrappings/Geometry_traits_aif.h"
17 //#include "FEVV/Wrappings/Graph_properties_aif.h"
18 
19 #include <fstream>
20 #include <iostream>
21 
25 // DBG #include "FEVV/Filters/Generic/print_points.hpp"
26 
27 using namespace FEVV;
28 using namespace FEVV::Operators;
29 
30 //------------------------------------------------------------------------------
31 
32 void
33 test_collapse_edge_aif(std::string filename,
34  int source_index,
35  int target_index,
36  const std::string &output_file_name)
37 {
40 
41  // Load a mesh
42  ptr_mesh pm;
43 
45  if(!(pm = in.read(filename)))
46  {
47  std::cout << "failed";
48  return;
49  }
50 
51  typedef boost::graph_traits< Mesh > GraphTraits;
52  typedef GraphTraits::edge_descriptor edge_descriptor;
53 
54  // DBG print_points(M, get(CGAL::vertex_point, *pm));
55 
56  edge_descriptor e = retrieve_edge(*pm, source_index, target_index);
57  if(e == GraphTraits::null_edge())
58  {
59  std::cout << "Failed to retrieve edge from " << source_index << " to "
60  << target_index << "." << std::endl;
61  std::cout << "Exiting";
62  exit(EXIT_FAILURE);
63  }
64 
65  std::cout << "Collapsing edge " << source_index << " to " << target_index
66  << "." << std::endl;
67 
69 
70  // DBG print_points(*pm, get(CGAL::vertex_point, M));
71 
73  try
74  {
75  out.write(pm, output_file_name);
76  }
77  catch(...)
78  {
79  std::cout << "writing failed" << std::endl;
80  return;
81  }
82 }
83 
84 //------------------------------------------------------------------------------
85 
86 int
87 main(int narg, char **argv)
88 {
89  if(narg < 3 || narg > 5)
90  {
91  std::cout << "Usage: " << argv[0]
92  << " filename int [filenameresult [filenameexpectedresult]]; int "
93  "is either 0, 1, 2 or 3."
94  << std::endl;
95  exit(EXIT_FAILURE);
96  }
97 
98  std::string to_treat = argv[1];
99 
100  int halfedge_case = std::stoi(std::string(argv[2]));
101  std::string output_file_name = std::string(argv[3]);
102 
103  if(halfedge_case == 0)
104  {
105  test_collapse_edge_aif(to_treat, 1, 2, output_file_name); // border halfedge
106  }
107  else if(halfedge_case == 1)
108  {
109  test_collapse_edge_aif(to_treat, 2, 1, output_file_name); // border halfedge
110  }
111  else if(halfedge_case == 2)
112  {
113  test_collapse_edge_aif(to_treat, 3, 4, output_file_name);
114  }
115  else if(halfedge_case == 3)
116  {
117  test_collapse_edge_aif(to_treat, 4, 3, output_file_name);
118  }
119  else if(halfedge_case == 4)
120  {
121  test_collapse_edge_aif(to_treat, 5, 7, output_file_name);
122  }
123  else if(halfedge_case == 5)
124  {
125  test_collapse_edge_aif(to_treat, 7, 5, output_file_name);
126  }
127  else if(halfedge_case == 6)
128  { // used for particular tests... (not for unit testing, but more for
129  // intensive local testing)
130 
131  // for tetra.off
132  test_collapse_edge_aif(to_treat, 0, 1, output_file_name);
133  test_collapse_edge_aif(to_treat, 1, 2, output_file_name);
134  test_collapse_edge_aif(to_treat, 0, 2, output_file_name);
135  test_collapse_edge_aif(to_treat, 2, 3, output_file_name);
136 
137  // for flip14.vtk:
138  // testCollapseEdgeAIF(toTreat, 0, 1, outputFileName);
139  // testCollapseEdgeAIF(toTreat, 1, 2, outputFileName);
140  // testCollapseEdgeAIF(toTreat, 2, 3, outputFileName);
141  // testCollapseEdgeAIF(toTreat, 3, 4, outputFileName);
142  // testCollapseEdgeAIF(toTreat, 4, 3, outputFileName);
143 
144  // for bunny.vtk:
145  // testCollapseEdgeAIF(toTreat, 3058, 4830, outputFileName);
146  // testCollapseEdgeAIF(toTreat, 274, 3220, outputFileName);
147  // testCollapseEdgeAIF(toTreat, 3007, 4231, outputFileName);
148  // testCollapseEdgeAIF(toTreat, 4892, 2359, outputFileName);
149  // testCollapseEdgeAIF(toTreat, 530, 1282, outputFileName);
150  // testCollapseEdgeAIF(toTreat, 609, 3423, outputFileName);
151  // testCollapseEdgeAIF(toTreat, 4041, 33, outputFileName);
152  // testCollapseEdgeAIF(toTreat, 4710, 4707, outputFileName);
153  // testCollapseEdgeAIF(toTreat, 3867, 2009, outputFileName);
154  // testCollapseEdgeAIF(toTreat, 2009, 2021, outputFileName);
155  // testCollapseEdgeAIF(toTreat, 3897, 2826, outputFileName);
156  // testCollapseEdgeAIF(toTreat, 2826, 2638, outputFileName);
157  // testCollapseEdgeAIF(toTreat, 2638, 3119, outputFileName);
158  // testCollapseEdgeAIF(toTreat, 3119, 3897, outputFileName);
159  // testCollapseEdgeAIF(toTreat, 3557, 3681, outputFileName);
160  // testCollapseEdgeAIF(toTreat, 3681, 603, outputFileName);
161  }
162  else
163  {
164  return 1; // test failed
165  }
166 
167  if(narg == 5)
168  {
169  if(!are_meshes_equal(
170  output_file_name,
171  argv[4],
172  true)) // this test currently fails for case 0 [border edge, because
173  // this is not handled for the time being]
174  return 1; // test failed
175  }
176 
177  return 0; // test succeeded
178 }
collapse_edge.hpp
FEVV::DataStructures::AIF::AIFMeshWriter
This class represents an AIFMesh object writer. An AIFMeshWriter writes a mesh file (....
Definition: AIFMeshWriter.hpp:37
FEVV::DataStructures::AIF::AIFMeshReader::read
ptr_output read(const std::string &filePath)
Definition: AIFMeshReader.inl:50
GraphConcept::edge_descriptor
boost::graph_traits< G >::edge_descriptor edge_descriptor
Definition: test_boost_graph_concept_aif.cpp:23
retrieve_edge
boost::graph_traits< MutableFaceGraph >::edge_descriptor retrieve_edge(MutableFaceGraph &g, int source_index, int target_index)
Definition: utils_retrieve_edge.h:30
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::Operators::collapse_edge_keep_target
void collapse_edge_keep_target(MutableFaceIncidentGraph &g, typename boost::graph_traits< MutableFaceIncidentGraph >::edge_descriptor &e)
Collapse an edge of the graph. The edge to collapse is given as a non-oriented edge....
Definition: collapse_edge.hpp:180
FEVV::DataStructures::AIF::AIFMeshWriter::write
void write(const ptr_input inputMesh, const std::string &filePath)
Definition: AIFMeshWriter.inl:28
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
AIFMesh.hpp
FEVV::DataStructures::AIF::AIFMesh::ptr_mesh
boost::shared_ptr< Self > ptr_mesh
Definition: AIFMesh.hpp:51
main
int main(int narg, char **argv)
Definition: test_non_manifold_collapse_edge_aif.cpp:87
FEVV::Operators
Definition: collapse_edge.hpp:25
Graph_traits_aif.h
Mesh
FEVV::DataStructures::AIF::AIFMesh Mesh
Definition: test_complying_concepts_aif.cpp:18
test_collapse_edge_aif
void test_collapse_edge_aif(std::string filename, int source_index, int target_index, const std::string &output_file_name)
Definition: test_non_manifold_collapse_edge_aif.cpp:33
utils_are_meshes_identical.hpp
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
FEVV::DataStructures::AIF::AIFMeshReader
This class represents an AIFMesh object reader. An AIFMeshReader reads a mesh file (....
Definition: AIFMeshReader.hpp:37
AIFMeshReader.hpp
utils_retrieve_edge.h
AIFMeshWriter.hpp