10#include "./indexSquaredDistance.h"
11#include "../Common/Containers/limitedPriorityQueue.h"
13#include PONCA_MULTIARCH_INCLUDE_STD(cmath)
14#include PONCA_MULTIARCH_INCLUDE_STD(limits)
22#define DECLARE_INDEX_QUERY_CLASS(OUT_TYPE) \
24template <typename Index, typename Scalar> \
25struct OUT_TYPE##IndexQuery : Query<QueryInputIsIndex<Index>, QueryOutputIs##OUT_TYPE<Index, Scalar>> \
27 using Base = Query<QueryInputIsIndex<Index>, QueryOutputIs##OUT_TYPE<Index, Scalar>>; \
35#define DECLARE_POINT_QUERY_CLASS(OUT_TYPE) \
37template <typename Index, typename DataPoint> \
38struct OUT_TYPE##PointQuery : Query<QueryInputIsPosition<DataPoint>, \
39 QueryOutputIs##OUT_TYPE<Index, typename DataPoint::Scalar>> \
41 using Base = Query<QueryInputIsPosition<DataPoint>, QueryOutputIs##OUT_TYPE<Index, typename DataPoint::Scalar>>; \
63 template<
typename InputType_>
65 using InputType = InputType_;
67 inline QueryInput(InputType input) : m_input(input) {}
69 inline const InputType &input()
const {
return m_input; }
75 inline void editInput(
const InputType& input) { m_input = input; }
79 const InputType m_input;
84 template <
typename Index>
87 using InputType =
typename Base::InputType;
93 template <
typename IndexType>
96 template <
typename Container>
97 inline auto getInputPosition(
const Container &c) ->
const typename Container::value_type::VectorType
98 {
return c[Base::input()].pos(); }
102 template<
typename DataPo
int>
105 using InputType =
typename Base::InputType;
111 template <
typename IndexType>
114 template <
typename Container>
115 inline auto getInputPosition(
const Container &) ->
const typename Container::value_type::VectorType
116 {
return Base::input(); }
120 template<
typename Index,
typename Scalar>
122 using OutputParameter = Scalar;
125 : m_squared_radius(PONCA_MULTIARCH_CU_STD_NAMESPACE(pow)(radius, OutputParameter(2))) {}
127 inline Scalar radius()
const {
128 PONCA_MULTIARCH_STD_MATH(sqrt);
129 return sqrt(m_squared_radius);
132 inline Scalar squared_radius()
const {
return m_squared_radius; }
134 inline void set_radius(Scalar radius) {
135 PONCA_MULTIARCH_STD_MATH(pow);
136 m_squared_radius = pow(radius, 2);
139 inline void set_squared_radius(Scalar radius) { m_squared_radius = radius; }
146 Scalar m_squared_radius{0};
150 template<
typename Index,
typename Scalar>
156 Index get()
const {
return m_nearest; }
161 PONCA_MULTIARCH_STD_MATH(numeric_limits);
163 m_squared_distance = numeric_limits<Scalar>::max();
168 Index m_nearest {-1};
169 Scalar m_squared_distance {PONCA_MULTIARCH_CU_STD_NAMESPACE(numeric_limits)<Scalar>::max()};
173 template<
typename Index,
typename Scalar>
175 using OutputParameter = Index;
184 PONCA_MULTIARCH_STD_MATH(numeric_limits);
186 m_queue.push({-1, numeric_limits<Scalar>::max()});
194 template<
typename Input_,
typename Output_>
195 struct Query :
public Input_,
public Output_ {
196 using QueryInType = Input_;
197 using QueryOutType = Output_;
199 static_assert(std::is_base_of<QueryInputBase, QueryInType>::value,
200 "QueryInType must inherit Ponca::QueryInputBase");
201 static_assert(std::is_base_of<QueryOutputBase, QueryOutType>::value,
202 "QueryInType must inherit Ponca::QueryInputBase");
204 inline Query(
const typename QueryInType::InputType &in)
205 : QueryInType(in), QueryOutType() {}
207 inline Query(
const typename QueryOutType::OutputParameter &outParam,
208 const typename QueryInType::InputType &in)
209 : QueryInType(in), QueryOutType(outParam) {}
212DECLARE_INDEX_QUERY_CLASS(KNearest)
213DECLARE_INDEX_QUERY_CLASS(Nearest)
214DECLARE_INDEX_QUERY_CLASS(Range)
215DECLARE_POINT_QUERY_CLASS(KNearest)
216DECLARE_POINT_QUERY_CLASS(Nearest)
217DECLARE_POINT_QUERY_CLASS(Range)
221#undef DECLARE_INDEX_QUERY_CLASS
222#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.