19 #include <tulip/Graph.h> 20 #include <tulip/Coord.h> 22 template<
typename nodeType,
typename edgeType,
typename propType>
24 typename nodeType::RealType NodeMax,
typename edgeType::RealType EdgeMin,
typename edgeType::RealType EdgeMax)
25 :
AbstractProperty<nodeType, edgeType, propType>(graph, name), _nodeMin(NodeMin), _nodeMax(NodeMax), _edgeMin(EdgeMin), _edgeMax(EdgeMax), needGraphListener(false) {
28 template<
typename nodeType,
typename edgeType,
typename propType>
31 graph = this->propType::graph;
34 unsigned int graphID = graph->
getId();
35 MINMAX_MAP(nodeType)::const_iterator it = minMaxNode.find(graphID);
37 if (it == minMaxNode.end())
38 return computeMinMaxNode(graph).first;
40 return it->second.first;
43 template<
typename nodeType,
typename edgeType,
typename propType>
46 graph = this->propType::graph;
49 unsigned int graphID = graph->
getId();
50 MINMAX_MAP(nodeType)::const_iterator it = minMaxNode.find(graphID);
52 if (it == minMaxNode.end())
53 return computeMinMaxNode(graph).second;
55 return it->second.second;
58 template<
typename nodeType,
typename edgeType,
typename propType>
61 graph = this->propType::graph;
64 unsigned int graphID = graph->
getId();
65 MINMAX_MAP(edgeType)::const_iterator it = minMaxEdge.find(graphID);
67 if (it == minMaxEdge.end())
68 return computeMinMaxEdge(graph).first;
70 return it->second.first;
73 template<
typename nodeType,
typename edgeType,
typename propType>
76 graph = this->propType::graph;
79 unsigned int graphID = graph->
getId();
80 MINMAX_MAP(edgeType)::const_iterator it = minMaxEdge.find(graphID);
82 if (it == minMaxEdge.end())
83 return computeMinMaxEdge(graph).second;
85 return it->second.second;
88 template<
typename nodeType,
typename edgeType,
typename propType>
91 graph = this->propType::graph;
94 typename nodeType::RealType maxN2 = _nodeMin, minN2 = _nodeMax;
99 Iterator<node>* nodeIterator = graph->
getNodes();
101 while (nodeIterator->hasNext()) {
102 node n=nodeIterator->next();
103 typename nodeType::RealType tmp = this->
getNodeValue(n);
121 unsigned int sgi = graph->
getId();
126 if (minMaxNode.find(sgi) == minMaxNode.end() &&
127 minMaxEdge.find(sgi) == minMaxEdge.end()) {
132 MINMAX_PAIR(nodeType) minmax(minN2, maxN2);
133 return minMaxNode[sgi] = minmax;
136 template<
typename nodeType,
typename edgeType,
typename propType>
138 typename edgeType::RealType maxE2 = _edgeMin, minE2 = _edgeMax;
143 Iterator<edge>* edgeIterator = graph->
getEdges();
145 while (edgeIterator->hasNext()) {
146 edge ite=edgeIterator->next();
147 typename edgeType::RealType tmp = this->
getEdgeValue(ite);
163 unsigned int sgi = graph->
getId();
168 if (minMaxNode.find(sgi) == minMaxNode.end() &&
169 minMaxEdge.find(sgi) == minMaxEdge.end()) {
174 MINMAX_PAIR(edgeType) minmax(minE2, maxE2);
175 return minMaxEdge[sgi] = minmax;
178 template<
typename nodeType,
typename edgeType,
typename propType>
189 MINMAX_MAP(nodeType)::const_iterator it = minMaxNode.begin();
190 MINMAX_MAP(nodeType)::const_iterator ite = minMaxNode.end();
192 for(; it != ite; ++it) {
193 unsigned int gi = it->first;
194 MINMAX_MAP(edgeType)::const_iterator itg = minMaxEdge.find(gi);
196 if (itg == minMaxEdge.end()) {
200 (propType::graph->getId() == gi) ?
201 (needGraphListener ? NULL : propType::graph) :
213 template<
typename nodeType,
typename edgeType,
typename propType>
224 MINMAX_MAP(edgeType)::const_iterator it = minMaxEdge.begin();
225 MINMAX_MAP(edgeType)::const_iterator ite = minMaxEdge.end();
227 for(; it != ite; ++it) {
228 unsigned int gi = it->first;
229 MINMAX_MAP(nodeType)::const_iterator itg = minMaxNode.find(gi);
231 if (itg == minMaxNode.end()) {
235 (propType::graph->getId() == gi) ?
236 (needGraphListener ? NULL : propType::graph) :
248 template<
typename nodeType,
typename edgeType,
typename propType>
250 MINMAX_MAP(nodeType)::const_iterator it = minMaxNode.begin();
252 if (it != minMaxNode.end()) {
253 typename nodeType::RealType oldV = this->
getNodeValue(n);
255 if (newValue != oldV) {
257 for(; it != minMaxNode.end(); ++it) {
260 typename nodeType::RealType minV = it->second.first;
261 typename nodeType::RealType maxV = it->second.second;
264 if ((newValue < minV) || (newValue > maxV) || (oldV == minV) || (oldV == maxV)) {
265 removeListenersAndClearNodeMap();
273 template<
typename nodeType,
typename edgeType,
typename propType>
275 MINMAX_MAP(edgeType)::const_iterator it = minMaxEdge.begin();
277 if (it != minMaxEdge.end()) {
278 typename edgeType::RealType oldV = this->
getEdgeValue(e);
280 if (newValue != oldV) {
282 for(; it != minMaxEdge.end(); ++it) {
285 typename edgeType::RealType minV = it->second.first;
286 typename edgeType::RealType maxV = it->second.second;
289 if ((newValue < minV) || (newValue > maxV) || (oldV == minV) || (oldV == maxV)) {
290 removeListenersAndClearEdgeMap();
298 template<
typename nodeType,
typename edgeType,
typename propType>
300 MINMAX_MAP(nodeType)::const_iterator it = minMaxNode.begin();
302 MINMAX_PAIR(nodeType) minmax(newValue, newValue);
304 for(; it != minMaxNode.end(); ++it) {
305 unsigned int gid = it->first;
306 minMaxNode[gid] = minmax;
310 template<
typename nodeType,
typename edgeType,
typename propType>
312 MINMAX_MAP(edgeType)::const_iterator it = minMaxEdge.begin();
314 MINMAX_PAIR(edgeType) minmax(newValue, newValue);
316 for(; it != minMaxEdge.end(); ++it) {
317 unsigned int gid = it->first;
318 minMaxEdge[gid] = minmax;
322 template<
typename nodeType,
typename edgeType,
typename propType>
329 switch(graphEvent->getType()) {
330 case GraphEvent::TLP_ADD_NODE:
331 removeListenersAndClearNodeMap();
334 case GraphEvent::TLP_DEL_NODE: {
335 unsigned int sgi = graph->
getId();
336 MINMAX_MAP(nodeType)::iterator it = minMaxNode.find(sgi);
338 if (it != minMaxNode.end()) {
339 typename nodeType::RealType oldV =
343 if ((oldV == it->second.first) || (oldV == it->second.second)) {
344 minMaxNode.erase(it);
346 if ((minMaxEdge.find(sgi) == minMaxEdge.end()) &&
347 (!needGraphListener || (graph != propType::graph)))
356 case GraphEvent::TLP_ADD_EDGE:
357 removeListenersAndClearEdgeMap();
360 case GraphEvent::TLP_DEL_EDGE: {
361 unsigned int sgi = graph->
getId();
362 MINMAX_MAP(edgeType)::iterator it = minMaxEdge.find(sgi);
364 if (it != minMaxEdge.end()) {
365 typename edgeType::RealType oldV =
369 if ((oldV == it->second.first) || (oldV == it->second.second)) {
370 minMaxEdge.erase(it);
372 if ((minMaxNode.find(sgi) == minMaxNode.end()) &&
373 (!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...
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.
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 Iterator< edge > * getEdges() const =0
Get an iterator over all the graph's edges.
virtual Graph * getDescendantGraph(unsigned int id) const =0
Returns a pointer on the descendant with the corresponding id or NULL if there is no descendant with ...
nodeType::RealType getNodeMin(const Graph *graph=NULL)
Gets the minimum value on the nodes. It is only computed if it has never been retrieved before...
nodeType::RealType getNodeMax(const Graph *graph=NULL)
Computes the maximum value on the nodes. It is only computed if it has never been retrieved before...
void addListener(Observable *const listener) const
Adds a Listener to this object.
The edge struct represents an edge in a Graph object.
The node struct represents a node in a Graph object.
virtual Iterator< node > * getNodes() const =0
Gets an iterator over this graph's nodes.
Event is the base class for all events used in the Observation mechanism.
void removeListener(Observable *const listener) const
Removes a listener from this object.
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.
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.
unsigned int getId() const
Gets the unique identifier of the graph.
edgeType::RealType getEdgeMin(const Graph *graph=NULL)
Computes the minimum value on the edges. It is only computed if it has never been retrieved before...
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.
edgeType::RealType getEdgeMax(const Graph *graph=NULL)
Computes the maximum value on the edges. It is only computed if it has never been retrieved before...