updated the ball pivoting alg to the new kdtree

This commit is contained in:
Paolo Cignoni 2014-08-23 01:31:16 +00:00
parent 7a68b662a8
commit 7285fadd53
2 changed files with 31 additions and 33 deletions

View File

@ -342,12 +342,7 @@ public:
protected:
void AddFace(int v0, int v1, int v2) {
assert(v0 < (int)mesh.vert.size() && v1 < (int)mesh.vert.size() && v2 < (int)mesh.vert.size());
FaceIterator fi = vcg::tri::Allocator<MESH>::AddFaces(mesh,1);
fi->ClearFlags();
fi->V(0) = &mesh.vert[v0];
fi->V(1) = &mesh.vert[v1];
fi->V(2) = &mesh.vert[v2];
FaceIterator fi = vcg::tri::Allocator<MESH>::AddFace(mesh,v0,v1,v2);
ComputeNormalizedNormal(*fi);
if(tri::HasVFAdjacency(mesh))
{
@ -520,24 +515,24 @@ template <class MESH> class AdvancingTest: public AdvancingFront<MESH> {
{
if((this->mesh.vert[i].P() - point).Norm() < 0.1)
{
vn = i;
//find the border
assert(this->mesh.vert[i].IsB());
for(std::list<FrontEdge>::iterator k = this->front.begin(); k != this->front.end(); k++)
if((*k).v0 == i)
{
touch.first = AdvancingFront<MESH>::FRONT;
touch.second = k;
}
vn = i;
//find the border
assert(this->mesh.vert[i].IsB());
for(std::list<FrontEdge>::iterator k = this->front.begin(); k != this->front.end(); k++)
if((*k).v0 == i)
{
touch.first = AdvancingFront<MESH>::FRONT;
touch.second = k;
}
for(std::list<FrontEdge>::iterator k = this->deads.begin(); k != this->deads.end(); k++)
if((*k).v0 == i)
if((*k).v0 == i)
{
touch.first = AdvancingFront<MESH>::FRONT;
touch.second = k;
}
break;
for(std::list<FrontEdge>::iterator k = this->deads.begin(); k != this->deads.end(); k++)
if((*k).v0 == i)
if((*k).v0 == i)
{
touch.first = AdvancingFront<MESH>::FRONT;
touch.second = k;
}
break;
}
}
if(vn == this->mesh.vert.size()) {

View File

@ -59,7 +59,7 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
VertexConstDataWrapper<MESH> ww(this->mesh);
tree = new KdTree<ScalarType>(ww);
tree->setMaxNofNeighbors(16);
// tree->setMaxNofNeighbors(16);
usedBit = VertexType::NewBitFlag();
UpdateFlags<MESH>::VertexClear(this->mesh,usedBit);
@ -88,11 +88,12 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
seed.SetUserBit(usedBit);
tree->doQueryK(seed.P());
int nn = tree->getNofFoundNeighbors();
typename KdTree<ScalarType>::PriorityQueue pq;
tree->doQueryK(seed.P(),16,pq);
int nn = pq.getNofElements();
for(int i=0;i<nn;++i)
{
VertexType *vp = &this->mesh.vert[tree->getNeighborId(i)];
VertexType *vp = &this->mesh.vert[pq.getIndex(i)];
if(Distance(seed.P(),vp->cP()) > 2*radius) continue;
targets.push_back(vp);
}
@ -223,8 +224,9 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
ScalarType r = sqrt(radius*radius - axis_len/4);
tree->doQueryK(middle);
int nn = tree->getNofFoundNeighbors();
typename KdTree<ScalarType>::PriorityQueue pq;
tree->doQueryK(middle,16,pq);
int nn = pq.getNofElements();
if(nn==0) return -1;
VertexType *candidate = NULL;
@ -233,7 +235,7 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
// Loop over all the nearest vertexes and choose the best one according the ball pivoting strategy.
//
for (int i = 0; i < nn; i++) {
int vInd = tree->getNeighborId(i);
int vInd = pq.getIndex(i);
VertexType *v = &this->mesh.vert[vInd];
if(Distance(middle,v->cP()) > r + radius) continue;
@ -391,10 +393,11 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
}
void Mark(VertexType *v) {
tree->doQueryK(v->cP());
int n = tree->getNofFoundNeighbors();
typename KdTree<ScalarType>::PriorityQueue pq;
tree->doQueryK(v->cP(),16,pq);
int n = pq.getNofElements();
for (int i = 0; i < n; i++) {
VertexType *vp = &this->mesh.vert[tree->getNeighborId(i)];
VertexType *vp = &this->mesh.vert[pq.getIndex(i)];
if(Distance(v->cP(),vp->cP())<min_edge)
vp->SetUserBit(usedBit);
}