Skip to content

Commit 6851026

Browse files
committed
[WIP] fix KdTree search
a point is neighbor to itself if it participated in creating the tree
1 parent bec6491 commit 6851026

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/software/pipeline/main_filterSfM.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,12 @@ bool filterObservations2(SfMData& sfmData, int maxNbObservationsPerLandmark, int
368368
{
369369
const sfmData::Landmark& landmark = landmarksData[i];
370370
auto& [indices_, weights_] = neighborsData[i];
371-
indices_.resize(nbNeighbors);
372-
weights_.resize(nbNeighbors);
373-
tree.knnSearch(landmark.X.data(), nbNeighbors, &indices_[0], &weights_[0]);
371+
// a landmark is a neighbor to itself with zero distance
372+
indices_.resize(nbNeighbors + 1);
373+
weights_.resize(nbNeighbors + 1);
374+
tree.knnSearch(landmark.X.data(), nbNeighbors + 1, &indices_[0], &weights_[0]);
375+
indices_.erase(indices_.begin());
376+
weights_.erase(weights_.begin());
374377
double total = 0.;
375378
for(auto& w : weights_)
376379
{

src/software/pipeline/main_prepareDenseScene.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ bool prepareDenseScene(const SfMData& sfmData,
358358
tree.buildIndex();
359359
ALICEVISION_LOG_INFO("KdTree created for " << observations.size() << " points.");
360360

361-
int n = std::min(nbNeighborObservations, static_cast<int>(observations.size()));
361+
int n = std::min(nbNeighborObservations, static_cast<int>(observations.size() - 1)) + 1;
362+
// note that the observation is a neighbor to itself with zero distance, hence the +/- 1
362363
std::vector<double> means(observations.size());
363364
const std::size_t cacheSize = 1000;
364365
accumulator_set<double, stats<tag::tail_quantile<right>, tag::mean>> acc(
@@ -373,7 +374,7 @@ bool prepareDenseScene(const SfMData& sfmData,
373374

374375
std::transform(distances_.begin(), distances_.end(), distances_.begin(),
375376
static_cast<double (*)(double)>(std::sqrt));
376-
const auto& mean = std::accumulate(distances_.begin(), distances_.end(), 0.0) / n;
377+
const auto& mean = std::accumulate(distances_.begin(), distances_.end(), 0.0) / (n - 1);
377378
means[j++] = mean;
378379
acc(mean);
379380
}

0 commit comments

Comments
 (0)