On the CGAL webpage you are greeted with this short example:
CGAL::AABB_tree tree(faces(surface_mesh));
In all surface_mesh and AABBTree documentation examples this line is not used, so I wonder how I have to configure the AABB traits to make that example possible. My own approach does not compile:
#include <CGAL/AABB_face_graph_triangle_primitive.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_triangle_primitive.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <fstream>
#include <iostream>
#include <list>
typedef CGAL::Simple_cartesian<double> Kernel;
typedef Kernel::FT FT;
typedef Kernel::Ray_3 Ray;
typedef Kernel::Line_3 Line;
typedef Kernel::Point_3 Point;
typedef CGAL::Surface_mesh<Point> SMesh;
typedef CGAL::AABB_face_graph_triangle_primitive<SMesh> Primitive;
typedef CGAL::AABB_traits<Kernel, Primitive> AABB_Mesh_Traits;
typedef CGAL::AABB_tree<AABB_Mesh_Traits> AABBTree;
int main( const int argc, const char* argv[] )
{
const char* filename = ( argc > 1 ) ? argv[1] : "model.obj";
std::ifstream input( filename );
SMesh mesh;
input >> mesh;
AABBTree tree( faces( mesh ) );
Point a( 1.0, 0.0, 0.0 );
Point b( 0.0, 1.0, 0.0 );
Ray ray_query( a, b );
std::cout << tree.number_of_intersected_primitives( ray_query )
<< " intersections(s) with ray query" << std::endl;
return EXIT_SUCCESS;
}
The compiler error is:
no matching constructor for initialization of 'AABBTree'
(aka 'AABB_tree<AABB_traits<Simple_cartesian<double>,
AABB_face_graph_triangle_primitive<
Surface_mesh<Point_3<CGAL::Simple_cartesian<double> > > > > >')
It should be tree(faces(mesh).first, faces(mesh).second, mesh)
.
Note that in the User Manual you find a real example that uses
the complete syntax. This example comes with the library in the
the directory examples/AABB_tree