[Bf-blender-cvs] [2f02949798a] functions-experimental-refactor: initial multi function network builder
Jacques Lucke
noreply at git.blender.org
Thu Oct 17 17:53:13 CEST 2019
Commit: 2f02949798a9c74557cdbdf252e122eb3b8d27b9
Author: Jacques Lucke
Date: Thu Oct 17 14:19:21 2019 +0200
Branches: functions-experimental-refactor
https://developer.blender.org/rB2f02949798a9c74557cdbdf252e122eb3b8d27b9
initial multi function network builder
===================================================================
M source/blender/blenkernel/BKE_multi_function.h
A source/blender/blenkernel/BKE_multi_function_network.h
M source/blender/blenkernel/CMakeLists.txt
A source/blender/blenkernel/intern/multi_function_network.cc
M source/blender/blenlib/BLI_array_ref.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_multi_function.h b/source/blender/blenkernel/BKE_multi_function.h
index 1cb3ae9a10f..bc53f14a7f1 100644
--- a/source/blender/blenkernel/BKE_multi_function.h
+++ b/source/blender/blenkernel/BKE_multi_function.h
@@ -11,19 +11,18 @@ namespace BKE {
using BLI::Vector;
-struct ParamType {
+struct MultiFunctionDataType {
public:
enum Category {
None,
- SingleInput,
- SingleOutput,
- VectorInput,
- VectorOutput,
- MutableVector,
+ Single,
+ Vector,
};
- ParamType(Category category, const CPPType *base_type = nullptr)
- : m_category(category), m_base_type(base_type)
+ MultiFunctionDataType() = default;
+
+ MultiFunctionDataType(Category category, const CPPType &type)
+ : m_category(category), m_base_type(&type)
{
}
@@ -34,14 +33,13 @@ struct ParamType {
const CPPType &type() const
{
- BLI_assert(ELEM(m_category, Category::SingleInput, Category::SingleOutput));
+ BLI_assert(m_category == Category::Single);
return *m_base_type;
}
const CPPType &base_type() const
{
- BLI_assert(
- ELEM(m_category, Category::VectorInput, Category::VectorOutput, Category::MutableVector));
+ BLI_assert(m_category == Category::Vector);
return *m_base_type;
}
@@ -50,16 +48,52 @@ struct ParamType {
const CPPType *m_base_type = nullptr;
};
-struct DataType {
+struct ParamType {
public:
enum Category {
None,
- Single,
- Vector,
+ ReadonlySingleInput,
+ SingleOutput,
+ ReadonlyVectorInput,
+ VectorOutput,
+ MutableVector,
};
- DataType(Category category, const CPPType &type) : m_category(category), m_base_type(&type)
+ ParamType(Category category, const CPPType *base_type = nullptr)
+ : m_category(category), m_base_type(base_type)
+ {
+ }
+
+ bool is_none() const
+ {
+ return m_category == ParamType::None;
+ }
+
+ bool is_input() const
+ {
+ return ELEM(m_category, ReadonlySingleInput, ReadonlyVectorInput, MutableVector);
+ }
+
+ bool is_output() const
{
+ return ELEM(m_category, SingleOutput, VectorOutput, MutableVector);
+ }
+
+ MultiFunctionDataType as_data_type() const
+ {
+ switch (m_category) {
+ case None:
+ return {};
+ case ReadonlySingleInput:
+ case SingleOutput:
+ return {MultiFunctionDataType::Single, *m_base_type};
+ case ReadonlyVectorInput:
+ case VectorOutput:
+ case MutableVector:
+ return {MultiFunctionDataType::Vector, *m_base_type};
+ }
+ BLI_assert(false);
+ return {};
}
Category category() const
@@ -69,13 +103,16 @@ struct DataType {
const CPPType &type() const
{
- BLI_assert(m_category == Category::Single);
+ BLI_assert(ELEM(m_category, Category::ReadonlySingleInput, Category::SingleOutput));
return *m_base_type;
}
const CPPType &base_type() const
{
- BLI_assert(m_category == Category::Vector);
+ BLI_assert(ELEM(m_category,
+ Category::ReadonlyVectorInput,
+ Category::VectorOutput,
+ Category::MutableVector));
return *m_base_type;
}
@@ -116,13 +153,13 @@ class MultiFunction {
case ParamType::None:
BLI_assert(false);
break;
- case ParamType::SingleInput:
+ case ParamType::ReadonlySingleInput:
corrected_index = array_or_single_refs++;
break;
case ParamType::SingleOutput:
corrected_index = mutable_array_refs++;
break;
- case ParamType::VectorInput:
+ case ParamType::ReadonlyVectorInput:
corrected_index = vector_array_or_single_refs++;
break;
case ParamType::VectorOutput:
@@ -134,6 +171,11 @@ class MultiFunction {
}
}
+ ArrayRef<ParamType> param_types() const
+ {
+ return m_param_types;
+ }
+
uint get_corrected_index(uint index) const
{
return m_corrected_indices[index];
@@ -141,11 +183,11 @@ class MultiFunction {
template<typename T> bool is_readonly_single_input(uint index, StringRef name) const
{
- return this->is_valid_param<T>(index, name, ParamType::SingleInput);
+ return this->is_valid_param<T>(index, name, ParamType::ReadonlySingleInput);
}
bool is_readonly_single_input(uint index, StringRef name) const
{
- return this->is_valid_param(index, name, ParamType::SingleInput);
+ return this->is_valid_param(index, name, ParamType::ReadonlySingleInput);
}
template<typename T> bool is_single_output(uint index, StringRef name) const
@@ -159,11 +201,11 @@ class MultiFunction {
template<typename T> bool is_readonly_vector_input(uint index, StringRef name) const
{
- return this->is_valid_param<T>(index, name, ParamType::VectorInput);
+ return this->is_valid_param<T>(index, name, ParamType::ReadonlyVectorInput);
}
bool is_readonly_vector_input(uint index, StringRef name) const
{
- return this->is_valid_param(index, name, ParamType::VectorInput);
+ return this->is_valid_param(index, name, ParamType::ReadonlyVectorInput);
}
template<typename T> bool is_vector_output(uint index, StringRef name) const
@@ -187,11 +229,11 @@ class MultiFunction {
if (!this->is_valid_param(index, name, category)) {
return false;
}
- else if (ELEM(category, ParamType::SingleInput, ParamType::SingleOutput)) {
+ else if (ELEM(category, ParamType::ReadonlySingleInput, ParamType::SingleOutput)) {
return GET_TYPE<T>().is_same_or_generalization(m_param_types[index].type());
}
else if (ELEM(category,
- ParamType::VectorInput,
+ ParamType::ReadonlyVectorInput,
ParamType::VectorOutput,
ParamType::MutableVector)) {
return GET_TYPE<T>().is_same_or_generalization(m_param_types[index].base_type());
@@ -222,7 +264,7 @@ class MultiFunction {
void readonly_single_input(StringRef name, CPPType &type)
{
m_param_names.append(name);
- m_param_types.append(ParamType(ParamType::SingleInput, &type));
+ m_param_types.append(ParamType(ParamType::ReadonlySingleInput, &type));
}
template<typename T> void single_output(StringRef name, bool has_external_dependencies = false)
@@ -245,7 +287,7 @@ class MultiFunction {
void readonly_vector_input(StringRef name, CPPType &base_type)
{
m_param_names.append(name);
- m_param_types.append(ParamType(ParamType::VectorInput, &base_type));
+ m_param_types.append(ParamType(ParamType::ReadonlyVectorInput, &base_type));
}
template<typename T> void vector_output(StringRef name, bool has_external_dependencies = false)
diff --git a/source/blender/blenkernel/BKE_multi_function_network.h b/source/blender/blenkernel/BKE_multi_function_network.h
new file mode 100644
index 00000000000..c58907915a4
--- /dev/null
+++ b/source/blender/blenkernel/BKE_multi_function_network.h
@@ -0,0 +1,276 @@
+#ifndef __BKE_MULTI_FUNCTION_NETWORK_H__
+#define __BKE_MULTI_FUNCTION_NETWORK_H__
+
+#include "BKE_multi_function.h"
+
+#include "BLI_optional.h"
+
+namespace BKE {
+
+using BLI::Optional;
+
+namespace MultiFunctionNetwork {
+
+class Node;
+class FunctionNode;
+class PlaceholderNode;
+
+class Socket;
+class InputSocket;
+class OutputSocket;
+
+class Network;
+
+class Node {
+ public:
+ Network &network();
+
+ ArrayRef<MultiFunctionDataType> input_types();
+ ArrayRef<MultiFunctionDataType> output_types();
+
+ bool is_function();
+ bool is_placeholder();
+
+ FunctionNode &as_function();
+ PlaceholderNode &as_placeholder();
+};
+
+class FunctionNode : public Node {
+ public:
+ MultiFunction &function();
+};
+
+class PlaceholderNode : public Node {
+};
+
+class Socket {
+ public:
+ Node &node();
+ MultiFunctionDataType &type();
+
+ bool is_input();
+ bool is_output();
+
+ InputSocket &as_input();
+ OutputSocket &as_output();
+};
+
+class InputSocket : public Socket {
+ public:
+ OutputSocket &origin();
+};
+
+class OutputSocket : public Socket {
+ public:
+ ArrayRef<InputSocket *> targets();
+};
+
+class Network {
+ public:
+};
+
+/* Builder
+ ****************************************/
+
+class BuilderNode;
+class BuilderFunctionNode;
+class BuilderPlaceholderNode;
+
+class BuilderSocket;
+class BuilderInputSocket;
+class BuilderOutputSocket;
+
+class BuilderNetwork;
+
+class BuilderNode {
+ protected:
+ BuilderNetwork *m_network;
+ Vector<BuilderInputSocket *> m_inputs;
+ Vector<BuilderOutputSocket *> m_outputs;
+ bool m_is_placeholder;
+
+ friend BuilderNetwork;
+
+ public:
+ BuilderNetwork &network();
+
+ ArrayRef<BuilderInputSocket *> inputs();
+ ArrayRef<BuilderOutputSocket *> outputs();
+
+ bool is_function();
+ bool is_placeholder();
+
+ BuilderFunctionNode &as_function();
+ BuilderPlaceholderNode &as_placeholder();
+};
+
+class BuilderFunctionNode : public BuilderNode {
+ private:
+ MultiFunction *m_function;
+ Vector<uint> m_input_param_indices;
+ Vector<uint> m_output_param_indices;
+
+ friend BuilderNetwork;
+
+ public:
+ MultiFunction &function();
+};
+
+class BuilderPlaceholderNode : public BuilderNode {
+};
+
+class BuilderSocket {
+ private:
+ BuilderNode *m_node;
+ bool m_is_output;
+ uint m_index;
+ MultiFunctionDataType m_type;
+
+ friend BuilderNetwork;
+
+ public:
+ BuilderNode &node();
+ MultiFunctionDataType type();
+
+ bool is_input();
+ bool is_output();
+
+ BuilderInputSocket &as_input();
+ BuilderOutputSocket &as_output();
+};
+
+class BuilderInputSocket : public BuilderSocket {
+ private:
+ BuilderOutputSocket *m_origin;
+
+ friend BuilderNetwork;
+
+ public:
+ BuilderOutputSocket *origin();
+};
+
+class BuilderOutputSocket : public BuilderSocket {
+ private:
+ Vector<BuilderInputSocket *> m_targets;
+
+ friend BuilderNetwork;
+
+ public:
+ ArrayRef<BuilderInputSocket *> targets();
+};
+
+class BuilderNetwork {
+ private:
+ Vector<std::unique_ptr<BuilderFunctionNode>> m_function_nodes;
+ Vector<std::unique_ptr<BuilderPlaceholderNode>> m_placeholder_nodes;
+ Vector<std::unique_ptr<Builder
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list