#include <iostream>
#include <list>
#include <boost/iterator/iterator_adaptor.hpp>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
struct My_point {
double x;
double y;
double z;
My_point (double _x, double _y, double _z)
: x(_x), y(_y), z(_z) {}
};
typedef std::vector<size_t>::const_iterator Point_index_iterator;
class Triangle_iterator
: public boost::iterator_adaptor<
Triangle_iterator
, Point_index_iterator
, boost::use_default
, boost::forward_traversal_tag
>
{
public:
Triangle_iterator()
: Triangle_iterator::iterator_adaptor_() {}
explicit Triangle_iterator(Point_index_iterator p)
: Triangle_iterator::iterator_adaptor_(p) {}
private:
friend class boost::iterator_core_access;
void increment() { this->base_reference() += 3; }
};
struct My_triangle_primitive {
public:
typedef Triangle_iterator Id;
typedef K::Point_3 Point;
typedef K::Triangle_3 Datum;
static const std::vector<My_point>* point_container;
private:
Id m_it;
public:
My_triangle_primitive() {}
My_triangle_primitive(Triangle_iterator a)
: m_it(a) {}
Id id() const { return m_it; }
Datum datum() const
{
Point_index_iterator p_it = m_it.base();
const My_point& mp = (*point_container)[*p_it];
Point p(mp.x, mp.y, mp.z);
++p_it;
const My_point& mq = (*point_container)[*p_it];
Point q(mq.x, mq.y, mq.z);
++p_it;
const My_point& mr = (*point_container)[*p_it];
Point r(mr.x, mr.y, mr.z);
return Datum(p, q, r);
}
Point reference_point() const
{
const My_point& mp = (*point_container)[*m_it];
return Point(mp.x, mp.y, mp.z);
}
};
const std::vector<My_point>* My_triangle_primitive::point_container = 0;
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_point> points;
My_triangle_primitive::point_container = &points;
points.push_back(a);
points.push_back(b);
points.push_back(c);
points.push_back(d);
std::vector<size_t> triangles;
triangles.push_back(0); triangles.push_back(1); triangles.push_back(2);
triangles.push_back(0); triangles.push_back(1); triangles.push_back(3);
triangles.push_back(0); triangles.push_back(3); triangles.push_back(2);
Tree tree(Triangle_iterator(triangles.begin()),
Triangle_iterator(triangles.end()));
K::Ray_3 ray_query(K::Point_3(0.2, 0.2, 0.2), 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;
}