MEPP2 Project
test_collapse_edge_euler_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::Filters;
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  halfedge_descriptor h = retrieve_halfedge(m, source_index, target_index);
57 
58  if(h == GraphTraits::null_halfedge())
59  {
60  std::cout << "Failed to retrieve edge from " << source_index << " to "
61  << target_index << "." << std::endl;
62  std::cout << "Exiting";
63  exit(EXIT_FAILURE);
64  }
65 
66  std::cout << "Collapsing edge " << source_index << " to " << target_index
67  << "." << std::endl;
68  // DBG FEVV::Filters::print_points(m, get(CGAL::vertex_point, m));
70  // DBG FEVV::Filters::print_points(m, get(CGAL::vertex_point, m));
71 
72  // Write result to file
73  m.garbage_collection();
74  // Required for the geometry to be cleaned before
75  // writing to file ; maybe this is a bug in OpenMesh
76  OpenMesh::IO::write_mesh(m, output_file_name);
77 }
78 
79 //------------------------------------------------------------------------------
80 
81 int
82 main(int narg, char **argv)
83 {
84  if(narg < 3 || narg > 4)
86  {
87  std::cout << "Usage: a.out filename; filename being an off file."
88  << std::endl;
89  exit(EXIT_FAILURE);
90  }
91 
92  std::string to_treat = argv[1];
93 
94  int deletion_case = std::stoi(std::string(argv[2]));
95  std::string output_file_name = std::string(argv[0]) + argv[2] + ".off";
96 
97  if(deletion_case == 0)
98  {
100  to_treat, 0, 1, output_file_name); // Whatever comes first
101  }
102  else if(deletion_case == 1)
103  {
104  test_collapse_edge_open_mesh(to_treat, 3, 4, output_file_name);
105  }
106  else if(deletion_case == 2)
107  {
108  test_collapse_edge_open_mesh(to_treat, 4, 3, output_file_name);
109  }
110 
111  if(narg == 4)
112  {
113  if(!are_meshes_equal(output_file_name, argv[3], false))
114  return 1; // test failed
115  }
116 
117  return 0; // test succeeded
118 }
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
are_meshes_equal
bool are_meshes_equal(std::string filename_a, std::string filename_b, bool verbose)
Definition: utils_are_meshes_identical.inl:925
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_euler_openmesh.cpp:36
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
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
collapse_edge_euler.hpp
main
int main(int narg, char **argv)
Definition: test_collapse_edge_euler_openmesh.cpp:82