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) \
29template <typename Index, typename Scalar> \
30struct OUT_TYPE##IndexQuery : Query<QueryInputIsIndex<Index>, QueryOutputIs##OUT_TYPE<Index, Scalar>> \
33 using Base = Query<QueryInputIsIndex<Index>, QueryOutputIs##OUT_TYPE<Index, Scalar>>; \
42#define DECLARE_POINT_QUERY_CLASS(OUT_TYPE) \
49template <typename Index, typename DataPoint> \
50struct OUT_TYPE##PointQuery : Query<QueryInputIsPosition<DataPoint>, \
51 QueryOutputIs##OUT_TYPE<Index, typename DataPoint::Scalar>> \
54 using Base = Query<QueryInputIsPosition<DataPoint>, QueryOutputIs##OUT_TYPE<Index, typename DataPoint::Scalar>>; \
93 template<
typename InputType_>
126 template <
typename Index>
143 template <
typename IndexType>
146 template <
typename Container>
147 inline auto getInputPosition(
const Container &c) ->
const typename Container::value_type::VectorType
157 template<
typename DataPo
int>
174 template <
typename IndexType>
177 template <
typename Container>
178 inline auto getInputPosition(
const Container &) ->
const typename Container::value_type::VectorType
188 template<
typename Index,
typename Scalar>
213 PONCA_MULTIARCH_STD_MATH(sqrt);
247 template<
typename Index,
typename Scalar>
264 PONCA_MULTIARCH_STD_MATH(numeric_limits);
282 template<
typename Index,
typename Scalar>
299 PONCA_MULTIARCH_STD_MATH(numeric_limits);
301 m_queue.push({-1, numeric_limits<Scalar>::max()});
315 template<
typename Input_,
typename Output_>
316 struct Query :
public Input_,
public Output_ {
322 static_assert(std::is_base_of<QueryInputBase, QueryInType>::value,
323 "QueryInType must inherit Ponca::QueryInputBase");
324 static_assert(std::is_base_of<QueryOutputBase, QueryOutType>::value,
325 "QueryInType must inherit Ponca::QueryInputBase");
328 inline Query(
const typename QueryInType::InputType &in)
332 inline Query(
const typename QueryOutType::OutputParameter &outParam,
333 const typename QueryInType::InputType &in)
337 template<
typename Base,
typename... outputType>
338 inline Base&
operator()(
const typename QueryInType::InputType &in, outputType&&... out){
339 QueryInType:: operator()(in);
340 QueryOutType::operator()(std::forward<outputType>(out)...);
341 return *((Base*)(
this));
345 template<
typename Base>
346 inline Base&
operator()(
const typename QueryInType::InputType &in){
347 QueryInType:: operator()(in);
348 return *((Base*)(
this));
352DECLARE_INDEX_QUERY_CLASS(KNearest)
353DECLARE_INDEX_QUERY_CLASS(Nearest)
354DECLARE_INDEX_QUERY_CLASS(Range)
355DECLARE_POINT_QUERY_CLASS(KNearest)
356DECLARE_POINT_QUERY_CLASS(Nearest)
357DECLARE_POINT_QUERY_CLASS(Range)
361#undef DECLARE_INDEX_QUERY_CLASS
362#undef DECLARE_POINT_QUERY_CLASS
The limited_priority_queue class is similar to std::priority_queue but has a limited capacity and han...
QueryInput(InputType input)
Default constructor that initialize the input field.
Index get() const
Get the closest points.
Scalar squaredRadius() const
Generic method to access the radius squared.
void operator()(const InputType &point=InputType::Zero())
Access operator that resets the input point.
Base & operator()(const typename QueryInType::InputType &in)
Access operator that resets the input parameter only.
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.
QueryOutputIsKNearest(OutputParameter k=0)
Default constructor that initialize the output parameter value.
InputType_ InputType
Alias to the templated input type.
Scalar descentDistanceThreshold() const
Distance threshold used during tree descent to select nodes to explore.
QueryOutputIsRange(OutputParameter radius=OutputParameter(0))
Default constructor that initialize the output parameter value.
Index OutputParameter
Alias to Output type.
QueryInputIsPosition(const InputType &point=InputType::Zero())
Default constructor that initialize the input position.
limited_priority_queue< IndexSquaredDistance< Index, Scalar > > m_queue
Queue storing the neighbors.
bool skipIndexFunctor(IndexType idx) const
Functor used to check if a given Idx must be skipped.
typename Base::InputType InputType
Alias to the templated input type (Index)
Index m_nearest
Index of the nearest neighbor.
auto getInputPosition(const Container &) -> const typename Container::value_type::VectorType
Generic method to access input position. Container is expected to hold kdtree positions.
void operator()()
Access operator.
Query(const typename QueryOutType::OutputParameter &outParam, const typename QueryInType::InputType &in)
Default constructor that initialize the input and output parameters.
Scalar radius() const
Generic method to access the radius.
Scalar OutputParameter
Alias to Output type.
void reset()
Reset Query for a new search.
typename QueryOutputBase::DummyOutputParameter OutputParameter
Alias to Output type.
Scalar m_squared_radius
Radius used for the search.
void setSquaredRadius(Scalar radius)
Set the squared radius distance of the query.
typename Base::InputType InputType
Alias to the templated input type (Index)
void reset()
Reset Query for a new search.
Base & operator()(const typename QueryInType::InputType &in, outputType &&... out)
Access operator that resets the input and output parameters.
Input_ QueryInType
Alias to the input type.
void setRadius(Scalar radius)
Set the radius distance of the query.
QueryOutputIsNearest()
Default constructor.
void reset()
Reset Query for a new search.
void operator()(OutputParameter k)
Access operator that resets the output parameter.
Output_ QueryOutType
Alias to the output type.
Scalar m_squared_distance
Distance to the nearest neighbor.
limited_priority_queue< IndexSquaredDistance< Index, Scalar > > & queue()
Access to the priority queue storing the neighbors.
Scalar descentDistanceThreshold() const
Distance threshold used during tree descent to select nodes to explore.
void operator()(OutputParameter radius)
Access operator that resets the output parameter.
const InputType & input() const
Read access to the input.
Query(const typename QueryInType::InputType &in)
Default constructor that initialize the input parameter only.
bool skipIndexFunctor(IndexType idx) const
Functor used to check if a given Idx must be skipped.
QueryInputIsIndex(const InputType &point=-1)
Default constructor that initialize the input index.
void setInput(const InputType &input)
Edit the input.
void operator()(const InputType &point=InputType::Zero())
Access operator that resets the input index.
Composes the Query object depending on an input type and output type.
Base class for queries output types.
Class to construct the knearest queries.
Class to construct the nearest query output.
Class to construct the range query output.
This Source Code Form is subject to the terms of the Mozilla Public License, v.