From 7d3175573a2b76c12d340e342e9a18157f28a48b Mon Sep 17 00:00:00 2001 From: cignoni Date: Mon, 11 Apr 2016 20:34:18 +0000 Subject: [PATCH] edge::VVStarVE now is templated on VertexType instead of EdgeType to avoid useless explicit template specialization --- vcg/simplex/edge/topology.h | 96 +++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/vcg/simplex/edge/topology.h b/vcg/simplex/edge/topology.h index d20e9d07..1933bbdd 100644 --- a/vcg/simplex/edge/topology.h +++ b/vcg/simplex/edge/topology.h @@ -56,11 +56,11 @@ inline bool IsEdgeBorder(EdgeType const & e, const int j ) return true; } -template -void VVStarVE(typename EdgeType::VertexType* vp, std::vector &starVec) +template +void VVStarVE(VertexType* vp, std::vector &starVec) { starVec.clear(); - edge::VEIterator vei(vp); + edge::VEIterator vei(vp); while(!vei.End()) { starVec.push_back(vei.V1()); @@ -96,34 +96,30 @@ void VEDetach(EdgeType & e, int z) typename EdgeType::VertexType *vz = e.V(z); // the vertex from which the edge must be detached. if(vz->VEp()==&e ) //if it is the first edge in the VE chain it detaches it from the begin + { + assert(vz->VEi() == z); + vz->VEp() = e.VEp(z); + vz->VEi() = e.VEi(z); + return; + } + else // scan the list of edges to find the current edge e to be detached + { + for( VEIterator vei(vz);!vei.End();++vei) { - int fz = vz->VEi(); - vz->VEp() = e.VEp(fz); - vz->VEi() = e.VEi(fz); - } - else // scan the list of edges to find the current edge e to be detached - { - VEIterator x(vz->VEp(),vz->VEi()); - VEIterator y; - - for(;;) - { - y = x; - ++x; - assert(x.e!=0); - if(x.e==&e) // found! - { - y.e->VEp(y.z) = e.VEp(z); - y.e->VEi(y.z) = e.VEi(z); - break; - } - } + if(vei.E()->VEp(vei.I()) == &e) + { + vei.e->VEp(vei.z) = e.VEp(z); + vei.e->VEi(vei.z) = e.VEi(z); + return; + } } + assert(0); + } } /// Append an edge in the VE list of vertex e->V(z) template -void VEAppend(EdgeType* & e, int z) +void VEAppend(EdgeType* e, int z) { typename EdgeType::VertexType *v = e->V(z); if (v->VEp()!=0) @@ -134,6 +130,11 @@ void VEAppend(EdgeType* & e, int z) e->VEp(z)=e0; e->VEi(z)=z0; } + else + { + e->VEp(z)=0; + e->VEi(z)=-1; + } v->VEp()=e; v->VEi()=z; } @@ -180,11 +181,14 @@ void VEEdgeCollapse(MeshType &poly, typename MeshType::EdgeType *e0, const int z assert(z1!=-1); VertexType *v1 = e1->V(z1); - - edge::VEDetach(*e1); - edge::VEDetach(*e0,z); - e0->V(z) = v1; - edge::VEAppend(e0, z); + assert(v1 != vd); + + edge::VEDetach(*e1); // detach the edge to be deleted. + + edge::VEDetach(*e0,z); // detach one side of the surviving edge + e0->V(z) = v1; // change one extreme of the edge + edge::VEAppend(e0, z); // attach it again. + tri::Allocator::DeleteEdge(poly,*e1); tri::Allocator::DeleteVertex(poly,*vd); } @@ -194,7 +198,39 @@ void VEEdgeCollapse(MeshType &poly, typename MeshType::VertexType *v) { VEEdgeCollapse(poly,v->VEp(),v->VEi()); } +/*! Perform a simple edge split using VE adjacency + * + */ +template +void VEEdgeSplit(MeshType &poly, typename MeshType::EdgeType *e, typename MeshType::VertexType &v) +{ + typename MeshType::VertexPointer v1 = e->V(1); + edge::VEDetach(*e,1); + e->V(1) = &v; + edge::VEAppend(e,1); +// tri::Allocator:: template PointerUpdater pu; + typename MeshType::EdgeIterator ei = tri::Allocator::AddEdges(poly, 1); + ei->V(0)=&v; + ei->V(1)=v1; + edge::VEAppend(&*ei,0); + edge::VEAppend(&*ei,1); +} +template +typename MeshType::VertexPointer VEEdgeSplit(MeshType &poly, typename MeshType::EdgeType *e, const typename MeshType::CoordType &p) +{ + typename MeshType::VertexIterator vi = tri::Allocator::AddVertex(poly,p); + VEEdgeSplit(poly,e,*vi); + return &*vi; +} + +template +typename MeshType::VertexPointer VEEdgeSplit(MeshType &poly, typename MeshType::EdgeType *e, const typename MeshType::CoordType &p, const typename MeshType::CoordType &n) +{ + typename MeshType::VertexIterator vi = tri::Allocator::AddVertex(poly,p,n); + VEEdgeSplit(poly,e,*vi); + return &*vi; +} /*! Returns the number of incident edges over a vertex vp; Using the VE adjacency.