MEPP2 Project
test_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 #include <CGAL/Cartesian.h>
12 #include <CGAL/Surface_mesh.h>
13 #include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
14 
17 
22 
26 
30 
31 #include <iostream>
32 #include <string>
33 
34 
35 using CGALKernel = CGAL::Cartesian< double >;
36 using CGALPoint = CGALKernel::Point_3;
37 using MeshT = CGAL::Surface_mesh< CGALPoint >;
38 
39 
40 int
41 main(int argc, const char **argv)
42 {
43  if(argc != 5)
44  {
45  std::cout
46  << "Load 2 meshes from input files, compute their MSDM2, write it to "
47  "an output file, then compare the output file with a reference file."
48  << std::endl;
49  std::cout << "Usage: " << argv[0]
50  << " input_original_mesh_file input_deformed_mesh_file "
51  "output_mesh_file reference_mesh_file"
52  << std::endl;
53  std::cout << "Example: " << argv[0]
54  << " armadillo.obj armadillo_simplified.obj armadillo.out.obj "
55  "armadillo_output_reference.obj"
56  << std::endl;
57  return EXIT_FAILURE;
58  }
59 
60  std::string input_original_file_path = argv[1];
61  std::string input_deformed_file_path = argv[2];
62  std::string output_file_path = argv[3];
63  std::string reference_file_path = argv[4];
64 
65  //--------------------------------------------------
66 
67  // create LUT
68  FEVV::Filters::ColorMeshLUT lut_courbure_clust =
70 
71  // read mesh from file
72  FEVV::MeshSurface m_original;
73  FEVV::PMapsContainer pmaps_bag_original;
75  input_original_file_path, m_original, pmaps_bag_original);
76 
77  FEVV::MeshSurface m_degraded;
78  FEVV::PMapsContainer pmaps_bag_degraded;
80  input_deformed_file_path, m_degraded, pmaps_bag_degraded);
81 
82  auto pm_degrad = get(boost::vertex_point, m_degraded);
83  auto pm_original = get(boost::vertex_point, m_original);
84 
85  using FaceNormalMap =
87  FEVV::MeshSurface >::pmap_type;
88  FaceNormalMap fnm_degrad;
89  if(has_map(pmaps_bag_degraded, FEVV::face_normal))
90  {
91  std::cout << "use existing face-normal map for degraded mesh" << std::endl;
92  fnm_degrad =
93  get_property_map(FEVV::face_normal, m_degraded, pmaps_bag_degraded);
94  }
95  else
96  {
97  std::cout << "create face-normal map for degraded mesh" << std::endl;
98  fnm_degrad = make_property_map(FEVV::face_normal, m_degraded);
99  // store property map in property maps bag
101  FEVV::face_normal, m_degraded, pmaps_bag_degraded, fnm_degrad);
102  FEVV::Filters::calculate_face_normals(m_degraded, pm_degrad, fnm_degrad);
103  }
104 
105  FaceNormalMap fnm_original;
106  if(has_map(pmaps_bag_original, FEVV::face_normal))
107  {
108  std::cout << "use existing face-normal map for original mesh" << std::endl;
109  fnm_original =
110  get_property_map(FEVV::face_normal, m_original, pmaps_bag_original);
111  }
112  else
113  {
114  std::cout << "create face-normal map for original mesh" << std::endl;
115  fnm_original = make_property_map(FEVV::face_normal, m_original);
116  // store property map in property maps bag
118  FEVV::face_normal, m_original, pmaps_bag_original, fnm_original);
120  m_original, pm_original, fnm_original);
121  }
122 
123 
125  VertexMSDM2Map;
126  VertexMSDM2Map msdm2_pmap;
127 
128  if(FEVV::has_map(pmaps_bag_degraded, std::string("v:msdm2")))
129  {
130  msdm2_pmap =
131  boost::any_cast< VertexMSDM2Map >(pmaps_bag_degraded.at("v:msdm2"));
132  }
133  else
134  {
135  msdm2_pmap =
136  FEVV::make_vertex_property_map< FEVV::MeshSurface, double >(m_degraded);
137  pmaps_bag_degraded["v:msdm2"] = msdm2_pmap;
138  }
139 
140  int nb_levels = 3;
141  double msd_m2;
142 
144  pm_degrad,
145  fnm_degrad,
146  pmaps_bag_degraded,
147  m_original,
148  pm_original,
149  fnm_original,
150  pmaps_bag_original,
151  nb_levels,
152  msdm2_pmap,
153  msd_m2);
154 
155  std::cout << "Calculated MSDM2 : " << msd_m2 << std::endl;
156 
157  using VertexColorMap =
159  FEVV::MeshSurface >::pmap_type;
160  VertexColorMap v_cm;
161  if(has_map(pmaps_bag_degraded, FEVV::vertex_color))
162  {
163  std::cout << "use existing vertex-color map" << std::endl;
164  v_cm = get_property_map(FEVV::vertex_color, m_degraded, pmaps_bag_degraded);
165  }
166  else
167  {
168  std::cout << "create vertex-color map" << std::endl;
169  v_cm = make_property_map(FEVV::vertex_color, m_degraded);
170  // store property map in property maps bag
171  put_property_map(FEVV::vertex_color, m_degraded, pmaps_bag_degraded, v_cm);
172  }
173 
174  double max_msd_m2, min_msd_m2;
175 
177  m_degraded, msdm2_pmap, min_msd_m2, max_msd_m2);
178 
180  m_degraded, msdm2_pmap, v_cm, min_msd_m2, max_msd_m2, lut_courbure_clust);
181 
182  FEVV::Filters::write_mesh(output_file_path, m_degraded, pmaps_bag_degraded);
183 
184  // check output file
185  std::cout << "Comparing output file '" << output_file_path
186  << "' with reference file '" << reference_file_path << "'..."
187  << std::endl;
188 
189  if(FEVV::FileUtils::has_extension(output_file_path, ".off") ||
190  FEVV::FileUtils::has_extension(output_file_path, ".coff"))
191  {
192  // use OFF file comparator
193  if(!are_meshes_equal(output_file_path, reference_file_path, false))
194  {
195  std::cout << "Files are different!" << std::endl;
196  return EXIT_FAILURE;
197  }
198  }
199  else
200  {
201  // use text file comparator
202  if(!identical_text_based_files(output_file_path, reference_file_path))
203  {
204  std::cout << "Files are different!" << std::endl;
205  return EXIT_FAILURE;
206  }
207  }
208 
209  std::cout << "Files are identical." << std::endl;
210 
211  return 0;
212 }
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
generic_reader.hpp
utils_identical_text_based_files.hpp
Graph_traits_extension_cgal_surface_mesh.h
color_mesh.h
Geometry_traits_cgal_surface_mesh.h
are_meshes_equal
bool are_meshes_equal(std::string filename_a, std::string filename_b, bool verbose)
Definition: utils_are_meshes_identical.inl:925
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
identical_text_based_files
bool identical_text_based_files(std::string filename_a, std::string filename_b, const std::vector< std::string > &skip=std::vector< std::string >())
Definition: utils_identical_text_based_files.hpp:27
CGALKernel
CGAL::Cartesian< double > CGALKernel
Definition: boolops_enriched_polyhedron.hpp:100
properties_surface_mesh.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
generic_writer.hpp
CGALPoint
CGALKernel::Point_3 CGALPoint
Definition: test_generic_writer_surfacemesh.cpp:30
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
utils_are_meshes_identical.hpp
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::FileUtils::has_extension
bool has_extension(const std::string &file_name)
Definition: FileUtilities.hpp:58
FEVV::_PMap_traits
Definition: properties.h:376
main
int main(int argc, const char **argv)
Definition: test_msdm2.cpp:41
FileUtilities.hpp
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