Tulip  4.6.0
Better Visualization Through Research
library/tulip-gui/include/tulip/cxx/CachedPropertyAnimation.cxx
00001 /*
00002  *
00003  * This file is part of Tulip (www.tulip-software.org)
00004  *
00005  * Authors: David Auber and the Tulip development Team
00006  * from LaBRI, University of Bordeaux
00007  *
00008  * Tulip is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation, either version 3
00011  * of the License, or (at your option) any later version.
00012  *
00013  * Tulip is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016  * See the GNU General Public License for more details.
00017  *
00018  */
00019 #include <tulip/ForEach.h>
00020 
00021 template<typename PropType, typename NodeType, typename EdgeType>
00022 CachedPropertyAnimation<PropType, NodeType, EdgeType>::CachedPropertyAnimation(tlp::Graph *graph, PropType *start, PropType *end, PropType *out,
00023     tlp::BooleanProperty *selection, int frameCount, bool computeNodes, bool computeEdges,QObject* parent) :
00024   PropertyAnimation<PropType, NodeType, EdgeType> (graph, start, end, out, selection, frameCount, computeNodes, computeEdges,parent) {
00025 
00026   if (this->_computeNodes) {
00027     tlp::node n;
00028     forEach (n, this->_graph->getNodes()) {
00029       if (this->equalNodes(this->_end->getNodeValue(n), this->_start->getNodeValue(n))) {
00030         this->_selection->setNodeValue(n, false);
00031         //Init the out properties with the default value.
00032         this->_out->setNodeValue(n,this->_end->getNodeValue(n));
00033       }
00034     }
00035   }
00036 
00037   if (this->_computeEdges) {
00038     tlp::edge e;
00039     forEach (e, this->_graph->getEdges()) {
00040       if (this->equalEdges(this->_end->getEdgeValue(e), this->_start->getEdgeValue(e))) {
00041         this->_selection->setEdgeValue(e, false);
00042         //Init the out properties with the default value.
00043         this->_out->setEdgeValue(e,end->getEdgeValue(e));
00044       }
00045     }
00046   }
00047 }
00048 
00049 template<typename PropType, typename NodeType, typename EdgeType>
00050 CachedPropertyAnimation<PropType, NodeType, EdgeType>::~CachedPropertyAnimation() {
00051 }
00052 
00053 template<typename PropType, typename NodeType, typename EdgeType>
00054 void CachedPropertyAnimation<PropType, NodeType, EdgeType>::frameChanged(int f) {
00055   if (this->_computeNodes) {
00056     computedNodeSteps.clear();
00057     tlp::node n;
00058     forEach(n, this->_graph->getNodes()) {
00059       if (this->_selection && !this->_selection->getNodeValue(n))
00060         continue;
00061 
00062       std::pair<NodeType, NodeType> values(this->_start->getNodeValue(n), this->_end->getNodeValue(n));
00063       NodeType frameValue;
00064 
00065       if (computedNodeSteps.find(values) == computedNodeSteps.end()) {
00066         frameValue = this->getNodeFrameValue(values.first, values.second, f);
00067         computedNodeSteps[values] = frameValue;
00068       }
00069       else
00070         frameValue = computedNodeSteps[values];
00071 
00072       this->_out->setNodeValue(n, frameValue);
00073     }
00074   }
00075 
00076   if (this->_computeEdges) {
00077     computedEdgeSteps.clear();
00078     tlp::edge e;
00079     forEach(e, this->_graph->getEdges()) {
00080       if (this->_selection && !this->_selection->getEdgeValue(e))
00081         continue;
00082 
00083       std::pair<EdgeType, EdgeType> values(this->_start->getEdgeValue(e), this->_end->getEdgeValue(e));
00084       EdgeType frameValue;
00085 
00086       if (computedEdgeSteps.find(values) == computedEdgeSteps.end()) {
00087         frameValue = this->getEdgeFrameValue(values.first, values.second, f);
00088         computedEdgeSteps[values] = frameValue;
00089       }
00090       else
00091         frameValue = computedEdgeSteps[values];
00092 
00093       this->_out->setEdgeValue(e, frameValue);
00094     }
00095   }
00096 }
 All Classes Files Functions Variables Enumerations Enumerator Properties