-
Notifications
You must be signed in to change notification settings - Fork 46
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
Allow use of renderers and cameras defined in external modules #310
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* Copyright (c) 2015-2017, EPFL/Blue Brain Project | ||
/* Copyright (c) 2015-2018, EPFL/Blue Brain Project | ||
* All rights reserved. Do not distribute without permission. | ||
* Responsible Author: Cyrille Favreau <cyrille.favreau@epfl.ch> | ||
* | ||
|
@@ -45,28 +45,30 @@ const std::string PARAM_DETECTION_ON_DIFFERENT_MATERIAL = | |
const std::string PARAM_DETECTION_NEAR_COLOR = "detection-near-color"; | ||
const std::string PARAM_DETECTION_FAR_COLOR = "detection-far-color"; | ||
const std::string PARAM_EPSILON = "epsilon"; | ||
const std::string PARAM_CAMERA_TYPE = "camera-type"; | ||
const std::string PARAM_CAMERA = "camera"; | ||
const std::string PARAM_HEAD_LIGHT = "head-light"; | ||
const std::string PARAM_VARIANCE_THRESHOLD = "variance-threshold"; | ||
|
||
const std::string ENGINES[2] = {"ospray", "optix"}; | ||
const std::string RENDERERS[7] = {"basic", | ||
const std::string RENDERERS[7] = {"default", | ||
"proximity", | ||
"simulation", | ||
"particle", | ||
"geometrynormals", | ||
"shadingnormals", | ||
"scientificvisualization"}; | ||
const std::string RENDERER_NAMES[7] = {"basic", | ||
"proximityrenderer", | ||
"simulationrenderer", | ||
"particlerenderer", | ||
"raycast_Ng", | ||
"raycast_Ns", | ||
"scivis"}; | ||
|
||
const std::string CAMERA_TYPES[5] = {"perspective", "stereo", "orthographic", | ||
"panoramic", "clipped"}; | ||
const std::string RENDERER_INTERNAL_NAMES[7] = {"basic", | ||
"proximityrenderer", | ||
"simulationrenderer", | ||
"particlerenderer", | ||
"raycast_Ng", | ||
"raycast_Ns", | ||
"scivis"}; | ||
|
||
const std::string CAMERA_TYPE_NAMES[5] = {"perspective", "stereo", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the JSON name also has to change to default, no? for both, camera and renderer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's already done in the jsonSerialization.h file. CAMERA_TYPE_NAMES defines the internal 'ospray' name of the camera, not the one that is exposed in JSON. |
||
"orthographic", "panoramic", | ||
"clipped"}; | ||
|
||
const std::string SHADING_TYPES[3] = {"none", "diffuse", "electron"}; | ||
} | ||
|
@@ -76,7 +78,7 @@ namespace brayns | |
RenderingParameters::RenderingParameters() | ||
: AbstractParameters("Rendering") | ||
, _engine(EngineType::ospray) | ||
, _renderer(RendererType::basic) | ||
, _renderer(RendererType::default_) | ||
, _ambientOcclusionStrength(0.f) | ||
, _ambientOcclusionDistance(1.20f) | ||
, _shading(ShadingType::diffuse) | ||
|
@@ -90,15 +92,15 @@ RenderingParameters::RenderingParameters() | |
, _detectionNearColor(1.f, 0.f, 0.f) | ||
, _detectionFarColor(0.f, 1.f, 0.f) | ||
, _epsilon(0.f) | ||
, _cameraType(CameraType::perspective) | ||
, _cameraType(CameraType::default_) | ||
, _headLight(false) | ||
{ | ||
_parameters.add_options()(PARAM_ENGINE.c_str(), po::value<std::string>(), | ||
"Engine name [ospray|optix]")( | ||
PARAM_MODULE.c_str(), po::value<std::string>(), | ||
"OSPRay module name [string]")( | ||
PARAM_RENDERER.c_str(), po::value<std::string>(), | ||
"OSPRay active renderer [basic|simulation|proximity|particle]")( | ||
"OSPRay active renderer [default|simulation|proximity|particle]")( | ||
PARAM_SPP.c_str(), po::value<size_t>(), | ||
"Number of samples per pixel [int]")( | ||
PARAM_ACCUMULATION.c_str(), po::value<bool>(), | ||
|
@@ -128,15 +130,27 @@ RenderingParameters::RenderingParameters() | |
PARAM_EPSILON.c_str(), po::value<float>(), | ||
"All intersection distances less than the " | ||
"epsilon value are ignored by the ray-tracer [float]")( | ||
PARAM_CAMERA_TYPE.c_str(), po::value<std::string>(), | ||
"Camera type [perspective|stereo|orthographic|panoramic]")( | ||
PARAM_CAMERA.c_str(), po::value<std::string>(), | ||
"Camera [perspective|stereo|orthographic|panoramic]")( | ||
PARAM_HEAD_LIGHT.c_str(), po::value<bool>(), | ||
"Enable/Disable light source attached to camera origin [bool]")( | ||
PARAM_VARIANCE_THRESHOLD.c_str(), po::value<float>(), | ||
"Threshold for adaptive accumulation [float]"); | ||
|
||
// Add default renderers | ||
_renderers.push_back(RendererType::basic); | ||
initializeDefaultRenderers(); | ||
initializeDefaultCameras(); | ||
} | ||
|
||
void RenderingParameters::initializeDefaultRenderers() | ||
{ | ||
_rendererNames.clear(); | ||
for (size_t i = 0; i < sizeof(RENDERER_INTERNAL_NAMES) / | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just _rendererNames{internal, internal+size} in ctor list |
||
sizeof(RENDERER_INTERNAL_NAMES[0]); | ||
++i) | ||
_rendererNames.push_back(RENDERER_INTERNAL_NAMES[i]); | ||
|
||
_renderers.clear(); | ||
_renderers.push_back(RendererType::default_); | ||
_renderers.push_back(RendererType::simulation); | ||
_renderers.push_back(RendererType::particle); | ||
_renderers.push_back(RendererType::proximity); | ||
|
@@ -145,6 +159,14 @@ RenderingParameters::RenderingParameters() | |
_renderers.push_back(RendererType::scientificvisualization); | ||
} | ||
|
||
void RenderingParameters::initializeDefaultCameras() | ||
{ | ||
_cameraTypeNames.clear(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as for renderers, just init list |
||
for (size_t i = 0; | ||
i < sizeof(CAMERA_TYPE_NAMES) / sizeof(CAMERA_TYPE_NAMES[0]); ++i) | ||
_cameraTypeNames.push_back(CAMERA_TYPE_NAMES[i]); | ||
} | ||
|
||
bool RenderingParameters::_parse(const po::variables_map& vm) | ||
{ | ||
if (vm.count(PARAM_ENGINE)) | ||
|
@@ -159,11 +181,21 @@ bool RenderingParameters::_parse(const po::variables_map& vm) | |
_module = vm[PARAM_MODULE].as<std::string>(); | ||
if (vm.count(PARAM_RENDERER)) | ||
{ | ||
_renderer = RendererType::basic; | ||
_renderer = RendererType::default_; | ||
bool found = false; | ||
const std::string& renderer = vm[PARAM_RENDERER].as<std::string>(); | ||
for (size_t i = 0; i < sizeof(RENDERERS) / sizeof(RENDERERS[0]); ++i) | ||
if (renderer == RENDERERS[i]) | ||
for (size_t i = 0; !found && i < _rendererNames.size(); ++i) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or shorter: found = std.find() == end() |
||
if (renderer == _rendererNames[i]) | ||
{ | ||
_renderer = static_cast<RendererType>(i); | ||
found = true; | ||
} | ||
if (!found) | ||
{ | ||
BRAYNS_INFO << "'" << renderer << "' replaces default renderer" | ||
<< std::endl; | ||
_rendererNames[0] = renderer; | ||
} | ||
} | ||
if (vm.count(PARAM_SPP)) | ||
_spp = vm[PARAM_SPP].as<size_t>(); | ||
|
@@ -212,14 +244,23 @@ bool RenderingParameters::_parse(const po::variables_map& vm) | |
} | ||
if (vm.count(PARAM_EPSILON)) | ||
_epsilon = vm[PARAM_EPSILON].as<float>(); | ||
if (vm.count(PARAM_CAMERA_TYPE)) | ||
if (vm.count(PARAM_CAMERA)) | ||
{ | ||
_cameraType = CameraType::perspective; | ||
const std::string& cameraType = vm[PARAM_CAMERA_TYPE].as<std::string>(); | ||
for (size_t i = 0; i < sizeof(CAMERA_TYPES) / sizeof(CAMERA_TYPES[0]); | ||
++i) | ||
if (cameraType == CAMERA_TYPES[i]) | ||
_cameraType = CameraType::default_; | ||
const std::string& cameraTypeName = vm[PARAM_CAMERA].as<std::string>(); | ||
bool found = false; | ||
for (size_t i = 0; !found && i < _cameraTypeNames.size(); ++i) | ||
if (cameraTypeName == _cameraTypeNames[i]) | ||
{ | ||
_cameraType = static_cast<CameraType>(i); | ||
found = true; | ||
} | ||
if (!found) | ||
{ | ||
BRAYNS_INFO << "'" << cameraTypeName << "' replaces default camera" | ||
<< std::endl; | ||
_cameraTypeNames[0] = cameraTypeName; | ||
} | ||
} | ||
if (vm.count(PARAM_HEAD_LIGHT)) | ||
_headLight = vm[PARAM_HEAD_LIGHT].as<bool>(); | ||
|
@@ -286,13 +327,13 @@ const std::string& RenderingParameters::getRendererAsString( | |
const std::string& RenderingParameters::getRendererNameAsString( | ||
const RendererType value) const | ||
{ | ||
return RENDERER_NAMES[static_cast<size_t>(value)]; | ||
return _rendererNames[static_cast<size_t>(value)]; | ||
} | ||
|
||
const std::string& RenderingParameters::getCameraTypeAsString( | ||
const CameraType value) const | ||
{ | ||
return CAMERA_TYPES[static_cast<size_t>(value)]; | ||
return _cameraTypeNames[static_cast<size_t>(value)]; | ||
} | ||
|
||
const std::string& RenderingParameters::getShadingAsString( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,33 +21,29 @@ | |
#include "OSPRayCamera.h" | ||
|
||
#include <brayns/common/log.h> | ||
#include <brayns/parameters/ParametersManager.h> | ||
|
||
#include <ospray/SDK/common/OSPCommon.h> | ||
|
||
namespace brayns | ||
{ | ||
OSPRayCamera::OSPRayCamera(const CameraType cameraType) | ||
: Camera(cameraType) | ||
OSPRayCamera::OSPRayCamera(ParametersManager& parametersManager) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const& at least. still quite ugly that a engine-specific camera needs full access to all parameters... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can restrict it to renderingParameters instead. Does this looks better to you? Or same... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, cannot be const because it can be reinitialized by the camera |
||
: Camera(parametersManager.getRenderingParameters().getCameraType()) | ||
{ | ||
std::string cameraAsString; | ||
switch (getType()) | ||
auto& rp = parametersManager.getRenderingParameters(); | ||
auto cameraTypeAsString = rp.getCameraTypeAsString(getType()); | ||
_camera = ospNewCamera(cameraTypeAsString.c_str()); | ||
if (!_camera) | ||
{ | ||
case CameraType::stereo: | ||
cameraAsString = "stereo"; | ||
break; | ||
case CameraType::orthographic: | ||
cameraAsString = "orthographic"; | ||
break; | ||
case CameraType::panoramic: | ||
cameraAsString = "panoramic"; | ||
break; | ||
case CameraType::clipped: | ||
cameraAsString = "clippedperspective"; | ||
break; | ||
default: | ||
cameraAsString = "perspective"; | ||
break; | ||
BRAYNS_WARN | ||
<< "'" << cameraTypeAsString << "'" | ||
<< " is not a registered camera, using default camera instead" | ||
<< std::endl; | ||
rp.initializeDefaultCameras(); | ||
cameraTypeAsString = rp.getCameraTypeAsString(CameraType::default_); | ||
_camera = ospNewCamera(cameraTypeAsString.c_str()); | ||
} | ||
_camera = ospNewCamera(cameraAsString.c_str()); | ||
assert(_camera); | ||
} | ||
|
||
OSPRayCamera::~OSPRayCamera() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,21 @@ OSPRayRenderer::OSPRayRenderer(const std::string& name, | |
: Renderer(parametersManager) | ||
, _name(name) | ||
, _camera(0) | ||
, _renderer(0) | ||
{ | ||
_renderer = ospNewRenderer(name.c_str()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to init list directly |
||
if (!_renderer) | ||
{ | ||
BRAYNS_WARN | ||
<< "'" << name << "'" | ||
<< " is not a registered renderer, using default renderer instead" | ||
<< std::endl; | ||
auto& rp = parametersManager.getRenderingParameters(); | ||
rp.initializeDefaultRenderers(); | ||
const auto& defaultRenderer = | ||
rp.getRendererNameAsString(RendererType::default_); | ||
_renderer = ospNewRenderer(defaultRenderer.c_str()); | ||
} | ||
assert(_renderer); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std.array instead, in case you need .size()