MEPP2 Project
test_boolean_operations_polyhedron.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 General Public License as published
6 // by the Free Software Foundation; either version 3 of the License,
7 // 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 
18 
20 
22 
23 
24 int usage_and_exit(const char **argv)
25 {
26  std::cout << "Apply boolean union, intersection or subtraction"
27  " on two meshes."
28  << std::endl;
29  std::cout << "Usage: "
30  << argv[0]
31  << " union|inter|minus mesh_file_1 mesh_file_2"
32  " [reference_mesh_file]"
33  << std::endl;
34  std::cout << "Example: "
35  << argv[0]
36  << " union"
37  " ../Testing/Data/CubeTriangleFaces.off"
38  " ../Testing/Data/tetra.off"
39  " ../Testing/Data/boolean_operations/mepp1_cube_tetra_union.off"
40  << std::endl;
41 
42  return EXIT_FAILURE;
43 }
44 
45 
46 int main(int argc, const char **argv)
47 {
48  // check arguments
49  if(argc < 4 || argc > 5)
50  return usage_and_exit(argv);
51 
52  // check operation
53  std::string operation = argv[1];
54  if(operation != "union" && operation != "inter" && operation != "minus")
55  return usage_and_exit(argv);
56 
57  // input and output files
58  std::string input_file_1 = argv[2];
59  std::string input_file_2 = argv[3];
60  std::string reference_file;
61  if(argc == 5)
62  reference_file = argv[4];
63  std::string output_file =
64  "test_boolean_operations_polyhedron_" + operation + ".off";
65 
66  // display parameters summary
67  std::cout << "\nParameters summary:" << std::endl;
68  std::cout << " - operation : " << operation << std::endl;
69  std::cout << " - input file 1 : " << input_file_1 << std::endl;
70  std::cout << " - input file 2 : " << input_file_2 << std::endl;
71  std::cout << " - reference file: " << reference_file << std::endl;
72  std::cout << "\nOutput in " << output_file << std::endl;
73 
74  // read input meshes from files
76  FEVV::PMapsContainer pmaps_bag_1;
77  FEVV::Filters::read_mesh(input_file_1, m1, pmaps_bag_1);
79  FEVV::PMapsContainer pmaps_bag_2;
80  FEVV::Filters::read_mesh(input_file_2, m2, pmaps_bag_2);
81 
82  // create output mesh
84  FEVV::PMapsContainer pmaps_bag_out;
85 
86  // apply filter, result in m_out
87  std::cout << "Running boolean operation" + operation + "..." << std::endl;
88  if(operation == "union")
89  FEVV::Filters::boolean_union(m1, m2, m_out);
90  else if(operation == "inter")
91  FEVV::Filters::boolean_inter(m1, m2, m_out);
92  else
93  FEVV::Filters::boolean_minus(m1, m2, m_out);
94 
95  // write result to file
96  FEVV::Filters::write_mesh(output_file, m_out, pmaps_bag_out);
97 
98  // compare output to reference
99  if(reference_file.empty())
100  {
101  std::cout << "No reference file provided, skipping result check."
102  << std::endl;
103  }
104  else
105  {
106  std::cout << "Checking result with reference file..." << std::endl;
107  bool is_result_ok = are_meshes_equal(reference_file,
108  output_file,
109  false, /*verbose*/
110  1e-5f,
111  true); /*relative error*/
112  if(is_result_ok)
113  {
114  std::cout << "Boolean operation " + operation + " successfully tested."
115  << std::endl;
116  }
117  else
118  {
119  std::cout << "Boolean operation " + operation + " FAILED!" << std::endl;
120  return EXIT_FAILURE;
121  }
122  }
123 
124  return 0;
125 }
boolean_operations.hpp
generic_reader.hpp
FEVV::Filters::boolean_union
void boolean_union(HalfedgeGraph &gA, HalfedgeGraph &gB, HalfedgeGraph &g_out, const GeometryTraits &)
Computes the union of two polyhedra.
Definition: boolean_operations.hpp:46
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
Geometry_traits_cgal_polyhedron_3.h
properties_polyhedron_3.h
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::boolean_inter
void boolean_inter(HalfedgeGraph &gA, HalfedgeGraph &gB, HalfedgeGraph &g_out, const GeometryTraits &)
Computes the intersection of two polyhedra.
Definition: boolean_operations.hpp:115
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
main
int main(int argc, const char **argv)
Definition: test_boolean_operations_polyhedron.cpp:46
utils_are_meshes_identical.hpp
FEVV::Filters::boolean_minus
void boolean_minus(HalfedgeGraph &gA, HalfedgeGraph &gB, HalfedgeGraph &g_out, const GeometryTraits &)
Computes the subtraction of two polyhedra.
Definition: boolean_operations.hpp:184
FEVV::MeshPolyhedron
CGAL::Polyhedron_3< CGALKernel, CGAL::Polyhedron_items_with_id_3 > MeshPolyhedron
Definition: DataStructures_cgal_polyhedron_3.h:33
usage_and_exit
int usage_and_exit(const char **argv)
Definition: test_boolean_operations_polyhedron.cpp:24
DataStructures_cgal_polyhedron_3.h