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