Skip to content

Commit c842742

Browse files
author
Fabien Servant
committed
add new rollback inside expansion
1 parent 6a93873 commit c842742

File tree

9 files changed

+85
-8
lines changed

9 files changed

+85
-8
lines changed

src/aliceVision/sfm/pipeline/bootstrapping/Bootstrap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,11 @@ bool bootstrapMesh(sfmData::SfMData & sfmData,
104104
std::mt19937 randomNumberGenerator;
105105
Eigen::Matrix4d pose;
106106
double threshold;
107+
size_t countInliers;
107108

108109
//Compute resection for selected view
109110
SfmResection resection(50000, std::numeric_limits<double>::infinity());
110-
if (!resection.processView(sfmData, tracksMap, tracksPerView, randomNumberGenerator, viewId, pose, threshold))
111+
if (!resection.processView(sfmData, tracksMap, tracksPerView, randomNumberGenerator, viewId, pose, threshold, countInliers))
111112
{
112113
return false;
113114
}

src/aliceVision/sfm/pipeline/expanding/ExpansionChunk.cpp

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace sfm {
1515

1616
bool ExpansionChunk::process(sfmData::SfMData & sfmData, const track::TracksHandler & tracksHandler, const std::set<IndexT> & viewsChunk)
1717
{
18+
_ignoredViews.clear();
1819
ALICEVISION_LOG_INFO("ExpansionChunk::process start");
1920
ALICEVISION_LOG_INFO("Chunk size : " << viewsChunk.size());
2021

@@ -31,6 +32,17 @@ bool ExpansionChunk::process(sfmData::SfMData & sfmData, const track::TracksHand
3132
return false;
3233
}
3334

35+
36+
struct IntermediateResectionInfo
37+
{
38+
IndexT viewId;
39+
Eigen::Matrix4d pose;
40+
size_t inliersCount;
41+
double threshold;
42+
};
43+
44+
std::vector<IntermediateResectionInfo> intermediateInfos;
45+
3446
ALICEVISION_LOG_INFO("Resection start");
3547
#pragma omp parallel for
3648
for (int i = 0; i < viewsChunk.size(); i++)
@@ -41,25 +53,52 @@ bool ExpansionChunk::process(sfmData::SfMData & sfmData, const track::TracksHand
4153

4254
if (!sfmData.isPoseAndIntrinsicDefined(viewId))
4355
{
56+
IntermediateResectionInfo iri;
57+
iri.viewId = viewId;
58+
4459
SfmResection resection(_resectionIterations, _resectionMaxError);
4560

46-
Eigen::Matrix4d pose;
47-
double threshold = 0.0;
4861
std::mt19937 randomNumberGenerator;
4962
if (!resection.processView(sfmData,
5063
tracksHandler.getAllTracks(), tracksHandler.getTracksPerView(),
5164
randomNumberGenerator, viewId,
52-
pose, threshold))
65+
iri.pose, iri.threshold, iri.inliersCount))
5366
{
5467
continue;
5568
}
5669

5770
#pragma omp critical
5871
{
59-
60-
addPose(sfmData, viewId, pose);
72+
intermediateInfos.push_back(iri);
73+
}
74+
}
75+
}
76+
77+
//Check that at least one view has rich info
78+
const int poorInliersCount = 100;
79+
int richViews = 0;
80+
for (const auto & item : intermediateInfos)
81+
{
82+
if (item.inliersCount > poorInliersCount)
83+
{
84+
richViews++;
85+
}
86+
}
87+
88+
89+
//Add pose only if it match conditions
90+
for (const auto & item : intermediateInfos)
91+
{
92+
if (richViews > 0)
93+
{
94+
if (item.inliersCount < poorInliersCount)
95+
{
96+
_ignoredViews.insert(item.viewId);
97+
continue;
6198
}
6299
}
100+
101+
addPose(sfmData, item.viewId, item.pose);
63102
}
64103

65104
// Get a list of valid views

src/aliceVision/sfm/pipeline/expanding/ExpansionChunk.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ class ExpansionChunk
9898
_minTriangulationAngleDegrees = angle;
9999
}
100100

101+
const std::set<IndexT> & getIgnoredViews()
102+
{
103+
return _ignoredViews;
104+
}
105+
101106
private:
102107

103108
/**
@@ -128,6 +133,7 @@ class ExpansionChunk
128133
SfmBundle::uptr _bundleHandler;
129134
ExpansionHistory::sptr _historyHandler;
130135
PointFetcher::uptr _pointFetcherHandler;
136+
std::set<IndexT> _ignoredViews;
131137

132138
private:
133139
size_t _resectionIterations = 1024;

src/aliceVision/sfm/pipeline/expanding/ExpansionIteration.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ bool ExpansionIteration::process(sfmData::SfMData & sfmData, track::TracksHandle
4747
continue;
4848
}
4949

50+
//Rollback any views which were ignored (not with errors)
51+
_policy->rollback(_chunkHandler->getIgnoredViews());
52+
53+
//Save this epoch to history
5054
_historyHandler->endEpoch(sfmData, _policy->getNextViews());
5155
}
5256

src/aliceVision/sfm/pipeline/expanding/ExpansionPolicy.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class ExpansionPolicy
3333
* @return true if the policy succeeded
3434
*/
3535
virtual bool process(const sfmData::SfMData & sfmData, const track::TracksHandler & tracksHandler) = 0;
36+
37+
/**
38+
* @brief rollback some processed views inside the available views
39+
* @param viewsSet the set of views that we want to be able to select again.
40+
*/
41+
virtual void rollback(const std::set<IndexT> & viewsSet) = 0;
3642

3743
/**
3844
* @brief Retrieve the selected next views

src/aliceVision/sfm/pipeline/expanding/ExpansionPolicyLegacy.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,14 @@ double ExpansionPolicyLegacy::computeScore(const track::TracksMap & tracksMap,
200200
return sum;
201201
}
202202

203+
void ExpansionPolicyLegacy::rollback(const std::set<IndexT> & viewsSet)
204+
{
205+
for (const auto & item : viewsSet)
206+
{
207+
ALICEVISION_LOG_INFO("rollback view : " << item);
208+
_availableViewsIds.insert(item);
209+
}
210+
}
211+
203212
}
204213
}

src/aliceVision/sfm/pipeline/expanding/ExpansionPolicyLegacy.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ class ExpansionPolicyLegacy : public ExpansionPolicy
7373
_maxViewsPerGroup = count;
7474
}
7575

76+
/**
77+
* @brief rollback some processed views inside the available views
78+
* @param viewsSet the set of views that we want to be able to select again.
79+
*/
80+
virtual void rollback(const std::set<IndexT> & viewsSet);
81+
7682
private:
7783

7884
// vector of selected views for this iteration

src/aliceVision/sfm/pipeline/expanding/SfmResection.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ bool SfmResection::processView(
2626
std::mt19937 &randomNumberGenerator,
2727
const IndexT viewId,
2828
Eigen::Matrix4d & updatedPose,
29-
double & updatedThreshold
29+
double & updatedThreshold,
30+
size_t & inliersCount
3031
)
3132
{
3233
ALICEVISION_LOG_INFO("SfmResection::processView start " << viewId);
@@ -90,6 +91,9 @@ bool SfmResection::processView(
9091
return false;
9192
}
9293

94+
inliersCount = inliers.size();
95+
ALICEVISION_LOG_INFO("Resection for view " << viewId << " had " << inliersCount << " inliers.");
96+
9397
//Refine the pose
9498
if (!internalRefinement(structure, observations, inliers, pose, intrinsic, errorMax))
9599
{

src/aliceVision/sfm/pipeline/expanding/SfmResection.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class SfmResection
3232
* @param viewId the view id to process
3333
* @param updatedPose output estimated pose
3434
* @param updatedThreshold estimated threshold
35+
* @param inliersCount number of inliers for this resection
3536
* @return false if a critical error occured
3637
*/
3738
bool processView(
@@ -41,7 +42,8 @@ class SfmResection
4142
std::mt19937 &randomNumberGenerator,
4243
const IndexT viewId,
4344
Eigen::Matrix4d & updatedPose,
44-
double & updatedThreshold
45+
double & updatedThreshold,
46+
size_t & inliersCount
4547
);
4648

4749
private:

0 commit comments

Comments
 (0)