From c5ec73d0f75e0e60a66fe0a8faab8116893317e9 Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Tue, 14 Oct 2008 14:31:35 +0000 Subject: [PATCH] Added IntersectionRayMesh overload function who return hit point, baricentric's coordinates and a pointer of intersected face. --- vcg/complex/intersection.h | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/vcg/complex/intersection.h b/vcg/complex/intersection.h index ab27889a..8cb2877c 100644 --- a/vcg/complex/intersection.h +++ b/vcg/complex/intersection.h @@ -279,6 +279,52 @@ bool IntersectionRayMesh( return hit; } + +/** + Computes the intersection between a Ray and a Mesh. Returns a 3D Pointset, baricentric's coordinates + and a pointer of intersected face. +*/ +template < typename TriMeshType, class ScalarType> +bool IntersectionRayMesh( + /* Input Mesh */ TriMeshType * m, + /* Ray */ const Line3 & ray, + /* Intersect Point */ Point3 & hitPoint, + /* Baricentric coord 1*/ ScalarType &bar1, + /* Baricentric coord 2*/ ScalarType &bar2, + /* Baricentric coord 3*/ ScalarType &bar3, + /* FacePointer */ typename TriMeshType::FacePointer fp + ) +{ + //typedef typename TriMeshType::FaceContainer FaceContainer; + typename TriMeshType::FaceIterator fi; + bool hit=false; + + if(m==0) return false; + + //TriMeshType::FaceIterator fi; + //std::vector::iterator fi; + + ScalarType dist; + Point3 p1; + Point3 p2; + Point3 p3; + for(fi = m->face.begin(); fi != m->face.end(); ++fi) + { + p1=vcg::Point3( (*fi).P(0).X() ,(*fi).P(0).Y(),(*fi).P(0).Z() ); + p2=vcg::Point3( (*fi).P(1).X() ,(*fi).P(1).Y(),(*fi).P(1).Z() ); + p3=vcg::Point3( (*fi).P(2).X() ,(*fi).P(2).Y(),(*fi).P(2).Z() ); + if(Intersection(ray,p1,p2,p3,bar1,bar2,dist)) + { + bar3 = (1-bar1-bar2); + hitPoint= p1*bar3 + p2*bar1 + p3*bar2; + fp = &(*fi); + hit=true; + } + } + + return hit; +} + /** Compute the intersection between a mesh and a ball. given a mesh return a new mesh made by a copy of all the faces entirely includeded in the ball plus