Blender
V5.0
source
blender
depsgraph
intern
builder
deg_builder_transitive.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2015 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9
#include "
DEG_depsgraph_debug.hh
"
10
11
#include "
intern/builder/deg_builder_transitive.h
"
12
13
#include "
intern/node/deg_node.hh
"
14
#include "
intern/node/deg_node_component.hh
"
15
#include "
intern/node/deg_node_operation.hh
"
16
17
#include "
intern/debug/deg_debug.h
"
18
#include "
intern/depsgraph.hh
"
19
#include "
intern/depsgraph_relation.hh
"
20
21
namespace
blender::deg
{
22
23
/* -------------------------------------------------- */
24
25
/* Performs a transitive reduction to remove redundant relations.
26
* https://en.wikipedia.org/wiki/Transitive_reduction
27
*
28
* XXX The current implementation is somewhat naive and has O(V*E) worst case
29
* runtime.
30
* A more optimized algorithm can be implemented later, e.g.
31
*
32
* http://www.sciencedirect.com/science/article/pii/0304397588900321/pdf?md5=3391e309b708b6f9cdedcd08f84f4afc&pid=1-s2.0-0304397588900321-main.pdf
33
*
34
* Care has to be taken to make sure the algorithm can handle the cyclic case
35
* too! (unless we can to prevent this case early on).
36
*/
37
38
enum
{
39
OP_VISITED
= 1,
40
OP_REACHABLE
= 2,
41
};
42
43
static
void
deg_graph_tag_paths_recursive
(
Node
*node)
44
{
45
if
(node->
custom_flags
&
OP_VISITED
) {
46
return
;
47
}
48
node->
custom_flags
|=
OP_VISITED
;
49
for
(
Relation
*rel : node->
inlinks
) {
50
deg_graph_tag_paths_recursive
(rel->
from
);
51
/* Do this only in inlinks loop, so the target node does not get
52
* flagged. */
53
rel->
from
->
custom_flags
|=
OP_REACHABLE
;
54
}
55
}
56
57
void
deg_graph_transitive_reduction
(
Depsgraph
*graph)
58
{
59
int
num_removed_relations = 0;
60
Vector<Relation *>
relations_to_remove;
61
62
for
(
OperationNode
*target : graph->
operations
) {
63
/* Clear tags. */
64
for
(
OperationNode
*node : graph->
operations
) {
65
node->
custom_flags
= 0;
66
}
67
/* Mark nodes from which we can reach the target
68
* start with children, so the target node and direct children are not
69
* flagged. */
70
target->
custom_flags
|=
OP_VISITED
;
71
for
(
Relation
*rel : target->
inlinks
) {
72
deg_graph_tag_paths_recursive
(rel->
from
);
73
}
74
/* Remove redundant paths to the target. */
75
for
(
Relation
*rel : target->
inlinks
) {
76
if
(rel->
from
->
type
==
NodeType::TIMESOURCE
) {
77
/* HACK: time source nodes don't get "custom_flags" flag
78
* set/cleared. */
79
/* TODO: there will be other types in future, so iterators above
80
* need modifying. */
81
continue
;
82
}
83
if
(rel->
from
->
custom_flags
&
OP_REACHABLE
) {
84
relations_to_remove.
append
(rel);
85
}
86
}
87
for
(
Relation
*rel : relations_to_remove) {
88
rel->
unlink
();
89
}
90
num_removed_relations += relations_to_remove.size();
91
relations_to_remove.clear();
92
}
93
DEG_DEBUG_PRINTF
((
::Depsgraph
*)graph, BUILD,
"Removed %d relations\n"
, num_removed_relations);
94
}
95
96
}
// namespace blender::deg
DEG_depsgraph_debug.hh
blender::Vector
Definition
BLI_vector.hh:76
blender::Vector::append
void append(const T &value)
Definition
BLI_vector.hh:489
deg_builder_transitive.h
deg_debug.h
DEG_DEBUG_PRINTF
#define DEG_DEBUG_PRINTF(depsgraph, type,...)
Definition
deg_debug.h:43
deg_node.hh
deg_node_component.hh
deg_node_operation.hh
depsgraph.hh
depsgraph_relation.hh
blender::deg
Definition
DEG_depsgraph_light_linking.hh:14
blender::deg::deg_graph_transitive_reduction
void deg_graph_transitive_reduction(Depsgraph *graph)
Definition
deg_builder_transitive.cc:57
blender::deg::NodeType::TIMESOURCE
@ TIMESOURCE
Definition
deg_node.hh:56
blender::deg::OP_VISITED
@ OP_VISITED
Definition
deg_builder_transitive.cc:39
blender::deg::OP_REACHABLE
@ OP_REACHABLE
Definition
deg_builder_transitive.cc:40
blender::deg::deg_graph_tag_paths_recursive
static void deg_graph_tag_paths_recursive(Node *node)
Definition
deg_builder_transitive.cc:43
blender::deg::Depsgraph
Definition
depsgraph.hh:48
blender::deg::Depsgraph::operations
OperationNodes operations
Definition
depsgraph.hh:133
blender::deg::Node
Definition
deg_node.hh:155
blender::deg::Node::type
NodeType type
Definition
deg_node.hh:181
blender::deg::Node::inlinks
Relations inlinks
Definition
deg_node.hh:182
blender::deg::Node::custom_flags
int custom_flags
Definition
deg_node.hh:190
blender::deg::OperationNode
Definition
deg_node_operation.hh:250
blender::deg::Relation
Definition
depsgraph_relation.hh:35
blender::deg::Relation::from
Node * from
Definition
depsgraph_relation.hh:43
blender::deg::Relation::unlink
void unlink()
Definition
depsgraph_relation.cc:15
Generated on
for Blender by
doxygen
1.16.1