HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
generativeProceduralFilteringSceneIndex.h
Go to the documentation of this file.
1 //
2 // Copyright 2024 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_GP_GENERATIVE_PROCEDURAL_FILTERING_SCENE_INDEX_H
8 #define PXR_IMAGING_HD_GP_GENERATIVE_PROCEDURAL_FILTERING_SCENE_INDEX_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdGp/api.h"
14 #include "pxr/usd/sdf/pathTable.h"
15 
16 #include <optional>
17 
19 
22 
23 /// \class HdGpGenerativeProceduralFilteringSceneIndex
24 ///
25 /// HdGpGenerativeProceduralFilteringSceneIndex is a scene index which
26 /// filters prims representing generative procedurals within its incoming
27 /// scene against a requested pattern.
28 ///
29 /// Typically, this scene index re-types (to its observers) any procedural prim
30 /// it filters to the type "skippedGenerativeProcedural" and ones that are
31 /// allowed will have their types remain the same. This scene index can also
32 /// be configured to have specific primTypes for procedurals that are skipped
33 /// or allowed.
34 ///
35 /// The hydra prim type used to identify generative procedurals can be
36 /// configured per instance of this scene index to allow for a pipeline to
37 /// stage when certain procedural prims are resolved within the chain of scene
38 /// indicies. By default that type is "generativeProcedural".
39 ///
42 {
43 public:
44  static HdGpGenerativeProceduralFilteringSceneIndexRefPtr New(
45  const HdSceneIndexBaseRefPtr &inputScene,
46  const TfTokenVector &allowedProceduralTypes) {
47  return TfCreateRefPtr(
49  inputScene, allowedProceduralTypes));
50  }
51 
52  /// This constructs a filtering scene index that will try to filter prims of
53  /// type \p targetPrimType. For each prim of this type,
54  /// \p allowedProceduralTypes will be used to determined if the procedural
55  /// is "allowed" or "skipped".
56  ///
57  /// Prims that are not of type \p targetPrimType are left alone.
58  ///
59  /// If \p allowedPrimTypeName is specified, then "allowed" prims will have
60  /// their type set to that. Otherwise, it will be set to \p targetPrimType.
61  ///
62  /// If \p skippedPrimTypeName is specified, then "skipped" prims will have
63  /// their type set to that. Otherwise, it will be set to
64  /// "skippedGenerativeProcedural".
65  static HdGpGenerativeProceduralFilteringSceneIndexRefPtr New(
66  const HdSceneIndexBaseRefPtr &inputScene,
67  const TfTokenVector &allowedProceduralTypes,
68  const std::optional<TfToken> &targetPrimTypeName,
69  const std::optional<TfToken> &allowedPrimTypeName,
70  const std::optional<TfToken> &skippedPrimTypeName) {
71  return TfCreateRefPtr(
73  inputScene, allowedProceduralTypes, targetPrimTypeName,
74  allowedPrimTypeName, skippedPrimTypeName));
75  }
76 
77  HDGP_API
78  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override;
79 
80  HDGP_API
81  SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override;
82 
83  /// Sets the allowed procedural types, replacing the existing set.
84  /// Sends _PrimsAdded notices for all prims in the input scene so that
85  /// observers re-evaluate the (possibly changed) prim types.
86  HDGP_API
87  void SetAllowedProceduralTypes(const TfTokenVector &allowedProceduralTypes);
88 
89 private:
91  const HdSceneIndexBaseRefPtr &inputScene,
92  const TfTokenVector &allowedProceduralTypes);
94  const HdSceneIndexBaseRefPtr &inputScene,
95  const TfTokenVector &allowedProceduralTypes,
96  const std::optional<TfToken> &targetPrimTypeName,
97  const std::optional<TfToken> &allowedPrimTypeName,
98  const std::optional<TfToken> &skippedPrimTypeName);
99 
100  void _PrimsAdded(
101  const HdSceneIndexBase &sender,
102  const HdSceneIndexObserver::AddedPrimEntries &entries) override;
103  void _PrimsRemoved(
104  const HdSceneIndexBase &sender,
105  const HdSceneIndexObserver::RemovedPrimEntries &entries) override;
106  void _PrimsDirtied(
107  const HdSceneIndexBase &sender,
108  const HdSceneIndexObserver::DirtiedPrimEntries &entries) override;
109 
110  TfToken _GetProceduralType(HdSceneIndexPrim const& prim) const;
111 
112  enum class _ShouldSkipResult {
113  Ignore = 0,
114  Skip,
115  Allow,
116  };
117  _ShouldSkipResult _ShouldSkipPrim(HdSceneIndexPrim const& prim) const;
118 
119  // Returns the "allowed" type, "skipped" type, or `std::nullopt`.
120  std::optional<TfToken> _GetOverridePrimTypeForPrim(
121  HdSceneIndexPrim const& prim) const;
122 
123  std::set<TfToken> _allowedProceduralTypes;
124  bool _allowAny = false;
125 
126  const TfToken _targetPrimTypeName;
127 
128  TfToken _allowedPrimTypeName;
129  TfToken _skippedPrimTypeName;
130 };
131 
133 
134 #endif
static HdGpGenerativeProceduralFilteringSceneIndexRefPtr New(const HdSceneIndexBaseRefPtr &inputScene, const TfTokenVector &allowedProceduralTypes)
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1190
#define HDGP_API
Definition: api.h:23
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
TF_DECLARE_REF_PTRS(HdGpGenerativeProceduralFilteringSceneIndex)
static HdGpGenerativeProceduralFilteringSceneIndexRefPtr New(const HdSceneIndexBaseRefPtr &inputScene, const TfTokenVector &allowedProceduralTypes, const std::optional< TfToken > &targetPrimTypeName, const std::optional< TfToken > &allowedPrimTypeName, const std::optional< TfToken > &skippedPrimTypeName)
Definition: token.h:70
std::vector< class SdfPath > SdfPathVector
HDGP_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:280
HDGP_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
HDGP_API void SetAllowedProceduralTypes(const TfTokenVector &allowedProceduralTypes)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74