MEPP2 Project
test_collapse_edge_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 #if(_MSC_VER >= 1400)
12 #ifndef _SCL_SECURE_NO_WARNINGS
13 #define _SCL_SECURE_NO_WARNINGS
14 #endif
15 #endif
16 
17 #include <OpenMesh/Core/IO/MeshIO.hh>
18 // Graph traits adaptors
19 #define CGAL_USE_OM_POINTS
20 #include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
21 
22 #include <fstream>
23 #include <iostream>
24 
28 // DBG #include "FEVV/Filters/Generic/print_points.hpp"
29 
30 using namespace FEVV;
31 using namespace FEVV::Operators;
32 
33 //------------------------------------------------------------------------------
34 
35 void
36 test_collapse_edge_open_mesh(std::string filename,
37  int source_index,
38  int target_index,
39  const std::string &output_file_name)
40 {
41  typedef OpenMesh::PolyMesh_ArrayKernelT< /*MyTraits*/ > Mesh;
42 
43  // Load a mesh
44  std::ifstream in(filename);
45  Mesh m;
46  if(!OpenMesh::IO::read_mesh(m, filename))
47  {
48  std::cout << "failed to open file " << filename << "\n";
49  exit(EXIT_FAILURE);
50  }
51 
52  // Collapse the first edge
53  typedef boost::graph_traits< Mesh > GraphTraits;
54  typedef typename GraphTraits::halfedge_descriptor halfedge_descriptor;
55 
56  // DBG print_points(M, get(CGAL::vertex_point, M));
57 
58  halfedge_descriptor h = retrieve_halfedge(m, source_index, target_index);
59  if(h == GraphTraits::null_halfedge())
60  {
61  std::cout << "Failed to retrieve edge from " << source_index << " to "
62  << target_index << "." << std::endl;
63  std::cout << "Exiting";
64  exit(EXIT_FAILURE);
65  }
66 
67  std::cout << "Collapsing edge " << source_index << " to " << target_index
68  << "." << std::endl;
70 
71  // DBG print_points(M, get(CGAL::vertex_point, M));
72 
73  // Write result to file
74  m.garbage_collection();
75  // Required for the geometry to be cleaned before
76  // writing to file ; maybe this is a bug in OpenMesh
77  OpenMesh::IO::write_mesh(m, output_file_name);
78 }
79 
80 //------------------------------------------------------------------------------
81 
82 int
83 main(int narg, char **argv)
84 {
85  if(narg < 3 || narg > 4)
87  {
88  std::cout << "Usage: a.out filename; filename being an off file."
89  << std::endl;
90  exit(EXIT_FAILURE);
91  }
92 
93  std::string to_treat = argv[1];
94 
95  int deletion_case = std::stoi(std::string(argv[2]));
96  std::string output_file_name = std::string(argv[0]) + argv[2] + ".off";
97 
98  if(deletion_case == 0)
99  {
101  to_treat, 0, 1, output_file_name); // Whatever comes first
102  }
103  else if(deletion_case == 1)
104  {
105  test_collapse_edge_open_mesh(to_treat, 3, 4, output_file_name);
106  }
107  else if(deletion_case == 2)
108  {
109  test_collapse_edge_open_mesh(to_treat, 4, 3, output_file_name);
110  }
111 
112  if(narg == 4)
113  {
114  if(!are_meshes_equal(output_file_name, argv[3], false))
115  return 1; // test failed
116  }
117 
118  return 0; // test succeeded
119 }
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
collapse_edge.hpp
main
int main(int narg, char **argv)
Definition: test_collapse_edge_openmesh.cpp:83
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
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
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
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
test_collapse_edge_open_mesh
void test_collapse_edge_open_mesh(std::string filename, int source_index, int target_index, const std::string &output_file_name)
Definition: test_collapse_edge_openmesh.cpp:36