MEPP2 Project
test_polyhedron.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 #include <CGAL/Cartesian.h>
13 #include <CGAL/Polyhedron_3.h>
14 #include <CGAL/Polyhedron_items_with_id_3.h>
15 #include <CGAL/IO/Polyhedron_iostream.h>
16 
17 #include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
18 
20 
27 
28 using namespace FEVV;
29 using namespace FEVV::Filters;
30 
31 //------------------------------------------------------------------------------
32 void
33 test_polyhedron(char *filename)
34 {
35  typedef CGAL::Cartesian< double > Kernel;
36  typedef Kernel::Vector_3 Vector;
37  typedef CGAL::Polyhedron_3< Kernel, CGAL::Polyhedron_items_with_id_3 >
38  Polyhedron;
39  typedef boost::property_map< Polyhedron, CGAL::face_index_t >::const_type
40  Face_index_map;
41 
42  // 1) Load a mesh
43  std::ifstream in(filename);
44  Polyhedron p;
45  try
46  {
47  in >> p;
48 
49  // initialize facet indices
50  std::size_t i = 0;
51  for(Polyhedron::Facet_iterator it = p.facets_begin(); it != p.facets_end();
52  ++it, ++i)
53  {
54  it->id() = i;
55  }
56  }
57  catch(const std::length_error &le)
58  {
59  std::cerr << "[Polyhedron] Exception caught while reading input file "
60  << filename << ": " << le.what() << std::endl;
61  BOOST_ASSERT_MSG(false,
62  "[Polyhedron] Exception caught while reading input file.");
63  }
64 
65  // 2) Add face normal property
66  // Ad hoc property_map to store normals. Face_index_map is used to
67  // map face_descriptors to a contiguous range of indices. See
68  // http://www.boost.org/libs/property_map/doc/vector_property_map.html
69  // for details.
70  boost::vector_property_map< Vector, Face_index_map > normals(
71  get(CGAL::face_index, p));
72 
73  auto pos_pm = get(CGAL::vertex_point, p);
74 
75  // 3) Compute normals
76  calculate_face_normals(p // Graph
77  ,
78  pos_pm // map from vertex_descriptor to point
79  ,
80  normals // map from face_descriptor to Vector_3
81  );
82 
83  // 4) Draw normals
84  print_face_normals(p, normals);
85 
86  // 5) Scale the mesh
87  calculate_scaling(p, pos_pm, 2.0, 3.0, 4.0);
88 
89  // 6) Display the points
90  print_points(p, pos_pm);
91 
92  // 7) Collapse some edges
93  /*std::cout << "Start collapsing edges ..." << std::endl;
94  collapse_some_edges(P);
95  std::ofstream collapse_some_edges_os("collapse_some_edges.off");
96  collapse_some_edges_os << P;*/
97 
98  // 8) Translate object
99  translate(p, pos_pm, 10, 5, 3);
100 
101  // End of test
102  std::cout << "Done." << std::endl;
103 }
104 
105 //------------------------------------------------------------------------------
106 int
107 main(int narg, char **argv)
108 {
109  if(narg < 2)
110  {
111  std::cout << "Usage: a.out filename; filename being an off file."
112  << std::endl;
113  exit(EXIT_FAILURE);
114  }
115 
116  test_polyhedron(argv[1]);
117  return 0;
118 }
FEVV::Filters::translate
void translate(const HalfedgeGraph &g, PointMap &pm, typename GeometryTraits::Scalar offset_x, typename GeometryTraits::Scalar offset_y, typename GeometryTraits::Scalar offset_z, const GeometryTraits &gt)
Translate a mesh.
Definition: translation.hpp:38
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
FEVV::Filters
Definition: clean_topology.hpp:21
test_polyhedron
void test_polyhedron(char *filename)
Definition: test_polyhedron.cpp:33
FEVV::Filters::print_points
void print_points(const HalfedgeGraph &g, PointMap pm)
Print all vertices coordinates.
Definition: print_points.hpp:28
Facet_iterator
EnrichedPolyhedron::Facet_iterator Facet_iterator
Definition: boolops_polyhedra.hpp:44
Polyhedron
CGAL::Polyhedron_3< Kernel, CGAL::Polyhedron_items_with_id_3 > Polyhedron
Definition: test_complying_concepts_polyhedron.cpp:22
collapse_edge.hpp
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
Geometry_traits_cgal_polyhedron_3.h
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
translation.hpp
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
print_face_normals.hpp
main
int main(int narg, char **argv)
Definition: test_polyhedron.cpp:107