From 280a9e606b3347547c1f54c086da90175ea630be Mon Sep 17 00:00:00 2001 From: cignoni Date: Sat, 12 Jul 2014 05:50:32 +0000 Subject: [PATCH] Updates pointcloud normal and smooth to the thread safe changes to the kdtree. --- vcg/complex/algorithms/pointcloud_normal.h | 35 ++++++++++++---------- vcg/complex/algorithms/smooth.h | 9 +++--- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/vcg/complex/algorithms/pointcloud_normal.h b/vcg/complex/algorithms/pointcloud_normal.h index 180db38f..e844de4e 100644 --- a/vcg/complex/algorithms/pointcloud_normal.h +++ b/vcg/complex/algorithms/pointcloud_normal.h @@ -35,24 +35,27 @@ public: bool operator< (const WArc &a) const {return w &tree,vcg::CallBackPos * cb=0) + static void ComputeUndirectedNormal(MeshType &m, int nn, ScalarType maxDist, KdTree &tree,vcg::CallBackPos * cb=0) { - tree.setMaxNofNeighbors(nn); +// tree.setMaxNofNeighbors(nn); + const ScalarType maxDistSquared = maxDist*maxDist; int cnt=0; int step=m.vn/100; + typename KdTree::PriorityQueue nq; for (VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi) { - tree.doQueryK(vi->cP()); + tree.doQueryK(vi->cP(),nn,nq); if(cb && (++cnt%step)==0) cb(cnt/step,"Fitting planes"); - int neighbours = tree.getNofFoundNeighbors(); +// int neighbours = tree.getNofFoundNeighbors(); + int neighbours = nq.getNofElements(); std::vector ptVec; - for (int i = 0; i < neighbours; i++) { - int neightId = tree.getNeighborId(i); - if(Distance(vi->cP(),m.vert[neightId].cP()) plane; FitPlaneToPointSet(ptVec,plane); @@ -60,14 +63,16 @@ public: } } - static void AddNeighboursToHeap( MeshType &m, VertexPointer vp, KdTree &tree, std::vector &heap) + static void AddNeighboursToHeap( MeshType &m, VertexPointer vp, int nn, KdTree &tree, std::vector &heap) { - tree.doQueryK(vp->cP()); + typename KdTree::PriorityQueue nq; + tree.doQueryK(vp->cP(),nn,nq); - int neighbours = tree.getNofFoundNeighbors(); + int neighbours = nq.getNofElements(); for (int i = 0; i < neighbours; i++) { - int neightId = tree.getNeighborId(i); +// int neightId = tree.getNeighborId(i); + int neightId = nq.getIndex(i); if (neightId < m.vn && (&m.vert[neightId] != vp)) { if(!m.vert[neightId].IsV()) @@ -114,7 +119,7 @@ public: tri::Smooth::VertexNormalPointCloud(m,p.fittingAdjNum,p.smoothingIterNum,&tree); if(p.coherentAdjNum==0) return; - tree.setMaxNofNeighbors(p.coherentAdjNum+1); +// tree.setMaxNofNeighbors(p.coherentAdjNum+1); tri::UpdateFlags::VertexClearV(m); std::vector heap; @@ -133,7 +138,7 @@ public: vi->N()=-(*vi).N(); vi->SetV(); - AddNeighboursToHeap(m,&*vi,tree,heap); + AddNeighboursToHeap(m,&*vi,p.coherentAdjNum,tree,heap); while(!heap.empty()) { @@ -146,7 +151,7 @@ public: if(a.src->cN()*a.trg->cN()<0.0f) if(!p.useViewPoint || ( a.trg->N().dot(p.viewPoint- a.trg->P())<0.0f)) // test to prevent flipping according to viewpos a.trg->N()=-a.trg->N(); - AddNeighboursToHeap(m,a.trg,tree,heap); + AddNeighboursToHeap(m,a.trg,p.coherentAdjNum,tree,heap); } } } diff --git a/vcg/complex/algorithms/smooth.h b/vcg/complex/algorithms/smooth.h index 60074523..845ea146 100644 --- a/vcg/complex/algorithms/smooth.h +++ b/vcg/complex/algorithms/smooth.h @@ -1194,17 +1194,18 @@ static void VertexNormalPointCloud(MeshType &m, int neighborNum, int iterNum, Kd KdTree *tree=0; if(tp==0) tree = new KdTree(ww); else tree=tp; + typename KdTree::PriorityQueue nq; - tree->setMaxNofNeighbors(neighborNum); +// tree->setMaxNofNeighbors(neighborNum); for(int ii=0;iidoQueryK(vi->cP()); - int neighbours = tree->getNofFoundNeighbors(); + tree->doQueryK(vi->cP(),neighborNum,nq); + int neighbours = nq.getNofElements(); for (int i = 0; i < neighbours; i++) { - int neightId = tree->getNeighborId(i); + int neightId = nq.getIndex(i); if(m.vert[neightId].cN()*vi->cN()>0) TD[vi]+= m.vert[neightId].cN(); else