MEPP2 Project
test_linear_cell_complex.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 <fstream>
12 
13 #include <CGAL/Cartesian.h>
14 
15 // Linear_cell_complex
16 #include <CGAL/Linear_cell_complex_for_combinatorial_map.h>
17 
18 #include <CGAL/boost/graph/graph_traits_Linear_cell_complex_for_combinatorial_map.h>
20 
21 #include <CGAL/Linear_cell_complex_incremental_builder.h>
22 
30 
31 using namespace FEVV;
32 using namespace FEVV::Filters;
33 
34 typedef CGAL::Cartesian< double > Kernel;
35 typedef Kernel::Point_3 Point;
36 typedef Kernel::Vector_3 Vector;
37 typedef CGAL::Linear_cell_complex_traits< 3, Kernel > MyTraits;
38 
39 struct Myitem
40 {
41  template< class Refs >
42  struct Dart_wrapper
43  {
44  typedef CGAL::Tag_true Darts_with_id;
45  typedef CGAL::Cell_attribute_with_point_and_id< Refs > Vertex_attribute;
46  typedef CGAL::Cell_attribute_with_id< Refs > Face_attribute;
47  typedef CGAL::cpp11::tuple< Vertex_attribute, void, Face_attribute >
49  };
50 };
51 
52 typedef CGAL::
53  Linear_cell_complex_for_combinatorial_map< 2, 3, MyTraits, Myitem >
54  LCC;
55 
56 //------------------------------------------------------------------------------
57 void
58 test_linear_cell_complex(char *filename)
59 {
60  // 1) Load a mesh
61  std::ifstream in(filename);
62  LCC lcc;
63  try
64  {
65  CGAL::read_off(in, lcc);
66  lcc.display_characteristics(std::cout);
67  }
68  catch(const std::length_error &le)
69  {
70  std::cerr << "[LCC] Exception caught while reading input file " << filename
71  << ": " << le.what() << std::endl;
72  BOOST_ASSERT_MSG(false, "[LCC] Exception caught while reading input file.");
73  }
74 
75  auto pos_pm = get(boost::vertex_point, lcc);
76 
77  // 2) Add face normal property
78  typedef boost::property_map< LCC, boost::face_index_t >::const_type
79  Face_index_map;
80  boost::vector_property_map< Vector, Face_index_map > normals(
81  get(boost::face_index, lcc));
82 
83  // 3) Compute normals
84  calculate_face_normals(lcc // Graph
85  ,
86  pos_pm // map from vertex_descriptor to point
87  ,
88  normals // map from face_descriptor to Vector_3
89  );
90 
91  // 4) Draw normals
92  print_face_normals(lcc, normals);
93 
94  // 5) Scale the mesh
95  calculate_scaling(lcc, pos_pm, 2.0, 3.0, 4.0);
96 
97  // 6) Smoothing
98  typedef FEVV::Geometry_traits< LCC > Geometry;
99  typedef Geometry::Point Point;
100  typedef boost::vector_property_map<
101  Point,
102  typename boost::property_map< LCC, boost::vertex_index_t >::const_type >
103  BarycenterMap;
104 
105  BarycenterMap barycenters_pm(get(boost::vertex_index, lcc));
107  lcc, pos_pm, barycenters_pm);
108  FEVV::Filters::reposition_vertices(lcc, pos_pm, barycenters_pm);
109 
110  // 7) Display the points
111  print_points(lcc, pos_pm);
112 
113  // 8) Collapse some edges
114  /*std::cout << "Start collapsing edges ..." << std::endl;
115  collapse_some_edges(lcc);
116  std::ofstream collapse_some_edges_os("collapse_some_edges.off");
117  collapse_some_edges_os << M;*/
118 
119 
120  std::cout << "Done." << std::endl;
121 }
122 
123 //------------------------------------------------------------------------------
124 int
125 main(int narg, char **argv)
126 {
127  if(narg < 2)
128  {
129  std::cout << "Usage: test-linear-cell-complex filename;"
130  " filename being an off file."
131  << std::endl;
132  exit(EXIT_FAILURE);
133  }
134 
135  test_linear_cell_complex(argv[1]);
136  return EXIT_SUCCESS;
137 }
Point
Kernel::Point_3 Point
Definition: test_linear_cell_complex.cpp:35
Kernel
CGAL::Cartesian< double > Kernel
Definition: test_linear_cell_complex.cpp:34
FEVV::Filters
Definition: clean_topology.hpp:21
Myitem
Definition: test_complying_concepts_linear_cell_complex.cpp:26
FEVV::Filters::print_points
void print_points(const HalfedgeGraph &g, PointMap pm)
Print all vertices coordinates.
Definition: print_points.hpp:28
Vector
Kernel::Vector_3 Vector
Definition: test_linear_cell_complex.cpp:36
collapse_edge.hpp
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
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
LCC
CGAL::Linear_cell_complex_for_combinatorial_map< 2, 3, MyTraits, Myitem > LCC
Definition: test_linear_cell_complex.cpp:54
Myitem::Dart_wrapper::Face_attribute
CGAL::Cell_attribute_with_id< Refs > Face_attribute
Definition: test_linear_cell_complex.cpp:46
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
FEVV::Filters::reposition_vertices
void reposition_vertices(const PropertyGraph &g, PointMap pm, const NewPointMap &smoothed_pm, const GeometryTraits &)
Apply new vertex positions to vertex position property map.
Definition: reposition_vertices.hpp:44
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
test_linear_cell_complex
void test_linear_cell_complex(char *filename)
Definition: test_linear_cell_complex.cpp:58
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
Myitem::Dart_wrapper::Vertex_attribute
CGAL::Cell_attribute_with_point_and_id< Refs > Vertex_attribute
Definition: test_linear_cell_complex.cpp:45
calculate_vertices_one_ring_barycenter.hpp
Myitem::Dart_wrapper::Darts_with_id
CGAL::Tag_true Darts_with_id
Definition: test_linear_cell_complex.cpp:44
reposition_vertices.hpp
MyTraits
CGAL::Linear_cell_complex_traits< 3, Kernel > MyTraits
Definition: test_linear_cell_complex.cpp:37
Myitem::Dart_wrapper::Attributes
CGAL::cpp11::tuple< Vertex_attribute, void, Face_attribute > Attributes
Definition: test_linear_cell_complex.cpp:48
main
int main(int narg, char **argv)
Definition: test_linear_cell_complex.cpp:125
FEVV::Filters::calculate_vertices_one_ring_barycenter
void calculate_vertices_one_ring_barycenter(const FaceGraph &g, const PointMap &pm, CentroidMap barycenters_pm, const typename GeometryTraits::Scalar smoothing_factor, const GeometryTraits &gt)
Compute barycenters for all vertices and store them in barycenters_pm.
Definition: calculate_vertices_one_ring_barycenter.hpp:47
Geometry_traits_cgal_linear_cell_complex.h