From f1ab4b19fae137bbffac1369b038ca03faf62e87 Mon Sep 17 00:00:00 2001 From: attcs Date: Sat, 3 Aug 2024 20:17:42 +0200 Subject: [PATCH] ALLOW_OUT_OF_BOX_GEOMETRY flag for smallest node search fixup! ALLOW_OUT_OF_BOX_GEOMETRY flag for smallest node search --- octree.h | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/octree.h b/octree.h index 00a1be6..4828917 100644 --- a/octree.h +++ b/octree.h @@ -1061,15 +1061,25 @@ namespace OrthoTree return ri; } - + template constexpr DimArray getGridIdPoint(TVector const& point) const noexcept { auto gridIDs = DimArray{}; for (dim_t dimensionID = 0; dimensionID < DIMENSION_NO; ++dimensionID) { - autoc pointComponent = AD::GetPointC(point, dimensionID) - AD::GetBoxMinC(this->m_boxSpace, dimensionID); - auto rasterID = static_cast(pointComponent) * this->m_rasterizerFactors[dimensionID]; - gridIDs[dimensionID] = std::min(this->m_maxRasterID, static_cast(rasterID)); + auto pointComponent = AD::GetPointC(point, dimensionID) - AD::GetBoxMinC(this->m_boxSpace, dimensionID); + if constexpr (ALLOW_OUT_OF_BOX_GEOMETRY) + { + if (pointComponent < 0.0) + pointComponent = 0.0; + } + else + { + assert(pointComponent >= 0.0); + } + + autoc rasterID = GridID(pointComponent * this->m_rasterizerFactors[dimensionID]); + gridIDs[dimensionID] = std::min(this->m_maxRasterID, rasterID); } return gridIDs; } @@ -1197,16 +1207,22 @@ namespace OrthoTree return nodeChild; } - constexpr MortonGridID getLocationID(TVector const& point) const noexcept { return MortonEncode(this->getGridIdPoint(point)); } + template + constexpr MortonGridID getLocationID(TVector const& point) const noexcept + { + return MortonEncode(this->getGridIdPoint(point)); + } + template constexpr std::tuple getDepthAndLocationID(TVector const& point) const noexcept { - return { this->m_maxDepthNo, this->getLocationID(point) }; + return { this->m_maxDepthNo, this->getLocationID(point) }; } + template constexpr std::tuple getDepthAndLocationID(TBox const& box) const noexcept { - autoc entityMinMaxGridID = this->getGridIdBox(box); + autoc entityMinMaxGridID = this->getGridIdBox(box); auto minLocationID = MortonEncode(entityMinMaxGridID[0]); autoc maxLocationID = MortonEncode(entityMinMaxGridID[1]); @@ -1895,9 +1911,10 @@ namespace OrthoTree } // Get Node ID of a point + template MortonNodeID GetNodeID(TVector const& searchPoint) const noexcept { - autoc locationID = this->getLocationID(searchPoint); + autoc locationID = this->getLocationID(searchPoint); return this->GetHash(this->m_maxDepthNo, locationID); } @@ -1909,12 +1926,15 @@ namespace OrthoTree } // Find smallest node which contains the box + template MortonNodeID FindSmallestNode(TVector const& searchPoint) const noexcept { - if (!AD::DoesBoxContainPoint(this->m_boxSpace, searchPoint)) - return MortonNodeID{}; - - return this->FindSmallestNodeKey(this->GetNodeID(searchPoint)); + if constexpr (!ALLOW_OUT_OF_BOX_GEOMETRY) + { + if (!AD::DoesBoxContainPoint(this->m_boxSpace, searchPoint)) + return MortonNodeID{}; + } + return this->FindSmallestNodeKey(this->GetNodeID(searchPoint)); } // Find smallest node which contains the box @@ -2565,7 +2585,7 @@ namespace OrthoTree std::vector GetNearestNeighbors(TVector const& searchPoint, std::size_t neighborNo, TContainer const& points) const noexcept { auto neighborEntities = std::multiset(); - autoc smallestNodeKey = this->FindSmallestNode(searchPoint); + autoc smallestNodeKey = this->FindSmallestNode(searchPoint); if (Base::IsValidKey(smallestNodeKey)) { autoc& smallestNode = this->GetNode(smallestNodeKey);