Skip to content

Commit

Permalink
Add the multiview camera plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
chevtche committed Mar 25, 2019
1 parent e3b3e33 commit 0071241
Show file tree
Hide file tree
Showing 9 changed files with 513 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ if(BRAYNS_NETWORKING_ENABLED)
add_subdirectory(Rockets)
endif()

option(BRAYNS_MULTIVIEW_ENABLED "Activate Multiview camera plugin" OFF)
if(BRAYNS_MULTIVIEW_ENABLED)
add_subdirectory(Multiview)
endif()

option(BRAYNS_OPENDECK_ENABLED "Activate OpenDeck plugin" OFF)
if(BRAYNS_OPENDECK_ENABLED)
add_subdirectory(OpenDeck)
Expand Down
53 changes: 53 additions & 0 deletions plugins/Multiview/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright (c) 2018, EPFL/Blue Brain Project
# All rights reserved. Do not distribute without permission.
# Responsible Author: Grigori Chevtchenko <grigori.chevtchenko@epfl.ch>
#
# This file is part of Brayns <https://github.com/BlueBrain/Brayns>

cmake_minimum_required(VERSION 3.1 FATAL_ERROR)

project(BraynsMultiview VERSION 0.1.0)
set(BraynsMultiview_VERSION_ABI 1)

include(Common)

common_find_package(ospray 1.7 SYSTEM)
common_find_package_post()

set(BRAYNSMULTIVIEW_HEADERS MultiviewPlugin.h)
set(BRAYNSMULTIVIEW_SOURCES MultiviewPlugin.cpp)
set(BRAYNSMULTIVIEW_LINK_LIBRARIES PRIVATE braynsCommon braynsEngine braynsPluginAPI)

if(OSPRAY_FOUND)
list(APPEND BRAYNSMULTIVIEW_SOURCES
ispc/multiview/MultiviewCamera.cpp)

set(BRAYNSMULTIVIEW_ISPC_SOURCES
ispc/multiview/MultiviewCamera.ispc)

list(APPEND BRAYNSMULTIVIEW_SOURCES ${BRAYNSMULTIVIEW_ISPC_SOURCES})

# reuse ispc setup and macros from ospray
list(APPEND CMAKE_MODULE_PATH ${OSPRAY_CMAKE_ROOT})
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set(OSPRAY_DEBUG_BUILD ON)
endif()
include(ispc)

# Compile ispc code
include_directories_ispc(${PROJECT_SOURCE_DIR}/../../ ${OSPRAY_INCLUDE_DIRS})
ospray_ispc_compile(${BRAYNSMULTIVIEW_ISPC_SOURCES})
list(APPEND BRAYNSMULTIVIEW_SOURCES ${ISPC_OBJECTS})

list(APPEND BRAYNSMULTIVIEW_LINK_LIBRARIES ${OSPRAY_LIBRARIES})
endif()

set(BRAYNSMULTIVIEW_OMIT_LIBRARY_HEADER ON)
set(BRAYNSMULTIVIEW_OMIT_VERSION_HEADERS ON)
set(BRAYNSMULTIVIEW_OMIT_EXPORT ON)
set(BRAYNSMULTIVIEW_INCLUDE_NAME brayns_multiview)
common_library(braynsMultiview)

if (TARGET Brayns-all)
add_dependencies(Brayns-all braynsMultiview)
endif()
74 changes: 74 additions & 0 deletions plugins/Multiview/MultiviewPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* Copyright (c) 2018, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "MultiviewPlugin.h"

#include <brayns/common/log.h>
#include <brayns/engine/Camera.h>
#include <brayns/engine/Engine.h>
#include <brayns/parameters/ParametersManager.h>
#include <brayns/pluginapi/PluginAPI.h>

constexpr auto PARAM_ARM_LENGTH = "armLength";

namespace brayns
{

MultiviewPlugin::MultiviewPlugin(PropertyMap&& properties)
: _properties(std::move(properties))
{
const double armLength = _properties.getProperty<double>(PARAM_ARM_LENGTH);
if (armLength <= 0.0f)
{
throw std::runtime_error(
"The multiview camera arm length must be stricly positive");
}
}

void MultiviewPlugin::init()
{
auto& engine = _api->getEngine();

auto& params = engine.getParametersManager();
if(params.getApplicationParameters().getEngine() == "ospray")
engine.addCameraType("multiview", _properties);
else
throw std::runtime_error("The multiview camera is only available for ospray engine");
}
}

