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

KnnGraph: replace flag table by set #104

Merged
merged 2 commits into from
Oct 5, 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
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Ponca changelog
--------------------------------------------------------------------------------
Current head (v.1.2 RC)

- API
- [spatialPartitioning] Optimize memory use in knngraph queries (#104)
- Examples
- Fix example cuda/ponca_ssgls (#109)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <vector>
#include <stack>
#include <set>

namespace Ponca {
template <typename Traits> class KnnGraphBase;
Expand All @@ -33,7 +34,7 @@ class KnnGraphRangeQuery : public RangeIndexQuery<typename Traits::IndexType, ty
inline KnnGraphRangeQuery(const KnnGraphBase<Traits>* graph, Scalar radius, int index):
QueryType(radius, index),
m_graph(graph),
m_flag(graph->size()),
m_flag(),
m_stack() {}

public:
Expand All @@ -50,12 +51,11 @@ class KnnGraphRangeQuery : public RangeIndexQuery<typename Traits::IndexType, ty

protected:
inline void initialize(Iterator& iterator){
m_flag.resize(m_graph->size());
std::fill(m_flag.begin(), m_flag.end(), false);
m_flag.clear();
m_flag.insert(QueryType::input());

PONCA_DEBUG_ASSERT(m_stack.empty());
m_stack.push(QueryType::input());
m_flag[QueryType::input()] = true;

iterator.m_index = -1;
}
Expand Down Expand Up @@ -84,9 +84,8 @@ class KnnGraphRangeQuery : public RangeIndexQuery<typename Traits::IndexType, ty
PONCA_DEBUG_ASSERT(idx_nei>0);
Scalar d = (point - points[idx_nei].pos()).squaredNorm();
Scalar th = QueryType::descentDistanceThreshold();
if(!m_flag[idx_nei] && (point - points[idx_nei].pos()).squaredNorm() < QueryType::descentDistanceThreshold())
if((point - points[idx_nei].pos()).squaredNorm() < QueryType::descentDistanceThreshold() && m_flag.insert(idx_nei).second)
{
m_flag[idx_nei] = true;
m_stack.push(idx_nei);
}
}
Expand All @@ -96,8 +95,8 @@ class KnnGraphRangeQuery : public RangeIndexQuery<typename Traits::IndexType, ty

protected:
const KnnGraphBase<Traits>* m_graph {nullptr};
std::vector<bool> m_flag; ///< hold ids status (ids range from 0 to point cloud size)
std::stack<int> m_stack; ///< hold ids (ids range from 0 to point cloud size)
std::set<int> m_flag; ///< store visited ids
std::stack<int> m_stack; ///< hold ids (ids range from 0 to point cloud size)
};

} // namespace Ponca
Loading