HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
primTypePruningSceneIndex.h
Go to the documentation of this file.
1 //
2 // Copyright 2023 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 #ifndef PXR_IMAGING_HDSI_PRIM_TYPE_PRUNING_SCENE_INDEX_H
24 #define PXR_IMAGING_HDSI_PRIM_TYPE_PRUNING_SCENE_INDEX_H
25 
26 #include "pxr/pxr.h"
27 
29 #include "pxr/imaging/hdsi/api.h"
30 #include "pxr/usd/sdf/pathTable.h"
31 
33 
34 #define HDSI_PRIM_TYPE_PRUNING_SCENE_INDEX_TOKENS \
35  (primTypes) \
36  (bindingToken) \
37  (doNotPruneNonPrimPaths)
38 
39 TF_DECLARE_PUBLIC_TOKENS(HdsiPrimTypePruningSceneIndexTokens, HDSI_API,
41 
43 
44 /// Scene Index that prunes prims of given type (e.g., material) and
45 /// (optionally) bindings to that prim type (e.g., materialBindings).
46 ///
47 /// Pruned prims are not removed from the scene index; instead, they
48 /// are given an empty primType and null dataSource. This is to
49 /// preserve hierarchy and allow children of the pruned types to still
50 /// exist.
51 ///
52 /// An optional bool argument specifies whether to suppress pruning for
53 /// prims at non-prim paths, and, correspondingly, leave bindings to
54 /// prims at non-prim paths unchanged.
55 ///
56 /// By default, when creating the scene index, it is disabled and does
57 /// not pruning anything.
58 ///
59 /// If an empty binding token is used, the scene index will not
60 /// prune any binding.
61 ///
64 {
65 public:
66  HDSI_API
67  static HdsiPrimTypePruningSceneIndexRefPtr
68  New(HdSceneIndexBaseRefPtr const &inputSceneIndex,
69  HdContainerDataSourceHandle const &inputArgs);
70 
71  /// Is scene index actually prunning?
72  HDSI_API
73  bool GetEnabled() const;
74  /// Enable scene index to prune.
75  HDSI_API
76  void SetEnabled(bool);
77 
78 public: // HdSceneIndex overrides
79  HDSI_API
80  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
81  HDSI_API
82  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
83 
84  const TfToken &GetBindingToken() const { return _bindingToken; }
85 
86 protected: // HdSingleInputFilteringSceneIndexBase overrides
87  HDSI_API
88  void _PrimsAdded(
89  const HdSceneIndexBase &sender,
90  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
91  HDSI_API
92  void _PrimsRemoved(
93  const HdSceneIndexBase &sender,
94  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
95  HDSI_API
96  void _PrimsDirtied(
97  const HdSceneIndexBase &sender,
98  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
99 
100 protected:
101  HDSI_API
103  HdSceneIndexBaseRefPtr const &inputSceneIndex,
104  HdContainerDataSourceHandle const &inputArgs);
105  HDSI_API
107 
108 private:
109  // Should prim be pruned based on its type?
110  bool _PruneType(const TfToken &primType) const;
111  // Should prim be pruned based on its path?
112  bool _PrunePath(const SdfPath &path) const;
113 
114  const TfTokenVector _primTypes;
115  const TfToken _bindingToken;
116  const bool _doNotPruneNonPrimPaths;
117 
118  // Track pruned prims in a SdfPathTable. A value of true
119  // indicates a prim was filtered at that path.
120  using _PruneMap = SdfPathTable<bool>;
121  _PruneMap _pruneMap;
122 
123  bool _enabled;
124 };
125 
127 
128 #endif
HDSI_API HdsiPrimTypePruningSceneIndex(HdSceneIndexBaseRefPtr const &inputSceneIndex, HdContainerDataSourceHandle const &inputArgs)
HDSI_API void _PrimsRemoved(const HdSceneIndexBase &sender, const HdSceneIndexObserver::RemovedPrimEntries &entries) override
HDSI_API void _PrimsDirtied(const HdSceneIndexBase &sender, const HdSceneIndexObserver::DirtiedPrimEntries &entries) override
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
HDSI_API void SetEnabled(bool)
Enable scene index to prune.
#define HDSI_PRIM_TYPE_PRUNING_SCENE_INDEX_TOKENS
HDSI_API ~HdsiPrimTypePruningSceneIndex() override
Definition: token.h:87
HDSI_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
const TfToken & GetBindingToken() const
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
HDSI_API void _PrimsAdded(const HdSceneIndexBase &sender, const HdSceneIndexObserver::AddedPrimEntries &entries) override
Definition: path.h:291
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:212
#define HDSI_API
Definition: api.h:40
HDSI_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
static HDSI_API HdsiPrimTypePruningSceneIndexRefPtr New(HdSceneIndexBaseRefPtr const &inputSceneIndex, HdContainerDataSourceHandle const &inputArgs)
HDSI_API bool GetEnabled() const
Is scene index actually prunning?
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
TF_DECLARE_PUBLIC_TOKENS(HdsiPrimTypePruningSceneIndexTokens, HDSI_API, HDSI_PRIM_TYPE_PRUNING_SCENE_INDEX_TOKENS)
TF_DECLARE_WEAK_AND_REF_PTRS(HdsiPrimTypePruningSceneIndex)