Loading...
Searching...
No Matches
shaderNodeQuery.h
1//
2// Copyright 2025 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_USD_SDR_SHADER_NODE_QUERY_H
9#define PXR_USD_SDR_SHADER_NODE_QUERY_H
10
11#include "pxr/pxr.h"
12#include "pxr/usd/sdr/api.h"
13#include "pxr/base/tf/type.h"
14#include "pxr/base/vt/value.h"
16
17#include <functional>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
21class SdrRegistry;
23
64public:
65 typedef std::function<bool (SdrShaderNodeConstPtr)> FilterFn;
66
99 SDR_API
101
104 SDR_API
105 SdrShaderNodeQuery& SelectDistinct(const std::vector<TfToken>& key);
106
129
132 SDR_API
133 SdrShaderNodeQuery& NodeValueIs(const TfToken& key, const VtValue& value);
134
135 template <typename T>
136 SdrShaderNodeQuery& NodeValueIs(const TfToken& key, const T& value) {
137 return NodeValueIs(key, VtValue(value));
138 }
139
142 SDR_API
144 const std::vector<VtValue>& values);
145
148 SDR_API
150
153 SDR_API
155
156 template <typename T>
157 SdrShaderNodeQuery& NodeValueIsNot(const TfToken& key, const T& value) {
158 return NodeValueIsNot(key, VtValue(value));
159 }
160
164 SDR_API
166 const std::vector<VtValue>& values);
167
170 SDR_API
172
174
180 SDR_API
182
186 SDR_API
188
189private:
190 friend class SdrRegistry;
191
192 std::vector<std::pair<TfToken, VtValue>> _hasValues;
193 std::vector<std::pair<TfToken, std::vector<VtValue>>> _hasOneOfValues;
194 std::vector<std::pair<TfToken, VtValue>> _lacksValues;
195 std::vector<std::pair<TfToken, std::vector<VtValue>>> _lacksAllOfValues;
196 std::vector<TfToken> _selectKeys;
197 std::vector<FilterFn> _customFilters;
198};
199
202public:
207 const TfTokenVector& GetKeys() const & { return _keys; }
208
210 TfTokenVector GetKeys() && { return std::move(_keys); }
211
224 const std::vector<std::vector<VtValue>>& GetValues() const & { return _values; }
225
227 std::vector<std::vector<VtValue>> GetValues() && {
228 return std::move(_values);
229 }
230
238 template <class T>
239 std::vector<std::vector<T>> GetValuesAs() const {
240 std::vector<std::vector<T>> result;
241 result.reserve(_values.size());
242 for (const std::vector<VtValue>& row : _values) {
243 std::vector<T> convertedRows;
244 convertedRows.reserve(row.size());
245 for (const VtValue& value : row) {
246 const VtValue convertedValue = VtValue::Cast<T>(value);
247 if (convertedValue.IsEmpty()) {
249 "Failed to get value of type %s from value '%s'",
250 typeid(T).name(), TfStringify(value).c_str());
251 return {};
252 } else {
253 convertedRows.push_back(convertedValue);
254 }
255 result.push_back(convertedRows);
256 }
257 }
258 return result;
259 }
260
262 SDR_API
263 std::vector<std::vector<std::string>> GetStringifiedValues() const;
264
276 SDR_API
277 std::vector<SdrShaderNodePtrVec> GetShaderNodesByValues() const;
278
283 SDR_API
284 SdrShaderNodePtrVec GetAllShaderNodes() const;
285
286private:
287 friend class SdrRegistry;
288
290 bool _IsValid() const;
291
292 std::vector<TfToken> _keys;
293 std::vector<std::vector<VtValue>> _values;
294 std::vector<SdrShaderNodePtrVec> _nodes;
295};
296
297PXR_NAMESPACE_CLOSE_SCOPE
298
299#endif // PXR_USD_SDR_SHADER_NODE_QUERY_H
The registry provides access to shader node information.
Definition: registry.h:51
SdrShaderNodeQuery is a constraint-based query builder object that operates on all SdrShaderNodes con...
SDR_API SdrShaderNodeQuery & NodeValueIsNot(const TfToken &key, const VtValue &value)
Only keep SdrShaderNodes whose value returned from SdrShaderNode::GetDataForKey(key) doesn't match th...
SDR_API SdrShaderNodeQuery & CustomFilter(FilterFn fn)
Supply a custom filter to this query.
SDR_API SdrShaderNodeQuery & NodeHasNoValueFor(const TfToken &key)
Only keep SdrShaderNodes that don't have an existing value for for the given key.
SDR_API SdrShaderNodeQuery & NodeHasValueFor(const TfToken &key)
Only keep SdrShaderNodes that have an existing value for for the given key.
SDR_API SdrShaderNodeQuery & NodeValueIs(const TfToken &key, const VtValue &value)
Only keep SdrShaderNodes whose value returned from SdrShaderNode::GetDataForKey(key) matches the give...
SDR_API SdrShaderNodeQuery & NodeValueIsNotIn(const TfToken &key, const std::vector< VtValue > &values)
Only keep SdrShaderNodes whose value returned from SdrShaderNode::GetDataForKey(key) doesn't match an...
SDR_API SdrShaderNodeQuery & NodeValueIsIn(const TfToken &key, const std::vector< VtValue > &values)
Only keep SdrShaderNodes whose value returned from SdrShaderNode::GetDataForKey(key) matches any of t...
SDR_API SdrShaderNodeQuery & SelectDistinct(const std::vector< TfToken > &key)
Specify multiple keys to query data for.
SDR_API SdrShaderNodeQueryResult Run()
Convenience to run this query on the SdrRegistry.
SDR_API SdrShaderNodeQuery & SelectDistinct(const TfToken &key)
SelectDistinct asks for distinct information from SdrShaderNodes via the SdrShaderNode::GetDataForKey...
SdrShaderNodeQueryResult stores the results of an SdrShaderNodeQuery.
SDR_API std::vector< SdrShaderNodePtrVec > GetShaderNodesByValues() const
Gets shader nodes, grouped by value rows.
std::vector< std::vector< T > > GetValuesAs() const
Convenience to convert all values to T.
SDR_API std::vector< std::vector< std::string > > GetStringifiedValues() const
Get string representations of all values, as provided by TfStringify.
TfTokenVector GetKeys() &&
Overload for rvalues, move out the keys.
std::vector< std::vector< VtValue > > GetValues() &&
Overload for rvalues, move out the values.
const std::vector< std::vector< VtValue > > & GetValues() const &
Returns distinct "list of values" extracted from SdrShaderNodes corresponding to keys requested by Se...
const TfTokenVector & GetKeys() const &
Returns keys requested by SelectDistinct calls on SdrShaderNodeQuery in the order they were added to ...
SDR_API SdrShaderNodePtrVec GetAllShaderNodes() const
Returns all shader nodes that match the constraints of the query.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
bool IsEmpty() const
Returns true iff this value is empty.
Definition: value.h:1227
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Definition: diagnostic.h:68
std::string TfStringify(const T &v)
Convert an arbitrary type into a string.
Definition: stringUtils.h:562
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440