Skip to content

Commit

Permalink
add new rollback inside expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
servantftechnicolor committed Jan 17, 2025
1 parent f0f9885 commit 6f30499
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/aliceVision/sfm/pipeline/bootstrapping/Bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,11 @@ bool bootstrapMesh(sfmData::SfMData & sfmData,
std::mt19937 randomNumberGenerator;
Eigen::Matrix4d pose;
double threshold;
size_t countInliers;

//Compute resection for selected view
SfmResection resection(50000, std::numeric_limits<double>::infinity());
if (!resection.processView(sfmData, tracksMap, tracksPerView, randomNumberGenerator, viewId, pose, threshold))
if (!resection.processView(sfmData, tracksMap, tracksPerView, randomNumberGenerator, viewId, pose, threshold, countInliers))
{
return false;
}
Expand Down
49 changes: 44 additions & 5 deletions src/aliceVision/sfm/pipeline/expanding/ExpansionChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace sfm {

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

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


struct IntermediateResectionInfo
{
IndexT viewId;
Eigen::Matrix4d pose;
size_t inliersCount;
double threshold;
};

std::vector<IntermediateResectionInfo> intermediateInfos;

ALICEVISION_LOG_INFO("Resection start");
#pragma omp parallel for
for (int i = 0; i < viewsChunk.size(); i++)
Expand All @@ -41,25 +53,52 @@ bool ExpansionChunk::process(sfmData::SfMData & sfmData, const track::TracksHand

if (!sfmData.isPoseAndIntrinsicDefined(viewId))
{
IntermediateResectionInfo iri;
iri.viewId = viewId;

SfmResection resection(_resectionIterations, _resectionMaxError);

Eigen::Matrix4d pose;
double threshold = 0.0;
std::mt19937 randomNumberGenerator;
if (!resection.processView(sfmData,
tracksHandler.getAllTracks(), tracksHandler.getTracksPerView(),
randomNumberGenerator, viewId,
pose, threshold))
iri.pose, iri.threshold, iri.inliersCount))
{
continue;
}

#pragma omp critical
{

addPose(sfmData, viewId, pose);
intermediateInfos.push_back(iri);
}
}
}

//Check that at least one view has rich info
const int poorInliersCount = 100;
int richViews = 0;
for (const auto & item : intermediateInfos)
{
if (item.inliersCount > poorInliersCount)
{
richViews++;
}
}


//Add pose only if it match conditions
for (const auto & item : intermediateInfos)
{
if (richViews > 0)
{
if (item.inliersCount < poorInliersCount)
{
_ignoredViews.insert(item.viewId);
continue;
}
}

addPose(sfmData, item.viewId, item.pose);
}

// Get a list of valid views
Expand Down
6 changes: 6 additions & 0 deletions src/aliceVision/sfm/pipeline/expanding/ExpansionChunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class ExpansionChunk
_minTriangulationAngleDegrees = angle;
}

const std::set<IndexT> & getIgnoredViews()
{
return _ignoredViews;
}

private:

/**
Expand Down Expand Up @@ -128,6 +133,7 @@ class ExpansionChunk
SfmBundle::uptr _bundleHandler;
ExpansionHistory::sptr _historyHandler;
PointFetcher::uptr _pointFetcherHandler;
std::set<IndexT> _ignoredViews;

private:
size_t _resectionIterations = 1024;
Expand Down
4 changes: 4 additions & 0 deletions src/aliceVision/sfm/pipeline/expanding/ExpansionIteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ bool ExpansionIteration::process(sfmData::SfMData & sfmData, track::TracksHandle
continue;
}

//Rollback any views which were ignored (not with errors)
_policy->rollback(_chunkHandler->getIgnoredViews());

//Save this epoch to history
_historyHandler->endEpoch(sfmData, _policy->getNextViews());
}

Expand Down
6 changes: 6 additions & 0 deletions src/aliceVision/sfm/pipeline/expanding/ExpansionPolicy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class ExpansionPolicy
* @return true if the policy succeeded
*/
virtual bool process(const sfmData::SfMData & sfmData, const track::TracksHandler & tracksHandler) = 0;

/**
* @brief rollback some processed views inside the available views
* @param viewsSet the set of views that we want to be able to select again.
*/
virtual void rollback(const std::set<IndexT> & viewsSet) = 0;

/**
* @brief Retrieve the selected next views
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,14 @@ double ExpansionPolicyLegacy::computeScore(const track::TracksMap & tracksMap,
return sum;
}

void ExpansionPolicyLegacy::rollback(const std::set<IndexT> & viewsSet)
{
for (const auto & item : viewsSet)
{
ALICEVISION_LOG_INFO("rollback view : " << item);
_availableViewsIds.insert(item);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class ExpansionPolicyLegacy : public ExpansionPolicy
_maxViewsPerGroup = count;
}

/**
* @brief rollback some processed views inside the available views
* @param viewsSet the set of views that we want to be able to select again.
*/
virtual void rollback(const std::set<IndexT> & viewsSet);

private:

// vector of selected views for this iteration
Expand Down
6 changes: 5 additions & 1 deletion src/aliceVision/sfm/pipeline/expanding/SfmResection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ bool SfmResection::processView(
std::mt19937 &randomNumberGenerator,
const IndexT viewId,
Eigen::Matrix4d & updatedPose,
double & updatedThreshold
double & updatedThreshold,
size_t & inliersCount
)
{
ALICEVISION_LOG_INFO("SfmResection::processView start " << viewId);
Expand Down Expand Up @@ -91,6 +92,9 @@ bool SfmResection::processView(
return false;
}

inliersCount = inliers.size();
ALICEVISION_LOG_INFO("Resection for view " << viewId << " had " << inliersCount << " inliers.");

//Refine the pose
if (!internalRefinement(structure, observations, inliers, pose, intrinsic, errorMax))
{
Expand Down
4 changes: 3 additions & 1 deletion src/aliceVision/sfm/pipeline/expanding/SfmResection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class SfmResection
* @param viewId the view id to process
* @param updatedPose output estimated pose
* @param updatedThreshold estimated threshold
* @param inliersCount number of inliers for this resection
* @return false if a critical error occured
*/
bool processView(
Expand All @@ -42,7 +43,8 @@ class SfmResection
std::mt19937 &randomNumberGenerator,
const IndexT viewId,
Eigen::Matrix4d & updatedPose,
double & updatedThreshold
double & updatedThreshold,
size_t & inliersCount
);

private:
Expand Down

0 comments on commit 6f30499

Please sign in to comment.