diff --git a/.gitignore b/.gitignore index 6b75457c..1019c660 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/vcg/space/index/kdtree/kdtree_face.h b/vcg/space/index/kdtree/kdtree_face.h index 3fc373ee..66d11a10 100644 --- a/vcg/space/index/kdtree/kdtree_face.h +++ b/vcg/space/index/kdtree/kdtree_face.h @@ -57,18 +57,23 @@ namespace vcg { public: - KdTreeFace(MeshType& mesh, unsigned int maxObjPerCell = 64, unsigned int maxDepth = 64) : epsilon(std::numeric_limits::epsilon()) + KdTreeFace():epsilon(std::numeric_limits::epsilon()) + { + targetCellSize = 64; + targetMaxDepth = 64; + }; + + KdTreeFace(unsigned int maxObjPerCell, unsigned int maxDepth) : epsilon(std::numeric_limits::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::epsilon()) + { + targetCellSize = maxObjPerCell; + targetMaxDepth = maxDepth; + Set(mesh, maxObjPerCell, maxDepth); }; ~KdTreeFace() @@ -76,10 +81,53 @@ namespace vcg { }; - - template FacePointer doQueryClosest(const VectorType& queryPoint, VectorType& narestPoint, Scalar& dist, ObjectMarker& marker, Scalar maxDist = std::numeric_limits::max()) + template + void Set(const ObjIter & _oBegin, const ObjIter & _oEnd, int size = 0, bool onlySelection = false) { - if (maxDist < std::numeric_limits::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 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 FacePointer GetClosest(const VectorType& queryPoint, VectorType& narestPoint, Scalar& dist, ObjectMarker& marker, Scalar maxDist = std::numeric_limits::max()) + template + FacePointer GetClosest(ObjPointDistFunction& pDistFunc, ObjectMarker& marker, const VectorType& queryPoint, Scalar maxDist, Scalar& dist, VectorType& narestPoint) + { + if (mNodes.size() == 0|| (maxDist < std::numeric_limits::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)