Blender V4.3
blender::fn Namespace Reference

Namespaces

namespace  detail
 
namespace  lazy_function
 
namespace  multi_function
 
namespace  tests
 

Classes

class  Field
 
class  FieldConstant
 
class  FieldContext
 
class  FieldEvaluator
 
class  FieldInput
 
struct  FieldInputs
 
class  FieldNode
 
class  FieldOperation
 
struct  FieldTreeInfo
 
class  GField
 
class  GFieldBase
 
class  GFieldRef
 
class  IndexFieldInput
 

Enumerations

enum class  FieldNodeType { Input , Operation , Constant }
 

Functions

Field Evaluation
Vector< GVArrayevaluate_fields (ResourceScope &scope, Span< GFieldRef > fields_to_evaluate, const IndexMask &mask, const FieldContext &context, Span< GVMutableArray > dst_varrays={})
 
static FieldTreeInfo preprocess_field_tree (Span< GFieldRef > entry_fields)
 
static Vector< GVArrayget_field_context_inputs (ResourceScope &scope, const IndexMask &mask, const FieldContext &context, const Span< std::reference_wrapper< const FieldInput > > field_inputs)
 
static Set< GFieldReffind_varying_fields (const FieldTreeInfo &field_tree_info, Span< GVArray > field_context_inputs)
 
static void build_multi_function_procedure_for_fields (mf::Procedure &procedure, ResourceScope &scope, const FieldTreeInfo &field_tree_info, Span< GFieldRef > output_fields)
 
Utility functions for simple field creation and evaluation
void evaluate_constant_field (const GField &field, void *r_value)
 
template<typename T >
T evaluate_constant_field (const Field< T > &field)
 
Field< bool > invert_boolean_field (const Field< bool > &field)
 
GField make_constant_field (const CPPType &type, const void *value)
 
template<typename T >
Field< Tmake_constant_field (T value)
 
GField make_field_constant_if_possible (GField field)
 
#FieldNode Inline Methods
bool operator== (const FieldNode &a, const FieldNode &b)
 
bool operator!= (const FieldNode &a, const FieldNode &b)
 
#FieldOperation
static std::shared_ptr< const FieldInputscombine_field_inputs (Span< GField > fields)
 
#FieldEvaluator
static IndexMask index_mask_from_selection (const IndexMask full_mask, const VArray< bool > &selection, ResourceScope &scope)
 
static IndexMask evaluate_selection (const Field< bool > &selection_field, const FieldContext &context, IndexMask full_mask, ResourceScope &scope)
 

Variables

template<typename T >
static constexpr bool is_field_v
 

Enumeration Type Documentation

◆ FieldNodeType

enum class blender::fn::FieldNodeType
strong

Have a fixed set of base node types, because all code that works with field nodes has to understand those.

Enumerator
Input 
Operation 
Constant 

Definition at line 56 of file FN_field.hh.

Function Documentation

◆ build_multi_function_procedure_for_fields()

static void blender::fn::build_multi_function_procedure_for_fields ( mf::Procedure & procedure,
ResourceScope & scope,
const FieldTreeInfo & field_tree_info,
Span< GFieldRef > output_fields )
static

Builds the #procedure so that it computes the fields.

Definition at line 146 of file field.cc.

References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add_new(), BLI_assert, BLI_assert_unreachable, Constant, blender::ResourceScope::construct(), blender::fn::multi_function::Procedure::construct_function(), blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), blender::Span< T >::contains(), blender::fn::multi_function::ParamType::data_type(), blender::fn::FieldTreeInfo::deduplicated_field_inputs, blender::fn::FieldTreeInfo::field_users, blender::GPointer::get(), Input, blender::fn::FieldOperation::inputs(), blender::fn::multi_function::ParamType::interface_type(), blender::Stack< T, InlineBufferCapacity, Allocator >::is_empty(), blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup(), blender::fn::FieldOperation::multi_function(), blender::fn::multi_function::Procedure::new_variable(), blender::fn::FieldNode::node_type(), Operation, blender::fn::multi_function::MultiFunction::param_amount(), blender::fn::multi_function::MultiFunction::param_indices(), blender::fn::multi_function::MultiFunction::param_type(), blender::Stack< T, InlineBufferCapacity, Allocator >::peek(), blender::Stack< T, InlineBufferCapacity, Allocator >::pop(), blender::Stack< T, InlineBufferCapacity, Allocator >::push(), blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::remove(), blender::Span< T >::size(), blender::fn::FieldConstant::type(), blender::fn::multi_function::Procedure::validate(), blender::fn::FieldConstant::value(), and blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::values().

Referenced by evaluate_fields().

◆ combine_field_inputs()

static std::shared_ptr< const FieldInputs > blender::fn::combine_field_inputs ( Span< GField > fields)
static

Returns the field inputs used by all the provided fields. This tries to reuse an existing #FieldInputs whenever possible to avoid copying it.

Definition at line 619 of file field.cc.

References blender::Vector< T, InlineBufferCapacity, Allocator >::append(), and blender::Vector< T, InlineBufferCapacity, Allocator >::is_empty().

Referenced by blender::fn::FieldOperation::FieldOperation().

◆ evaluate_constant_field() [1/2]

template<typename T >
T blender::fn::evaluate_constant_field ( const Field< T > & field)

Definition at line 501 of file FN_field.hh.

References evaluate_constant_field().

◆ evaluate_constant_field() [2/2]

