Tulip  5.5.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/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  DEFINE_GET_CPP_CLASS_NAME;
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 private:
114  // override Observable::treatEvent
115  void treatEvent(const Event &) override;
116 };
117 
118 /**
119  * @ingroup Graph
120  * @brief A graph property that maps a std::vector<double> value to graph elements.
121  */
122 
123 class TLP_SCOPE DoubleVectorProperty
124  : public AbstractVectorProperty<tlp::DoubleVectorType, tlp::DoubleType> {
125 public:
126  DoubleVectorProperty(Graph *g, const std::string &n = "")
127  : AbstractVectorProperty<DoubleVectorType, tlp::DoubleType>(g, n) {}
128  // redefinition of some PropertyInterface methods
129  PropertyInterface *clonePrototype(Graph *, const std::string &) const override;
130  static const std::string propertyTypename;
131  const std::string &getTypename() const override {
132  return propertyTypename;
133  }
134  DEFINE_GET_CPP_CLASS_NAME;
135 };
136 } // namespace tlp
137 #endif
tlp::Graph
Definition: Graph.h:234
tlp::DoubleProperty::getTypename
const std::string & getTypename() const override
Gets a string describing the type of the property value (e.g. "graph", "double", "layout",...
Definition: DoubleProperty.h:48
tlp::PropertyInterface
PropertyInterface describes the interface of a graph property.
Definition: PropertyInterface.h:60
tlp::AbstractProperty
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
Definition: AbstractProperty.h:55
tlp::DoubleVectorProperty::getTypename
const std::string & getTypename() const override
Gets a string describing the type of the property value (e.g. "graph", "double", "layout",...
Definition: DoubleProperty.h:131
tlp::DoubleVectorProperty
A graph property that maps a std::vector<double> value to graph elements.
Definition: DoubleProperty.h:123
tlp::DoubleProperty
A graph property that maps a double value to graph elements.
Definition: DoubleProperty.h:39
tlp
Definition: AbstractProperty.h:34
tlp::edge
The edge struct represents an edge in a Graph object.
Definition: Edge.h:40
tlp::node
The node struct represents a node in a Graph object.
Definition: Node.h:40
tlp::MinMaxProperty
Abstracts the computation of minimal and maximal values on node and edge values of properties.
Definition: minmaxproperty.h:41