MEPP2 Project
distortion_computing.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2022 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 Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, 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 
12 #pragma once
13 
21 #include "boost/filesystem.hpp"
22 #include <iostream>
23 
24 
25 namespace fs = boost::filesystem;
26 
29 std::vector< fs::path >
30 get_files(fs::path const &root, std::string const &ext)
31 {
32  std::vector< fs::path > paths;
33 
34  if(fs::exists(root) && fs::is_directory(root))
35  {
36  for(auto const &entry : fs::recursive_directory_iterator(root))
37  {
38  if(fs::is_regular_file(entry) && entry.path().extension() == ext)
39  paths.emplace_back(entry.path().filename());
40  }
41  }
42  return paths;
43 }
44 
48 template< typename HalfedgeGraph,
49  typename PointMap >
50 void
51 compute_distortions(HalfedgeGraph &g,
52  PointMap &pm,
53  fs::path const &root
54  )
57 {
58  // initialize AABB tree for the original mesh
60 
61  // PREPROCESS: get quantization parameters
63  preprocess(g, pm);
65 
67 
68  std::vector< double > bb = pq.get_bb_dimension();
69  std::vector< double > init = pq.get_init_coord();
70  auto files = get_files(root, ".obj");
71  size_t nbf = files.size();
72  std::vector< double > _distortion_per_batch(nbf, 0.);
73  for(size_t i = 0; i < nbf; i++)
74  {
75  HalfedgeGraph current_mesh;
76  FEVV::PMapsContainer current_pmaps_bag;
77 
78  // read quantized mesh
79  FEVV::Filters::read_mesh(root.string()+files[i].string(),current_mesh,current_pmaps_bag);
80  auto current_pm = get(boost::vertex_point, current_mesh);
81 
82  // unquantize mesh
84  current_mesh,
85  current_pm,
87  pq.get_bb_dimension(),
88  pq.get_init_coord());
89 
91 
92  // compute distortion
93  _distortion_per_batch[i] =
94  g_metric.compute_symmetric_L2(current_mesh, true);
95  }
96  // create distortion column in a new .csv file
97  std::ofstream dist_file;
98  dist_file.open(root.string() + "dist_measures" + ".csv");
99  auto it_dist = _distortion_per_batch.begin();
100  dist_file << "DISTORSION"
101  << "\n";
102  for( ; it_dist != _distortion_per_batch.end(); it_dist++)
103  {
104  dist_file << (*it_dist) << "\n";
105  }
106 
107  dist_file.close();
108 }
FEVV::Filters::Preprocessing
Preprocessing class is dedicated to provide a list of preprocessings that are needed to guarantee tha...
Definition: Preprocessing.h:51
FEVV::Filters::Uniform_quantization::get_bb_dimension
std::vector< double > get_bb_dimension() const
Definition: Uniform_quantization.h:228
Uniform_quantization.h
FEVV::Filters::Uniform_quantization
Uniform_quantization is a class dedicated to the XYZ uniform quantization of vertex coordinates store...
Definition: Uniform_quantization.h:49
generic_reader.hpp
Preprocessing.h
Uniform_dequantization.h
FEVV::Filters::Uniform_dequantization::point_dequantization
void point_dequantization()
Dequantizes all vertex positions stored in the point map.
Definition: Uniform_dequantization.h:111
FEVV::Filters::Geometric_metrics
Geometric_metrics is a class dedicated to the geometric distance computation between an original full...
Definition: Geometric_metrics.h:55
FEVV::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
FEVV::Filters::Preprocessing::process_mesh_before_quantization
void process_mesh_before_quantization()
Suppress all small connected components (isolated vertices and isolated edges). To apply before quant...
Definition: Preprocessing.h:61
get_files
std::vector< fs::path > get_files(fs::path const &root, std::string const &ext)
Definition: distortion_computing.h:30
FEVV::Filters::Geometric_metrics::compute_symmetric_L2
double compute_symmetric_L2(const HalfedgeGraph &LoD, bool compute_RMSE_instead_of_max)
Proposed RMSE and Hausdorff distances implementation.
Definition: Geometric_metrics.h:211
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::Filters::Uniform_quantization::get_nb_bits_quantization
int get_nb_bits_quantization() const
Definition: Uniform_quantization.h:257
FEVV::Filters::Uniform_dequantization< HalfedgeGraph, PointMap >
generic_writer.hpp
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
Geometric_metrics.h
FEVV::Filters::Uniform_quantization::get_init_coord
std::vector< double > get_init_coord() const
Definition: Uniform_quantization.h:239
compute_distortions
void compute_distortions(HalfedgeGraph &g, PointMap &pm, fs::path const &root)
Definition: distortion_computing.h:51
Batch_collapser.h