From d4e0165a1e07f4f365da66af4c09d988e27f216b Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Sat, 29 Jun 2019 13:02:35 +0300
Subject: [PATCH] Allow snapshot camera adjustments

---
 applications/gui/src/screen.cpp               | 65 +++++++++++++++----
 applications/reconstruct/src/voxel_scene.cpp  | 12 ++--
 .../rgbd-sources/src/snapshot_source.cpp      | 19 ++++++
 3 files changed, 77 insertions(+), 19 deletions(-)

diff --git a/applications/gui/src/screen.cpp b/applications/gui/src/screen.cpp
index 63965a3fc..00d46ee58 100644
--- a/applications/gui/src/screen.cpp
+++ b/applications/gui/src/screen.cpp
@@ -9,6 +9,7 @@
 #include <nanogui/combobox.h>
 #include <nanogui/label.h>
 #include <nanogui/toolbutton.h>
+#include <nanogui/popupbutton.h>
 
 #include <opencv2/opencv.hpp>
 
@@ -121,6 +122,7 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl
 	button->setFixedSize(Vector2i(40,40));
 	button->setCallback([this]() {
 		//swindow_->setVisible(true);
+		setActiveCamera(nullptr);
 	});
 
 	/*button = new ToolButton(innertool, ENTYPO_ICON_PLUS);
@@ -132,22 +134,54 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl
 		//swindow_->setVisible(true);
 	});*/
 
