Updates pointcloud normal and smooth to the thread safe changes to the kdtree.
This commit is contained in:
parent
c2f98a8595
commit
280a9e606b
|
@ -35,24 +35,27 @@ public:
|
||||||
bool operator< (const WArc &a) const {return w<a.w;}
|
bool operator< (const WArc &a) const {return w<a.w;}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void ComputeUndirectedNormal(MeshType &m, int nn, float maxDist, KdTree<ScalarType> &tree,vcg::CallBackPos * cb=0)
|
static void ComputeUndirectedNormal(MeshType &m, int nn, ScalarType maxDist, KdTree<ScalarType> &tree,vcg::CallBackPos * cb=0)
|
||||||
{
|
{
|
||||||
tree.setMaxNofNeighbors(nn);
|
// tree.setMaxNofNeighbors(nn);
|
||||||
|
const ScalarType maxDistSquared = maxDist*maxDist;
|
||||||
int cnt=0;
|
int cnt=0;
|
||||||
int step=m.vn/100;
|
int step=m.vn/100;
|
||||||
|
typename KdTree<ScalarType>::PriorityQueue nq;
|
||||||
for (VertexIterator vi=m.vert.begin();vi!=m.vert.end();++vi)
|
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");
|
if(cb && (++cnt%step)==0) cb(cnt/step,"Fitting planes");
|
||||||
|
|
||||||
int neighbours = tree.getNofFoundNeighbors();
|
// int neighbours = tree.getNofFoundNeighbors();
|
||||||
|
int neighbours = nq.getNofElements();
|
||||||
std::vector<CoordType> ptVec;
|
std::vector<CoordType> ptVec;
|
||||||
|
|
||||||
for (int i = 0; i < neighbours; i++)
|
for (int i = 0; i < neighbours; i++)
|
||||||
{
|
{
|
||||||
int neightId = tree.getNeighborId(i);
|
// int neightId = tree.getNeighborId(i);
|
||||||
if(Distance(vi->cP(),m.vert[neightId].cP())<maxDist)
|
int neightId = nq.getIndex(i);
|
||||||
ptVec.push_back(m.vert[neightId].cP());
|
if(nq.getWeight(i) <maxDistSquared)
|
||||||
|
ptVec.push_back(m.vert[neightId].cP());
|
||||||
}
|
}
|
||||||
Plane3<ScalarType> plane;
|
Plane3<ScalarType> plane;
|
||||||
FitPlaneToPointSet(ptVec,plane);
|
FitPlaneToPointSet(ptVec,plane);
|
||||||
|
@ -60,14 +63,16 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddNeighboursToHeap( MeshType &m, VertexPointer vp, KdTree<ScalarType> &tree, std::vector<WArc> &heap)
|
static void AddNeighboursToHeap( MeshType &m, VertexPointer vp, int nn, KdTree<ScalarType> &tree, std::vector<WArc> &heap)
|
||||||
{
|
{
|
||||||
tree.doQueryK(vp->cP());
|
typename KdTree<ScalarType>::PriorityQueue nq;
|
||||||
|
tree.doQueryK(vp->cP(),nn,nq);
|
||||||
|
|
||||||
int neighbours = tree.getNofFoundNeighbors();
|
int neighbours = nq.getNofElements();
|
||||||
for (int i = 0; i < neighbours; i++)
|
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 (neightId < m.vn && (&m.vert[neightId] != vp))
|
||||||
{
|
{
|
||||||
if(!m.vert[neightId].IsV())
|
if(!m.vert[neightId].IsV())
|
||||||
|
@ -114,7 +119,7 @@ public:
|
||||||
tri::Smooth<MeshType>::VertexNormalPointCloud(m,p.fittingAdjNum,p.smoothingIterNum,&tree);
|
tri::Smooth<MeshType>::VertexNormalPointCloud(m,p.fittingAdjNum,p.smoothingIterNum,&tree);
|
||||||
|
|
||||||
if(p.coherentAdjNum==0) return;
|
if(p.coherentAdjNum==0) return;
|
||||||
tree.setMaxNofNeighbors(p.coherentAdjNum+1);
|
// tree.setMaxNofNeighbors(p.coherentAdjNum+1);
|
||||||
|
|
||||||
tri::UpdateFlags<MeshType>::VertexClearV(m);
|
tri::UpdateFlags<MeshType>::VertexClearV(m);
|
||||||
std::vector<WArc> heap;
|
std::vector<WArc> heap;
|
||||||
|
@ -133,7 +138,7 @@ public:
|
||||||
vi->N()=-(*vi).N();
|
vi->N()=-(*vi).N();
|
||||||
|
|
||||||
vi->SetV();
|
vi->SetV();
|
||||||
AddNeighboursToHeap(m,&*vi,tree,heap);
|
AddNeighboursToHeap(m,&*vi,p.coherentAdjNum,tree,heap);
|
||||||
|
|
||||||
while(!heap.empty())
|
while(!heap.empty())
|
||||||
{
|
{
|
||||||
|
@ -146,7 +151,7 @@ public:
|
||||||
if(a.src->cN()*a.trg->cN()<0.0f)
|
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
|
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();
|
a.trg->N()=-a.trg->N();
|
||||||
AddNeighboursToHeap(m,a.trg,tree,heap);
|
AddNeighboursToHeap(m,a.trg,p.coherentAdjNum,tree,heap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1194,17 +1194,18 @@ static void VertexNormalPointCloud(MeshType &m, int neighborNum, int iterNum, Kd
|
||||||
KdTree<ScalarType> *tree=0;
|
KdTree<ScalarType> *tree=0;
|
||||||
if(tp==0) tree = new KdTree<ScalarType>(ww);
|
if(tp==0) tree = new KdTree<ScalarType>(ww);
|
||||||
else tree=tp;
|
else tree=tp;
|
||||||
|
typename KdTree<ScalarType>::PriorityQueue nq;
|
||||||
|
|
||||||
tree->setMaxNofNeighbors(neighborNum);
|
// tree->setMaxNofNeighbors(neighborNum);
|
||||||
for(int ii=0;ii<iterNum;++ii)
|
for(int ii=0;ii<iterNum;++ii)
|
||||||
{
|
{
|
||||||
for (VertexIterator vi = m.vert.begin();vi!=m.vert.end();++vi)
|
for (VertexIterator vi = m.vert.begin();vi!=m.vert.end();++vi)
|
||||||
{
|
{
|
||||||
tree->doQueryK(vi->cP());
|
tree->doQueryK(vi->cP(),neighborNum,nq);
|
||||||
int neighbours = tree->getNofFoundNeighbors();
|
int neighbours = nq.getNofElements();
|
||||||
for (int i = 0; i < neighbours; i++)
|
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)
|
if(m.vert[neightId].cN()*vi->cN()>0)
|
||||||
TD[vi]+= m.vert[neightId].cN();
|
TD[vi]+= m.vert[neightId].cN();
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue