Blue Brain BioExplorer
Scene.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 
30 
31 #include <shared_mutex>
32 
34 
35 namespace core
36 {
42 class Scene : public BaseObject
43 {
44 public:
48  PLATFORM_API virtual void commit();
49 
54  PLATFORM_API virtual bool commitLights() = 0;
55 
59  PLATFORM_API virtual ModelPtr createModel() const = 0;
60 
64  PLATFORM_API Scene(AnimationParameters& animationParameters, GeometryParameters& geometryParameters,
65  VolumeParameters& volumeParameters, FieldParameters& fieldParameters);
69  PLATFORM_API const Boxd& getBounds() const { return _bounds; }
70 
75 
83 
90  PLATFORM_API bool removeModel(const size_t id);
97 
103  PLATFORM_API ModelDescriptorPtr getModel(const size_t id) const;
104 
108  PLATFORM_API void buildDefault();
109 
114  PLATFORM_API bool empty() const;
115 
121  PLATFORM_API size_t addClipPlane(const Plane& plane);
122 
128  PLATFORM_API ClipPlanePtr getClipPlane(const size_t id) const;
129 
134  PLATFORM_API void removeClipPlane(const size_t id);
135 
142 
147  PLATFORM_API size_t getSizeInBytes() const;
148 
153  PLATFORM_API size_t getNumModels() const;
154 
160 
166  PLATFORM_API bool setEnvironmentMap(const std::string& envMap);
167 
172  PLATFORM_API const std::string& getEnvironmentMap() const { return _environmentMap; }
173 
178  PLATFORM_API bool hasEnvironmentMap() const;
179 
185 
194 
202  PLATFORM_API ModelDescriptorPtr loadModel(const std::string& path, const ModelParams& params, LoaderProgress cb);
203 
208  PLATFORM_API void visitModels(const std::function<void(Model&)>& functor);
209 
215 
217  PLATFORM_API auto acquireReadAccess() const { return std::shared_lock<std::shared_timed_mutex>(_modelMutex); }
218 
223  PLATFORM_API void copyFrom(const Scene& rhs);
224 
229 
230 protected:
235  virtual bool supportsConcurrentSceneUpdates() const { return false; }
236 
237  void _loadIBLMaps(const std::string& envMap);
238 
244  std::string _environmentMap;
245 
246  size_t _modelID{0};
248  mutable std::shared_timed_mutex _modelMutex;
249 
252 
255 
256 private:
258 };
259 } // namespace core
#define PLATFORM_API
Definition: Api.h:37
#define SERIALIZATION_FRIEND(type)
Definition: Macros.h:32
#define SERIALIZATION_ACCESS(type)
Definition: Macros.h:25
Manages light sources in a scene.
Definition: LightManager.h:41
The ModelParams class represents the parameters needed for initializing a model instance.
Definition: Model.h:178
The abstract Model class holds the geometry attached to an asset of the scene (mesh,...
Definition: Model.h:469
Scene object This object contains collections of geometries, materials and light sources that are use...
Definition: Scene.h:43
ModelDescriptors _modelDescriptors
Definition: Scene.h:247
ClipPlanes _clipPlanes
Definition: Scene.h:251
PLATFORM_API size_t addModel(ModelDescriptorPtr model)
Adds a model to the scene.
Definition: Scene.cpp:116
virtual PLATFORM_API ModelPtr createModel() const =0
Factory method to create an engine-specific model.
PLATFORM_API bool setEnvironmentMap(const std::string &envMap)
Set a new environment map as the background image.
Definition: Scene.cpp:392
PLATFORM_API void computeBounds()
Compute the bounds of the geometry handled by the scene.
Definition: Scene.cpp:427
PLATFORM_API MaterialPtr getBackgroundMaterial() const
Get the background material.
Definition: Scene.h:184
std::shared_timed_mutex _modelMutex
Definition: Scene.h:248
PLATFORM_API size_t getNumModels() const
Get the current number of models in the scene.
Definition: Scene.cpp:110
size_t _modelID
Definition: Scene.h:246
PLATFORM_API ModelDescriptorPtr loadModel(Blob &&blob, const ModelParams &params, LoaderProgress cb)
Load a model from the given blob.
Definition: Scene.cpp:214
LoaderRegistry _loaderRegistry
Definition: Scene.h:253
PLATFORM_API size_t getSizeInBytes() const
Get the current size in bytes of the loaded geometry.
Definition: Scene.cpp:101
PLATFORM_API size_t addClipPlane(const Plane &plane)
Add a clip plane to the scene.
Definition: Scene.cpp:194
PLATFORM_API const Boxd & getBounds() const
Returns the bounding box of the scene.
Definition: Scene.h:69
GeometryParameters & _geometryParameters
Definition: Scene.h:240
std::string _environmentMap
Definition: Scene.h:244
PLATFORM_API const ClipPlanes & getClipPlanes() const
Get all clip planes in the scene.
Definition: Scene.h:141
Boxd _bounds
Definition: Scene.h:254
virtual PLATFORM_API void commit()
Called after scene-related changes have been made before rendering the scene.
Definition: Scene.cpp:99
FieldParameters & _fieldParameters
Definition: Scene.h:242
VolumeParameters & _volumeParameters
Definition: Scene.h:241
LightManager _lightManager
Definition: Scene.h:250
PLATFORM_API void removeClipPlane(const size_t id)
Remove a clip plane by its ID, or no-op if not found.
Definition: Scene.cpp:208
PLATFORM_API void buildDefault()
Builds a default scene made of a Cornell box, a reflective cube, and a transparent sphere.
Definition: Scene.cpp:250
PLATFORM_API void visitModels(const std::function< void(Model &)> &functor)
Apply the given functor to every model in the scene.
Definition: Scene.cpp:243
PLATFORM_API void setMaterialsColorMap(MaterialsColorMap colorMap)
Initializes materials for all models in the scene.
Definition: Scene.cpp:382
AnimationParameters & _animationParameters
Definition: Scene.h:239
PLATFORM_API ModelDescriptorPtr getModel(const size_t id) const
Get a model descriptor given its ID.
Definition: Scene.cpp:179
PLATFORM_API void copyFrom(const Scene &rhs)
Copy the scene from another scene.
Definition: Scene.cpp:74
PLATFORM_API auto acquireReadAccess() const
Definition: Scene.h:217
virtual bool supportsConcurrentSceneUpdates() const
Check whether this scene supports scene updates from any thread.
Definition: Scene.h:235
PLATFORM_API const std::string & getEnvironmentMap() const
Get the current environment map texture file, or empty if no environment is set.
Definition: Scene.h:172
MaterialPtr _backgroundMaterial
Definition: Scene.h:243
void _loadIBLMaps(const std::string &envMap)
Definition: Scene.cpp:455
PLATFORM_API bool hasEnvironmentMap() const
Check if an environment map is currently set in the scene.
Definition: Scene.cpp:422
PLATFORM_API LoaderRegistry & getLoaderRegistry()
Get the registry for all supported loaders of this scene.
Definition: Scene.h:214
PLATFORM_API ClipPlanePtr getClipPlane(const size_t id) const
Get a clip plane by its ID.
Definition: Scene.cpp:203
PLATFORM_API bool removeModel(const size_t id)
Removes a model from the scene.
Definition: Scene.cpp:147
PLATFORM_API Scene(AnimationParameters &animationParameters, GeometryParameters &geometryParameters, VolumeParameters &volumeParameters, FieldParameters &fieldParameters)
Creates a scene object responsible for handling models, simulations and light sources.
Definition: Scene.cpp:65
PLATFORM_API const ModelDescriptors & getModelDescriptors() const
Get all model descriptors.
Definition: Scene.h:96
PLATFORM_API bool empty() const
Checks whether the scene is empty.
Definition: Scene.cpp:185
virtual PLATFORM_API bool commitLights()=0
Commits lights to renderers.
PLATFORM_API LightManager & getLightManager()
Gets the light manager.
Definition: Scene.h:74
std::vector< ModelDescriptorPtr > ModelDescriptors
Definition: Types.h:113
std::shared_ptr< ClipPlane > ClipPlanePtr
Definition: Types.h:121
MaterialsColorMap
Definition: Types.h:287
std::vector< ClipPlanePtr > ClipPlanes
Definition: Types.h:122
std::shared_ptr< ModelDescriptor > ModelDescriptorPtr
Definition: Types.h:112
std::unique_ptr< Model > ModelPtr
Definition: Types.h:103
std::shared_ptr< Material > MaterialPtr
Definition: Types.h:117
std::array< double, 4 > Plane
Definition: Types.h:308