mirror of https://github.com/CGAL/cgal
Add a trivial test case for do_intersect(Bbox_3,Triangle_3)
This commit is contained in:
parent
ad798d8390
commit
aa219ea69a
|
|
@ -0,0 +1,64 @@
|
||||||
|
// used by test_intersections_3.cpp
|
||||||
|
|
||||||
|
#include <CGAL/Modifier_base.h>
|
||||||
|
#include <CGAL/Bbox_3.h>
|
||||||
|
#include <CGAL/Polyhedron_incremental_builder_3.h>
|
||||||
|
|
||||||
|
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 <typename Polyhedron>
|
||||||
|
struct Build_bbox_mesh :
|
||||||
|
public CGAL::Modifier_base<typename Polyhedron::HalfedgeDS>
|
||||||
|
{
|
||||||
|
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<HDS> 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 <typename Polyhedron>
|
||||||
|
const Polyhedron create_bbox_mesh(const CGAL::Bbox_3& bbox)
|
||||||
|
{
|
||||||
|
Polyhedron result;
|
||||||
|
Build_bbox_mesh<Polyhedron> build_bbox(bbox);
|
||||||
|
result.delegate(build_bbox);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
@ -7,9 +7,16 @@
|
||||||
#include <CGAL/Homogeneous.h>
|
#include <CGAL/Homogeneous.h>
|
||||||
#include <CGAL/MP_Float.h>
|
#include <CGAL/MP_Float.h>
|
||||||
|
|
||||||
|
#include <CGAL/AABB_tree.h>
|
||||||
|
#include <CGAL/AABB_traits.h>
|
||||||
|
#include <CGAL/AABB_face_graph_triangle_primitive.h>
|
||||||
|
#include <CGAL/Polyhedron_3.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "create_bbox_mesh.h"
|
||||||
|
|
||||||
const double epsilon = 0.001;
|
const double epsilon = 0.001;
|
||||||
|
|
||||||
struct randomint {
|
struct randomint {
|
||||||
|
|
@ -467,6 +474,30 @@ struct Test {
|
||||||
check_intersection<S> (box,R(P(0, 0.5,0),P(-0.5,0,0)));
|
check_intersection<S> (box,R(P(0, 0.5,0),P(-0.5,0,0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bbox_Tr() {
|
||||||
|
std::cout << "Bbox - Triangle\n";
|
||||||
|
|
||||||
|
typedef CGAL::Polyhedron_3<K> Polyhedron;
|
||||||
|
typedef CGAL::AABB_face_graph_triangle_primitive<const Polyhedron> Primitive;
|
||||||
|
typedef CGAL::AABB_traits<K, Primitive> Traits;
|
||||||
|
typedef CGAL::AABB_tree<Traits> Tree;
|
||||||
|
|
||||||
|
Bbox unit_bbox(-1., -1., -1.
|
||||||
|
,1., 1., 1.);
|
||||||
|
const Polyhedron unit_bbox_poly = create_bbox_mesh<Polyhedron>(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()
|
void run()
|
||||||
{
|
{
|
||||||
std::cout << "3D Intersection tests\n";
|
std::cout << "3D Intersection tests\n";
|
||||||
|
|
@ -486,6 +517,7 @@ struct Test {
|
||||||
R_R();
|
R_R();
|
||||||
Bbox_L();
|
Bbox_L();
|
||||||
Bbox_R();
|
Bbox_R();
|
||||||
|
Bbox_Tr();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue