HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
collectionExpressionEvaluator.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 
8 #ifndef PXR_IMAGING_HD_COLLECTION_EXPRESSION_EVALUATOR_H
9 #define PXR_IMAGING_HD_COLLECTION_EXPRESSION_EVALUATOR_H
10 
11 #include "pxr/pxr.h"
12 
13 #include "pxr/imaging/hd/api.h"
14 
16 
19 
20 #include <vector>
21 
23 
24 class HdSceneIndexBase;
25 struct HdSceneIndexPrim;
26 class SdfPathExpression;
27 
28 using SdfPathVector = std::vector<class SdfPath>;
29 
31 
34 
35 ///
36 /// \class HdCollectionExpressionEvaluator
37 ///
38 /// Evaluates SdfPathExpressions with prims from a given HdSceneIndex.
39 ///
41 {
42 public:
43  /// Default c'tor. Constructs an empty evaluator.
45 
46  /// Constructs an evaluator that evaluates \p expr on prims from
47  /// \p sceneIndex using the predicates in HdGetCollectionPredicateLibrary().
48  ///
49  HD_API
51  const HdSceneIndexBaseRefPtr &sceneIndex,
52  const SdfPathExpression &expr);
53 
54  /// Constructs an evaluator that evaluates \p expr on prims from
55  /// \p sceneIndex using the predicates in \p predicateLib.
56  ///
57  HD_API
59  const HdSceneIndexBaseRefPtr &sceneIndex,
60  const SdfPathExpression &expr,
61  const HdCollectionPredicateLibrary &predicateLib);
62 
63  /// Returns true if the evaluator has an invalid scene index or an empty
64  /// underlying SdfPathExpressionEval object.
65  bool IsEmpty() const {
66  return !_sceneIndex || _eval.IsEmpty();
67  }
68 
69  /// Returns the scene index provided during construction, or nullptr if
70  /// it was default constructed.
71  HdSceneIndexBaseRefPtr
72  GetSceneIndex() const {
73  return _sceneIndex;
74  }
75 
76  /// Returns the result of evaluating the expression (provided on
77  /// construction) against the scene index prim at \p path.
78  ///
79  HD_API
81  Match(const SdfPath &path) const;
82 
83  /// Updates \p result with the paths of all prims in the
84  /// subtree at \p rootPath (including \p rootPath) that match the
85  /// expression (provided on construction).
86  ///
87  /// An empty evaluator would leave \p result unaffected.
88  ///
89  /// \note: \p result is guaranteed to have unique paths because a scene
90  /// index prim is traversed at most once.
91  ///
92  HD_API
93  void
95  const SdfPath &rootPath,
96  SdfPathVector * const result) const;
97 
98  /// \enum MatchKind
99  ///
100  /// Option to configure the paths returned by PopulateMatches.
101  ///
102  /// \li MatchAll: Return the paths of all prims that match the expression.
103  ///
104  /// \li ShallowestMatches: Return the paths of just the top level
105  /// prims that match, in a level-order or BFS sense.
106  ///
107  /// \li ShallowestMatchesAndAllDescendants: Returns the paths of the top
108  /// level prims that match the expression, as well as all their
109  /// descendants.
110  ///
111  enum MatchKind {
115  };
116 
117  /// Utility that uses \p matchKind to configure the paths returned by
118  /// \p result when evaluating the expression for the subtree at \p rootPath
119  /// (including \p rootPath).
120  ///
121  /// If \p matchKind is MatchAll, the result is identical to that returned
122  /// by PopulateAllMatches.
123  ///
124  /// Example:
125  /// Consider a scene index with prims:
126  /// {"/a", "/a/foobar", "/a/foobar/b", "/a/foobar/bar", "/a/foobar/baz"}
127  ///
128  /// PopulateMatches would return different results for the expression
129  /// "/a/*bar" depending on \p matchKind as follows:
130  ///
131  /// MatchAll : {"/a/foobar", "/a/foobar/bar"}
132  ///
133  /// ShallowestMatches : {"/a/foobar"}
134  ///
135  /// ShallowestMatchesAndAllDescendants: {"/a/foobar", "/a/foobar/b",
136  /// "/a/foobar/bar", "/a/foobar/baz"}
137  ///
138  /// \note: \p result is guaranteed to have unique paths because a scene
139  /// index prim is traversed at most once.
140  ///
141  HD_API
142  void
144  const SdfPath &rootPath,
145  MatchKind matchKind,
146  SdfPathVector * const result) const;
147 
148 private:
149  HdSceneIndexBaseRefPtr _sceneIndex;
150 
152  _PrimEvaluator _eval;
153 };
154 
155 
157 
158 #endif // PXR_IMAGING_HD_COLLECTION_EXPRESSION_EVALUATOR_H
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
#define HD_API
Definition: api.h:23
**But if you need a result
Definition: thread.h:622
HD_API void PopulateMatches(const SdfPath &rootPath, MatchKind matchKind, SdfPathVector *const result) const
TF_DECLARE_WEAK_AND_REF_PTRS(HdSceneIndexBase)
std::vector< class SdfPath > SdfPathVector
HdSceneIndexBaseRefPtr GetSceneIndex() const
Definition: path.h:273
HD_API void PopulateAllMatches(const SdfPath &rootPath, SdfPathVector *const result) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HD_API SdfPredicateFunctionResult Match(const SdfPath &path) const
HdCollectionExpressionEvaluator()=default
Default c'tor. Constructs an empty evaluator.