From f9a7860f5e1238a94729d7847fb0ecd6c44992ec Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 15 Nov 2011 11:19:08 +0000 Subject: [PATCH] Added a much more robust IntersectionPlaneMeshQuality function to compute the intersection between a mesh and a plane that exploit quality for storing the distance from the plane and to make consistent decision about the cutting of the plane... --- vcg/complex/algorithms/intersection.h | 91 +++++++++++++++++++++------ 1 file changed, 72 insertions(+), 19 deletions(-) diff --git a/vcg/complex/algorithms/intersection.h b/vcg/complex/algorithms/intersection.h index 4123b7d3..1dd6dc0a 100644 --- a/vcg/complex/algorithms/intersection.h +++ b/vcg/complex/algorithms/intersection.h @@ -93,6 +93,7 @@ bool IntersectionPlaneGrid( GridType & grid, Plane3 plane, std::vect /*@}*/ + /** \addtogroup complex */ /*@{*/ /** @@ -108,28 +109,80 @@ bool IntersectionPlaneMesh(TriMeshType & m, Plane3 pl, EdgeMeshType & em) { - typename EdgeMeshType::VertexIterator vi; - typename TriMeshType::FaceIterator fi; + typename EdgeMeshType::VertexIterator vi; + typename TriMeshType::FaceIterator fi; em.Clear(); - Segment3 seg; - for(fi=m.face.begin();fi!=m.face.end();++fi) - if(!(*fi).IsD()) - { - if(vcg::IntersectionPlaneTriangle(pl,*fi,seg))// intersezione piano triangolo - { - vcg::tri::Allocator::AddEdges(em,1); - vi = vcg::tri::Allocator::AddVertices(em,2); - (*vi).P() = seg.P0(); - em.edge.back().V(0) = &(*vi); - vi++; - (*vi).P() = seg.P1(); - em.edge.back().V(1) = &(*vi); - } - }//end for - - return true; + Segment3 seg; + for(fi=m.face.begin();fi!=m.face.end();++fi) + if(!(*fi).IsD()) + { + if(vcg::IntersectionPlaneTriangle(pl,*fi,seg))// intersezione piano triangolo + { + vcg::tri::Allocator::AddEdges(em,1); + vi = vcg::tri::Allocator::AddVertices(em,2); + (*vi).P() = seg.P0(); + em.edge.back().V(0) = &(*vi); + vi++; + (*vi).P() = seg.P1(); + em.edge.back().V(1) = &(*vi); + } + }//end for + + return true; } +/** \addtogroup complex */ +/*@{*/ +/** + 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 > +bool IntersectionPlaneMeshQuality(TriMeshType & m, + Plane3 pl, + EdgeMeshType & em) +{ + std::vector ptVec; + tri::UpdateQuality::VertexFromPlane(m,pl); + for(size_t i=0;iQ() * m.face[i].V1(j)->Q())<0) + { + const Point3f &p0 = m.face[i].V0(j)->cP(); + const Point3f &p1 = m.face[i].V1(j)->cP(); +// printf("Intersection ( %3.2f %3.2f %3.2f )-( %3.2f %3.2f %3.2f )\n",p0[0],p0[1],p0[2],p1[0],p1[1],p1[2]); + Point3f pp; + Segment3f seg(p0,p1); + IntersectionPlaneSegment(pl,seg,pp); + ptVec.push_back(pp); + } + if(m.face[i].V(j)->Q()==0) ptVec.push_back(m.face[i].V(j)->cP()); + } + if(ptVec.size()>=2) + { + typename EdgeMeshType::VertexIterator vi; + vcg::tri::Allocator::AddEdges(em,1); + vi = vcg::tri::Allocator::AddVertices(em,2); + (*vi).P() = ptVec[0]; + em.edge.back().V(0) = &(*vi); + vi++; + (*vi).P() = ptVec[1]; + em.edge.back().V(1) = &(*vi); + } + } + + return true; +} + + /** \addtogroup complex */ /*@{*/ /**