Tulip 6.1.0
Large graphs analysis and drawing
Loading...
Searching...
No Matches
DoubleProperty.h
1/*
2 *
3 * This file is part of Tulip (https://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
29namespace tlp {
30
31class PropertyContext;
32
34
35/**
36 * @ingroup Graph
37 * @brief A graph property that maps a double value to graph elements.
38 */
39class TLP_SCOPE DoubleProperty : public DoubleMinMaxProperty {
40public:
41 DoubleProperty(Graph *, const std::string &n = "");
42 using DoubleMinMaxProperty::operator=;
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
55 // inner class used to extend the overloading of the operator[]
56 // to set a node value
57 class nodeValueRef : public AbstractProperty<tlp::DoubleType, tlp::DoubleType,
58 tlp::NumericProperty>::nodeValueRef {
59 public:
60 constexpr nodeValueRef(DoubleProperty *prop, node n)
61 : AbstractProperty<tlp::DoubleType, tlp::DoubleType, tlp::NumericProperty>::nodeValueRef(
62 prop, n) {}
63
64 nodeValueRef &operator=(
65 typename tlp::StoredType<typename DoubleType::RealType>::ReturnedConstValue val) noexcept {
66 _prop->setNodeValue(_n, val);
67 return *this;
68 }
69
70 // prefix increment
71 nodeValueRef &operator++() {
72 _prop->setNodeValue(_n, getValue() + 1);
73 return *this;
74 }
75
76 // postfix increment
77 auto operator++(int) {
78 auto val = getValue();
79 _prop->setNodeValue(_n, val + 1);
80 return val;
81 }
82
83 // increment and assign
84 nodeValueRef &operator+=(double val) {
85 _prop->setNodeValue(_n, getValue() + val);
86 return *this;
87 }
88
89 // prefix decrement
90 nodeValueRef &operator--() {
91 _prop->setNodeValue(_n, getValue() - 1);
92 return *this;
93 }
94
95 // postfix decrement
96 auto operator--(int) {
97 auto val = getValue();
98 _prop->setNodeValue(_n, val - 1);
99 return val;
100 }
101
102 // decrement and assign
103 nodeValueRef &operator-=(double val) {
104 _prop->setNodeValue(_n, getValue() - val);
105 return *this;
106 }
107 };
108
109 // overload operator[] to set a node value
110 constexpr nodeValueRef operator[](node n) {
111 return nodeValueRef(this, n);
112 }
113
114 void setEdgeValue(const edge e, tlp::StoredType<double>::ReturnedConstValue v) override;
115
116 // inner class used to extend the overloading of the operator[]
117 // to set an edge value
118 class edgeValueRef : public AbstractProperty<tlp::DoubleType, tlp::DoubleType,
119 tlp::NumericProperty>::edgeValueRef {
120 public:
121 constexpr edgeValueRef(DoubleProperty *prop, edge e)
122 : AbstractProperty<tlp::DoubleType, tlp::DoubleType, tlp::NumericProperty>::edgeValueRef(
123 prop, e) {}
124
125 edgeValueRef &operator=(
126 typename tlp::StoredType<typename DoubleType::RealType>::ReturnedConstValue val) noexcept {
127 _prop->setEdgeValue(_e, val);
128 return *this;
129 }
130
131 // prefix increment
132 edgeValueRef &operator++() {
133 _prop->setEdgeValue(_e, getValue() + 1);
134 return *this;
135 }
136
137 // postfix increment
138 auto operator++(int) {
139 auto val = getValue();
140 _prop->setEdgeValue(_e, val + 1);
141 return val;
142 }
143
144 // increase value
145 edgeValueRef &operator+=(double val) {
146 _prop->setEdgeValue(_e, getValue() + val);
147 return *this;
148 }
149
150 // prefix decrement
151 edgeValueRef &operator--() {
152 _prop->setEdgeValue(_e, getValue() - 1);
153 return *this;
154 }
155
156 // postfix decrement
157 auto operator--(int) {
158 auto val = getValue();
159 _prop->setEdgeValue(_e, val - 1);
160 return val;
161 }
162
163 // decrease value
164 edgeValueRef &operator-=(double val) {
165 _prop->setEdgeValue(_e, getValue() - val);
166 return *this;
167 }
168 };
169
170 // overload operator[] to set an edge value
171 constexpr edgeValueRef operator[](edge e) {
172 return edgeValueRef(this, e);
173 }
174
175 void setAllNodeValue(tlp::StoredType<double>::ReturnedConstValue v) override;
176
177 void setValueToGraphNodes(tlp::StoredType<double>::ReturnedConstValue v,
178 const Graph *graph) override;
179 void setAllEdgeValue(tlp::StoredType<double>::ReturnedConstValue v) override;
180 void setValueToGraphEdges(tlp::StoredType<double>::ReturnedConstValue v,
181 const Graph *graph) override;
182
183 enum StandardMetaValueCalculator : unsigned int {
184 NO_CALC = 0,
185 AVG_CALC = 1,
186 SUM_CALC = 2,
187 MAX_CALC = 3,
188 MIN_CALC = 4
189 };
190
191 // setMetaValueCalculator overloading
193 void setMetaValueCalculator(StandardMetaValueCalculator nodeCalc = AVG_CALC,
194 StandardMetaValueCalculator edgeCalc = AVG_CALC);
195
196 // NumericProperty interface
197 double getNodeDoubleValue(const node n) const override {
198 return getNodeValue(n);
199 }
200 double getNodeDoubleDefaultValue() const override {
201 return getNodeDefaultValue();
202 }
203 double getNodeDoubleMin(const Graph *g = nullptr) override {
204 return getNodeMin(g);
205 }
206 double getNodeDoubleMax(const Graph *g = nullptr) override {
207 return getNodeMax(g);
208 }
209 double getEdgeDoubleValue(const edge e) const override {
210 return getEdgeValue(e);
211 }
212 double getEdgeDoubleDefaultValue() const override {
213 return getEdgeDefaultValue();
214 }
215 double getEdgeDoubleMin(const Graph *g = nullptr) override {
216 return getEdgeMin(g);
217 }
218 double getEdgeDoubleMax(const Graph *g = nullptr) override {
219 return getEdgeMax(g);
220 }
221
222 void nodesUniformQuantification(unsigned int) override;
223
224 void edgesUniformQuantification(unsigned int) override;
225
226 NumericProperty *copyProperty(Graph *g) override {
227 DoubleProperty *newProp = new DoubleProperty(g);
228 newProp->copy(this);
229
230 return newProp;
231 }
232
233private:
234 // override Observable::treatEvent
235 void treatEvent(const Event &) override;
236};
237
238/**
239 * @ingroup Graph
240 * @brief A graph property that maps a std::vector<double> value to graph elements.
241 */
242
243class TLP_SCOPE DoubleVectorProperty
244 : public AbstractVectorProperty<tlp::DoubleVectorType, tlp::DoubleType> {
245public:
246 DoubleVectorProperty(Graph *g, const std::string &n = "")
247 : AbstractVectorProperty<DoubleVectorType, tlp::DoubleType>(g, n) {}
248 // redefinition of some PropertyInterface methods
249 using AbstractVectorProperty<tlp::DoubleVectorType, tlp::DoubleType>::operator=;
250 PropertyInterface *clonePrototype(Graph *, const std::string &) const override;
251 static const std::string propertyTypename;
252 const std::string &getTypename() const override {
253 return propertyTypename;
254 }
255 DEFINE_GET_CPP_CLASS_NAME;
256};
257} // namespace tlp
258#endif
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
tlp::StoredType< typenameTnode::RealType >::ReturnedConstValue getNodeValue(const node n) const
Returns the value associated with the node n in this property. If there is no value,...
A graph property that maps a double value to graph elements.
const std::string & getTypename() const override
Gets a string describing the type of the property value (e.g. "graph", "double", "layout",...
void setMetaValueCalculator(PropertyInterface::MetaValueCalculator *calc) override
Sets the Calculator for meta nodes and edges.
PropertyInterface * clonePrototype(Graph *, const std::string &) const override
Creates a property of the same type (e.g. tlp::DoubleProperty) in the graph. The new property will no...
const std::string & getTypename() const override
Gets a string describing the type of the property value (e.g. "graph", "double", "layout",...
PropertyInterface * clonePrototype(Graph *, const std::string &) const override
Creates a property of the same type (e.g. tlp::DoubleProperty) in the graph. The new property will no...
Abstracts the computation of minimal and maximal values on node and edge values of properties.
Interface all numerical properties. Property values are always returned as double.
Base class for computing values on meta nodes and edges.
PropertyInterface describes the interface of a graph property.
The node struct represents a node in a Graph object.
Definition Node.h:40