Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef __VCG_TRIMESH_INSIDE
00041 #define __VCG_TRIMESH_INSIDE
00042
00043 #include <vcg/complex/algorithms/closest.h>
00044
00045
00048
00049 namespace vcg {
00050
00051 namespace tri {
00052
00053 template <class FaceSpatialIndexing,class TriMeshType>
00054 class Inside
00055 {
00056 public:
00057
00058 typedef typename FaceSpatialIndexing::CoordType CoordType;
00059 typedef typename FaceSpatialIndexing::ScalarType ScalarType;
00060
00062 static bool Is_Inside( TriMeshType & m, FaceSpatialIndexing & _g_mesh, const CoordType & test )
00063 {
00064 typedef typename TriMeshType::FaceType FaceType;
00065 typedef typename TriMeshType::ScalarType ScalarType;
00066 typedef typename TriMeshType::CoordType CoordType;
00067 const ScalarType EPSILON = 0.000001;
00069 if( !( m.bbox.IsIn(test) ) )
00070 return false;
00071 else
00072 {
00073 ScalarType dist;
00074 CoordType Norm, ip, nearest;
00075 FaceType *f = vcg::tri::GetClosestFaceBase< TriMeshType, FaceSpatialIndexing >( m, _g_mesh, test, m.bbox.Diag(), dist, nearest, Norm, ip);
00076 assert( f != NULL );
00077
00078 if( ( test - nearest ).Norm() <= EPSILON )
00079 return true;
00081 if( ( ip.V(0) > EPSILON ) && ( ip.V(1) > EPSILON ) && ( ip.V(2) > EPSILON ) )
00082 {
00084 if( ( f->N() * ( test - nearest ) ) < 0 )
00085 return true;
00086 else
00087 return false;
00088 }
00091 else
00092 {
00093 CoordType bary = vcg::Barycenter< FaceType >(*f);
00095 vcg::Ray3<ScalarType> r;
00096 r.Set( test, ( bary - test ) );
00097 r.Normalize();
00098 FaceType *f1 = vcg::tri::DoRay< TriMeshType, FaceSpatialIndexing >( m, _g_mesh, r, m.bbox.Diag(), dist );
00099 assert( f1 != NULL );
00101 if( ( f1->N() * ( test - bary ) ) < 0 )
00102 return true;
00103 else
00104 return false;
00105 }
00106
00107 }
00108 }
00109
00110 };
00111 }
00112 }
00113
00114 #endif // __VCG_TRIMESH_INSIDE