Tulip  4.6.0
Better Visualization Through Research
library/tulip-core/include/tulip/DoubleProperty.h
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 
00020 #ifndef TULIP_METRIC_H
00021 #define TULIP_METRIC_H
00022 
00023 #include <tulip/tuliphash.h>
00024 #include <tulip/PropertyTypes.h>
00025 #include <tulip/AbstractProperty.h>
00026 #include <tulip/PropertyAlgorithm.h>
00027 #include <tulip/minmaxproperty.h>
00028 #include <tulip/NumericProperty.h>
00029 
00030 namespace tlp {
00031 
00032 class PropertyContext;
00033 
00034 typedef MinMaxProperty<tlp::DoubleType, tlp::DoubleType, tlp::NumericProperty> DoubleMinMaxProperty;
00035 
00036 /**
00037  * @ingroup Graph
00038  * @brief A graph property that maps a double value to graph elements.
00039  */
00040 class TLP_SCOPE DoubleProperty : public DoubleMinMaxProperty {
00041 public :
00042   DoubleProperty (Graph *, const std::string& n="");
00043 
00044   virtual void clone_handler(AbstractProperty<tlp::DoubleType, tlp::DoubleType, tlp::NumericProperty> &);
00045 
00046   PropertyInterface* clonePrototype(Graph *, const std::string& );
00047   static const std::string propertyTypename;
00048   const std::string& getTypename() const {
00049     return propertyTypename;
00050   }
00051 
00052   virtual void setNodeValue(const node n, const double &v);
00053   virtual void setEdgeValue(const edge e, const double &v);
00054   virtual void setAllNodeValue(const double &v);
00055   virtual void setAllEdgeValue(const double &v);
00056 
00057   enum PredefinedMetaValueCalculator {NO_CALC = 0, AVG_CALC = 1, SUM_CALC = 2,
00058                                       MAX_CALC = 3, MIN_CALC = 4
00059                                      };
00060 
00061   // setMetaValueCalculator overloading
00062   virtual void setMetaValueCalculator(PropertyInterface::MetaValueCalculator* calc);
00063   void setMetaValueCalculator(PredefinedMetaValueCalculator nodeCalc = AVG_CALC,
00064                               PredefinedMetaValueCalculator edgeCalc = AVG_CALC);
00065 
00066   // NumericProperty interface
00067   virtual double getNodeDoubleValue(const node n) const {
00068     return getNodeValue(n);
00069   }
00070   virtual double getNodeDoubleDefaultValue() const {
00071     return getNodeDefaultValue();
00072   }
00073   virtual double getNodeDoubleMin(Graph* g = NULL) {
00074     return getNodeMin(g);
00075   }
00076   virtual double getNodeDoubleMax(Graph* g = NULL) {
00077     return getNodeMax(g);
00078   }
00079   virtual double getEdgeDoubleValue(const edge e) const {
00080     return getEdgeValue(e);
00081   }
00082   virtual double getEdgeDoubleDefaultValue() const {
00083     return getEdgeDefaultValue();
00084   }
00085   virtual double getEdgeDoubleMin(Graph* g = NULL) {
00086     return getEdgeMin(g);
00087   }
00088   virtual double getEdgeDoubleMax(Graph* g = NULL) {
00089     return getEdgeMax(g);
00090   }
00091 
00092   void nodesUniformQuantification(unsigned int);
00093 
00094   void edgesUniformQuantification(unsigned int);
00095 
00096   NumericProperty* copyProperty(Graph *g) {
00097     DoubleProperty* newProp = new DoubleProperty(g);
00098     newProp->copy(this);
00099 
00100     return newProp;
00101   }
00102 
00103 private:
00104   // override Observable::treatEvent
00105   void treatEvent(const Event&);
00106 
00107 };
00108 
00109 /**
00110  * @ingroup Graph
00111  * @brief A graph property that maps a std::vector<double> value to graph elements.
00112  */
00113 
00114 class TLP_SCOPE DoubleVectorProperty:public AbstractVectorProperty<tlp::DoubleVectorType, tlp::DoubleType> {
00115 public :
00116   DoubleVectorProperty(Graph *g, const std::string& n=""):AbstractVectorProperty<DoubleVectorType, tlp::DoubleType>(g, n) {}
00117   // redefinition of some PropertyInterface methods
00118   PropertyInterface* clonePrototype(Graph *, const std::string& );
00119   static const std::string propertyTypename;
00120   const std::string& getTypename() const {
00121     return propertyTypename;
00122   }
00123 
00124 };
00125 
00126 
00127 }
00128 #endif
 All Classes Files Functions Variables Enumerations Enumerator Properties