MEPP2 Project
example_msdm2.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 
16 
17 //---------------------------------------------------------
18 // Main
19 //---------------------------------------------------------
20 
21 // Main: load a mesh, apply the filter, write the mesh
22 int
23 main(int narg, char **argv)
24 {
25  // input and output files
26  std::string input_original;
27  std::string input_degraded;
28 
29  std::string output_file_path = "msdm2.output.obj";
30 
31  if(narg == 3)
32  {
33  std::string reader = std::string(argv[1]);
34  input_original = reader;
35  std::string reader2 = std::string(argv[2]);
36  input_degraded = reader2;
37  }
38  else
39  {
40  std::cout << "Use of " << argv[0] << " is :\n";
41  std::cout << "\t" << argv[0]
42  << " path/to/original_mesh path/to/degraged_mesh" << std::endl;
43  std::cout << argv[0]
44  << " will compute the MSDM2 value between the degraded mesh and "
45  "the original.\n"
46  << std::endl;
47  return 1;
48  }
49 
50  // create LUT
51  FEVV::Filters::ColorMeshLUT lut_courbure_clust =
53 
54  // read mesh from file
55  FEVV::MeshSurface m_original;
56  FEVV::PMapsContainer pmaps_bag_original;
57  FEVV::Filters::read_mesh(input_original, m_original, pmaps_bag_original);
58 
59  FEVV::MeshSurface m_degraded;
60  FEVV::PMapsContainer pmaps_bag_degraded;
61  FEVV::Filters::read_mesh(input_degraded, m_degraded, pmaps_bag_degraded);
62 
63  auto pm_degrad = get(boost::vertex_point, m_degraded);
64  auto pm_original = get(boost::vertex_point, m_original);
65 
66  using FaceNormalMap =
68  FEVV::MeshSurface >::pmap_type;
69  FaceNormalMap fnm_degrad;
70  if(has_map(pmaps_bag_degraded, FEVV::face_normal))
71  {
72  std::cout << "use existing face-normal map for degraded mesh" << std::endl;
73  fnm_degrad =
74  get_property_map(FEVV::face_normal, m_degraded, pmaps_bag_degraded);
75  }
76  else
77  {
78  std::cout << "create face-normal map for degraded mesh" << std::endl;
79  fnm_degrad = make_property_map(FEVV::face_normal, m_degraded);
80  // store property map in property maps bag
82  FEVV::face_normal, m_degraded, pmaps_bag_degraded, fnm_degrad);
83  FEVV::Filters::calculate_face_normals(m_degraded, pm_degrad, fnm_degrad);
84  }
85 
86  FaceNormalMap fnm_original;
87  if(has_map(pmaps_bag_original, FEVV::face_normal))
88  {
89  std::cout << "use existing face-normal map for original mesh" << std::endl;
90  fnm_original =
91  get_property_map(FEVV::face_normal, m_original, pmaps_bag_original);
92  }
93  else
94  {
95  std::cout << "create face-normal map for original mesh" << std::endl;
96  fnm_original = make_property_map(FEVV::face_normal, m_original);
97  // store property map in property maps bag
99  FEVV::face_normal, m_original, pmaps_bag_original, fnm_original);
101  m_original, pm_original, fnm_original);
102  }
103 
104 
106  VertexMSDM2Map;
107  VertexMSDM2Map msdm2_pmap;
108 
109  if(FEVV::has_map(pmaps_bag_degraded, std::string("v:msdm2")))
110  {
111  msdm2_pmap =
112  boost::any_cast< VertexMSDM2Map >(pmaps_bag_degraded.at("v:msdm2"));
113  }
114  else
115  {
116  msdm2_pmap =
117  FEVV::make_vertex_property_map< FEVV::MeshSurface, double >(m_degraded);
118  pmaps_bag_degraded["v:msdm2"] = msdm2_pmap;
119  }
120 
121  int nb_levels = 3;
122  double msdm2;
123 
125  pm_degrad,
126  fnm_degrad,
127  pmaps_bag_degraded,
128  m_original,
129  pm_original,
130  fnm_original,
131  pmaps_bag_original,
132  nb_levels,
133  msdm2_pmap,
134  msdm2);
135 
136  std::cout << "Calculated MSDM2 : " << msdm2 << std::endl;
137 
138  using VertexColorMap =
140  FEVV::MeshSurface >::pmap_type;
141  VertexColorMap v_cm;
142  if(has_map(pmaps_bag_degraded, FEVV::vertex_color))
143  {
144  std::cout << "use existing vertex-color map" << std::endl;
145  v_cm = get_property_map(FEVV::vertex_color, m_degraded, pmaps_bag_degraded);
146  }
147  else
148  {
149  std::cout << "create vertex-color map" << std::endl;
150  v_cm = make_property_map(FEVV::vertex_color, m_degraded);
151  // store property map in property maps bag
152  put_property_map(FEVV::vertex_color, m_degraded, pmaps_bag_degraded, v_cm);
153  }
154 
155  double max_msdm2, min_msdm2;
156 
158  m_degraded, msdm2_pmap, min_msdm2, max_msdm2);
159 
161  m_degraded, msdm2_pmap, v_cm, min_msdm2, max_msdm2, lut_courbure_clust);
162 
163  FEVV::Filters::write_mesh(output_file_path, m_degraded, pmaps_bag_degraded);
164 
165  return 0;
166 }
msdm2
Definition: msdm2_surfacemesh.cpp:20
FEVV::put_property_map
void put_property_map(PropertyT p, const MeshT &, PMapsContainer &pmaps, const typename PMap_traits< PropertyT, MeshT >::pmap_type &pmap)
Definition: properties.h:664
FEVV::face_normal_t
face_normal_t
Definition: properties.h:77
FEVV::Filters::compute_min_max_vertices
void compute_min_max_vertices(const HalfedgeGraph &g, const PropertyMap &prop_map, MapType &min_metric, MapType &max_metric)
Compute min and max value of a numerical property map for the vertices of a mesh.
Definition: minmax_map.h:92
FEVV::get_property_map
PMap_traits< PropertyT, MeshT >::pmap_type get_property_map(PropertyT p, const MeshT &, const PMapsContainer &pmaps)
Definition: properties.h:646
minmax_map.h
FEVV::has_map
bool has_map(const PMapsContainer &pmaps, const std::string &map_name)
(refer to Property Maps API)
Definition: properties.h:103
color_mesh.h
FEVV::MeshSurface
CGAL::Surface_mesh< CGALPoint > MeshSurface
Definition: DataStructures_cgal_surface_mesh.h:23
calculate_face_normals.hpp
FEVV::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
FEVV::Filters::color_vertices_from_map
void color_vertices_from_map(const HalfedgeGraph &g, const PropertyMap &prop_map, ColorMap &color_pmap, const MapType min_metric, const MapType max_metric, const ColorMeshLUT &colors=make_LUT())
Fill the color map for the vertices of a mesh using a numerical property map.
Definition: color_mesh.h:211
FEVV::Filters::make_LUT
ColorMeshLUT make_LUT(bool color_in_0_255=true, unsigned int colors_nbr=256, float h1=240, float h2=0)
Create a RGB LUT based on an HSV range. Default range creates a blue-cyan-green-yellow-red gradient.
Definition: color_mesh.h:41
FEVV::vertex_color_t
vertex_color_t
Definition: properties.h:47
msdm2.h
FEVV::Filters::ColorMeshLUT
std::vector< float > ColorMeshLUT
Definition: color_mesh.h:25
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::vertex_color
@ vertex_color
Definition: properties.h:47
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::Vertex_pmap
typename Vertex_pmap_traits< MeshT, ValueT >::pmap_type Vertex_pmap
Definition: properties.h:607
FEVV::Filters::process_msdm2_multires
double process_msdm2_multires(const HalfedgeGraph &m_poly_degrad, const PointMap &pm_degrad, const FaceNormalMap &fnm_degrad, FEVV::PMapsContainer &pmaps_degrad, const GeometryTraits &gt_degrad, const HalfedgeGraph &m_poly_original, const PointMap &pm_original, const FaceNormalMap &fnm_original, FEVV::PMapsContainer &, const GeometryTraits &, const int nb_level, VertexMSDM2Map &msdm2_pmap, const double maxdim, double &msdm2_value)
Definition: msdm2.h:274
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
boost::get
boost::property_map< FEVV::DataStructures::AIF::AIFMesh, boost::vertex_index_t >::const_type get(const boost::vertex_index_t &, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the vertex index property map of the mesh.
Definition: Graph_properties_aif.h:108
main
int main(int narg, char **argv)
Definition: example_msdm2.cpp:23
FEVV::_PMap_traits
Definition: properties.h:376
FEVV::make_property_map
PMap_traits< PropertyT, MeshT >::pmap_type make_property_map(PropertyT, const MeshT &m)
Definition: properties.h:630
FEVV::face_normal
@ face_normal
Definition: properties.h:77