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

Initial ability to reconstruct from manual tracks #493

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion CMake/telesculptor-external-kwiver.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ExternalProject_Add(kwiver
BINARY_DIR ${TELESCULPTOR_EXTERNAL_DIR}/kwiver-build
STAMP_DIR ${TELESCULPTOR_STAMP_DIR}
GIT_REPOSITORY "https://github.com/Kitware/kwiver.git"
GIT_TAG 68709c321bd23cf541b9b3acbf8ef728754df5bc
GIT_TAG 0dc3f67c58df77909f463864f18068db6e645679
#GIT_SHALLOW 1
CMAKE_CACHE_ARGS
-DBUILD_SHARED_LIBS:BOOL=ON
Expand Down
7 changes: 7 additions & 0 deletions config/gui_manual_initialize.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Default configuration for the "Estimate Cameras/Landmarks" algorithm used in the GUI

default_camera_config := gui_default_camera_intrinsics.conf

block initializer
mvg:min_frame_to_frame_matches = 10
endblock
57 changes: 57 additions & 0 deletions gui/GroundControlPointsHelper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,63 @@ void GroundControlPointsHelper::setGroundControlPoints(
emit this->pointCountChanged(d->groundControlPoints.size());
}

//-----------------------------------------------------------------------------
void GroundControlPointsHelper::setGroundControlPoint(
id_t id, kwiver::vital::vector_3d const& loc)
{
QTE_D();

if (auto* const gcp = qtGet(d->groundControlPoints, id))
{
if (gcp->second.gcp)
{
if (auto* const hp = qtGet(d->gcpIdToHandleMap, id))
{
auto const handleId = d->worldWidget->findHandleWidget(hp->second);
if (handleId < 0)
{
qWarning()
<< "Failed to find the VTK ID associated with the VTK handle"
<< hp->second << " and the point with ID" << id;
return;
}

d->movePoint(handleId, d->worldWidget, loc);
if (auto* const camera = d->mainWindow->activeCamera())
{
double cameraPt[2];
camera->ProjectPoint(loc, cameraPt);
d->movePoint(
handleId, d->cameraWidget, { cameraPt[0], cameraPt[1], 0.0 });
}
else
{
d->updatePoint(handleId);
}
}
else
{
qWarning() << "Failed to find the VTK handle associated with "
"the point with ID" << id;
}

return;
}
}

auto const oldNextId = d->nextId;

auto gcp = std::make_shared<kv::ground_control_point>();
gcp->set_loc(loc);

d->addPoint(id, gcp);

d->nextId = std::max(id + 1, oldNextId);

emit this->pointAdded(id);
emit this->pointCountChanged(d->groundControlPoints.size());
}

//-----------------------------------------------------------------------------
bool GroundControlPointsHelper::isEmpty() const
{
Expand Down
1 change: 1 addition & 0 deletions gui/GroundControlPointsHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class GroundControlPointsHelper : public QObject

// Set ground control points
void setGroundControlPoints(kwiver::vital::ground_control_point_map const&);
void setGroundControlPoint(id_t, kwiver::vital::vector_3d const&);

// Get ground control points
std::vector<gcp_sptr> groundControlPoints() const;
Expand Down
76 changes: 75 additions & 1 deletion gui/MainWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,7 @@ void MainWindowPrivate::setActiveTool(AbstractTool* tool)
tool->setEnabled(enableTools);
}
this->UI.actionCancelComputation->setEnabled(enableCancel);
this->UI.actionRebuildScene->setEnabled(enableTools);
this->UI.actionOpenProject->setEnabled(enableTools);
// FIXME disable import actions
}
Expand Down Expand Up @@ -1500,7 +1501,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)

d->toolMenu = d->UI.menuCompute;
d->toolSeparator =
d->UI.menuCompute->insertSeparator(d->UI.actionCancelComputation);
d->UI.menuCompute->insertSeparator(d->UI.actionRebuildScene);
QAction * runAllSep = d->UI.menuCompute->insertSeparator(d->toolSeparator);

d->addTool(new TrackFeaturesTool(this), this);
Expand Down Expand Up @@ -1700,6 +1701,8 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)
});
connect(d->UI.cameraView, &CameraView::cameraComputationRequested,
this, &MainWindow::computeCamera);
connect(d->UI.actionRebuildScene, &QAction::triggered,
this, &MainWindow::rebuildScene);

// Ruler widget
d->rulerHelper = new RulerHelper(this);
Expand Down Expand Up @@ -3576,6 +3579,77 @@ void MainWindow::computeCamera()
}
}

//-----------------------------------------------------------------------------
void MainWindow::rebuildScene()
{
QTE_D();

if (!d->activeTool)
{
InitCamerasLandmarksTool tool{this};
QEventLoop eventLoop;

QObject::connect(&tool, &AbstractTool::completed,
&eventLoop, &QEventLoop::quit);
QObject::connect(&tool, &AbstractTool::failed,
&eventLoop, &QEventLoop::quit);
QObject::connect(&tool, &AbstractTool::failed,
this, &MainWindow::reportToolError);

auto const constraints =
std::make_shared<kv::sfm_constraints>(*d->sfmConstraints);
constraints->set_metadata(nullptr);

auto features = d->groundControlPointsHelper->registrationTracks();
auto landmarks = d->groundControlPointsHelper->registrationLandmarks();

tool.setTracks(features);
tool.setLandmarks(landmarks);
tool.setSfmConstraints(constraints);
tool.setVideoPath(stdString(d->videoPath));
tool.setMaskPath(stdString(d->maskPath));

auto config = readConfig("gui_manual_initialize.conf");
config->merge_config(d->project->config);

tool.setConfig(config);

if (tool.execute())
{
d->setActiveTool(&tool);
d->updateProgress(&tool, tool.description(), 0);

eventLoop.exec();

if (auto const& data = tool.data())
{
if (data->cameras && data->cameras->size())
{
d->updateCameras(data->cameras);
}
if (data->landmarks && data->landmarks->size())
{
auto lm = data->landmarks->landmarks();
for (auto const& li : lm)
{
if (li.second)
{
using gcp_id_t = kwiver::vital::ground_control_point_id_t;

auto const i = li.first;
d->groundControlPointsHelper->setGroundControlPoint(
static_cast<gcp_id_t>(i), li.second->loc());
}
}
}
}

d->setActiveTool(nullptr);
d->updateProgress(&tool, tool.description(), 100);
}
}
}

//-----------------------------------------------------------------------------
void MainWindow::updateToolProgress(QString const& desc, int progress)
{
Expand Down
1 change: 1 addition & 0 deletions gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public slots:

void applySimilarityTransform();
void computeCamera();
void rebuildScene();

void saveWebGLScene();

Expand Down
10 changes: 10 additions & 0 deletions gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
<addaction name="actionVariableLens"/>
<addaction name="actionFixGeoOrigin"/>
</widget>
<addaction name="actionRebuildScene"/>
<addaction name="separator"/>
<addaction name="actionCancelComputation"/>
<addaction name="separator"/>
<addaction name="menuAdvanced"/>
Expand Down Expand Up @@ -670,6 +672,14 @@
<string>.</string>
</property>
</action>
<action name="actionRebuildScene">
<property name="text">
<string>Reb&amp;uild Scene</string>
</property>
<property name="toolTip">
<string>Reconstruct cameras and ground control points from camera registration points</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down