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 
39 
40 #define USDIMAGING_STAGE_SCENE_INDEX_TOKENS \
41  (includeUnloadedPrims) \
42 
43 TF_DECLARE_PUBLIC_TOKENS(UsdImagingStageSceneIndexTokens, USDIMAGING_API,
45 
47  std::shared_ptr<class UsdImagingPrimAdapter>;
48 class UsdImaging_AdapterManager;
49 
51 
53 {
54 public:
55  static UsdImagingStageSceneIndexRefPtr New(
56  HdContainerDataSourceHandle const &inputArgs = nullptr) {
57  return TfCreateRefPtr(new UsdImagingStageSceneIndex(inputArgs));
58  }
59 
62 
63  // ------------------------------------------------------------------------
64  // Scene index API
65 
67  HdSceneIndexPrim GetPrim(const SdfPath & primPath) const override;
68 
70  SdfPathVector GetChildPrimPaths(const SdfPath & primPath) const override;
71 
72  // ------------------------------------------------------------------------
73  // App-facing API
74 
75  // Set the USD stage to pull data from. Note that this will delete all
76  // scene index prims and reset stage global data.
78  void SetStage(UsdStageRefPtr stage);
79 
80  // Set the time, and call PrimsDirtied for any time-varying attributes.
82  void SetTime(UsdTimeCode time);
83 
84  // Return the current time.
86  UsdTimeCode GetTime() const;
87 
88  // Apply queued stage edits to imaging scene.
89  // If the USD stage is edited while the scene index is pulling from it,
90  // those edits get queued and deferred. Calling ApplyPendingUpdates will
91  // turn resync requests into PrimsAdded/PrimsRemoved, and property changes
92  // into PrimsDirtied.
94  void ApplyPendingUpdates();
95 
96 private:
98  UsdImagingStageSceneIndex(HdContainerDataSourceHandle const &inputArgs);
99 
100  Usd_PrimFlagsConjunction _GetTraversalPredicate() const;
101 
102  void _ApplyPendingResyncs();
103  void _ComputeDirtiedEntries(
104  const std::map<SdfPath, TfTokenVector> &pathToUsdProperties,
105  SdfPathVector * primPathsToResync,
106  UsdImagingPropertyInvalidationType invalidationType,
107  HdSceneIndexObserver::DirtiedPrimEntries * dirtiedPrims) const;
108 
109  class _StageGlobals : public UsdImagingDataSourceStageGlobals
110  {
111  public:
112  // Datasource-facing API
113  void FlagAsTimeVarying(
114  const SdfPath & primPath,
115  const HdDataSourceLocator & locator) const override;
116 
117  UsdTimeCode GetTime() const override;
118 
119  // Scene index-facing API
120  void SetTime(UsdTimeCode time,
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  UsdTimeCode _time;
138  };
139 
140  const bool _includeUnloadedPrims;
141 
142  UsdStageRefPtr _stage;
143  _StageGlobals _stageGlobals;
144 
145  // Population
146  void _Populate();
147  void _PopulateSubtree(UsdPrim subtreeRoot);
148 
149  // Edit processing
150  void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const& notice,
151  UsdStageWeakPtr const& sender);
152  TfNotice::Key _objectsChangedNoticeKey;
153 
154  // Note: resync paths mean we remove the whole subtree and repopulate.
155  SdfPathVector _usdPrimsToResync;
156  // Property changes get converted into PrimsDirtied messages.
157  std::map<SdfPath, TfTokenVector> _usdPropertiesToUpdate;
158  std::map<SdfPath, TfTokenVector> _usdPropertiesToResync;
159 
160  using _PrimAdapterPair = std::pair<UsdPrim, UsdImagingPrimAdapterSharedPtr>;
161  _PrimAdapterPair _FindResponsibleAncestor(const UsdPrim &prim) const;
162 
163  std::unique_ptr<UsdImaging_AdapterManager> const _adapterManager;
164 };
165 
167 
168 #endif
USDIMAGING_API void SetTime(UsdTimeCode time)
USDIMAGING_API void SetStage(UsdStageRefPtr stage)
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1198
#define USDIMAGING_API
Definition: api.h:40
GT_API const UT_StringHolder time
#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:135
Definition: path.h:291
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:212
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
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)