Tulip  4.4.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
PropertyAnimation.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 PropertyAnimation<PropType, NodeType, EdgeType>::PropertyAnimation(tlp::Graph *graph, PropType *start, PropType *end, PropType *out,
23  tlp::BooleanProperty *selection, int frameCount, bool computeNodes, bool computeEdges, QObject* parent) :
24 
25  Animation(frameCount,parent), _graph(graph), _start(0), _end(0), _out(out), _computeNodes(computeNodes), _computeEdges(computeEdges) {
26 
27  assert(out);
28  assert(start);
29  assert(end);
30  assert(end->getGraph()->getRoot() == start->getGraph()->getRoot());
31  assert(end->getGraph()->getRoot() == out->getGraph()->getRoot());
32  assert(graph);
33  assert(frameCount > 0);
34 
35  this->_start = new PropType(start->getGraph());
36  *(this->_start) = *start;
37  this->_end = new PropType(end->getGraph());
38  *(this->_end) = *end;
39 
40  if (!selection) {
41  this->_selection = new tlp::BooleanProperty(graph);
42  this->_selection->setAllNodeValue(true);
43  this->_selection->setAllEdgeValue(true);
44  }
45  else {
46  this->_selection = new tlp::BooleanProperty(selection->getGraph());
47  *(this->_selection) = *selection;
48  }
49 }
50 
51 template<typename PropType, typename NodeType, typename EdgeType>
52 PropertyAnimation<PropType, NodeType, EdgeType>::~PropertyAnimation() {
53  delete _start;
54  delete _end;
55  delete _selection;
56 }
57 
58 template<typename PropType, typename NodeType, typename EdgeType>
59 void PropertyAnimation<PropType, NodeType, EdgeType>::frameChanged(int f) {
60  if (_computeNodes) {
61  tlp::node n;
62  forEach(n, _graph->getNodes()) {
63  if (_selection->getNodeValue(n))
64  _out->setNodeValue(n, getNodeFrameValue(_start->getNodeValue(n), _end->getNodeValue(n), f));
65  }
66  }
67 
68  if (_computeEdges) {
69  tlp::edge e;
70  forEach(e, _graph->getEdges()) {
71  if (_selection->getEdgeValue(e))
72  _out->setEdgeValue(e, getEdgeFrameValue(_start->getEdgeValue(e), _end->getEdgeValue(e), f));
73  }
74  }
75 }