Loading...
Searching...
No Matches
expressionEvaluatingSceneIndexBase.h
1//
2// Copyright 2026 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_HDSI_EXPRESSION_EVALUATING_SCENE_INDEX_BASE_H
8#define PXR_IMAGING_HDSI_EXPRESSION_EVALUATING_SCENE_INDEX_BASE_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hdsi/api.h"
12
13#include "pxr/imaging/hd/instancingAwareCollectionExpressionEvaluator.h"
14#include "pxr/imaging/hd/filteringSceneIndex.h"
15#include "pxr/imaging/hd/sceneIndexObserver.h"
16
17#include "pxr/usd/sdf/path.h"
18#include "pxr/usd/sdf/pathExpression.h"
19
20PXR_NAMESPACE_OPEN_SCOPE
21
23
26
27// Alias that's also defined in hd/collectionPredicateLibrary.h
30
52{
53public:
55 HDSI_API
56 std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const final;
57
59 HDSI_API
60 std::vector<HdSceneIndexBaseRefPtr> GetEncapsulatedScenes() const override;
61
63 HDSI_API
64 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const final;
65
67 HDSI_API
68 SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const final;
69
70protected:
73 HDSI_API
75 const HdSceneIndexBaseRefPtr &inputSceneIndex,
76 const HdCollectionPredicateLibrary &predicateLibrary);
77
78 // -----------------------------------------------------------------------
79 // Query hooks
80
84 HDSI_API
85 virtual void _ModifyPrim(
86 const SdfPath &primPath, HdSceneIndexPrim *prim) const;
87
91 HDSI_API
93 const SdfPath &primPath, SdfPathVector *children) const;
94
97 HDSI_API
98 virtual bool _IsPruned(const SdfPath &primPath) const;
99
100 // -----------------------------------------------------------------------
101 // Notice hooks (pure virtual)
102 //
103 // Each hook provides the input entries and returns a resullt that bundles
104 // optional added, removed, and dirtied entries, and indicates whether to
105 // forward the input notices as-is to downstream observers.
106 //
107 // The base class implementations of the non-virtual notice handlers call
108 // these hooks and forwards the resulting notices in the following order:
109 // Added, Removed, Dirtied.
110 //
111 // The _IsObserved() check runs after the hook so derived classes can
112 // track state unconditionally.
113
114public:
115 using OptionalAddedEntries =
116 std::optional<HdSceneIndexObserver::AddedPrimEntries>;
117 using OptionalRemovedEntries =
118 std::optional<HdSceneIndexObserver::RemovedPrimEntries>;
119 using OptionalDirtiedEntries =
120 std::optional<HdSceneIndexObserver::DirtiedPrimEntries>;
121
122 struct NoticeProcessingResult {
123 static NoticeProcessingResult ForwardInputNotices() {
124 return NoticeProcessingResult(true);
125 }
126
127 static NoticeProcessingResult Empty() {
128 return NoticeProcessingResult(false);
129 }
130
131 explicit NoticeProcessingResult(bool forwardInputNotices)
132 : forwardInputNotices(forwardInputNotices) {}
133
134 NoticeProcessingResult& SetAddedEntries(
136 addedEntries = entries;
137 return *this;
138 }
139
140 NoticeProcessingResult& SetRemovedEntries(
142 removedEntries = entries;
143 return *this;
144 }
145
146 NoticeProcessingResult& SetDirtiedEntries(
148 dirtiedEntries = entries;
149 return *this;
150 }
151
152 bool forwardInputNotices;
153 OptionalAddedEntries addedEntries;
154 OptionalRemovedEntries removedEntries;
155 OptionalDirtiedEntries dirtiedEntries;
156 };
157
158protected:
159 virtual NoticeProcessingResult _PrimsAdded(
160 const HdSceneIndexBase &sender,
161 const HdSceneIndexObserver::AddedPrimEntries &inputEntries) = 0;
162
163 virtual NoticeProcessingResult _PrimsRemoved(
164 const HdSceneIndexBase &sender,
165 const HdSceneIndexObserver::RemovedPrimEntries &inputEntries) = 0;
166
167 virtual NoticeProcessingResult _PrimsDirtied(
168 const HdSceneIndexBase &sender,
169 const HdSceneIndexObserver::DirtiedPrimEntries &inputEntries) = 0;
170
171 // Default implementation converts the renamed entries to removed and added
172 // entries and calls _PrimsRemoved and _PrimsAdded. Derived classes can
173 // override this to handle renamed entries directly.
174 virtual NoticeProcessingResult _PrimsRenamed(
175 const HdSceneIndexBase &sender,
176 const HdSceneIndexObserver::RenamedPrimEntries &inputEntries);
177
178 // -----------------------------------------------------------------------
179 // Utilities
180
185 HDSI_API
187 const SdfPathExpression &pathExpr) const;
188
197 HDSI_API
199 const SdfPathSet &outermostInstancePaths) const;
200
202 HDSI_API
203 const HdSceneIndexBaseRefPtr &_GetInputSceneIndex() const;
204
205private:
206
207 friend class _Observer;
208
213 class _Observer : public HdSceneIndexObserver
214 {
215 public:
217 : _owner(owner) {}
218
219 HDSI_API
220 void PrimsAdded(
221 const HdSceneIndexBase &sender,
222 const AddedPrimEntries &entries) override;
223
224 HDSI_API
225 void PrimsRemoved(
226 const HdSceneIndexBase &sender,
227 const RemovedPrimEntries &entries) override;
228
229 HDSI_API
230 void PrimsDirtied(
231 const HdSceneIndexBase &sender,
232 const DirtiedPrimEntries &entries) override;
233
234 HDSI_API
235 void PrimsRenamed(
236 const HdSceneIndexBase &sender,
237 const RenamedPrimEntries &entries) override;
238
239 private:
241 };
242
243 // -----------------------------------------------------------------------
244 // Data
245 const HdSceneIndexBaseRefPtr _inputSceneIndex;
246 const HdCollectionPredicateLibrary _predicateLibrary;
247
248 // Note: The proxy view scene index should be created *before* the internal
249 // observer to ensure that it has processed any notices before the observer
250 // receives them.
251 const HdInstanceProxyViewSceneIndexRefPtr _proxyViewSceneIndex;
252 _Observer _observer;
253};
254
255PXR_NAMESPACE_CLOSE_SCOPE
256
257#endif // PXR_IMAGING_HDSI_EXPRESSION_EVALUATING_SCENE_INDEX_BASE_H
A mix-in class for scene indices that implement their behaviour by creating other scene indices (inte...
An abstract base class for scene indexes that have one or more input scene indexes which serve as a b...
A scene index that provides a topological view of the scene as though instancing were not being used.
A wrapper around HdCollectionExpressionEvaluator that uses the "unrolled" instance proxy view of the ...
Abstract interface to scene data.
Definition sceneIndex.h:55
Observer of scene data.
An abstract base class for scene indices that evaluate path expressions against a scene.
HDSI_API HdInstancingAwareCollectionExpressionEvaluator _MakeEvaluator(const SdfPathExpression &pathExpr) const
Constructs an HdInstancingAwareCollectionExpressionEvaluator for the given pathExpr using the predica...
HDSI_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const final
Delegates to the input scene index, then calls _ModifyPrim.
HDSI_API SdfPathVector GetInstancerPrimPaths(const SdfPathSet &outermostInstancePaths) const
Given a set of outermost instance prim paths (e.g.
virtual HDSI_API void _FilterChildPrimPaths(const SdfPath &primPath, SdfPathVector *children) const
Called by GetChildPrimPaths after querying the input scene index.
HDSI_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const final
Delegates to the input scene index, then calls _FilterChildPrimPaths.
HDSI_API const HdSceneIndexBaseRefPtr & _GetInputSceneIndex() const
Returns the input scene index.
HDSI_API std::vector< HdSceneIndexBaseRefPtr > GetInputScenes() const final
Returns {_inputSceneIndex}.
virtual HDSI_API void _ModifyPrim(const SdfPath &primPath, HdSceneIndexPrim *prim) const
Called by GetPrim after querying the input scene index.
HDSI_API std::vector< HdSceneIndexBaseRefPtr > GetEncapsulatedScenes() const override
Returns {_proxyViewSceneIndex}.
virtual HDSI_API bool _IsPruned(const SdfPath &primPath) const
Override to bail early from GetPrim and GetChildPrimPaths for pruned prims.
Objects of this class represent a logical expression syntax tree consisting of SdfPathPattern s,...
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
Represents a library of predicate functions for use with SdfPredicateExpression.
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition declarePtrs.h:58
STL namespace.
Small struct representing a 'prim' in the Hydra scene index.
Definition sceneIndex.h:36