HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stageSceneIndex.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 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_USD_IMAGING_USD_IMAGING_STAGE_SCENE_INDEX_H
8 #define PXR_USD_IMAGING_USD_IMAGING_STAGE_SCENE_INDEX_H
9 
10 #include "pxr/pxr.h"
11 
15 
17 
18 #include "pxr/usd/usd/notice.h"
19 #include "pxr/usd/usd/stage.h"
20 
21 #include <mutex>
22 #include <set>
23 
25 
26 #define USDIMAGING_STAGE_SCENE_INDEX_TOKENS \
27  (includeUnloadedPrims) \
28 
29 TF_DECLARE_PUBLIC_TOKENS(UsdImagingStageSceneIndexTokens, USDIMAGING_API,
31 
33  std::shared_ptr<class UsdImagingPrimAdapter>;
34 class UsdImaging_AdapterManager;
35 
37 
39 {
40 public:
41  static UsdImagingStageSceneIndexRefPtr New(
42  HdContainerDataSourceHandle const &inputArgs = nullptr) {
43  return TfCreateRefPtr(new UsdImagingStageSceneIndex(inputArgs));
44  }
45 
48 
49  // ------------------------------------------------------------------------
50  // Scene index API
51 
53  HdSceneIndexPrim GetPrim(const SdfPath & primPath) const override;
54 
56  SdfPathVector GetChildPrimPaths(const SdfPath & primPath) const override;
57 
58  // ------------------------------------------------------------------------
59  // App-facing API
60 
61  // Set the USD stage to pull data from. Note that this will delete all
62  // scene index prims and reset stage global data.
64  void SetStage(UsdStageRefPtr stage);
65 
66  // Set the time, and call PrimsDirtied for any time-varying attributes.
67  //
68  // PrimsDirtied is only called if the time is different from the last call
69  // or forceDirtyingTimeDeps is true.
71  void SetTime(UsdTimeCode time, bool forceDirtyingTimeDeps = false);
72 
73  // Return the current time.
75  UsdTimeCode GetTime() const;
76 
77  // Apply queued stage edits to imaging scene.
78  // If the USD stage is edited while the scene index is pulling from it,
79  // those edits get queued and deferred. Calling ApplyPendingUpdates will
80  // turn resync requests into PrimsAdded/PrimsRemoved, and property changes
81  // into PrimsDirtied.
83  void ApplyPendingUpdates();
84 
85 private:
87  UsdImagingStageSceneIndex(HdContainerDataSourceHandle const &inputArgs);
88 
89  Usd_PrimFlagsPredicate _GetPrimPredicate() const;
90 
91  void _ApplyPendingResyncs();
92  void _ComputeDirtiedEntries(
93  const std::map<SdfPath, TfTokenVector> &pathToUsdProperties,
94  SdfPathVector * primPathsToResync,
95  UsdImagingPropertyInvalidationType invalidationType,
96  HdSceneIndexObserver::DirtiedPrimEntries * dirtiedPrims) const;
97 
98  class _StageGlobals : public UsdImagingDataSourceStageGlobals
99  {
100  public:
101  // Datasource-facing API
102  void FlagAsTimeVarying(
103  const SdfPath & hydraPath,
104  const HdDataSourceLocator & locator) const override;
105 
106  void FlagAsAssetPathDependent(
107  const SdfPath & usdPath) const override;
108 
109  UsdTimeCode GetTime() const override;
110 
111  // Scene index-facing API
112  void SetTime(UsdTimeCode time,
114 
115  void RemoveAssetPathDependentsUnder(const SdfPath &path);
116 
117  void InvalidateAssetPathDependentsUnder(
118  const SdfPath &path,
119  std::vector<SdfPath> *primsToInvalidate,
120  std::map<SdfPath, TfTokenVector> *propertiesToInvalidate) const;
121 
122  void Clear();
123 
124  private:
125  struct _PathHashCompare {
126  static bool equal(const SdfPath &a, const SdfPath &b) {
127  return a == b;
128  }
129  static size_t hash(const SdfPath &p) {
130  return hash_value(p);
131  }
132  };
133  using _VariabilityMap = tbb::concurrent_hash_map<SdfPath,
134  HdDataSourceLocatorSet, _PathHashCompare>;
135  mutable _VariabilityMap _timeVaryingLocators;
136 
137  using _AssetPathDependentsSet = std::set<SdfPath>;
138  mutable _AssetPathDependentsSet _assetPathDependents;
139  mutable std::mutex _assetPathDependentsMutex;
140 
141  UsdTimeCode _time;
142  };
143 
144  const bool _includeUnloadedPrims;
145 
146  UsdStageRefPtr _stage;
147  _StageGlobals _stageGlobals;
148 
149  // Population
150  void _Populate();
151  void _PopulateSubtree(UsdPrim subtreeRoot);
152 
153  // Edit processing
154  void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const& notice,
155  UsdStageWeakPtr const& sender);
156  TfNotice::Key _objectsChangedNoticeKey;
157 
158  // Note: resync paths mean we remove the whole subtree and repopulate.
159  SdfPathVector _usdPrimsToResync;
160  // Property changes get converted into PrimsDirtied messages.
161  std::map<SdfPath, TfTokenVector> _usdPropertiesToUpdate;
162  std::map<SdfPath, TfTokenVector> _usdPropertiesToResync;
163 
164  using _PrimAdapterPair = std::pair<UsdPrim, UsdImagingPrimAdapterSharedPtr>;
165  _PrimAdapterPair _FindResponsibleAncestor(const UsdPrim &prim) const;
166 
167  std::unique_ptr<UsdImaging_AdapterManager> const _adapterManager;
168 };
169 
171 
172 #endif
USDIMAGING_API void SetStage(UsdStageRefPtr stage)
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1190
#define USDIMAGING_API
Definition: api.h:23
GT_API const UT_StringHolder time
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDIMAGING_API void SetTime(UsdTimeCode time, bool forceDirtyingTimeDeps=false)
#define USDIMAGING_STAGE_SCENE_INDEX_TOKENS
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
Definition: ImathFun.h:105
USDIMAGING_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
UsdStagePtr UsdStageWeakPtr
Definition: common.h:38
TF_DECLARE_PUBLIC_TOKENS(UsdImagingStageSceneIndexTokens, USDIMAGING_API, USDIMAGING_STAGE_SCENE_INDEX_TOKENS)
std::vector< class SdfPath > SdfPathVector
Definition: prim.h:116
Definition: path.h:273
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDIMAGING_API ~UsdImagingStageSceneIndex()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDIMAGING_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
std::shared_ptr< UsdImagingPrimAdapter > UsdImagingPrimAdapterSharedPtr
USDIMAGING_API UsdTimeCode GetTime() const
static UsdImagingStageSceneIndexRefPtr New(HdContainerDataSourceHandle const &inputArgs=nullptr)
USDIMAGING_API void ApplyPendingUpdates()
size_t hash_value(const CH_ChannelRef &ref)
UsdImagingPropertyInvalidationType
Definition: types.h:17
TF_DECLARE_REF_PTRS(UsdImagingStageSceneIndex)