Skip to content
Snippets Groups Projects
Commit b7e0468d authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Add density channel

parent fdb51c99
No related branches found
No related tags found
1 merge request!123Implements #189 using density to estimate radius
Pipeline #15137 passed
...@@ -235,6 +235,7 @@ void ftl::gui::Camera::setChannel(Channel c) { ...@@ -235,6 +235,7 @@ void ftl::gui::Camera::setChannel(Channel c) {
channel_ = c; channel_ = c;
switch (c) { switch (c) {
case Channel::Energy: case Channel::Energy:
case Channel::Density:
case Channel::Flow: case Channel::Flow:
case Channel::Confidence: case Channel::Confidence:
case Channel::Normals: case Channel::Normals:
......
#ifndef _FTL_EXCEPTION_HPP_ #ifndef _FTL_EXCEPTION_HPP_
#define _FTL_EXCEPTION_HPP_ #define _FTL_EXCEPTION_HPP_
#include <sstream>
namespace ftl { namespace ftl {
class Formatter {
public:
Formatter() {}
~Formatter() {}
template <typename Type>
inline Formatter & operator << (const Type & value)
{
stream_ << value;
return *this;
}
inline std::string str() const { return stream_.str(); }
inline operator std::string () const { return stream_.str(); }
enum ConvertToString
{
to_str
};
inline std::string operator >> (ConvertToString) { return stream_.str(); }
private:
std::stringstream stream_;
Formatter(const Formatter &);
Formatter & operator = (Formatter &);
};
class exception : public std::exception class exception : public std::exception
{ {
public: public:
explicit exception(const char *msg) : msg_(msg) {}; explicit exception(const char *msg) : msg_(msg) {}
explicit exception(const Formatter &msg) : msg_(msg.str()) {}
const char * what () const throw () { const char * what () const throw () {
return msg_; return msg_.c_str();
} }
private: private:
const char *msg_; std::string msg_;
}; };
} }
......
...@@ -26,7 +26,7 @@ class Splatter : public ftl::render::Renderer { ...@@ -26,7 +26,7 @@ class Splatter : public ftl::render::Renderer {
//void setOutputDevice(int); //void setOutputDevice(int);
protected: protected:
void _renderChannel(ftl::rgbd::Frame &out, const ftl::rgbd::Channel &channel, cudaStream_t stream); void _renderChannel(ftl::rgbd::Frame &out, ftl::rgbd::Channel channel_in, ftl::rgbd::Channel channel_out, cudaStream_t stream);
private: private:
int device_; int device_;
...@@ -40,6 +40,7 @@ class Splatter : public ftl::render::Renderer { ...@@ -40,6 +40,7 @@ class Splatter : public ftl::render::Renderer {
//SplatParams params_; //SplatParams params_;
ftl::rgbd::Frame temp_; ftl::rgbd::Frame temp_;
ftl::rgbd::Frame accum_;
ftl::rgbd::FrameSet *scene_; ftl::rgbd::FrameSet *scene_;
ftl::cuda::ClipSpace clip_; ftl::cuda::ClipSpace clip_;
bool clipping_; bool clipping_;
......
...@@ -215,75 +215,77 @@ void Splatter::_dibr(cudaStream_t stream) { ...@@ -215,75 +215,77 @@ void Splatter::_dibr(cudaStream_t stream) {
void Splatter::_renderChannel( void Splatter::_renderChannel(
ftl::rgbd::Frame &out, ftl::rgbd::Frame &out,
const Channel &channel, cudaStream_t stream) Channel channel_in, Channel channel_out, cudaStream_t stream)
{ {
if (channel == Channel::None) return; if (channel_out == Channel::None || channel_in == Channel::None) return;
cv::cuda::Stream cvstream = cv::cuda::StreamAccessor::wrapStream(stream); cv::cuda::Stream cvstream = cv::cuda::StreamAccessor::wrapStream(stream);
if (scene_->frames.size() < 1) return; if (scene_->frames.size() < 1) return;
bool is_float = out.get<GpuMat>(channel).type() == CV_32F; //ftl::rgbd::isFloatChannel(channel); bool is_float = out.get<GpuMat>(channel_out).type() == CV_32F; //ftl::rgbd::isFloatChannel(channel);
bool is_4chan = out.get<GpuMat>(channel).type() == CV_32FC4; bool is_4chan = out.get<GpuMat>(channel_out).type() == CV_32FC4;
temp_.createTexture<float4>(Channel::Colour); temp_.createTexture<float4>(Channel::Colour);
temp_.createTexture<float>(Channel::Contribution); temp_.createTexture<float>(Channel::Contribution);
// Generate initial normals for the splats // Generate initial normals for the splats
out.create<GpuMat>(Channel::Normals, Format<float4>(params_.camera.width, params_.camera.height)); accum_.create<GpuMat>(Channel::Normals, Format<float4>(params_.camera.width, params_.camera.height));
_blendChannel(out, Channel::Normals, Channel::Normals, stream); _blendChannel(accum_, Channel::Normals, Channel::Normals, stream);
// Estimate point density // Estimate point density
out.create<GpuMat>(Channel::Density, Format<float>(params_.camera.width, params_.camera.height)); accum_.create<GpuMat>(Channel::Density, Format<float>(params_.camera.width, params_.camera.height));
_blendChannel(out, Channel::Depth, Channel::Density, stream); _blendChannel(accum_, Channel::Depth, Channel::Density, stream);
// FIXME: Using colour 2 in this way seems broken since it is already used // FIXME: Using colour 2 in this way seems broken since it is already used
if (is_4chan) { if (is_4chan) {
temp_.create<GpuMat>(Channel::Colour2, Format<float4>(params_.camera.width, params_.camera.height)); accum_.create<GpuMat>(channel_out, Format<float4>(params_.camera.width, params_.camera.height));
temp_.get<GpuMat>(Channel::Colour2).setTo(cv::Scalar(0.0f,0.0f,0.0f,0.0f), cvstream); accum_.get<GpuMat>(channel_out).setTo(cv::Scalar(0.0f,0.0f,0.0f,0.0f), cvstream);
} else if (is_float) { } else if (is_float) {
temp_.create<GpuMat>(Channel::Colour2, Format<float>(params_.camera.width, params_.camera.height)); accum_.create<GpuMat>(channel_out, Format<float>(params_.camera.width, params_.camera.height));
temp_.get<GpuMat>(Channel::Colour2).setTo(cv::Scalar(0.0f), cvstream); accum_.get<GpuMat>(channel_out).setTo(cv::Scalar(0.0f), cvstream);
} else { } else {
temp_.create<GpuMat>(Channel::Colour2, Format<uchar4>(params_.camera.width, params_.camera.height)); accum_.create<GpuMat>(channel_out, Format<uchar4>(params_.camera.width, params_.camera.height));
temp_.get<GpuMat>(Channel::Colour2).setTo(cv::Scalar(0,0,0,0), cvstream); accum_.get<GpuMat>(channel_out).setTo(cv::Scalar(0,0,0,0), cvstream);
} }
if (splat_) { //if (splat_) {
_blendChannel(temp_, channel, Channel::Colour2, stream); _blendChannel(accum_, channel_in, channel_out, stream);
} else { //} else {
_blendChannel(out, channel, channel, stream); // _blendChannel(out, channel, channel, stream);
} //}
// Now splat the points // Now splat the points
if (splat_) { if (splat_) {
if (is_4chan) { if (is_4chan) {
ftl::cuda::splat( ftl::cuda::splat(
out.getTexture<float4>(Channel::Normals), accum_.getTexture<float4>(Channel::Normals),
temp_.getTexture<float4>(Channel::Colour2), accum_.getTexture<float4>(channel_out),
temp_.getTexture<int>(Channel::Depth2), temp_.getTexture<int>(Channel::Depth2),
out.createTexture<float>(Channel::Depth), out.createTexture<float>(Channel::Depth),
out.createTexture<float4>(channel), out.createTexture<float4>(channel_out),
params_, stream params_, stream
); );
} else if (is_float) { } else if (is_float) {
ftl::cuda::splat( ftl::cuda::splat(
out.getTexture<float4>(Channel::Normals), accum_.getTexture<float4>(Channel::Normals),
temp_.getTexture<float>(Channel::Colour2), accum_.getTexture<float>(channel_out),
temp_.getTexture<int>(Channel::Depth2), temp_.getTexture<int>(Channel::Depth2),
out.createTexture<float>(Channel::Depth), out.createTexture<float>(Channel::Depth),
out.createTexture<float>(channel), out.createTexture<float>(channel_out),
params_, stream params_, stream
); );
} else { } else {
ftl::cuda::splat( ftl::cuda::splat(
out.getTexture<float4>(Channel::Normals), accum_.getTexture<float4>(Channel::Normals),
temp_.getTexture<uchar4>(Channel::Colour2), accum_.getTexture<uchar4>(channel_out),
temp_.getTexture<int>(Channel::Depth2), temp_.getTexture<int>(Channel::Depth2),
out.createTexture<float>(Channel::Depth), out.createTexture<float>(Channel::Depth),
out.createTexture<uchar4>(channel), out.createTexture<uchar4>(channel_out),
params_, stream params_, stream
); );
} }
} else {
// Swap accum frames directly to output.
} }
} }
...@@ -367,7 +369,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda ...@@ -367,7 +369,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
} }
_dibr(stream); _dibr(stream);
_renderChannel(out, Channel::Colour, stream); _renderChannel(out, Channel::Colour, Channel::Colour, stream);
Channel chan = src->getChannel(); Channel chan = src->getChannel();
if (chan == Channel::Depth) if (chan == Channel::Depth)
...@@ -377,7 +379,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda ...@@ -377,7 +379,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
out.create<GpuMat>(Channel::Normals, Format<float4>(camera.width, camera.height)); out.create<GpuMat>(Channel::Normals, Format<float4>(camera.width, camera.height));
// Render normal attribute // Render normal attribute
_renderChannel(out, Channel::Normals, stream); _renderChannel(out, Channel::Normals, Channel::Normals, stream);
// Convert normal to single float value // Convert normal to single float value
temp_.create<GpuMat>(Channel::Colour, Format<uchar4>(camera.width, camera.height)); temp_.create<GpuMat>(Channel::Colour, Format<uchar4>(camera.width, camera.height));
...@@ -394,6 +396,11 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda ...@@ -394,6 +396,11 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
//{ //{
// cv::cuda::swap(temp_.get<GpuMat>(Channel::Contribution), out.create<GpuMat>(Channel::Contribution)); // cv::cuda::swap(temp_.get<GpuMat>(Channel::Contribution), out.create<GpuMat>(Channel::Contribution));
//} //}
else if (chan == Channel::Density) {
out.create<GpuMat>(chan, Format<float>(camera.width, camera.height));
out.get<GpuMat>(chan).setTo(cv::Scalar(0.0f), cvstream);
_renderChannel(out, Channel::Depth, Channel::Density, stream);
}
else if (chan == Channel::Right) else if (chan == Channel::Right)
{ {
Eigen::Affine3f transform(Eigen::Translation3f(camera.baseline,0.0f,0.0f)); Eigen::Affine3f transform(Eigen::Translation3f(camera.baseline,0.0f,0.0f));
...@@ -405,7 +412,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda ...@@ -405,7 +412,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
out.get<GpuMat>(Channel::Right).setTo(background_, cvstream); out.get<GpuMat>(Channel::Right).setTo(background_, cvstream);
_dibr(stream); // Need to re-dibr due to pose change _dibr(stream); // Need to re-dibr due to pose change
_renderChannel(out, Channel::Right, stream); _renderChannel(out, Channel::Right, Channel::Right, stream);
} else if (chan != Channel::None) { } else if (chan != Channel::None) {
if (ftl::rgbd::isFloatChannel(chan)) { if (ftl::rgbd::isFloatChannel(chan)) {
out.create<GpuMat>(chan, Format<float>(camera.width, camera.height)); out.create<GpuMat>(chan, Format<float>(camera.width, camera.height));
...@@ -414,7 +421,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda ...@@ -414,7 +421,7 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
out.create<GpuMat>(chan, Format<uchar4>(camera.width, camera.height)); out.create<GpuMat>(chan, Format<uchar4>(camera.width, camera.height));
out.get<GpuMat>(chan).setTo(background_, cvstream); out.get<GpuMat>(chan).setTo(background_, cvstream);
} }
_renderChannel(out, chan, stream); _renderChannel(out, chan, chan, stream);
} }
return true; return true;
......
...@@ -181,7 +181,7 @@ template <> cv::cuda::GpuMat &Frame::create(ftl::rgbd::Channel c); ...@@ -181,7 +181,7 @@ template <> cv::cuda::GpuMat &Frame::create(ftl::rgbd::Channel c);
template <typename T> template <typename T>
ftl::cuda::TextureObject<T> &Frame::getTexture(ftl::rgbd::Channel c) { ftl::cuda::TextureObject<T> &Frame::getTexture(ftl::rgbd::Channel c) {
if (!channels_.has(c)) throw ftl::exception("Texture channel does not exist"); if (!channels_.has(c)) throw ftl::exception(ftl::Formatter() << "Texture channel does not exist: " << (int)c);
if (!gpu_.has(c)) throw ftl::exception("Texture channel is not on GPU"); if (!gpu_.has(c)) throw ftl::exception("Texture channel is not on GPU");
auto &m = _get(c); auto &m = _get(c);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment