From dcb0d036ff4392a306841afd89f6486a48c1ce46 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Sat, 22 Sep 2012 12:54:30 +0000 Subject: [PATCH] added FindSharedFaces and VFOrderedStarVF functions --- vcg/simplex/face/topology.h | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/vcg/simplex/face/topology.h b/vcg/simplex/face/topology.h index 5040c7c5..36493724 100644 --- a/vcg/simplex/face/topology.h +++ b/vcg/simplex/face/topology.h @@ -690,6 +690,50 @@ static void VFOrderedStarVF_FF(const typename FaceType::VertexType &vp, } +/*! +* Compute the ordered set of faces adjacent to a given vertex using VF adjacency.and FF adiacency +* \param vp pointer to the vertex whose star has to be computed. +* \param faceVec a std::vector of Face pointer that is filled with the adjacent faces. +* +*/ +template +static void VFOrderedStarVF_FF(const typename FaceType::VertexType &vp, + std::vector &faceVec, + std::vector &edgeVec) +{ + + ///check that is not on border.. + assert (!vp.IsB()); + + ///get first face sharing the edge + FaceType *f_init=vp.cVFp(); + int edge_init=vp.cVFi(); + + ///and initialize the pos + vcg::face::Pos VFI(f_init,edge_init); + bool complete_turn=false; + do + { + FaceType *curr_f=VFI.F(); + faceVec.push_back(curr_f); + + int curr_edge=VFI.E(); + edgeVec.push_back(curr_edge); + ///assert that is not a border edge + assert(curr_f->FFp(curr_edge)!=curr_f); + + ///continue moving + VFI.FlipF(); + VFI.FlipE(); + + FaceType *next_f=VFI.F(); + + ///test if I've finiseh with the face exploration + complete_turn=(next_f==f_init); + /// or if I've just crossed a mismatch + }while (!complete_turn); +} + /*! * Check if two faces share and edge through the FF topology. * \param f0,f1 the two face to be checked @@ -764,6 +808,44 @@ bool FindSharedEdge(FaceType *f0,FaceType *f1, int &i, int &j) return false; } +/*! +* find the faces that shares the two vertices +* \param v0,v1 the two vertices +* \param f0,f1 the two faces , counterclokwise order +* +*/ +template +bool FindSharedFaces(typename FaceType::VertexType *v0, + typename FaceType::VertexType *v1, + FaceType *&f0, + FaceType *&f1, + int &e0, + int &e1) +{ + std::vector faces0; + std::vector faces1; + + VFOrderedStarVF_FF(*v0,faces0); + VFOrderedStarVF_FF(v1,faces1); + ///then find the intersection + std::sort(faces0.begin(),faces0.end()); + std::sort(faces1.begin(),faces1.end()); + std::vector Intersection; + std::set_intersection(faces0.begin(),faces0.end(),faces1.begin(),faces1.end(),std::back_inserter(Intersection)); + if (Intersection.size()<2)return false; ///no pair of faces share the 2 vertices + assert(Intersection.size()==2);//otherwhise non manifoldess + f0=Intersection[0]; + f1=Intersection[1]; + FindSharedEdge(f0,f1,e0,e1); + ///and finally check if the order is right + if (f0->V(e0)!=v0) + { + std::swap(f0,f1); + std::swap(e0,e1); + } + return true; +} + /*@}*/ } // end namespace } // end namespace