From 698e2ffbf804928160c9e4dce016a422ecdde28d Mon Sep 17 00:00:00 2001 From: Cyrille Favreau Date: Mon, 24 Apr 2017 11:32:03 +0200 Subject: [PATCH] Added support for 3D Stereo in Deflect plugin (#151) --- .gitexternals | 2 +- .gitsubprojects | 2 +- 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 +- 7 files changed, 38 insertions(+), 13 deletions(-) diff --git a/.gitexternals b/.gitexternals index 3d0450d54..d09a14b5a 100644 --- a/.gitexternals +++ b/.gitexternals @@ -1,2 +1,2 @@ # -*- mode: cmake -*- -# CMake/common https://github.com/Eyescale/CMake.git 6a44f78 +# CMake/common https://github.com/Eyescale/CMake.git c782fbd diff --git a/.gitsubprojects b/.gitsubprojects index 3501bb6bf..cf32666b5 100644 --- a/.gitsubprojects +++ b/.gitsubprojects @@ -10,7 +10,7 @@ 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 diff --git a/apps/ui/BaseWindow.cpp b/apps/ui/BaseWindow.cpp index 593e1eddc..e4080ac4f 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 96a0ee059..f11f87ab5 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 3a1173f8f..9d273f824 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 5f7f2f6ce..a9c83848a 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 b95a30e2f..3ca8e0c32 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;