Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare mls #105

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class KdTreeRangeQueryBase : public KdTreeQuery<Traits>, public QueryType
using VectorType = typename DataPoint::VectorType;
using QueryAccelType = KdTreeQuery<Traits>;
using Iterator = IteratorType<IndexType, DataPoint, KdTreeRangeQueryBase>;
using Self = KdTreeRangeQueryBase<Traits, IteratorType, QueryType>;

protected:
friend Iterator;
Expand All @@ -34,6 +35,11 @@ class KdTreeRangeQueryBase : public KdTreeQuery<Traits>, public QueryType
KdTreeQuery<Traits>(kdtree), QueryType(radius, input){}

public:
inline Self& operator()(typename QueryType::InputType input, Scalar radius)
{ QueryAccelType::reset(); return QueryType::template operator()<Self>(input, radius); }
inline Self& operator()(typename QueryType::InputType input)
{ QueryAccelType::reset(); return QueryType::template operator()<Self>(input); }

inline Iterator begin(){
QueryAccelType::reset();
QueryType::reset();
Expand Down
27 changes: 26 additions & 1 deletion Ponca/src/SpatialPartitioning/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct OUT_TYPE##PointQuery : Query<QueryInputIsPosition<DataPoint>, \
inline QueryInput(InputType input) : m_input(input) {}

inline const InputType &input() const { return m_input; }

inline void operator()(InputType_ input) { m_input = input; }
protected:
/// \brief Edit the input
/// Need to be used carefully. Modifying a query input while iterating on the query will result in undefined behavior.
Expand All @@ -75,7 +77,7 @@ struct OUT_TYPE##PointQuery : Query<QueryInputIsPosition<DataPoint>, \

private:
/// Index of the queried point
const InputType m_input;
InputType m_input;
};


Expand Down Expand Up @@ -123,6 +125,10 @@ struct OUT_TYPE##PointQuery : Query<QueryInputIsPosition<DataPoint>, \
inline QueryOutputIsRange(OutputParameter radius = OutputParameter(0))
: m_squared_radius(std::pow(radius, OutputParameter(2))) {}

inline void operator() (OutputParameter radius){
m_squared_radius = std::pow(radius, OutputParameter(2));
}

inline Scalar radius() const { return std::sqrt(m_squared_radius); }

inline Scalar squared_radius() const { return m_squared_radius; }
Expand All @@ -146,6 +152,8 @@ struct OUT_TYPE##PointQuery : Query<QueryInputIsPosition<DataPoint>, \

QueryOutputIsNearest() {}

inline void operator() (){ }

Index get() const { return m_nearest; }

protected:
Expand All @@ -168,6 +176,8 @@ struct OUT_TYPE##PointQuery : Query<QueryInputIsPosition<DataPoint>, \

inline QueryOutputIsKNearest(OutputParameter k = 0) : m_queue(k) {}

inline void operator() (OutputParameter k) { m_queue = limited_priority_queue<IndexSquaredDistance<Index, Scalar>>(k); }

inline limited_priority_queue<IndexSquaredDistance<Index, Scalar>> &queue() { return m_queue; }

protected:
Expand Down Expand Up @@ -198,6 +208,21 @@ struct OUT_TYPE##PointQuery : Query<QueryInputIsPosition<DataPoint>, \
inline Query(const typename QueryOutType::OutputParameter &outParam,
const typename QueryInType::InputType &in)
: QueryOutType(outParam), QueryInType(in) {}

template<typename Base, typename... outputType>
inline Base& operator()(const typename QueryInType::InputType &in, outputType... out){
QueryInType:: operator()(in);
QueryOutType::operator()(out...);
QueryOutType::reset();
return *((Base*)(this));
}

template<typename Base>
inline Base& operator()(const typename QueryInType::InputType &in){
QueryInType:: operator()(in);
QueryOutType::reset();
return *((Base*)(this));
}
};

DECLARE_INDEX_QUERY_CLASS(KNearest) //KNearestIndexQuery
Expand Down
40 changes: 26 additions & 14 deletions tests/src/queries_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,33 @@ void testKdTreeRangeIndex(bool quick = true)


#pragma omp parallel for
for (int i = 0; i < N; ++i)
{
Scalar r = Eigen::internal::random<Scalar>(0., 0.5);
std::vector<int> resultsTree;
for (int i = 0; i < N; ++i) {

for (int j : kdtree->range_neighbors(i, r)) {
resultsTree.push_back(j);
}
if( SampleKdTree ) {
bool resTree = check_range_neighbors<Scalar, VectorContainer>(points, sampling, i, r, resultsTree);
VERIFY(resTree);
}
else {
bool resTree = check_range_neighbors<Scalar, VectorContainer>(points, sampling, i, r, resultsTree);
VERIFY(resTree);
// auto query = KdTreeRangeIndexQuery<KdTreeDefaultTraits<DataPoint>>(kdtree, 0, 0.);
auto query = kdtree->range_neighbors(0, 0);

for (int repeatRadius = 0; repeatRadius != 10; ++repeatRadius) {
std::vector<int> resultsTree, resultsMutable;
Scalar r = Eigen::internal::random<Scalar>(0.01, 0.5);

for (int j: kdtree->range_neighbors(i, r)) {
resultsTree.push_back(j);
}
// for (int j : kdtree->range_neighbors(i, r)) {
for (int j: query(i, r)) {
resultsMutable.push_back(j);
}
if (SampleKdTree) {
bool resTree = check_range_neighbors<Scalar, VectorContainer>(points, sampling, i, r, resultsTree);
bool resMutable = check_range_neighbors<Scalar, VectorContainer>(points, sampling, i, r, resultsMutable);
VERIFY(resTree);
VERIFY(resMutable);
} else {
bool resTree = check_range_neighbors<Scalar, VectorContainer>(points, sampling, i, r, resultsTree);
bool resMutable = check_range_neighbors<Scalar, VectorContainer>(points, sampling, i, r, resultsMutable);
VERIFY(resTree);
VERIFY(resMutable);
}
}
}

Expand Down
Loading