Skip to content

Commit

Permalink
[SpatialPartitioning] Rename KdTreeImplBase to KdTreeBase
Browse files Browse the repository at this point in the history
  • Loading branch information
mazestic committed Dec 21, 2023
1 parent 24a9de6 commit 749fb53
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 45 deletions.
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 KdTreeImplBase<Traits>* kdtree, IndexType k, typename QueryType::InputType input) :
inline KdTreeKNearestQueryBase(const KdTreeBase<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 KdTreeImplBase<Traits>* kdtree, typename QueryType::InputType input) :
KdTreeNearestQueryBase(const KdTreeBase<Traits>* kdtree, typename QueryType::InputType input) :
KdTreeQuery<Traits>(kdtree), QueryType(input){}

public:
Expand Down
6 changes: 3 additions & 3 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 KdTreeImplBase;
template <typename Traits> class KdTreeBase;

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 KdTreeImplBase<Traits>* kdtree) : m_kdtree( kdtree ), m_stack() {}
explicit inline KdTreeQuery(const KdTreeBase<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 KdTreeImplBase<Traits>* m_kdtree { nullptr };
const KdTreeBase<Traits>* m_kdtree { nullptr };
Stack<IndexSquaredDistance<IndexType, Scalar>, 2 * Traits::MAX_DEPTH> m_stack;

template<typename LeafPreparationFunctor,
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 KdTreeImplBase<Traits>* kdtree, Scalar radius, typename QueryType::InputType input) :
KdTreeRangeQueryBase(const KdTreeBase<Traits>* kdtree, Scalar radius, typename QueryType::InputType input) :
KdTreeQuery<Traits>(kdtree), QueryType(radius, input){}

public:
Expand Down
28 changes: 14 additions & 14 deletions Ponca/src/SpatialPartitioning/KdTree/kdTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
#include "Query/kdTreeRangeQueries.h"

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

/*!
* \brief Base type for default KdTree implementations
*
* \see KdTreeDefaultTraits for the default trait interface documentation.
* \see KdTreeImplBase for complete API
* \see KdTreeBase for complete API
*/
template <typename DataPoint>
using KdTreeImpl = KdTreeImplBase<KdTreeDefaultTraits<DataPoint>>;
using KdTree = KdTreeBase<KdTreeDefaultTraits<DataPoint>>;

/*!
* \brief Public interface for dense KdTree datastructure.
Expand Down Expand Up @@ -74,7 +74,7 @@ using KdTreeSparse = KdTreeSparseBase<KdTreeDefaultTraits<DataPoint>>;
* \todo Better handle sampling: do not store non-selected points (requires to store original indices)
*/
template <typename Traits>
class KdTreeImplBase
class KdTreeBase
{
public:
using DataPoint = typename Traits::DataPoint; ///< DataPoint given by user via Traits
Expand Down Expand Up @@ -277,7 +277,7 @@ public :

// Internal ----------------------------------------------------------------
protected:
inline KdTreeImplBase() = default;
inline KdTreeBase() = default;

/// Generate a tree sampled from a custom contained type converted using a `Converter`
/// \tparam PointUserContainer Input point, transformed to PointContainer
Expand All @@ -291,7 +291,7 @@ public :
IndexUserContainer sampling,
Converter c);

