MEPP2 Project
test_smoothing_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 <CGAL/Cartesian.h>
12 #include <CGAL/Polyhedron_3.h>
13 #include <CGAL/Polyhedron_items_with_id_3.h>
14 #include <CGAL/IO/Polyhedron_iostream.h>
15 
16 #include "FEVV/Wrappings/Geometry_traits_cgal_polyhedron_3.h" // Geometry adaptor
17 
18 //#define USE_GENERIC_READER_WRITER // when activated you need to link to vtk
19 //libs if VTK is used
20 #ifdef USE_GENERIC_READER_WRITER
21 #include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
22 
24 #include "FEVV/Wrappings/properties_cgal.h"
27 #endif
28 
30 
35 
36 #include <fstream>
37 #include <string>
38 
39 using namespace FEVV;
40 using namespace FEVV::Filters;
41 
42 void
43 test_smoothing_polyhedron(std::string filename)
44 {
45  typedef CGAL::Cartesian< double > Kernel;
46  typedef CGAL::Polyhedron_3< Kernel, CGAL::Polyhedron_items_with_id_3 > Mesh;
47 
48  typedef boost::graph_traits< Mesh > GraphTraits;
50  typedef typename GraphTraits::vertex_iterator vertex_iterator;
51 
52  typedef FEVV::Geometry_traits< Mesh > Geometry;
53  typedef Geometry::Point Point;
54  typedef boost::vector_property_map<
55  Point,
56  typename boost::property_map< Mesh, boost::vertex_index_t >::const_type >
57  BarycenterMap;
58  /**********************************************************************************************************/
59  Mesh m;
60 #ifdef USE_GENERIC_READER_WRITER
62  FEVV::Filters::read_mesh(filename, m, pmaps);
63 #else
64  std::ifstream in(filename);
65  if(!in)
66  {
67  std::cerr << "Unable to read file " << filename << std::endl;
68  exit(EXIT_FAILURE);
69  }
70  in >> m;
71 #endif
72  /**********************************************************************************************************/
73  vertex_iterator vb, ve;
74  int index = 0;
75  for(boost::tie(vb, ve) = boost::vertices(m); vb != ve; ++vb)
76  {
77  vertex_descriptor vd = *vb;
78  vd->id() = index++; // When using a Polyhedron with indices you need to
79  // initialize the indices manually
80  }
81  /**********************************************************************************************************/
82  auto pos_pm = get(boost::vertex_point, m);
83  /**********************************************************************************************************/
84  BarycenterMap barycenters_pm(get(boost::vertex_index, m));
86  m, pos_pm, barycenters_pm, 0.2f);
87  FEVV::Filters::reposition_vertices(m, pos_pm, barycenters_pm);
88 
90  m, pos_pm, barycenters_pm, 0.2f);
91  FEVV::Filters::reposition_vertices(m, pos_pm, barycenters_pm);
92 
94  m, pos_pm, barycenters_pm, 0.2f);
95  FEVV::Filters::reposition_vertices(m, pos_pm, barycenters_pm);
96  /**********************************************************************************************************/
97 #ifdef USE_GENERIC_READER_WRITER
98  FEVV::Filters::write_mesh("smoothed_poly_" +
101  m,
102  pmaps);
103 #else
104  std::ofstream smoothed_off("smoothed_poly_" +
107  smoothed_off << m;
108  smoothed_off.close();
109 #endif
110 
111  std::cout << "Done." << std::endl;
112 }
113 
114 int
115 main(int narg, char **argv)
116 {
117  if(narg < 2)
118  {
119  std::cout << "Usage: " << argv[0]
120  << " filename; filename being an off file." << std::endl;
121  exit(EXIT_FAILURE);
122  }
123 
124  test_smoothing_polyhedron(argv[1]);
125 
126  // system("pause");
127  return 0;
128 }
FEVV::DataStructures::AIF::vertices
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator > vertices(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the iterator range of the vertices of the mesh.
Definition: Graph_traits_aif.h:172
test_smoothing_polyhedron
void test_smoothing_polyhedron(std::string filename)
Definition: test_smoothing_polyhedron.cpp:43
FEVV::Filters::calculate_vertices_one_ring_geometric_laplacian
void calculate_vertices_one_ring_geometric_laplacian(const FaceGraph &g, const PointMap &pm, CentroidMap geom_laplacians_pm, const typename GeometryTraits::Scalar smoothing_factor, const GeometryTraits &gt)
Compute geometric laplacians for all vertices and store them in geom_laplacians_pm.
Definition: calculate_vertices_one_ring_geometric_laplacian.hpp:49
FEVV::Filters
Definition: clean_topology.hpp:21
calculate_vertices_one_ring_geometric_laplacian.hpp
generic_reader.hpp
main
int main(int narg, char **argv)
Definition: test_smoothing_polyhedron.cpp:115
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
FEVV::FileUtils::get_file_name
std::string get_file_name(const std::string &file_name)
Definition: FileUtilities.hpp:128
Kernel
CGAL::Cartesian< double > Kernel
Definition: test_complying_concepts_linear_cell_complex.cpp:22
Geometry_traits_cgal_polyhedron_3.h
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
calculate_vertices_one_ring_angles_based_centroid.hpp
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
Graph_traits_extension_cgal_polyhedron_3.h
FEVV::FileUtils::get_file_extension
std::string get_file_extension(const std::string &file_name)
Definition: FileUtilities.hpp:36
calculate_vertices_one_ring_barycenter.hpp
reposition_vertices.hpp
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
generic_writer.hpp
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
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
FEVV::Filters::calculate_vertices_one_ring_angles_based_centroid
void calculate_vertices_one_ring_angles_based_centroid(const FaceGraph &g, const PointMap &pm, CentroidMap angles_based_centroids_pm, const typename GeometryTraits::Scalar smoothing_factor, const GeometryTraits &gt)
Compute angle-based centroids for all vertices and store them in bangles_based_centroids_pm.
Definition: calculate_vertices_one_ring_angles_based_centroid.hpp:49
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
FileUtilities.hpp