10#include "./indexSquaredDistance.h"
11#include "../Common/Containers/limitedPriorityQueue.h"
21#define DECLARE_INDEX_QUERY_CLASS(OUT_TYPE) \
23template <typename Index, typename Scalar> \
24struct OUT_TYPE##IndexQuery : Query<QueryInputIsIndex<Index>, QueryOutputIs##OUT_TYPE<Index, Scalar>> \
26 using Base = Query<QueryInputIsIndex<Index>, QueryOutputIs##OUT_TYPE<Index, Scalar>>; \
34#define DECLARE_POINT_QUERY_CLASS(OUT_TYPE) \
36template <typename Index, typename DataPoint> \
37struct OUT_TYPE##PointQuery : Query<QueryInputIsPosition<DataPoint>, \
38 QueryOutputIs##OUT_TYPE<Index, typename DataPoint::Scalar>> \
40 using Base = Query<QueryInputIsPosition<DataPoint>, QueryOutputIs##OUT_TYPE<Index, typename DataPoint::Scalar>>; \
62 template<
typename InputType_>
64 using InputType = InputType_;
66 inline QueryInput(InputType input) : m_input(input) {}
68 inline const InputType &input()
const {
return m_input; }
74 inline void editInput(
const InputType& input) { m_input = input; }
78 const InputType m_input;
83 template <
typename Index>
86 using InputType =
typename Base::InputType;
92 template <
typename IndexType>
95 template <
typename Container>
96 inline auto getInputPosition(
const Container &c) ->
const typename Container::value_type::VectorType
97 {
return c[Base::input()].pos(); }
101 template<
typename DataPo
int>
104 using InputType =
typename Base::InputType;
110 template <
typename IndexType>
113 template <
typename Container>
114 inline auto getInputPosition(
const Container &) ->
const typename Container::value_type::VectorType
115 {
return Base::input(); }
119 template<
typename Index,
typename Scalar>
121 using OutputParameter = Scalar;
124 : m_squared_radius(std::pow(radius, OutputParameter(2))) {}
126 inline Scalar radius()
const {
return std::sqrt(m_squared_radius); }
128 inline Scalar squared_radius()
const {
return m_squared_radius; }
130 inline void set_radius(Scalar radius) { m_squared_radius = std::pow(radius, 2); }
132 inline void set_squared_radius(Scalar radius) { m_squared_radius = radius; }
139 Scalar m_squared_radius{0};
143 template<
typename Index,
typename Scalar>
149 Index get()
const {
return m_nearest; }
155 m_squared_distance = std::numeric_limits<Scalar>::max();
160 Index m_nearest {-1};
161 Scalar m_squared_distance {std::numeric_limits<Scalar>::max()};
165 template<
typename Index,
typename Scalar>
167 using OutputParameter = Index;
177 m_queue.push({-1,std::numeric_limits<Scalar>::max()});
185 template<
typename Input_,
typename Output_>
186 struct Query :
public Input_,
public Output_ {
187 using QueryInType = Input_;
188 using QueryOutType = Output_;
190 static_assert(std::is_base_of<QueryInputBase, QueryInType>::value,
191 "QueryInType must inherit Ponca::QueryInputBase");
192 static_assert(std::is_base_of<QueryOutputBase, QueryOutType>::value,
193 "QueryInType must inherit Ponca::QueryInputBase");
195 inline Query(
const typename QueryInType::InputType &in)
196 : QueryInType(in), QueryOutType() {}
198 inline Query(
const typename QueryOutType::OutputParameter &outParam,
199 const typename QueryInType::InputType &in)
200 : QueryOutType(outParam), QueryInType(in) {}
203DECLARE_INDEX_QUERY_CLASS(KNearest)
204DECLARE_INDEX_QUERY_CLASS(Nearest)
205DECLARE_INDEX_QUERY_CLASS(Range)
206DECLARE_POINT_QUERY_CLASS(KNearest)
207DECLARE_POINT_QUERY_CLASS(Nearest)
208DECLARE_POINT_QUERY_CLASS(Range)
212#undef DECLARE_INDEX_QUERY_CLASS
213#undef DECLARE_POINT_QUERY_CLASS
The limited_priority_queue class is similar to std::priority_queue but has a limited capacity and han...
Scalar descentDistanceThreshold() const
Distance threshold used during tree descent to select nodes to explore.
auto getInputPosition(const Container &c) -> const typename Container::value_type::VectorType
Generic method to access input position. Container is expected to hold kdtree positions.
void editInput(const InputType &input)
Edit the input Need to be used carefully. Modifying a query input while iterating on the query will r...
Scalar descentDistanceThreshold() const
Distance threshold used during tree descent to select nodes to explore.
bool skipIndexFunctor(IndexType idx) const
Functor used to check if a given Idx must be skipped.
auto getInputPosition(const Container &) -> const typename Container::value_type::VectorType
Generic method to access input position. Container is expected to hold kdtree positions.
void reset()
Reset Query for a new search.
void reset()
Reset Query for a new search.
void reset()
Reset Query for a new search.
Scalar descentDistanceThreshold() const
Distance threshold used during tree descent to select nodes to explore.
bool skipIndexFunctor(IndexType idx) const
Functor used to check if a given Idx must be skipped.
Base class for queries output type.
Base class for knearest queries.
Base class for nearest queries.
Base class for range queries.
This Source Code Form is subject to the terms of the Mozilla Public License, v.