From 19b903e34ba8069643b9af985b5c09451faaa638 Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 14 Aug 2008 10:04:01 +0000 Subject: [PATCH] added a basic Function computing the intersection between a trimesh and a plane that does not require a spatial search structure (useful if you want to make a small number of slices) --- vcg/complex/intersection.h | 100 +++++++++++++++++++++++-------------- 1 file changed, 63 insertions(+), 37 deletions(-) diff --git a/vcg/complex/intersection.h b/vcg/complex/intersection.h index c6f7736c..16f96f5b 100644 --- a/vcg/complex/intersection.h +++ b/vcg/complex/intersection.h @@ -115,51 +115,83 @@ bool Intersect( GridType & grid,Plane3 plane, std::vector + bool Intersection( /*TriMeshType & m, */ + Plane3 pl, + EdgeMeshType & em, + double& ave_length, + IndexingType *grid, + typename std::vector< typename IndexingType::Cell* >& cells) +{ + typedef typename TriMeshType::FaceContainer FaceContainer; + typedef IndexingType GridType; + typename EdgeMeshType::VertexIterator vi; + typename TriMeshType::FaceIterator fi; + std::vector v; + v.clear(); + Intersect(*grid,pl,cells); + Segment3 seg; + ave_length = 0.0; + typename std::vector::iterator ic; + typename GridType::Cell fs,ls; + for(ic = cells.begin(); ic != cells.end();++ic) + { + grid->Grid(*ic,fs,ls); + typename GridType::Link * lk = fs; + while(lk != ls){ + typename TriMeshType::FaceType & face = *(lk->Elem()); + if(!face.IsS()) + { + face.SetS(); + v.push_back(&face); + if(vcg::IntersectionPlaneTriangle(pl,face,seg))// intersezione piano triangolo + { + face.SetS(); + // add to em + ave_length+=seg.Length(); + vcg::edge::Allocator::AddEdges(em,1); + vi = vcg::edge::Allocator::AddVertices(em,2); + (*vi).P() = seg.P0(); + em.edges.back().V(0) = &(*vi); + vi++; + (*vi).P() = seg.P1(); + em.edges.back().V(1) = &(*vi); + } + }//endif + lk++; + }//end while + } + ave_length/=em.en; + typename std::vector::iterator v_i; + for(v_i=v.begin(); v_i!=v.end(); ++v_i) (*v_i)->ClearS(); + + return true; +} /** \addtogroup complex */ /*@{*/ /** - Function computing the intersection between a trimesh and a plane. It returns an EdgeMesh. + Basic Function computing the intersection between a trimesh and a plane. It returns an EdgeMesh without needing anything else. Note: This version always returns a segment for each triangle of the mesh which intersects with the plane. In other 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, class IndexingType > -bool Intersection( /*TriMeshType & m, */ - Plane3 pl, - EdgeMeshType & em, - double& ave_length, - IndexingType *grid, - typename std::vector< typename IndexingType::Cell* >& cells) +template < typename TriMeshType, typename EdgeMeshType, class ScalarType > +bool Intersection(TriMeshType & m, + Plane3 pl, + EdgeMeshType & em) { - typedef typename TriMeshType::FaceContainer FaceContainer; - typedef IndexingType GridType; typename EdgeMeshType::VertexIterator vi; typename TriMeshType::FaceIterator fi; - std::vector v; - v.clear(); - Intersect(*grid,pl,cells); + em.Clear(); Segment3 seg; - ave_length = 0.0; - typename std::vector::iterator ic; - typename GridType::Cell fs,ls; - for(ic = cells.begin(); ic != cells.end();++ic) + for(fi=m.face.begin();fi!=m.face.end();++fi) + if(!(*fi).IsD()) { - grid->Grid(*ic,fs,ls); - typename GridType::Link * lk = fs; - while(lk != ls){ - typename TriMeshType::FaceType & face = *(lk->Elem()); - if(!face.IsS()) - { - face.SetS(); - v.push_back(&face); - if(vcg::IntersectionPlaneTriangle(pl,face,seg))// intersezione piano triangolo + if(vcg::IntersectionPlaneTriangle(pl,*fi,seg))// intersezione piano triangolo { - face.SetS(); - // add to em - ave_length+=seg.Length(); vcg::edge::Allocator::AddEdges(em,1); vi = vcg::edge::Allocator::AddVertices(em,2); (*vi).P() = seg.P0(); @@ -168,14 +200,8 @@ bool Intersection( /*TriMeshType & m, */ (*vi).P() = seg.P1(); em.edges.back().V(1) = &(*vi); } - }//endif - lk++; - }//end while - } - ave_length/=em.en; - typename std::vector::iterator v_i; - for(v_i=v.begin(); v_i!=v.end(); ++v_i) (*v_i)->ClearS(); - + }//end for + return true; }