Commit: 1968c9b702477fff56aab160f63b9317a70d4bf5 Author: Hans Goudey Date: Sat Aug 28 21:17:21 2021 -0500 Branches: temp-geometry-nodes-fields--fields https://developer.blender.org/rB1968c9b702477fff56aab160f63b9317a70d4bf5
Add another test, add TODO comments =================================================================== M source/blender/functions/FN_field.hh M source/blender/functions/intern/field.cc M source/blender/functions/tests/FN_field_test.cc =================================================================== diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh index f0e2fdb7a8f..14790d4e9e7 100644 --- a/source/blender/functions/FN_field.hh +++ b/source/blender/functions/FN_field.hh @@ -19,7 +19,7 @@ /** \file * \ingroup fn * - * Field serve as an intermediate representation for a calculation of a group of functions. Having + * Field serve as an intermediate representation for calculation of a group of functions. Having * an intermediate representation is helpful mainly to separate the execution system from the * system that describes the necessary computations. Fields can be executed in different contexts, * and optimization might mean executing the fields differently based on some factors like the @@ -33,6 +33,7 @@ #include "BLI_string_ref.hh" #include "BLI_vector.hh" +#include "FN_generic_virtual_array.hh" #include "FN_multi_function_procedure.hh" #include "FN_multi_function_procedure_builder.hh" #include "FN_multi_function_procedure_executor.hh" @@ -145,7 +146,6 @@ class FieldFunction { }; class FieldInput { - protected: StringRef name_; diff --git a/source/blender/functions/intern/field.cc b/source/blender/functions/intern/field.cc index b323ff7e8fa..3e27e537f26 100644 --- a/source/blender/functions/intern/field.cc +++ b/source/blender/functions/intern/field.cc @@ -23,10 +23,11 @@ namespace blender::fn { /** - * A map to hold the output variables for each function so they can be reused. + * A map to hold the output variables for each function or input so they can be reused. */ // using VariableMap = Map<const FunctionOrInput *, Vector<MFVariable *>>; using VariableMap = Map<const void *, Vector<MFVariable *>>; +/* TODO: Use use counter in the vector to control when to add the desctruct call. */ /** * A map of the computed inputs for all of a field system's inputs, to avoid creating duplicates. @@ -79,7 +80,7 @@ static void add_field_variables_recursive(const Field &field, Vector<MFVariable *> outputs = builder.add_call(function.multi_function(), inputs); - builder.add_destruct(unique_inputs); + builder.add_destruct(unique_inputs); /* TODO: What if the same variable was used later on? */ variable_map.add(&function, std::move(outputs)); } diff --git a/source/blender/functions/tests/FN_field_test.cc b/source/blender/functions/tests/FN_field_test.cc index c0d7d4b2a82..c01fa0f87b8 100644 --- a/source/blender/functions/tests/FN_field_test.cc +++ b/source/blender/functions/tests/FN_field_test.cc @@ -10,10 +10,10 @@ namespace blender::fn::tests { TEST(field, ConstantFunction) { - Field constant_field = Field(CPPType::get<int>(), - std::make_shared<FieldFunction>(FieldFunction( - std::make_unique<CustomMF_Constant<int>>(10), {})), - 0); + Field constant_field{CPPType::get<int>(), + std::make_shared<FieldFunction>( + FieldFunction(std::make_unique<CustomMF_Constant<int>>(10), {})), + 0}; Array<int> result(4); GMutableSpan result_generic(result.as_mutable_span()); @@ -38,7 +38,7 @@ class IndexFieldInput final : public FieldInput { TEST(field, VArrayInput) { - Field index_field = Field(CPPType::get<int>(), std::make_shared<IndexFieldInput>()); + Field index_field{CPPType::get<int>(), std::make_shared<IndexFieldInput>()}; Array<int> result_1(4); GMutableSpan result_generic_1(result_1.as_mutable_span()); @@ -61,8 +61,8 @@ TEST(field, VArrayInput) TEST(field, VArrayInputMultipleOutputs) { std::shared_ptr<FieldInput> index_input = std::make_shared<IndexFieldInput>(); - Field field_1 = Field(CPPType::get<int>(), index_input); - Field field_2 = Field(CPPType::get<int>(), index_input); + Field field_1{CPPType::get<int>(), index_input}; + Field field_2{CPPType::get<int>(), index_input}; Array<int> result_1(10); Array<int> result_2(10); @@ -82,14 +82,14 @@ TEST(field, VArrayInputMultipleOutputs) TEST(field, InputAndFunction) { - Field index_field = Field(CPPType::get<int>(), std::make_shared<IndexFieldInput>()); + Field index_field{CPPType::get<int>(), std::make_shared<IndexFieldInput>()}; - Field output_field = Field(CPPType::get<int>(), - std::make_shared<FieldFunction>( - FieldFunction(std::make_unique<CustomMF_SI_SI_SO<int, int, int>>( - "add", [](int a, int b) { return a + b; }), - {index_field, index_field})), - 0); + Field output_field{CPPType::get<int>(), + std::make_shared<FieldFunction>( + FieldFunction(std::make_unique<CustomMF_SI_SI_SO<int, int, int>>( + "add", [](int a, int b) { return a + b; }), + {index_field, index_field})), + 0}; Array<int> result(10); GMutableSpan result_generic(result.as_mutable_span()); @@ -100,4 +100,31 @@ TEST(field, InputAndFunction) EXPECT_EQ(result[8], 16); } +TEST(field, TwoFunctions) +{ + Field index_field{CPPType::get<int>(), std::make_shared<IndexFieldInput>()}; + + Field add_field{CPPType::get<int>(), + std::make_shared<FieldFunction>( + FieldFunction(std::make_unique<CustomMF_SI_SI_SO<int, int, int>>( + "add", [](int a, int b) { return a + b; }), + {index_field, index_field})), + 0}; + + Field result_field{ + CPPType::get<int>(), + std::make_shared<FieldFunction>(FieldFunction( + std::make_unique<CustomMF_SI_SO<int, int>>("add_10", [](int a) { return a + 10; }), + {add_field})), + 0}; + + Array<int> result(10); + GMutableSpan result_generic(result.as_mutable_span()); + evaluate_fields({result_field}, {2, 4, 6, 8}, {result_generic}); + EXPECT_EQ(result[2], 14); + EXPECT_EQ(result[4], 18); + EXPECT_EQ(result[6], 22); + EXPECT_EQ(result[8], 26); +} + } // namespace blender::fn::tests _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs