Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for 3D Stereo in Deflect plugin #151

Merged
merged 1 commit into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitexternals
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- mode: cmake -*-
# CMake/common https://github.com/Eyescale/CMake.git 6a44f78
# CMake/common https://github.com/Eyescale/CMake.git c782fbd
2 changes: 1 addition & 1 deletion .gitsubprojects
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions apps/ui/BaseWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 13 additions & 3 deletions brayns/common/engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ void Engine::reshape(const Vector2ui& frameSize)
if (_frameBuffer->getSize() == frameSize)
return;

_frameBuffer->resize(frameSize);
_camera->setAspectRatio(static_cast<float>(frameSize.x()) /
static_cast<float>(frameSize.y()));
const auto size = getSupportedFrameSize(frameSize);
_frameBuffer->resize(size);
_camera->setAspectRatio(static_cast<float>(size.x()) /
static_cast<float>(size.y()));
}

void Engine::commit()
Expand Down Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions brayns/common/engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 5 additions & 2 deletions plugins/extensions/plugins/DeflectPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <brayns/Brayns.h>
#include <brayns/common/camera/AbstractManipulator.h>
#include <brayns/common/camera/Camera.h>
#include <brayns/common/engine/Engine.h>
#include <brayns/common/input/KeyboardHandler.h>
#include <brayns/common/renderer/FrameBuffer.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion plugins/extensions/plugins/DeflectPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down