Blue Brain BioExplorer
Engine.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  *
4  * The Blue Brain BioExplorer is a tool for scientists to extract and analyse
5  * scientific data from visualization
6  *
7  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License version 3.0 as published
11  * by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #pragma once
24 
29 
30 #include <functional>
31 
32 namespace core
33 {
58 class Engine
59 {
60 public:
65  PLATFORM_API virtual void commit();
66 
70  PLATFORM_API virtual void preRender();
71 
75  PLATFORM_API virtual void postRender();
76 
83 
93  PLATFORM_API virtual FrameBufferPtr createFrameBuffer(const std::string& name, const Vector2ui& frameSize,
94  FrameBufferFormat frameBufferFormat) const = 0;
95 
105  PLATFORM_API virtual ScenePtr createScene(AnimationParameters& animationParameters,
106  GeometryParameters& geometryParameters,
107  VolumeParameters& volumeParameters,
108  FieldParameters& fieldParameters) const = 0;
109 
115  PLATFORM_API virtual CameraPtr createCamera() const = 0;
116 
125  PLATFORM_API virtual RendererPtr createRenderer(const AnimationParameters& animationParameters,
126  const RenderingParameters& renderingParameters) const = 0;
127 
133  PLATFORM_API explicit Engine(ParametersManager& parametersManager);
134 
135  PLATFORM_API virtual ~Engine() = default;
136 
140  PLATFORM_API void render();
141 
148 
155 
161  PLATFORM_API const Camera& getCamera() const { return *_camera; }
163 
170 
174  PLATFORM_API std::function<void()> triggerRender{[] {}};
175 
181  PLATFORM_API void setKeepRunning(bool keepRunning) { _keepRunning = keepRunning; }
182 
188  PLATFORM_API bool getKeepRunning() const { return _keepRunning; }
189 
196 
203  PLATFORM_API bool continueRendering() const;
204 
210  PLATFORM_API const auto& getParametersManager() const { return _parametersManager; }
211 
217  PLATFORM_API void addFrameBuffer(FrameBufferPtr frameBuffer);
218 
225 
231  PLATFORM_API const std::vector<FrameBufferPtr>& getFrameBuffers() const { return _frameBuffers; }
232 
237 
242 
249  PLATFORM_API void setRendererType(const std::string& name) { _rendererType = name; }
250 
257  PLATFORM_API void addRendererType(const std::string& name, const PropertyMap& properties = {});
258 
265 
272  PLATFORM_API void addCameraType(const std::string& name, const PropertyMap& properties = {});
273 
274 protected:
275  std::string _rendererType{RENDERER_PROPERTY_TYPE_BASIC};
280  std::vector<FrameBufferPtr> _frameBuffers;
283  bool _keepRunning{true};
284 };
285 } // namespace core
#define PLATFORM_API
Definition: Api.h:37
The Camera class is an abstract interface for a camera in a 3D graphics application....
Definition: Camera.h:41
Provides an abstract implementation of a ray-tracing engine.
Definition: Engine.h:59
PLATFORM_API bool getKeepRunning() const
Returns a boolean indicating whether the user wants to continue rendering.
Definition: Engine.h:188
PLATFORM_API void removeFrameBuffer(FrameBufferPtr frameBuffer)
Removes a frame buffer from the list of buffers that are filled during rendering.
Definition: Engine.cpp:89
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 void addRendererType(const std::string &name, const PropertyMap &properties={})
Adds a new renderer type with optional properties.
Definition: Engine.cpp:106
PLATFORM_API FrameBuffer & getFrameBuffer()
Returns the frame buffer.
Definition: Engine.h:154
Statistics _statistics
Definition: Engine.h:281
PLATFORM_API const auto & getParametersManager() const
Returns the parameter manager.
Definition: Engine.h:210
std::vector< FrameBufferPtr > _frameBuffers
Definition: Engine.h:280
PLATFORM_API bool continueRendering() const
Returns a boolean indicating whether render calls shall be continued based on current accumulation se...
Definition: Engine.cpp:77
ParametersManager & _parametersManager
Definition: Engine.h:276
virtual PLATFORM_API ScenePtr createScene(AnimationParameters &animationParameters, GeometryParameters &geometryParameters, VolumeParameters &volumeParameters, FieldParameters &fieldParameters) const =0
Factory method to create an engine-specific scene.
ScenePtr _scene
Definition: Engine.h:277
PLATFORM_API const std::vector< FrameBufferPtr > & getFrameBuffers() const
Returns all registered frame buffers that are used during rendering.
Definition: Engine.h:231
PLATFORM_API Renderer & getRenderer()
Returns the renderer.
Definition: Engine.cpp:72
PLATFORM_API std::function< void()> triggerRender
Callback when a new frame shall be triggered. Currently called by event plugins Deflect and Rockets.
Definition: Engine.h:174
PLATFORM_API Statistics & getStatistics()
Returns statistics information.
Definition: Engine.h:195
virtual PLATFORM_API void commit()
Commits changes to the engine. This includes scene modifications, camera modifications and renderer m...
Definition: Engine.cpp:41
std::string _rendererType
Definition: Engine.h:275
PLATFORM_API Scene & getScene()
Returns the scene.
Definition: Engine.h:147
PLATFORM_API Camera & getCamera()
Definition: Engine.h:162
virtual PLATFORM_API void preRender()
Executes engine-specific pre-render operations.
Definition: Engine.cpp:46
PLATFORM_API void clearFrameBuffers()
Clears all frame buffers.
Definition: Engine.cpp:94
virtual PLATFORM_API RendererPtr createRenderer(const AnimationParameters &animationParameters, const RenderingParameters &renderingParameters) const =0
Factory method to create an engine-specific renderer.
PLATFORM_API void render()
Renders the current scene and populates the frame buffer accordingly.
Definition: Engine.cpp:55
PLATFORM_API const strings & getRendererTypes() const
Returns all renderer types.
Definition: Engine.h:264
virtual PLATFORM_API ~Engine()=default
RendererPtr _renderer
Definition: Engine.h:279
PLATFORM_API void addFrameBuffer(FrameBufferPtr frameBuffer)
Adds a frame buffer to the list to be filled during rendering.
Definition: Engine.cpp:84
virtual PLATFORM_API CameraPtr createCamera() const =0
Factory method to create an engine-specific camera.
PLATFORM_API void setKeepRunning(bool keepRunning)
Sets a flag to continue or stop rendering.
Definition: Engine.h:181
virtual PLATFORM_API void postRender()
Executes engine-specific post-render operations.
Definition: Engine.cpp:66
PLATFORM_API void addCameraType(const std::string &name, const PropertyMap &properties={})
Adds a new camera type with optional properties.
Definition: Engine.cpp:113
strings _rendererTypes
Definition: Engine.h:282
PLATFORM_API void resetFrameBuffers()
Resets all frame buffers.
Definition: Engine.cpp:100
PLATFORM_API void setRendererType(const std::string &name)
Adds a new renderer type with optional properties.
Definition: Engine.h:249
CameraPtr _camera
Definition: Engine.h:278
PLATFORM_API const Camera & getCamera() const
Returns the camera.
Definition: Engine.h:161
bool _keepRunning
Definition: Engine.h:283
PLATFORM_API Engine(ParametersManager &parametersManager)
Engine Constructor.
Definition: Engine.cpp:36
virtual PLATFORM_API Vector2ui getMinimumFrameSize() const =0
Returns the minimum frame size in pixels supported by this engine.
This class represents a frame buffer for an engine specific code. It provides an API for utilizing an...
Definition: FrameBuffer.h:39
Renderer class inherits from PropertyObject class The Renderer class has methods to render a FrameBuf...
Definition: Renderer.h:42
Scene object This object contains collections of geometries, materials and light sources that are use...
Definition: Scene.h:43
std::shared_ptr< Camera > CameraPtr
Definition: Types.h:93
std::shared_ptr< Renderer > RendererPtr
Definition: Types.h:97
std::shared_ptr< FrameBuffer > FrameBufferPtr
Definition: Types.h:100
std::shared_ptr< Scene > ScenePtr
Definition: Types.h:88
FrameBufferFormat
Definition: Types.h:205
glm::vec< 2, uint32_t > Vector2ui
Definition: MathTypes.h:133
std::vector< std::string > strings
Definition: Types.h:44