MEPP2 Project
example_just_noticeable_distortion.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 
14 
18 
24 
25 #include <boost/property_tree/ptree.hpp>
26 #include <boost/property_tree/json_parser.hpp>
27 #include <time.h>
28 
29 //---------------------------------------------------------
30 // Main
31 //---------------------------------------------------------
32 
33 // Main: load a mesh, apply the filter, write the mesh
34 int
35 main(int narg, char **argv)
36 {
37  typedef boost::graph_traits< FEVV::MeshSurface > GraphTraits;
38  //typedef typename GraphTraits::vertex_iterator vertex_iterator;
40  // input and output files
41  // std::string inputFilePath =
42  // "../../../../Testing/Data/CubeTriangleFaces.obj";
43  std::string input_file_path = "sphere.obj";
44  if(narg == 2 || narg == 3)
45  {
46  std::string reader = std::string(argv[1]);
47  input_file_path = reader;
48  }
49  std::string output_file_path = "just_noticeable_distortion_filter.output.obj";
50 
51  int screen_width = 1920;
52  int screen_height = 1080;
53  double screen_size = 55.;
54  double user_dist = 50.;
55  int scene_width = 1080;
56  double scene_fov = M_PI * 0.3333;
57  int number_of_lights = 128;
58 
59  if(narg == 3)
60  {
61  boost::property_tree::ptree pt;
62  boost::property_tree::read_json(argv[2], pt);
63 
64  screen_width = pt.get< int >("screen_width", screen_width);
65  screen_height = pt.get< int >("screen_height", screen_height);
66  screen_size = pt.get< double >("screen_size", screen_size);
67  user_dist = pt.get< double >("user_dist", user_dist);
68  scene_width = pt.get< int >("scene_width", scene_width);
69  scene_fov = M_PI * pt.get< double >("scene_fov", scene_fov);
70  number_of_lights = pt.get< int >("number_of_lights", number_of_lights);
71  }
72  std::cout << "Confing used :" << std::endl;
73  std::cout << "\tScreen : " << screen_width << " * " << screen_height << " - "
74  << screen_size << std::endl;
75  std::cout << "\tUser distance : " << user_dist << std::endl;
76  std::cout << "\tScene : " << scene_width << " - " << scene_fov << std::endl;
77  std::cout << "\tNumber of lights : " << number_of_lights << std::endl;
78 
79 
80  ScreenParam screen(screen_width, screen_height, screen_size);
81  UserParam user(user_dist);
82  SceneParam scene(scene_width, scene_fov);
83  // read mesh from file
85  FEVV::PMapsContainer pmaps_bag;
86  FEVV::Filters::read_mesh(input_file_path, m, pmaps_bag);
87 
88  // retrieve point property map (aka geometry)
89  auto pm = get(boost::vertex_point, m);
90  // Note: the property maps must be extracted from the
91  // property maps bag, and explicitely passed as
92  // parameters to the filter, in order to make
93  // clear what property is used by the filter
94 
95  // retrieve or create vertex-color property map
96  using VertexColorMap =
98  FEVV::MeshSurface >::pmap_type;
99  VertexColorMap v_cm;
100  if(has_map(pmaps_bag, FEVV::vertex_color))
101  {
102  std::cout << "use existing vertex-color map" << std::endl;
103  v_cm = get_property_map(FEVV::vertex_color, m, pmaps_bag);
104  }
105  else
106  {
107  std::cout << "create vertex-color map" << std::endl;
109  // store property map in property maps bag
110  put_property_map(FEVV::vertex_color, m, pmaps_bag, v_cm);
111  }
112 
113 
114  // retrieve or create vertex-normal property map
115  using FaceNormalMap =
117  FEVV::MeshSurface >::pmap_type;
118  FaceNormalMap f_nm;
119  if(has_map(pmaps_bag, FEVV::face_normal))
120  {
121  std::cout << "use existing face-normal map" << std::endl;
122  f_nm = get_property_map(FEVV::face_normal, m, pmaps_bag);
123  }
124  else
125  {
126  std::cout << "create face-normal map" << std::endl;
128  // store property map in property maps bag
129  put_property_map(FEVV::face_normal, m, pmaps_bag, f_nm);
131  }
132 
133 
134  // retrieve or create vertex-normal property map
135  using VertexNormalMap =
137  FEVV::MeshSurface >::pmap_type;
138  VertexNormalMap v_nm;
139  if(has_map(pmaps_bag, FEVV::vertex_normal))
140  {
141  std::cout << "use existing vertex-normal map" << std::endl;
142  v_nm = get_property_map(FEVV::vertex_normal, m, pmaps_bag);
143  }
144  else
145  {
146  std::cout << "create vertex-normal map" << std::endl;
148 
149  put_property_map(FEVV::vertex_normal, m, pmaps_bag, v_nm);
150  FEVV::Filters::calculate_vertex_normals(m, pm, f_nm, v_nm);
151  }
152 
153  using JndTypeMap =
155  JndTypeMap jnd_m;
156 
157  jnd_m = FEVV::make_vertex_property_map< FEVV::MeshSurface, double >(m);
158 
159 
160  // apply filter
161  clock_t t_start = clock();
163  pm,
164  v_nm,
165  f_nm,
166  jnd_m,
167  screen,
168  user,
169  scene,
170  number_of_lights,
171  true,
172  false);
173 
174  std::cout << "Time used to compute JND : "
175  << (double)(clock() - t_start) / CLOCKS_PER_SEC << std::endl;
176 
177 
178  double max_jnd, min_jnd;
179 
180  FEVV::Filters::ColorMeshLUT lut_courbure_clust =
182 
183  FEVV::Filters::compute_min_max_vertices(m, jnd_m, min_jnd, max_jnd);
184 
186  m, jnd_m, v_cm, min_jnd, max_jnd, lut_courbure_clust);
187 
188  // write mesh to file
189  int counter = 0;
190  BOOST_FOREACH(vertex_descriptor vd, m.vertices())
191  {
192  double jnd = get(jnd_m, vd);
193  std::cout << "vertex #" << ++counter;
194  std::cout << " - Jnd= " << jnd << std::endl;
195  }
196  FEVV::Filters::write_mesh(output_file_path, m, pmaps_bag);
197 
198 
199  return 0;
200 }
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
SceneParam
The parameters of the scene.
Definition: types.h:55
color_mesh.h
Geometry_traits_cgal_surface_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::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
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
DataStructures_cgal_surface_mesh.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
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
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
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
main
int main(int narg, char **argv)
Definition: example_just_noticeable_distortion.cpp:35
FEVV::_PMap_traits
Definition: properties.h:376
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