Skip to content

Commit

Permalink
[WIP][filterSfM] fix reference issue and refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
almarouk committed Sep 25, 2023
1 parent b16da19 commit 21105d0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 38 deletions.
16 changes: 0 additions & 16 deletions src/aliceVision/sfmData/SfMData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,21 +331,5 @@ LandmarksPerView getLandmarksPerViews(const SfMData& sfmData)
return landmarksPerView;
}

ObservationsPerView getObservationsPerViews(SfMData& sfmData)
{
ObservationsPerView observationsPerView;
for(auto& landIt : sfmData.getLandmarks())
{
for(const auto& obsIt : landIt.second.observations)
{
IndexT viewId = obsIt.first;
auto& landmarksSet = observationsPerView[viewId];
landmarksSet.first.push_back(&obsIt.second);
landmarksSet.second.push_back(&landIt.second);
}
}
return observationsPerView;
}

} // namespace sfmData
} // namespace aliceVision
10 changes: 0 additions & 10 deletions src/aliceVision/sfmData/SfMData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,15 +577,5 @@ using LandmarksPerView = stl::flat_map<std::size_t, LandmarkIdSet>;

LandmarksPerView getLandmarksPerViews(const SfMData& sfmData);

using ObservationsPerView = stl::flat_map<std::size_t, std::pair<std::vector<const Observation*>, std::vector<Landmark*>>>;

/**
* @brief Get the landmark observations of camera views
* with the corresponding landmarks information.
* @param[in] sfmData: A given SfMData
* @return Observation information per camera view
*/
ObservationsPerView getObservationsPerViews(SfMData& sfmData);

} // namespace sfmData
} // namespace aliceVision
42 changes: 33 additions & 9 deletions src/software/pipeline/main_filterSfM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ struct ObservationsAdaptator
/// CRTP helper method
inline Derived& derived() { return *static_cast<Derived*>(this); }

const std::vector<const Observation*> _data;
ObservationsAdaptator(const std::vector<const Observation*>& data)
const std::vector<Observation> _data;
ObservationsAdaptator(const std::vector<Observation>& data)
: _data(data)
{
}
Expand All @@ -68,7 +68,7 @@ struct ObservationsAdaptator
inline size_t kdtree_get_point_count() const { return _data.size(); }

// Returns the dim'th component of the idx'th point in the class:
inline T kdtree_get_pt(const size_t idx, int dim) const { return _data[idx]->x(dim); }
inline T kdtree_get_pt(const size_t idx, int dim) const { return _data[idx].x(dim); }

// Optional bounding-box computation: return false to default to a standard bbox computation loop.
// Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it
Expand Down Expand Up @@ -191,6 +191,30 @@ class PixSizeSearch
inline double worstDist() const { return _radius_sq; }
};

using ObservationsPerView = stl::flat_map<std::size_t, std::pair<std::vector<Observation>, std::vector<Landmark*>>>;

/**
* @brief Get the landmark observations of camera views
* with the corresponding landmarks information.
* @param[in] sfmData: A given SfMData
* @return Observation information per camera view
*/
ObservationsPerView getObservationsPerViews(SfMData& sfmData)
{
ObservationsPerView observationsPerView;
for(auto& landIt : sfmData.getLandmarks())
{
for(const auto& obsIt : landIt.second.observations)
{
IndexT viewId = obsIt.first;
auto& landmarksSet = observationsPerView[viewId];
landmarksSet.first.push_back(obsIt.second);
landmarksSet.second.push_back(&landIt.second);
}
}
return observationsPerView;
}

