diff --git a/Intersections_3/test/Intersections_3/create_bbox_mesh.h b/Intersections_3/test/Intersections_3/create_bbox_mesh.h new file mode 100644 index 00000000000..6ba58028eb1 --- /dev/null +++ b/Intersections_3/test/Intersections_3/create_bbox_mesh.h @@ -0,0 +1,64 @@ +// used by test_intersections_3.cpp + +#include +#include +#include + +const int cube[][3] = { { 0, 1, 3 }, + { 3, 1, 2 }, + { 0, 4, 1 }, + { 1, 4, 5 }, + { 3, 2, 7 }, + { 7, 2, 6 }, + { 4, 0, 3 }, + { 7, 4, 3 }, + { 6, 4, 7 }, + { 6, 5, 4 }, + { 1, 5, 6 }, + { 2, 1, 6 } }; + +template +struct Build_bbox_mesh : + public CGAL::Modifier_base +{ + CGAL::Bbox_3 bbox; + +public: + Build_bbox_mesh(CGAL::Bbox_3 b) + : bbox(b) + {} + + typedef typename Polyhedron::HalfedgeDS HDS; + + void operator()(HDS& hds) { + CGAL::Polyhedron_incremental_builder_3 B( hds, true); + B.begin_surface( 8, 12, 24); + typedef typename HDS::Vertex Vertex; + typedef typename Vertex::Point Point; + B.add_vertex( Point( bbox.xmin(), bbox.ymin(), bbox.zmin())); // -1 -1 -1 + B.add_vertex( Point( bbox.xmin(), bbox.ymax(), bbox.zmin())); // -1 1 -1 + B.add_vertex( Point( bbox.xmax(), bbox.ymax(), bbox.zmin())); // 1 1 -1 + B.add_vertex( Point( bbox.xmax(), bbox.ymin(), bbox.zmin())); // 1 -1 -1 + B.add_vertex( Point( bbox.xmin(), bbox.ymin(), bbox.zmax())); // -1 -1 1 + B.add_vertex( Point( bbox.xmin(), bbox.ymax(), bbox.zmax())); // -1 1 1 + B.add_vertex( Point( bbox.xmax(), bbox.ymax(), bbox.zmax())); // 1 1 1 + B.add_vertex( Point( bbox.xmax(), bbox.ymin(), bbox.zmax())); // 1 -1 1 + for(int i = 0; i < 12; ++i) { + B.begin_facet(); + B.add_vertex_to_facet( cube[i][0]); + B.add_vertex_to_facet( cube[i][1]); + B.add_vertex_to_facet( cube[i][2]); + B.end_facet(); + } + B.end_surface(); + } +}; + +template +const Polyhedron create_bbox_mesh(const CGAL::Bbox_3& bbox) +{ + Polyhedron result; + Build_bbox_mesh build_bbox(bbox); + result.delegate(build_bbox); + return result; +} diff --git a/Intersections_3/test/Intersections_3/test_intersections_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_3.cpp index b02d362d080..a7fddfac09c 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_3.cpp @@ -7,9 +7,16 @@ #include #include +#include +#include +#include +#include + #include #include +#include "create_bbox_mesh.h" + const double epsilon = 0.001; struct randomint { @@ -467,6 +474,30 @@ struct Test { check_intersection (box,R(P(0, 0.5,0),P(-0.5,0,0))); } + void Bbox_Tr() { + std::cout << "Bbox - Triangle\n"; + + typedef CGAL::Polyhedron_3 Polyhedron; + typedef CGAL::AABB_face_graph_triangle_primitive Primitive; + typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_tree Tree; + + Bbox unit_bbox(-1., -1., -1. + ,1., 1., 1.); + const Polyhedron unit_bbox_poly = create_bbox_mesh(unit_bbox); + const Tree tree(unit_bbox_poly.facets_begin(), + unit_bbox_poly.facets_end(), + unit_bbox_poly); + + const Tr tr(P(-3. , 0. , 0.), + P(-2. , 0.1, 0.), + P(-0.5, 3. , 0.)); + + const bool b = CGAL::do_intersect(unit_bbox, tr); + assert(b == false); + assert(tree.do_intersect(tr) == b); + } + void run() { std::cout << "3D Intersection tests\n"; @@ -486,6 +517,7 @@ struct Test { R_R(); Bbox_L(); Bbox_R(); + Bbox_Tr(); } };