[Bf-blender-cvs] [f6ef23ebe7e] functions: remove IndexedNodeTree data structure in favor of VirtualNodeTree
Jacques Lucke
noreply at git.blender.org
Thu Aug 1 18:22:51 CEST 2019
Commit: f6ef23ebe7eaf3077f774ffa8593da9b055f228a
Author: Jacques Lucke
Date: Thu Aug 1 09:59:55 2019 +0200
Branches: functions
https://developer.blender.org/rBf6ef23ebe7eaf3077f774ffa8593da9b055f228a
remove IndexedNodeTree data structure in favor of VirtualNodeTree
===================================================================
M source/blender/blenkernel/BKE_node_tree.hpp
M source/blender/blenkernel/intern/node_tree.cpp
M source/blender/simulations/bparticles/c_wrapper.cpp
M source/blender/simulations/bparticles/inserters.hpp
===================================================================
diff --git a/source/blender/blenkernel/BKE_node_tree.hpp b/source/blender/blenkernel/BKE_node_tree.hpp
index a2ba409f3d0..59807d701e6 100644
--- a/source/blender/blenkernel/BKE_node_tree.hpp
+++ b/source/blender/blenkernel/BKE_node_tree.hpp
@@ -27,99 +27,6 @@ using bNodeList = ListBaseWrapper<struct bNode *, true>;
using bLinkList = ListBaseWrapper<struct bNodeLink *, true>;
using bSocketList = ListBaseWrapper<struct bNodeSocket *, true>;
-struct SocketWithNode {
- bNodeSocket *socket;
- bNode *node;
-};
-
-struct SingleOriginLink {
- bNodeSocket *from;
- bNodeSocket *to;
- bNodeLink *source_link;
-};
-
-/**
- * The DNA structure of a node tree is difficult to parse, since it does not support e.g. the
- * following queries efficiently:
- * - Which nodes have a specific type?
- * - Which node corresponds to a socket?
- * - Which other sockets are connected to a socket (with and without reroutes)?
- *
- * This data structure does some preprocessing to make these queries more efficient. It is only
- * valid as long as the underlying node tree is not modified.
- */
-class IndexedNodeTree {
- public:
- IndexedNodeTree(bNodeTree *btree);
-
- bNodeTree *btree() const
- {
- return m_btree;
- }
-
- ID *btree_id() const
- {
- return &m_btree->id;
- }
-
- PointerRNA rna(bNode *bnode) const
- {
- PointerRNA rna;
- RNA_pointer_create(this->btree_id(), &RNA_Node, bnode, &rna);
- return rna;
- }
-
- /**
- * Get all nodes that are in the btree->nodes list.
- */
- ArrayRef<bNode *> original_nodes() const
- {
- return m_original_nodes;
- }
-
- /**
- * Get all links that are in the btree->links list.
- */
- ArrayRef<bNodeLink *> original_links() const
- {
- return m_original_links;
- }
-
- /**
- * Get all nodes that are not reroutes or frames.
- */
- ArrayRef<bNode *> actual_nodes() const
- {
- return m_actual_nodes;
- }
-
- bNode *node_of_socket(bNodeSocket *bsocket) const
- {
- return m_node_by_socket.lookup(bsocket);
- }
-
- ArrayRef<SingleOriginLink> single_origin_links() const;
- ArrayRef<bNode *> nodes_with_idname(StringRef idname) const;
- ArrayRef<SocketWithNode> linked(bNodeSocket *bsocket) const;
-
- private:
- bool is_reroute(bNode *bnode) const;
- bool is_frame(bNode *bnode) const;
-
- void find_connected_sockets_left(bNodeSocket *bsocket, Vector<SocketWithNode> &r_sockets) const;
- void find_connected_sockets_right(bNodeSocket *bsocket, Vector<SocketWithNode> &r_sockets) const;
-
- bNodeTree *m_btree;
- Vector<bNode *> m_original_nodes;
- Vector<bNodeLink *> m_original_links;
- Vector<bNode *> m_actual_nodes;
- Map<bNodeSocket *, bNode *> m_node_by_socket;
- MultiMap<bNodeSocket *, SocketWithNode> m_direct_links;
- MultiMap<bNodeSocket *, SocketWithNode> m_links;
- MultiMap<std::string, bNode *> m_nodes_by_idname;
- Vector<SingleOriginLink> m_single_origin_links;
-};
-
class VirtualNode;
class VirtualSocket;
class VirtualLink;
diff --git a/source/blender/blenkernel/intern/node_tree.cpp b/source/blender/blenkernel/intern/node_tree.cpp
index f2c78a61988..a50eb9f3e54 100644
--- a/source/blender/blenkernel/intern/node_tree.cpp
+++ b/source/blender/blenkernel/intern/node_tree.cpp
@@ -3,107 +3,6 @@
namespace BKE {
-IndexedNodeTree::IndexedNodeTree(bNodeTree *btree)
- : m_btree(btree), m_original_nodes(btree->nodes, true), m_original_links(btree->links, true)
-{
- for (bNode *bnode : m_original_nodes) {
- for (bNodeSocket *bsocket : bSocketList(bnode->inputs)) {
- m_node_by_socket.add(bsocket, bnode);
- }
- for (bNodeSocket *bsocket : bSocketList(bnode->outputs)) {
- m_node_by_socket.add(bsocket, bnode);
- }
- }
-
- for (bNode *bnode : m_original_nodes) {
- m_nodes_by_idname.add(bnode->idname, bnode);
- if (!this->is_reroute(bnode) && !this->is_frame(bnode)) {
- m_actual_nodes.append(bnode);
- }
- }
-
- for (bNodeLink *blink : m_original_links) {
- m_direct_links.add(blink->tosock, {blink->fromsock, blink->fromnode});
- m_direct_links.add(blink->fromsock, {blink->tosock, blink->tonode});
- }
-
- for (bNodeLink *blink : m_original_links) {
- if (!this->is_reroute(blink->fromnode) && !m_links.contains(blink->fromsock)) {
- Vector<SocketWithNode> connected;
- this->find_connected_sockets_right(blink->fromsock, connected);
- m_links.add_multiple_new(blink->fromsock, connected);
- }
- if (!this->is_reroute(blink->tonode) && !m_links.contains(blink->tosock)) {
- Vector<SocketWithNode> connected;
- this->find_connected_sockets_left(blink->tosock, connected);
- m_links.add_multiple_new(blink->tosock, connected);
- if (connected.size() == 1) {
- m_single_origin_links.append(SingleOriginLink{connected[0].socket, blink->tosock, blink});
- }
- }
- }
-}
-
-void IndexedNodeTree::find_connected_sockets_left(bNodeSocket *bsocket,
- Vector<SocketWithNode> &r_sockets) const
-{
- BLI_assert(bsocket->in_out == SOCK_IN);
- auto from_sockets = m_direct_links.lookup_default(bsocket);
- for (SocketWithNode linked : from_sockets) {
- if (this->is_reroute(linked.node)) {
- this->find_connected_sockets_left((bNodeSocket *)linked.node->inputs.first, r_sockets);
- }
- else {
- r_sockets.append(linked);
- }
- }
-}
-void IndexedNodeTree::find_connected_sockets_right(bNodeSocket *bsocket,
- Vector<SocketWithNode> &r_sockets) const
-{
- BLI_assert(bsocket->in_out == SOCK_OUT);
- auto to_sockets = m_direct_links.lookup_default(bsocket);
- for (SocketWithNode other : to_sockets) {
- if (this->is_reroute(other.node)) {
- this->find_connected_sockets_right((bNodeSocket *)other.node->outputs.first, r_sockets);
- }
- else {
- r_sockets.append(other);
- }
- }
-}
-
-bool IndexedNodeTree::is_reroute(bNode *bnode) const
-{
- return STREQ(bnode->idname, "NodeReroute");
-}
-
-bool IndexedNodeTree::is_frame(bNode *bnode) const
-{
- return STREQ(bnode->idname, "NodeFrame");
-}
-
-/* Queries
- *******************************************************/
-
-ArrayRef<bNode *> IndexedNodeTree::nodes_with_idname(StringRef idname) const
-{
- return m_nodes_by_idname.lookup_default(idname.to_std_string());
-}
-
-ArrayRef<SocketWithNode> IndexedNodeTree::linked(bNodeSocket *bsocket) const
-{
- return m_links.lookup_default(bsocket);
-}
-
-ArrayRef<SingleOriginLink> IndexedNodeTree::single_origin_links() const
-{
- return m_single_origin_links;
-}
-
-/* Virtual Node Tree
- *****************************************/
-
void VirtualNodeTree::add_all_of_tree(bNodeTree *btree)
{
Map<bNode *, VirtualNode *> node_mapping;
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 26e082912f4..9341e2d0d36 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -30,9 +30,6 @@
using namespace BParticles;
-using BKE::bSocketList;
-using BKE::IndexedNodeTree;
-using BKE::SocketWithNode;
using BLI::ArrayRef;
using BLI::float3;
using BLI::StringRef;
diff --git a/source/blender/simulations/bparticles/inserters.hpp b/source/blender/simulations/bparticles/inserters.hpp
index 16d58341109..8fa2aa31f8c 100644
--- a/source/blender/simulations/bparticles/inserters.hpp
+++ b/source/blender/simulations/bparticles/inserters.hpp
@@ -14,9 +14,6 @@
namespace BParticles {
-using BKE::bSocketList;
-using BKE::IndexedNodeTree;
-using BKE::SocketWithNode;
using BKE::VirtualLink;
using BKE::VirtualNode;
using BKE::VirtualNodeTree;
More information about the Bf-blender-cvs
mailing list