MEPP2 Project
test_surface_mesh.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 <fstream>
12 
13 // Surface mesh
14 #include <CGAL/Surface_mesh.h>
15 #include <CGAL/Cartesian.h>
16 
17 // Graph traits adaptors
18 #include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
19 
21 
27 
28 using namespace FEVV;
29 using namespace FEVV::Filters;
30 
31 //------------------------------------------------------------------------------
32 void
33 test_surface_mesh(char *filename)
34 {
35  typedef CGAL::Cartesian< double > Kernel;
36  typedef Kernel::Point_3 Point;
37  typedef Kernel::Vector_3 Vector;
38  typedef CGAL::Surface_mesh< Point > Mesh;
39 
40  // 1) Load a mesh
41  std::ifstream in(filename);
42  Mesh m;
43  try
44  {
45  in >> m;
46  }
47  catch(const std::length_error &le)
48  {
49  std::cerr << "[SurfaceMesh] Exception caught while reading input file "
50  << filename << ": " << le.what() << std::endl;
51  BOOST_ASSERT_MSG(
52  false, "[SurfaceMesh] Exception caught while reading input file.");
53  }
54 
55  auto pos_pm = get(CGAL::vertex_point, m);
56 
57  // 2) Add face normal property
58  Mesh::Property_map< Mesh::Face_index, Vector > normals;
59  normals = m.add_property_map< Mesh::Face_index, Vector >("f:Normal").first;
60 
61  // 3) Compute normals
62  calculate_face_normals(m // Graph
63  ,
64  pos_pm // map from vertex_descriptor to point
65  ,
66  normals // map from face_descriptor to Vector_3
67  );
68 
69  // 4) Draw normals
70  print_face_normals(m, normals);
71 
72  // 5) Scale the mesh
73  calculate_scaling(m, pos_pm, 2.0, 3.0, 4.0);
74 
75  // 6) Display the points
76  print_points(m, pos_pm);
77 
78  // 7) Collapse some edges
79  /*std::cout << "Start collapsing edges ..." << std::endl;
80  collapse_some_edges(M);
81  std::ofstream collapse_some_edges_os("collapse_some_edges.off");
82  collapse_some_edges_os << M;*/
83 
84  std::cout << "Done." << std::endl;
85 }
86 
87 //------------------------------------------------------------------------------
88 int
89 main(int narg, char **argv)
90 {
91  if(narg < 2)
92  {
93  std::cout
94  << "Usage: test-surface-mesh filename; filename being an off file."
95  << std::endl;
96  exit(EXIT_FAILURE);
97  }
98 
99  test_surface_mesh(argv[1]);
100  return 0;
101 }
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
FEVV::Filters
Definition: clean_topology.hpp:21
main
int main(int narg, char **argv)
Definition: test_surface_mesh.cpp:89
FEVV::Filters::print_points
void print_points(const HalfedgeGraph &g, PointMap pm)
Print all vertices coordinates.
Definition: print_points.hpp:28
collapse_edge.hpp
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
Geometry_traits_cgal_surface_mesh.h
print_points.hpp
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
Kernel
CGAL::Cartesian< double > Kernel
Definition: test_complying_concepts_linear_cell_complex.cpp:22
FEVV::Filters::calculate_scaling
void calculate_scaling(Graph &g, PointMap &pm, typename GeometryTraits::Scalar scale_x, typename GeometryTraits::Scalar scale_y, typename GeometryTraits::Scalar scale_z, const GeometryTraits &gt)
Scale a mesh.
Definition: scaling.hpp:38
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
test_surface_mesh
void test_surface_mesh(char *filename)
Definition: test_surface_mesh.cpp:33
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
scaling.hpp
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
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