MEPP2 Project
test_cmdm.cpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2020 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 
14 
18 
21 
22 int
23 main(int argc, const char **argv)
24 {
25  if(argc != 5)
26  {
27  std::cout
28  << "Load 2 meshes from input files, compute their CMDM, then compare the output file (the degraded mesh covered by the local distortion map) with the reference file."
29  << std::endl;
30  std::cout << "Usage: " << argv[0]
31  << " input_original_mesh_path input_degraded_mesh_path Output_LD_degraded_mesh DegradedMesh_LD_OutputReferenceValues"
32  << std::endl;
33  std::cout << "Example: " << argv[0]
34  << " Fish_ref.obj Fish_simplified.obj Fish_simplified_cmdm.out.obj Fish_cmdm_reference.obj"
35  << std::endl;
36  return EXIT_FAILURE;
37  }
38 
39  std::string input_original_file_path = argv[1];
40  std::string input_deformed_file_path = argv[2];
41  std::string output_file_path = argv[3];
42  std::string reference_file_path = argv[4];
43 
44  // create LUT
45  FEVV::Filters::ColorMeshLUT lut_courbure_clust = FEVV::Filters::make_LUT(false);
46 
47  // read meshes from file
48  FEVV::MeshSurface m_original;
49  FEVV::PMapsContainer pmaps_bag_original;
50  FEVV::Filters::read_mesh(input_original_file_path, m_original, pmaps_bag_original);
51 
52  FEVV::MeshSurface m_degraded;
53  FEVV::PMapsContainer pmaps_bag_degraded;
54  FEVV::Filters::read_mesh(input_deformed_file_path, m_degraded, pmaps_bag_degraded);
55 
56  auto pm_degrad = get(boost::vertex_point, m_degraded);
57  auto pm_original = get(boost::vertex_point, m_original);
58 
60  FaceNormalMap fnm_degrad;
61  if(has_map(pmaps_bag_degraded, FEVV::face_normal))
62  {
63  std::cout << "use existing face-normal map for degraded mesh" << std::endl;
64  fnm_degrad = get_property_map(FEVV::face_normal, m_degraded, pmaps_bag_degraded);
65  }
66  else
67  {
68  std::cout << "create face-normal map for degraded mesh" << std::endl;
69  fnm_degrad = make_property_map(FEVV::face_normal, m_degraded);
70  // store property map in property maps bag
71  put_property_map(FEVV::face_normal, m_degraded, pmaps_bag_degraded, fnm_degrad);
72  FEVV::Filters::calculate_face_normals(m_degraded, pm_degrad, fnm_degrad);
73  }
74 
75  FaceNormalMap fnm_original;
76  if(has_map(pmaps_bag_original, FEVV::face_normal))
77  {
78  std::cout << "use existing face-normal map for original mesh" << std::endl;
79  fnm_original = get_property_map(FEVV::face_normal, m_original, pmaps_bag_original);
80  }
81  else
82  {
83  std::cout << "create face-normal map for original mesh" << std::endl;
84  fnm_original = make_property_map(FEVV::face_normal, m_original);
85  // store property map in property maps bag
86  put_property_map(FEVV::face_normal, m_original, pmaps_bag_original, fnm_original);
87  FEVV::Filters::calculate_face_normals(m_original, pm_original, fnm_original);
88  }
89 
90  // Verify if the original and the degraded meshes have diffuse color maps
91  if(has_map(pmaps_bag_original, FEVV::vertex_color) &&
92  has_map(pmaps_bag_degraded, FEVV::vertex_color))
93  {
94  std::cout << "use existing color maps for original and degraded meshes"
95  << std::endl;
96  }
97  else
98  {
99  std::cout
100  << "CMDM needs 2 meshes with diffuse colors.\nUse MSDM2 Plugin for "
101  "meshes having geometry characteristics only."
102  << std::endl;
103  return EXIT_FAILURE;
104  }
105 
106  // Using a vertex property map to store the local distortions and visualize them later (color map).
107  typedef typename FEVV::Vertex_pmap< FEVV::MeshSurface, double > vertex_cmdm_map;
108  vertex_cmdm_map cmdm_pmap_deg, cmdm_pmap_orig;
109 
110  if(FEVV::has_map(pmaps_bag_degraded, std::string("v:cmdm")))
111  {
112  cmdm_pmap_deg =
113  boost::any_cast< vertex_cmdm_map >(pmaps_bag_degraded.at("v:cmdm"));
114  }
115  else
116  {
117  cmdm_pmap_deg =
118  FEVV::make_vertex_property_map< FEVV::MeshSurface, double >(m_degraded);
119  pmaps_bag_degraded["v:cmdm"] = cmdm_pmap_deg;
120  }
121 
122  int nb_levels = 3;
123  double cmdm_1_2, cmdm;//cmdm_2_1,
124 
126  pm_degrad,
127  fnm_degrad,
128  pmaps_bag_degraded,
129  m_original,
130  pm_original,
131  fnm_original,
132  pmaps_bag_original,
133  nb_levels,
134  cmdm_pmap_deg,
135  cmdm_1_2);
136 
137  cmdm = cmdm_1_2;
138  std::cout << "Calculated CMDM = " << cmdm << std::endl;
139 
140  // Visalize local distortions of the degraded mesh (color map of cmdm_1_2)
141  using VertexColorMap =
143  FEVV::MeshSurface >::pmap_type;
144  VertexColorMap v_cm =
145  get_property_map(FEVV::vertex_color, m_degraded, pmaps_bag_degraded);
146 
147  double max_cmdm_1_2, min_cmdm_1_2;
148 
150  m_degraded, cmdm_pmap_deg, min_cmdm_1_2, max_cmdm_1_2);
151 
153  cmdm_pmap_deg,
154  v_cm,
155  min_cmdm_1_2,
156  max_cmdm_1_2,
157  lut_courbure_clust);
158 
159  FEVV::Filters::write_mesh(output_file_path, m_degraded, pmaps_bag_degraded);
160 
161  // check output file
162  std::cout << "Comparing output file '" << output_file_path
163  << "' with reference file '" << reference_file_path << "'..."
164  << std::endl;
165 
166  if(FEVV::FileUtils::has_extension(output_file_path, ".off") ||
167  FEVV::FileUtils::has_extension(output_file_path, ".coff"))
168  {
169  // use OFF file comparator
170  if(!are_meshes_equal(output_file_path, reference_file_path, false))
171  {
172  std::cout << "Files are different!" << std::endl;
173  return EXIT_FAILURE;
174  }
175  }
176  else
177  {
178  // use text file comparator
179  if(!identical_text_based_files(output_file_path, reference_file_path))
180  {
181  std::cout << "Files are different!" << std::endl;
182  return EXIT_FAILURE;
183  }
184  }
185 
186  std::cout << "Files are identical." << std::endl;
187 
188  return 0;
189 }
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::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
main
int main(int argc, const char **argv)
Definition: test_cmdm.cpp:23
FEVV::has_map
bool has_map(const PMapsContainer &pmaps, const std::string &map_name)
(refer to Property Maps API)
Definition: properties.h:103
utils_identical_text_based_files.hpp
color_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
cmdm.h
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
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
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::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
utils_are_meshes_identical.hpp
FEVV::FileUtils::has_extension
bool has_extension(const std::string &file_name)
Definition: FileUtilities.hpp:58
FEVV::_PMap_traits
Definition: properties.h:376
FEVV::Filters::process_CMDM_multires
double process_CMDM_multires(const HalfedgeGraph &m_poly_degrad, const PointMap &pm_degrad, const FaceNormalMap &fnm_degrad, FEVV::PMapsContainer &pmaps_degrad, const HalfedgeGraph &m_poly_original, const PointMap &pm_original, const FaceNormalMap &fnm_original, FEVV::PMapsContainer &pmaps_original, const int nb_level, VertexCMDMMap &cmdm_pmap, const double maxdim, double &CMDM_value)
Definition: cmdm.h:484
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