19 #include <tulip/Graph.h> 20 #include <tulip/Coord.h> 22 template <
typename nodeType,
typename edgeType,
typename propType>
24 tlp::Graph *graph,
const std::string &name,
typename nodeType::RealType NodeMin,
25 typename nodeType::RealType NodeMax,
typename edgeType::RealType EdgeMin,
26 typename edgeType::RealType EdgeMax)
27 :
AbstractProperty<nodeType, edgeType, propType>(graph, name), _nodeMin(NodeMin),
28 _nodeMax(NodeMax), _edgeMin(EdgeMin), _edgeMax(EdgeMax), needGraphListener(false) {}
30 template <
typename nodeType,
typename edgeType,
typename propType>
31 typename nodeType::RealType
34 graph = this->propType::graph;
37 unsigned int graphID = graph->
getId();
38 auto it = minMaxNode.find(graphID);
40 if (it == minMaxNode.end())
41 return computeMinMaxNode(graph).first;
43 return it->second.first;
46 template <
typename nodeType,
typename edgeType,
typename propType>
47 typename nodeType::RealType
50 graph = this->propType::graph;
53 unsigned int graphID = graph->
getId();
54 auto it = minMaxNode.find(graphID);
56 if (it == minMaxNode.end())
57 return computeMinMaxNode(graph).second;
59 return it->second.second;
62 template <
typename nodeType,
typename edgeType,
typename propType>
63 typename edgeType::RealType
66 graph = this->propType::graph;
69 unsigned int graphID = graph->
getId();
70 auto it = minMaxEdge.find(graphID);
72 if (it == minMaxEdge.end())
73 return computeMinMaxEdge(graph).first;
75 return it->second.first;
78 template <
typename nodeType,
typename edgeType,
typename propType>
79 typename edgeType::RealType
82 graph = this->propType::graph;
85 unsigned int graphID = graph->
getId();
86 auto it = minMaxEdge.find(graphID);
88 if (it == minMaxEdge.end())
89 return computeMinMaxEdge(graph).second;
91 return it->second.second;
94 template <
typename nodeType,
typename edgeType,
typename propType>
98 graph = this->propType::graph;
101 typename nodeType::RealType maxN2 = _nodeMin, minN2 = _nodeMax;
104 for (
auto n : graph->
nodes()) {
105 typename nodeType::RealType tmp = this->
getNodeValue(n);
120 unsigned int sgi = graph->
getId();
125 if (minMaxNode.find(sgi) == minMaxNode.end() && minMaxEdge.find(sgi) == minMaxEdge.end()) {
130 MINMAX_PAIR(nodeType) minmax(minN2, maxN2);
131 return minMaxNode[sgi] = minmax;
134 template <
typename nodeType,
typename edgeType,
typename propType>
135 MINMAX_PAIR(edgeType)
137 typename edgeType::RealType maxE2 = _edgeMin, minE2 = _edgeMax;
140 for (
auto ite : graph->
edges()) {
141 typename edgeType::RealType tmp = this->
getEdgeValue(ite);
154 unsigned int sgi = graph->
getId();
159 if (minMaxNode.find(sgi) == minMaxNode.end() && minMaxEdge.find(sgi) == minMaxEdge.end()) {
164 MINMAX_PAIR(edgeType) minmax(minE2, maxE2);
165 return minMaxEdge[sgi] = minmax;
168 template <
typename nodeType,
typename edgeType,
typename propType>
179 auto it = minMaxNode.begin();
180 auto ite = minMaxNode.end();
182 for (; it != ite; ++it) {
183 unsigned int gi = it->first;
184 auto itg = minMaxEdge.find(gi);
186 if (itg == minMaxEdge.end()) {
189 Graph *g = (propType::graph->getId() == gi) ? (needGraphListener ?
nullptr : propType::graph)
201 template <
typename nodeType,
typename edgeType,
typename propType>
212 auto it = minMaxEdge.begin();
213 auto ite = minMaxEdge.end();
215 for (; it != ite; ++it) {
216 unsigned int gi = it->first;
217 auto itg = minMaxNode.find(gi);
219 if (itg == minMaxNode.end()) {
222 Graph *g = (propType::graph->getId() == gi) ? (needGraphListener ?
nullptr : propType::graph)
234 template <
typename nodeType,
typename edgeType,
typename propType>
236 tlp::node n,
typename nodeType::RealType newValue) {
237 auto it = minMaxNode.begin();
239 if (it != minMaxNode.end()) {
240 typename nodeType::RealType oldV = this->
getNodeValue(n);
242 if (newValue != oldV) {
244 for (; it != minMaxNode.end(); ++it) {
247 typename nodeType::RealType minV = it->second.first;
248 typename nodeType::RealType maxV = it->second.second;
251 if ((newValue < minV) || (newValue > maxV) || (oldV == minV) || (oldV == maxV)) {
252 removeListenersAndClearNodeMap();
260 template <
typename nodeType,
typename edgeType,
typename propType>
262 tlp::edge e,
typename edgeType::RealType newValue) {
263 auto it = minMaxEdge.begin();
265 if (it != minMaxEdge.end()) {
266 typename edgeType::RealType oldV = this->
getEdgeValue(e);
268 if (newValue != oldV) {
270 for (; it != minMaxEdge.end(); ++it) {
273 typename edgeType::RealType minV = it->second.first;
274 typename edgeType::RealType maxV = it->second.second;
277 if ((newValue < minV) || (newValue > maxV) || (oldV == minV) || (oldV == maxV)) {
278 removeListenersAndClearEdgeMap();
286 template <
typename nodeType,
typename edgeType,
typename propType>
288 typename nodeType::RealType newValue) {
289 auto it = minMaxNode.begin();
291 MINMAX_PAIR(nodeType) minmax(newValue, newValue);
293 for (; it != minMaxNode.end(); ++it) {
294 unsigned int gid = it->first;
295 minMaxNode[gid] = minmax;
299 template <
typename nodeType,
typename edgeType,
typename propType>
301 typename edgeType::RealType newValue) {
302 auto it = minMaxEdge.begin();
304 MINMAX_PAIR(edgeType) minmax(newValue, newValue);
306 for (; it != minMaxEdge.end(); ++it) {
307 unsigned int gid = it->first;
308 minMaxEdge[gid] = minmax;
312 template <
typename nodeType,
typename edgeType,
typename propType>
319 switch (graphEvent->getType()) {
320 case GraphEvent::TLP_ADD_NODE:
321 removeListenersAndClearNodeMap();
324 case GraphEvent::TLP_DEL_NODE: {
325 unsigned int sgi = graph->
getId();
326 auto it = minMaxNode.find(sgi);
328 if (it != minMaxNode.end()) {
329 typename nodeType::RealType oldV = this->
getNodeValue(graphEvent->getNode());
332 if ((oldV == it->second.first) || (oldV == it->second.second)) {
333 minMaxNode.erase(it);
335 if ((minMaxEdge.find(sgi) == minMaxEdge.end()) &&
336 (!needGraphListener || (graph != propType::graph)))
345 case GraphEvent::TLP_ADD_EDGE:
346 removeListenersAndClearEdgeMap();
349 case GraphEvent::TLP_DEL_EDGE: {
350 unsigned int sgi = graph->
getId();
351 auto it = minMaxEdge.find(sgi);
353 if (it != minMaxEdge.end()) {
354 typename edgeType::RealType oldV = this->
getEdgeValue(graphEvent->getEdge());
357 if ((oldV == it->second.first) || (oldV == it->second.second)) {
358 minMaxEdge.erase(it);
360 if ((minMaxNode.find(sgi) == minMaxNode.end()) &&
361 (!needGraphListener || (graph != propType::graph)))
This class extends upon PropertyInterface, and adds type-safe methods to get and set the node and edg...
Abstracts the computation of minimal and maximal values on node and edge values of properties...
void updateAllNodesValues(typename nodeType::RealType newValue)
Updates the value of all nodes, setting the maximum and minimum values to this. Should be called by s...
MinMaxProperty(tlp::Graph *graph, const std::string &name, typename nodeType::RealType NodeMin, typename nodeType::RealType NodeMax, typename edgeType::RealType EdgeMin, typename edgeType::RealType EdgeMax)
Constructs a MinMaxProperty.
virtual Graph * getDescendantGraph(unsigned int id) const =0
Returns a pointer on the descendant with the corresponding id or nullptr if there is no descendant wi...
edgeType::RealType getEdgeMax(const Graph *graph=nullptr)
Computes the maximum value on the edges. It is only computed if it has never been retrieved before...
virtual const std::vector< edge > & edges() const =0
Return a const reference on the vector of edges of the graph It is the fastest way to access to edges...
virtual const std::vector< node > & nodes() const =0
Return a const reference on the vector of nodes of the graph It is the fastest way to access to nodes...
nodeType::RealType getNodeMin(const Graph *graph=nullptr)
Gets the minimum value on the nodes. It is only computed if it has never been retrieved before...
void removeListener(Observable *const listener) const
Removes a listener from this object.
tlp::StoredType< typename nodeType ::RealType >::ReturnedConstValue getNodeValue(const node n) const
Returns the value associated with the node n in this property. If there is no value, it returns the default node value.
tlp::StoredType< typename edgeType ::RealType >::ReturnedConstValue getEdgeValue(const edge e) const
Returns the value associated to the edge e in this property. If there is no value, it returns the default edge value.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.
nodeType::RealType getNodeMax(const Graph *graph=nullptr)
Computes the maximum value on the nodes. It is only computed if it has never been retrieved before...
edgeType::RealType getEdgeMin(const Graph *graph=nullptr)
Computes the minimum value on the edges. It is only computed if it has never been retrieved before...
Event is the base class for all events used in the Observation mechanism.
unsigned int getId() const
Gets the unique identifier of the graph.
void updateAllEdgesValues(typename edgeType::RealType newValue)
Updates the value of all edges, setting the maximum and minimum values to this. Should be called by s...
void updateEdgeValue(tlp::edge e, typename edgeType::RealType newValue)
Updates the value on an edge, and updates the minimal/maximal cached values if necessary. Should be called by subclasses in order to keep the cache up to date.
void updateNodeValue(tlp::node n, typename nodeType::RealType newValue)
Updates the value on a node, and updates the minimal/maximal cached values if necessary. Should be called by subclasses in order to keep the cache up to date.
void addListener(Observable *const listener) const
Adds a Listener to this object.