Tulip  5.1.0
Large graphs analysis and drawing
VectorPropertyAnimation.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 #include <tulip/ForEach.h>
20 
21 template<typename PropType, typename RealType, typename VectorType, unsigned int SIZE>
22 VectorPropertyAnimation<PropType, RealType, VectorType, SIZE>::VectorPropertyAnimation(tlp::Graph *graph, PropType *start, PropType *end,
23  PropType *out, tlp::BooleanProperty *selection, int frameCount, bool computeNodes, bool computeEdges,QObject* parent) :
24  CachedPropertyAnimation<PropType, RealType, RealType> (graph, start, end, out, selection, frameCount, computeNodes, computeEdges,parent) {
25 
26  assert(frameCount > 1);
27 
28  if (this->_computeNodes) {
29  tlp::node n;
30  forEach(n, this->_graph->getNodes()) {
31  if (this->_selection && !this->_selection->getNodeValue(n))
32  continue;
33 
34  std::pair<PropVector, PropVector> values(PropVector(this->_start->getNodeValue(n)), PropVector(this->_end->getNodeValue(n)));
35 
36  if (steps.find(values) == steps.end()) {
37  tlp::Vector<double, SIZE> stepsVector;
38 
39  for (unsigned int i = 0; i < SIZE; ++i)
40  stepsVector[i] = ((double)values.second[i] - (double)values.first[i]) * 1. / (frameCount - 1);
41 
42  steps[values] = stepsVector;
43  }
44  }
45  }
46 
47  if (this->_computeEdges) {
48  tlp::edge e;
49  forEach(e, this->_graph->getEdges()) {
50  if (this->_selection && !this->_selection->getEdgeValue(e))
51  continue;
52 
53  std::pair<PropVector, PropVector> values(PropVector(this->_start->getEdgeValue(e)), PropVector(this->_end->getEdgeValue(e)));
54 
55  if (steps.find(values) == steps.end()) {
56  tlp::Vector<double, SIZE> stepsVector;
57 
58  for (unsigned int i = 0; i < SIZE; ++i)
59  stepsVector[i] = ((double) (values.second[i] - (double)values.first[i])) * 1. / (frameCount - 1);
60 
61  steps[values] = stepsVector;
62  }
63  }
64  }
65 }
66 
67 template<typename PropType, typename RealType, typename VectorType, unsigned int SIZE>
68 RealType VectorPropertyAnimation<PropType, RealType, VectorType, SIZE>::getNodeFrameValue(const RealType &startValue, const RealType &endValue,
69  int frame) {
70  PropVector result((PropVector)startValue);
71  std::pair<PropVector, PropVector> values(result, (PropVector) endValue);
72  tlp::Vector<double, SIZE> stepVal(steps[values]);
73 
74  for (unsigned i=0; i < SIZE; ++i)
75  result[i] += stepVal[i] * frame;
76 
77  return RealType(result);
78 }
79 
80 template<typename PropType, typename RealType, typename VectorType, unsigned int SIZE>
81 RealType VectorPropertyAnimation<PropType, RealType, VectorType, SIZE>::getEdgeFrameValue(const RealType &startValue, const RealType &endValue,
82  int frame) {
83  return getNodeFrameValue(startValue, endValue, frame);
84 }
A graph property that maps a boolean value to graph elements.
The edge struct represents an edge in a Graph object.
Definition: Edge.h:39
The node struct represents a node in a Graph object.
Definition: Node.h:39