Tulip  4.10.0
Better Visualization Through Research
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
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 *, const std::string& n="");
43 
45 
46  PropertyInterface* clonePrototype(Graph *, const std::string&) const;
47  static const std::string propertyTypename;
48  const 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, const Graph* graph = NULL);
55  virtual void setAllEdgeValue(const double &v, const Graph *graph = NULL);
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 getNodeDoubleDefaultValue() const {
71  return getNodeDefaultValue();
72  }
73  virtual double getNodeDoubleMin(const Graph* g = NULL) {
74  return getNodeMin(g);
75  }
76  virtual double getNodeDoubleMax(const Graph* g = NULL) {
77  return getNodeMax(g);
78  }
79  virtual double getEdgeDoubleValue(const edge e) const {
80  return getEdgeValue(e);
81  }
82  virtual double getEdgeDoubleDefaultValue() const {
83  return getEdgeDefaultValue();
84  }
85  virtual double getEdgeDoubleMin(const Graph* g = NULL) {
86  return getEdgeMin(g);
87  }
88  virtual double getEdgeDoubleMax(const Graph* g = NULL) {
89  return getEdgeMax(g);
90  }
91 
92  void nodesUniformQuantification(unsigned int);
93 
94  void edgesUniformQuantification(unsigned int);
95 
96  NumericProperty* copyProperty(Graph *g) {
97  DoubleProperty* newProp = new DoubleProperty(g);
98  newProp->copy(this);
99 
100  return newProp;
101  }
102 
103 private:
104  // override Observable::treatEvent
105  void treatEvent(const Event&);
106 
107 };
108 
109 /**
110  * @ingroup Graph
111  * @brief A graph property that maps a std::vector<double> value to graph elements.
112  */
113 
114 class TLP_SCOPE DoubleVectorProperty:public AbstractVectorProperty<tlp::DoubleVectorType, tlp::DoubleType> {
115 public :
116  DoubleVectorProperty(Graph *g, const std::string& n=""):AbstractVectorProperty<DoubleVectorType, tlp::DoubleType>(g, n) {}
117  // redefinition of some PropertyInterface methods
118  PropertyInterface* clonePrototype(Graph *, const std::string&) const;
119  static const std::string propertyTypename;
120  const std::string& getTypename() const {
121  return propertyTypename;
122  }
123 
124 };
125 
126 
127 }
128 #endif
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
PropertyInterface describes the interface of a graph property.
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
A graph property that maps a double value to graph elements.
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:47
Interface all numerical properties. Property values are always returned as double.
Base class for computing values on meta nodes and edges.
A graph property that maps a std::vector<double> value to graph elements.