Tulip  5.2.1
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), _graph(graph), _start(nullptr), _end(nullptr), _out(out),
28  _computeNodes(computeNodes), _computeEdges(computeEdges) {
29 
30  assert(out);
31  assert(start);
32  assert(end);
33  assert(end->getGraph()->getRoot() == start->getGraph()->getRoot());
34  assert(end->getGraph()->getRoot() == out->getGraph()->getRoot());
35  assert(graph);
36  assert(frameCount > 0);
37 
38  this->_start = new PropType(start->getGraph());
39  *(this->_start) = *start;
40  this->_end = new PropType(end->getGraph());
41  *(this->_end) = *end;
42 
43  if (!selection) {
44  this->_selection = new tlp::BooleanProperty(graph);
45  this->_selection->setAllNodeValue(true);
46  this->_selection->setAllEdgeValue(true);
47  } else {
48  this->_selection = new tlp::BooleanProperty(selection->getGraph());
49  *(this->_selection) = *selection;
50  }
51 }
52 
53 template <typename PropType, typename NodeType, typename EdgeType>
54 PropertyAnimation<PropType, NodeType, EdgeType>::~PropertyAnimation() {
55  delete _start;
56  delete _end;
57  delete _selection;
58 }
59 
60 template <typename PropType, typename NodeType, typename EdgeType>
61 void PropertyAnimation<PropType, NodeType, EdgeType>::frameChanged(int f) {
62  if (_computeNodes) {
63  for (auto n : _graph->nodes()) {
64  if (_selection->getNodeValue(n))
65  _out->setNodeValue(n, getNodeFrameValue(_start->getNodeValue(n), _end->getNodeValue(n), f));
66  }
67  }
68 
69  if (_computeEdges) {
70  for (auto e : _graph->edges()) {
71  if (_selection->getEdgeValue(e))
72  _out->setEdgeValue(e, getEdgeFrameValue(_start->getEdgeValue(e), _end->getEdgeValue(e), f));
73  }
74  }
75 }
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.