From 41ba29e19abf2c4fd9cb90d916c805532059d0a4 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Fri, 15 Jun 2012 15:06:34 +0000 Subject: [PATCH] Factorize code of Do_intersect(Bbox_3, ) Uniform use of do_intersect_bbox_segment_aux(..) with various Boolean template arguments. --- .../internal/Static_filters/Do_intersect_3.h | 16 ++- .../Bbox_3_Line_3_do_intersect.h | 113 ++--------------- .../Bbox_3_Ray_3_do_intersect.h | 114 ++---------------- 3 files changed, 38 insertions(+), 205 deletions(-) diff --git a/Filtered_kernel/include/CGAL/internal/Static_filters/Do_intersect_3.h b/Filtered_kernel/include/CGAL/internal/Static_filters/Do_intersect_3.h index 60236923265..1961ad0b438 100644 --- a/Filtered_kernel/include/CGAL/internal/Static_filters/Do_intersect_3.h +++ b/Filtered_kernel/include/CGAL/internal/Static_filters/Do_intersect_3.h @@ -28,8 +28,10 @@ #include #include #include + #include -#include +// for CGAL::internal::do_intersect_bbox_segment_aux + #include // inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf @@ -123,7 +125,11 @@ public: CGAL_BRANCH_PROFILER_BRANCH_1(tmp); const Uncertain ub = - do_intersect_bbox_segment_aux + do_intersect_bbox_segment_aux + // do use static filters (px, py, pz, qx, qy, qz, b); @@ -165,7 +171,11 @@ public: CGAL_BRANCH_PROFILER_BRANCH_1(tmp); const Uncertain ub = - do_intersect_bbox_segment_aux + do_intersect_bbox_segment_aux + // do use static filters (px, py, pz, qx, qy, qz, b); diff --git a/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Line_3_do_intersect.h b/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Line_3_do_intersect.h index 6175e1c37ef..282bbca3850 100644 --- a/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Line_3_do_intersect.h +++ b/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Line_3_do_intersect.h @@ -26,107 +26,15 @@ #include #include +#include +// for CGAL::internal::do_intersect_bbox_segment_aux + // inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf namespace CGAL { namespace internal { - template - inline - bool - bbox_line_do_intersect_aux(const FT& px, const FT& py, const FT& pz, - const FT& vx, const FT& vy, const FT& vz, - const FT& bxmin, const FT& bymin, const FT& bzmin, - const FT& bxmax, const FT& bymax, const FT& bzmax) - { - // ----------------------------------- - // treat x coord - // ----------------------------------- - FT dmin, tmin, tmax; - if ( vx >= 0 ) - { - tmin = bxmin - px; - tmax = bxmax - px; - dmin = vx; - } - else - { - tmin = px - bxmax; - tmax = px - bxmin; - dmin = -vx; - } - - //if px is not in the x-slab - if ( dmin == FT(0) && (tmin > FT(0) || tmax < FT(0)) ) return false; - - FT dmax = dmin; - - // ----------------------------------- - // treat y coord - // ----------------------------------- - FT d_, tmin_, tmax_; - if ( vy >= 0 ) - { - tmin_ = bymin - py; - tmax_ = bymax - py; - d_ = vy; - } - else - { - tmin_ = py - bymax; - tmax_ = py - bymin; - d_ = -vy; - } - - - - - if ( d_ == FT(0) ){ - //if py is not in the y-slab - if( (tmin_ > FT(0) || tmax_ < FT(0)) ) return false; - } - else - if ( (dmin*tmax_) < (d_*tmin) || (dmax*tmin_) > (d_*tmax) ) - return false; - - if( (dmin*tmin_) > (d_*tmin) ) - { - tmin = tmin_; - dmin = d_; - } - - if( (dmax*tmax_) < (d_*tmax) ) - { - tmax = tmax_; - dmax = d_; - } - - // ----------------------------------- - // treat z coord - // ----------------------------------- - if ( vz >= 0 ) - { - tmin_ = bzmin - pz; - tmax_ = bzmax - pz; - d_ = vz; - } - else - { - tmin_ = pz - bzmax; - tmax_ = pz - bzmin; - d_ = -vz; - } - - //if pz is not in the z-slab - //if ( d_ == FT(0) && (tmin_ > FT(0) || tmax_ < FT(0)) ) return false; - //The previous line is not needed as either dmin or d_ are not 0 - //(otherwise the direction of the line would be null). - // The following is equivalent to the in z-slab test if d_=0. - - return ( (dmin*tmax_) >= (d_*tmin) && (dmax*tmin_) <= (d_*tmax) ); - } - template bool do_intersect(const typename K::Line_3& line, const CGAL::Bbox_3& bbox, @@ -139,11 +47,16 @@ namespace internal { const Point_3& point = line.point(); const Vector_3& v = line.to_vector(); - return bbox_line_do_intersect_aux( - point.x(), point.y(), point.z(), - v.x(), v.y(), v.z(), - FT(bbox.xmin()), FT(bbox.ymin()), FT(bbox.zmin()), - FT(bbox.xmax()), FT(bbox.ymax()), FT(bbox.zmax()) ); + return do_intersect_bbox_segment_aux + // do not use static filters + ( + point.x(), point.y(), point.z(), + v.x(), v.y(), v.z(), + bbox + ); } } // namespace internal diff --git a/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Ray_3_do_intersect.h b/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Ray_3_do_intersect.h index 25e56bf062d..249264aca74 100644 --- a/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Ray_3_do_intersect.h +++ b/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Ray_3_do_intersect.h @@ -24,7 +24,9 @@ #include #include + #include +// for CGAL::internal::do_intersect_bbox_segment_aux // inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf @@ -32,99 +34,6 @@ namespace CGAL { namespace internal { - template - inline - bool - bbox_ray_do_intersect_aux(const FT& px, const FT& py, const FT& pz, - const FT& qx, const FT& qy, const FT& qz, - const FT& bxmin, const FT& bymin, const FT& bzmin, - const FT& bxmax, const FT& bymax, const FT& bzmax) - { - // (px, py, pz) is the source - // ----------------------------------- - // treat x coord - // ----------------------------------- - FT dmin, tmin, tmax; - if ( qx >= px ) - { - tmin = bxmin - px; - tmax = bxmax - px; - dmin = qx - px; - if ( tmax < FT(0) ) - return false; - } - else - { - tmin = px - bxmax; - tmax = px - bxmin; - dmin = px - qx; - if ( tmax < FT(0) ) - return false; - } - - FT dmax = dmin; - if ( tmin > FT(0) ) - { - if ( dmin == FT(0) ) - return false; - } - else - { - tmin = FT(0); - dmin = FT(1); - } - - // ----------------------------------- - // treat y coord - // ----------------------------------- - FT d_, tmin_, tmax_; - if ( qy >= py ) - { - tmin_ = bymin - py; - tmax_ = bymax - py; - d_ = qy - py; - } - else - { - tmin_ = py - bymax; - tmax_ = py - bymin; - d_ = py - qy; - } - - if ( (dmin*tmax_) < (d_*tmin) || (dmax*tmin_) > (d_*tmax) ) - return false; - - if( (dmin*tmin_) > (d_*tmin) ) - { - tmin = tmin_; - dmin = d_; - } - - if( (dmax*tmax_) < (d_*tmax) ) - { - tmax = tmax_; - dmax = d_; - } - - // ----------------------------------- - // treat z coord - // ----------------------------------- - if ( qz >= pz ) - { - tmin_ = bzmin - pz; - tmax_ = bzmax - pz; - d_ = qz - pz; - } - else - { - tmin_ = pz - bzmax; - tmax_ = pz - bzmin; - d_ = pz - qz; - } - - return ( (dmin*tmax_) >= (d_*tmin) && (dmax*tmin_) <= (d_*tmax) ); - } - template bool do_intersect(const typename K::Ray_3& ray, const CGAL::Bbox_3& bbox, @@ -136,15 +45,16 @@ namespace internal { const Point_3& source = ray.source(); const Point_3& point_on_ray = ray.second_point(); - return do_intersect_bbox_segment_aux( - source.x(), source.y(), source.z(), - point_on_ray.x(), point_on_ray.y(), point_on_ray.z(), - bbox); - // const CGAL::cpp0x::array rray = {source.x(), source.y(), source.z(), - // point_on_ray.x(), point_on_ray.y(), point_on_ray.z() }; - // return do_intersect_bbox_segment_aux - // (rray, - // *reinterpret_cast*>(&*bbox.cartesian_begin()) ); + return do_intersect_bbox_segment_aux + // do not use static filters + ( + source.x(), source.y(), source.z(), + point_on_ray.x(), point_on_ray.y(), point_on_ray.z(), + bbox + ); } } // namespace internal