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