Code refactory

Added common interface with the other indexing structure
This commit is contained in:
Gianpaolo Palma 2018-02-22 11:25:04 +01:00
parent 70d9050ffc
commit 2a33dcf967
2 changed files with 70 additions and 16 deletions

6
.gitignore vendored
View File

@ -19,3 +19,9 @@ release/
*.vcxproj
*.vcxproj.filters
*.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

View File

@ -57,18 +57,23 @@ namespace vcg {
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;
targetMaxDepth = maxDepth;
mNodes.resize(1);
Node& node = mNodes.back();
node.leaf = 0;
node.aabb = mesh.bbox;
node.aabb.Offset(VectorType(epsilon, epsilon, epsilon));
for (int i = 0; i < mesh.face.size(); i++)
node.list.push_back(&mesh.face[i]);
numLevel = createTree(0, 1);
};
KdTreeFace(MeshType& mesh, unsigned int maxObjPerCell = 64, unsigned int maxDepth = 64, bool onlySelection = false) : epsilon(std::numeric_limits<Scalar>::epsilon())
{
targetCellSize = maxObjPerCell;
targetMaxDepth = maxDepth;
Set(mesh, maxObjPerCell, maxDepth);
};
~KdTreeFace()
@ -76,10 +81,53 @@ namespace vcg {
};
template <class ObjectMarker> FacePointer doQueryClosest(const VectorType& queryPoint, VectorType& narestPoint, Scalar& dist, ObjectMarker& marker, Scalar maxDist = std::numeric_limits<Scalar>::max())
template <class ObjIter>
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;
return NULL;
@ -109,7 +157,7 @@ namespace vcg {
marker.Mark(node.list[i]);
Scalar tempDist = minDist;
VectorType tempP;
if (vcg::face::PointDistanceBase(*node.list[i], queryPoint, tempDist, tempP))
if (pDistFunc(*node.list[i], queryPoint, tempDist, tempP))
{
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];
VectorType diag = node.aabb.max - node.aabb.min;
@ -264,7 +312,7 @@ namespace vcg {
else
{
leftChild.leaf = 0;
leftLevel = createTree(firstChildId, level + 1);
leftLevel = CreateTree(firstChildId, level + 1);
}
}
@ -278,7 +326,7 @@ namespace vcg {
else
{
rightChild.leaf = 0;
rightLevel = createTree(firstChildId + 1, level + 1);
rightLevel = CreateTree(firstChildId + 1, level + 1);
}
}
if (leftLevel > rightLevel)