All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sceneIndex.h
1//
2// Copyright 2021 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HD_SCENE_INDEX_H
8#define PXR_IMAGING_HD_SCENE_INDEX_H
9
10#include "pxr/pxr.h"
11
12#include <set>
13#include <unordered_map>
14
18
19
20#include "pxr/usd/sdf/path.h"
21
22#include "pxr/imaging/hd/api.h"
23#include "pxr/imaging/hd/dataSource.h"
24#include "pxr/imaging/hd/dataSourceLocator.h"
25#include "pxr/imaging/hd/sceneIndexObserver.h"
26
27PXR_NAMESPACE_OPEN_SCOPE
28
29
35{
36 TfToken primType;
37 HdContainerDataSourceHandle dataSource;
38};
39
48{
49public:
50 HD_API
52
53 HD_API
54 ~HdSceneIndexBase() override;
55
56 // ------------------------------------------------------------------------
57 // Scene Observer API
58 // ------------------------------------------------------------------------
59
66 HD_API
67 void AddObserver(const HdSceneIndexObserverPtr &observer);
68
74 HD_API
75 void RemoveObserver(const HdSceneIndexObserverPtr &observer);
76
77 // ------------------------------------------------------------------------
78 // Scene Data API
79 // ------------------------------------------------------------------------
80
85 virtual HdSceneIndexPrim GetPrim(const SdfPath &primPath) const = 0;
86
93 virtual SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const = 0;
94
99 HdDataSourceBaseHandle GetDataSource(
100 const SdfPath &primPath,
101 const HdDataSourceLocator &locator) const
102 {
104 GetPrim(primPath).dataSource, locator);
105 }
106
107 // ------------------------------------------------------------------------
108 // System-wide API
109 // ------------------------------------------------------------------------
110
114 HD_API
116 const TfToken &messageType,
117 const HdDataSourceBaseHandle &args);
118
119 // ------------------------------------------------------------------------
120 // User Interface Utilities
121 // ------------------------------------------------------------------------
122
127 HD_API
128 std::string GetDisplayName() const;
129
133 HD_API
134 void SetDisplayName(const std::string &n);
135
139 HD_API
140 void AddTag(const TfToken &tag);
141
145 HD_API
146 void RemoveTag(const TfToken &tag);
147
151 HD_API
152 bool HasTag(const TfToken &tag) const;
153
157 HD_API
159
160protected:
161
170 HD_API
173
178 HD_API
181
189 HD_API
192
193
198 HD_API
201
202
206 HD_API
207 bool _IsObserved() const;
208
211 HD_API
212 virtual void _SystemMessage(
213 const TfToken &messageType,
214 const HdDataSourceBaseHandle &args);
215
216private:
217 void _RemoveExpiredObservers();
218
219 // Scoped (RAII) helper to manage tracking recursion depth,
220 // and to remove expired observers after completing delivery.
221 struct _NotifyScope;
222
223 // Registered observers, in order of registration.
224 using _Observers = std::vector<HdSceneIndexObserverPtr>;
225 _Observers _observers;
226
227 // Count of in-flight observer notifications
228 int _notifyDepth;
229
230 // Flag hinting that expired observers may exist.
231 bool _shouldRemoveExpiredObservers;
232
233 // User-visible label for this scene index
234 std::string _displayName;
235
236 // Tags used to categorize this scene index
238 _TagSet _tags;
239};
240
241
250 : public TfSingleton<HdSceneIndexNameRegistry>
251{
253
254 HdSceneIndexNameRegistry() = default;
255
256public:
257
260 HD_API
263 }
264
267 HD_API
269 const std::string &name, HdSceneIndexBasePtr instance);
270
273 HD_API
274 std::vector<std::string> GetRegisteredNames();
275
278 HD_API
279 HdSceneIndexBaseRefPtr GetNamedSceneIndex(const std::string &name);
280
281private:
282
283 using _NamedInstanceMap =
284 std::unordered_map<std::string, HdSceneIndexBasePtr>;
285
286 _NamedInstanceMap _namedInstances;
287};
288
289PXR_NAMESPACE_CLOSE_SCOPE
290
291#endif // PXR_IMAGING_HD_SCENE_INDEX_H
virtual HdDataSourceBaseHandle Get(const TfToken &name)=0
Returns the child datasource of the given name.
Represents an object that can identify the location of a data source.
Abstract interface to scene data.
Definition: sceneIndex.h:48
HdDataSourceBaseHandle GetDataSource(const SdfPath &primPath, const HdDataSourceLocator &locator) const
A convenience function: look up the object at primPath, and if successful return the datasource at lo...
Definition: sceneIndex.h:99
virtual SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const =0
Returns the paths of all scene index prims located immediately below primPath.
HD_API void _SendPrimsRemoved(const HdSceneIndexObserver::RemovedPrimEntries &entries)
Notify attached observers of prims removed from the scene.
HD_API void _SendPrimsRenamed(const HdSceneIndexObserver::RenamedPrimEntries &entries)
Notify attached observers of prims (and their descendents) which have been renamed or reparented.
HD_API void RemoveObserver(const HdSceneIndexObserverPtr &observer)
Removes an observer from this scene index; the given observer will no longer be forwarded notices.
HD_API void AddObserver(const HdSceneIndexObserverPtr &observer)
Adds an observer to this scene index.
HD_API bool _IsObserved() const
Returns whether the scene index has any registered observers; this information can be used to skip wo...
HD_API void _SendPrimsAdded(const HdSceneIndexObserver::AddedPrimEntries &entries)
Notify attached observers of prims added to the scene.
HD_API std::string GetDisplayName() const
Returns a value previously set by SetDisplayName.
HD_API void AddTag(const TfToken &tag)
Adds a specified tag token to a scene index instance.
virtual HD_API void _SystemMessage(const TfToken &messageType, const HdDataSourceBaseHandle &args)
Implement in order to react directly to system messages sent from downstream.
HD_API TfTokenVector GetTags() const
Returns all tag tokens currently added to a scene index instance.
HD_API void _SendPrimsDirtied(const HdSceneIndexObserver::DirtiedPrimEntries &entries)
Notify attached observers of datasource invalidations from the scene.
virtual HdSceneIndexPrim GetPrim(const SdfPath &primPath) const =0
Returns a pair of (prim type, datasource) for the object at primPath.
HD_API void SystemMessage(const TfToken &messageType, const HdDataSourceBaseHandle &args)
Sends a message with optional arguments to this and any upstream input scene indices.
HD_API bool HasTag(const TfToken &tag) const
Returns true if a specified tag token has been added to a scene index instance.
HD_API void SetDisplayName(const std::string &n)
Allows for scene index instances to be identified in a more contextually relevant way.
HD_API void RemoveTag(const TfToken &tag)
Removes a specified tag token to a scene index instance.
A registry containing named instances of Hydra indexes.
Definition: sceneIndex.h:251
static HD_API HdSceneIndexNameRegistry & GetInstance()
Returns the singleton-instance of this registry.
Definition: sceneIndex.h:261
HD_API void RegisterNamedSceneIndex(const std::string &name, HdSceneIndexBasePtr instance)
Registers an instance of a scene index with a given name.
HD_API std::vector< std::string > GetRegisteredNames()
Returns the names of all registered scene indexes.
HD_API HdSceneIndexBaseRefPtr GetNamedSceneIndex(const std::string &name)
Returns the scene index that was registered with the given name.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:56
Manage a single instance of an object (see.
Definition: singleton.h:105
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Definition: singleton.h:120
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:124
Standard pointer typedefs.
Manage a single instance of an object.
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440