diff --git a/docs/Doxygen/doxyfile b/docs/Doxygen/doxyfile index 20f9f17a..b19036e2 100644 --- a/docs/Doxygen/doxyfile +++ b/docs/Doxygen/doxyfile @@ -682,7 +682,9 @@ INPUT = ../../vcg/complex/allocate.h \ ../../vcg/simplex/vertex/component.h \ ../../vcg/simplex/face/component.h \ ../../vcg/complex/algorithms/create/platonic.h \ - ../../vcg/complex/append.h + ../../vcg/complex/append.h \ + ../../vcg/simplex/edge/component.h \ + ../../vcg/complex/algorithms/geodesic.h # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is diff --git a/vcg/complex/algorithms/geodesic.h b/vcg/complex/algorithms/geodesic.h index c92bf8df..acd7bd26 100644 --- a/vcg/complex/algorithms/geodesic.h +++ b/vcg/complex/algorithms/geodesic.h @@ -20,29 +20,11 @@ * for more details. * * * ****************************************************************************/ -#include -#include -#include #include #include #include #include -#include -#include #include - -/* -class for computing approximated geodesic distances on a mesh. - -basic example: farthest vertex from a specified one -MyMesh m; -MyMesh::VertexPointer seed,far; -MyMesh::ScalarType dist; - -vcg::Geo g; -g.FarthestVertex(m,seed,far,d); - -*/ #ifndef __VCGLIB_GEODESIC #define __VCGLIB_GEODESIC @@ -59,8 +41,14 @@ struct EuclideanDistance{ {return vcg::Distance(v0->cP(),v1->cP());} }; +/*! \brief class for computing approximate geodesic distances on a mesh + * +basic example: farthest vertex from a specified one +\sa trimesh_geodesic.cpp +*/ + template > -class Geo{ +class Geodesic{ public: @@ -277,96 +265,65 @@ wrapping function. public: - /* - Given a mesh and a vector of pointers to seed vertices, this function assigns the approximated geodesic - distance from the closest source to all the mesh vertices within the - specified interval and returns the found vertices writing on their Quality field the distance. - Optionally for each vertex it can store, in a passed attribute, its corresponding seed vertex. - To allocate such an attribute: + /*! \brief Given a set of source vertices compute the approximate geodesic distance to all the other vertices - typename MeshType::template PerVertexAttributeHandle sources; - sources = tri::Allocator::AddPerVertexAttribute (m,"sources"); +\param m the mesh +\param seedVec a vector of Vertex pointers with the \em sources of the flood fill +\param maxDistanceThr max distance that we travel on the mesh starting from the sources +\param withinDistanceVec a pointer to a vector for storing the vertexes reached within the passed maxDistanceThr +\param sourceSeed pointer to the handle to keep for each vertex its seed +\param parentSeed pointer to the handle to keep for each vertex its parent in the closest tree +Given a mesh and a vector of pointers to seed vertices, this function compute the approximated geodesic +distance from the given sources to all the mesh vertices within the given maximum distance threshold. +The computed distance is stored in the vertex::Quality component. +Optionally for each vertex it can store, in a passed attribute, the corresponding seed vertex +(e.g. the vertex of the source set closest to him) and the 'parent' in a tree forest that connects each vertex to the closest source. + +To allocate the attributes: +\code + typename MeshType::template PerVertexAttributeHandle sourcesHandle; + sourcesHandle = tri::Allocator::AddPerVertexAttribute (m,"sources"); + + typename MeshType::template PerVertexAttributeHandle parentHandle; + parentHandle = tri::Allocator::AddPerVertexAttribute (m,"parent"); +\endcode +\warning that this function has ALWAYS at least a linear cost (it use additional attributes that have a linear initialization) +\todo make it O(output) by using incremental mark and persistent attributes. */ - static bool FarthestVertex( MeshType & m, - std::vector & seedVec, - VertexPointer & farthest_vert, - ScalarType distance_thr = std::numeric_limits::max(), - typename MeshType::template PerVertexAttributeHandle * sourceSeed = NULL, - typename MeshType::template PerVertexAttributeHandle * parentSeed = NULL, - std::vector *InInterval=NULL) + static bool Compute( MeshType & m, + const std::vector & seedVec, + ScalarType maxDistanceThr = std::numeric_limits::max(), + std::vector *withinDistanceVec=NULL, + typename MeshType::template PerVertexAttributeHandle * sourceSeed = NULL, + typename MeshType::template PerVertexAttributeHandle * parentSeed = NULL + ) { - typename std::vector::iterator fi; - std::vector vdSeedVec; if(seedVec.empty()) return false; + std::vector vdSeedVec; + typename std::vector::const_iterator fi; for( fi = seedVec.begin(); fi != seedVec.end() ; ++fi) vdSeedVec.push_back(VertDist(*fi,0.0)); - farthest_vert = Visit(m, vdSeedVec, false, distance_thr, sourceSeed, parentSeed, InInterval); + + Visit(m, vdSeedVec, false, maxDistanceThr, sourceSeed, parentSeed, withinDistanceVec); return true; } - /* - Given a mesh and a pointers to a vertex-source (source), assigns the approximated geodesic - distance from the vertex-source to all the mesh vertices and returns the pointer to the farthest - Note: it updates the field Q() of the vertices - */ - static bool FarthestVertex( MeshType & m, VertexPointer seed, ScalarType distance_thr = std::numeric_limits::max()) - { - std::vector seedVec(1,seed); - VertexPointer v0; - return FarthestVertex(m,seedVec,v0,distance_thr); - } - - - /* - Same as FarthestPoint but the returned pointer is to a border vertex - Note: update the field Q() of the vertices - */ - static void FarthestBVertex(MeshType & m, - std::vector & seedVec, - VertexPointer & farthest, - ScalarType & distance, - typename MeshType::template PerVertexAttributeHandle * sources = NULL - ) - { - std::vectorfr; - for(typename std::vector::iterator fi = seedVec.begin(); fi != seedVec.end() ; ++fi) - fr.push_back(VertDist(*fi,0)); - farthest = Visit(m,fr,distance,true,sources); - } - /* - Same as FarthestPoint but the returned pointer is to a border vertex - Note: update the field Q() of the vertices - */ - static void FarthestBVertex( MeshType & m, - VertexPointer seed, - VertexPointer & farthest, - ScalarType & distance, - typename MeshType::template PerVertexAttributeHandle * sources = NULL) - { - std::vector fro(1,seed); - VertexPointer v0; - FarthestBVertex(m,fro,v0,distance,sources); - farthest = v0; - } /* Assigns to each vertex of the mesh its distance to the closest vertex on the border Note: update the field Q() of the vertices Note: it needs the border bit set. */ - static bool DistanceFromBorder( MeshType & m, typename MeshType::template PerVertexAttributeHandle * sources = NULL - ){ + static bool DistanceFromBorder( MeshType & m, typename MeshType::template PerVertexAttributeHandle * sources = NULL) + { std::vector fro; - VertexIterator vi; - VertexPointer farthest; - for(vi = m.vert.begin(); vi != m.vert.end(); ++vi) + for(VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) if( (*vi).IsB()) fro.push_back(&(*vi)); if(fro.empty()) return false; tri::UpdateQuality::VertexConstant(m,0); - - return FarthestVertex(m,fro,farthest,std::numeric_limits::max(),sources); + return Compute(m,fro,std::numeric_limits::max(),0,sources); } };// end class diff --git a/vcg/complex/algorithms/voronoi_clustering.h b/vcg/complex/algorithms/voronoi_clustering.h index 1de3c883..3166839b 100644 --- a/vcg/complex/algorithms/voronoi_clustering.h +++ b/vcg/complex/algorithms/voronoi_clustering.h @@ -101,21 +101,21 @@ typedef typename MeshType::template PerFaceAttributeHandle PerFac static void ComputePerVertexSources(MeshType &m, std::vector &seedVec) { - tri::Geo g; - VertexPointer farthest; tri::Allocator::DeletePerVertexAttribute(m,"sources"); // delete any conflicting handle regardless of the type... PerVertexPointerHandle vertexSources = tri::Allocator:: template AddPerVertexAttribute (m,"sources"); + tri::Allocator::DeletePerFaceAttribute(m,"sources"); // delete any conflicting handle regardless of the type... PerFacePointerHandle faceSources = tri::Allocator:: template AddPerFaceAttribute (m,"sources"); + assert(tri::Allocator::IsValidHandle(m,vertexSources)); - g.FarthestVertex(m,seedVec,farthest,std::numeric_limits::max(),&vertexSources); + tri::Geodesic::Compute(m,seedVec,std::numeric_limits::max(),0,&vertexSources); } static void VoronoiColoring(MeshType &m, std::vector &seedVec, bool frontierFlag=true) { PerVertexPointerHandle sources = tri::Allocator:: template GetPerVertexAttribute (m,"sources"); assert(tri::Allocator::IsValidHandle(m,sources)); - tri::Geo g; + tri::Geodesic g; VertexPointer farthest; if(frontierFlag) @@ -124,7 +124,7 @@ static void VoronoiColoring(MeshType &m, std::vector &seedVec, boo std::vector< std::pair > regionArea(m.vert.size(),zz); std::vector borderVec; GetAreaAndFrontier(m, sources, regionArea, borderVec); - g.FarthestVertex(m,borderVec,farthest); + tri::Geodesic::Compute(m,borderVec); } tri::UpdateColor::PerVertexQualityRamp(m); @@ -274,13 +274,11 @@ static void VoronoiRelaxing(MeshType &m, std::vector &seedVec, int for(int iter=0;iter g; - VertexPointer farthest; // first run: find for each point what is the closest to one of the seeds. typename MeshType::template PerVertexAttributeHandle sources; sources = tri::Allocator:: template AddPerVertexAttribute (m,"sources"); - g.FarthestVertex(m,seedVec,farthest,std::numeric_limits::max(),&sources); + tri::Geodesic::Compute(m,seedVec,std::numeric_limits::max(),0,&sources); std::pair zz(0,0); std::vector< std::pair > regionArea(m.vert.size(),zz); @@ -300,7 +298,7 @@ static void VoronoiRelaxing(MeshType &m, std::vector &seedVec, int if(cb) cb(iter*100/relaxIter,"Voronoi Lloyd Relaxation: Searching New Seeds"); - g.FarthestVertex(m,borderVec,farthest); + tri::Geodesic::Compute(m,borderVec); tri::UpdateColor::PerVertexQualityRamp(m); // Search the local maxima for each region and use them as new seeds