#include <iostream>
#include <vector>
#include <boost/iterator.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<My_point>::const_iterator Point_iterator;
class Triangle_iterator
: public boost::iterator_adaptor<
Triangle_iterator
, Point_iterator
, boost::use_default
, boost::forward_traversal_tag
>
{
public:
Triangle_iterator()
: Triangle_iterator::iterator_adaptor_() {}
explicit Triangle_iterator(Point_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;
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_iterator p_it = m_it.base();
Point p(p_it->x, p_it->y, p_it->z);
++p_it;
Point q(p_it->x, p_it->y, p_it->z);
++p_it;
Point r(p_it->x, p_it->y, p_it->z);
return Datum(p, q, r);
}
Point reference_point() const
{
return Point(m_it->x, m_it->y, m_it->z);
}
};
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> triangles;
triangles.push_back(a); triangles.push_back(b); triangles.push_back(c);
triangles.push_back(a); triangles.push_back(b); triangles.push_back(d);
triangles.push_back(a); triangles.push_back(d); triangles.push_back(c);
Tree tree(Triangle_iterator(triangles.begin()),
Triangle_iterator(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;
}