MEPP2 Project
test_reader_writer_aif.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.
14 
18 
19 #include <cassert>
20 
21 using namespace FEVV::DataStructures::AIF;
24 
25 int
26 main(int narg, char **argv)
27 {
28  std::string input_file_path;
29  std::string output_file_path("test_AIFWriter_output.obj");
30  std::string reference_file_path;
31 
32  if(narg == 2)
33  {
34  input_file_path = argv[1];
35  }
36  else if(narg == 3)
37  {
38  input_file_path = argv[1];
39  output_file_path = argv[2];
40  }
41  else if(narg == 4)
42  {
43  input_file_path = argv[1];
44  output_file_path = argv[2];
45  reference_file_path = argv[3];
46  }
47  else
48  {
49  std::cout << "Usage: " << argv[0]
50  << " mesh_file [output_file [reference_file]]" << std::endl;
51  std::cout << "Example: " << argv[0] << " airplane.off" << std::endl;
52  std::cout << "Example: " << argv[0] << " airplane.off airplane.out.obj"
53  << std::endl;
54  std::cout << "Example: " << argv[0]
55  << " airplane.off airplane.out.obj airplane.ref.obj"
56  << std::endl;
57  return EXIT_FAILURE;
58  }
59 
60  //--------------------------------------------------
61 
62  reader_type my_reader;
63  writer_type my_writer;
65 
66  try
67  {
68  my_mesh = my_reader.read(input_file_path);
69 
70  // myMesh->Print();
71  }
72  catch(const std::invalid_argument &e)
73  {
74  std::cerr << "Invalid Argument Exception catch while reading "
75  << input_file_path << " :" << std::endl
76  << e.what() << std::endl;
77  return EXIT_FAILURE;
78  }
79  catch(const std::ios_base::failure &e)
80  {
81  std::cerr << "IOS Failure Exception catch while reading " << input_file_path
82  << " :" << std::endl
83  << e.what() << std::endl;
84  return EXIT_FAILURE;
85  }
86  catch(const std::length_error &le)
87  {
88  std::cerr << "[AIF] Exception caught while reading input file "
89  << input_file_path << ": " << le.what() << std::endl;
90  BOOST_ASSERT_MSG(false, "[AIF] Exception caught while reading input file.");
91  }
92 
93  try
94  {
95  my_writer.write(my_mesh, output_file_path);
96  }
97  catch(const std::invalid_argument &e)
98  {
99  std::cerr << "Invalid Argument Exception catch while writing "
100  << output_file_path << " :" << std::endl
101  << e.what() << std::endl;
102  return EXIT_FAILURE;
103  }
104  catch(const std::ios_base::failure &e)
105  {
106  std::cerr << "IOS Failure Exception catch while writing "
107  << output_file_path << " :" << std::endl
108  << e.what() << std::endl;
109  return EXIT_FAILURE;
110  }
111 
112  if(!reference_file_path.empty())
113  {
114  std::cout << "Comparing output file '" << output_file_path
115  << "' with reference file '" << reference_file_path << "'..."
116  << std::endl;
117 
118  if(FEVV::FileUtils::has_extension(output_file_path, ".off") ||
119  FEVV::FileUtils::has_extension(output_file_path, ".coff"))
120  {
121  // use OFF file comparator
122  if(!are_meshes_equal(output_file_path, reference_file_path, false))
123  {
124  std::cout << "Files are different!" << std::endl;
125  return EXIT_FAILURE;
126  }
127  }
128  else
129  {
130  // use text file comparator
131  if(!identical_text_based_files(output_file_path, reference_file_path))
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 
141  return 0;
142 }
FEVV::DataStructures::AIF::AIFMeshWriter
This class represents an AIFMesh object writer. An AIFMeshWriter writes a mesh file (....
Definition: AIFMeshWriter.hpp:37
FEVV::DataStructures::AIF::AIFMeshReader::ptr_output
superclass::ptr_output ptr_output
Definition: AIFMeshReader.hpp:43
FEVV::DataStructures::AIF
Definition: AIFCellContainer.h:15
utils_identical_text_based_files.hpp
FEVV::DataStructures::AIF::AIFMeshReader::read
ptr_output read(const std::string &filePath)
Definition: AIFMeshReader.inl:50
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::DataStructures::AIF::AIFMeshWriter::write
void write(const ptr_input inputMesh, const std::string &filePath)
Definition: AIFMeshWriter.inl:28
AIFMesh.hpp
writer_type
AIFMeshWriter writer_type
Definition: test_reader_writer_aif.cpp:23
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
reader_type
AIFMeshReader reader_type
Definition: test_reader_writer_aif.cpp:22
main
int main(int narg, char **argv)
Definition: test_reader_writer_aif.cpp:26
utils_are_meshes_identical.hpp
FEVV::FileUtils::has_extension
bool has_extension(const std::string &file_name)
Definition: FileUtilities.hpp:58
FEVV::DataStructures::AIF::AIFMeshReader
This class represents an AIFMesh object reader. An AIFMeshReader reads a mesh file (....
Definition: AIFMeshReader.hpp:37
AIFMeshReader.hpp
FileUtilities.hpp
AIFMeshWriter.hpp