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
63public:
64 typedef std::function<bool (SdrShaderNodeConstPtr)> FilterFn;
65
98 SDR_API
100
103 SDR_API
104 SdrShaderNodeQuery& SelectDistinct(const std::vector<TfToken>& key);
105
128
131 SDR_API
132 SdrShaderNodeQuery& NodeValueIs(const TfToken& key, const VtValue& value);
133
134 template <typename T>
135 SdrShaderNodeQuery& NodeValueIs(const TfToken& key, const T& value) {
136 return NodeValueIs(key, VtValue(value));
137 }
138
141 SDR_API
143 const std::vector<VtValue>& values);
144
147 SDR_API
149
152 SDR_API
154
155 template <typename T>
156 SdrShaderNodeQuery& NodeValueIsNot(const TfToken& key, const T& value) {
157 return NodeValueIsNot(key, VtValue(value));
158 }
159
163 SDR_API
165 const std::vector<VtValue>& values);
166
169 SDR_API
171
173
179 SDR_API
181
185 SDR_API
187
188private:
189 friend class SdrRegistry;
190
191 std::vector<std::pair<TfToken, VtValue>> _hasValues;
192 std::vector<std::pair<TfToken, std::vector<VtValue>>> _hasOneOfValues;
193 std::vector<std::pair<TfToken, VtValue>> _lacksValues;
194 std::vector<std::pair<TfToken, std::vector<VtValue>>> _lacksAllOfValues;
195 std::vector<TfToken> _selectKeys;
196 std::vector<FilterFn> _customFilters;
197};
198
201public:
206 const TfTokenVector& GetKeys() const & { return _keys; }
207
209 TfTokenVector GetKeys() && { return std::move(_keys); }
210
223 const std::vector<std::vector<VtValue>>& GetValues() const & { return _values; }
224
226 std::vector<std::vector<VtValue>> GetValues() && {
227 return std::move(_values);
228 }
229
237 template <class T>
238 std::vector<std::vector<T>> GetValuesAs() const {
239 std::vector<std::vector<T>> result;
240 result.reserve(_values.size());
241 for (const std::vector<VtValue>& row : _values) {
242 std::vector<T> convertedRows;
243 convertedRows.reserve(row.size());
244 for (const VtValue& value : row) {
245 const VtValue convertedValue = VtValue::Cast<T>(value);
246 if (convertedValue.IsEmpty()) {
248 "Failed to get value of type %s from value '%s'",
249 typeid(T).name(), TfStringify(value).c_str());
250 return {};
251 } else {
252 convertedRows.push_back(convertedValue);
253 }
254 result.push_back(convertedRows);
255 }
256 }
257 return result;
258 }
259
261 SDR_API
262 std::vector<std::vector<std::string>> GetStringifiedValues() const;
263
272 SDR_API
273 std::vector<SdrShaderNodePtrVec> GetShaderNodesByValues() const;
274
276 SDR_API
277 SdrShaderNodePtrVec GetAllShaderNodes() const;
278
279private:
280 friend class SdrRegistry;
281
282 std::vector<TfToken> _keys;
283 std::vector<std::vector<VtValue>> _values;
284 std::vector<SdrShaderNodePtrVec> _nodes;
285};
286
287PXR_NAMESPACE_CLOSE_SCOPE
288
289#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