-	button = new ToolButton(innertool, ENTYPO_ICON_PLUS);
-	button->setIconExtraScale(1.5f);
-	button->setTheme(toolbuttheme);
-	button->setTooltip("Camera Sources");
-	button->setFixedSize(Vector2i(40,40));
-	button->setCallback([this]() {
+	auto popbutton = new PopupButton(innertool, "", ENTYPO_ICON_PLUS);
+	popbutton->setIconExtraScale(1.5f);
+	popbutton->setTheme(toolbuttheme);
+	popbutton->setTooltip("Add");
+	popbutton->setFixedSize(Vector2i(40,40));
+	popbutton->setSide(Popup::Side::Right);
+	popbutton->setChevronIcon(0);
+	Popup *popup = popbutton->popup();
+    popup->setLayout(new GroupLayout());
+	popup->setTheme(toolbuttheme);
+    //popup->setAnchorHeight(100);
+
+	auto itembutton = new Button(popup, "Add Camera", ENTYPO_ICON_CAMERA);
+	itembutton->setCallback([this,popup]() {
 		swindow_->setVisible(true);
+		popup->setVisible(false);
 	});
 
-	button = new ToolButton(innertool, ENTYPO_ICON_TOOLS);
-	button->setIconExtraScale(1.5f);
-	button->setTheme(toolbuttheme);
-	button->setTooltip("Connections");
-	button->setFixedSize(Vector2i(40,40));
-	button->setCallback([this]() {
+	itembutton = new Button(popup, "Add Node", ENTYPO_ICON_LAPTOP);
+	itembutton->setCallback([this,popup]() {
+		cwindow_->setVisible(true);
+		popup->setVisible(false);
+	});
+
+	popbutton = new PopupButton(innertool, "", ENTYPO_ICON_TOOLS);
+	popbutton->setIconExtraScale(1.5f);
+	popbutton->setTheme(toolbuttheme);
+	popbutton->setTooltip("Tools");
+	popbutton->setFixedSize(Vector2i(40,40));
+	popbutton->setSide(Popup::Side::Right);
+	popbutton->setChevronIcon(0);
+	popup = popbutton->popup();
+    popup->setLayout(new GroupLayout());
+	popup->setTheme(toolbuttheme);
+	//popbutton->setCallback([this]() {
+	//	cwindow_->setVisible(true);
+	//});
+
+	itembutton = new Button(popup, "Connections");
+	itembutton->setCallback([this,popup]() {
 		cwindow_->setVisible(true);
+		popup->setVisible(false);
+	});
+
+	itembutton = new Button(popup, "Manual Registration");
+	itembutton->setCallback([this,popup]() {
+		// Show pose win...
+		popup->setVisible(false);
 	});
 
 	button = new ToolButton(toolbar, ENTYPO_ICON_COG);
@@ -164,9 +198,10 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl
 	mwindow_->setVisible(false);
 
 	cwindow_->setPosition(Eigen::Vector2i(80, 20));
-	swindow_->setPosition(Eigen::Vector2i(80, 400));
+	//swindow_->setPosition(Eigen::Vector2i(80, 400));
 	cwindow_->setVisible(false);
-	swindow_->setVisible(false);
+	swindow_->setVisible(true);
+	swindow_->center();
 	cwindow_->setTheme(windowtheme);
 	swindow_->setTheme(windowtheme);
 
@@ -201,8 +236,10 @@ void ftl::gui::Screen::setActiveCamera(ftl::gui::Camera *cam) {
 	if (cam) {
 		status_ = cam->source()->getURI();
 		mwindow_->setVisible(true);
+		swindow_->setVisible(false);
 	} else {
 		mwindow_->setVisible(false);
+		swindow_->setVisible(true);
 		status_ = "No camera...";
 	}
 }
diff --git a/applications/reconstruct/src/voxel_scene.cpp b/applications/reconstruct/src/voxel_scene.cpp
index ccdee9e7d..216325ded 100644
--- a/applications/reconstruct/src/voxel_scene.cpp
+++ b/applications/reconstruct/src/voxel_scene.cpp
@@ -84,12 +84,14 @@ int SceneRep::upload() {
 			continue;
 		} else {
 			auto in = cam.source;
+
+			cam.params.fx = in->parameters().fx;
+			cam.params.fy = in->parameters().fy;
+			cam.params.mx = -in->parameters().cx;
+			cam.params.my = -in->parameters().cy;
+
 			// Only now do we have camera parameters for allocations...
 			if (cam.params.m_imageWidth == 0) {
-				cam.params.fx = in->parameters().fx;
-				cam.params.fy = in->parameters().fy;
-				cam.params.mx = -in->parameters().cx;
-				cam.params.my = -in->parameters().cy;
 				cam.params.m_imageWidth = in->parameters().width;
 				cam.params.m_imageHeight = in->parameters().height;
 				cam.params.m_sensorDepthWorldMax = in->parameters().maxDepth;
@@ -185,7 +187,7 @@ void SceneRep::garbage() {
 
 void SceneRep::setLastRigidTransform(const Eigen::Matrix4f& lastRigidTransform) {
 	m_hashParams.m_rigidTransform = MatrixConversion::toCUDA(lastRigidTransform);
-	m_hashParams.m_rigidTransformInverse = m_hashParams.m_rigidTransform.getInverse();
+	m_hashParams.m_rigidTransformInverse = MatrixConversion::toCUDA(lastRigidTransform.inverse()); //m_hashParams.m_rigidTransform.getInverse();
 }
 
 /*void SceneRep::setLastRigidTransformAndCompactify(const Eigen::Matrix4f& lastRigidTransform, const DepthCameraData& depthCameraData) {
diff --git a/components/rgbd-sources/src/snapshot_source.cpp b/components/rgbd-sources/src/snapshot_source.cpp
index 0e8dec08b..d3e70524e 100644
--- a/components/rgbd-sources/src/snapshot_source.cpp
+++ b/components/rgbd-sources/src/snapshot_source.cpp
@@ -23,5 +23,24 @@ SnapshotSource::SnapshotSource(ftl::rgbd::Source *host, SnapshotReader &reader,
 		ftl::rgbd::colourCorrection(rgb_, host->value("gamma", 1.0f), host->value("temperature", 6500));
 	});
 
+	// Add calibration to config object
+	host_->getConfig()["focal"] = params_.fx;
+	host_->getConfig()["centre_x"] = params_.cx;
+	host_->getConfig()["centre_y"] = params_.cy;
+	host_->getConfig()["baseline"] = params_.baseline;
+
+	host_->on("focal", [this](const ftl::config::Event &e) {
+		params_.fx = host_->value("focal", params_.fx);
+		params_.fy = params_.fx;
+	});
+
+	host_->on("centre_x", [this](const ftl::config::Event &e) {
+		params_.cx = host_->value("centre_x", params_.cx);
+	});
+
+	host_->on("centre_y", [this](const ftl::config::Event &e) {
+		params_.cy = host_->value("centre_y", params_.cy);
+	});
+
     setPose(pose);
 }
-- 
GitLab