MEPP2 Project
test_jnd.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> // CGAL Graph traits wrapper
14 #include "FEVV/Wrappings/Graph_traits_extension_cgal_surface_mesh.h" // FEVV extension for Graph traits wrapper
15 
16 #include "FEVV/Wrappings/Geometry_traits_cgal_surface_mesh.h" // FEVV geometry wrapper
17 
21 
25 
31 
32 #include <iostream>
33 #include <string>
34 
35 
36 using CGALKernel = CGAL::Cartesian< double >;
37 using CGALPoint = CGALKernel::Point_3;
38 using MeshT = CGAL::Surface_mesh< CGALPoint >;
39 
40 
41 int
42 main(int argc, const char **argv)
43 {
44 
45  int screen_width = 1920;
46  int screen_height = 1080;
47  double screen_size = 55.;
48  double user_dist = 50.;
49  int scene_width = 1080;
50  double scene_fov = M_PI * 0.3333;
51  int number_of_lights = 16;
52 
53  if(argc != 4)
54  {
55  std::cout
56  << "Load a mesh from an input file, compute it's JND, write it to an "
57  "output file, then compare the output file with a reference file."
58  << std::endl;
59  std::cout << "Usage: " << argv[0]
60  << " input_mesh_file output_mesh_file reference_mesh_file"
61  << std::endl;
62  std::cout << "Example: " << argv[0]
63  << " armadillo_simplified.obj armadillo.out.obj "
64  "armadillo_jnd_reference.obj"
65  << std::endl;
66  return EXIT_FAILURE;
67  }
68 
69  std::string input_file_path = argv[1];
70  std::string output_file_path = argv[2];
71  std::string reference_file_path = argv[3];
72 
73  //--------------------------------------------------
74 
75  FEVV::Filters::ColorMeshLUT lut_courbure_clust =
77 
78  ScreenParam screen(screen_width, screen_height, screen_size);
79  UserParam user(user_dist);
80  SceneParam scene(scene_width, scene_fov);
81  // read mesh from file
83  FEVV::PMapsContainer pmaps_bag;
84  FEVV::Filters::read_mesh(input_file_path, m, pmaps_bag);
85 
86  // retrieve point property map (aka geometry)
87  auto pm = get(boost::vertex_point, m);
88  // Note: the property maps must be extracted from the
89  // property maps bag, and explicitely passed as
90  // parameters to the filter, in order to make
91  // clear what property is used by the filter
92 
93  // retrieve or create vertex-color property map
94  using VertexColorMap =
96  FEVV::MeshSurface >::pmap_type;
97  VertexColorMap v_cm;
98  if(has_map(pmaps_bag, FEVV::vertex_color))
99  {
100  std::cout << "use existing vertex-color map" << std::endl;
101  v_cm = get_property_map(FEVV::vertex_color, m, pmaps_bag);
102  }
103  else
104  {
105  std::cout << "create vertex-color map" << std::endl;
107  // store property map in property maps bag
108  put_property_map(FEVV::vertex_color, m, pmaps_bag, v_cm);
109  }
110 
111 
112  // retrieve or create vertex-normal property map
113  using FaceNormalMap =
115  FEVV::MeshSurface >::pmap_type;
116  FaceNormalMap f_nm;
117  if(has_map(pmaps_bag, FEVV::face_normal))
118  {
119  std::cout << "use existing face-normal map" << std::endl;
120  f_nm = get_property_map(FEVV::face_normal, m, pmaps_bag);
121  }
122  else
123  {
124  std::cout << "create face-normal map" << std::endl;
126  // store property map in property maps bag
127  put_property_map(FEVV::face_normal, m, pmaps_bag, f_nm);
129  }
130 
131 
132  // retrieve or create vertex-normal property map
133  using VertexNormalMap =
135  FEVV::MeshSurface >::pmap_type;
136  VertexNormalMap v_nm;
137  if(has_map(pmaps_bag, FEVV::vertex_normal))
138  {
139  std::cout << "use existing vertex-normal map" << std::endl;
140  v_nm = get_property_map(FEVV::vertex_normal, m, pmaps_bag);
141  }
142  else
143  {
144  std::cout << "create vertex-normal map" << std::endl;
146 
147  put_property_map(FEVV::vertex_normal, m, pmaps_bag, v_nm);
148  FEVV::Filters::calculate_vertex_normals(m, pm, f_nm, v_nm);
149  }
150 
151  using JndTypeMap =
153  JndTypeMap jnd_m;
154 
155  jnd_m = FEVV::make_vertex_property_map< FEVV::MeshSurface, double >(m);
156 
157 
158  // apply filter
159  //clock_t t_start = clock();
161  pm,
162  v_nm,
163  f_nm,
164  jnd_m,
165  screen,
166  user,
167  scene,
168  number_of_lights,
169  false,
170  false);
171 
172 
173  double max_jnd, min_jnd;
174 
175  FEVV::Filters::compute_min_max_vertices(m, jnd_m, min_jnd, max_jnd);
176 
178  m, jnd_m, v_cm, min_jnd, max_jnd, lut_courbure_clust);
179 
180  FEVV::Filters::write_mesh(output_file_path, m, pmaps_bag);
181 
182  // check output file
183  std::cout << "Comparing output file '" << output_file_path
184  << "' with reference file '" << reference_file_path << "'..."
185  << std::endl;
186 
187  if(FEVV::FileUtils::has_extension(output_file_path, ".off") ||
188  FEVV::FileUtils::has_extension(output_file_path, ".coff"))
189  {
190  // use OFF file comparator
191  if(!are_meshes_equal(output_file_path, reference_file_path, false))
192  {
193  std::cout << "Files are different!" << std::endl;
194  return EXIT_FAILURE;
195  }
196  }
197  else
198  {
199  // use text file comparator
200  if(!identical_text_based_files(output_file_path, reference_file_path))
201  {
202  std::cout << "Files are different!" << std::endl;
203  return EXIT_FAILURE;
204  }
205  }
206 
207  std::cout << "Files are identical." << std::endl;
208 
209  return 0;
210 }
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
UserParam
The parameters of the user.
Definition: types.h:43
minmax_map.h
just_noticeable_distortion.hpp
ScreenParam
The parameters of the screen.
Definition: types.h:27
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
SceneParam
The parameters of the scene.
Definition: types.h:55
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::vertex_normal_t
vertex_normal_t
Definition: properties.h:35
FEVV::Assoc_property_map
Definition: properties.h:236
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
calculate_vertex_normals.hpp
FEVV::vertex_color_t
vertex_color_t
Definition: properties.h:47
main
int main(int argc, const char **argv)
Definition: test_jnd.cpp:42
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::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
FEVV::Filters::calculate_vertex_normals
void calculate_vertex_normals(const HalfedgeGraph &g, const PointMap &pm, const FaceNormalMap &fnm, VertexNormalMap vnm, const GeometryTraits &gt)
Compute the respectice vertex normal for all the vertices of the considered mesh and populate the arg...
Definition: calculate_vertex_normals.hpp:41
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
FileUtilities.hpp
FEVV::Filters::just_noticeable_distortion_filter
void just_noticeable_distortion_filter(const HalfedgeGraph &halfedge_graph, PointMap &point_map, const VertexNormalMap &vertex_normal_map, const GeometryTraits &geometry_traits, const FaceNormalMap &face_normal_map, JNDMap &jnd_map, const ScreenParam &screen, const UserParam &user, const SceneParam &scene, const int nb_light_sources, bool data_output=false, bool use_random=true)
Computes the Just Noticeable Distortion metric.
Definition: just_noticeable_distortion.hpp:336
FEVV::vertex_normal
@ vertex_normal
Definition: properties.h:35
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