Skip to content

Commit 21105d0

Browse files
committed
[WIP][filterSfM] fix reference issue and refactor code
1 parent b16da19 commit 21105d0

File tree

4 files changed

+58
-38
lines changed

4 files changed

+58
-38
lines changed

src/aliceVision/sfmData/SfMData.cpp

-16
Original file line numberDiff line numberDiff line change
@@ -331,21 +331,5 @@ LandmarksPerView getLandmarksPerViews(const SfMData& sfmData)
331331
return landmarksPerView;
332332
}
333333

334-
ObservationsPerView getObservationsPerViews(SfMData& sfmData)
335-
{
336-
ObservationsPerView observationsPerView;
337-
for(auto& landIt : sfmData.getLandmarks())
338-
{
339-
for(const auto& obsIt : landIt.second.observations)
340-
{
341-
IndexT viewId = obsIt.first;
342-
auto& landmarksSet = observationsPerView[viewId];
343-
landmarksSet.first.push_back(&obsIt.second);
344-
landmarksSet.second.push_back(&landIt.second);
345-
}
346-
}
347-
return observationsPerView;
348-
}
349-
350334
} // namespace sfmData
351335
} // namespace aliceVision

src/aliceVision/sfmData/SfMData.hpp

-10
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,5 @@ using LandmarksPerView = stl::flat_map<std::size_t, LandmarkIdSet>;
577577

578578
LandmarksPerView getLandmarksPerViews(const SfMData& sfmData);
579579

580-
using ObservationsPerView = stl::flat_map<std::size_t, std::pair<std::vector<const Observation*>, std::vector<Landmark*>>>;
581-
582-
/**
583-
* @brief Get the landmark observations of camera views
584-
* with the corresponding landmarks information.
585-
* @param[in] sfmData: A given SfMData
586-
* @return Observation information per camera view
587-
*/
588-
ObservationsPerView getObservationsPerViews(SfMData& sfmData);
589-
590580
} // namespace sfmData
591581
} // namespace aliceVision

src/software/pipeline/main_filterSfM.cpp

+33-9
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ struct ObservationsAdaptator
5858
/// CRTP helper method
5959
inline Derived& derived() { return *static_cast<Derived*>(this); }
6060

61-
const std::vector<const Observation*> _data;
62-
ObservationsAdaptator(const std::vector<const Observation*>& data)
61+
const std::vector<Observation> _data;
62+
ObservationsAdaptator(const std::vector<Observation>& data)
6363
: _data(data)
6464
{
6565
}
@@ -68,7 +68,7 @@ struct ObservationsAdaptator
6868
inline size_t kdtree_get_point_count() const { return _data.size(); }
6969

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

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

194+
using ObservationsPerView = stl::flat_map<std::size_t, std::pair<std::vector<Observation>, std::vector<Landmark*>>>;
195+
196+
/**
197+
* @brief Get the landmark observations of camera views
198+
* with the corresponding landmarks information.
199+
* @param[in] sfmData: A given SfMData
200+
* @return Observation information per camera view
201+
*/
202+
ObservationsPerView getObservationsPerViews(SfMData& sfmData)
203+
{
204+
ObservationsPerView observationsPerView;
205+
for(auto& landIt : sfmData.getLandmarks())
206+
{
207+
for(const auto& obsIt : landIt.second.observations)
208+
{
209+
IndexT viewId = obsIt.first;
210+
auto& landmarksSet = observationsPerView[viewId];
211+
landmarksSet.first.push_back(obsIt.second);
212+
landmarksSet.second.push_back(&landIt.second);
213+
}
214+
}
215+
return observationsPerView;
216+
}
217+
194218
bool filterLandmarks(SfMData& sfmData, double radiusScale, bool useFeatureScale, int minNbObservationsPerLandmark)
195219
{
196220
const auto initialNbLandmarks = sfmData.getLandmarks().size();
@@ -648,7 +672,7 @@ bool filterObservations2D(SfMData& sfmData, int nbNeighbors2D, float percentile,
648672
std::advance(itView, i);
649673
const IndexT viewId = *itView;
650674

651-
auto& observationsIt = observationsPerView.find(viewId);
675+
auto observationsIt = observationsPerView.find(viewId);
652676
if(observationsIt == observationsPerView.end())
653677
continue;
654678

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

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

727-
auto& observationsIt = observationsPerView.find(viewId);
751+
auto observationsIt = observationsPerView.find(viewId);
728752
if(observationsIt != observationsPerView.end())
729753
{
730754
auto& observations = observationsIt->second.first;
731755
auto& landmarks = observationsIt->second.second;
732756
for(int j = 0; j < observations.size(); j++)
733757
{
734-
landmarks[j]->observations[viewId] = *observations[j];
758+
landmarks[j]->observations[viewId] = observations[j];
735759
}
736760
}
737761
}
@@ -754,7 +778,7 @@ int aliceVision_main(int argc, char *argv[])
754778
double neighborsInfluence = 0.5;
755779
int nbIterations = 5;
756780
int nbNeighbors2D = 5;
757-
float percentile = 0.95;
781+
float percentile = 0.95f;
758782

759783
// user optional parameters
760784
std::vector<std::string> featuresFolders;

src/software/pipeline/main_prepareDenseScene.cpp

+25-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,29 @@ void process(const std::string &dstColorImage, const IntrinsicBase* cam, const o
7676
}
7777
}
7878

79-
bool prepareDenseScene(SfMData& sfmData,
79+
using ObservationsPerView = stl::flat_map<std::size_t, std::vector<const Observation*>>;
80+
81+
/**
82+
* @brief Get the landmark observations of camera views.
83+
* @param[in] sfmData: A given SfMData
84+
* @return Observations per camera view
85+
*/
86+
ObservationsPerView getObservationsPerViews(const SfMData& sfmData)
87+
{
88+
ObservationsPerView observationsPerView;
89+
for(auto& landIt : sfmData.getLandmarks())
90+
{
91+
for(const auto& obsIt : landIt.second.observations)
92+
{
93+
IndexT viewId = obsIt.first;
94+
auto& observationsSet = observationsPerView[viewId];
95+
observationsSet.push_back(&obsIt.second);
96+
}
97+
}
98+
return observationsPerView;
99+
}
100+
101+
bool prepareDenseScene(const SfMData& sfmData,
80102
const std::vector<std::string>& imagesFolders,
81103
const std::vector<std::string>& masksFolders,
82104
const std::string& maskExtension,
@@ -126,7 +148,7 @@ bool prepareDenseScene(SfMData& sfmData,
126148
ALICEVISION_LOG_INFO("Median Camera Exposure: " << medianCameraExposure << ", Median EV: " << std::log2(1.0/medianCameraExposure));
127149

128150
bool doMaskLandmarks = landmarksMaskScale > 0.f;
129-
sfmData::ObservationsPerView observationsPerView;
151+
ObservationsPerView observationsPerView;
130152
HashMap<IndexT, double> estimatedRadii;
131153
if (doMaskLandmarks)
132154
{
@@ -301,7 +323,7 @@ bool prepareDenseScene(SfMData& sfmData,
301323
const auto& observationsIt = observationsPerView.find(viewId);
302324
if(observationsIt != observationsPerView.end())
303325
{
304-
const auto& observations = observationsIt->second.first;
326+
const auto& observations = observationsIt->second;
305327
int j = 0;
306328
for(const auto& observation : observations)
307329
{

0 commit comments

Comments
 (0)