From 93cb4af8ff0ac1a958441fd206497924ca093021 Mon Sep 17 00:00:00 2001 From: Cyrille Favreau Date: Fri, 21 Apr 2017 16:15:58 +0200 Subject: [PATCH] Added support for 3D Stereo in Deflect plugin --- .gitsubprojects | 14 +++++++------- apps/ui/BaseWindow.cpp | 12 +++++++----- brayns/common/engine/Engine.cpp | 16 +++++++++++++--- brayns/common/engine/Engine.h | 10 ++++++++++ plugins/extensions/plugins/DeflectPlugin.cpp | 7 +++++-- plugins/extensions/plugins/DeflectPlugin.h | 2 +- 6 files changed, 43 insertions(+), 18 deletions(-) diff --git a/.gitsubprojects b/.gitsubprojects index 3501bb6bf9..6695a5b829 100644 --- a/.gitsubprojects +++ b/.gitsubprojects @@ -1,22 +1,22 @@ # -*- mode: cmake -*- git_subproject(vmmlib https://github.com/Eyescale/vmmlib.git cfa6243) -git_subproject(Servus https://github.com/HBPVIS/Servus.git 36180b5) +git_subproject(Servus https://github.com/HBPVIS/Servus.git 3d7e09a) if(BRAYNS_NETWORKING_ENABLED OR BRAYNS_DEFLECT_ENABLED) - git_subproject(ZeroBuf https://github.com/HBPVIS/ZeroBuf.git cea0338) - git_subproject(ZeroEQ https://github.com/HBPVis/ZeroEQ.git 847025a) - git_subproject(Lexis https://github.com/HBPVis/Lexis.git 2f50220) + git_subproject(ZeroBuf https://github.com/HBPVIS/ZeroBuf.git 136330e) + git_subproject(ZeroEQ https://github.com/HBPVis/ZeroEQ.git 1787b96) + git_subproject(Lexis https://github.com/HBPVis/Lexis.git afa2a02) endif() # Streaming to display walls if(BRAYNS_DEFLECT_ENABLED) - git_subproject(Deflect https://github.com/BlueBrain/Deflect.git 24e97d7) + git_subproject(Deflect https://github.com/BlueBrain/Deflect.git f7b9019) endif() # Data access if(BRAYNS_BRION_ENABLED) - git_subproject(Brion https://github.com/BlueBrain/Brion.git 8b0c1f1) - git_subproject(Lunchbox https://github.com/Eyescale/Lunchbox.git f05b9c6) + git_subproject(Brion https://github.com/BlueBrain/Brion.git c775240) + git_subproject(Lunchbox https://github.com/Eyescale/Lunchbox.git 78dc474) endif() diff --git a/apps/ui/BaseWindow.cpp b/apps/ui/BaseWindow.cpp index 593e1eddca..e4080ac4f1 100644 --- a/apps/ui/BaseWindow.cpp +++ b/apps/ui/BaseWindow.cpp @@ -207,16 +207,18 @@ void BaseWindow::idle() void BaseWindow::reshape(const Vector2i& newSize) { - _windowSize = newSize; Engine& engine = _brayns.getEngine(); - engine.getCamera().setAspectRatio(float(newSize.x()) / float(newSize.y())); - engine.reshape(newSize); + _windowSize = engine.getSupportedFrameSize(newSize); + + engine.getCamera().setAspectRatio(float(_windowSize.x()) / + float(_windowSize.y())); + engine.reshape(_windowSize); auto& applicationParameters = _brayns.getParametersManager(); - applicationParameters.getApplicationParameters().setWindowSize(newSize); + applicationParameters.getApplicationParameters().setWindowSize(_windowSize); if (!applicationParameters.getApplicationParameters().getFilters().empty()) - _screenSpaceProcessor.resize(newSize.x(), newSize.y()); + _screenSpaceProcessor.resize(_windowSize.x(), _windowSize.y()); } void BaseWindow::activate() diff --git a/brayns/common/engine/Engine.cpp b/brayns/common/engine/Engine.cpp index 96a0ee0599..f11f87ab52 100644 --- a/brayns/common/engine/Engine.cpp +++ b/brayns/common/engine/Engine.cpp @@ -52,9 +52,10 @@ void Engine::reshape(const Vector2ui& frameSize) if (_frameBuffer->getSize() == frameSize) return; - _frameBuffer->resize(frameSize); - _camera->setAspectRatio(static_cast(frameSize.x()) / - static_cast(frameSize.y())); + const auto size = getSupportedFrameSize(frameSize); + _frameBuffer->resize(size); + _camera->setAspectRatio(static_cast(size.x()) / + static_cast(size.y())); } void Engine::commit() @@ -119,4 +120,13 @@ void Engine::resetFrameNumber() { _frameNumber = -1; } + +Vector2ui Engine::getSupportedFrameSize(const Vector2ui& size) +{ + Vector2f result = size; + if (getCamera().getType() == CameraType::stereo && size.x() % 2 != 0) + // In case of 3D stereo vision, make sure the width is even + result.x() = size.x() - 1; + return result; +} } diff --git a/brayns/common/engine/Engine.h b/brayns/common/engine/Engine.h index 3a1173f8fe..9d273f8248 100644 --- a/brayns/common/engine/Engine.h +++ b/brayns/common/engine/Engine.h @@ -73,6 +73,7 @@ class Engine /** Gets the frame buffer */ FrameBuffer& getFrameBuffer() { return *_frameBuffer; } /** Gets the camera */ + const Camera& getCamera() const { return *_camera; } Camera& getCamera() { return *_camera; } /** Gets the renderer */ Renderer& getRenderer(); @@ -133,6 +134,15 @@ class Engine * @returns the current frame number */ size_t getFrameNumber() const { return _frameNumber; } + /** + * @brief Adapts the size of the frame buffer according to camera + * requirements. Typically, in case of 3D stereo vision, the frame buffer + * width has to be an even number. + * @param size New size of the frame buffer + * @return Size that matches the camera requirements + */ + Vector2ui getSupportedFrameSize(const Vector2ui& size); + protected: void _render(const RenderInput& renderInput, RenderOutput& renderOutput); void _render(); diff --git a/plugins/extensions/plugins/DeflectPlugin.cpp b/plugins/extensions/plugins/DeflectPlugin.cpp index 5f7f2f6cea..a9c83848ae 100644 --- a/plugins/extensions/plugins/DeflectPlugin.cpp +++ b/plugins/extensions/plugins/DeflectPlugin.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -172,7 +173,7 @@ void DeflectPlugin::_sendDeflectFrame(Engine& engine) _lastImage.size = frameSize; _lastImage.format = frameBuffer.getFrameBufferFormat(); - _send(true); + _send(engine, true); } else _sendFuture = make_ready_future(true); @@ -252,7 +253,7 @@ bool DeflectPlugin::_handleDeflectEvents(Engine& engine) return true; } -void DeflectPlugin::_send(const bool swapYAxis) +void DeflectPlugin::_send(const Engine& engine, const bool swapYAxis) { deflect::PixelFormat format = deflect::RGBA; switch (_lastImage.format) @@ -270,6 +271,8 @@ void DeflectPlugin::_send(const bool swapYAxis) deflect::ImageWrapper deflectImage(_lastImage.data.data(), _lastImage.size.x(), _lastImage.size.y(), format); + if (engine.getCamera().getType() == CameraType::stereo) + deflectImage.view = deflect::View::side_by_side; deflectImage.compressionQuality = _params.getQuality(); deflectImage.compressionPolicy = _params.getCompression() diff --git a/plugins/extensions/plugins/DeflectPlugin.h b/plugins/extensions/plugins/DeflectPlugin.h index b95a30e2f0..3ca8e0c32b 100644 --- a/plugins/extensions/plugins/DeflectPlugin.h +++ b/plugins/extensions/plugins/DeflectPlugin.h @@ -80,7 +80,7 @@ class DeflectPlugin : public ExtensionPlugin * * @param swapYAxis enables a vertical flip operation on the image */ - void _send(bool swapYAxis); + void _send(const Engine& engine, bool swapYAxis); Vector2d _getWindowPos(const deflect::Event& event, const Vector2ui& windowSize) const;