Improved self_intersections tests

This commit is contained in:
Mael Rouxel-Labbé 2016-11-03 11:41:25 +01:00
parent 8c7e45b2eb
commit c2135823a8
4 changed files with 38958 additions and 40 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
OFF
4 2 0
0 0 0
1 0 0
0 1 0
1 1 0
3 0 1 2
3 0 2 3

View File

@ -11,56 +11,70 @@
#include <CGAL/Timer.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Epic;
typedef CGAL::Exact_predicates_exact_constructions_kernel Epec;
typedef CGAL::Exact_predicates_inexact_constructions_kernel Epic;
typedef CGAL::Exact_predicates_exact_constructions_kernel Epec;
template <typename K>
int
test_self_intersections(const char* filename)
test_self_intersections(const char* filename, const bool expected)
{
typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef typename boost::graph_traits<Polyhedron>::face_descriptor face_descriptor;
typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef typename boost::graph_traits<Polyhedron>::face_descriptor face_descriptor;
std::ifstream input(filename);
Polyhedron poly;
if ( !input || !(input >> poly) ){
std::cerr << "Error: can not read file.";
std::cerr << "Error: cannot read file: " << filename << std::endl;
return 1;
}
std::cout << "Reading file: " << filename << std::endl;
CGAL::Timer timer;
timer.start();
std::vector<std::pair<face_descriptor, face_descriptor> > intersected_tris;
CGAL::Polygon_mesh_processing::self_intersections
(poly,
std::back_inserter(intersected_tris),
CGAL::Polygon_mesh_processing::parameters::vertex_index_map(get(CGAL::vertex_point, poly)));
CGAL::Polygon_mesh_processing::self_intersections(
poly,
std::back_inserter(intersected_tris),
CGAL::Polygon_mesh_processing::parameters::vertex_index_map(get(CGAL::vertex_point, poly)));
bool intersecting_1 = !intersected_tris.empty();
assert(!intersecting_1);
std::cerr << "Self-intersection test took " << timer.time() << " sec." << std::endl;
std::cerr << intersected_tris.size() << " pairs of triangles intersect." << std::endl;
std::cout << "Self-intersection test took " << timer.time() << " sec." << std::endl;
std::cout << intersected_tris.size() << " pairs of triangles intersect." << std::endl;
timer.reset();
bool intersecting_2 =
CGAL::Polygon_mesh_processing::does_self_intersect(poly,
bool intersecting_2 = CGAL::Polygon_mesh_processing::does_self_intersect(poly,
CGAL::Polygon_mesh_processing::parameters::vertex_index_map(get(CGAL::vertex_point, poly)));
assert(intersecting_1 == intersecting_2);
std::cout << "does_self_intersect test took " << timer.time() << " sec." << std::endl;
std::cout << (intersecting_2 ? "There is a self-intersection." :
"There are no self-intersections.") << std::endl;
assert(intersecting_1 == intersecting_2);
assert(intersecting_1 == expected);
std::cout << filename << " passed the tests." << std::endl << std::endl;
std::cerr << "does_self_intersect test took " << timer.time() << " sec." << std::endl;
std::cerr
<< (intersecting_2 ? "There is a self-intersection." : "There are no self-intersections.")
<< std::endl;
return 0;
}
int main(int argc, char** argv)
{
const char* filename = (argc > 1) ? argv[1] : "data/elephant.off";
int r = test_self_intersections<Epic>(filename);
r += test_self_intersections<Epec>(filename);
const char* filename_ele = (argc > 1) ? argv[1] : "data/elephant.off";
const char* filename_man = (argc > 2) ? argv[2] : "data/mannequin-devil.off";
const char* filename_ove = (argc > 3) ? argv[3] : "data/overlapping_triangles.off";
std::cout << "Testing with Epic:" << std::endl;
int r = test_self_intersections<Epic>(filename_ele, false);
r += test_self_intersections<Epic>(filename_man, true);
r += test_self_intersections<Epic>(filename_ove, true);
std::cout << "Testing with Epec:" << std::endl;
r += test_self_intersections<Epec>(filename_ele, false);
r += test_self_intersections<Epec>(filename_man, true);
r += test_self_intersections<Epec>(filename_ove, true);
return r;
}

View File

@ -2,19 +2,24 @@
#include <fstream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/self_intersections.h>
#include <CGAL/Timer.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Surface_mesh<K::Point_3> Mesh;
typedef boost::graph_traits<Mesh>::face_descriptor face_descriptor;
typedef CGAL::Exact_predicates_inexact_constructions_kernel Epic;
typedef CGAL::Exact_predicates_exact_constructions_kernel Epec;
int main(int argc, char** argv)
template <typename K>
int
test_self_intersections(const char* filename, const bool expected)
{
const char* filename = (argc > 1) ? argv[1] : "data/elephant.off";
typedef CGAL::Surface_mesh<typename K::Point_3> Mesh;
typedef typename boost::graph_traits<Mesh>::face_descriptor face_descriptor;
std::ifstream input(filename);
Mesh m;
@ -22,30 +27,53 @@ int main(int argc, char** argv)
std::cerr << "Error: can not read file.";
return 1;
}
std::cout << "Reading file: " << filename << std::endl;
CGAL::Timer timer;
timer.start();
std::vector<std::pair<face_descriptor, face_descriptor> > intersected_tris;
CGAL::Polygon_mesh_processing::self_intersections(m,
CGAL::Polygon_mesh_processing::self_intersections(
m,
std::back_inserter(intersected_tris),
CGAL::Polygon_mesh_processing::parameters::vertex_index_map(get(CGAL::vertex_point, m)));
bool intersecting_1 = !intersected_tris.empty();
assert(!intersecting_1);
std::cerr << "self_intersections test took " << timer.time() << " sec." << std::endl;
std::cerr << intersected_tris.size() << " pairs of triangles are intersecting." << std::endl;
std::cout << "self_intersections test took " << timer.time() << " sec." << std::endl;
std::cout << intersected_tris.size() << " pairs of triangles are intersecting." << std::endl;
timer.reset();
bool intersecting_2 = CGAL::Polygon_mesh_processing::does_self_intersect(m,
CGAL::Polygon_mesh_processing::parameters::vertex_index_map(get(CGAL::vertex_point, m)));
assert(intersecting_1 == intersecting_2);
std::cerr << "does_self_intersect test took " << timer.time() << " sec." << std::endl;
std::cerr
<< (intersecting_2 ? "There is a self-intersection." : "There are no self-intersections.")
<< std::endl;
std::cerr << (intersecting_2 ? "There is a self-intersection." :
"There are no self-intersections.") << std::endl;
assert(intersecting_1 == intersecting_2);
assert(intersecting_1 == expected);
std::cout << filename << " passed the tests." << std::endl << std::endl;
return 0;
}
int main(int argc, char** argv)
{
const char* filename_ele = (argc > 1) ? argv[1] : "data/elephant.off";
const char* filename_man = (argc > 2) ? argv[2] : "data/mannequin-devil.off";
const char* filename_ove = (argc > 3) ? argv[3] : "data/overlapping_triangles.off";
std::cout << "Testing with Epic:" << std::endl;
int r = test_self_intersections<Epic>(filename_ele, false);
r += test_self_intersections<Epic>(filename_man, true);
r += test_self_intersections<Epic>(filename_ove, true);
std::cout << "Testing with Epec:" << std::endl;
r += test_self_intersections<Epec>(filename_ele, false);
r += test_self_intersections<Epec>(filename_man, true);
r += test_self_intersections<Epec>(filename_ove, true);
return r;
}