diff --git a/AABB_tree/include/CGAL/AABB_intersections.h b/AABB_tree/include/CGAL/AABB_intersections.h index 2fcdd144ce4..2b092ca29d8 100644 --- a/AABB_tree/include/CGAL/AABB_intersections.h +++ b/AABB_tree/include/CGAL/AABB_intersections.h @@ -14,3 +14,5 @@ #include #include #include + +#include diff --git a/AABB_tree/include/CGAL/AABB_traits.h b/AABB_tree/include/CGAL/AABB_traits.h index aa27d4628ec..d0fd038cfba 100644 --- a/AABB_tree/include/CGAL/AABB_traits.h +++ b/AABB_tree/include/CGAL/AABB_traits.h @@ -134,15 +134,18 @@ public: Sphere sphere(const Projection_query& center, const Projection& hint) const { - return Sphere(center, GeomTraits().compute_squared_distance_3_object() - (center, hint)); + return GeomTraits().construct_sphere_3_object() + (center, GeomTraits().compute_squared_distance_3_object()(center, hint)); } - bool intersection(const Sphere& sphere, - const Primitive& pr, - Projection& projection_return) const; - - bool is_contained(const Sphere& a, const Sphere& b) const; + template + Projection nearest_point(const Query& q, + const Primitive& pr, + const Projection& bound) const + { + return CGAL::nearest_point_3(q, pr.datum(), bound); + //return GeomTraits().nearest_point_3_object()(q, pr.datum(), bound); + } private: /** @@ -171,6 +174,7 @@ private: }; // end class AABB_traits + template template void @@ -234,50 +238,6 @@ AABB_traits::intersection(const Query& q, } -// PA: CAREFUL: the ad-hoc code here must be removed. - -template -bool -AABB_traits::intersection(const Sphere& sphere, - const P& pr, - Projection& projected) const -{ - typedef typename P::Datum Triangle_3; - - const Triangle_3 triangle = pr.datum(); - projected = triangle.supporting_plane().projection(sphere.center()); - - // If point is projected outside sphere, return false - if ( sphere.bounded_side(projected) == CGAL::ON_UNBOUNDED_SIDE ) - { - return false; - } - - if( is_inside_triangle_3(projected, triangle) ) // projected is modified - { - return true; - } - - if(sphere.bounded_side(projected) == CGAL::ON_UNBOUNDED_SIDE) - { - return false; - } - - return true; -} - - -template -bool -AABB_traits::is_contained(const Sphere& a, const Sphere& b) const -{ - CGAL_precondition(a.center() == b.center()); - - return ( GT().compute_squared_radius_3_object()(a) - < GT().compute_squared_radius_3_object()(b) ); -} - - //------------------------------------------------------- // Private methods @@ -314,56 +274,6 @@ AABB_traits::longest_axis(const Bounding_box& bbox) const } } -// PA: ad-hoc code to be removed -template -bool -AABB_traits::is_inside_triangle_3(Point_3& p, - const Triangle_3& t) const -{ - typedef typename GT::Vector_3 Vector; - typedef typename GT::Line_3 Line; - - Vector w = CGAL::cross_product(t.vertex(1) - t.vertex(0), - t.vertex(2) - t.vertex(0)); - bool out = false; - for(int i = 0; i < 3; ++i) - { - Vector v = CGAL::cross_product(t.vertex(i+1) - t.vertex(i), - p - t.vertex(i)); - if(v*w < 0) - { // p is outside, on the side of (i, i+1) - out = true; - if( (p - t.vertex(i))*(t.vertex(i+1) - t.vertex(i)) >= 0 - && (p - t.vertex(i+1))*(t.vertex(i) - t.vertex(i+1)) >= 0 ) - { - p = Line(t.vertex(i), t.vertex(i+1)).projection(p); - return false; - } - } - } - - if(out) - { - typename GT::Compare_distance_3 c = GT().compare_distance_3_object(); - if(c(p, t.vertex(1), t.vertex(0)) == CGAL::LARGER && - c(p, t.vertex(2), t.vertex(0)) == CGAL::LARGER) - { - p = t.vertex(0); - return false; - } - if(c(p, t.vertex(0), t.vertex(1)) == CGAL::LARGER && - c(p, t.vertex(2), t.vertex(1)) == CGAL::LARGER) - { - p = t.vertex(1); - return false; - } - p = t.vertex(2); - return false; - } - - return true; -} - } // end namespace CGAL diff --git a/AABB_tree/include/CGAL/AABB_tree.h b/AABB_tree/include/CGAL/AABB_tree.h index 491525e81ce..0b647ac5ddb 100644 --- a/AABB_tree/include/CGAL/AABB_tree.h +++ b/AABB_tree/include/CGAL/AABB_tree.h @@ -254,26 +254,14 @@ namespace CGAL { Projecting_traits(const Projection_query& query, const Projection& hint) : projection_(hint) - , center_(query) , sphere_(AABBTraits().sphere(query,hint)) { } bool go_further() const { return true; } void intersection(const Projection_query& q, const Primitive& primitive) { - // We don't use q here because it is embedded in sphere_ and we don't - // want to compute sphere everytime - - Projection projection; - if ( AABBTraits().intersection(sphere_, primitive, projection) ) - { - const Sphere sphere = AABBTraits().sphere(center_, projection); - if ( AABBTraits().is_contained(sphere, sphere_) ) - { - projection_ = projection; - sphere_ = sphere; - } - } + projection_ = AABBTraits().nearest_point(q, primitive, projection_); + sphere_ = AABBTraits().sphere(q, projection_); } bool do_intersect(const Projection_query& q, const Node& node) const @@ -285,7 +273,6 @@ namespace CGAL { private: Projection projection_; - Projection_query center_; Sphere sphere_; }; @@ -437,7 +424,7 @@ namespace CGAL { // first nearest neighbor point to get a hint template typename AABB_tree::Projection - AABB_tree::closest_point(const Projection_query& query) + AABB_tree::closest_point(const Projection_query& query) { // construct search KD-tree if needed Projection hint; 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 4dc88aca27e..86c9c412b26 100644 --- a/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp +++ b/AABB_tree/test/AABB_tree/aabb_intersection_triangle_test.cpp @@ -97,13 +97,13 @@ double random_in(const double a, } template -typename K::Point_3 random_point_in(CGAL::Bbox_3& bbox) +typename K::Point_3 random_point_in(const CGAL::Bbox_3& bbox) { typedef typename K::FT FT; FT x = (FT)random_in(bbox.xmin(),bbox.xmax()); FT y = (FT)random_in(bbox.ymin(),bbox.ymax()); FT z = (FT)random_in(bbox.zmin(),bbox.zmax()); - return K::Point_3(x,y,z); + return typename K::Point_3(x,y,z); } template @@ -113,7 +113,7 @@ typename K::Vector_3 random_vector() FT x = (FT)random_in(0.0,1.0); FT y = (FT)random_in(0.0,1.0); FT z = (FT)random_in(0.0,1.0); - return K::Vector_3(x,y,z); + return typename K::Vector_3(x,y,z); } enum Query_type {RAY_QUERY,