Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LocalBA intrinsics edges management #624

Merged
merged 7 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 50 additions & 6 deletions src/aliceVision/sfm/LocalBundleAdjustmentGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <lemon/bfs.h>

#include <fstream>
#include <algorithm>

namespace fs = boost::filesystem;

Expand Down Expand Up @@ -132,23 +133,66 @@ void LocalBundleAdjustmentGraph::exportIntrinsicsHistory(const std::string& fold
os.close();
}

bool LocalBundleAdjustmentGraph::removeViewsToTheGraph(const std::set<IndexT>& removedViewsId)
bool LocalBundleAdjustmentGraph::removeViews(const sfmData::SfMData& sfmData, const std::set<IndexT>& removedViewsId)
{
std::size_t numRemovedNode = 0;
std::map<IndexT, std::vector<int>> removedEdgesByIntrinsic;

for(const IndexT& viewId : removedViewsId)
{
auto it = _nodePerViewId.find(viewId);
fabiencastan marked this conversation as resolved.
Show resolved Hide resolved
if(it != _nodePerViewId.end())
if(it == _nodePerViewId.end())
{
ALICEVISION_LOG_WARNING("The view id: " << viewId << " does not exist in the graph, cannot remove it.");
continue;
}

// keep track of node incident edges that are going to be removed
// in order to update _intrinsicEdgesId accordingly
{
IndexT intrinsicId = sfmData.getView(viewId).getIntrinsicId();
fabiencastan marked this conversation as resolved.
Show resolved Hide resolved
auto intrinsicIt = _intrinsicEdgesId.find(intrinsicId);
fabiencastan marked this conversation as resolved.
Show resolved Hide resolved
if(intrinsicIt != _intrinsicEdgesId.end())
{
// store incident edge ids before removal
for(lemon::ListGraph::IncEdgeIt e(_graph, it->second); e != lemon::INVALID; ++e)
{
removedEdgesByIntrinsic[intrinsicId].push_back(_graph.id(lemon::ListGraph::Edge(e)));
}
}
}

_graph.erase(it->second); // this function erase a node with its incident arcs
_viewIdPerNode.erase(it->second);
_nodePerViewId.erase(it->first);
yann-lty marked this conversation as resolved.
Show resolved Hide resolved

numRemovedNode++;
ALICEVISION_LOG_DEBUG("The view #" << viewId << " has been successfully removed to the distance graph.");
numRemovedNode++;
yann-lty marked this conversation as resolved.
Show resolved Hide resolved
ALICEVISION_LOG_DEBUG("The view #" << viewId << " has been successfully removed to the distance graph.");
}

// remove erased edges from _intrinsicsEdgesId
for(auto& edgesIt : removedEdgesByIntrinsic)
{
const IndexT intrinsicId = edgesIt.first;
std::vector<int>& edgeIds = _intrinsicEdgesId[intrinsicId];
std::vector<int>& removedEdges = edgesIt.second;

std::vector<int> newEdgeIds;
// sort before using set_difference
std::sort(edgeIds.begin(), edgeIds.end());
std::sort(removedEdges.begin(), removedEdges.end());

std::set_difference(
edgeIds.begin(), edgeIds.end(),
removedEdges.begin(), removedEdges.end(),
std::back_inserter(newEdgeIds)
);
std::swap(edgeIds, newEdgeIds);

if(edgeIds.empty())
{
_intrinsicEdgesId.erase(intrinsicId);
}
else
ALICEVISION_LOG_WARNING("The view id: " << viewId << " does not exist in the graph, cannot remove it.");
}
return numRemovedNode == removedViewsId.size();
}
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/sfm/LocalBundleAdjustmentGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class LocalBundleAdjustmentGraph
* @param[in] removedViewsId Set of views index to remove
* @return true if the number of removed node is equal to the size of \c removedViewsId
*/
bool removeViewsToTheGraph(const std::set<IndexT>& removedViewsId);
bool removeViews(const sfmData::SfMData& sfmData, const std::set<IndexT>& removedViewsId);
yann-lty marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Complete the graph with the newly resected views or all the posed views if the graph is empty.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,9 @@ bool ReconstructionEngine_sequentialSfM::bundleAdjustment(std::set<IndexT>& newR

if(_params.useLocalBundleAdjustment && !removedViewsIdIteration.empty())
{
// remove removed views to the graph
_localStrategyGraph->removeViewsToTheGraph(removedViewsIdIteration);
ALICEVISION_LOG_DEBUG("Removed views to the local strategy graph: " << removedViewsIdIteration);
// remove views from localBA graph
_localStrategyGraph->removeViews(_sfmData, removedViewsIdIteration);
ALICEVISION_LOG_DEBUG("Removed views from local strategy graph: " << removedViewsIdIteration);
yann-lty marked this conversation as resolved.
Show resolved Hide resolved
}

ALICEVISION_LOG_INFO("Bundle adjustment iteration: " << iteration << " took " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - chronoItStart).count() << " msec.");
Expand Down