extern "C" brayns::ExtensionPlugin* brayns_plugin_create(const int argc,
const char** argv)
{
brayns::PropertyMap properties;
properties.setProperty({PARAM_ARM_LENGTH, 5.0, brayns::Property::MetaData{"Cameras arm length",
"The distance between the cameras and the view center"}});

if (!properties.parse(argc, argv))
return nullptr;
try
{
return new brayns::MultiviewPlugin(std::move(properties));
}
catch (const std::runtime_error& exc)
{
std::cerr << exc.what() << std::endl;
return nullptr;
}
}
38 changes: 38 additions & 0 deletions plugins/Multiview/MultiviewPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Copyright (c) 2018, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include <brayns/common/PropertyMap.h>
#include <brayns/common/types.h>
#include <brayns/pluginapi/ExtensionPlugin.h>

namespace brayns
{
class MultiviewPlugin : public ExtensionPlugin
{
public:
MultiviewPlugin(PropertyMap&& properties);

void init() final;

private:
PropertyMap _properties;
};
}
15 changes: 15 additions & 0 deletions plugins/Multiview/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The Multiview Module for Brayns
==================================

This module implements the multiview(top/front/right/perspective) camera for Brayns

Usage
-----

- Point LD_LIBRARY_PATH to the folder which contains
'libospray_module_multiview.so'
- Run Brayns application either with command line '--module multiview --camera-type multiview' or do
'ospLoadModule("multiview")' programmatically
```
OSPCamera camera = ospNewCamera("multiview");
```
88 changes: 88 additions & 0 deletions plugins/Multiview/ispc/multiview/MultiviewCamera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* Copyright (c) 2018, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Grigori Chevtchenko <grigori.chevtchenko@epfl.ch>
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "MultiviewCamera.h"
#include "MultiviewCamera_ispc.h"

#include <ospray/SDK/common/Data.h>

namespace ospray
{
MultiviewCamera::MultiviewCamera()
{
ispcEquivalent = ispc::MultiviewCamera_create(this);
}

std::string MultiviewCamera::toString() const
{
return "ospray::MultiviewCamera";
}

void MultiviewCamera::commit()
{
Camera::commit();

const float fovy = getParamf("fovy", 60.f);
const float aspect = getParamf("aspect", 1.66667f);
const float apertureRadius = getParamf("apertureRadius", 0.f);
const float focusDistance = getParamf("focusDistance", 1.f);
const float height = getParamf("height", 1.f); // imgPlane_size_y
const float armLength = getParamf("armLength", 5.f);

clipPlanes = getParamData("clipPlanes", nullptr);

dir = normalize(dir);
vec3f dir_du = normalize(cross(dir, up));
vec3f dir_dv = cross(dir_du, dir);

vec3f org = pos;

float imgPlane_size_y = 2.f * tanf(deg2rad(0.5f * fovy));
float imgPlane_size_x = imgPlane_size_y * aspect;

dir_du *= imgPlane_size_x;
dir_dv *= imgPlane_size_y;

vec3f dir_00 = dir - 0.5f * dir_du - 0.5f * dir_dv;

float scaledAperture = 0.f;
// prescale to focal plane
if (apertureRadius > 0.f)
{
dir_du *= focusDistance;
dir_dv *= focusDistance;
dir_00 *= focusDistance;
scaledAperture = apertureRadius / imgPlane_size_x;
}

const auto clipPlaneData = clipPlanes ? clipPlanes->data : nullptr;
const size_t numClipPlanes = clipPlanes ? clipPlanes->numItems : 0;

ispc::MultiviewCamera_set(getIE(), (const ispc::vec3f&)org,
(const ispc::vec3f&)dir_00,
(const ispc::vec3f&)dir_du,
(const ispc::vec3f&)dir_dv, scaledAperture,
height, aspect, armLength,
(const ispc::vec4f*)clipPlaneData,
numClipPlanes);
}

OSP_REGISTER_CAMERA(MultiviewCamera, multiview);
}
40 changes: 40 additions & 0 deletions plugins/Multiview/ispc/multiview/MultiviewCamera.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Copyright (c) 2018, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Grigori Chevtchenko <grigori.chevtchenko@epfl.ch>
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include <ospray/SDK/camera/Camera.h>

namespace ospray
{
/**
* This is a 4 view camera. You can see from the top,
* right, front and perspective viewports.
*/
struct OSPRAY_SDK_INTERFACE MultiviewCamera : public Camera
{
MultiviewCamera();
std::string toString() const override;
void commit() override;

// Clip planes
Ref<Data> clipPlanes;
};
}
41 changes: 41 additions & 0 deletions plugins/Multiview/ispc/multiview/MultiviewCamera.ih
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* Copyright (c) 2018, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Grigori Chevtchenko <grigori.chevtchenko@epfl.ch>
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include <ospray/SDK/camera/Camera.ih>

struct MultiviewCamera
{
Camera super;

vec3f org;
vec3f dir_00;
vec3f dir_du;
vec3f dir_dv;
float scaledAperture;
float height;
float aspect;
float armLength;

// Clip planes
const uniform vec4f* clipPlanes;
unsigned int numClipPlanes;
};
Loading

0 comments on commit 0071241

Please sign in to comment.