MEPP2 Project
test_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 #include "FEVV/Wrappings/Geometry_traits_openmesh.h" // Always in first position for MVS 4996 warnings
12 
13 #include <fstream>
14 
17 
18 // OpenMesh
20 
21 using namespace FEVV;
22 using namespace FEVV::Filters;
23 
24 //------------------------------------------------------------------------------
25 void
26 test_open_mesh(char *filename)
27 {
28  typedef MeshOpenMesh Mesh;
29  typedef Mesh::Normal Vector;
30 
31  // 1) Load a mesh
32  std::ifstream in(filename);
33  Mesh m;
34  try
35  {
36  if(!OpenMesh::IO::read_mesh(m, filename))
37  {
38  std::cout << "failed";
39  return;
40  }
41  }
42  catch(const std::length_error &le)
43  {
44  std::cerr << "[OpenMesh] Exception catched while reading input file "
45  << filename << ": " << le.what() << std::endl;
46  BOOST_ASSERT_MSG(false,
47  "[OpenMesh] Exception catched while reading input file.");
48  }
49 
50  // 2) Add face normal property
51  typedef boost::property_map< Mesh, boost::face_index_t >::const_type
52  Face_index_map;
53  Face_index_map face_index_pm = get(boost::face_index, m);
54  boost::vector_property_map< Vector, Face_index_map > normals(face_index_pm);
55 
56  // 3) Compute normals
58  m, // Graph
59  get(boost::vertex_point, m), // map from vertex_descriptor to point
60  normals // map from face_descriptor to Vector_3
61  );
62 
63  // 4) Draw normals
64  print_face_normals(m, normals);
65 
66  std::cout << "Done." << std::endl;
67 }
68 
69 //------------------------------------------------------------------------------
70 int
71 main(int narg, char **argv)
72 {
73  if(narg < 2)
74  {
75  std::cout << "Usage: " << argv[0]
76  << " filename; filename being an off file." << std::endl;
77  exit(EXIT_FAILURE);
78  }
79 
80  test_open_mesh(argv[1]);
81  return 0;
82 }
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
FEVV::Filters
Definition: clean_topology.hpp:21
Geometry_traits_openmesh.h
main
int main(int narg, char **argv)
Definition: test_openmesh.cpp:71
FEVV::Filters::print_face_normals
void print_face_normals(const HalfedgeGraph &g, NormalMap nm)
Print all faces normals.
Definition: print_face_normals.hpp:28
calculate_face_normals.hpp
FEVV::get
FEVV::PCLPointCloudPointMap::value_type get(const FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key)
Specialization of get(point_map, key) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:117
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::Filters::calculate_face_normals
void calculate_face_normals(const HalfedgeGraph &g, const PointMap &pm, FaceNormalMap fnm, const GeometryTraits &gt)
Calculate "some" normal of all the faces of the considered mesh and populate the argument provided Fa...
Definition: calculate_face_normals.hpp:40
FEVV::DataStructures::AIF::AIFVector
Definition: AIFProperties.h:173
print_face_normals.hpp
Mesh
FEVV::DataStructures::AIF::AIFMesh Mesh
Definition: test_complying_concepts_aif.cpp:18
DataStructures_openmesh.h
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
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_open_mesh
void test_open_mesh(char *filename)
Definition: test_openmesh.cpp:26