From 422f857e219c8a0699eb4ca2cbdcec259c9a272d Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 18 Sep 2019 18:01:46 +0300
Subject: [PATCH] Fix missing virtual capabilities

---
 components/renderers/cpp/src/splat_render.cpp | 14 ++++++++------
 components/rgbd-sources/src/streamer.cpp      |  1 +
 components/rgbd-sources/src/virtual.cpp       |  6 ++++++
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/components/renderers/cpp/src/splat_render.cpp b/components/renderers/cpp/src/splat_render.cpp
index 9bae08e43..f6e05eeb4 100644
--- a/components/renderers/cpp/src/splat_render.cpp
+++ b/components/renderers/cpp/src/splat_render.cpp
@@ -77,11 +77,13 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
 	params.m_viewMatrixInverse = MatrixConversion::toCUDA(src->getPose().cast<float>());
 	params.camera = camera;
 
+	LOG(INFO) << "VPOSE = " << src->getPose();
+
 	// Clear all channels to 0 or max depth
 	temp_.get<GpuMat>(Channel::Depth).setTo(cv::Scalar(0x7FFFFFFF), cvstream);
 	temp_.get<GpuMat>(Channel::Depth2).setTo(cv::Scalar(0x7FFFFFFF), cvstream);
 	out.get<GpuMat>(Channel::Depth).setTo(cv::Scalar(1000.0f), cvstream);
-	out.get<GpuMat>(Channel::Colour).setTo(cv::Scalar(0,0,0), cvstream);
+	out.get<GpuMat>(Channel::Colour).setTo(cv::Scalar(76,76,76), cvstream);
 
 	LOG(INFO) << "Render ready: " << camera.width << "," << camera.height;
 
@@ -99,7 +101,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
 
 		// Needs to create points channel first?
 		if (!f.hasChannel(Channel::Points)) {
-			LOG(INFO) << "Creating points...";
+			LOG(INFO) << "Creating points... " << s->parameters().width;
 			
 			auto &t = f.createTexture<float4>(Channel::Points, Format<float4>(f.get<GpuMat>(Channel::Colour).size()));
 			auto pose = MatrixConversion::toCUDA(s->getPose().cast<float>().inverse());
@@ -166,16 +168,16 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
 			//src->write(scene_.timestamp, output_, stream);
 		} else {
 			LOG(INFO) << "No second rendering";
-			if (value("splatting",  false)) {
+			//if (value("splatting",  false)) {
 				//ftl::cuda::splat_points(depth1_, colour1_, normal1_, depth2_, colour2_, params, stream);
 				//src->writeFrames(ts, colour1_, depth2_, stream);
 				//src->write(scene_.timestamp, out, stream);
-			} else {
+			//} else {
 				//ftl::cuda::int_to_float(depth1_, depth2_, 1.0f / 1000.0f, stream);
-				//temp_.get<GpuMat>(Channel::Depth).convertTo(out.get<GpuMat>(Channel::Depth), CV_32F, 1.0f / 1000.0f, cvstream);
+				temp_.get<GpuMat>(Channel::Depth).convertTo(out.get<GpuMat>(Channel::Depth), CV_32F, 1.0f / 1000.0f, cvstream);
 				//src->writeFrames(ts, colour1_, depth2_, stream);
 				//src->write(scene_.timestamp, output_, stream);
-			}
+			//}
 		}
 	//}
 
diff --git a/components/rgbd-sources/src/streamer.cpp b/components/rgbd-sources/src/streamer.cpp
index a1019cb8e..2b43f97a7 100644
--- a/components/rgbd-sources/src/streamer.cpp
+++ b/components/rgbd-sources/src/streamer.cpp
@@ -74,6 +74,7 @@ Streamer::Streamer(nlohmann::json &config, Universe *net)
 		if (sources_.find(uri) != sources_.end()) {
 			Eigen::Matrix4d pose;
 			memcpy(pose.data(), buf.data(), buf.size());
+			LOG(INFO) << "SET POSE:";
 			sources_[uri]->src->setPose(pose);
 		}
 	});
diff --git a/components/rgbd-sources/src/virtual.cpp b/components/rgbd-sources/src/virtual.cpp
index 54c9754b9..62b404155 100644
--- a/components/rgbd-sources/src/virtual.cpp
+++ b/components/rgbd-sources/src/virtual.cpp
@@ -8,6 +8,7 @@ class VirtualImpl : public ftl::rgbd::detail::Source {
 	public:
 	explicit VirtualImpl(ftl::rgbd::Source *host, const ftl::rgbd::Camera &params) : ftl::rgbd::detail::Source(host) {
 		params_ = params;
+		capabilities_ = ftl::rgbd::kCapMovable | ftl::rgbd::kCapVideo | ftl::rgbd::kCapStereo;
 	}
 
 	~VirtualImpl() {
@@ -15,6 +16,7 @@ class VirtualImpl : public ftl::rgbd::detail::Source {
 	}
 
 	bool capture(int64_t ts) override {
+		timestamp_ = ts;
 		return true;
 	}
 
@@ -38,9 +40,13 @@ class VirtualImpl : public ftl::rgbd::detail::Source {
 				frame.download(Channel::Colour + Channel::Depth);
 				cv::swap(frame.get<cv::Mat>(Channel::Colour), rgb_);
 				cv::swap(frame.get<cv::Mat>(Channel::Depth), depth_);
+				LOG(INFO) << "Written: " << rgb_.cols;
 			} else {
 				LOG(ERROR) << "Missing colour or depth frame in rendering";
 			}
+
+			auto cb = host_->callback();
+			if (cb) cb(timestamp_, rgb_, depth_);
 		}
 		return true;
 	}
-- 
GitLab