From 433d07069164dd8b9ee0d94a9242a2ac07a8a9f6 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Fri, 1 Aug 2014 00:15:14 +0000 Subject: [PATCH] added RayBoxIntersection function and RaySegmentIntersectionFunctor --- vcg/space/intersection2.h | 52 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/vcg/space/intersection2.h b/vcg/space/intersection2.h index dc108045..073f3ce2 100644 --- a/vcg/space/intersection2.h +++ b/vcg/space/intersection2.h @@ -40,7 +40,7 @@ added circle-line intersection #include #include #include - +#include @@ -137,6 +137,34 @@ namespace vcg { return ((d0 + inline bool RayBoxIntersection(const vcg::Ray2 & r, + const vcg::Box2 &bbox, + Point2 &p_inters) + { + ///first create the 4 segments + vcg::Segment2 S[4]; + for (int i=0;i<4;i++) + S[i]=vcg::Segment2(bbox.P(i),bbox.P((i+1)%4)); + + SCALAR_TYPE mind=std::numeric_limits::max(); + bool found=false; + for (int i=0;i<4;i++) + { + Point2 p_inters_test; + if (!RaySegmentIntersection(r,S[i],p_inters_test))continue; + SCALAR_TYPE Norm=(p_inters_test-r.Origin()).Norm(); + if (Norm inline bool LineSegmentIntersection(const vcg::Line2 & line, @@ -333,6 +361,28 @@ namespace vcg { return true; } } + + + // Ray-Segment Functor + class RaySegmentIntersectionFunctor { + public: + + template + inline bool operator () (const SEGMENTTYPE & S, + const Ray2 & ray, + SCALARTYPE & t) + { + typedef SCALARTYPE ScalarType; + typedef vcg::Point2 CoordType; + + CoordType inters_test; + bool bret = RaySegmentIntersection(ray,S, inters_test); + if (bret) + t=(inters_test-ray.Origin()).Norm(); + return (bret); + } + }; + /*@}*/ } // end namespace #endif