From 362905152bcbc1ba141bf49a9060cf01ef73cc7f Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Tue, 29 Oct 2019 18:24:19 +0200
Subject: [PATCH] Some work to improve node listings

---
 applications/gui/src/main.cpp                 |  2 +-
 applications/gui/src/screen.cpp               | 26 ++++++++++++-------
 components/control/cpp/src/master.cpp         |  1 +
 .../cpp/include/ftl/render/tri_render.hpp     |  1 +
 components/renderers/cpp/src/tri_render.cpp   | 25 +++++++++++++++---
 .../rgbd-sources/src/sources/net/net.cpp      |  2 +-
 6 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/applications/gui/src/main.cpp b/applications/gui/src/main.cpp
index 974afff14..50bc3638c 100644
--- a/applications/gui/src/main.cpp
+++ b/applications/gui/src/main.cpp
@@ -13,7 +13,7 @@ int main(int argc, char **argv) {
 	ftl::net::Universe *net = ftl::create<ftl::net::Universe>(root, "net");
 
 	net->start();
-	//net->waitConnections();
+	net->waitConnections();
 
 	ftl::ctrl::Master *controller = new ftl::ctrl::Master(root, net);
 	controller->onLog([](const ftl::ctrl::LogEvent &e){
diff --git a/applications/gui/src/screen.cpp b/applications/gui/src/screen.cpp
index bb69755fb..76d727a99 100644
--- a/applications/gui/src/screen.cpp
+++ b/applications/gui/src/screen.cpp
@@ -225,17 +225,23 @@ ftl::gui::Screen::Screen(ftl::Configurable *proot, ftl::net::Universe *pnet, ftl
 	popup->setLayout(new GroupLayout());
 	popup->setTheme(toolbuttheme);
 
-	auto node_details = ctrl_->getSlaves();
-	std::vector<std::string> node_titles;
-
-	for (auto &d : node_details) {
-		auto peer = ftl::UUID(d["id"].get<std::string>());
-		itembutton = new Button(popup, d["title"].get<std::string>());
-		itembutton->setCallback([this,popup,peer]() {
-			auto config_window = new ConfigWindow(this, ctrl_, peer);
-			config_window->setTheme(windowtheme);
-		});
+	//net_->onConnect([this,popup](ftl::net::Peer *p) {
+	{
+		LOG(INFO) << "NET CONNECT";
+		auto node_details = ctrl_->getSlaves();
+		std::vector<std::string> node_titles;
+
+		for (auto &d : node_details) {
+			LOG(INFO) << "ADDING TITLE: " << d.dump();
+			auto peer = ftl::UUID(d["id"].get<std::string>());
+			auto itembutton = new Button(popup, d["title"].get<std::string>());
+			itembutton->setCallback([this,popup,peer]() {
+				auto config_window = new ConfigWindow(this, ctrl_, peer);
+				config_window->setTheme(windowtheme);
+			});
+		}
 	}
+	//});
 
 	itembutton = new Button(popup, "Local");
 	itembutton->setCallback([this,popup]() {
diff --git a/components/control/cpp/src/master.cpp b/components/control/cpp/src/master.cpp
index a1248fac7..a13a67a90 100644
--- a/components/control/cpp/src/master.cpp
+++ b/components/control/cpp/src/master.cpp
@@ -86,6 +86,7 @@ vector<string> Master::getConfigurables() {
 
 vector<string> Master::getConfigurables(const ftl::UUID &peer) {
 	try {
+		LOG(INFO) << "LISTING CONFIGS";
 		return net_->call<vector<string>>(peer, "list_configurables");
 	} catch (...) {
 		return {};
diff --git a/components/renderers/cpp/include/ftl/render/tri_render.hpp b/components/renderers/cpp/include/ftl/render/tri_render.hpp
index e07e9577e..6d03fd4a8 100644
--- a/components/renderers/cpp/include/ftl/render/tri_render.hpp
+++ b/components/renderers/cpp/include/ftl/render/tri_render.hpp
@@ -63,6 +63,7 @@ class Triangular : public ftl::render::Renderer {
 	void __reprojectChannel(ftl::rgbd::Frame &, ftl::codecs::Channel in, ftl::codecs::Channel out, cudaStream_t);
 	void _reprojectChannel(ftl::rgbd::Frame &, ftl::codecs::Channel in, ftl::codecs::Channel out, cudaStream_t);
 	void _dibr(cudaStream_t);
+	void _mesh(cudaStream_t);
 };
 
 }
diff --git a/components/renderers/cpp/src/tri_render.cpp b/components/renderers/cpp/src/tri_render.cpp
index 0e405f9e4..58e21c367 100644
--- a/components/renderers/cpp/src/tri_render.cpp
+++ b/components/renderers/cpp/src/tri_render.cpp
@@ -268,12 +268,27 @@ void Triangular::_dibr(cudaStream_t stream) {
 			continue;
 		}
 
-		/*ftl::cuda::dibr_merge(
+		ftl::cuda::dibr_merge(
 			f.createTexture<float4>(Channel::Points),
 			f.createTexture<float4>(Channel::Normals),
 			temp_.createTexture<int>(Channel::Depth2),
 			params_, backcull_, stream
-		);*/
+		);
+	}
+}
+
+void Triangular::_mesh(cudaStream_t stream) {
+	cv::cuda::Stream cvstream = cv::cuda::StreamAccessor::wrapStream(stream);
+	temp_.get<GpuMat>(Channel::Depth2).setTo(cv::Scalar(0x7FFFFFFF), cvstream);
+
+	for (size_t i=0; i < scene_->frames.size(); ++i) {
+		auto &f = scene_->frames[i];
+		auto *s = scene_->sources[i];
+
+		if (f.empty(Channel::Depth + Channel::Colour)) {
+			LOG(ERROR) << "Missing required channel";
+			continue;
+		}
 
 		auto pose = MatrixConversion::toCUDA(s->getPose().cast<float>());
 
@@ -444,7 +459,11 @@ bool Triangular::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out) {
 	}
 
 	// Create and render triangles for depth
-	_dibr(stream_);
+	if (splat_) {
+		_mesh(stream_);
+	} else {
+		_dibr(stream_);
+	}
 	
 	// Generate normals
 	ftl::cuda::normals(accum_.createTexture<float4>(Channel::Normals, Format<float4>(camera.width, camera.height)),
diff --git a/components/rgbd-sources/src/sources/net/net.cpp b/components/rgbd-sources/src/sources/net/net.cpp
index 16c5994d4..56b6355eb 100644
--- a/components/rgbd-sources/src/sources/net/net.cpp
+++ b/components/rgbd-sources/src/sources/net/net.cpp
@@ -229,7 +229,7 @@ void NetSource::_processConfig(const ftl::codecs::Packet &pkt) {
 	auto unpacked = msgpack::unpack((const char*)pkt.data.data(), pkt.data.size());
 	unpacked.get().convert(cfg);
 
-	LOG(INFO) << "Config Received: " << std::get<1>(cfg);
+	//LOG(INFO) << "Config Received: " << std::get<1>(cfg);
 	// TODO: This needs to be put in safer / better location
 	host_->set(std::get<0>(cfg), nlohmann::json::parse(std::get<1>(cfg)));
 }
-- 
GitLab