sceneIndex.h
1 //
2 // Copyright 2021 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_SCENE_INDEX_H
25 #define PXR_IMAGING_HD_SCENE_INDEX_H
26 
27 #include "pxr/pxr.h"
28 
29 #include <set>
30 #include <unordered_map>
31 
33 #include "pxr/base/tf/singleton.h"
34 
35 #include "pxr/usd/sdf/path.h"
36 
37 #include "pxr/imaging/hd/api.h"
38 #include "pxr/imaging/hd/dataSource.h"
39 #include "pxr/imaging/hd/dataSourceLocator.h"
40 #include "pxr/imaging/hd/sceneIndexObserver.h"
41 
42 PXR_NAMESPACE_OPEN_SCOPE
43 
44 
50 {
51  TfToken primType;
52  HdContainerDataSourceHandle dataSource;
53 };
54 
62 class HdSceneIndexBase : public TfRefBase, public TfWeakBase
63 {
64 public:
65 
66  HD_API
67  ~HdSceneIndexBase() override;
68 
69  // ------------------------------------------------------------------------
70  // Scene Observer API
71  // ------------------------------------------------------------------------
72 
79  HD_API
80  void AddObserver(const HdSceneIndexObserverPtr &observer);
81 
87  HD_API
88  void RemoveObserver(const HdSceneIndexObserverPtr &observer);
89 
90  // ------------------------------------------------------------------------
91  // Scene Data API
92  // ------------------------------------------------------------------------
93 
98  virtual HdSceneIndexPrim GetPrim(const SdfPath &primPath) const = 0;
99 
106  virtual SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const = 0;
107 
112  HdDataSourceBaseHandle GetDataSource(
113  const SdfPath &primPath,
114  const HdDataSourceLocator &locator) const
115  {
117  GetPrim(primPath).dataSource, locator);
118  }
119 
120 protected:
121 
130  HD_API
131  void _SendPrimsAdded(
133 
138  HD_API
139  void _SendPrimsRemoved(
141 
149  HD_API
150  void _SendPrimsDirtied(
152 
156  HD_API
157  bool _IsObserved() const;
158 
159 private:
160 
161  using _ObserverSet = std::set<HdSceneIndexObserverPtr>;
162  _ObserverSet _observers;
163 };
164 
165 
174  : public TfSingleton<HdSceneIndexNameRegistry>
175 {
177 
178  HdSceneIndexNameRegistry() = default;
179 
180 public:
181 
184  HD_API
187  }
188 
191  HD_API
193  const std::string &name, HdSceneIndexBasePtr instance);
194 
197  HD_API
198  std::vector<std::string> GetRegisteredNames();
199 
202  HD_API
203  HdSceneIndexBaseRefPtr GetNamedSceneIndex(const std::string &name);
204 
205 private:
206 
207  using _NamedInstanceMap =
208  std::unordered_map<std::string, HdSceneIndexBasePtr>;
209 
210  _NamedInstanceMap _namedInstances;
211 };
212 
213 PXR_NAMESPACE_CLOSE_SCOPE
214 
215 #endif // PXR_IMAGING_HD_SCENE_INDEX_H
Manage a single instance of an object.
virtual HdDataSourceBaseHandle Get(const TfToken &name)=0
Returns the child datasource of the given name.
Manage a single instance of an object (see.
Definition: singleton.h:119
virtual HdSceneIndexPrim GetPrim(const SdfPath &primPath) const =0
Returns a pair of (prim type, datasource) for the object at primPath.
Standard pointer typedefs.
Enable a concrete base class for use with TfRefPtr.
Definition: refBase.h:71
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:49
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
virtual SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const =0
Returns the paths of all scene index prims located immediately below primPath.
Represents an object that can identify the location of a data source.
A registry containing named instances of Hydra indexes.
Definition: sceneIndex.h:173
HD_API void RegisterNamedSceneIndex(const std::string &name, HdSceneIndexBasePtr instance)
Registers an instance of a scene index with a given name.
Abstract interface to scene data.
Definition: sceneIndex.h:62
HD_API bool _IsObserved() const
Returns whether the scene index has any registered observers; this information can be used to skip wo...
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:112
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
static T & GetInstance()
Return a reference to an object of type T, creating it if necessary.
Definition: singleton.h:134
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 _SendPrimsAdded(const HdSceneIndexObserver::AddedPrimEntries &entries)
Notify attached observers of prims added to the scene.
HD_API void _SendPrimsDirtied(const HdSceneIndexObserver::DirtiedPrimEntries &entries)
Notify attached observers of datasource invalidations from the scene.
HD_API void AddObserver(const HdSceneIndexObserverPtr &observer)
Adds an observer to this scene index.
static HD_API HdSceneIndexNameRegistry & GetInstance()
Returns the singleton-instance of this registry.
Definition: sceneIndex.h:185
HD_API HdSceneIndexBaseRefPtr GetNamedSceneIndex(const std::string &name)
Returns the scene index that was registered with the given name.
HD_API std::vector< std::string > GetRegisteredNames()
Returns the names of all registered scene indexes.
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
HD_API void _SendPrimsRemoved(const HdSceneIndexObserver::RemovedPrimEntries &entries)
Notify attached observers of prims removed from the scene.