7#ifndef PXR_EXEC_EXEC_IR_CONTROLLER_BUILDER_H
8#define PXR_EXEC_EXEC_IR_CONTROLLER_BUILDER_H
29#include "pxr/exec/exec/builtinComputations.h"
34PXR_NAMESPACE_OPEN_SCOPE
38class ExecIr_ControllerBuilderBase {
41 ExecIr_ControllerBuilderBase(
47 virtual ~ExecIr_ControllerBuilderBase();
56 template <
typename ValueType>
58 _DesiredValueComputations(
72 template <
typename ValueType>
74 _GetExactlyOneDesiredValue(
188 template <
typename ValueType>
199 template <
typename ValueType>
206 template <
typename ValueType>
210 for (
const TfToken &attributeName : attributeNames) {
222 template <
typename ValueType>
229 template <
typename ValueType>
233 for (
const TfToken &attributeName : attributeNames) {
246 template <
typename ValueType>
258 template <
typename ValueType>
261 const TfToken &inAttributeName,
262 const TfToken &outAttributeName);
268 struct _PrivateComputationsType {
270 _PrivateComputationsType();
272 const TfToken computeInvertedForwardValue;
286template <
typename ValueType>
291 using namespace exec_registration;
299 _self.AttributeComputation(
300 attributeName, ExecIrComputations->computeDesiredValue)
301 .Callback<ValueType>([attributeName](
const VdfContext &ctx) {
303 _privateComputations->inverseCompute);
307 if (
const auto it = resultMap.
find(attributeName);
308 it != resultMap.
end()) {
309 ctx.SetOutput(it->second.Get<ValueType>());
312 ctx.SetEmptyOutput();
317 _privateComputations->inverseCompute));
331 _self.AttributeComputation(
332 attributeName, _privateComputations->computeInvertedForwardValue)
333 .Callback(+[](
const VdfContext &ctx) -> ValueType {
335 if (
const ValueType *
const desiredValue =
337 ExecIrComputations->computeDesiredValue)) {
338 return *desiredValue;
343 ExecBuiltinComputations->computeValue);
351 _forwardComputeReg.
Inputs(
354 _privateComputations->computeInvertedForwardValue)
358template <
typename ValueType>
363 using namespace exec_registration;
367 _forwardComputeReg.
Inputs(AttributeValue<ValueType>(attributeName));
370 _inverseComputeReg.
Inputs(AttributeValue<ValueType>(attributeName));
373template <
typename ValueType>
378 using namespace exec_registration;
380 _invertibleOutputAttributeNames.push_back(attributeName);
383 _DesiredValueComputations<ValueType>(attributeName);
387 _inverseComputeReg.
Inputs(
390 ExecIrComputations->computeDesiredValue)
395 _self.AttributeExpression(attributeName)
399 _privateComputations->forwardCompute);
400 const auto it = resultMap.
find(attributeName);
401 if (it != resultMap.
end()) {
402 ctx.SetOutput(it->second.Get<ValueType>());
406 "Failed to find a result value for output attribute '%s' "
409 ctx.GetNodeDebugName().c_str());
413 .GetFallback<ValueType>());
418 _privateComputations->forwardCompute));
421template <
typename ValueType>
437template <
typename ValueType>
440 const TfToken &inAttributeName,
441 const TfToken &outAttributeName)
443 using namespace exec_registration;
447 _forwardComputeReg.
Inputs(AttributeValue<ValueType>(inAttributeName));
448 _inverseComputeReg.
Inputs(AttributeValue<ValueType>(inAttributeName));
452 _self.AttributeExpression(outAttributeName)
453 .
Inputs(
Prim().AttributeValue<ValueType>(inAttributeName))
459template <
typename ValueType>
461ExecIr_ControllerBuilderBase::_DesiredValueComputations(
464 using namespace exec_registration;
470 attributeName, ExecIrComputations->explicitDesiredValue)
472 ctx.SetEmptyOutput();
482 attributeName, ExecIrComputations->computeDesiredValue)
483 .
Callback<ValueType>(&_GetExactlyOneDesiredValue<ValueType>)
486 ExecIrComputations->explicitDesiredValue),
487 IncomingConnections<ValueType>(
488 ExecIrComputations->computeDesiredValue));
491template <
typename ValueType>
493ExecIr_ControllerBuilderBase::_GetExactlyOneDesiredValue(
496 const ValueType *
const inputValue = [&]() ->
const ValueType*
498 const ValueType *foundInputValue =
500 ExecIrComputations->explicitDesiredValue);
502 for (
const ValueType &value :
504 ctx, ExecIrComputations->computeDesiredValue)) {
505 if (!foundInputValue) {
506 foundInputValue = &value;
511 "Found more than one desired value for node %s",
517 return foundInputValue;
527PXR_NAMESPACE_CLOSE_SCOPE
The top-level builder object (aka, the self variable generated by EXEC_REGISTER_COMPUTATIONS_FOR_SCHE...
Builder class used to register invertible controller computations.
void SwitchAttribute(const TfToken &attributeName)
Registers a switch attribute.
EXECIR_API ExecIrControllerBuilder(ExecComputationBuilder &self, Callback forwardCallback, Callback inverseCallback)
Constructs a builder that is used to register computations that implement an invertible controller.
ExecIrResult(*)(const VdfContext &) Callback
The type for forward and inverse controller computation calbacks.
void InvertibleOutputAttribute(const TfToken &attributeName)
Registers an invertible output attribute.
void InvertibleInputAttributes(const TfTokenVector &attributeNames)
Registers multiple invertible input attributes.
void InvertibleOutputAttributes(const TfTokenVector &attributeNames)
Registers multiple invertible output attributes.
void PassthroughAttributes(const TfToken &inAttributeName, const TfToken &outAttributeName)
Registers a pair of input, output passthrough attributes.
void NonInvertibleInputAttribute(const TfToken &attributeName)
Registers a non-invertible input attribute.
void InvertibleInputAttribute(const TfToken &attributeName)
Registers an invertible input attribute.
Class used to build prim computation definitions.
This is a space efficient container that mimics the TfHashMap API that uses a vector for storage when...
iterator find(const key_type &k)
Finds the element with key k.
iterator end()
Returns an const_iterator pointing to the end of the map.
Create or return a previously created object instance of global data.
Token for efficient comparison, assignment, and hashing of known strings.
char const * GetText() const
Return the text that this token represents.
A context is the parameter bundle passed to callbacks of computations.
VDF_API void SetEmptyOutput() const
Sets an empty value on the output.
VdfByValueOrConstRef< T > GetInputValue(const TfToken &name) const
Returns a value from the input named name of type T.
VDF_API std::string GetNodeDebugName() const
Returns the debug name for the node for this context.
VDF_API void SetOutputToReferenceInput(const TfToken &inputName) const
Sets the one and only output to have the same output value as the value on the output connected to in...
const T * GetInputValuePtr(const TfToken &name) const
Returns a pointer to the value from the input named name if the input has a valid value,...
void SetOutput(const TfToken &outputName, const T &value) const
Sets the value of the output named outputName to value.
static VDF_API VdfExecutionTypeRegistry & GetInstance()
Returns the VdfExecutionTypeRegistry singleton instance.
This class allows for construction of iterable ranges of input values.
This is a public header, but many of the symbols have private names because they are not intended for...
TfDenseHashMap< TfToken, VtValue, TfToken::HashFunctor > ExecIrResult
Map used to return results from controller forward and inverse computations.
Derived & Callback(ReturnType(*callback)(const VdfContext &))
Registers a callback function that implements the evaluation logic for a computation.
ExecPrimComputationBuilder & Inputs(Args &&... args)
Takes one or more input registrations that specify how to source input values for a prim computation.
EXEC_API ExecAttributeComputationBuilder AttributeComputation(const TfToken &attributeName, const TfToken &computationName)
Registers an attribute computation named computationName on attributes named attributeName.
#define TF_RUNTIME_ERROR(fmt, args)
Issue a generic runtime error, but continue execution.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Attribute accessor, valid for providing input to a prim computation.
Computation value specifier, valid for providing input to any computation.
Prim accessor, valid for providing input to an attribute computation.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
std::vector< TfToken > TfTokenVector
Convenience types.