Skip to content

Commit

Permalink
Merge pull request #88 from poncateam/fix_47
Browse files Browse the repository at this point in the history
Fix code duplication in queries
  • Loading branch information
nmellado authored Jul 27, 2023
2 parents e24146e + 483737f commit 85767c1
Show file tree
Hide file tree
Showing 22 changed files with 357 additions and 821 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ improved doc.
- Bug-fixes and code improvements
- [spatialPartitioning] Fix unwanted function hiding with DryFit::setWeightFunc (#86)
- [spatialPartitioning] Fix missing include directive in kdTreeTraits.h (#92)
- [spatialPartitioning] Fix duplicated code in KdTree queries (see issue #47) (#88)
- [fitting] Fix a potential bug when using multi-pass fitting (#89)
- [fitting] Fix a bug in CovarianceFit (#93)
- [fitting] Remove deadcode in Basket (#86)
Expand Down
1 change: 0 additions & 1 deletion Ponca/SpatialPartitioning
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
#include "src/SpatialPartitioning/indexSquaredDistance.h"
#include "src/SpatialPartitioning/query.h"
#include "src/SpatialPartitioning/KdTree/kdTree.h"
#include "src/SpatialPartitioning/KdTree/kdTreeQuery.h"
#include "src/SpatialPartitioning/KdTree/kdTreeTraits.h"

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

59 changes: 59 additions & 0 deletions Ponca/src/SpatialPartitioning/KdTree/Query/kdTreeKNearestQueries.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#pragma once

#include "kdTreeQuery.h"
#include "../../query.h"
#include "../Iterator/kdTreeKNearestIterator.h"

namespace Ponca {

template <typename Traits,
template <typename, typename> typename IteratorType,
typename QueryType>
class KdTreeKNearestQueryBase : public KdTreeQuery<Traits>, public QueryType
{
public:
using DataPoint = typename Traits::DataPoint;
using IndexType = typename Traits::IndexType;
using Scalar = typename DataPoint::Scalar;
using VectorType = typename DataPoint::VectorType;
using QueryAccelType = KdTreeQuery<Traits>;
using Iterator = IteratorType<typename Traits::IndexType, typename Traits::DataPoint>;

inline KdTreeKNearestQueryBase(const KdTreeBase<Traits>* kdtree, IndexType k, typename QueryType::InputType input) :
KdTreeQuery<Traits>(kdtree), QueryType(k, input) { }

public:
inline Iterator begin(){
QueryAccelType::reset();
QueryType::reset();
this->search();
return Iterator(QueryType::m_queue.begin());
}
inline Iterator end(){
return Iterator(QueryType::m_queue.end());
}

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

template <typename Traits>
using KdTreeKNearestIndexQuery = KdTreeKNearestQueryBase< Traits, KdTreeKNearestIterator,
KNearestIndexQuery<typename Traits::IndexType, typename Traits::DataPoint::Scalar>>;
template <typename Traits>
using KdTreeKNearestPointQuery = KdTreeKNearestQueryBase< Traits, KdTreeKNearestIterator,
KNearestPointQuery<typename Traits::IndexType, typename Traits::DataPoint>>;
} // namespace ponca

This file was deleted.

Loading

0 comments on commit 85767c1

Please sign in to comment.