HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filteringSceneIndex.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 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_HD_FILTERING_SCENE_INDEX_H
8 #define PXR_IMAGING_HD_FILTERING_SCENE_INDEX_H
9 
10 #include "pxr/pxr.h"
11 
12 #include <set>
13 #include <unordered_map>
14 
16 #include "pxr/base/tf/singleton.h"
17 
18 #include "pxr/usd/sdf/path.h"
19 
23 
25 
27 
28 ///
29 /// \class HdFilteringSceneIndexBase
30 ///
31 /// An abstract base class for scene indexes that have one or more input scene
32 /// indexes which serve as a basis for their own scene.
33 ///
35 {
36 public:
37  virtual std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const = 0;
38 };
39 
40 ///
41 /// \class HdEncapsulatingSceneIndexBase
42 ///
43 /// A mix-in class for scene indices that implement their behaviour by
44 /// creating other scene indices (internally).
45 ///
46 /// Note that this can be combined with the HdFilteringSceneIndexBase.
47 ///
48 /// The intention here is that we can traverse the scene index topology
49 /// at different levels of detail in, e.g., a piece of software to display
50 /// the scene index graph.
51 ///
52 /// More precisely, the topology of scene indices should be imagined as a
53 /// nested directed acyclic graph, that is, each node of the graph itself
54 /// contains a graph. The high-level directed acyclic graph structure is
55 /// obtained by recursing GetInputScenes. A node itself contains a graph
56 /// if the node corresponds to an encapsulating scene index. This nested
57 /// graph consists of the scene indices internal to the encapsulating scene
58 /// index as defined below. We also need some extra information in how
59 /// some of the internal scene indices are connected to the external scene
60 /// indices to completely describe the scene index topology.
61 ///
62 /// Given a scene index that is both an HdFilteringSceneIndexBase and an
63 /// HdEncapsulatingSceneIndexBase, we call the result of GetInputScenes()
64 /// the "external" scene indices. Now consider the scene indices that can be
65 /// reached by first calling GetEncapsulatingScenes and then recursing
66 /// GetInputScenes until we hit an external scene index. We call these scene
67 /// indices "internal". If the scene index is not subclassing from
68 /// HdFilteringSceneIndexBase, we compute the internal scene indices in the
69 /// same way under the premise that there are no external scene indices.
70 ///
71 /// If this mix-in class is combined with HdFilteringSceneIndexBase, then
72 /// GetInputScenes() should be a subset of the scene indices obtained by
73 /// recursively calling GetInputScenes or GetEncapsulatedScenes (or a mix of
74 /// those).
75 ///
76 ///
77 /// Example:
78 /// B filtering scene index with inputs {A}
79 /// C filtering scene index with inputs {B}
80 /// D filtering scene index with inputs {B}
81 /// E filtering scene index with inputs {C, D}
82 /// F filtering and encapsulating scene index with inputs {B} and
83 /// encapsulated scenes {E}
84 /// G filtering scene index with inputs {F}
85 ///
86 /// Nested scene index Graph:
87 ///
88 /// A
89 /// |
90 /// B
91 /// / \ |
92 /// -F------/---\--------
93 /// | / \ |
94 /// | C D |
95 /// | \ / |
96 /// | \ / |
97 /// | \ / |
98 /// | E |
99 /// | |
100 /// ---------------------
101 /// |
102 /// G
103 ///
105 {
106 public:
107  virtual std::vector<HdSceneIndexBaseRefPtr>
108  GetEncapsulatedScenes() const = 0;
109 
110  static HdEncapsulatingSceneIndexBase * Cast(const HdSceneIndexBaseRefPtr &);
111 };
112 
114 
115 ///
116 /// \class HdSingleInputFilteringSceneIndexBase
117 ///
118 /// An abstract base class for a filtering scene index that observes a single
119 /// input scene index.
120 ///
122 {
123 public:
124  HD_API
125  std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const final;
126 
127 protected:
128  HD_API
130  const HdSceneIndexBaseRefPtr &inputSceneIndex);
131 
132  virtual void _PrimsAdded(
133  const HdSceneIndexBase &sender,
134  const HdSceneIndexObserver::AddedPrimEntries &entries) = 0;
135 
136  virtual void _PrimsRemoved(
137  const HdSceneIndexBase &sender,
138  const HdSceneIndexObserver::RemovedPrimEntries &entries) = 0;
139 
140  virtual void _PrimsDirtied(
141  const HdSceneIndexBase &sender,
142  const HdSceneIndexObserver::DirtiedPrimEntries &entries) = 0;
143 
144  // Base implementation converts prim removed messages.
145  HD_API
146  virtual void _PrimsRenamed(
147  const HdSceneIndexBase &sender,
149 
150  /// Returns the input scene.
151  ///
152  /// It is always safe to call and dereference this return value. If this
153  /// was constructed with a null scene index, a fallback one will be used.
154  const HdSceneIndexBaseRefPtr &_GetInputSceneIndex() const {
155  return _inputSceneIndex;
156  }
157 
158 private:
159 
160  HdSceneIndexBaseRefPtr _inputSceneIndex;
161 
162  friend class _Observer;
163 
164  class _Observer : public HdSceneIndexObserver
165  {
166  public:
167  _Observer(HdSingleInputFilteringSceneIndexBase *owner)
168  : _owner(owner) {}
169 
170  HD_API
171  void PrimsAdded(
172  const HdSceneIndexBase &sender,
173  const AddedPrimEntries &entries) override;
174 
175  HD_API
176  void PrimsRemoved(
177  const HdSceneIndexBase &sender,
178  const RemovedPrimEntries &entries) override;
179 
180  HD_API
181  void PrimsDirtied(
182  const HdSceneIndexBase &sender,
183  const DirtiedPrimEntries &entries) override;
184 
185  HD_API
186  void PrimsRenamed(
187  const HdSceneIndexBase &sender,
188  const RenamedPrimEntries &entries) override;
189  private:
190  HdSingleInputFilteringSceneIndexBase *_owner;
191  };
192 
193  _Observer _observer;
194 
195 };
196 
198 
199 #endif // PXR_IMAGING_HD_FILTERING_SCENE_INDEX_H
virtual std::vector< HdSceneIndexBaseRefPtr > GetInputScenes() const =0
HD_API std::vector< HdSceneIndexBaseRefPtr > GetInputScenes() const final
#define HD_API
Definition: api.h:23
virtual void _PrimsRemoved(const HdSceneIndexBase &sender, const HdSceneIndexObserver::RemovedPrimEntries &entries)=0
virtual std::vector< HdSceneIndexBaseRefPtr > GetEncapsulatedScenes() const =0
HD_API HdSingleInputFilteringSceneIndexBase(const HdSceneIndexBaseRefPtr &inputSceneIndex)
virtual void _PrimsDirtied(const HdSceneIndexBase &sender, const HdSceneIndexObserver::DirtiedPrimEntries &entries)=0
virtual HD_API void _PrimsRenamed(const HdSceneIndexBase &sender, const HdSceneIndexObserver::RenamedPrimEntries &entries)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_AND_REF_PTRS(HdFilteringSceneIndexBase)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static HdEncapsulatingSceneIndexBase * Cast(const HdSceneIndexBaseRefPtr &)
virtual void _PrimsAdded(const HdSceneIndexBase &sender, const HdSceneIndexObserver::AddedPrimEntries &entries)=0
const HdSceneIndexBaseRefPtr & _GetInputSceneIndex() const