From ce75b4e68f8fec04d8bc1cc068f4c8a590b10b0d Mon Sep 17 00:00:00 2001 From: Luigi Malomo Date: Thu, 28 Feb 2019 12:37:01 +0100 Subject: [PATCH] updated polygon triangulate funnction + corrected Dijkstra spelling --- .../trimesh_geodesic/trimesh_geodesic.cpp | 2 +- vcg/complex/algorithms/geodesic.h | 4 +- vcg/complex/algorithms/polygonal_algorithms.h | 71 ++++++++++--------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/apps/sample/trimesh_geodesic/trimesh_geodesic.cpp b/apps/sample/trimesh_geodesic/trimesh_geodesic.cpp index f458e3a5..fd166f58 100644 --- a/apps/sample/trimesh_geodesic/trimesh_geodesic.cpp +++ b/apps/sample/trimesh_geodesic/trimesh_geodesic.cpp @@ -84,7 +84,7 @@ int main( int argc, char **argv ) printf("min %f max %f\n",minmax.first,minmax.second); tri::io::ExporterPLY::Save(m,"base.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY); int t0=clock(); - tri::Geodesic::PerVertexDijsktraCompute(m,seedVec,ed); + tri::Geodesic::PerVertexDijkstraCompute(m,seedVec,ed); int t1=clock(); printf("Geodesic dijkstra %6.3f\n",float(t1-t0)/CLOCKS_PER_SEC); tri::UpdateColor::PerVertexQualityRamp(m); diff --git a/vcg/complex/algorithms/geodesic.h b/vcg/complex/algorithms/geodesic.h index e64b99ed..e5a438fe 100644 --- a/vcg/complex/algorithms/geodesic.h +++ b/vcg/complex/algorithms/geodesic.h @@ -514,7 +514,7 @@ It is just a simple wrapper of the basic Compute() static inline std::string parentsAttributeName(void) { return "parent"; } template - static void PerFaceDijsktraCompute(MeshType &m, const std::vector &seedVec, + static void PerFaceDijkstraCompute(MeshType &m, const std::vector &seedVec, DistanceFunctor &distFunc, ScalarType maxDistanceThr = std::numeric_limits::max(), std::vector *InInterval=NULL, @@ -579,7 +579,7 @@ It is just a simple wrapper of the basic Compute() template - static void PerVertexDijsktraCompute(MeshType &m, const std::vector &seedVec, + static void PerVertexDijkstraCompute(MeshType &m, const std::vector &seedVec, DistanceFunctor &distFunc, ScalarType maxDistanceThr = std::numeric_limits::max(), std::vector *InInterval=NULL, diff --git a/vcg/complex/algorithms/polygonal_algorithms.h b/vcg/complex/algorithms/polygonal_algorithms.h index 9dd27254..13e813d9 100644 --- a/vcg/complex/algorithms/polygonal_algorithms.h +++ b/vcg/complex/algorithms/polygonal_algorithms.h @@ -72,11 +72,12 @@ This class is used to performs varisous kind of geometric optimization on generi template class PolygonalAlgorithm { - typedef typename PolyMeshType::FaceType FaceType; - typedef typename PolyMeshType::VertexType VertexType; - typedef typename PolyMeshType::CoordType CoordType; - typedef typename PolyMeshType::ScalarType ScalarType; - typedef typename vcg::face::Pos PosType; + typedef typename PolyMeshType::FaceType FaceType; + typedef typename PolyMeshType::VertexType VertexType; + typedef typename PolyMeshType::VertexPointer VertexPointer; + typedef typename PolyMeshType::CoordType CoordType; + typedef typename PolyMeshType::ScalarType ScalarType; + typedef typename vcg::face::Pos PosType; public: static bool CollapseEdges(PolyMeshType &poly_m, const std::vector &CollapsePos, @@ -1257,42 +1258,42 @@ public: } } - static void Triangulate(PolyMeshType &poly_m,size_t IndexF) - { + /*! \brief Triangulate a polygonal face with a triangle fan. + * \returns pointer to the newly added vertex. + */ + static VertexPointer Triangulate(PolyMeshType & poly_m, size_t IndexF) + { - CoordType bary=vcg::PolyBarycenter(poly_m.face[IndexF]); - size_t sizeV=poly_m.face[IndexF].VN(); + const CoordType bary = vcg::PolyBarycenter(poly_m.face[IndexF]); + size_t sizeV = poly_m.face[IndexF].VN(); - //add the new vertex - vcg::tri::Allocator::AddVertex(poly_m,bary); - VertexType *newV=&poly_m.vert.back(); + //add the new vertex + VertexPointer newV = &(*vcg::tri::Allocator::AddVertex(poly_m,bary)); - std::vector ToUpdateF; + //then reupdate the faces + for (size_t j=0;j<(sizeV-1);j++) + { + VertexType * v0=poly_m.face[IndexF].V0(j); + VertexType * v1=poly_m.face[IndexF].V1(j); + VertexType * v2=newV; - //then reupdate the faces - for (size_t j=0;j<(sizeV-1);j++) - { - VertexType * v0=poly_m.face[IndexF].V0(j); - VertexType * v1=poly_m.face[IndexF].V1(j); - VertexType * v2=newV; + vcg::tri::Allocator::AddFaces(poly_m,1); - vcg::tri::Allocator::AddFaces(poly_m,1); + poly_m.face.back().Alloc(3); + poly_m.face.back().V(0)=v0; + poly_m.face.back().V(1)=v1; + poly_m.face.back().V(2)=v2; + } - poly_m.face.back().Alloc(3); - poly_m.face.back().V(0)=v0; - poly_m.face.back().V(1)=v1; - poly_m.face.back().V(2)=v2; - ToUpdateF.push_back(poly_m.face.size()-1); - } - VertexType * v0=poly_m.face[IndexF].V0((sizeV-1)); - VertexType * v1=poly_m.face[IndexF].V1((sizeV-1)); - poly_m.face[IndexF].Dealloc(); - poly_m.face[IndexF].Alloc(3); - poly_m.face[IndexF].V(0)=v0; - poly_m.face[IndexF].V(1)=v1; - poly_m.face[IndexF].V(2)=newV; - ToUpdateF.push_back(IndexF); - } + VertexType * v0=poly_m.face[IndexF].V0((sizeV-1)); + VertexType * v1=poly_m.face[IndexF].V1((sizeV-1)); + poly_m.face[IndexF].Dealloc(); + poly_m.face[IndexF].Alloc(3); + poly_m.face[IndexF].V(0)=v0; + poly_m.face[IndexF].V(1)=v1; + poly_m.face[IndexF].V(2)=newV; + return newV; + } static void ReorderFaceVert(FaceType &f,const size_t &StartI) {