MEPP2 Project
test_smoothing_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 <OpenMesh/Core/IO/MeshIO.hh>
14 // Boost properties adaptor
15 #define CGAL_USE_OM_POINTS
16 #include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
17 #include <CGAL/boost/graph/properties_PolyMesh_ArrayKernelT.h>
18 
19 //#define USE_GENERIC_READER_WRITER // when activated you need to link to vtk
20 //libs if VTK is used
21 #ifdef USE_GENERIC_READER_WRITER
26 #endif
27 
29 
34 
35 #include <fstream>
36 
37 #define USE_OPENMESH_DOUBLE_TRAITS
38 #ifdef USE_OPENMESH_DOUBLE_TRAITS
39 struct MyTraitsDouble : public OpenMesh::DefaultTraits
40 {
41  typedef OpenMesh::Vec3d Point; // use double-values points
42  typedef OpenMesh::Vec3d Normal;
43 };
44 #endif
45 
46 using namespace FEVV;
47 using namespace FEVV::Filters;
48 
49 //------------------------------------------------------------------------------
50 void
51 test_smoothing_open_mesh(char *filename)
52 {
53  typedef OpenMesh::PolyMesh_ArrayKernelT<
54 #ifdef USE_OPENMESH_DOUBLE_TRAITS
56 #endif
57  >
58  Mesh;
59  typedef FEVV::Geometry_traits< Mesh > Geometry;
60  typedef Geometry::Point Point;
61  typedef boost::vector_property_map<
62  Point,
63  typename boost::property_map< Mesh, boost::vertex_index_t >::const_type >
64  BarycenterMap;
65  /**********************************************************************************************************/
66  Mesh m;
67 #ifdef USE_GENERIC_READER_WRITER
69  FEVV::Filters::read_mesh(filename, m, pmaps);
70 #else
71  std::ifstream in(filename);
72  if(!OpenMesh::IO::read_mesh(m, filename))
73  {
74  std::cout << "reading failed";
75  return;
76  }
77 #endif
78  /**********************************************************************************************************/
79  auto pos_pm = get(boost::vertex_point, m);
80  /**********************************************************************************************************/
81  BarycenterMap barycenters_pm(get(boost::vertex_index, m));
82  const auto pos_pm_const = get(boost::vertex_point, m);
84  m, pos_pm_const, barycenters_pm, 0.2f);
85  FEVV::Filters::reposition_vertices(m, pos_pm, barycenters_pm);
86 
88  m, pos_pm, barycenters_pm, 0.2f);
89  FEVV::Filters::reposition_vertices(m, pos_pm, barycenters_pm);
90 
92  m, pos_pm, barycenters_pm, 0.2f);
93  FEVV::Filters::reposition_vertices(m, pos_pm, barycenters_pm);
94  /**********************************************************************************************************/
95 #ifdef USE_GENERIC_READER_WRITER
96  FEVV::Filters::write_mesh("smoothed_om_" +
99  m,
100  pmaps);
101 #else
103  m,
104  "smoothed_om_" + FEVV::FileUtils::get_file_name(filename) +
106  {
107  std::cout << "writing failed";
108  return;
109  }
110 #endif
111  std::cout << "Done." << std::endl;
112 }
113 
114 //------------------------------------------------------------------------------
115 int
116 main(int narg, char **argv)
117 {
118  if(narg < 2)
119  {
120  std::cout << "Usage: " << argv[0]
121  << " filename; filename being an off file." << std::endl;
122  exit(EXIT_FAILURE);
123  }
124 
125  test_smoothing_open_mesh(argv[1]);
126  return 0;
127 }
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
Geometry_traits_openmesh.h
calculate_vertices_one_ring_geometric_laplacian.hpp
generic_reader.hpp
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
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
MyTraitsDouble::Point
OpenMesh::Vec3d Point
Definition: test_smoothing_openmesh.cpp:41
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
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
Graph_traits_extension_openmesh.h
properties_openmesh.h
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
MyTraitsDouble::Normal
OpenMesh::Vec3d Normal
Definition: test_smoothing_openmesh.cpp:42
main
int main(int narg, char **argv)
Definition: test_smoothing_openmesh.cpp:116
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_smoothing_open_mesh
void test_smoothing_open_mesh(char *filename)
Definition: test_smoothing_openmesh.cpp:51
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
MyTraitsDouble
Definition: test_curvature_filter_openmesh.cpp:31