bool filterLandmarks(SfMData& sfmData, double radiusScale, bool useFeatureScale, int minNbObservationsPerLandmark)
{
const auto initialNbLandmarks = sfmData.getLandmarks().size();
Expand Down Expand Up @@ -648,7 +672,7 @@ bool filterObservations2D(SfMData& sfmData, int nbNeighbors2D, float percentile,
std::advance(itView, i);
const IndexT viewId = *itView;

auto& observationsIt = observationsPerView.find(viewId);
auto observationsIt = observationsPerView.find(viewId);
if(observationsIt == observationsPerView.end())
continue;

Expand All @@ -669,7 +693,7 @@ bool filterObservations2D(SfMData& sfmData, int nbNeighbors2D, float percentile,
cacheSize);
for(auto j = 0; j < observations.size(); j++)
{
const auto& obs = *observations[j];
const auto& obs = observations[j];
std::vector<size_t> indices_(nbNeighbors_);
std::vector<double> distances_(nbNeighbors_);
tree.knnSearch(obs.x.data(), nbNeighbors_, &indices_[0], &distances_[0]);
Expand All @@ -694,7 +718,7 @@ bool filterObservations2D(SfMData& sfmData, int nbNeighbors2D, float percentile,
}
estimatedRadii_[i] = radius;

std::vector<const Observation*> filteredObservations;
std::vector<Observation> filteredObservations;
std::vector<Landmark*> filteredLandmarks;
filteredObservations.reserve(observations.size());
filteredLandmarks.reserve(landmarks.size());
Expand Down Expand Up @@ -724,14 +748,14 @@ bool filterObservations2D(SfMData& sfmData, int nbNeighbors2D, float percentile,
if(estimatedRadii_[i] != -1.)
estimatedRadii[viewId] = estimatedRadii_[i];

auto& observationsIt = observationsPerView.find(viewId);
auto observationsIt = observationsPerView.find(viewId);
if(observationsIt != observationsPerView.end())
{
auto& observations = observationsIt->second.first;
auto& landmarks = observationsIt->second.second;
for(int j = 0; j < observations.size(); j++)
{
landmarks[j]->observations[viewId] = *observations[j];
landmarks[j]->observations[viewId] = observations[j];
}
}
}
Expand All @@ -754,7 +778,7 @@ int aliceVision_main(int argc, char *argv[])
double neighborsInfluence = 0.5;
int nbIterations = 5;
int nbNeighbors2D = 5;
float percentile = 0.95;
float percentile = 0.95f;

// user optional parameters
std::vector<std::string> featuresFolders;
Expand Down
28 changes: 25 additions & 3 deletions src/software/pipeline/main_prepareDenseScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,29 @@ void process(const std::string &dstColorImage, const IntrinsicBase* cam, const o
}
}

bool prepareDenseScene(SfMData& sfmData,
using ObservationsPerView = stl::flat_map<std::size_t, std::vector<const Observation*>>;

/**
* @brief Get the landmark observations of camera views.
* @param[in] sfmData: A given SfMData
* @return Observations per camera view
*/
ObservationsPerView getObservationsPerViews(const SfMData& sfmData)
{
ObservationsPerView observationsPerView;
for(auto& landIt : sfmData.getLandmarks())
{
for(const auto& obsIt : landIt.second.observations)
{
IndexT viewId = obsIt.first;
auto& observationsSet = observationsPerView[viewId];
observationsSet.push_back(&obsIt.second);
}
}
return observationsPerView;
}

bool prepareDenseScene(const SfMData& sfmData,
const std::vector<std::string>& imagesFolders,
const std::vector<std::string>& masksFolders,
const std::string& maskExtension,
Expand Down Expand Up @@ -126,7 +148,7 @@ bool prepareDenseScene(SfMData& sfmData,
ALICEVISION_LOG_INFO("Median Camera Exposure: " << medianCameraExposure << ", Median EV: " << std::log2(1.0/medianCameraExposure));

bool doMaskLandmarks = landmarksMaskScale > 0.f;
sfmData::ObservationsPerView observationsPerView;
ObservationsPerView observationsPerView;
HashMap<IndexT, double> estimatedRadii;
if (doMaskLandmarks)
{
Expand Down Expand Up @@ -301,7 +323,7 @@ bool prepareDenseScene(SfMData& sfmData,
const auto& observationsIt = observationsPerView.find(viewId);
if(observationsIt != observationsPerView.end())
{
const auto& observations = observationsIt->second.first;
const auto& observations = observationsIt->second;
int j = 0;
for(const auto& observation : observations)
{
Expand Down

0 comments on commit 21105d0

Please sign in to comment.