Skip to content

Commit

Permalink
[WIP] fix KdTree search
Browse files Browse the repository at this point in the history
a point is neighbor to itself if it participated in creating the tree
  • Loading branch information
almarouk committed Sep 12, 2023
1 parent 5991230 commit b7ff339
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/software/pipeline/main_filterSfM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,12 @@ bool filterObservations2(SfMData& sfmData, int maxNbObservationsPerLandmark, int
{
const sfmData::Landmark& landmark = landmarksData[i];
auto& [indices_, weights_] = neighborsData[i];
indices_.resize(nbNeighbors);
weights_.resize(nbNeighbors);
tree.knnSearch(landmark.X.data(), nbNeighbors, &indices_[0], &weights_[0]);
// a landmark is a neighbor to itself with zero distance
indices_.resize(nbNeighbors + 1);
weights_.resize(nbNeighbors + 1);
tree.knnSearch(landmark.X.data(), nbNeighbors + 1, &indices_[0], &weights_[0]);
indices_.erase(indices_.begin());
weights_.erase(weights_.begin());
double total = 0.;
for(auto& w : weights_)
{
Expand Down
5 changes: 3 additions & 2 deletions src/software/pipeline/main_prepareDenseScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ bool prepareDenseScene(const SfMData& sfmData,
tree.buildIndex();
ALICEVISION_LOG_INFO("KdTree created for " << observations.size() << " points.");

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

std::transform(distances_.begin(), distances_.end(), distances_.begin(),
static_cast<double (*)(double)>(std::sqrt));
const auto& mean = std::accumulate(distances_.begin(), distances_.end(), 0.0) / n;
const auto& mean = std::accumulate(distances_.begin(), distances_.end(), 0.0) / (n - 1);
means[j++] = mean;
acc(mean);
}
Expand Down

0 comments on commit b7ff339

Please sign in to comment.