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: protected:
void AddFace(int v0, int v1, int v2) { 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>::AddFace(mesh,v0,v1,v2);
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];
ComputeNormalizedNormal(*fi); ComputeNormalizedNormal(*fi);
if(tri::HasVFAdjacency(mesh)) 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) if((this->mesh.vert[i].P() - point).Norm() < 0.1)
{ {
vn = i; vn = i;
//find the border //find the border
assert(this->mesh.vert[i].IsB()); assert(this->mesh.vert[i].IsB());
for(std::list<FrontEdge>::iterator k = this->front.begin(); k != this->front.end(); k++) for(std::list<FrontEdge>::iterator k = this->front.begin(); k != this->front.end(); k++)
if((*k).v0 == i) if((*k).v0 == i)
{ {
touch.first = AdvancingFront<MESH>::FRONT; touch.first = AdvancingFront<MESH>::FRONT;
touch.second = k; touch.second = k;
} }
for(std::list<FrontEdge>::iterator k = this->deads.begin(); k != this->deads.end(); k++) for(std::list<FrontEdge>::iterator k = this->deads.begin(); k != this->deads.end(); k++)
if((*k).v0 == i) if((*k).v0 == i)
if((*k).v0 == i) if((*k).v0 == i)
{ {
touch.first = AdvancingFront<MESH>::FRONT; touch.first = AdvancingFront<MESH>::FRONT;
touch.second = k; touch.second = k;
} }
break; break;
} }
} }
if(vn == this->mesh.vert.size()) { 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); VertexConstDataWrapper<MESH> ww(this->mesh);
tree = new KdTree<ScalarType>(ww); tree = new KdTree<ScalarType>(ww);
tree->setMaxNofNeighbors(16); // tree->setMaxNofNeighbors(16);
usedBit = VertexType::NewBitFlag(); usedBit = VertexType::NewBitFlag();
UpdateFlags<MESH>::VertexClear(this->mesh,usedBit); UpdateFlags<MESH>::VertexClear(this->mesh,usedBit);
@ -88,11 +88,12 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
seed.SetUserBit(usedBit); seed.SetUserBit(usedBit);
tree->doQueryK(seed.P()); typename KdTree<ScalarType>::PriorityQueue pq;
int nn = tree->getNofFoundNeighbors(); tree->doQueryK(seed.P(),16,pq);
int nn = pq.getNofElements();
for(int i=0;i<nn;++i) 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; if(Distance(seed.P(),vp->cP()) > 2*radius) continue;
targets.push_back(vp); targets.push_back(vp);
} }
@ -223,8 +224,9 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
ScalarType r = sqrt(radius*radius - axis_len/4); ScalarType r = sqrt(radius*radius - axis_len/4);
tree->doQueryK(middle); typename KdTree<ScalarType>::PriorityQueue pq;
int nn = tree->getNofFoundNeighbors(); tree->doQueryK(middle,16,pq);
int nn = pq.getNofElements();
if(nn==0) return -1; if(nn==0) return -1;
VertexType *candidate = NULL; 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. // Loop over all the nearest vertexes and choose the best one according the ball pivoting strategy.
// //
for (int i = 0; i < nn; i++) { for (int i = 0; i < nn; i++) {
int vInd = tree->getNeighborId(i); int vInd = pq.getIndex(i);
VertexType *v = &this->mesh.vert[vInd]; VertexType *v = &this->mesh.vert[vInd];
if(Distance(middle,v->cP()) > r + radius) continue; if(Distance(middle,v->cP()) > r + radius) continue;
@ -391,10 +393,11 @@ template <class MESH> class BallPivoting: public AdvancingFront<MESH> {
} }
void Mark(VertexType *v) { void Mark(VertexType *v) {
tree->doQueryK(v->cP()); typename KdTree<ScalarType>::PriorityQueue pq;
int n = tree->getNofFoundNeighbors(); tree->doQueryK(v->cP(),16,pq);
int n = pq.getNofElements();
for (int i = 0; i < n; i++) { 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) if(Distance(v->cP(),vp->cP())<min_edge)
vp->SetUserBit(usedBit); vp->SetUserBit(usedBit);
} }