Code refactory
Added common interface with the other indexing structure
This commit is contained in:
parent
70d9050ffc
commit
2a33dcf967
|
@ -19,3 +19,9 @@ release/
|
||||||
*.vcxproj
|
*.vcxproj
|
||||||
*.vcxproj.filters
|
*.vcxproj.filters
|
||||||
*.suo
|
*.suo
|
||||||
|
*.ply
|
||||||
|
wrap/nanoply/nanoply_vcg/nanoply_vcg.sln
|
||||||
|
*.db
|
||||||
|
wrap/nanoply/nanoply_vcg/nanoply_vcg.VC.VC.opendb
|
||||||
|
wrap/nanoply/nanoply_vcg/.vs/nanoply_vcg/v15/ipch/AutoPCH/NANOPLY_VCG-1b6b1a83/MAIN-5f62d91f/MAIN.ipch
|
||||||
|
*.sln
|
||||||
|
|
|
@ -57,18 +57,23 @@ namespace vcg {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
KdTreeFace(MeshType& mesh, unsigned int maxObjPerCell = 64, unsigned int maxDepth = 64) : epsilon(std::numeric_limits<Scalar>::epsilon())
|
KdTreeFace():epsilon(std::numeric_limits<Scalar>::epsilon())
|
||||||
|
{
|
||||||
|
targetCellSize = 64;
|
||||||
|
targetMaxDepth = 64;
|
||||||
|
};
|
||||||
|
|
||||||
|
KdTreeFace(unsigned int maxObjPerCell, unsigned int maxDepth) : epsilon(std::numeric_limits<Scalar>::epsilon())
|
||||||
{
|
{
|
||||||
targetCellSize = maxObjPerCell;
|
targetCellSize = maxObjPerCell;
|
||||||
targetMaxDepth = maxDepth;
|
targetMaxDepth = maxDepth;
|
||||||
mNodes.resize(1);
|
};
|
||||||
Node& node = mNodes.back();
|
|
||||||
node.leaf = 0;
|
KdTreeFace(MeshType& mesh, unsigned int maxObjPerCell = 64, unsigned int maxDepth = 64, bool onlySelection = false) : epsilon(std::numeric_limits<Scalar>::epsilon())
|
||||||
node.aabb = mesh.bbox;
|
{
|
||||||
node.aabb.Offset(VectorType(epsilon, epsilon, epsilon));
|
targetCellSize = maxObjPerCell;
|
||||||
for (int i = 0; i < mesh.face.size(); i++)
|
targetMaxDepth = maxDepth;
|
||||||
node.list.push_back(&mesh.face[i]);
|
Set(mesh, maxObjPerCell, maxDepth);
|
||||||
numLevel = createTree(0, 1);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
~KdTreeFace()
|
~KdTreeFace()
|
||||||
|
@ -76,10 +81,53 @@ namespace vcg {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class ObjIter>
|
||||||
template <class ObjectMarker> FacePointer doQueryClosest(const VectorType& queryPoint, VectorType& narestPoint, Scalar& dist, ObjectMarker& marker, Scalar maxDist = std::numeric_limits<Scalar>::max())
|
void Set(const ObjIter & _oBegin, const ObjIter & _oEnd, int size = 0, bool onlySelection = false)
|
||||||
{
|
{
|
||||||
if (maxDist < std::numeric_limits<Scalar>::max() && !mNodes[0].aabb.IsIn(queryPoint) && vcg::PointFilledBoxDistance(queryPoint, mNodes[0].aabb) >= maxDist)
|
mNodes.resize(1);
|
||||||
|
Node& node = mNodes.back();
|
||||||
|
node.leaf = 0;
|
||||||
|
node.aabb.Offset(VectorType(epsilon, epsilon, epsilon));
|
||||||
|
Box3<Scalar> box;
|
||||||
|
if (onlySelection)
|
||||||
|
{
|
||||||
|
for (ObjIter i = _oBegin; i != _oEnd; ++i)
|
||||||
|
{
|
||||||
|
if ((*i).IsS())
|
||||||
|
{
|
||||||
|
node.list.push_back(&(*i));
|
||||||
|
box.Add((*i).P(0));
|
||||||
|
box.Add((*i).P(1));
|
||||||
|
box.Add((*i).P(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (ObjIter i = _oBegin; i != _oEnd; ++i)
|
||||||
|
{
|
||||||
|
node.list.push_back(&(*i));
|
||||||
|
box.Add((*i).P(0));
|
||||||
|
box.Add((*i).P(1));
|
||||||
|
box.Add((*i).P(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node.aabb = box;
|
||||||
|
numLevel = CreateTree(0, 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
void Clear()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < mNodes.size(); i++)
|
||||||
|
mNodes[i].list.clear();
|
||||||
|
mNodes.clear();
|
||||||
|
};
|
||||||
|
|
||||||
|
//template <class ObjectMarker> FacePointer GetClosest(const VectorType& queryPoint, VectorType& narestPoint, Scalar& dist, ObjectMarker& marker, Scalar maxDist = std::numeric_limits<Scalar>::max())
|
||||||
|
template <class ObjPointDistFunction, class ObjectMarker>
|
||||||
|
FacePointer GetClosest(ObjPointDistFunction& pDistFunc, ObjectMarker& marker, const VectorType& queryPoint, Scalar maxDist, Scalar& dist, VectorType& narestPoint)
|
||||||
|
{
|
||||||
|
if (mNodes.size() == 0|| (maxDist < std::numeric_limits<Scalar>::max() && !mNodes[0].aabb.IsIn(queryPoint) && vcg::PointFilledBoxDistance(queryPoint, mNodes[0].aabb) >= maxDist))
|
||||||
{
|
{
|
||||||
dist = maxDist;
|
dist = maxDist;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -109,7 +157,7 @@ namespace vcg {
|
||||||
marker.Mark(node.list[i]);
|
marker.Mark(node.list[i]);
|
||||||
Scalar tempDist = minDist;
|
Scalar tempDist = minDist;
|
||||||
VectorType tempP;
|
VectorType tempP;
|
||||||
if (vcg::face::PointDistanceBase(*node.list[i], queryPoint, tempDist, tempP))
|
if (pDistFunc(*node.list[i], queryPoint, tempDist, tempP))
|
||||||
{
|
{
|
||||||
if (tempDist < minDist)
|
if (tempDist < minDist)
|
||||||
{
|
{
|
||||||
|
@ -176,7 +224,7 @@ namespace vcg {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int createTree(unsigned int nodeId, unsigned int level)
|
int CreateTree(unsigned int nodeId, unsigned int level)
|
||||||
{
|
{
|
||||||
Node& node = mNodes[nodeId];
|
Node& node = mNodes[nodeId];
|
||||||
VectorType diag = node.aabb.max - node.aabb.min;
|
VectorType diag = node.aabb.max - node.aabb.min;
|
||||||
|
@ -264,7 +312,7 @@ namespace vcg {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
leftChild.leaf = 0;
|
leftChild.leaf = 0;
|
||||||
leftLevel = createTree(firstChildId, level + 1);
|
leftLevel = CreateTree(firstChildId, level + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +326,7 @@ namespace vcg {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rightChild.leaf = 0;
|
rightChild.leaf = 0;
|
||||||
rightLevel = createTree(firstChildId + 1, level + 1);
|
rightLevel = CreateTree(firstChildId + 1, level + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (leftLevel > rightLevel)
|
if (leftLevel > rightLevel)
|
||||||
|
|
Loading…
Reference in New Issue