From 46dc55fb3c69e0c14854d4e752768d0950fdebd8 Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 10 Sep 2013 10:51:15 +0000 Subject: [PATCH] Refactored code to use the AddFace of the Allocator that add and fill a face with three vertex pointers. --- vcg/complex/algorithms/voronoi_clustering.h | 52 ++++++++++----------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/vcg/complex/algorithms/voronoi_clustering.h b/vcg/complex/algorithms/voronoi_clustering.h index 9116fb44..3b0ff862 100644 --- a/vcg/complex/algorithms/voronoi_clustering.h +++ b/vcg/complex/algorithms/voronoi_clustering.h @@ -352,8 +352,12 @@ static void ConvertVoronoiDiagramToMesh(MeshType &m, MeshType &outM, MeshType &p // There is a voronoi edge if there are two corner face that share two sources. // In such a case we add a pair of triangles with an edge connecting these two corner faces // and with the two involved sources + // For each pair of adjacent sources we store the first of the two corner that we encounter. std::map, FacePointer > VoronoiEdge; + + // First Loop build all the triangles connecting seeds with voronoi edges + // we loop over the edges and build two triangles for each edge for(size_t i=0;i::AddFace(outM,&(outM.vert[seedMap[v0]]), corner0, corner1); fi->SetF(0); fi->SetF(2); - fi = tri::Allocator::AddFace(outM,&(outM.vert[seedMap[v1]]), corner0, corner1); + fi = tri::Allocator::AddFace(outM,&(outM.vert[seedMap[v1]]), corner1, corner0); fi->SetF(0); fi->SetF(2); tri::Allocator::AddEdge(poly,&(poly.vert[tri::Index(outM,corner0)]),&(poly.vert[tri::Index(outM,corner1)]) ); @@ -380,7 +384,10 @@ static void ConvertVoronoiDiagramToMesh(MeshType &m, MeshType &outM, MeshType &p } } - // Now build the boundary facets, e.g. the triangles with an edge on the boundary that connects two bordercorner face. + // Now build the boundary facets: + // Two cases: + // - triangles with an edge on the boundary that connects two bordercorner face. + // - triangles with only a vertex on the border and an internal 'corner' for(size_t i=0;iV(0)]; @@ -397,42 +404,33 @@ static void ConvertVoronoiDiagramToMesh(MeshType &m, MeshType &outM, MeshType &p VertexPointer corner1 = &(outM.vert[bcOff+otherCorner]); FaceIterator fi = tri::Allocator::AddFace(outM,&(outM.vert[seedMap[v0]]), corner0, corner1); fi->SetF(0);fi->SetF(2); + + tri::Allocator::AddEdge(poly,&(poly.vert[tri::Index(outM,corner0)]),&(poly.vert[tri::Index(outM,corner1)]) ); } + if(VoronoiEdge[std::make_pair(VertexPointer(0),v1)] == 0) VoronoiEdge[std::make_pair(VertexPointer(0),v1)] = borderCornerVec[i]; else { int otherCorner = cornerMap[VoronoiEdge[std::make_pair(VertexPointer(0),v1)]]; - FaceIterator fi=tri::Allocator::AddFaces(outM,1); VertexPointer corner0 = &(outM.vert[bcOff+i]); VertexPointer corner1 = &(outM.vert[bcOff+otherCorner]); - fi->V(0) = &(outM.vert[seedMap[v1]]); - fi->V(1) = corner0; - fi->V(2) = corner1; - fi->SetF(0);fi->SetF(2); - } - if(VoronoiEdge[std::make_pair(v0,v1)] == 0) - assert(0); - else - { - int otherCorner = cornerMap[VoronoiEdge[std::make_pair(v0,v1)]]; - FaceIterator fi=tri::Allocator::AddFaces(outM,2); - VertexPointer corner0 = &(outM.vert[bcOff+i]); - VertexPointer corner1 = &(outM.vert[cOff+otherCorner]); - fi->V(0) = &(outM.vert[seedMap[v0]]); - fi->V(1) = corner0; - fi->V(2) = corner1; + FaceIterator fi = tri::Allocator::AddFace(outM,&(outM.vert[seedMap[v1]]), corner0, corner1); fi->SetF(0);fi->SetF(2); tri::Allocator::AddEdge(poly,&(poly.vert[tri::Index(outM,corner0)]),&(poly.vert[tri::Index(outM,corner1)]) ); - - ++fi; - fi->V(0) = &(outM.vert[seedMap[v1]]); - fi->V(1) = corner0; - fi->V(2) = corner1; - fi->SetF(0);fi->SetF(2); - tri::Allocator::AddEdge(poly,&(poly.vert[tri::Index(outM,corner0)]),&(poly.vert[tri::Index(outM,corner1)]) ); - } + + assert(VoronoiEdge[std::make_pair(v0,v1)]!=0); + + int otherCorner = cornerMap[VoronoiEdge[std::make_pair(v0,v1)]]; + VertexPointer corner0 = &(outM.vert[bcOff+i]); + VertexPointer corner1 = &(outM.vert[cOff+otherCorner]); + FaceIterator fi = tri::Allocator::AddFace(outM,&(outM.vert[seedMap[v0]]), corner0, corner1); + fi->SetF(0);fi->SetF(2); + fi = tri::Allocator::AddFace(outM,&(outM.vert[seedMap[v1]]), corner0, corner1); + fi->SetF(0);fi->SetF(2); + + tri::Allocator::AddEdge(poly,&(poly.vert[tri::Index(outM,corner0)]),&(poly.vert[tri::Index(outM,corner1)]) ); } } static void DeleteUnreachedRegions(MeshType &m, PerVertexPointerHandle &sources)