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 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_USD_IMAGING_USD_IMAGING_STAGE_SCENE_INDEX_H
25 #define PXR_USD_IMAGING_USD_IMAGING_STAGE_SCENE_INDEX_H
26 
27 #include "pxr/pxr.h"
28 
32 
34 
35 #include "pxr/usd/usd/notice.h"
36 #include "pxr/usd/usd/stage.h"
37 
38 #include <mutex>
39 #include <set>
40 
42 
43 #define USDIMAGING_STAGE_SCENE_INDEX_TOKENS \
44  (includeUnloadedPrims) \
45 
46 TF_DECLARE_PUBLIC_TOKENS(UsdImagingStageSceneIndexTokens, USDIMAGING_API,
48 
50  std::shared_ptr<class UsdImagingPrimAdapter>;
51 class UsdImaging_AdapterManager;
52 
54 
56 {
57 public:
58  static UsdImagingStageSceneIndexRefPtr New(
59  HdContainerDataSourceHandle const &inputArgs = nullptr) {
60  return TfCreateRefPtr(new UsdImagingStageSceneIndex(inputArgs));
61  }
62 
65 
66  // ------------------------------------------------------------------------
67  // Scene index API
68 
70  HdSceneIndexPrim GetPrim(const SdfPath & primPath) const override;
71 
73  SdfPathVector GetChildPrimPaths(const SdfPath & primPath) const override;
74 
75  // ------------------------------------------------------------------------
76  // App-facing API
77 
78  // Set the USD stage to pull data from. Note that this will delete all
79  // scene index prims and reset stage global data.
81  void SetStage(UsdStageRefPtr stage);
82 
83  // Set the time, and call PrimsDirtied for any time-varying attributes.
84  //
85  // PrimsDirtied is only called if the time is different from the last call
86  // or forceDirtyingTimeDeps is true.
88  void SetTime(UsdTimeCode time, bool forceDirtyingTimeDeps = false);
89 
90  // Return the current time.
92  UsdTimeCode GetTime() const;
93 
94  // Apply queued stage edits to imaging scene.
95  // If the USD stage is edited while the scene index is pulling from it,
96  // those edits get queued and deferred. Calling ApplyPendingUpdates will
97  // turn resync requests into PrimsAdded/PrimsRemoved, and property changes
98  // into PrimsDirtied.
100  void ApplyPendingUpdates();
101 
102 private:
104  UsdImagingStageSceneIndex(HdContainerDataSourceHandle const &inputArgs);
105 
106  Usd_PrimFlagsConjunction _GetTraversalPredicate() const;
107 
108  void _ApplyPendingResyncs();
109  void _ComputeDirtiedEntries(
110  const std::map<SdfPath, TfTokenVector> &pathToUsdProperties,
111  SdfPathVector * primPathsToResync,
112  UsdImagingPropertyInvalidationType invalidationType,
113  HdSceneIndexObserver::DirtiedPrimEntries * dirtiedPrims) const;
114 
115  class _StageGlobals : public UsdImagingDataSourceStageGlobals
116  {
117  public:
118  // Datasource-facing API
119  void FlagAsTimeVarying(
120  const SdfPath & hydraPath,
121  const HdDataSourceLocator & locator) const override;
122 
123  void FlagAsAssetPathDependent(
124  const SdfPath & usdPath) const override;
125 
126  UsdTimeCode GetTime() const override;
127 
128  // Scene index-facing API
129  void SetTime(UsdTimeCode time,
131 
132  void RemoveAssetPathDependentsUnder(const SdfPath &path);
133 
134  void InvalidateAssetPathDependentsUnder(
135  const SdfPath &path,
136  std::vector<SdfPath> *primsToInvalidate,
137  std::map<SdfPath, TfTokenVector> *propertiesToInvalidate) const;
138 
139  void Clear();
140 
141  private:
142  struct _PathHashCompare {
143  static bool equal(const SdfPath &a, const SdfPath &b) {
144  return a == b;
145  }
146  static size_t hash(const SdfPath &p) {
147  return hash_value(p);
148  }
149  };
150  using _VariabilityMap = tbb::concurrent_hash_map<SdfPath,
151  HdDataSourceLocatorSet, _PathHashCompare>;
152  mutable _VariabilityMap _timeVaryingLocators;
153 
154  using _AssetPathDependentsSet = std::set<SdfPath>;
155  mutable _AssetPathDependentsSet _assetPathDependents;
156  mutable std::mutex _assetPathDependentsMutex;
157 
158  UsdTimeCode _time;
159  };
160 
161  const bool _includeUnloadedPrims;
162 
163  UsdStageRefPtr _stage;
164  _StageGlobals _stageGlobals;
165 
166  // Population
167  void _Populate();
168  void _PopulateSubtree(UsdPrim subtreeRoot);
169 
170  // Edit processing
171  void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const& notice,
172  UsdStageWeakPtr const& sender);
173  TfNotice::Key _objectsChangedNoticeKey;
174 
175  // Note: resync paths mean we remove the whole subtree and repopulate.
176  SdfPathVector _usdPrimsToResync;
177  // Property changes get converted into PrimsDirtied messages.
178  std::map<SdfPath, TfTokenVector> _usdPropertiesToUpdate;
179  std::map<SdfPath, TfTokenVector> _usdPropertiesToResync;
180 
181  using _PrimAdapterPair = std::pair<UsdPrim, UsdImagingPrimAdapterSharedPtr>;
182  _PrimAdapterPair _FindResponsibleAncestor(const UsdPrim &prim) const;
183 
184  std::unique_ptr<UsdImaging_AdapterManager> const _adapterManager;
185 };
186 
188 
189 #endif
USDIMAGING_API void SetStage(UsdStageRefPtr stage)
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1223
#define USDIMAGING_API
Definition: api.h:40
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:55
TF_DECLARE_PUBLIC_TOKENS(UsdImagingStageSceneIndexTokens, USDIMAGING_API, USDIMAGING_STAGE_SCENE_INDEX_TOKENS)
Definition: prim.h:133
Definition: path.h:290
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:211
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
USDIMAGING_API ~UsdImagingStageSceneIndex()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
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:34
TF_DECLARE_REF_PTRS(UsdImagingStageSceneIndex)