Skip to content

Commit

Permalink
[SpatialPartitioning] Refactor KdTree into KdTreeDense + KdTreeSparse
Browse files Browse the repository at this point in the history
  • Loading branch information
Amael Marquez committed Dec 19, 2023
1 parent 8f9df5f commit 518fed8
Show file tree
Hide file tree
Showing 17 changed files with 316 additions and 192 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ Ponca changelog
Current head (v.1.3 RC)

- API
- [SpatialPartitioning] Change part of the kdtree API (#123)
- [spatialPartitioning] Change part of the kdtree API (#123)
- [spatialPartitioning] Refactor KdTree into KdTreeDense + KdTreeSparse (#129)

- Docs
- [spatialPartitioning] Update KdTree docs to reflect the kdtree API refactor (#129)

--------------------------------------------------------------------------------
v.1.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class KdTreeKNearestQueryBase : public KdTreeQuery<Traits>, public QueryType
using QueryAccelType = KdTreeQuery<Traits>;
using Iterator = IteratorType<typename Traits::IndexType, typename Traits::DataPoint>;

inline KdTreeKNearestQueryBase(const KdTreeBase<Traits>* kdtree, IndexType k, typename QueryType::InputType input) :
inline KdTreeKNearestQueryBase(const KdTreeImplBase<Traits>* kdtree, IndexType k, typename QueryType::InputType input) :
KdTreeQuery<Traits>(kdtree), QueryType(k, input) { }

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class KdTreeNearestQueryBase : public KdTreeQuery<Traits>, public QueryType
using QueryAccelType = KdTreeQuery<Traits>;
using Iterator = IteratorType<typename Traits::IndexType>;

KdTreeNearestQueryBase(const KdTreeBase<Traits>* kdtree, typename QueryType::InputType input) :
KdTreeNearestQueryBase(const KdTreeImplBase<Traits>* kdtree, typename QueryType::InputType input) :
KdTreeQuery<Traits>(kdtree), QueryType(input){}

public:
Expand Down
15 changes: 7 additions & 8 deletions Ponca/src/SpatialPartitioning/KdTree/Query/kdTreeQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "../../../Common/Containers/stack.h"

namespace Ponca {
template <typename Traits> class KdTreeBase;
template <typename Traits> class KdTreeImplBase;

template <typename Traits>
class KdTreeQuery
Expand All @@ -21,7 +21,7 @@ class KdTreeQuery
using Scalar = typename DataPoint::Scalar;
using VectorType = typename DataPoint::VectorType;

explicit inline KdTreeQuery(const KdTreeBase<Traits>* kdtree) : m_kdtree( kdtree ), m_stack() {}
explicit inline KdTreeQuery(const KdTreeImplBase<Traits>* kdtree) : m_kdtree( kdtree ), m_stack() {}

protected:
/// \brief Init stack for a new search
Expand All @@ -30,7 +30,7 @@ class KdTreeQuery
m_stack.push({0,0});
}

const KdTreeBase<Traits>* m_kdtree { nullptr };
const KdTreeImplBase<Traits>* m_kdtree { nullptr };
Stack<IndexSquaredDistance<IndexType, Scalar>, 2 * Traits::MAX_DEPTH> m_stack;

template<typename LeafPreparationFunctor,
Expand All @@ -44,11 +44,10 @@ class KdTreeQuery
ProcessNeighborFunctor processNeighborFunctor
)
{
const auto& nodes = m_kdtree->nodes();
const auto& points = m_kdtree->points();
const auto& indices = m_kdtree->samples();
const auto& nodes = m_kdtree->nodes();
const auto& points = m_kdtree->points();

if (nodes.empty() || points.empty() || indices.empty())
if (nodes.empty() || points.empty() || m_kdtree->sample_count() == 0)
throw std::invalid_argument("Empty KdTree");

while(!m_stack.empty())
Expand All @@ -66,7 +65,7 @@ class KdTreeQuery
prepareLeafTraversal(start, end);
for(IndexType i=start; i<end; ++i)
{
IndexType idx = indices[i];
IndexType idx = m_kdtree->pointFromSample(i);
if(skipFunctor(idx)) continue;

Scalar d = (point - points[idx].pos()).squaredNorm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class KdTreeRangeQueryBase : public KdTreeQuery<Traits>, public QueryType
friend Iterator;

public:
KdTreeRangeQueryBase(const KdTreeBase<Traits>* kdtree, Scalar radius, typename QueryType::InputType input) :
KdTreeRangeQueryBase(const KdTreeImplBase<Traits>* kdtree, Scalar radius, typename QueryType::InputType input) :
KdTreeQuery<Traits>(kdtree), QueryType(radius, input){}

public:
Expand Down
Loading

0 comments on commit 518fed8

Please sign in to comment.