Skip to content

Commit 95dbe2c

Browse files
committed
[filterSfM] fix reference issue and refactor code
1 parent 47048d8 commit 95dbe2c

File tree

4 files changed

+58
-38
lines changed

4 files changed

+58
-38
lines changed

src/aliceVision/sfmData/SfMData.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,5 @@ LandmarksPerView getLandmarksPerViews(const SfMData& sfmData)
378378
return landmarksPerView;
379379
}
380380

381-
ObservationsPerView getObservationsPerViews(SfMData& sfmData)
382-
{
383-
ObservationsPerView observationsPerView;
384-
for(auto& landIt : sfmData.getLandmarks())
385-
{
386-
for(const auto& obsIt : landIt.second.observations)
387-
{
388-
IndexT viewId = obsIt.first;
389-
auto& landmarksSet = observationsPerView[viewId];
390-
landmarksSet.first.push_back(&obsIt.second);
391-
landmarksSet.second.push_back(&landIt.second);
392-
}
393-
}
394-
return observationsPerView;
395-
}
396-
397381
} // namespace sfmData
398382
} // namespace aliceVision

src/aliceVision/sfmData/SfMData.hpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -599,15 +599,5 @@ using LandmarksPerView = stl::flat_map<std::size_t, LandmarkIdSet>;
599599

600600
LandmarksPerView getLandmarksPerViews(const SfMData& sfmData);
601601

602-
using ObservationsPerView = stl::flat_map<std::size_t, std::pair<std::vector<const Observation*>, std::vector<Landmark*>>>;
603-
604-
/**
605-
* @brief Get the landmark observations of camera views
606-
* with the corresponding landmarks information.
607-
* @param[in] sfmData: A given SfMData
608-
* @return Observation information per camera view
609-
*/
610-
ObservationsPerView getObservationsPerViews(SfMData& sfmData);
611-
612602
} // namespace sfmData
613603
} // namespace aliceVision

src/software/pipeline/main_filterSfM.cpp

Lines changed: 33 additions & 9 deletions
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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,29 @@ void process(const std::string& dstColorImage,
8383
}
8484
}
8585

86-
bool prepareDenseScene(SfMData& sfmData,
86+
using ObservationsPerView = stl::flat_map<std::size_t, std::vector<const Observation*>>;
87+
88+
/**
89+
* @brief Get the landmark observations of camera views.
90+
* @param[in] sfmData: A given SfMData
91+
* @return Observations per camera view
92+
*/
93+
ObservationsPerView getObservationsPerViews(const SfMData& sfmData)
94+
{
95+
ObservationsPerView observationsPerView;
96+
for(auto& landIt : sfmData.getLandmarks())
97+
{
98+
for(const auto& obsIt : landIt.second.observations)
99+
{
100+
IndexT viewId = obsIt.first;
101+
auto& observationsSet = observationsPerView[viewId];
102+
observationsSet.push_back(&obsIt.second);
103+
}
104+
}
105+
return observationsPerView;
106+
}
107+
108+
bool prepareDenseScene(const SfMData& sfmData,
87109
const std::vector<std::string>& imagesFolders,
88110
const std::vector<std::string>& masksFolders,
89111
const std::string& maskExtension,
@@ -132,7 +154,7 @@ bool prepareDenseScene(SfMData& sfmData,
132154
ALICEVISION_LOG_INFO("Median Camera Exposure: " << medianCameraExposure << ", Median EV: " << std::log2(1.0 / medianCameraExposure));
133155

134156
bool doMaskLandmarks = landmarksMaskScale > 0.f;
135-
sfmData::ObservationsPerView observationsPerView;
157+
ObservationsPerView observationsPerView;
136158
HashMap<IndexT, double> estimatedRadii;
137159
if (doMaskLandmarks)
138160
{
@@ -307,7 +329,7 @@ bool prepareDenseScene(SfMData& sfmData,
307329
const auto& observationsIt = observationsPerView.find(viewId);
308330
if(observationsIt != observationsPerView.end())
309331
{
310-
const auto& observations = observationsIt->second.first;
332+
const auto& observations = observationsIt->second;
311333
int j = 0;
312334
for(const auto& observation : observations)
313335
{

0 commit comments

Comments
 (0)