◆ evaluate_fields()

Vector< GVArray > blender::fn::evaluate_fields ( ResourceScope & scope,
Span< GFieldRef > fields_to_evaluate,
const IndexMask & mask,
const FieldContext & context,
Span< GVMutableArray > dst_varrays = {} )

Evaluate fields in the given context. If possible, multiple fields should be evaluated together, because that can be more efficient when they share common sub-fields.

Parameters
scopeThe resource scope that owns data that makes up the output virtual arrays. Make sure the scope is not destructed when the output virtual arrays are still used.
fields_to_evaluateThe fields that should be evaluated together.
maskDetermines which indices are computed. The mask may be referenced by the returned virtual arrays. So the underlying indices (if applicable) should live longer then #scope.
contextThe context that the field is evaluated in. Used to retrieve data from each #FieldInput in the field network.
dst_varraysIf provided, the computed data will be written into those virtual arrays instead of into newly created ones. That allows making the computed data live longer than #scope and is more efficient when the data will be written into those virtual arrays later anyway.
Returns
The computed virtual arrays for each provided field. If #dst_varrays is passed, the provided virtual arrays are returned.

Definition at line 281 of file field.cc.

References blender::ResourceScope::add_destruct_call(), blender::LinearAllocator< Allocator >::allocate(), blender::Vector< T, InlineBufferCapacity, Allocator >::append(), BLI_assert, build_multi_function_procedure_for_fields(), Constant, blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), blender::array_utils::copy(), blender::GMutableSpan::data(), blender::fn::FieldTreeInfo::deduplicated_field_inputs, find_varying_fields(), blender::GVArray::ForEmpty(), blender::GVArray::ForSingleRef(), blender::GVArray::ForSpan(), blender::GPointer::get(), get_field_context_inputs(), blender::GVMutableArray::get_internal_span(), blender::Span< T >::index_range(), blender::Vector< T, InlineBufferCapacity, Allocator >::index_range(), Input, blender::Span< T >::is_empty(), blender::Vector< T, InlineBufferCapacity, Allocator >::is_empty(), blender::GVArrayCommon::is_span(), blender::ResourceScope::linear_allocator(), mask(), blender::fn::FieldNode::node_type(), Operation, blender::threading::parallel_for(), preprocess_field_tree(), blender::GVArrayCommon::size(), blender::Span< T >::size(), blender::GMutableSpan::take_front(), blender::fn::FieldConstant::type(), blender::GVArrayCommon::type(), and blender::fn::FieldConstant::value().

Referenced by blender::fn::FieldEvaluator::evaluate(), evaluate_constant_field(), evaluate_selection(), and blender::fn::tests::TEST().

◆ evaluate_selection()

static IndexMask blender::fn::evaluate_selection ( const Field< bool > & selection_field,
const FieldContext & context,
IndexMask full_mask,
ResourceScope & scope )
static

Definition at line 775 of file field.cc.

References evaluate_fields(), and index_mask_from_selection().

Referenced by blender::fn::FieldEvaluator::evaluate().

◆ find_varying_fields()

◆ get_field_context_inputs()

static Vector< GVArray > blender::fn::get_field_context_inputs ( ResourceScope & scope,
const IndexMask & mask,
const FieldContext & context,
const Span< std::reference_wrapper< const FieldInput > > field_inputs )
static

Retrieves the data from the context that is passed as input into the field.

Definition at line 86 of file field.cc.

References blender::Vector< T, InlineBufferCapacity, Allocator >::append(), and blender::GVArray::ForSingleDefault().

Referenced by evaluate_fields().

◆ index_mask_from_selection()

static IndexMask blender::fn::index_mask_from_selection ( const IndexMask full_mask,
const VArray< bool > & selection,
ResourceScope & scope )
static

◆ invert_boolean_field()

◆ make_constant_field() [1/2]

◆ make_constant_field() [2/2]

template<typename T >
Field< T > blender::fn::make_constant_field ( T value)

Definition at line 513 of file FN_field.hh.

References blender::CPPType::get(), and make_constant_field().

◆ make_field_constant_if_possible()

GField blender::fn::make_field_constant_if_possible ( GField field)

If the field depends on some input, the same field is returned. Otherwise the field is evaluated and a new field is created that just computes this constant.

Making the field constant has two benefits:

  • The field-tree becomes a single node, which is more efficient when the field is evaluated many times.
  • Memory of the input fields may be freed.

Definition at line 512 of file field.cc.

References BUFFER_FOR_CPP_TYPE_VALUE, evaluate_constant_field(), make_constant_field(), and make_field_constant_if_possible().

Referenced by make_field_constant_if_possible().

◆ operator!=()

bool blender::fn::operator!= ( const FieldNode & a,
const FieldNode & b )
inline

Definition at line 581 of file FN_field.hh.

References b.

◆ operator==()

bool blender::fn::operator== ( const FieldNode & a,
const FieldNode & b )
inline

Definition at line 576 of file FN_field.hh.

References b.

◆ preprocess_field_tree()

Variable Documentation

◆ is_field_v

template<typename T >
bool blender::fn::is_field_v
staticconstexpr
Initial value:
= std::is_base_of_v<detail::TypedFieldBase, T> &&
!std::is_same_v<detail::TypedFieldBase, T>

True when T is any Field<...> type.

Definition at line 217 of file FN_field.hh.

Referenced by blender::bke::SocketValueVariant::extract().