diff --git a/AABB_tree/doc/AABB_tree/aabb_tree.txt b/AABB_tree/doc/AABB_tree/aabb_tree.txt index 4a030061f99..31009ee5bda 100644 --- a/AABB_tree/doc/AABB_tree/aabb_tree.txt +++ b/AABB_tree/doc/AABB_tree/aabb_tree.txt @@ -137,6 +137,19 @@ a segment. We finally compute the first intersection along a ray. \cgalExample{AABB_tree/AABB_polyhedron_facet_intersection_example.cpp} + +\subsection aabb_tree_examples_2 Ray Shooting + +In the following example we load a closed polyhedral surface and perform a +ray shooting query from the centroid of each face, orthogonally to the face +towards the interior. As the centroid is computed with floating point +arithmetic the first face hit by the ray may be the face of the centroid. +The skip functor takes care of ignoring the face. + +\cgalExample{AABB_tree/AABB_ray_shooting_example.cpp} + + + \subsection aabb_tree_examples_3 Tree of Polyhedron Triangle Facets for Distance Queries In the following example the AABB primitive wraps a facet handle of a diff --git a/AABB_tree/doc/AABB_tree/examples.txt b/AABB_tree/doc/AABB_tree/examples.txt index 65e98ceb004..cc274a27469 100644 --- a/AABB_tree/doc/AABB_tree/examples.txt +++ b/AABB_tree/doc/AABB_tree/examples.txt @@ -8,6 +8,7 @@ \example AABB_tree/AABB_polyhedron_facet_distance_example.cpp \example AABB_tree/AABB_polyhedron_facet_intersection_example.cpp \example AABB_tree/AABB_segment_3_example.cpp +\example AABB_tree/AABB_ray_shooting_example.cpp \example AABB_tree/AABB_triangle_3_example.cpp \example AABB_tree/AABB_halfedge_graph_edge_example.cpp \example AABB_tree/AABB_face_graph_triangle_example.cpp diff --git a/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp b/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp index d0a607a0d35..78ff6daa183 100644 --- a/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp +++ b/AABB_tree/examples/AABB_tree/AABB_polyhedron_facet_intersection_example.cpp @@ -58,8 +58,10 @@ int main() if(intersection) { // gets intersection object - if(boost::get(&(intersection->first))) - std::cout << "intersection object is a point" << std::endl; + const Point* p = boost::get(&(intersection->first)) + if(p) + std::cout << "intersection object is a point " << *p << std::endl; + } // computes all intersections with segment query (as pairs object - primitive_id) @@ -83,10 +85,6 @@ int main() if(boost::get(&(plane_intersection->first))) std::cout << "intersection object is a segment" << std::endl; } - - Point inside(0.1, 0.1, 0.1); - Ray ray(inside,r); - tree.first_intersection(ray); return EXIT_SUCCESS; } diff --git a/AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp b/AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp new file mode 100644 index 00000000000..c5023f1ebe7 --- /dev/null +++ b/AABB_tree/examples/AABB_tree/AABB_ray_shooting_example.cpp @@ -0,0 +1,72 @@ +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; +typedef K::FT FT; +typedef K::Point_3 Point; +typedef K::Vector_3 Vector; +typedef K::Ray_3 Ray; + +typedef CGAL::Surface_mesh Mesh; +typedef boost::graph_traits::face_descriptor face_descriptor; +typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; + +typedef CGAL::AABB_face_graph_triangle_primitive Primitive; +typedef CGAL::AABB_traits Traits; +typedef CGAL::AABB_tree Tree; +typedef boost::optional::Type> Ray_intersection; + + +struct Skip { + face_descriptor fd; + + Skip(const face_descriptor fd) + : fd(fd) + {} + + bool operator()(const face_descriptor& t) const + { if(t == fd){ + std::cerr << "ignore" << t < 1) ? argv[1] : "data/tetrahedron.off"; + std::ifstream input(filename); + Mesh mesh; + input >> mesh; + Tree tree(faces(mesh).first, faces(mesh).second, mesh); + + double d = CGAL::Polygon_mesh_processing::is_outward_oriented(mesh)?-1:1; + + BOOST_FOREACH(face_descriptor fd, faces(mesh)){ + halfedge_descriptor hd = halfedge(fd,mesh); + Point p = CGAL::centroid(mesh.point(source(hd,mesh)), + mesh.point(target(hd,mesh)), + mesh.point(target(next(hd,mesh),mesh))); + Vector v = CGAL::Polygon_mesh_processing::compute_face_normal(fd,mesh); + + Ray ray(p,d * v); + Ray_intersection intersection = tree.first_intersection(ray, Skip(fd)); + if(intersection){ + if(boost::get(&(intersection->first))){ + const Point* p = boost::get(&(intersection->first) ); + std::cout << *p << std::endl; + } + } + } + std::cerr << "done" << std::endl; + return 0; +} diff --git a/AABB_tree/examples/AABB_tree/data/tetrahedron.off b/AABB_tree/examples/AABB_tree/data/tetrahedron.off new file mode 100644 index 00000000000..5c641a7849e --- /dev/null +++ b/AABB_tree/examples/AABB_tree/data/tetrahedron.off @@ -0,0 +1,11 @@ +OFF +4 4 0 +0.0 0.0 0.0 +1.0 0.0 0.0 +0.0 1.0 0.0 +0.0 0.0 1.0 +3 0 1 2 +3 0 3 1 +3 0 2 3 +3 1 3 2 + diff --git a/AABB_tree/examples/AABB_tree/AABB_ray_intersection.cpp b/AABB_tree/test/AABB_tree/AABB_ray_intersection.cpp similarity index 100% rename from AABB_tree/examples/AABB_tree/AABB_ray_intersection.cpp rename to AABB_tree/test/AABB_tree/AABB_ray_intersection.cpp