[Bf-blender-cvs] [0ca2f55] compositor-2016: Code refactor: minor node and node type utility functions and changes.
Brecht Van Lommel
noreply at git.blender.org
Wed Jun 8 21:51:05 CEST 2016
Commit: 0ca2f554c4fa597222ef8dec0ffde75958b506e0
Author: Brecht Van Lommel
Date: Sun May 29 11:20:10 2016 +0200
Branches: compositor-2016
https://developer.blender.org/rB0ca2f554c4fa597222ef8dec0ffde75958b506e0
Code refactor: minor node and node type utility functions and changes.
===================================================================
M intern/cycles/graph/node.cpp
M intern/cycles/graph/node.h
M intern/cycles/graph/node_type.cpp
M intern/cycles/graph/node_type.h
M intern/cycles/graph/node_xml.cpp
M intern/cycles/render/background.cpp
M intern/cycles/render/background.h
M intern/cycles/render/camera.cpp
M intern/cycles/render/camera.h
M intern/cycles/render/film.cpp
M intern/cycles/render/integrator.cpp
M intern/cycles/render/integrator.h
===================================================================
diff --git a/intern/cycles/graph/node.cpp b/intern/cycles/graph/node.cpp
index 98b66fb..941a667 100644
--- a/intern/cycles/graph/node.cpp
+++ b/intern/cycles/graph/node.cpp
@@ -36,12 +36,8 @@ Node::Node(const NodeType *type_, ustring name_)
}
/* initialize default values */
- typedef unordered_map<ustring, SocketType, ustringHash> map_type;
- foreach(const map_type::value_type& it, type->inputs) {
- const SocketType& socket = it.second;
- const void *src = socket.default_value;
- void *dst = ((char*)this) + socket.struct_offset;
- memcpy(dst, src, socket.size());
+ foreach(const SocketType& socket, type->inputs) {
+ set_default_value(socket);
}
}
@@ -297,7 +293,8 @@ const array<Node*>& Node::get_node_array(const SocketType& input) const
return get_socket_value<array<Node*> >(this, input);
}
-/* default values */
+/* generic value operations */
+
bool Node::has_default_value(const SocketType& input) const
{
const void *src = input.default_value;
@@ -305,6 +302,48 @@ bool Node::has_default_value(const SocketType& input) const
return memcmp(dst, src, input.size()) == 0;
}
+void Node::set_default_value(const SocketType& socket)
+{
+ const void *src = socket.default_value;
+ void *dst = ((char*)this) + socket.struct_offset;
+ memcpy(dst, src, socket.size());
+}
+
+template<typename T>
+static void copy_array(const Node *node, const SocketType& socket, const Node *other, const SocketType& other_socket)
+{
+ const array<T>* src = (const array<T>*)(((char*)other) + other_socket.struct_offset);
+ array<T>* dst = (array<T>*)(((char*)node) + socket.struct_offset);
+ *dst = *src;
+}
+
+void Node::copy_value(const SocketType& socket, const Node& other, const SocketType& other_socket)
+{
+ assert(socket.type == other_socket.type);
+
+ if(socket.is_array()) {
+ switch(socket.type) {
+ case SocketType::BOOLEAN_ARRAY: copy_array<bool>(this, socket, &other, other_socket); break;
+ case SocketType::FLOAT_ARRAY: copy_array<float>(this, socket, &other, other_socket); break;
+ case SocketType::INT_ARRAY: copy_array<int>(this, socket, &other, other_socket); break;
+ case SocketType::COLOR_ARRAY: copy_array<float3>(this, socket, &other, other_socket); break;
+ case SocketType::VECTOR_ARRAY: copy_array<float3>(this, socket, &other, other_socket); break;
+ case SocketType::POINT_ARRAY: copy_array<float3>(this, socket, &other, other_socket); break;
+ case SocketType::NORMAL_ARRAY: copy_array<float3>(this, socket, &other, other_socket); break;
+ case SocketType::POINT2_ARRAY: copy_array<float2>(this, socket, &other, other_socket); break;
+ case SocketType::STRING_ARRAY: copy_array<ustring>(this, socket, &other, other_socket); break;
+ case SocketType::TRANSFORM_ARRAY: copy_array<Transform>(this, socket, &other, other_socket); break;
+ case SocketType::NODE_ARRAY: copy_array<void*>(this, socket, &other, other_socket); break;
+ default: assert(0); break;
+ }
+ }
+ else {
+ const void *src = ((char*)&other) + other_socket.struct_offset;
+ void *dst = ((char*)this) + socket.struct_offset;
+ memcpy(dst, src, socket.size());
+ }
+}
+
template<typename T>
static bool is_array_equal(const Node *node, const Node *other, const SocketType& socket)
{
@@ -313,48 +352,43 @@ static bool is_array_equal(const Node *node, const Node *other, const SocketType
return *a == *b;
}
-/* modified */
-bool Node::modified(const Node& other)
+bool Node::equals_value(const Node& other, const SocketType& socket) const
+{
+ if(socket.is_array()) {
+ switch(socket.type) {
+ case SocketType::BOOLEAN_ARRAY: return is_array_equal<bool>(this, &other, socket);
+ case SocketType::FLOAT_ARRAY: return is_array_equal<float>(this, &other, socket);
+ case SocketType::INT_ARRAY: return is_array_equal<int>(this, &other, socket);
+ case SocketType::COLOR_ARRAY: return is_array_equal<float3>(this, &other, socket);
+ case SocketType::VECTOR_ARRAY: return is_array_equal<float3>(this, &other, socket);
+ case SocketType::POINT_ARRAY: return is_array_equal<float3>(this, &other, socket);
+ case SocketType::NORMAL_ARRAY: return is_array_equal<float3>(this, &other, socket);
+ case SocketType::POINT2_ARRAY: return is_array_equal<float2>(this, &other, socket);
+ case SocketType::STRING_ARRAY: return is_array_equal<ustring>(this, &other, socket);
+ case SocketType::TRANSFORM_ARRAY: return is_array_equal<Transform>(this, &other, socket);
+ case SocketType::NODE_ARRAY: return is_array_equal<void*>(this, &other, socket);
+ default: assert(0); return true;
+ }
+ }
+ else {
+ const void *a = ((char*)this) + socket.struct_offset;
+ const void *b = ((char*)&other) + socket.struct_offset;
+ return (memcmp(a, b, socket.size()) == 0);
+ }
+}
+
+/* equals */
+
+bool Node::equals(const Node& other) const
{
assert(type == other.type);
- typedef unordered_map<ustring, SocketType, ustringHash> map_type;
- foreach(const map_type::value_type& it, type->inputs) {
- const SocketType& socket = it.second;
-
- if(socket.is_array()) {
- bool equal = true;
-
- switch(socket.type)
- {
- case SocketType::BOOLEAN_ARRAY: equal = is_array_equal<bool>(this, &other, socket); break;
- case SocketType::FLOAT_ARRAY: equal = is_array_equal<float>(this, &other, socket); break;
- case SocketType::INT_ARRAY: equal = is_array_equal<int>(this, &other, socket); break;
- case SocketType::COLOR_ARRAY: equal = is_array_equal<float3>(this, &other, socket); break;
- case SocketType::VECTOR_ARRAY: equal = is_array_equal<float3>(this, &other, socket); break;
- case SocketType::POINT_ARRAY: equal = is_array_equal<float3>(this, &other, socket); break;
- case SocketType::NORMAL_ARRAY: equal = is_array_equal<float3>(this, &other, socket); break;
- case SocketType::POINT2_ARRAY: equal = is_array_equal<float2>(this, &other, socket); break;
- case SocketType::STRING_ARRAY: equal = is_array_equal<ustring>(this, &other, socket); break;
- case SocketType::TRANSFORM_ARRAY: equal = is_array_equal<Transform>(this, &other, socket); break;
- case SocketType::NODE_ARRAY: equal = is_array_equal<void*>(this, &other, socket); break;
- default: assert(0); break;
- }
-
- if(!equal) {
- return true;
- }
- }
- else {
- const void *a = ((char*)this) + socket.struct_offset;
- const void *b = ((char*)&other) + socket.struct_offset;
- if(memcmp(a, b, socket.size()) != 0) {
- return true;
- }
- }
+ foreach(const SocketType& socket, type->inputs) {
+ if(!equals_value(other, socket))
+ return false;
}
- return false;
+ return true;
}
CCL_NAMESPACE_END
diff --git a/intern/cycles/graph/node.h b/intern/cycles/graph/node.h
index de06df1..bb84f98 100644
--- a/intern/cycles/graph/node.h
+++ b/intern/cycles/graph/node.h
@@ -77,11 +77,14 @@ struct Node
const array<Transform>& get_transform_array(const SocketType& input) const;
const array<Node*>& get_node_array(const SocketType& input) const;
- /* default values */
+ /* generic values operations */
bool has_default_value(const SocketType& input) const;
+ void set_default_value(const SocketType& input);
+ bool equals_value(const Node& other, const SocketType& input) const;
+ void copy_value(const SocketType& input, const Node& other, const SocketType& other_input);
- /* modified */
- bool modified(const Node& other);
+ /* equals */
+ bool equals(const Node& other) const;
ustring name;
const NodeType *type;
diff --git a/intern/cycles/graph/node_type.cpp b/intern/cycles/graph/node_type.cpp
index dc87965..7f68ae9 100644
--- a/intern/cycles/graph/node_type.cpp
+++ b/intern/cycles/graph/node_type.cpp
@@ -114,9 +114,15 @@ ustring SocketType::type_name(Type type)
return names[(int)type];
}
+bool SocketType::is_float3(Type type)
+{
+ return (type == COLOR || type == VECTOR || type == POINT || type == NORMAL);
+}
+
/* Node Type */
-NodeType::NodeType()
+NodeType::NodeType(Type type_)
+: type(type_)
{
}
@@ -137,7 +143,7 @@ void NodeType::register_input(ustring name, ustring ui_name, SocketType::Type ty
socket.enum_values = enum_values;
socket.node_type = node_type;
socket.flags = flags | extra_flags;
- inputs[name] = socket;
+ inputs.push_back(socket);
}
void NodeType::register_output(ustring name, ustring ui_name, SocketType::Type type)
@@ -151,7 +157,29 @@ void NodeType::register_output(ustring name, ustring ui_name, SocketType::Type t
socket.enum_values = NULL;
socket.node_type = NULL;
socket.flags = SocketType::LINKABLE;
- outputs[name] = socket;
+ outputs.push_back(socket);
+}
+
+const SocketType *NodeType::find_input(ustring name) const
+{
+ foreach(const SocketType& socket, inputs) {
+ if(socket.name == name) {
+ return &socket;
+ }
+ }
+
+ return NULL;
+}
+
+const SocketType *NodeType::find_output(ustring name) const
+{
+ foreach(const SocketType& socket, outputs) {
+ if(socket.name == name) {
+ return &socket;
+ }
+ }
+
+ return NULL;
}
/* Node Type Registry */
@@ -162,7 +190,7 @@ unordered_map<ustring, NodeType, ustringHash>& NodeType::types()
return _types;
}
-NodeType *NodeType::add(const char *name_, CreateFunc create_)
+NodeType *NodeType::add(const char *name_, CreateFunc create_, Type type_)
{
ustring name(name_);
@@ -172,7 +200,7 @@ NodeType *NodeType::add(const char *name_, CreateFunc create_)
return NULL;
}
- types()[name] = NodeType();
+ types()[name] = NodeType(type_);
NodeType *type = &types()[name];
type->name = name;
diff --git a/intern/cycles/graph/node_type.h b/intern/cycles/graph/node_type.h
index 82ddd29..20816f6 100644
--- a/intern/cycles/graph/node_type.h
+++ b/intern/cycles/graph/node_type.h
@@ -21,6 +21,7 @@
#include "util_map.h"
#include "util_param.h"
#include "util_string.h"
+#include "util_vector.h"
CCL_NAMESPACE_BEGIN
@@ -94,13 +95,19 @@ struct SocketType
static size_t max_size();
static ustring type_name(Type type);
static void *zero_default_value();
+ static bool is_float3(Type type);
};
/* Node Type */
struct NodeType
{
- explicit NodeType();
+ enum Type {
+ NONE,
+ SHADER
+ };
+
+ explicit NodeType(Type type = NONE);
~NodeType();
void register_input(ustring name, ustring ui_name, SocketType::Type type,
@@ -110,15 +117,18 @@ struct NodeType
int f
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list