Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SpatialPartitioning] Clean up kdtree API #122

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 0 additions & 15 deletions Ponca/src/SpatialPartitioning/KdTree/kdTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,6 @@ class KdTreeBase
IndexUserContainer sampling,
Converter c);


/// Update sampling of an existing tree
template<typename IndexUserContainer>
inline void rebuild(IndexUserContainer sampling); // IndexUserContainer => Given by user, transformed to IndexContainer

inline bool valid() const;
inline std::string to_string() const;

Expand Down Expand Up @@ -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
Expand Down
40 changes: 5 additions & 35 deletions Ponca/src/SpatialPartitioning/KdTree/kdTree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,75 +47,45 @@ inline void KdTreeBase<Traits>::buildWithSampling(PointUserContainer&& points,
PONCA_DEBUG_ASSERT(this->valid());
}

template<typename Traits>
template<typename IndexUserContainer>
inline void KdTreeBase<Traits>::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<typename Traits>
bool KdTreeBase<Traits>::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<bool> 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;
}

for(NodeIndexType n=0;n<node_count();++n)
{
const NodeType& node = m_nodes.operator[](n);
const NodeType& node = m_nodes[n];
if(node.is_leaf())
{
if(index_count() <= node.leaf_start() || index_count() < node.leaf_start()+node.leaf_size())
if(index_count() <= node.leaf_start() || node.leaf_start()+node.leaf_size() > 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;
}
}
Expand Down
Loading