MEPP2 Project
compare_mesh_files.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 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 
15 
16 #include <iostream>
17 #include <string>
18 
19 
20 int
21 main(int argc, const char **argv)
22 {
23  if(argc < 3 || argc > 6)
24  {
25  std::cout << "Compare two mesh files." << std::endl;
26  std::cout << "For .OFF files, the comparison can be exact or approximated. "
27  "In the approximated case, the threshold can be a relative "
28  "value (default) or an absolute value."
29  << std::endl;
30  std::cout << std::endl;
31  std::cout << "Usage #1, exact comparison:" << std::endl;
32  std::cout << " " << argv[0] << " mesh_file_1 mesh_file_2" << std::endl;
33  std::cout << "Usage #2, approximate comparison, same threshold for both "
34  "geometry and attributes:"
35  << std::endl;
36  std::cout << " " << argv[0]
37  << " mesh_file_1 mesh_file_2 threshold [ABSOLUTE]"
38  << std::endl;
39  std::cout << "Usage #3, approximate comparison, separate thresholds for "
40  "geometry and attributes:"
41  << std::endl;
42  std::cout << " " << argv[0]
43  << " mesh_file_1 mesh_file_2 geometry_threshold "
44  "attributes_threshold [ABSOLUTE]"
45  << std::endl;
46 
47  std::cout << std::endl;
48  std::cout << "Examples: " << std::endl;
49  std::cout << " " << argv[0] << " airplane1.off airplane2.off"
50  << std::endl;
51  std::cout << " " << argv[0] << " airplane1.off airplane2.off 1e-3"
52  << std::endl;
53  std::cout << " " << argv[0]
54  << " airplane1.off airplane2.off 1e-3 ABSOLUTE" << std::endl;
55  std::cout << " " << argv[0] << " airplane1.off airplane2.off 1e-3 1e-4"
56  << std::endl;
57  std::cout << " " << argv[0]
58  << " airplane1.off airplane2.off 1e-3 1e-4 ABSOLUTE"
59  << std::endl;
60  return EXIT_FAILURE;
61  }
62 
63  std::string mesh_file1 = argv[1];
64  std::string mesh_file2 = argv[2];
65 
66  bool relative_threshold = true;
67  if(std::string(argv[argc - 1]) == "ABSOLUTE")
68  relative_threshold = false;
69 
70  float geom_threshold = 0;
71  float attr_threshold = 0;
72  if((argc == 4) && relative_threshold)
73  {
74  // relative mode, same threshold
75  geom_threshold = (float)std::atof(argv[3]);
76  attr_threshold = (float)std::atof(argv[3]);
77  }
78  else if((argc == 5) && relative_threshold)
79  {
80  // relative mode, different thresholds
81  geom_threshold = (float)std::atof(argv[3]);
82  attr_threshold = (float)std::atof(argv[4]);
83  }
84  else if((argc == 5) && !relative_threshold)
85  {
86  // absolute mode, same threshold
87  geom_threshold = (float)std::atof(argv[3]);
88  attr_threshold = (float)std::atof(argv[3]);
89  }
90  else if((argc == 6) && !relative_threshold)
91  {
92  // absolute mode, same threshold
93  geom_threshold = (float)std::atof(argv[3]);
94  attr_threshold = (float)std::atof(argv[4]);
95  }
96 
97  //--------------------------------------------------
98 
99  std::cout << "Comparing file '" << mesh_file1 << "'" << std::endl;
100  std::cout << " with file '" << mesh_file2 << "'" << std::endl;
101 
102  if(FEVV::FileUtils::has_extension(mesh_file1, ".off") ||
103  FEVV::FileUtils::has_extension(mesh_file2, ".coff"))
104  {
105  // use OFF file comparator
106  std::cout << "Use OFF file comparison" << std::endl;
107 
108  std::cout << "Geometry tolerance: " << geom_threshold << std::endl;
109  std::cout << "Attributes tolerance: " << attr_threshold << std::endl;
110  if(relative_threshold)
111  std::cout << "Mode: relative error" << std::endl;
112  else
113  std::cout << "Mode: absolute error" << std::endl;
114 
115  if(!are_meshes_equal(mesh_file1,
116  mesh_file2,
117  false,
118  geom_threshold,
119  attr_threshold,
120  relative_threshold))
121  {
122  std::cout << "Files are different!" << std::endl;
123  return EXIT_FAILURE;
124  }
125  }
126  else
127  {
128  // use text file comparator
129  std::cout << "Use text file comparison" << std::endl;
130 
131  if(!identical_text_based_files(mesh_file1, mesh_file2))
132  {
133  std::cout << "Files are different!" << std::endl;
134  return EXIT_FAILURE;
135  }
136  }
137 
138  std::cout << "Files are identical." << std::endl;
139 
140  return 0;
141 }
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
main
int main(int argc, const char **argv)
Definition: compare_mesh_files.cpp:21
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
utils_are_meshes_identical.hpp
FEVV::FileUtils::has_extension
bool has_extension(const std::string &file_name)
Definition: FileUtilities.hpp:58
FileUtilities.hpp