Skip to content

better behaving real time query of KDTree #216

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

Merged
merged 3 commits into from
Feb 21, 2023
Merged
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
10 changes: 5 additions & 5 deletions include/clients/nrt/KDTreeClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ class KDTreeQuery : public FluidBaseClient, ControlIn, ControlOut
get<kOutputBuffer>().get()))
return;
auto datasetClientPtr = get<kDataSet>().get().lock();
// if (!datasetClientPtr) datasetClientPtr = mDataSetClient.get().lock();
if (!datasetClientPtr)
datasetClientPtr = kdtreeptr->getDataSet().get().lock();

Expand All @@ -219,8 +218,9 @@ class KDTreeQuery : public FluidBaseClient, ControlIn, ControlOut
auto dataset = datasetClientPtr->getDataSet();
index pointSize = dataset.pointSize();
auto outBuf = BufferAdaptor::Access(get<kOutputBuffer>().get());
index outputSize = k * pointSize;
if (outBuf.samps(0).size() < outputSize) return;
index maxK = std::min(k, (outBuf.samps(0).size() / pointSize));
if (maxK <= 0) return;
index outputSize = maxK * pointSize;

RealVector point(dims, c.allocator());
point <<= BufferAdaptor::ReadAccess(get<kInputBuffer>().get())
Expand All @@ -232,9 +232,9 @@ class KDTreeQuery : public FluidBaseClient, ControlIn, ControlOut
}

auto [dists, ids] =
kdtreeptr->algorithm().kNearest(point, k, 0, c.allocator());
kdtreeptr->algorithm().kNearest(point, maxK, 0, c.allocator());

for (index i = 0; i < k; i++)
for (index i = 0; i < maxK; i++)
{
dataset.get(*ids[asUnsigned(i)],
mRTBuffer(Slice(i * pointSize, pointSize)));
Expand Down