cleaned up a bit the interface and formatting of the code of the voronoiclustering alg
This commit is contained in:
parent
1c4e43955b
commit
42da29417b
|
@ -21,11 +21,9 @@
|
|||
* *
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef VORONOI_PROCESSING_H
|
||||
#define VORONOI_PROCESSING_H
|
||||
|
||||
//#include <vcg/simplex/face/topology.h>
|
||||
#include <vcg/complex/algorithms/geodesic.h>
|
||||
#include <vcg/complex/algorithms/update/color.h>
|
||||
namespace vcg
|
||||
|
@ -35,25 +33,22 @@ namespace tri
|
|||
|
||||
template <class MeshType>
|
||||
class ClusteringSampler
|
||||
{
|
||||
public:
|
||||
{
|
||||
public:
|
||||
typedef typename MeshType::VertexType VertexType;
|
||||
|
||||
ClusteringSampler()
|
||||
{
|
||||
sampleVec=0;
|
||||
}
|
||||
ClusteringSampler(std::vector<VertexType *> *_vec)
|
||||
ClusteringSampler(std::vector<VertexType *> &_vec): sampleVec(_vec)
|
||||
{
|
||||
sampleVec = _vec;
|
||||
}
|
||||
std::vector<VertexType *> *sampleVec;
|
||||
|
||||
std::vector<VertexType *> &sampleVec;
|
||||
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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.
|
||||
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);
|
||||
|
||||
|
@ -293,7 +291,7 @@ static void VoronoiRelaxing(MeshType &m, std::vector<VertexType *> &seedVec, int
|
|||
face::VFDetach(*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::Allocator<MeshType>::CompactFaceVector(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)
|
||||
seedVec[i]->C() = Color4b::White;
|
||||
|
||||
}
|
||||
tri::Allocator<MeshType>::DeletePerVertexAttribute (m,"sources");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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.
|
||||
static void TopologicalVertexColoring(MeshType &m, std::vector<VertexType *> &seedVec)
|
||||
|
@ -388,7 +387,7 @@ static void TopologicalVertexColoring(MeshType &m, std::vector<VertexType *> &se
|
|||
}
|
||||
} // end while(!VQ.empty())
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Drastic Simplification algorithm.
|
||||
// Similar in philosopy to the classic grid clustering but using a voronoi partition instead of the regular grid.
|
||||
|
@ -412,7 +411,7 @@ static void VoronoiClustering(MeshType &mOld, MeshType &mNew, std::vector<Vertex
|
|||
|
||||
tri::Allocator<MeshType>::AddVertices(mNew,seedVec.size());
|
||||
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());
|
||||
std::set<Point3i>::iterator fsi; ;
|
||||
|
|
Loading…
Reference in New Issue