Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
CachedPropertyAnimation.cxx
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
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 #include <tulip/ForEach.h>
20 
21 template<typename PropType, typename NodeType, typename EdgeType>
22 CachedPropertyAnimation<PropType, NodeType, EdgeType>::CachedPropertyAnimation(tlp::Graph *graph, PropType *start, PropType *end, PropType *out,
23  tlp::BooleanProperty *selection, int frameCount, bool computeNodes, bool computeEdges,QObject* parent) :
24  PropertyAnimation<PropType, NodeType, EdgeType> (graph, start, end, out, selection, frameCount, computeNodes, computeEdges,parent) {
25 
26  if (this->_computeNodes) {
27  tlp::node n;
28  forEach (n, this->_graph->getNodes()) {
29  if (this->equalNodes(this->_end->getNodeValue(n), this->_start->getNodeValue(n))) {
30  this->_selection->setNodeValue(n, false);
31  //Init the out properties with the default value.
32  this->_out->setNodeValue(n,this->_end->getNodeValue(n));
33  }
34  }
35  }
36 
37  if (this->_computeEdges) {
38  tlp::edge e;
39  forEach (e, this->_graph->getEdges()) {
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 
53 template<typename PropType, typename NodeType, typename EdgeType>
54 void CachedPropertyAnimation<PropType, NodeType, EdgeType>::frameChanged(int f) {
55  if (this->_computeNodes) {
56  computedNodeSteps.clear();
57  tlp::node n;
58  forEach(n, this->_graph->getNodes()) {
59  if (this->_selection && !this->_selection->getNodeValue(n))
60  continue;
61 
62  std::pair<NodeType, NodeType> values(this->_start->getNodeValue(n), this->_end->getNodeValue(n));
63  NodeType frameValue;
64 
65  if (computedNodeSteps.find(values) == computedNodeSteps.end()) {
66  frameValue = this->getNodeFrameValue(values.first, values.second, f);
67  computedNodeSteps[values] = frameValue;
68  }
69  else
70  frameValue = computedNodeSteps[values];
71 
72  this->_out->setNodeValue(n, frameValue);
73  }
74  }
75 
76  if (this->_computeEdges) {
77  computedEdgeSteps.clear();
78  tlp::edge e;
79  forEach(e, this->_graph->getEdges()) {
80  if (this->_selection && !this->_selection->getEdgeValue(e))
81  continue;
82 
83  std::pair<EdgeType, EdgeType> values(this->_start->getEdgeValue(e), this->_end->getEdgeValue(e));
84  EdgeType frameValue;
85 
86  if (computedEdgeSteps.find(values) == computedEdgeSteps.end()) {
87  frameValue = this->getEdgeFrameValue(values.first, values.second, f);
88  computedEdgeSteps[values] = frameValue;
89  }
90  else
91  frameValue = computedEdgeSteps[values];
92 
93  this->_out->setEdgeValue(e, frameValue);
94  }
95  }
96 }