52 #if PLATFORM_USE_LIBARCHIVE
70 const float DEFAULT_MOTION_ACCELERATION = 1.5f;
74 constexpr
double DEFAULT_SUN_ANGULAR_DIAMETER = 0.53;
75 constexpr
double DEFAULT_SUN_INTENSITY = 1.0;
82 Impl(
int argc,
const char** argv)
83 : _parametersManager{argc, argv}
84 , _engineFactory{argc, argv, _parametersManager}
85 , _pluginManager{argc, argv}
97 _registerKeyboardShortcuts();
105 _createFrameBuffer();
124 std::unique_lock<std::mutex> lock{_renderMutex, std::defer_lock};
125 if (!lock.try_lock())
137 if (renderer.getHeadLight() && (camera.isModified() || rp.isModified()))
139 const auto newDirection = glm::rotate(camera.getOrientation(),
Vector3d(0, 0, -1));
140 _sunLight->_direction = newDirection;
141 lightManager.addLight(_sunLight);
152 if (camera.hasProperty(CAMERA_PROPERTY_ASPECT_RATIO.name))
153 camera.updateProperty(CAMERA_PROPERTY_ASPECT_RATIO.name,
154 static_cast<double>(windowSize.x) /
static_cast<double>(windowSize.y));
156 for (
auto frameBuffer : _frameBuffers)
157 frameBuffer->resize(windowSize);
165 if (_parametersManager.
isAnyModified() || camera.isModified() || scene.isModified() || renderer.isModified() ||
166 lightManager.isModified())
170 camera.resetModified();
171 scene.resetModified();
172 renderer.resetModified();
173 lightManager.resetModified();
180 std::lock_guard<std::mutex> lock{_renderMutex};
182 _renderTimer.
start();
189 const auto delta = _lastFPS - fps;
192 const int64_t targetTime = (1. / fps) * 1000.f;
193 std::this_thread::sleep_for(std::chrono::milliseconds(targetTime - _renderTimer.
milliseconds()));
228 const size_t size = frameSize.x * frameSize.y * frameBuffer.
getColorDepth();
229 renderOutput.
colorBuffer.assign(colorBuffer, colorBuffer + size);
236 size_t size = frameSize.x * frameSize.y;
238 size *=
sizeof(float);
239 renderOutput.
floatBuffer.assign(floatBuffer, floatBuffer + size);
263 _engine = _engineFactory.
create(engineName);
266 _sunLight = std::make_shared<DirectionalLight>(DEFAULT_SUN_DIRECTION, DEFAULT_SUN_ANGULAR_DIAMETER,
267 DEFAULT_SUN_COLOR, DEFAULT_SUN_INTENSITY,
false);
273 void _createFrameBuffer()
280 for (
const auto& name : names)
281 _addFrameBuffer(name);
284 void _addFrameBuffer(
const std::string& name)
291 _frameBuffers.push_back(frameBuffer);
294 void _registerLoaders()
301 registry.registerLoader(std::make_unique<RawVolumeLoader>(scene));
302 registry.registerLoader(std::make_unique<MHDVolumeLoader>(scene));
303 registry.registerLoader(std::make_unique<XYZBLoader>(scene));
305 registry.registerLoader(std::make_unique<MeshLoader>(scene, params));
307 #if PLATFORM_USE_LIBARCHIVE
308 registry.registerArchiveLoader(std::make_unique<ArchiveLoader>(scene, registry));
320 if (paths.size() == 1 && paths[0] ==
"demo")
326 for (
const auto& path : paths)
327 if (!registry.isSupportedFile(path))
328 throw std::runtime_error(
"No loader found for '" + path +
"'");
330 for (
const auto& path : paths)
332 int percentageLast = 0;
334 auto timeLast = std::chrono::steady_clock::now();
338 auto progress = [&](
const std::string& msg,
float t)
340 constexpr
auto MIN_SECS = 5;
341 constexpr
auto MIN_PERCENTAGE = 10;
343 t = std::max(0.f, std::min(t, 1.f));
344 const int percentage =
static_cast<int>(100.0f * t);
345 const auto time = std::chrono::steady_clock::now();
346 const auto secondsElapsed =
347 std::chrono::duration_cast<std::chrono::seconds>(time - timeLast).count();
348 const auto percentageElapsed = percentage - percentageLast;
350 if ((secondsElapsed >= MIN_SECS && percentageElapsed > 0) || msgLast != msg ||
351 (percentageElapsed >= MIN_PERCENTAGE))
353 std::string p = std::to_string(percentage);
354 p.insert(p.begin(), 3 - p.size(),
' ');
358 percentageLast = percentage;
364 ModelParams params(path, path, {});
365 scene.loadModel(path, params, {progress});
369 scene.markModified();
372 void _setupCameraManipulator(
const CameraMode mode,
const bool adjust =
true)
374 _cameraManipulator.reset();
379 _cameraManipulator.reset(
new FlyingModeManipulator(_engine->
getCamera(), _keyboardHandler));
382 _cameraManipulator.reset(
new InspectCenterManipulator(_engine->
getCamera(), _keyboardHandler));
390 void _registerKeyboardShortcuts()
393 std::bind(&Core::Impl::_decreaseAnimationFrame,
this));
395 std::bind(&Core::Impl::_increaseAnimationFrame,
this));
403 std::bind(&Core::Impl::_resetAnimationFrame,
this));
405 std::bind(&Core::Impl::_toggleAnimationPlayback,
this));
407 std::bind(&Core::Impl::_resetCamera,
this));
409 std::bind(&Core::Impl::_increaseMotionSpeed,
this));
411 std::bind(&Core::Impl::_decreaseMotionSpeed,
this));
413 std::bind(&Core::Impl::_displayCameraInformation,
this));
426 void _resetAnimationFrame()
438 const auto& bounds = scene.getBounds();
440 const auto size = bounds.getSize();
441 const double diag = 1.6 * std::max(std::max(size.x, size.y), size.z);
442 camera.setPosition(bounds.getCenter() +
Vector3d(0.0, 0.0, diag));
443 camera.setTarget(bounds.getCenter());
447 void _increaseMotionSpeed() { _cameraManipulator->updateMotionSpeed(DEFAULT_MOTION_ACCELERATION); }
449 void _decreaseMotionSpeed() { _cameraManipulator->updateMotionSpeed(1.f / DEFAULT_MOTION_ACCELERATION); }
453 ParametersManager _parametersManager;
454 EngineFactory _engineFactory;
455 PluginManager _pluginManager;
456 Engine* _engine{
nullptr};
457 KeyboardHandler _keyboardHandler;
458 std::unique_ptr<AbstractManipulator> _cameraManipulator;
459 std::vector<FrameBufferPtr> _frameBuffers;
462 std::mutex _renderMutex;
465 std::atomic<double> _lastFPS;
467 std::shared_ptr<ActionInterface> _actionInterface;
468 std::shared_ptr<DirectionalLight> _sunLight;
474 : _impl(std::make_unique<
Impl>(argc, argv))
481 if (_impl->commit(renderInput))
484 _impl->postRender(&renderOutput);
493 _impl->postRender(
nullptr);
495 return _impl->getEngine().getKeepRunning();
500 return _impl->commit();
504 return _impl->render();
508 _impl->postRender(
nullptr);
512 return _impl->getEngine();
516 return _impl->getParametersManager();
521 return _impl->getKeyboardHandler();
526 return _impl->getCameraManipulator();
void jumpFrames(int frames)
void setFrame(uint32_t value)
void setBenchmarking(bool enabled)
const strings & getInputPaths() const
const std::string & getEnvMap() const
size_t getMaxRenderFPS() const
void setWindowSize(const Vector2ui &size)
const std::string & getEngine() const
const Vector2ui getWindowSize() const
The Camera class is an abstract interface for a camera in a 3D graphics application....
PLATFORM_API void set(const Vector3d &position, const Quaterniond &orientation, const Vector3d &target=Vector3d(0.0, 0.0, 0.0))
Sets the position, orientation quaternion, and target of the camera.
PLATFORM_API Engine & getEngine()
PLATFORM_API void render()
PLATFORM_API Core(int argc, const char **argv)
PLATFORM_API void postRender()
PLATFORM_API AbstractManipulator & getCameraManipulator()
PLATFORM_API bool commitAndRender()
PLATFORM_API ParametersManager & getParametersManager()
PLATFORM_API KeyboardHandler & getKeyboardHandler()
PLATFORM_API bool commit()
Engine * create(const std::string &name)
Create an instance of the engine corresponding the given name. If the name is incorrect,...
Provides an abstract implementation of a ray-tracing engine.
virtual PLATFORM_API FrameBufferPtr createFrameBuffer(const std::string &name, const Vector2ui &frameSize, FrameBufferFormat frameBufferFormat) const =0
Factory method to create an engine-specific framebuffer.
PLATFORM_API FrameBuffer & getFrameBuffer()
Returns the frame buffer.
PLATFORM_API const std::vector< FrameBufferPtr > & getFrameBuffers() const
Returns all registered frame buffers that are used during rendering.
PLATFORM_API Renderer & getRenderer()
Returns the renderer.
PLATFORM_API std::function< void()> triggerRender
Callback when a new frame shall be triggered. Currently called by event plugins Deflect and Rockets.
PLATFORM_API Statistics & getStatistics()
Returns statistics information.
virtual PLATFORM_API void commit()
Commits changes to the engine. This includes scene modifications, camera modifications and renderer m...
PLATFORM_API Scene & getScene()
Returns the scene.
virtual PLATFORM_API void preRender()
Executes engine-specific pre-render operations.
PLATFORM_API void clearFrameBuffers()
Clears all frame buffers.
PLATFORM_API void render()
Renders the current scene and populates the frame buffer accordingly.
PLATFORM_API void addFrameBuffer(FrameBufferPtr frameBuffer)
Adds a frame buffer to the list to be filled during rendering.
virtual PLATFORM_API void postRender()
Executes engine-specific post-render operations.
PLATFORM_API void resetFrameBuffers()
Resets all frame buffers.
PLATFORM_API const Camera & getCamera() const
Returns the camera.
This class represents a frame buffer for an engine specific code. It provides an API for utilizing an...
PLATFORM_API FrameBufferFormat getFrameBufferFormat() const
Get the Frame Buffer Format object.
virtual PLATFORM_API const uint8_t * getColorBuffer() const =0
Get the Color Buffer object.
virtual PLATFORM_API void map()=0
Map the buffer for reading with get*Buffer().
PLATFORM_API size_t getColorDepth() const
Get the Color Depth object.
virtual PLATFORM_API Vector2ui getSize() const
Get the Size object.
virtual PLATFORM_API const float * getFloatBuffer() const =0
Get the Float Buffer object.
PLATFORM_API AccumulationType getAccumulationType() const
Get the Accumulation Type object.
virtual PLATFORM_API void unmap()=0
Unmap the buffer for reading with get*Buffer().
The KeyboardHandler class manages keyboard shortcuts and special keys.
void registerKeyboardShortcut(const unsigned char key, const std::string &description, std::function< void()> functor)
Registers a keyboard shortcut.
PLATFORM_API size_t addLight(LightPtr light)
addLight Attaches a light source to the scene.
PLATFORM_API GeometryParameters & getGeometryParameters()
PLATFORM_API ApplicationParameters & getApplicationParameters()
PLATFORM_API AnimationParameters & getAnimationParameters()
PLATFORM_API RenderingParameters & getRenderingParameters()
bool isAnyModified() const
void initPlugins(PluginAPI *api)
void setCurrentType(const std::string &type)
Renderer class inherits from PropertyObject class The Renderer class has methods to render a FrameBuf...
const std::string & getCurrentCamera() const
Scene object This object contains collections of geometries, materials and light sources that are use...
PLATFORM_API void computeBounds()
Compute the bounds of the geometry handled by the scene.
PLATFORM_API const Boxd & getBounds() const
Returns the bounding box of the scene.
virtual PLATFORM_API void commit()
Called after scene-related changes have been made before rendering the scene.
PLATFORM_API void buildDefault()
Builds a default scene made of a Cornell box, a reflective cube, and a transparent sphere.
PLATFORM_API LoaderRegistry & getLoaderRegistry()
Get the registry for all supported loaders of this scene.
PLATFORM_API LightManager & getLightManager()
Gets the light manager.
void setFPS(const double fps)
void setSceneSizeInBytes(const size_t sceneSizeInBytes)
double perSecondSmoothed() const
int64_t milliseconds() const
Quaterniond safeQuatlookAt(const Vector3d &v)
glm::vec< 2, int32_t > Vector2i
glm::vec< 3, double > Vector3d
std::shared_ptr< ActionInterface > ActionInterfacePtr
void _updateRenderOutput(RenderOutput &renderOutput)
ActionInterface * getActionInterface() final
bool commit(const RenderInput &renderInput)
KeyboardHandler & getKeyboardHandler() final
void triggerRender() final
Renderer & getRenderer() final
Impl(int argc, const char **argv)
ParametersManager & getParametersManager() final
void setActionInterface(const ActionInterfacePtr &interface) final
AbstractManipulator & getCameraManipulator() final
void postRender(RenderOutput *output)
Camera & getCamera() final
Engine & getEngine() final
FrameBufferFormat colorBufferFormat