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
00041
00042 #include <vcg/space/ray3.h>
00043 #include <vcg/space/box3.h>
00044 #include <vcg/space/triangle3.h>
00045
00046
00047 #ifndef VCG_INSIDE
00048 #define VCG_INSIDE
00049
00050
00053
00054 namespace vcg {
00055
00056 namespace tri {
00057
00058 template <class FaceSpatialIndexing,class TriMeshType>
00059 class Inside
00060 {
00061
00062 private:
00063
00064 typedef typename FaceSpatialIndexing::CoordType CoordType;
00065 typedef typename FaceSpatialIndexing::ScalarType ScalarType;
00066
00067 public:
00068
00070 static bool Is_Inside( TriMeshType & m, FaceSpatialIndexing & _g_mesh, const CoordType & test )
00071 {
00072 typedef typename TriMeshType::FaceType FaceType;
00073 typedef typename TriMeshType::ScalarType ScalarType;
00074 typedef typename TriMeshType::CoordType CoordType;
00075 const ScalarType EPSILON = 0.000001;
00077 if( !( m.bbox.IsIn(test) ) ) return false;
00078 else
00079 {
00080 ScalarType dist;
00081 CoordType Norm, ip, nearest;
00082 FaceType *f = vcg::tri::GetClosestFace< TriMeshType, FaceSpatialIndexing >( m, _g_mesh, test, m.bbox.Diag(), dist, nearest, Norm, ip );
00083 assert( f != NULL );
00084
00085 if( ( test - nearest ).Norm() <= EPSILON ) return true;
00087 if( ( ip.V(0) > EPSILON ) && ( ip.V(1) > EPSILON ) && ( ip.V(2) > EPSILON ) )
00088 {
00090 vcg::Point3f debugn = f->N();
00091 if( ( f->N() * ( test - nearest ) ) < 0 ) return true;
00092 else return false;
00093 }
00096 else
00097 {
00098 CoordType bary = vcg::Barycenter< FaceType >(*f);
00100 vcg::Ray3<ScalarType> r; r.Set( test, ( bary - test ) ); r.Normalize();
00101 FaceType *f1 = vcg::tri::DoRay< TriMeshType, FaceSpatialIndexing >( m, _g_mesh, r, m.bbox.Diag(), dist );
00102 assert( f1 != NULL );
00104 if( ( f1->N() * ( test - bary ) ) < 0 ) return true;
00105 else return false;
00106 }
00107
00108 }
00109 }
00110
00111 };
00112 }
00113 }
00114
00115 #endif