added IntersectionRayMesh
This commit is contained in:
parent
2fe93647ab
commit
099bae2d71
|
@ -5,7 +5,8 @@
|
|||
#include<vcg/space/intersection3.h>
|
||||
#include<vcg/space/index/grid_static_ptr.h>
|
||||
|
||||
|
||||
#include<vcg/complex/trimesh/base.h>
|
||||
using namespace std;
|
||||
|
||||
namespace vcg{
|
||||
|
||||
|
@ -66,12 +67,16 @@ bool Intersect( GridType & grid,Plane3<ScalarType> plane, vector<typename Grid
|
|||
words there are 2*n vertices where n is the number of segments fo the mesh. You can run vcg::edge::Unify to unify
|
||||
the vertices closer that a given value epsilon. Note that, due to subtraction error during triangle plane intersection,
|
||||
it is not safe to put epsilon to 0.
|
||||
*/
|
||||
// TODO si dovrebbe considerare la topologia face-face della trimesh per derivare quella della edge mesh..
|
||||
*/
|
||||
template < typename TriMeshType, typename EdgeMeshType, class ScalarType>
|
||||
bool Intersection( TriMeshType & m, Plane3<ScalarType> pl,EdgeMeshType & em,double& ave_length,
|
||||
bool Intersection( TriMeshType & m,
|
||||
Plane3<ScalarType> pl,
|
||||
EdgeMeshType & em,
|
||||
double& ave_length,
|
||||
typename GridStaticPtr<typename TriMeshType::FaceContainer> *grid,
|
||||
typename vector< typename GridStaticPtr<typename TriMeshType::FaceContainer>::Cell* >& cells){
|
||||
typename vector< typename GridStaticPtr<typename TriMeshType::FaceContainer>::Cell* >& cells)
|
||||
{
|
||||
typedef typename TriMeshType::FaceContainer FaceContainer;
|
||||
typedef GridStaticPtr<FaceContainer> GridType;
|
||||
EdgeMeshType::VertexIterator vi;
|
||||
|
@ -115,6 +120,44 @@ bool Intersection( TriMeshType & m, Plane3<ScalarType> pl,EdgeMeshType & em,dou
|
|||
for(v_i=v.begin(); v_i!=v.end(); ++v_i) (*v_i)->ClearS();
|
||||
|
||||
return true;
|
||||
}
|
||||
/*****************************************************************/
|
||||
/*INTERSECTION RAY - MESH */
|
||||
/* */
|
||||
/* Intersection between a Ray and a Mesh. Returns a 3D Pointset! */
|
||||
/*****************************************************************/
|
||||
template < typename TriMeshType, class ScalarType>
|
||||
bool IntersectionRayMesh(
|
||||
/* Input Mesh */ TriMeshType * m,
|
||||
/* Ray */ const Line3<ScalarType> & ray,
|
||||
/* Intersect Point */ Point3<ScalarType> & hitPoint)
|
||||
{
|
||||
//typedef typename TriMeshType::FaceContainer FaceContainer;
|
||||
TriMeshType::FaceIterator fi;
|
||||
bool hit=false;
|
||||
|
||||
if(m==0) return false;
|
||||
|
||||
//TriMeshType::FaceIterator fi;
|
||||
//vector<TriMeshType::FaceType*>::iterator fi;
|
||||
|
||||
ScalarType bar1,bar2,dist;
|
||||
Point3<ScalarType> p1;
|
||||
Point3<ScalarType> p2;
|
||||
Point3<ScalarType> p3;
|
||||
for(fi = m->face.begin(); fi != m->face.end(); ++fi)
|
||||
{
|
||||
p1=vcg::Point3<ScalarType>( (*fi).P(0).X() ,(*fi).P(0).Y(),(*fi).P(0).Z() );
|
||||
p2=vcg::Point3<ScalarType>( (*fi).P(1).X() ,(*fi).P(1).Y(),(*fi).P(1).Z() );
|
||||
p3=vcg::Point3<ScalarType>( (*fi).P(2).X() ,(*fi).P(2).Y(),(*fi).P(2).Z() );
|
||||
if(Intersection<ScalarType>(ray,p1,p2,p3,bar1,bar2,dist))
|
||||
{
|
||||
hitPoint= p1*(1-bar1-bar2) + p2*bar1 + p3*bar2;
|
||||
hit=true;
|
||||
}
|
||||
}
|
||||
|
||||
return hit;
|
||||
}
|
||||
/*@}*/
|
||||
} // end namespace vcg
|
Loading…
Reference in New Issue