diff --git a/Ponca/src/SpatialPartitioning/KnnGraph/Query/knnGraphRangeQuery.h b/Ponca/src/SpatialPartitioning/KnnGraph/Query/knnGraphRangeQuery.h index 8beb23772..e2de75b13 100644 --- a/Ponca/src/SpatialPartitioning/KnnGraph/Query/knnGraphRangeQuery.h +++ b/Ponca/src/SpatialPartitioning/KnnGraph/Query/knnGraphRangeQuery.h @@ -11,6 +11,7 @@ #include #include +#include namespace Ponca { template class KnnGraphBase; @@ -33,7 +34,7 @@ class KnnGraphRangeQuery : public RangeIndexQuery* graph, Scalar radius, int index): QueryType(radius, index), m_graph(graph), - m_flag(graph->size()), + m_flag(), m_stack() {} public: @@ -50,12 +51,11 @@ class KnnGraphRangeQuery : public RangeIndexQuerysize()); - 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; } @@ -84,9 +84,8 @@ class KnnGraphRangeQuery : public RangeIndexQuery0); 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); } } @@ -96,8 +95,8 @@ class KnnGraphRangeQuery : public RangeIndexQuery* m_graph {nullptr}; - std::vector m_flag; ///< hold ids status (ids range from 0 to point cloud size) - std::stack m_stack; ///< hold ids (ids range from 0 to point cloud size) + std::set m_flag; ///< store visited ids + std::stack m_stack; ///< hold ids (ids range from 0 to point cloud size) }; } // namespace Ponca