Ocean
scenedescription/Library.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_SCENEDESCRIPTION_LIBRARY_H
9 #define META_OCEAN_SCENEDESCRIPTION_LIBRARY_H
10 
15 
16 namespace Ocean
17 {
18 
19 namespace SceneDescription
20 {
21 
22 // Forward declaration.
23 class Library;
24 
25 /**
26  * Definition of a object reference holding a library object.
27  * @see ObjectRef, Library.
28  * @ingroup media
29  */
31 
32 /**
33  * This class is the base class for all scene description libraries.
34  * @ingroup scenedescription
35  */
36 class OCEAN_SCENEDESCRIPTION_EXPORT Library
37 {
38  friend class Manager;
39  friend class ObjectRef<Library>;
40 
41  public:
42 
43  /**
44  * Definition of a map mapping file extensions to file type descriptions.
45  */
46  typedef std::map<std::string, std::string> FileExtensions;
47 
48  public:
49 
50  /**
51  * Loads a new scene by a given filename.
52  * @param filename Entire filename of the scene to load
53  * @param fileExtension File extention of the scene to load
54  * @param engine Rendering engine to be connected with the scene description, must be defined for permanent scene description objects only
55  * @param timestamp The current timestamp, must be valid
56  * @param descriptionType Scene description type
57  * @param progress Progress state receiving recurrently information about the load state with range [0, 1]
58  * @param cancel Cancel state allows the cancelation of a load process while loading process hasn't finished, if the cancel state is used the load process stops if the value is set to True
59  * @return Resulting scene
60  * @see Manager::load().
61  */
62  SceneRef load(const std::string& filename, const std::string& fileExtension, const Rendering::EngineRef& engine, const Timestamp& timestamp, const DescriptionType descriptionType, float* progress = nullptr, bool* cancel = nullptr);
63 
64  /**
65  * Returns the name of the library.
66  * @return Library name
67  */
68  inline const std::string& name() const;
69 
70  /**
71  * Returns the description type supported by the library.
72  * @return Scene description type
73  */
74  inline DescriptionType descriptionType() const;
75 
76  /**
77  * Returns the node reference of the first available scene description node with a specified name.
78  * @param name The name of the node to return
79  * @return Node reference of the node, the reference will be empty if the node does not exist
80  */
81  virtual NodeRef node(const std::string& name) const;
82 
83  /**
84  * Returns all node references of all available scene description nodes with a specified name.
85  * @param name The name of the nodes to return
86  * @return All node references found
87  */
88  virtual NodeRefs nodes(const std::string& name) const;
89 
90  /**
91  * Returns the node reference manager of this library.
92  * @return Node reference manager
93  */
94  inline NodeRefManager& nodeManager() const;
95 
96  /**
97  * Releases the library.
98  */
99  virtual void release();
100 
101  protected:
102 
103  /**
104  * Disabled copy constructor.
105  * @param library Object which would be copied
106  */
107  Library(const Library& library) = delete;
108 
109  /**
110  * Creates a new library object.
111  * @param name The name of the library
112  * @param descriptionType Supported scene description type
113  * @param priority The priority of this library, the higher the value, the higher the priority, with range [0, infinity)
114  */
115  Library(const std::string& name, const DescriptionType descriptionType, const unsigned int priority);
116 
117  /**
118  * Destructs a library object.
119  */
120  virtual ~Library();
121 
122  /**
123  * Returns the priority of this library.
124  * In case two libraries support the same scene description format, the library with higher priority will be used first to load the scene.
125  * @return The library's priority, with range [0, infinity)
126  */
127  inline unsigned int priority() const;
128 
129  /**
130  * Returns all registered file extensions.
131  * @return Registered file extensions
132  */
133  inline FileExtensions registeredFileExtensions() const;
134 
135  /**
136  * Registers an additional file extension.
137  * @param extension New file extension to register
138  * @param description Description of the file type
139  */
140  void registerFileExtension(const std::string& extension, const std::string& description);
141 
142  /**
143  * Loads a new scene by a given filename and returns a scene hierarchy which can be used permanently.
144  * @param filename Entire filename of the scene to load
145  * @param fileExtension File extention of the scene to load
146  * @param engine Rendering engine to be connected with the scene description
147  * @param timestamp The current timestamp, must be valid
148  * @param progress Progress state receiving recurrently information about the load state with range [0, 1]
149  * @param cancel Cancel state allows the cancelation of a load process while loading process hasn't finished, if the cancel state is used the load process stops if the value is set to True
150  * @return Resulting scene
151  */
152  virtual SceneRef loadPermanent(const std::string& filename, const std::string& fileExtension, const Rendering::EngineRef& engine, const Timestamp& timestamp, float* progress, bool* cancel);
153 
154  /**
155  * Loads a new scene by a given filename and returns a transient scene hierarchy which can be converted to a rendering scene graph afterwards.
156  * @param filename Entire filename of the scene to load
157  * @param fileExtension File extention of the scene to load
158  * @param progress Progress state receiving recurrently information about the load state with range [0, 1]
159  * @param cancel Cancel state allows the cancelation of a load process while loading process hasn't finished, if the cancel state is used the load process stops if the value is set to True
160  * @return Resulting scene
161  */
162  virtual SceneRef loadTransient(const std::string& filename, const std::string& fileExtension, float* progress, bool* cancel);
163 
164  /**
165  * Disabled copy operator.
166  * @param library Object which would be copied
167  * @return Reference to this object
168  */
169  Library& operator=(const Library& library) = delete;
170 
171  /**
172  * Unregisters a library at the manager.
173  * @param library Name of the library to unregister
174  * @return True, if succeeded
175  */
176  static bool unregisterLibrary(const std::string& library);
177 
178  private:
179 
180  /// The name of the library.
181  std::string name_;
182 
183  /// The priority of this library, the higher the value, the higher the priority.
184  unsigned int priority_ = 0u;
185 
186  /// Map holding accepted file extensions supported by this library.
188 
189  /// Supported scene description type.
191 
192  /// Node reference manager for this library only.
194 };
195 
196 inline const std::string& Library::name() const
197 {
198  return name_;
199 }
200 
202 {
203  return fileExtensions_;
204 }
205 
207 {
208  return descriptionType_;
209 }
210 
212 {
213  return nodeRefManager_;
214 }
215 
216 inline unsigned int Library::priority() const
217 {
218  return priority_;
219 }
220 
221 }
222 
223 }
224 
225 #endif // META_OCEAN_SCENEDESCRIPTION_LIBRARY_H
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
This class is the base class for all scene description libraries.
Definition: scenedescription/Library.h:37
Library & operator=(const Library &library)=delete
Disabled copy operator.
Library(const std::string &name, const DescriptionType descriptionType, const unsigned int priority)
Creates a new library object.
DescriptionType descriptionType() const
Returns the description type supported by the library.
Definition: scenedescription/Library.h:206
std::map< std::string, std::string > FileExtensions
Definition of a map mapping file extensions to file type descriptions.
Definition: scenedescription/Library.h:46
const std::string & name() const
Returns the name of the library.
Definition: scenedescription/Library.h:196
virtual NodeRefs nodes(const std::string &name) const
Returns all node references of all available scene description nodes with a specified name.
virtual SceneRef loadPermanent(const std::string &filename, const std::string &fileExtension, const Rendering::EngineRef &engine, const Timestamp &timestamp, float *progress, bool *cancel)
Loads a new scene by a given filename and returns a scene hierarchy which can be used permanently.
unsigned int priority() const
Returns the priority of this library.
Definition: scenedescription/Library.h:216
DescriptionType descriptionType_
Supported scene description type.
Definition: scenedescription/Library.h:190
FileExtensions fileExtensions_
Map holding accepted file extensions supported by this library.
Definition: scenedescription/Library.h:187
void registerFileExtension(const std::string &extension, const std::string &description)
Registers an additional file extension.
virtual NodeRef node(const std::string &name) const
Returns the node reference of the first available scene description node with a specified name.
virtual void release()
Releases the library.
FileExtensions registeredFileExtensions() const
Returns all registered file extensions.
Definition: scenedescription/Library.h:201
std::string name_
The name of the library.
Definition: scenedescription/Library.h:181
virtual ~Library()
Destructs a library object.
static bool unregisterLibrary(const std::string &library)
Unregisters a library at the manager.
NodeRefManager nodeRefManager_
Node reference manager for this library only.
Definition: scenedescription/Library.h:193
NodeRefManager & nodeManager() const
Returns the node reference manager of this library.
Definition: scenedescription/Library.h:211
virtual SceneRef loadTransient(const std::string &filename, const std::string &fileExtension, float *progress, bool *cancel)
Loads a new scene by a given filename and returns a transient scene hierarchy which can be converted ...
unsigned int priority_
The priority of this library, the higher the value, the higher the priority.
Definition: scenedescription/Library.h:184
Library(const Library &library)=delete
Disabled copy constructor.
SceneRef load(const std::string &filename, const std::string &fileExtension, const Rendering::EngineRef &engine, const Timestamp &timestamp, const DescriptionType descriptionType, float *progress=nullptr, bool *cancel=nullptr)
Loads a new scene by a given filename.
This class implements the manager for all scene descriptions.
Definition: scenedescription/Manager.h:101
This class implements a scene description node reference manager.
Definition: NodeRefManager.h:32
This template class implements a smart object reference which is a specialization of an ObjectRef obj...
Definition: SmartObjectRef.h:90
This class implements a timestamp.
Definition: Timestamp.h:36
ObjectRef< Library > LibraryRef
Definition of a object reference holding a library object.
Definition: scenedescription/Library.h:23
DescriptionType
Definition of different scene description types.
Definition: SceneDescription.h:64
std::vector< NodeRef > NodeRefs
Definition of a vector holding scene description node references.
Definition: scenedescription/Node.h:42
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15