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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 #ifndef PXR_IMAGING_HDSI_PRIM_TYPE_PRUNING_SCENE_INDEX_H
7 #define PXR_IMAGING_HDSI_PRIM_TYPE_PRUNING_SCENE_INDEX_H
8 
9 #include "pxr/pxr.h"
10 
12 #include "pxr/imaging/hdsi/api.h"
13 #include "pxr/usd/sdf/pathTable.h"
14 
16 
17 #define HDSI_PRIM_TYPE_PRUNING_SCENE_INDEX_TOKENS \
18  (primTypes) \
19  (bindingToken) \
20  (doNotPruneNonPrimPaths)
21 
22 TF_DECLARE_PUBLIC_TOKENS(HdsiPrimTypePruningSceneIndexTokens, HDSI_API,
24 
26 
27 /// Scene Index that prunes prims of given type (e.g., material) and
28 /// (optionally) bindings to that prim type (e.g., materialBindings).
29 ///
30 /// Pruned prims are not removed from the scene index; instead, they
31 /// are given an empty primType and null dataSource. This is to
32 /// preserve hierarchy and allow children of the pruned types to still
33 /// exist.
34 ///
35 /// An optional bool argument specifies whether to suppress pruning for
36 /// prims at non-prim paths, and, correspondingly, leave bindings to
37 /// prims at non-prim paths unchanged.
38 ///
39 /// By default, when creating the scene index, it is disabled and does
40 /// not pruning anything.
41 ///
42 /// If an empty binding token is used, the scene index will not
43 /// prune any binding.
44 ///
45 /// \deprecated Use HdsiSceneMaterialPruningSceneIndex or
46 /// HdPrimTypeAndPathPruningSceneIndex with tautological PathPredicate instead.
47 ///
50 {
51 public:
52  HDSI_API
53  static HdsiPrimTypePruningSceneIndexRefPtr
54  New(HdSceneIndexBaseRefPtr const &inputSceneIndex,
55  HdContainerDataSourceHandle const &inputArgs);
56 
57  /// Is scene index actually prunning?
58  HDSI_API
59  bool GetEnabled() const;
60  /// Enable scene index to prune.
61  HDSI_API
62  void SetEnabled(bool);
63 
64 public: // HdSceneIndex overrides
65  HDSI_API
66  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
67  HDSI_API
68  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
69 
70  const TfToken &GetBindingToken() const { return _bindingToken; }
71 
72 protected: // HdSingleInputFilteringSceneIndexBase overrides
73  HDSI_API
74  void _PrimsAdded(
75  const HdSceneIndexBase &sender,
76  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
77  HDSI_API
78  void _PrimsRemoved(
79  const HdSceneIndexBase &sender,
80  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
81  HDSI_API
82  void _PrimsDirtied(
83  const HdSceneIndexBase &sender,
84  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
85 
86 protected:
87  HDSI_API
89  HdSceneIndexBaseRefPtr const &inputSceneIndex,
90  HdContainerDataSourceHandle const &inputArgs);
91  HDSI_API
93 
94 private:
95  // Should prim be pruned based on its type?
96  bool _PruneType(const TfToken &primType) const;
97  // Should prim be pruned based on its path?
98  bool _PrunePath(const SdfPath &path) const;
99 
100  const TfTokenVector _primTypes;
101  const TfToken _bindingToken;
102  const bool _doNotPruneNonPrimPaths;
103 
104  // Track pruned prims in a SdfPathTable. A value of true
105  // indicates a prim was filtered at that path.
106  using _PruneMap = SdfPathTable<bool>;
107  _PruneMap _pruneMap;
108 
109  bool _enabled;
110 };
111 
113 
114 #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:70
std::vector< class SdfPath > SdfPathVector
HDSI_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
const TfToken & GetBindingToken() const
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
HDSI_API void _PrimsAdded(const HdSceneIndexBase &sender, const HdSceneIndexObserver::AddedPrimEntries &entries) override
Definition: path.h:273
#define HDSI_API
Definition: api.h:23
HDSI_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
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:74
TF_DECLARE_PUBLIC_TOKENS(HdsiPrimTypePruningSceneIndexTokens, HDSI_API, HDSI_PRIM_TYPE_PRUNING_SCENE_INDEX_TOKENS)
TF_DECLARE_WEAK_AND_REF_PTRS(HdsiPrimTypePruningSceneIndex)