From 8c02be6e68735d9757805e9a72ab483b0b7cd132 Mon Sep 17 00:00:00 2001 From: Amael Marquez Date: Tue, 5 Dec 2023 17:23:29 +0100 Subject: [PATCH 1/2] [SpatialPartitioning] Clean up API --- Ponca/src/SpatialPartitioning/KdTree/kdTree.h | 15 ------- .../src/SpatialPartitioning/KdTree/kdTree.hpp | 40 +++---------------- 2 files changed, 5 insertions(+), 50 deletions(-) diff --git a/Ponca/src/SpatialPartitioning/KdTree/kdTree.h b/Ponca/src/SpatialPartitioning/KdTree/kdTree.h index a5de62af..57cdecca 100644 --- a/Ponca/src/SpatialPartitioning/KdTree/kdTree.h +++ b/Ponca/src/SpatialPartitioning/KdTree/kdTree.h @@ -185,11 +185,6 @@ class KdTreeBase IndexUserContainer sampling, Converter c); - - /// Update sampling of an existing tree - template - inline void rebuild(IndexUserContainer sampling); // IndexUserContainer => Given by user, transformed to IndexContainer - inline bool valid() const; inline std::string to_string() const; @@ -230,21 +225,11 @@ class KdTreeBase return m_nodes; } - inline NodeContainer& node_data() - { - return m_nodes; - } - inline const IndexContainer& index_data() const { return m_indices; } - inline IndexContainer& index_data() - { - return m_indices; - } - // Parameters -------------------------------------------------------------- public: /// Read leaf min size diff --git a/Ponca/src/SpatialPartitioning/KdTree/kdTree.hpp b/Ponca/src/SpatialPartitioning/KdTree/kdTree.hpp index d30dc369..0ace85f2 100644 --- a/Ponca/src/SpatialPartitioning/KdTree/kdTree.hpp +++ b/Ponca/src/SpatialPartitioning/KdTree/kdTree.hpp @@ -47,49 +47,22 @@ inline void KdTreeBase::buildWithSampling(PointUserContainer&& points, PONCA_DEBUG_ASSERT(this->valid()); } -template -template -inline void KdTreeBase::rebuild(IndexUserContainer sampling) -{ - PONCA_DEBUG_ASSERT(sampling.size() <= m_points->size()); - - m_nodes.clear(); - m_nodes.emplace_back(); - - m_indices = std::move(sampling); - - this->build_rec(0, 0, index_count(), 1); - - PONCA_DEBUG_ASSERT(this->valid()); -} - template bool KdTreeBase::valid() const { - PONCA_DEBUG_ERROR; - return false; - if (m_points.empty()) return m_nodes.empty() && m_indices.empty(); - + if(m_nodes.empty() || m_indices.empty()) { - PONCA_DEBUG_ERROR; return false; } - - if(point_count() < index_count()) - { - PONCA_DEBUG_ERROR; - return false; - } - + std::vector b(point_count(), false); for(IndexType idx : m_indices) { if(idx < 0 || point_count() <= idx || b[idx]) { - PONCA_DEBUG_ERROR; return false; } b[idx] = true; @@ -97,25 +70,22 @@ bool KdTreeBase::valid() const for(NodeIndexType n=0;n index_count()) { - PONCA_DEBUG_ERROR; return false; } } else { - if(node.inner_dim() < 0 || 2 < node.inner_dim()) + if(node.inner_split_dim() < 0 || DataPoint::Dim-1 < node.inner_split_dim()) { - PONCA_DEBUG_ERROR; return false; } if(node_count() <= node.inner_first_child_id() || node_count() <= node.inner_first_child_id()+1) { - PONCA_DEBUG_ERROR; return false; } } From ec8de6097e5f0cc469c6d28482e0ebed2040160c Mon Sep 17 00:00:00 2001 From: Nicolas Mellado Date: Thu, 7 Dec 2023 21:34:05 +0100 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 068abc9d..e4e84924 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ Current head (v.1.2 RC) - API - [spatialPartitioning] Optimize memory use in knngraph queries (#104) + - [spatialPartitioning] Clean KdTree API (#122) - [fitting] Mark `Base` type as protected instead of private in CRTP classes (#119) - [fitting] Improve KdTreeNodes API by hiding internal memory layout, improve methods naming (#120)