cleaned up a bit the interface and formatting of the code of the voronoiclustering alg

This commit is contained in:
Paolo Cignoni 2013-07-05 14:46:48 +00:00
parent 1c4e43955b
commit 42da29417b
1 changed files with 171 additions and 172 deletions

View File

@ -21,11 +21,9 @@
* * * *
****************************************************************************/ ****************************************************************************/
#ifndef VORONOI_PROCESSING_H #ifndef VORONOI_PROCESSING_H
#define VORONOI_PROCESSING_H #define VORONOI_PROCESSING_H
//#include <vcg/simplex/face/topology.h>
#include <vcg/complex/algorithms/geodesic.h> #include <vcg/complex/algorithms/geodesic.h>
#include <vcg/complex/algorithms/update/color.h> #include <vcg/complex/algorithms/update/color.h>
namespace vcg namespace vcg
@ -39,19 +37,16 @@ class ClusteringSampler
public: public:
typedef typename MeshType::VertexType VertexType; typedef typename MeshType::VertexType VertexType;
ClusteringSampler() ClusteringSampler(std::vector<VertexType *> &_vec): sampleVec(_vec)
{
sampleVec=0;
}
ClusteringSampler(std::vector<VertexType *> *_vec)
{ {
sampleVec = _vec; sampleVec = _vec;
} }
std::vector<VertexType *> *sampleVec;
std::vector<VertexType *> &sampleVec;
void AddVert(const VertexType &p) void AddVert(const VertexType &p)
{ {
sampleVec->push_back((VertexType *)(&p)); sampleVec.push_back((VertexType *)(&p));
} }
}; // end class ClusteringSampler }; // end class ClusteringSampler
@ -273,12 +268,15 @@ static void GetAreaAndFrontier(MeshType &m, PerVertexPointerHandle &sources,
static void VoronoiRelaxing(MeshType &m, std::vector<VertexType *> &seedVec, int relaxIter, int /*percentileClamping*/, vcg::CallBackPos *cb=0) static void VoronoiRelaxing(MeshType &m, std::vector<VertexType *> &seedVec, int relaxIter, int /*percentileClamping*/, vcg::CallBackPos *cb=0)
{ {
tri::RequireVFAdjacency(m);
typename MeshType::template PerVertexAttributeHandle<VertexPointer> sources;
sources = tri::Allocator<MeshType>:: template AddPerVertexAttribute<VertexPointer> (m,"sources");
for(int iter=0;iter<relaxIter;++iter) for(int iter=0;iter<relaxIter;++iter)
{ {
if(cb) cb(iter*100/relaxIter,"Voronoi Lloyd Relaxation: First Partitioning"); if(cb) cb(iter*100/relaxIter,"Voronoi Lloyd Relaxation: First Partitioning");
// first run: find for each point what is the closest to one of the seeds. // first run: find for each point what is the closest to one of the seeds.
typename MeshType::template PerVertexAttributeHandle<VertexPointer> sources;
sources = tri::Allocator<MeshType>:: template AddPerVertexAttribute<VertexPointer> (m,"sources");
tri::Geodesic<MeshType>::Compute(m,seedVec,std::numeric_limits<ScalarType>::max(),0,&sources); tri::Geodesic<MeshType>::Compute(m,seedVec,std::numeric_limits<ScalarType>::max(),0,&sources);
@ -293,7 +291,7 @@ static void VoronoiRelaxing(MeshType &m, std::vector<VertexType *> &seedVec, int
face::VFDetach(*fi); face::VFDetach(*fi);
tri::Allocator<MeshType>::DeleteFace(m,*fi); tri::Allocator<MeshType>::DeleteFace(m,*fi);
} }
qDebug("Deleted faces not reached: %i -> %i",int(m.face.size()),m.fn); // qDebug("Deleted faces not reached: %i -> %i",int(m.face.size()),m.fn);
tri::Clean<MeshType>::RemoveUnreferencedVertex(m); tri::Clean<MeshType>::RemoveUnreferencedVertex(m);
tri::Allocator<MeshType>::CompactFaceVector(m); tri::Allocator<MeshType>::CompactFaceVector(m);
tri::Allocator<MeshType>::CompactVertexVector(m); tri::Allocator<MeshType>::CompactVertexVector(m);
@ -352,11 +350,12 @@ static void VoronoiRelaxing(MeshType &m, std::vector<VertexType *> &seedVec, int
for(size_t i=0;i<seedVec.size();++i) for(size_t i=0;i<seedVec.size();++i)
seedVec[i]->C() = Color4b::White; seedVec[i]->C() = Color4b::White;
}
tri::Allocator<MeshType>::DeletePerVertexAttribute (m,"sources"); tri::Allocator<MeshType>::DeletePerVertexAttribute (m,"sources");
} }
}
// Base vertex voronoi coloring algorithm. // Base vertex voronoi coloring algorithm.
// it assumes VF adjacency. No attempt of computing real geodesic distnace is done. Just a BFS visit starting from the seeds. // it assumes VF adjacency. No attempt of computing real geodesic distnace is done. Just a BFS visit starting from the seeds.
static void TopologicalVertexColoring(MeshType &m, std::vector<VertexType *> &seedVec) static void TopologicalVertexColoring(MeshType &m, std::vector<VertexType *> &seedVec)
@ -412,7 +411,7 @@ static void VoronoiClustering(MeshType &mOld, MeshType &mNew, std::vector<Vertex
tri::Allocator<MeshType>::AddVertices(mNew,seedVec.size()); tri::Allocator<MeshType>::AddVertices(mNew,seedVec.size());
for(size_t i=0;i< seedVec.size();++i) for(size_t i=0;i< seedVec.size();++i)
mNew.vert[i].ImportLocal(*(seedVec[i])); mNew.vert[i].ImportData(*(seedVec[i]));
tri::Allocator<MeshType>::AddFaces(mNew,clusteredFace.size()); tri::Allocator<MeshType>::AddFaces(mNew,clusteredFace.size());
std::set<Point3i>::iterator fsi; ; std::set<Point3i>::iterator fsi; ;