#include <iostream>
#include <fstream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/AABB_face_graph_triangle_primitive.h>
#include <CGAL/KDOP_tree/KDOP_tree.h>
#include <CGAL/KDOP_tree/KDOP_traits.h>
const unsigned int NUM_DIRECTIONS = 14;
typedef K::Point_3 Point;
typedef K::Ray_3 Ray;
typedef CGAL::Surface_mesh<Point> Mesh;
typedef boost::optional< Tree_kdop::Intersection_and_primitive_id<Ray>::Type > Ray_intersection;
int main(int argc, char* argv[])
{
if (argc != 2) {
std::cerr << "Need mesh file!" << std::endl;
return 0;
}
const char* filename = argv[1];
std::ifstream input(filename);
Mesh mesh;
input >> mesh;
Point p1(1., 1., 1.);
Point p2(1./3., 1./6., 2./3.);
Ray ray(p1, p2);
Tree_kdop tree_kdop( faces(mesh).first, faces(mesh).second, mesh );
tree_kdop.build();
Ray_intersection
intersection = tree_kdop.first_intersection(ray);
if (intersection) {
const Point* p_kdop = boost::get<Point>( &(intersection->first) );
std::cout << *p_kdop << std::endl;
}
else {
std::cout << "No intersection" << std::endl;
}
return 0;
}