MEPP2 Project
test_decompression_valence.inl
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 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.
13 
17 
18 #include <iostream>
19 #include <string>
20 #include <cstdlib>
21 
22 
23 #ifdef UNIX
24 #include <unistd.h> // for getpid()
25 #include <fstream>
26 
27 void
28 get_vmpeak_vmsize(pid_t pid, unsigned int &vmpeak_kb, unsigned int &vmsize_kb)
29 {
30  std::string filename = "/proc/" + std::to_string(pid) + "/status";
31  std::ifstream file(filename);
32  if(!file.is_open())
33  {
34  std::cout << "Failed to open file '" << filename << "'" << std::endl;
35  return;
36  }
37 
38  std::string word;
39  while(true)
40  {
41  file >> word;
42  // DBG std::cout << "word=" << word << std::endl;
43 
44  if(file.eof())
45  break;
46 
47  if(word == "VmPeak:")
48  file >> vmpeak_kb;
49  else if(word == "VmSize:")
50  file >> vmsize_kb;
51  }
52 
53  file.close();
54 }
55 #endif // UNIX
56 
57 
58 template< typename MeshT >
59 int
60 test_decompression_valence(int argc, const char **argv)
61 {
62  // parse arguments
63 
64  if(argc < 2 || argc > 5)
65  {
66  std::cout << "Load a .p3d file generated by the Compression Valence "
67  "filter, then decompress it."
68  << std::endl;
69  std::cout << "Usage: " << argv[0]
70  << " p3d_file [output_mesh_file [reference_mesh_file "
71  "[relative_tolerance]]]"
72  << std::endl;
73  std::cout << "Example: " << argv[0] << " airplane.p3d" << std::endl;
74  std::cout << "Example: " << argv[0]
75  << " airplane.p3d airplane_uncompressed.off" << std::endl;
76  std::cout << "Example: " << argv[0]
77  << " airplane.p3d airplane_uncompressed.off airplane.ref.obj"
78  << std::endl;
79  std::cout
80  << "Example: " << argv[0]
81  << " airplane.p3d airplane_uncompressed.off airplane.ref.obj 1e-04"
82  << std::endl;
83  return EXIT_FAILURE;
84  }
85 
86  std::string input_file_path;
87  std::string output_file_path;
88  std::string reference_file_path;
89  float relative_tolerance = 0.0f;
90 
91  input_file_path = argv[1];
92  if(argc >= 3)
93  output_file_path = argv[2];
94  if(argc >= 4)
95  reference_file_path = argv[3];
96  if(argc >= 5)
97  relative_tolerance = (float)std::atof(argv[4]);
98 
99  // display parameters summary
100  std::cout << "\nParameters summary:" << std::endl;
101  std::cout << " - input file: " << input_file_path << std::endl;
102  std::cout << " - output file: " << output_file_path << std::endl;
103  std::cout << " - ref. file: " << reference_file_path << std::endl;
104  std::cout << " - rel. tolerance: " << relative_tolerance << std::endl;
105 
106  // display memory usage before loading and processing mesh
107 #ifdef UNIX
108  pid_t pid = getpid();
109  uint vmpeak_kb;
110  uint vmsize_kb;
111 
112  get_vmpeak_vmsize(pid, vmpeak_kb, vmsize_kb);
113  std::cout << "before loading and decompression vmpeak=" << vmpeak_kb
114  << " kB vmsize=" << vmsize_kb << " kB" << std::endl;
115 #endif
116 
117  //--------------------------------------------------
118 
119  // read mesh from file
120  MeshT m;
121  FEVV::PMapsContainer pmaps_bag;
122 
123  // retrieve geometry property map
124  auto pm = get(boost::vertex_point, m);
125 
126  // create vertex color property map
127  using VertexColorMap =
129  VertexColorMap v_cm;
130  put_property_map(FEVV::vertex_color, m, pmaps_bag, v_cm);
131 
132  // apply Compression Valence filter
133  bool has_color;
134  FEVV::Filters::decompression_valence(m, &pm, &v_cm, input_file_path, has_color);
135 
136  // display memory usage after decompression
137 #ifdef UNIX
138  uint vmpeak2_kb;
139  get_vmpeak_vmsize(pid, vmpeak2_kb, vmsize_kb);
140  std::cout << "after decompression vmpeak=" << vmpeak2_kb
141  << " kB vmsize=" << vmsize_kb
142  << " kB extra.vmpeak=" << vmpeak2_kb - vmpeak_kb << " kB"
143  << std::endl;
144 #endif
145 
146  // save the uncompressed mesh
147  if(!output_file_path.empty())
148  FEVV::Filters::write_mesh(output_file_path, m, pmaps_bag);
149 
150  // check output file
151  if(!reference_file_path.empty())
152  {
153  std::cout << "Comparing output file" << std::endl;
154  std::cout << " '" << output_file_path << "'" << std::endl;
155  std::cout << "with reference file" << std::endl;
156  std::cout << " '" << reference_file_path << "'" << std::endl;
157  std::cout << "..." << std::endl;
158 
159  if(FEVV::FileUtils::has_extension(output_file_path, ".off") ||
160  FEVV::FileUtils::has_extension(output_file_path, ".coff"))
161  {
162  // use OFF file comparator
163  if(!are_meshes_equal(output_file_path,
164  reference_file_path,
165  false,
166  relative_tolerance,
167  true /*relative_threshold*/))
168  {
169  std::cout << "Files are different!" << std::endl;
170  return EXIT_FAILURE;
171  }
172  }
173  else
174  {
175  // use text file comparator
176  if(!identical_text_based_files(output_file_path, reference_file_path))
177  {
178  std::cout << "Files are different!" << std::endl;
179  return EXIT_FAILURE;
180  }
181  }
182 
183  std::cout << "Files are identical." << std::endl;
184  }
185 
186  return 0;
187 }
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
utils_identical_text_based_files.hpp
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
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::decompression_valence
std::string decompression_valence(HalfedgeGraph &g, PointMap *pm, VertexColorMap *v_cm, const std::string &input_filename, bool &has_color, bool do_write_info, std::vector< HalfedgeGraph * > *intermediate_meshes, std::vector< VertexColorMap * > *intermediate_vertex_color_maps, int stop_level, bool do_write_intermediate_meshes, const GeometryTraits &)
Uncompress a mesh compressed with Compression Valence algorithm.
Definition: decompression_valence.h:59
decompression_valence.h
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
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
test_decompression_valence
int test_decompression_valence(int argc, const char **argv)
Definition: test_decompression_valence.inl:60
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