Tulip  5.2.1
Large graphs analysis and drawing
DoubleProperty.h
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 #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 
44  void clone_handler(
46 
47  PropertyInterface *clonePrototype(Graph *, const std::string &) const override;
48  static const std::string propertyTypename;
49  const std::string &getTypename() const override {
50  return propertyTypename;
51  }
52 
53  void setNodeValue(const node n, tlp::StoredType<double>::ReturnedConstValue v) override;
54  void setEdgeValue(const edge e, tlp::StoredType<double>::ReturnedConstValue v) override;
55  void setAllNodeValue(tlp::StoredType<double>::ReturnedConstValue v) override;
56 
57  void setValueToGraphNodes(tlp::StoredType<double>::ReturnedConstValue v,
58  const Graph *graph) override;
59  void setAllEdgeValue(tlp::StoredType<double>::ReturnedConstValue v) override;
60  void setValueToGraphEdges(tlp::StoredType<double>::ReturnedConstValue v,
61  const Graph *graph) override;
62 
63  enum PredefinedMetaValueCalculator {
64  NO_CALC = 0,
65  AVG_CALC = 1,
66  SUM_CALC = 2,
67  MAX_CALC = 3,
68  MIN_CALC = 4
69  };
70 
71  // setMetaValueCalculator overloading
72  void setMetaValueCalculator(PropertyInterface::MetaValueCalculator *calc) override;
73  void setMetaValueCalculator(PredefinedMetaValueCalculator nodeCalc = AVG_CALC,
74  PredefinedMetaValueCalculator edgeCalc = AVG_CALC);
75 
76  // NumericProperty interface
77  double getNodeDoubleValue(const node n) const override {
78  return getNodeValue(n);
79  }
80  double getNodeDoubleDefaultValue() const override {
81  return getNodeDefaultValue();
82  }
83  double getNodeDoubleMin(const Graph *g = nullptr) override {
84  return getNodeMin(g);
85  }
86  double getNodeDoubleMax(const Graph *g = nullptr) override {
87  return getNodeMax(g);
88  }
89  double getEdgeDoubleValue(const edge e) const override {
90  return getEdgeValue(e);
91  }
92  double getEdgeDoubleDefaultValue() const override {
93  return getEdgeDefaultValue();
94  }
95  double getEdgeDoubleMin(const Graph *g = nullptr) override {
96  return getEdgeMin(g);
97  }
98  double getEdgeDoubleMax(const Graph *g = nullptr) override {
99  return getEdgeMax(g);
100  }
101 
102  void nodesUniformQuantification(unsigned int) override;
103 
104  void edgesUniformQuantification(unsigned int) override;
105 
106  NumericProperty *copyProperty(Graph *g) override {
107  DoubleProperty *newProp = new DoubleProperty(g);
108  newProp->copy(this);
109 
110  return newProp;
111  }
112 
113  _DEPRECATED void setAllEdgeValue(tlp::StoredType<double>::ReturnedConstValue v,
114  const Graph *graph) override;
115  _DEPRECATED void setAllNodeValue(tlp::StoredType<double>::ReturnedConstValue v,
116  const Graph *graph) override;
117 
118 private:
119  // override Observable::treatEvent
120  void treatEvent(const Event &) override;
121 };
122 
123 /**
124  * @ingroup Graph
125  * @brief A graph property that maps a std::vector<double> value to graph elements.
126  */
127 
128 class TLP_SCOPE DoubleVectorProperty
129  : public AbstractVectorProperty<tlp::DoubleVectorType, tlp::DoubleType> {
130 public:
131  DoubleVectorProperty(Graph *g, const std::string &n = "")
132  : AbstractVectorProperty<DoubleVectorType, tlp::DoubleType>(g, n) {}
133  // redefinition of some PropertyInterface methods
134  PropertyInterface *clonePrototype(Graph *, const std::string &) const override;
135  static const std::string propertyTypename;
136  const std::string &getTypename() const override {
137  return propertyTypename;
138  }
139 };
140 } // namespace tlp
141 #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:40
The node struct represents a node in a Graph object.
Definition: Node.h:40
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:51
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.