Minor changes.
This commit is contained in:
parent
9105a551cd
commit
f25f034dcb
|
@ -26,27 +26,38 @@
|
||||||
History
|
History
|
||||||
|
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.3 2007/06/06 15:38:57 turini
|
||||||
|
Use the barycenter function from triangle3.h instead of
|
||||||
|
the one in face\base.h.
|
||||||
|
|
||||||
Revision 1.2 2007/06/06 14:26:51 pietroni
|
Revision 1.2 2007/06/06 14:26:51 pietroni
|
||||||
compiling error resolved
|
compiling error resolved
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <vcg/space/ray3.h>
|
#include <vcg/space/ray3.h>
|
||||||
#include <vcg/space/box3.h>
|
#include <vcg/space/box3.h>
|
||||||
#include <vcg/space/triangle3.h>
|
#include <vcg/space/triangle3.h>
|
||||||
|
|
||||||
|
|
||||||
#ifndef VCG_INSIDE
|
#ifndef VCG_INSIDE
|
||||||
#define VCG_INSIDE
|
#define VCG_INSIDE
|
||||||
|
|
||||||
///this static funtion is used to see if one point is inside
|
|
||||||
///a triangular mesh or not... First parameter is a spatial indexing
|
/// This static funtion is used to see if one point is inside a triangular mesh or not...
|
||||||
///structure (eg. a grid) used to perform research operation,
|
/// First parameter is a spatial indexing structure (eg. a grid) used to perform research operation, initialized with faces of the triangular mesh of type TriMeshType
|
||||||
///initialized with faces of the triangular mesh of type TriMeshType
|
|
||||||
namespace vcg {
|
namespace vcg {
|
||||||
|
|
||||||
namespace trimesh {
|
namespace trimesh {
|
||||||
|
|
||||||
template <class FaceSpatialIndexing,class TriMeshType>
|
template <class FaceSpatialIndexing,class TriMeshType>
|
||||||
class Inside{
|
class Inside
|
||||||
|
{
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -55,59 +66,43 @@ namespace vcg {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/// Return true if the point is inside the mesh.
|
||||||
|
static bool Is_Inside( TriMeshType & m, FaceSpatialIndexing & _g_mesh, const CoordType & test )
|
||||||
//return true if the point is inside the mesh
|
|
||||||
static bool Is_Inside(TriMeshType &m,
|
|
||||||
FaceSpatialIndexing &_g_mesh,
|
|
||||||
const CoordType &test)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
typedef typename TriMeshType::FaceType FaceType;
|
typedef typename TriMeshType::FaceType FaceType;
|
||||||
typedef typename TriMeshType::ScalarType ScalarType;
|
typedef typename TriMeshType::ScalarType ScalarType;
|
||||||
typedef typename TriMeshType::CoordType CoordType;
|
typedef typename TriMeshType::CoordType CoordType;
|
||||||
|
const ScalarType EPSILON = 0.000001;
|
||||||
const ScalarType EPSILON=0.000001;
|
/// First test if the element is inside the bounding box of the mesh.
|
||||||
|
if( !( m.bbox.IsIn(test) ) ) return false;
|
||||||
///first test if the element is inside the bb of the mesh
|
|
||||||
if (!m.bbox.IsIn(test))
|
|
||||||
return false;
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ScalarType dist;
|
ScalarType dist;
|
||||||
CoordType Norm,ip,nearest;
|
CoordType Norm, ip, nearest;
|
||||||
FaceType *f=vcg::trimesh::GetClosestFace<TriMeshType,FaceSpatialIndexing>(m,_g_mesh,test,m.bbox.Diag(),dist,nearest,Norm,ip);
|
FaceType *f = vcg::trimesh::GetClosestFace< TriMeshType, FaceSpatialIndexing >( m, _g_mesh, test, m.bbox.Diag(), dist, nearest, Norm, ip );
|
||||||
//any face in the mesh
|
assert( f != NULL ); /// Check if there is any face in the mesh
|
||||||
assert(f!=NULL);
|
/// If the point is on the face is considered inside.
|
||||||
//if the point is on the face is considered inside
|
if( ( test - nearest ).Norm() <= EPSILON ) return true;
|
||||||
if ((test-nearest).Norm()<=EPSILON)
|
/// Check if the closest point is inside a face
|
||||||
return true;
|
if( ( ip.V(0) > EPSILON ) && ( ip.V(1) > EPSILON ) && ( ip.V(2) > EPSILON ) )
|
||||||
///if the point is in surface of a face then is ok
|
|
||||||
if ((ip.V(0)>EPSILON)&&(ip.V(1)>EPSILON)&&(ip.V(2)>EPSILON))
|
|
||||||
{
|
{
|
||||||
if ((f->N()*(test-nearest))<0)///in this case normal direction is enought
|
/// Check if the test point is inside the mesh using the normal direction
|
||||||
return true;
|
vcg::Point3f debugn = f->N();
|
||||||
else
|
if( ( f->N() * ( test - nearest ) ) < 0 ) return true;
|
||||||
return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
/// In this case we are not sure because hit an edge or a vertex.
|
||||||
///in this case we are not sure because
|
/// So we use a ray that go until the barycenter of found face, then see normal value again
|
||||||
///hit an edge or a vertex then we use a ray that
|
|
||||||
///go until the barycenter of found face,
|
|
||||||
///then see normal value again
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CoordType bary = vcg::Barycenter< FaceType >(*f);
|
CoordType bary = vcg::Barycenter< FaceType >(*f);
|
||||||
vcg::Ray3<ScalarType> r;
|
/// Set ray : origin and direction
|
||||||
r.Set(test,(bary-test));///set origin and direction
|
vcg::Ray3<ScalarType> r; r.Set( test, ( bary - test ) ); r.Normalize();
|
||||||
r.Normalize();
|
FaceType *f1 = vcg::trimesh::DoRay< TriMeshType, FaceSpatialIndexing >( m, _g_mesh, r, m.bbox.Diag(), dist );
|
||||||
FaceType *f1=vcg::trimesh::DoRay<TriMeshType,FaceSpatialIndexing>(m,_g_mesh,r,m.bbox.Diag(),dist);
|
assert( f1 != NULL );
|
||||||
if (f1==NULL)
|
/// In this case normal direction is enough.
|
||||||
assert(0);
|
if( ( f1->N() * ( test - bary ) ) < 0 ) return true;
|
||||||
if ((f1->N()*(test-bary))<0)///in this case normal direction is enought
|
else return false;
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue