Tulip  4.3.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
DoubleProperty.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
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 #ifndef TULIP_METRIC_H
21 #define TULIP_METRIC_H
22 
23 #include <tulip/tuliphash.h>
24 #include <tulip/PropertyTypes.h>
25 #include <tulip/AbstractProperty.h>
26 #include <tulip/PropertyAlgorithm.h>
27 #include <tulip/minmaxproperty.h>
28 #include <tulip/NumericProperty.h>
29 
30 namespace tlp {
31 
32 class PropertyContext;
33 
34 typedef MinMaxProperty<tlp::DoubleType, tlp::DoubleType, tlp::NumericProperty> DoubleMinMaxProperty;
35 
36 /**
37  * @ingroup Graph
38  * @brief A graph property that maps a double value to graph elements.
39  */
40 class TLP_SCOPE DoubleProperty : public DoubleMinMaxProperty {
41 public :
42  DoubleProperty (Graph *, std::string n="");
43 
45 
46  PropertyInterface* clonePrototype(Graph *, const std::string& );
47  static const std::string propertyTypename;
48  std::string getTypename() const {
49  return propertyTypename;
50  }
51 
52  virtual void setNodeValue(const node n, const double &v);
53  virtual void setEdgeValue(const edge e, const double &v);
54  virtual void setAllNodeValue(const double &v);
55  virtual void setAllEdgeValue(const double &v);
56 
57  enum PredefinedMetaValueCalculator {NO_CALC = 0, AVG_CALC = 1, SUM_CALC = 2,
58  MAX_CALC = 3, MIN_CALC = 4
59  };
60 
61  // setMetaValueCalculator overloading
62  virtual void setMetaValueCalculator(PropertyInterface::MetaValueCalculator* calc);
63  void setMetaValueCalculator(PredefinedMetaValueCalculator nodeCalc = AVG_CALC,
64  PredefinedMetaValueCalculator edgeCalc = AVG_CALC);
65 
66  // NumericProperty interface
67  virtual double getNodeDoubleValue(const node n ) const {
68  return getNodeValue(n);
69  }
70  virtual double getNodeDoubleMin(Graph* g = NULL) {
71  return getNodeMin(g);
72  }
73  virtual double getNodeDoubleMax(Graph* g = NULL) {
74  return getNodeMax(g);
75  }
76  virtual double getEdgeDoubleValue(const edge e) const {
77  return getEdgeValue(e);
78  }
79  virtual double getEdgeDoubleMin(Graph* g = NULL) {
80  return getEdgeMin(g);
81  }
82  virtual double getEdgeDoubleMax(Graph* g = NULL) {
83  return getEdgeMax(g);
84  }
85 
86  void nodesUniformQuantification(unsigned int);
87 
88  void edgesUniformQuantification(unsigned int);
89 
90  NumericProperty* copyProperty(Graph *g) {
91  DoubleProperty* newProp = new DoubleProperty(g);
92  newProp->copy(this);
93 
94  return newProp;
95  }
96 
97 private:
98  // override Observable::treatEvent
99  void treatEvent(const Event&);
100 
101 };
102 
103 /**
104  * @ingroup Graph
105  * @brief A graph property that maps a std::vector<double> value to graph elements.
106  */
107 
108 class TLP_SCOPE DoubleVectorProperty:public AbstractVectorProperty<tlp::DoubleVectorType, tlp::DoubleType> {
109 public :
110  DoubleVectorProperty(Graph *g, std::string n=""):AbstractVectorProperty<DoubleVectorType, tlp::DoubleType>(g, n) {}
111  // redefinition of some PropertyInterface methods
112  PropertyInterface* clonePrototype(Graph *, const std::string& );
113  static const std::string propertyTypename;
114  std::string getTypename() const {
115  return propertyTypename;
116  }
117 
118 };
119 
120 
121 }
122 #endif