inside.h
Go to the documentation of this file.
00001 
00002 /****************************************************************************
00003 * IDOLib                                                                    *
00004 * Interactive Deformable Objects Library                                                                        *
00005 *       http://idolib.sf.net                                                                                                    *       
00006 *                                                                                                                                                       *
00007 * Copyright(C) 2005                                                                                                                     *
00008 * Visual Computing Lab                                                      *
00009 * ISTI - Italian National Research Council                                  *
00010 *                                                                           *
00011 * All rights reserved.                                                      *
00012 *                                                                           *
00013 * This program is free software; you can redistribute it and/or modify      *   
00014 * it under the terms of the GNU General Public License as published by      *
00015 * the Free Software Foundation; either version 2 of the License, or         *
00016 * (at your option) any later version.                                       *
00017 *                                                                           *
00018 * This program is distributed in the hope that it will be useful,           *
00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00021 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00022 * for more details.                                                         *
00023 *                                                                           *
00024 ****************************************************************************/
00025 /****************************************************************************
00026   History
00027 
00028 $Log: not supported by cvs2svn $
00029 Revision 1.3  2007/06/06 15:38:57  turini
00030 Use the barycenter function from triangle3.h instead of
00031 the one in face\base.h.
00032 
00033 Revision 1.2  2007/06/06 14:26:51  pietroni
00034 compiling error resolved
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                 }; // end class
00111         }
00112 }
00113 
00114 #endif // __VCG_TRIMESH_INSIDE


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:32:04