MEPP2 Project
test_progressive_comp_decomp.inl
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
15 
18 
20 
22 
30 template< typename MeshT >
31 int
33  const char **argv
34  )
35 {
36  if (argc < 2)
37  {
38  std::cout << "test_automatic_progressive_compression_decompression_ld needs an input mesh filename." << std::endl;
39  return -1;
40  }
42  MeshT m;
43  FEVV::PMapsContainer pmaps_bag;
45  // Input and output files
46  std::string input_file_path = argv[1];
47  std::string output_file_path_save_preprocess = "";
48  std::string output_file_path_decomp = "";
49  std::string measurepath = typeid(m).name();
50  if (measurepath.find("Surface_mesh") != std::string::npos)
51  {
52  measurepath = "Surface_mesh_";
53  }
54  else if (measurepath.find("Polyhedron_3") != std::string::npos)
55  {
56  measurepath = "Polyhedron_3_";
57  }
58  else if (measurepath.find("Linear_cell_complex") != std::string::npos)
59  {
60  measurepath = "LCC_";
61  }
62  else if (measurepath.find("AIF") != std::string::npos)
63  {
64  measurepath = "AIF_";
65  }
66  else
67  {
68  measurepath = "Other_mesh_type_";
69  }
70  // Note: the file comparison can only be done with .off files
71  std::string compressed_mesh_binary_file = measurepath + FEVV::FileUtils::get_file_name(input_file_path);
72  output_file_path_save_preprocess = "progressive_compression_" + compressed_mesh_binary_file + "_original_mesh_after_preprocess.off"; // default value
73  output_file_path_decomp = "progressive_decompression_" + compressed_mesh_binary_file + "_output.off"; // default value
74  compressed_mesh_binary_file = compressed_mesh_binary_file + ".bin";
76  if (argc > 2)
77  {
78  output_file_path_save_preprocess = argv[2];
79  }
80  if (argc > 3)
81  {
82  output_file_path_decomp = argv[3];
83  }
84  if (argc > 4)
85  {
86  std::cout << "test_automatic_progressive_compression_decompression needs at maximum 3 input parameters: input mesh filename, output filename for the preprocessed mesh, and an output filename for the decompressed mesh." << std::endl;
87  return -1;
88  }
90  // Read mesh from file
91  FEVV::Filters::read_mesh(input_file_path, m, pmaps_bag);
96  set_mesh_and_properties(m, pmaps_bag, v_cm, e_cm, v_nm);
97 
99  FEVV::Filters::VKEPT_POSITION::MIDPOINT,
101  true,
102  false,
103  12);
104 
105  //FEVV::Filters::Parameters params( FEVV::Filters::PREDICTION_TYPE::BUTTERFLY,
106  // FEVV::Filters::VKEPT_POSITION::HALFEDGE,
107  // FEVV::Filters::METRIC_TYPE::QEM_3D,
108  // true,
109  // false,
110  // 12);
111 
112  //FEVV::Filters::Parameters params( FEVV::Filters::PREDICTION_TYPE::DELTA,
113  // FEVV::Filters::VKEPT_POSITION::MIDPOINT,
114  // FEVV::Filters::METRIC_TYPE::QEM_3D,
115  // true,
116  // false,
117  // 12);
118 
119  //FEVV::Filters::Parameters params( FEVV::Filters::PREDICTION_TYPE::DELTA,
120  // FEVV::Filters::VKEPT_POSITION::HALFEDGE,
121  // FEVV::Filters::METRIC_TYPE::QEM_3D,
122  // true,
123  // false,
124  // 12);
125 
126  //FEVV::Filters::Parameters params( FEVV::Filters::PREDICTION_TYPE::POSITION,
127  // FEVV::Filters::VKEPT_POSITION::MIDPOINT,
128  // FEVV::Filters::METRIC_TYPE::QEM_3D,
129  // true,
130  // false,
131  // 12);
132 
133  //FEVV::Filters::Parameters params( FEVV::Filters::PREDICTION_TYPE::POSITION,
134  // FEVV::Filters::VKEPT_POSITION::HALFEDGE,
135  // FEVV::Filters::METRIC_TYPE::QEM_3D,
136  // true,
137  // false,
138  // 12);
139  auto pm = get(boost::vertex_point, m);
140  auto gt_ = FEVV::Geometry_traits< MeshT >(m);
142  // Compression algorithm call (Algorithm 1) //
145  pm,
146  v_cm,
147  e_cm,
148  // v_nm,
149  gt_,
150  params,
151  200,
152  3,
153  FEVV::Filters::BATCH_CONDITION::ALL_EDGES,
154  measurepath,
155  compressed_mesh_binary_file,
156  true,
157  true,
158  true,
159  output_file_path_save_preprocess);
161  MeshT m_decomp;
162  FEVV::PMapsContainer pmaps_bag_decomp;
164  v_cm_decomp;
166  e_cm_decomp;
168  v_nm_decomp;
169  auto pm_decomp = get(boost::vertex_point, m_decomp);
170  set_mesh_and_properties(m_decomp,
171  pmaps_bag_decomp,
172  v_cm_decomp,
173  e_cm_decomp,
174  v_nm_decomp);
176  // Decompression algorithm call (Algorithm 2) //
179  pm_decomp,
180  v_cm_decomp,
181  compressed_mesh_binary_file,
182  false);
184  // Write mesh to file
185  FEVV::PMapsContainer pmaps_bag_decomp_without_material;
186 
188  FEVV::edge_color, m_decomp, pmaps_bag_decomp_without_material, e_cm);
190  FEVV::vertex_color, m_decomp, pmaps_bag_decomp_without_material, v_cm);
192  output_file_path_decomp, m_decomp, pmaps_bag_decomp_without_material);
194  // Compare preprocessed and decompressed meshes (with quantized coordinates)
195  bool equal_or_not = are_meshes_equal(output_file_path_save_preprocess,
196  output_file_path_decomp,
197  false,
198  0,
199  0,
200  true);
201  if(equal_or_not)
202  {
203  std::cout << "meshes are equal!" << std::endl;
204  return 0;
205  }
206  else
207  {
208  std::cout << "meshes are not equal" << std::endl;
209  return -1;
210  }
211 }
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
progressive_decompression_filter.hpp
set_mesh_and_properties
void set_mesh_and_properties(const MeshT &m, FEVV::PMapsContainer &pmaps_bag, typename FEVV::PMap_traits< FEVV::vertex_color_t, MeshT >::pmap_type &v_cm, typename FEVV::PMap_traits< FEVV::edge_color_t, MeshT >::pmap_type &e_cm, typename FEVV::PMap_traits< FEVV::vertex_normal_t, MeshT >::pmap_type &v_nm)
Function to extract or create property map associated with a property map bag (for generic processing...
Definition: initializer_compression.h:35
generic_reader.hpp
FEVV::Geometry_traits
Refer to Geometry_traits_documentation_dummy for further documentation on provided types and algorith...
Definition: Geometry_traits.h:162
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::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
FEVV::FileUtils::get_file_name
std::string get_file_name(const std::string &file_name)
Definition: FileUtilities.hpp:128
FEVV::edge_color
@ edge_color
Definition: properties.h:73
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
initializer_compression.h
test_automatic_progressive_compression_decompression
int test_automatic_progressive_compression_decompression(int argc, const char **argv)
Compresses then decompresses a mesh.
Definition: test_progressive_comp_decomp.inl:32
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
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::Filters::progressive_compression_filter
void progressive_compression_filter(HalfedgeGraph &g, PointMap &pm, FEVV::Filters::Uniform_quantization< HalfedgeGraph, PointMap > &pq, VertexColorMap &v_cm, EdgeColorMap &e_cm, const GeometryTraits &gt, FEVV::Filters::Error_metric< HalfedgeGraph, PointMap > *EM, const FEVV::Filters::Kept_position< HalfedgeGraph, PointMap > *KP, FEVV::Filters::Predictor< HalfedgeGraph, PointMap > *predict, int nb_q_bits, int nb_max_batches, int nb_min_vertices, FEVV::Filters::BATCH_CONDITION batch_condition, draco::EncoderBuffer &buffer, const std::string &measure_path, bool preprocess=true, bool dequantiz=false, bool save_preprocess=false, const std::string &output_file_path_save_preprocess="", bool allow_duplicates=false)
Takes a mesh g, applies batches of simplification until either the number of max batches or the minim...
Definition: progressive_compression_filter.hpp:126
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::Filters::progressive_decompression_filter
void progressive_decompression_filter(HalfedgeGraph &g, PointMap &pm, VertexColorMap &v_cm, const GeometryTraits &, draco::DecoderBuffer &buffer, bool dequantize=true, unsigned int nb_max_batches=10000)
Takes a buffer as an input, will decode the compression settings, the coarse mesh and refine the mesh...
Definition: progressive_decompression_filter.hpp:67
FEVV::_PMap_traits
Definition: properties.h:376
FileUtilities.hpp
FEVV::Filters::Parameters
Parameters contains the compression parameters except the stopping criteria.
Definition: Parameters.h:46
FEVV::Filters::METRIC_TYPE::QEM_3D
@ QEM_3D
do not use a local metric (not implemented in this release)
FEVV::Filters::PREDICTION_TYPE::POSITION
@ POSITION