ag_functions module
Module ag_functions provides the definition of the classes FunctionContext,
used for making it simpler to define functions using the ag_types classes.
- class autograph.ag_functions.FunctionContext(doc, fn_node=None, name=None, use_constant_cache=True, layout_nodes=True, remove_unused_nodes=True)
Bases:
objectClass helping out generating functions by keeping track of the document and the root node in which the construction happens
- input_parameter(name, widget_type)
Creates an input parameter for the graph and returns the node for accessing it.
- Parameters:
name (string) – The name of the input parameter
widget_type (
WidgetEnum) – The type with its visual representation
- Returns:
- variable(self, name, widget_type, use_param_type=False)
Creates a reference to a variable in the graph and returns the node for accessing it.
- Parameters:
name (string) – The name of the input parameter
widget_type (
WidgetEnum) – The type with its visual representationuse_param_type (bool) – use
ParamTypeEnuminstead ofWidgetEnum
- Returns:
- constant(constant, t=None)
Creates a constant
- Parameters:
constant (int, bool, float, [int], [float]) – The constant value
t (None or a class such as Float3) – Type constructor None means autodetect
- Returns:
- import_external_function(path)
Imports a function from the same document as the function is created in
- Parameters:
path (string) – Path to function to import
- Returns:
Typethe node representing the imported function
- import_local_function(name)
Imports a function from an external file
- Parameters:
name (string) – Name of function to import
- Returns:
Typethe node representing the imported function
- generate(output_node)
Finalizes function generation.
- dot(a, b)
Dot product
- sqrt(a)
Sqrt
- atan2(a)
Atan2
- abs_of(a)
Modulus, or Absolute value, of a.
- log(a)
Log
- exp(a)
Exp
- log2(a)
Log2
- pow2(a)
Pow2
- floor(a)
Floor
- ceil(a)
Ceil
- cos(a)
Cos
- sin(a)
Sin
- tan(a)
Tan
- rand(a)
Rand
- cartesian(a, b)
Cartesian
- max_of(a, b)
Maximum of a and b
- Parameters:
a (
VectorType, int, float, list of float or list of int) – input parameter 1b (
VectorType, int, float, list of float or list of int) – input parameter 2
- Returns:
- maximum(*values)
Maximum value of the values
- Parameters:
values (
VectorType, int, float, list of float or list of int) – input values- Returns:
- min_of(a, b)
Minimum of a and b
- Parameters:
a (
VectorType, int, float, list of float or list of int) – input parameter 1b (
VectorType, int, float, list of float or list of int) – input parameter 2
- Returns:
- minimum(*values)
Minimum value of the values
- Parameters:
values (
VectorType, int, float, list of float or list of int) – input values- Returns:
- clamp(a, b, x)
Clamp value x between a and b.
- Parameters:
a (
VectorType, int, float, list of float or list of int) – min value of clamped xb (
VectorType, int, float, list of float or list of int) – max value of clamped xx – value to clamp
- Returns:
- lerp(a, b, x)
Lerp
- swizzle_float1(src, out_vars)
Swizzle Float1
- swizzle_float2(src, out_vars)
Swizzle Float2
- swizzle_float3(src, out_vars)
Swizzle Float3
- swizzle_float4(src, out_vars)
Swizzle Float4
- swizzle_int1(src, out_vars)
Swizzle Int1
- swizzle_int2(src, out_vars)
Swizzle Int2
- swizzle_int3(src, out_vars)
Swizzle Int3
- swizzle_int4(src, out_vars)
Swizzle Int4
- expand_to_int2(src, fill)
Expands a Int1 to Int2
- expand_to_int3(src, fill)
Expands a Int1 or Int2 to Int3
- expand_to_int4(src, fill)
Expands a Int1, Int2 or Int3 to Int4
- expand_to_float2(src, fill)
Expands a Float1 to Float2
- expand_to_float3(src, fill)
Expands a Float1 or Float2 to Float3
- expand_to_float4(src, fill)
Expands a Float1, Float2 or Float3 to Float4
- expand(*vectors)
Expand two vector to a vector of the appropriate type and dimension.
The sum of the dimension of the input vectors must not be larger than 4. Plus all input vectors must be integers or all input vectors must be float.
- Parameters:
vectors (
VectorType, int, float, list of int, list of float) – vectors to concatenate- Returns:
- cast_to_float2(src)
Casts an Int2 to Float2
- cast_to_float3(src)
Casts an Int3 to Float3
- cast_to_float4(src)
Casts an Int4 to Float4
- auto_cast_to_float(src)
Casts a numeric vector to a float vector of the same dimension
- cast_to_int2(src)
Casts a Float2 to Int2
- cast_to_int3(src)
Casts a Float3 to Int3
- cast_to_int4(src)
Casts a Float4 to Int4
- auto_cast_to_int(src)
Casts a numeric vector to an Int vector of the same dimension
- if_else(condition, value_on_true, value_on_false)
Choose one of two values based on a condition
- Parameters:
condition (
Booleanor bool) – The condition to select onvalue_on_true (
VectorType, float, int, list of float or list of int) – Return value for truevalue_on_false (
VectorType, float, int, list of float or list of int) – Return value for false
- Returns:
- seq(a, b)
Execute all nodes resulting in branch a then execute all nodes resulting in branch b. Outputs the output of branch b.
- sequence(*values)
Execute all nodes in sequence and output the output of the last input.
- set_var(a, name)
Set a variable name to the give value.
- create_color_sampler(pos, input_index)
Creates a color sampler
- Parameters:
pos (
Float2or list of float) – Point to sampleinput_index (int) – Index of input to sample from
filtering_mode (
FilteringEnum) – Filter to use for the sampler
- Returns:
- create_gray_sampler(pos, input_index)
Creates a gray scale sampler
- Parameters:
pos (
Float2or list of float) – Point to sampleinput_index (int) – Index of input to sample from
filtering_mode (
FilteringEnum) – Filter to use for the sampler
- Returns:
- autograph.ag_functions.generate_function(fn, doc, fn_node=None, name=None, layout_nodes=True, remove_unused_nodes=True)
Generates a function by calling back to the generator function
- Parameters:
fn (Python function, taking as unique parameter a
FunctionContext) – Function taking a FunctionContext as input that generates the actual operationsdoc (
SBSDocument) – The document to create the network infn_node (
SBSDynamicValue) – A function node in which the function should be created, must be None if the name is not Nonename (string) – Name of the function to be created. Must be None if fn_node is not None
layout_nodes (bool) – Whether the nodes should be laid out left to right
remove_unused_nodes (bool) – Whether nodes not connected to the output node should be removed. Only works if layout_nodes is true
- Returns:
function to call to create node