#include <iostream>
#include <list>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
struct My_point {
double m_x;
double m_y;
double m_z;
My_point(const double x,
const double y,
const double z)
: m_x(x), m_y(y), m_z(z) {}
};
struct My_triangle {
My_point *m_pa;
My_point *m_pb;
My_point *m_pc;
My_triangle(My_point *pa,
My_point *pb,
My_point *pc)
: m_pa(pa), m_pb(pb), m_pc(pc) {}
};
typedef std::vector<My_triangle>::const_iterator
Iterator;
struct My_triangle_primitive {
public:
typedef const My_triangle* Id;
typedef K::Point_3 Point;
typedef K::Triangle_3 Datum;
private:
Id m_pt;
public:
My_triangle_primitive() {}
: m_pt(&(*it)) {}
const Id& id() const { return m_pt; }
Point convert(const My_point *p) const
{
return Point(p->m_x,p->m_y,p->m_z);
}
Datum datum() const
{
return Datum(convert(m_pt->m_pa),
convert(m_pt->m_pb),
convert(m_pt->m_pc));
}
Point reference_point() const
{ return convert(m_pt->m_pa); }
};
int main()
{
My_point a(1.0, 0.0, 0.0);
My_point b(0.0, 1.0, 0.0);
My_point c(0.0, 0.0, 1.0);
My_point d(0.0, 0.0, 0.0);
std::vector<My_triangle> triangles;
triangles.push_back(My_triangle(&a,&b,&c));
triangles.push_back(My_triangle(&a,&b,&d));
triangles.push_back(My_triangle(&a,&d,&c));
Tree tree(triangles.begin(),triangles.end());
K::Ray_3 ray_query(K::Point_3(1.0, 0.0, 0.0), K::Point_3(0.0, 1.0, 0.0));
std::cout << tree.number_of_intersected_primitives(ray_query)
<< " intersections(s) with ray query" << std::endl;
K::Point_3 point_query(2.0, 2.0, 2.0);
K::Point_3 closest_point = tree.closest_point(point_query);
std::cerr << "closest point is: " << closest_point << std::endl;
return EXIT_SUCCESS;
}