diff --git a/AABB_tree/include/CGAL/AABB_search_tree.h b/AABB_tree/include/CGAL/AABB_search_tree.h index 7b57abfff0a..0586a4f1172 100644 --- a/AABB_tree/include/CGAL/AABB_search_tree.h +++ b/AABB_tree/include/CGAL/AABB_search_tree.h @@ -15,7 +15,7 @@ // $Id: AABB_tree.h 48894 2009-04-24 14:11:17Z palliez $ // // -// Author(s) : Pierre Alliez +// Author(s) : Pierre Alliez #ifndef CGAL_AABB_SEARCH_TREE_H #define CGAL_AABB_SEARCH_TREE_H @@ -25,7 +25,6 @@ namespace CGAL { - template class AABB_search_tree { @@ -35,10 +34,8 @@ namespace CGAL typedef typename CGAL::Search_traits_3 TreeTraits; typedef typename CGAL::Orthogonal_k_neighbor_search Neighbor_search; typedef typename Neighbor_search::Tree Tree; - private: Tree m_tree; - public: AABB_search_tree() {} ~AABB_search_tree() {} @@ -51,7 +48,6 @@ namespace CGAL Point nearest_point(const Point& query) { - // queries first nearest neighbor Neighbor_search search(m_tree, query, 1); return search.begin()->first; } diff --git a/AABB_tree/include/CGAL/AABB_tree.h b/AABB_tree/include/CGAL/AABB_tree.h index 2b296d8ee8d..8659e99a9fb 100644 --- a/AABB_tree/include/CGAL/AABB_tree.h +++ b/AABB_tree/include/CGAL/AABB_tree.h @@ -16,7 +16,7 @@ // $Id$ // // -// Author(s) : Camille Wormser, Pierre Alliez, Laurent Rineau, Stephane Tayeb +// Author(s) : Camille Wormser, Pierre Alliez, Laurent Rineau, Stephane Tayeb #ifndef CGAL_AABB_TREE_H #define CGAL_AABB_TREE_H @@ -42,10 +42,10 @@ namespace CGAL { public: /// Traits types typedef typename AABBTraits::Primitive Primitive; - typedef typename AABBTraits::Bounding_box Bounding_box; - typedef typename AABBTraits::Projection_query Projection_query; typedef typename AABBTraits::Projection Projection; + typedef typename AABBTraits::Bounding_box Bounding_box; typedef typename AABBTraits::Intersection Intersection; + typedef typename AABBTraits::Projection_query Projection_query; private: typedef typename AABB_search_tree Search_tree; @@ -69,9 +69,8 @@ namespace CGAL { template void construct_search_tree(ConstPointIterator first, ConstPointIterator beyond); - /// Construct internal search tree from a point set taken on - // the internal primitives - void construct_search_tree(); + /// Construct internal search tree from a point set taken on the internal primitives + void construct_search_tree(void); template bool do_intersect(const Query& q) const; @@ -295,17 +294,13 @@ namespace CGAL { private: - // member data - - // set of input primitives (halfedge or face handles) + // set of input primitives std::vector m_data; // single root node Node* m_p_root; - // single root node - bool m_search_tree_constructed; - - public: + // search KD-tree Search_tree m_search_tree; + bool m_search_tree_constructed; private: // Disabled copy constructor & assignment operator @@ -332,9 +327,11 @@ namespace CGAL { } m_p_root = new Node[m_data.size()-1](); + CGAL_assertion(m_p_root != NULL); m_p_root->expand(m_data.begin(), m_data.end(), m_data.size()); } + // constructs the search KD tree from given points template template void @@ -345,13 +342,14 @@ namespace CGAL { m_search_tree_constructed = true; } + // constructs the search KD tree from interal primitives template - void AABB_tree::construct_search_tree() + void AABB_tree::construct_search_tree(void) { // iterate over primitives to get points on them std::list points; std::vector::const_iterator it; - for(it = m_data.begin();it != m_data.end();it++) + for(it = m_data.begin(); it != m_data.end(); it++) { const Primitive& pr = *it; points.push_back(pr.point_on()); @@ -378,8 +376,6 @@ namespace CGAL { return traversal_traits.is_intersection_found(); } - - template template int @@ -435,7 +431,6 @@ namespace CGAL { return traversal_traits.is_intersection_found(); } - // closest point with user-specified hint template typename AABB_tree::Projection @@ -448,12 +443,13 @@ namespace CGAL { return traversal_traits.projection(); } - // closest point without hint + // closest point without hint, the search KD-tree is queried for the + // first nearest neighbor point to get a hint template typename AABB_tree::Projection AABB_tree::closest_point(const Projection_query& query) { - // construct search tree if needed + // construct search KD-tree if needed if(!m_search_tree_constructed) construct_search_tree(); diff --git a/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp b/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp index 504d14d766e..cfa104813db 100644 --- a/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp @@ -22,93 +22,149 @@ // //****************************************************************************** -#include #include +#include + #include -#include -#include + +#include +#include +#include + #include #include + +#include +#include #include -#include + +template +void test_all_query_types(Tree& tree) +{ + std::cout << "Test all query types" << std::endl; + + typedef K::FT FT; + typedef K::Ray_3 Ray; + typedef K::Line_3 Line; + typedef K::Point_3 Point; + typedef K::Vector_3 Vector; + typedef K::Segment_3 Segment; + typedef Tree::Primitive Primitive; + typedef Tree::Intersection Intersection; + + Point p((FT)-0.5, (FT)-0.5, (FT)-0.5); + Point q((FT) 0.5, (FT) 0.5, (FT) 0.5); + Ray ray(p,q); + Ray line(p,q); + Ray segment(p,q); + bool success = false; + + // do_intersect + success = tree.do_intersect(ray); + success = tree.do_intersect(line); + success = tree.do_intersect(segment); + + // number_of_intersections + tree.number_of_intersections(ray); + tree.number_of_intersections(line); + tree.number_of_intersections(segment); + + // all_intersected_primitives + std::list primitives; + tree.all_intersected_primitives(ray,std::back_inserter(primitives)); + tree.all_intersected_primitives(line,std::back_inserter(primitives)); + tree.all_intersected_primitives(segment,std::back_inserter(primitives)); + + // any_intersection + Intersection intersection; + success = tree.any_intersection(ray,intersection); + success = tree.any_intersection(line,intersection); + success = tree.any_intersection(segment,intersection); + + // all_intersections + std::list intersections; + tree.all_intersections(ray,std::back_inserter(intersections)); + tree.all_intersections(line,std::back_inserter(intersections)); + tree.all_intersections(segment,std::back_inserter(intersections)); +} template void test_speed(Tree& tree, Polyhedron& polyhedron) { - typedef K::FT FT; - typedef K::Ray_3 Ray; - typedef K::Point_3 Point; - typedef K::Vector_3 Vector; + std::cout << "Test for speed" << std::endl; + typedef K::FT FT; + typedef K::Ray_3 Ray; + typedef K::Point_3 Point; + typedef K::Vector_3 Vector; - CGAL::Timer timer; - unsigned int nb = 0; - timer.start(); - Point source((FT)0.0, (FT)0.0, (FT)0.0); - Vector vec((FT)0.1, (FT)0.2, (FT)0.3); - Ray ray(source, vec); - while(timer.time() < 1.0) - { - tree.do_intersect(ray); - nb++; - } - double speed = (double)nb / timer.time(); - std::cout << speed << " intersections/s" << std::endl; - timer.stop(); + CGAL::Timer timer; + unsigned int nb = 0; + timer.start(); + Point source((FT)0.0, (FT)0.0, (FT)0.0); + Vector vec((FT)0.1, (FT)0.2, (FT)0.3); + Ray ray(source, vec); + while(timer.time() < 1.0) + { + tree.do_intersect(ray); + nb++; + } + double speed = (double)nb / timer.time(); + std::cout << speed << " intersections/s" << std::endl; + timer.stop(); } template void test(const char *filename) { - typedef K::FT FT; - typedef K::Ray_3 Ray; - typedef K::Point_3 Point; - typedef K::Vector_3 Vector; - typedef CGAL::Polyhedron_3 Polyhedron; - typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; - typedef CGAL::AABB_tree Tree; + typedef K::FT FT; + typedef K::Ray_3 Ray; + typedef K::Point_3 Point; + typedef K::Vector_3 Vector; + typedef CGAL::Polyhedron_3 Polyhedron; + typedef CGAL::AABB_polyhedron_triangle_primitive Primitive; + typedef CGAL::AABB_traits Traits; + typedef CGAL::AABB_tree Tree; - Polyhedron polyhedron; - std::ifstream ifs(filename); - ifs >> polyhedron; + // load (triangle) polyhedral surface + Polyhedron polyhedron; + std::ifstream ifs(filename); + ifs >> polyhedron; - // construct tree without internal KD-tree as we do not query - // any projection. - Tree tree(polyhedron.facets_begin(),polyhedron.facets_end()); + // construct tree (without internal KD-tree as we do not query any projection). + Tree tree(polyhedron.facets_begin(),polyhedron.facets_end()); - // TODO - // - compare tree tests with exhaustive ones - // - query with ray/line/segment - - Point source((FT)0.5, (FT)0.5, (FT)0.5); - Ray ray(source, Vector((FT)0.1, (FT)0.2, (FT)0.3)); - std::cout << tree.number_of_intersections(ray) - << " intersections(s) with ray" << std::endl; - - test_speed(tree,polyhedron); + // call tests + test_all_query_types(tree); + test_speed(tree,polyhedron); } -void test_kernels(const char *filename) +void test_several_kernels(const char *filename) { - std::cout << std::endl; - std::cout << "Polyhedron " << filename << std::endl; + std::cout << std::endl; + std::cout << "Polyhedron " << filename << std::endl; - std::cout << "Simple cartesian float kernel" << std::endl; - test >(filename); + std::cout << "Simple cartesian float kernel" << std::endl; + test >(filename); - std::cout << "Simple cartesian double kernel" << std::endl; - test >(filename); + std::cout << "Cartesian float kernel" << std::endl; + test >(filename); - std::cout << "Epic kernel" << std::endl; - test(filename); + std::cout << "Simple cartesian double kernel" << std::endl; + test >(filename); + + std::cout << "Cartesian double kernel" << std::endl; + test >(filename); + + std::cout << "Epic kernel" << std::endl; + test(filename); } int main(void) { - std::cout << "AABB intersection tests" << std::endl; - test_kernels("../data/cube.off"); - test_kernels("../data/coverrear.off"); - test_kernels("../data/nested_spheres.off"); - return 0; + std::cout << "AABB intersection tests" << std::endl; + test_several_kernels("../data/cube.off"); + test_several_kernels("../data/coverrear.off"); + test_several_kernels("../data/nested_spheres.off"); + return 0; } \ No newline at end of file