Skip to content

Commit

Permalink
[SpatialPartitioning] KdTreeQueries: Move implementation to headers
Browse files Browse the repository at this point in the history
  • Loading branch information
nmellado committed Jul 26, 2023
1 parent 360e4ea commit 557aa8c
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,24 @@ class KdTreeKNearestIndexQuery : public KdTreeQuery<Traits>,
}

public:
KdTreeKNearestIterator<IndexType, DataPoint> begin();
KdTreeKNearestIterator<IndexType, DataPoint> end();
KdTreeKNearestIterator<IndexType, DataPoint> begin(){
QueryAccelType::reset();
QueryType::reset();
this->search();
return KdTreeKNearestIterator<IndexType, DataPoint>(QueryType::m_queue.begin());
}
KdTreeKNearestIterator<IndexType, DataPoint> end(){
return KdTreeKNearestIterator<IndexType, DataPoint>(QueryType::m_queue.end());
}

protected:
void search();
void search(){
KdTreeQuery<Traits>::search_internal(QueryAccelType::m_kdtree->point_data()[QueryType::input()].pos(),
[](IndexType, IndexType){},
[this](){return QueryType::descentDistanceThreshold();},
[this](IndexType idx){return QueryType::input() == idx;},
[this](IndexType idx, IndexType, Scalar d){QueryType::m_queue.push({idx, d}); return false;}
);
}
};

#include "./kdTreeKNearestIndexQuery.hpp"
} // namespace ponca

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,25 @@ class KdTreeKNearestPointQuery : public KdTreeQuery<Traits>,
}

public:
KdTreeKNearestIterator<IndexType, DataPoint> begin();
KdTreeKNearestIterator<IndexType, DataPoint> end();
KdTreeKNearestIterator<IndexType, DataPoint> begin(){
QueryAccelType::reset();
QueryType::reset();
this->search();
return KdTreeKNearestIterator<IndexType, DataPoint>(QueryType::m_queue.begin());
}
KdTreeKNearestIterator<IndexType, DataPoint> end(){
return KdTreeKNearestIterator<IndexType, DataPoint>(QueryType::m_queue.end());
}

protected:
void search();
void search(){
KdTreeQuery<Traits>::search_internal(QueryType::input(),
[](IndexType, IndexType){},
[this](){return QueryType::descentDistanceThreshold();},
[](IndexType){return false;},
[this](IndexType idx, IndexType, Scalar d){QueryType::m_queue.push({idx, d}); return false;}
);
}
};

#include "./kdTreeKNearestPointQuery.hpp"
} // namespace Ponca

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,29 @@ class KdTreeNearestIndexQuery : public KdTreeQuery<Traits>,
}

public:
KdTreeNearestIterator<IndexType> begin();
KdTreeNearestIterator<IndexType> end();
KdTreeNearestIterator<IndexType> begin(){
QueryAccelType::reset();
QueryType::reset();
this->search();
return KdTreeNearestIterator<IndexType>(QueryType::m_nearest);
}
KdTreeNearestIterator<IndexType> end(){
return KdTreeNearestIterator<IndexType>(QueryType::m_nearest + 1);
}

protected:
void search();
void search(){
KdTreeQuery<Traits>::search_internal(QueryAccelType::m_kdtree->point_data()[QueryType::input()].pos(),
[](IndexType, IndexType){},
[this](){return QueryType::descentDistanceThreshold();},
[this](IndexType idx){return QueryType::input() == idx;},
[this](IndexType idx, IndexType, Scalar d)
{
QueryType::m_nearest = idx;
QueryType::m_squared_distance = d;
return false;
}
);
}
};

#include "./kdTreeNearestIndexQuery.hpp"
} // namespace ponca

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,29 @@ class KdTreeNearestPointQuery : public KdTreeQuery<Traits>,
}

public:
KdTreeNearestIterator<IndexType> begin();
KdTreeNearestIterator<IndexType> end();
KdTreeNearestIterator<IndexType> begin(){
QueryAccelType::reset();
QueryType::reset();
this->search();
return KdTreeNearestIterator<IndexType>(QueryType::m_nearest);
}
KdTreeNearestIterator<IndexType> end(){
return KdTreeNearestIterator<IndexType>(QueryType::m_nearest + 1);
}

protected:
void search();
void search(){
KdTreeQuery<Traits>::search_internal(QueryType::input(),
[](IndexType, IndexType){},
[this](){return QueryType::descentDistanceThreshold();},
[](IndexType){return false;},
[this](IndexType idx, IndexType, Scalar d)
{
QueryType::m_nearest = idx;
QueryType::m_squared_distance = d;
return false;
}
);
}
};

#include "./kdTreeNearestPointQuery.hpp"
} // namespace ponca

This file was deleted.

55 changes: 49 additions & 6 deletions Ponca/src/SpatialPartitioning/KdTree/Query/kdTreeRangeIndexQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,56 @@ class KdTreeRangeIndexQuery : public KdTreeQuery<Traits>,
}

public:
inline Iterator begin();
inline Iterator end();
inline Iterator begin(){
QueryAccelType::reset();
QueryType::reset();
Iterator it(this);
this->advance(it);
return it;
}
inline Iterator end(){
return Iterator(this, QueryAccelType::m_kdtree->point_count());
}

protected:
inline void initialize();
inline void advance(Iterator& iterator);
};
inline void advance(Iterator& it){
const auto& points = QueryAccelType::m_kdtree->point_data();
const auto& indices = QueryAccelType::m_kdtree->index_data();
const auto& point = points[QueryType::input()].pos();

if (points.empty() || indices.empty())
throw std::invalid_argument("Empty KdTree");

#include "./kdTreeRangeIndexQuery.hpp"
for(IndexType i=it.m_start; i<it.m_end; ++i)
{
IndexType idx = indices[i];
if(idx == QueryType::input()) continue;

Scalar d = (point - points[idx].pos()).squaredNorm();
if(d < QueryType::descentDistanceThreshold())
{
it.m_index = idx;
it.m_start = i+1;
return;
}
}

if (KdTreeQuery<Traits>::search_internal(point,
[&it](IndexType start, IndexType end)
{
it.m_start = start;
it.m_end = end;
},
[this](){return QueryType::descentDistanceThreshold();},
[this](IndexType idx){return QueryType::input() == idx;},
[&it](IndexType idx, IndexType i, Scalar)
{
it.m_index = idx;
it.m_start = i+1;
return true;
}
))
it.m_index = static_cast<IndexType>(points.size());
}
};
} // namespace ponca
Loading

0 comments on commit 557aa8c

Please sign in to comment.