Blue Brain BioExplorer
OpenDeckPlugin.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2024, EPFL/Blue Brain Project
3  * All rights reserved. Do not distribute without permission.
4  *
5  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
6  *
7  * This library is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License version 3.0 as published
9  * by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include "OpenDeckPlugin.h"
22 
23 #include <plugin/common/Logs.h>
24 
29 
30 #ifdef USE_OPTIX6
33 #endif
34 
35 namespace core
36 {
37 namespace
38 {
39 const std::string CAMERA_CYLINDRIC = "cylindric";
40 const std::string CAMERA_CYLINDRIC_STEREO = "cylindricStereo";
41 const std::string CAMERA_CYLINDRIC_STEREO_TRACKED = "cylindricStereoTracked";
42 
43 constexpr uint32_t openDeckWallResX = 11940u;
44 constexpr uint32_t openDeckWallResY = 3424u;
45 constexpr uint32_t openDeckFloorResX = 4096u;
46 constexpr uint32_t openDeckFloorResY = 2125u;
47 
48 constexpr char leftWallBufferName[] = "0L";
49 constexpr char rightWallBufferName[] = "0R";
50 constexpr char leftFloorBufferName[] = "1L";
51 constexpr char rightFloorBufferName[] = "1R";
52 
53 const std::string HEAD_POSITION_PROP = "headPosition";
54 const std::string HEAD_ROTATION_PROP = "headRotation";
55 
56 constexpr std::array<double, 3> HEAD_INIT_POS{{0.0, 2.0, 0.0}};
57 constexpr std::array<double, 4> HEAD_INIT_ROT{{0.0, 0.0, 0.0, 1.0}};
58 
59 Property getHeadPositionProperty()
60 {
61  Property headPosition{HEAD_POSITION_PROP, HEAD_INIT_POS};
62  headPosition.markReadOnly();
63  return headPosition;
64 }
65 
66 Property getHeadRotationProperty()
67 {
68  Property headRotation{HEAD_ROTATION_PROP, HEAD_INIT_ROT};
69  headRotation.markReadOnly();
70  return headRotation;
71 }
72 
73 Property getStereoModeProperty()
74 {
75  return {"stereoMode",
76  3, // side-by-side
77  {"None", "Left eye", "Right eye", "Side by side"},
78  {"Stereo mode"}};
79 }
80 
81 Property getInterpupillaryDistanceProperty()
82 {
83  return CAMERA_PROPERTY_INTERPUPILLARY_DISTANCE;
84 }
85 
86 Property getCameraScalingProperty(const double scaling)
87 {
88  return {PARAM_CAMERA_SCALING, scaling, {"Camera scaling"}};
89 }
90 
91 PropertyMap getCylindricStereoProperties()
92 {
93  PropertyMap properties;
94  properties.setProperty(getStereoModeProperty());
95  properties.setProperty(getInterpupillaryDistanceProperty());
96  return properties;
97 }
98 
99 PropertyMap getCylindricStereoTrackedProperties(const OpenDeckParameters& params)
100 {
101  PropertyMap properties;
102  properties.setProperty(getHeadPositionProperty());
103  properties.setProperty(getHeadRotationProperty());
104  properties.setProperty(getStereoModeProperty());
105  properties.setProperty(getInterpupillaryDistanceProperty());
106  properties.setProperty(getCameraScalingProperty(params.getCameraScaling()));
107  return properties;
108 }
109 } // namespace
110 
112  : _params(params)
113 {
114  if (_params.getResolutionScaling() > 1.0f || _params.getResolutionScaling() <= 0.0f)
115  {
116  throw std::runtime_error(
117  "The scale of the native OpenDeck resolution cannot be bigger "
118  "than 1.0, zero or negative.");
119  }
120  if (_params.getCameraScaling() <= 0.0)
121  throw std::runtime_error("The camera scale cannot be zero or negative");
122 
123  _wallRes =
124  Vector2ui(openDeckWallResX * _params.getResolutionScaling(), openDeckWallResY * _params.getResolutionScaling());
125  _floorRes = Vector2ui(openDeckFloorResX * _params.getResolutionScaling(),
126  openDeckFloorResY * _params.getResolutionScaling());
127  PLUGIN_INFO("Wall resolution : " << _wallRes << "(" << _params.getResolutionScaling() << ")");
128  PLUGIN_INFO("Floor resolution: " << _floorRes);
129 }
130 
132 {
133  auto& engine = _api->getEngine();
134  auto& params = engine.getParametersManager().getApplicationParameters();
135  const auto& engineName = params.getEngine();
136 #ifdef USE_OSPRAY
137  if (engineName == ENGINE_OSPRAY)
138  {
139  engine.addCameraType(CAMERA_CYLINDRIC);
140  engine.addCameraType(CAMERA_CYLINDRIC_STEREO, getCylindricStereoProperties());
141  engine.addCameraType(CAMERA_CYLINDRIC_STEREO_TRACKED, getCylindricStereoTrackedProperties(_params));
142  FrameBufferPtr frameBuffer = engine.createFrameBuffer(leftWallBufferName, _wallRes, FrameBufferFormat::rgba_i8);
143  engine.addFrameBuffer(frameBuffer);
144  frameBuffer = engine.createFrameBuffer(rightWallBufferName, _wallRes, FrameBufferFormat::rgba_i8);
145  engine.addFrameBuffer(frameBuffer);
146  frameBuffer = engine.createFrameBuffer(leftFloorBufferName, _floorRes, FrameBufferFormat::rgba_i8);
147  engine.addFrameBuffer(frameBuffer);
148  frameBuffer = engine.createFrameBuffer(rightFloorBufferName, _floorRes, FrameBufferFormat::rgba_i8);
149  engine.addFrameBuffer(frameBuffer);
150  }
151 #endif
152 #ifdef USE_OPTIX6
153  if (engineName == ENGINE_OPTIX_6)
154  {
156  context.addCamera(CAMERA_CYLINDRIC_STEREO, std::make_shared<core::engine::optix::OptiXCylindricStereoCamera>());
157  engine.addCameraType(CAMERA_CYLINDRIC_STEREO, getCylindricStereoProperties());
158  }
159 #endif
160 }
161 
162 extern "C" core::ExtensionPlugin* core_plugin_create(const int argc, const char** argv)
163 {
164  PLUGIN_INFO("");
165  PLUGIN_INFO(" _|_| _|_|_| _| ");
166  PLUGIN_INFO(" _| _| _|_|_| _|_| _|_|_| _| _| _|_| _|_|_| _| _| ");
167  PLUGIN_INFO(" _| _| _| _| _|_|_|_| _| _| _| _| _|_|_|_| _| _|_| ");
168  PLUGIN_INFO(" _| _| _| _| _| _| _| _| _| _| _| _| _| ");
169  PLUGIN_INFO(" _|_| _|_|_| _|_|_| _| _| _|_|_| _|_|_| _|_|_| _| _|");
170  PLUGIN_INFO(" _| ");
171  PLUGIN_INFO(" _| ");
172  PLUGIN_INFO("");
173 
175  if (!params.getPropertyMap().parse(argc, argv))
176  return nullptr;
177  try
178  {
179  return new core::OpenDeckPlugin(std::move(params));
180  }
181  catch (const std::runtime_error& exc)
182  {
183  PLUGIN_ERROR(exc.what());
184  return nullptr;
185  }
186 }
187 } // namespace core
PLATFORM_API const auto & getParametersManager() const
Returns the parameter manager.
Definition: Engine.h:210
double getResolutionScaling() const
const PropertyMap & getPropertyMap() const
OpenDeckPlugin(const OpenDeckParameters &params)
virtual Engine & getEngine()=0
bool parse(int argc, const char **argv)
void addCamera(const std::string &name, OptiXCameraProgramPtr program)
static OptiXContext & get()
std::shared_ptr< FrameBuffer > FrameBufferPtr
Definition: Types.h:100
core::ExtensionPlugin * core_plugin_create(const int argc, const char **argv)
constexpr auto PARAM_CAMERA_SCALING
glm::vec< 2, uint32_t > Vector2ui
Definition: MathTypes.h:133
#define PLUGIN_ERROR(message)
Definition: Logs.h:32
#define PLUGIN_INFO(message)
Definition: Logs.h:34