Tulip  5.2.0
Large graphs analysis and drawing
CachedPropertyAnimation.cxx
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 template <typename PropType, typename NodeType, typename EdgeType>
21 CachedPropertyAnimation<PropType, NodeType, EdgeType>::CachedPropertyAnimation(
22  tlp::Graph *graph, PropType *start, PropType *end, PropType *out,
23  tlp::BooleanProperty *selection, int frameCount, bool computeNodes, bool computeEdges,
24  QObject *parent)
25  : PropertyAnimation<PropType, NodeType, EdgeType>(graph, start, end, out, selection, frameCount,
26  computeNodes, computeEdges, parent) {
27 
28  if (this->_computeNodes) {
29  for (auto n : this->_graph->nodes()) {
30  if (this->equalNodes(this->_end->getNodeValue(n), this->_start->getNodeValue(n))) {
31  this->_selection->setNodeValue(n, false);
32  // Init the out properties with the default value.
33  this->_out->setNodeValue(n, this->_end->getNodeValue(n));
34  }
35  }
36  }
37 
38  if (this->_computeEdges) {
39  for (auto e : this->_graph->edges()) {
40  if (this->equalEdges(this->_end->getEdgeValue(e), this->_start->getEdgeValue(e))) {
41  this->_selection->setEdgeValue(e, false);
42  // Init the out properties with the default value.
43  this->_out->setEdgeValue(e, end->getEdgeValue(e));
44  }
45  }
46  }
47 }
48 
49 template <typename PropType, typename NodeType, typename EdgeType>
50 CachedPropertyAnimation<PropType, NodeType, EdgeType>::~CachedPropertyAnimation() {}
51 
52 template <typename PropType, typename NodeType, typename EdgeType>
53 void CachedPropertyAnimation<PropType, NodeType, EdgeType>::frameChanged(int f) {
54  if (this->_computeNodes) {
55  computedNodeSteps.clear();
56  for (auto n : this->_graph->nodes()) {
57  if (this->_selection && !this->_selection->getNodeValue(n))
58  continue;
59 
60  std::pair<NodeType, NodeType> values(this->_start->getNodeValue(n),
61  this->_end->getNodeValue(n));
62  NodeType frameValue;
63 
64  if (computedNodeSteps.find(values) == computedNodeSteps.end()) {
65  frameValue = this->getNodeFrameValue(values.first, values.second, f);
66  computedNodeSteps[values] = frameValue;
67  } else
68  frameValue = computedNodeSteps[values];
69 
70  this->_out->setNodeValue(n, frameValue);
71  }
72  }
73 
74  if (this->_computeEdges) {
75  computedEdgeSteps.clear();
76  for (auto e : this->_graph->edges()) {
77  if (this->_selection && !this->_selection->getEdgeValue(e))
78  continue;
79 
80  std::pair<EdgeType, EdgeType> values(this->_start->getEdgeValue(e),
81  this->_end->getEdgeValue(e));
82  EdgeType frameValue;
83 
84  if (computedEdgeSteps.find(values) == computedEdgeSteps.end()) {
85  frameValue = this->getEdgeFrameValue(values.first, values.second, f);
86  computedEdgeSteps[values] = frameValue;
87  } else
88  frameValue = computedEdgeSteps[values];
89 
90  this->_out->setEdgeValue(e, frameValue);
91  }
92  }
93 }
A graph property that maps a boolean value to graph elements.