/// Generate a tree sampled from a custom contained type converted using a \ref KdTreeImplBase::DefaultConverter
/// Generate a tree sampled from a custom contained type converted using a \ref KdTreeBase::DefaultConverter
/// \tparam PointUserContainer Input points, transformed to PointContainer
/// \tparam IndexUserContainer Input sampling, transformed to IndexContainer
/// \param points Input points
Expand Down Expand Up @@ -323,17 +323,17 @@ public :
* \see KdTreeDefaultTraits for the trait interface documentation.
*/
template <typename Traits>
class KdTreeDenseBase : public KdTreeImplBase<Traits>
class KdTreeDenseBase : public KdTreeBase<Traits>
{
private:
using Base = KdTreeImplBase<Traits>;
using Base = KdTreeBase<Traits>;

public:
/// Default constructor creating an empty tree
/// \see build
KdTreeDenseBase() = default;

/// Constructor generating a tree from a custom contained type converted using a \ref KdTreeImplBase::DefaultConverter
/// Constructor generating a tree from a custom contained type converted using a \ref KdTreeBase::DefaultConverter
template<typename PointUserContainer>
inline explicit KdTreeDenseBase(PointUserContainer&& points)
: Base()
Expand All @@ -357,10 +357,10 @@ class KdTreeDenseBase : public KdTreeImplBase<Traits>
* \see KdTreeDefaultTraits for the trait interface documentation.
*/
template <typename Traits>
class KdTreeSparseBase : public KdTreeImplBase<Traits>
class KdTreeSparseBase : public KdTreeBase<Traits>
{
private:
using Base = KdTreeImplBase<Traits>;
using Base = KdTreeBase<Traits>;

public:
static constexpr bool SUPPORTS_SUBSAMPLING = false;
Expand All @@ -369,15 +369,15 @@ class KdTreeSparseBase : public KdTreeImplBase<Traits>
/// \see build
KdTreeSparseBase() = default;

/// Constructor generating a tree from a custom contained type converted using a \ref KdTreeImplBase::DefaultConverter
/// Constructor generating a tree from a custom contained type converted using a \ref KdTreeBase::DefaultConverter
template<typename PointUserContainer>
inline explicit KdTreeSparseBase(PointUserContainer&& points)
: Base()
{
this->build(std::forward<PointUserContainer>(points));
}

/// Constructor generating a tree sampled from a custom contained type converted using a \ref KdTreeImplBase::DefaultConverter
/// Constructor generating a tree sampled from a custom contained type converted using a \ref KdTreeBase::DefaultConverter
/// \tparam PointUserContainer Input points, transformed to PointContainer
/// \tparam IndexUserContainer Input sampling, transformed to IndexContainer
/// \param point Input points
Expand All @@ -396,7 +396,7 @@ class KdTreeSparseBase : public KdTreeImplBase<Traits>
} // namespace Ponca

template <typename Traits>
std::ostream& operator<<(std::ostream& os, const Ponca::KdTreeImplBase<Traits>& kdtree)
std::ostream& operator<<(std::ostream& os, const Ponca::KdTreeBase<Traits>& kdtree)
{
kdtree.print(os);
return os;
Expand Down
18 changes: 9 additions & 9 deletions Ponca/src/SpatialPartitioning/KdTree/kdTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

template<typename Traits>
template<typename PointUserContainer, typename Converter>
inline void KdTreeImplBase<Traits>::build(PointUserContainer&& points, Converter c)
inline void KdTreeBase<Traits>::build(PointUserContainer&& points, Converter c)
{
IndexContainer ids(points.size());
std::iota(ids.begin(), ids.end(), 0);
this->buildWithSampling(std::forward<PointUserContainer>(points), std::move(ids), std::move(c));
}

template<typename Traits>
void KdTreeImplBase<Traits>::clear()
void KdTreeBase<Traits>::clear()
{
m_points.clear();
m_nodes.clear();
Expand All @@ -25,7 +25,7 @@ void KdTreeImplBase<Traits>::clear()
}

template<typename Traits>
bool KdTreeImplBase<Traits>::valid() const
bool KdTreeBase<Traits>::valid() const
{
if (m_points.empty())
return m_nodes.empty() && m_indices.empty();
Expand Down Expand Up @@ -72,7 +72,7 @@ bool KdTreeImplBase<Traits>::valid() const
}

template<typename Traits>
void KdTreeImplBase<Traits>::print(std::ostream& os, bool verbose) const
void KdTreeBase<Traits>::print(std::ostream& os, bool verbose) const
{
os << "KdTree:";
os << "\n MaxNodes: " << MAX_NODE_COUNT;
Expand Down Expand Up @@ -118,9 +118,9 @@ void KdTreeImplBase<Traits>::print(std::ostream& os, bool verbose) const

template<typename Traits>
template<typename PointUserContainer, typename IndexUserContainer, typename Converter>
inline void KdTreeImplBase<Traits>::buildWithSampling(PointUserContainer&& points,
IndexUserContainer sampling,
Converter c)
inline void KdTreeBase<Traits>::buildWithSampling(PointUserContainer&& points,
IndexUserContainer sampling,
Converter c)
{
PONCA_DEBUG_ASSERT(points.size() <= MAX_POINT_COUNT);
this->clear();
Expand All @@ -140,7 +140,7 @@ inline void KdTreeImplBase<Traits>::buildWithSampling(PointUserContainer&& point
}

template<typename Traits>
void KdTreeImplBase<Traits>::build_rec(NodeIndexType node_id, IndexType start, IndexType end, int level)
void KdTreeBase<Traits>::build_rec(NodeIndexType node_id, IndexType start, IndexType end, int level)
{
NodeType& node = m_nodes[node_id];
AabbType aabb;
Expand Down Expand Up @@ -174,7 +174,7 @@ void KdTreeImplBase<Traits>::build_rec(NodeIndexType node_id, IndexType start, I
}

template<typename Traits>
auto KdTreeImplBase<Traits>::partition(IndexType start, IndexType end, int dim, Scalar value)
auto KdTreeBase<Traits>::partition(IndexType start, IndexType end, int dim, Scalar value)
-> IndexType
{
const auto& points = m_points;
Expand Down
2 changes: 1 addition & 1 deletion Ponca/src/SpatialPartitioning/KnnGraph/knnGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ template <typename Traits> class KnnGraphBase
/// \warning Stores a const reference to kdtree.point_data()
/// \warning KdTreeTraits compatibility is checked with static assertion
template<typename KdTreeTraits>
inline KnnGraphBase(const KdTreeImplBase<KdTreeTraits>& kdtree, int k = 6)
inline KnnGraphBase(const KdTreeBase<KdTreeTraits>& kdtree, int k = 6)
: m_k(std::min(k,kdtree.sample_count()-1)),
m_kdTreePoints(kdtree.points())
{
Expand Down
10 changes: 5 additions & 5 deletions doc/src/ponca_module_spatialpartitioning.mdoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ fit.computeWithIds( myDataStructure.range_neighbors(fitInitPos, scale), vectorPo

We call indices into the underlying point storage *point indices* and indices into the sample storage *sample
indices*. Note that the sample storage stores point indices: sample number 0 may, for example, refer to point number 25.
The point storage can be accessed with KdTreeImplBase::points, while the array of samples can be accessed with
KdTreeImplBase::samples.
The point storage can be accessed with KdTreeBase::points, while the array of samples can be accessed with
KdTreeBase::samples.

While most of the KdTree API is built on using point indices, it can still be useful to iterate over samples instead
(e.g. when using a Ponca::KdTreeSparse). If you ever need to convert sample indices to point indices, see
KdTreeImplBase::pointFromSample (see also KdTreeImplBase::pointDataFromSample).
KdTreeBase::pointFromSample (see also KdTreeBase::pointDataFromSample).

\subsection spatialpartitioning_kdtree_examples Examples

Expand All @@ -120,8 +120,8 @@ fit.computeWithIds( myDataStructure.range_neighbors(fitInitPos, scale), vectorPo
The kd-tree is a binary search tree that
- is balanced (cuts at the median at each node)
- cuts along the dimension that extends the most at each node
- has a maximal depth (KdTreeImplBase::MAX_DEPTH)
- has a minimal number of points per leaf (KdTreeImplBase::m_min_cell_size)
- has a maximal depth (KdTreeBase::MAX_DEPTH)
- has a minimal number of points per leaf (KdTreeBase::m_min_cell_size)
- only stores points in the leafs
- uses depth-first search with a static stack for queries
- keeps the initial order of points
Expand Down
6 changes: 3 additions & 3 deletions tests/src/basket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using namespace std;
using namespace Ponca;

template<typename DataPoint>
typename DataPoint::Scalar generateData(KdTreeImpl<DataPoint>& tree)
typename DataPoint::Scalar generateData(KdTree<DataPoint>& tree)
{
typedef typename DataPoint::Scalar Scalar;
typedef typename DataPoint::VectorType VectorType;
Expand Down Expand Up @@ -61,7 +61,7 @@ typename DataPoint::Scalar generateData(KdTreeImpl<DataPoint>& tree)
}

template<typename Fit>
void testBasicFunctionalities(const KdTreeImpl<typename Fit::DataPoint>& tree, typename Fit::Scalar analysisScale)
void testBasicFunctionalities(const KdTree<typename Fit::DataPoint>& tree, typename Fit::Scalar analysisScale)
{
using DataPoint = typename Fit::DataPoint;

Expand Down Expand Up @@ -124,7 +124,7 @@ void testBasicFunctionalities(const KdTreeImpl<typename Fit::DataPoint>& tree, t
}

template<typename Fit1, typename Fit2, typename Functor>
void testIsSame(const KdTreeImpl<typename Fit1::DataPoint>& tree,
void testIsSame(const KdTree<typename Fit1::DataPoint>& tree,
typename Fit1::Scalar analysisScale,
Functor f)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/src/queries_knearest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ template<typename DataPoint>
void testKdTreeKNearestIndex(bool quick = true)
{
using Scalar = typename DataPoint::Scalar;
using VectorContainer = typename KdTreeImpl<DataPoint>::PointContainer;
using VectorContainer = typename KdTree<DataPoint>::PointContainer;
using VectorType = typename DataPoint::VectorType;

const int N = quick ? 100 : 10000;
Expand Down Expand Up @@ -77,7 +77,7 @@ template<typename DataPoint>
void testKdTreeKNearestPoint(bool quick = true)
{
using Scalar = typename DataPoint::Scalar;
using VectorContainer = typename KdTreeImpl<DataPoint>::PointContainer;
using VectorContainer = typename KdTree<DataPoint>::PointContainer;
using VectorType = typename DataPoint::VectorType;

const int N = quick ? 100 : 10000;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/queries_nearest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ template<typename DataPoint>
void testKdTreeNearestIndex(bool quick = true)
{
using Scalar = typename DataPoint::Scalar;
using VectorContainer = typename KdTreeImpl<DataPoint>::PointContainer;
using VectorContainer = typename KdTree<DataPoint>::PointContainer;
using VectorType = typename DataPoint::VectorType;

const int N = quick ? 100 : 10000;
Expand Down Expand Up @@ -61,7 +61,7 @@ template<typename DataPoint>
void testKdTreeNearestPoint(bool quick = true)
{
using Scalar = typename DataPoint::Scalar;
using VectorContainer = typename KdTreeImpl<DataPoint>::PointContainer;
using VectorContainer = typename KdTree<DataPoint>::PointContainer;
using VectorType = typename DataPoint::VectorType;

const int N = quick ? 100 : 10000;
Expand Down
6 changes: 3 additions & 3 deletions tests/src/queries_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ template<typename DataPoint, bool SampleKdTree = true>
void testKdTreeRangeIndex(bool quick = true)
{
using Scalar = typename DataPoint::Scalar;
using VectorContainer = typename KdTreeImpl<DataPoint>::PointContainer;
using VectorContainer = typename KdTree<DataPoint>::PointContainer;
using VectorType = typename DataPoint::VectorType;

const int N = quick ? 100 : 5000;
auto points = VectorContainer(N);
std::generate(points.begin(), points.end(), []() {return DataPoint(VectorType::Random()); });

KdTreeImpl<DataPoint> *kdtree {nullptr};
KdTree<DataPoint> *kdtree {nullptr};

std::vector<int> sampling; // we need sampling for GT computation
if(SampleKdTree){
Expand Down Expand Up @@ -89,7 +89,7 @@ template<typename DataPoint>
void testKdTreeRangePoint(bool quick = true)
{
using Scalar = typename DataPoint::Scalar;
using VectorContainer = typename KdTreeImpl<DataPoint>::PointContainer;
using VectorContainer = typename KdTree<DataPoint>::PointContainer;
using VectorType = typename DataPoint::VectorType;

const int N = quick ? 100 : 10000;
Expand Down

0 comments on commit 749fb53

Please sign in to comment.