Tulip  5.2.0
Large graphs analysis and drawing
PropertyAnimation.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 PropertyAnimation<PropType, NodeType, EdgeType>::PropertyAnimation(
22  tlp::Graph *graph, PropType *start, PropType *end, PropType *out,
23  tlp::BooleanProperty *selection, int frameCount, bool computeNodes, bool computeEdges,
24  QObject *parent)
25  :
26 
27  Animation(frameCount, parent),
28  _graph(graph), _start(nullptr), _end(nullptr), _out(out), _computeNodes(computeNodes),
29  _computeEdges(computeEdges) {
30 
31  assert(out);
32  assert(start);
33  assert(end);
34  assert(end->getGraph()->getRoot() == start->getGraph()->getRoot());
35  assert(end->getGraph()->getRoot() == out->getGraph()->getRoot());
36  assert(graph);
37  assert(frameCount > 0);
38 
39  this->_start = new PropType(start->getGraph());
40  *(this->_start) = *start;
41  this->_end = new PropType(end->getGraph());
42  *(this->_end) = *end;
43 
44  if (!selection) {
45  this->_selection = new tlp::BooleanProperty(graph);
46  this->_selection->setAllNodeValue(true);
47  this->_selection->setAllEdgeValue(true);
48  } else {
49  this->_selection = new tlp::BooleanProperty(selection->getGraph());
50  *(this->_selection) = *selection;
51  }
52 }
53 
54 template <typename PropType, typename NodeType, typename EdgeType>
55 PropertyAnimation<PropType, NodeType, EdgeType>::~PropertyAnimation() {
56  delete _start;
57  delete _end;
58  delete _selection;
59 }
60 
61 template <typename PropType, typename NodeType, typename EdgeType>
62 void PropertyAnimation<PropType, NodeType, EdgeType>::frameChanged(int f) {
63  if (_computeNodes) {
64  for (auto n : _graph->nodes()) {
65  if (_selection->getNodeValue(n))
66  _out->setNodeValue(n, getNodeFrameValue(_start->getNodeValue(n), _end->getNodeValue(n), f));
67  }
68  }
69 
70  if (_computeEdges) {
71  for (auto e : _graph->edges()) {
72  if (_selection->getEdgeValue(e))
73  _out->setEdgeValue(e, getEdgeFrameValue(_start->getEdgeValue(e), _end->getEdgeValue(e), f));
74  }
75  }
76 }
A graph property that maps a boolean value to graph elements.
virtual void setNodeValue(const node n, typename tlp::StoredType< typename Tnode::RealType >::ReturnedConstValue v)
Sets the value of a node and notify the observers of a modification.