COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-edge.cc @ 178:a96d2a540454

Last change on this file since 178:a96d2a540454 was 178:a96d2a540454, checked in by Hegyi Péter, 17 years ago

If visualization is not autoscaled, edges with widths associated with negative map values will be hidden.

  • Property exe set to *
File size: 5.8 KB
RevLine 
[174]1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
[53]19#include "graph_displayer_canvas.h"
[59]20#include <cmath>
[27]21
[167]22const int minimum_edge_width=0;
[27]23
[81]24int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
25{
26  double min, max;
27
28  min=edge_property_defaults[E_WIDTH];
29  max=edge_property_defaults[E_WIDTH];
[96]30  Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_WIDTH]);
[81]31 
32  if(edge==INVALID)
33    {
[96]34      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[81]35        {
[91]36          double v=fabs(actual_map[i]);
[81]37          int w;
38          if(min==max)
39            {
40              w=(int)(edge_property_defaults[E_WIDTH]);
41            }
42          else
43            {
44              w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
45            }
[157]46          if(zoomtrack)
47            {
48              double actual_ppu=get_pixels_per_unit();
49              w=(int)(w/actual_ppu*fixed_zoom_factor);
50            }
[147]51          edgesmap[i]->setLineWidth(w);
[81]52        }
53    }
54  else
55    {
[91]56      int w=(int)actual_map[edge];
[81]57      if(w>=0)
58        {
[147]59          edgesmap[edge]->setLineWidth(w);
[81]60        }
61    }
62  return 0;
63}
64
65
[62]66int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
[27]67{
[31]68  Graph::EdgeMap<double> * actual_map;
[48]69  double min, max;
70
[96]71  min=(mytab.mapstorage).minOfEdgeMap(mapname);
72  max=(mytab.mapstorage).maxOfEdgeMap(mapname);
73  actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
[31]74
[28]75  if(edge==INVALID)
[27]76    {
[96]77      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[28]78        {
[178]79          double v=(*actual_map)[i];
[48]80          int w;
[157]81          if(autoscale)
[28]82            {
[157]83              if(min==max)
84                {
85                  w=(int)(edge_property_defaults[E_WIDTH]);
86                }
87              else
88                {
89                  w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width));
90                }
[28]91            }
[48]92          else
93            {
[157]94              w=(int)(v*edge_width);
95            }
[178]96          if(w<0)
[157]97            {
[178]98              edgesmap[i]->hide();
[157]99            }
[178]100          else
[157]101            {
[178]102              edgesmap[i]->show();
103              if(w<minimum_edge_width)
104                {
105                  w=minimum_edge_width;
106                }
107              if(zoomtrack)
108                {
109                  double actual_ppu=get_pixels_per_unit();
110                  w=(int)(w/actual_ppu*fixed_zoom_factor);
111                }
112              edgesmap[i]->setLineWidth(w);
[48]113            }
[28]114        }
115    }
116  else
117    {
[31]118      int w=(int)(*actual_map)[edge];
[27]119      if(w>=0)
120        {
[147]121          edgesmap[edge]->setLineWidth(w);
[27]122        }
123    }
124  return 0;
125};
126
[62]127int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
[27]128
129
130  //function maps the range of the maximum and
131  //the minimum of the nodemap to the range of
132  //green in RGB
[31]133  Graph::EdgeMap<double> * actual_map;
[96]134  actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
[81]135
136  double max, min;
137
[96]138  max=(mytab.mapstorage).maxOfEdgeMap(mapname);
139  min=(mytab.mapstorage).minOfEdgeMap(mapname);
[81]140
141  if(edge==INVALID)
[31]142    {
[96]143      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[81]144        {
145          double w=(*actual_map)[i];
146
147          Gdk::Color color;
148          if(max!=min)
149            {
150              color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
151            }
152          else
153            {
154              color.set_rgb_p (0, 100, 0);
155            }
[147]156          edgesmap[i]->setFillColor(color);
[81]157        }
[31]158    }
159  else
160    {
[81]161      Gdk::Color color;
162
163      double w=(*actual_map)[edge];
164
165      if(max!=min)
166        {
167          color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
168        }
169      else
170        {
171          color.set_rgb_p (0, 100, 0);
172        }
173
[147]174      edgesmap[edge]->setFillColor(color);
[31]175    }
[81]176  return 0;
177};
178
179int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
180
181
182  //function maps the range of the maximum and
183  //the minimum of the nodemap to the range of
184  //green in RGB
[96]185  Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_COLOR]);
[31]186
187  double max, min;
188
[81]189  max=edge_property_defaults[E_COLOR];
190  min=edge_property_defaults[E_COLOR];
[31]191
[28]192  if(edge==INVALID)
193    {
[96]194      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[28]195        {
[91]196          double w=actual_map[i];
[31]197
[28]198          Gdk::Color color;
199          if(max!=min)
200            {
201              color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
202            }
203          else
204            {
205              color.set_rgb_p (0, 100, 0);
206            }
[147]207          edgesmap[i]->setFillColor(color);
[28]208        }
209    }
210  else
[27]211    {
[28]212      Gdk::Color color;
[31]213
[91]214      double w=actual_map[edge];
[31]215
[28]216      if(max!=min)
217        {
218          color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
219        }
220      else
221        {
222          color.set_rgb_p (0, 100, 0);
223        }
224
[147]225      edgesmap[edge]->setFillColor(color);
[27]226    }
227  return 0;
228};
229
[62]230int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
[27]231{
232  //the number in the map will be written on the edge
[40]233  //EXCEPT when the name of the map is Default, because
[27]234  //in that case empty string will be written, because
235  //that is the deleter map
[63]236 
[28]237  if(edge==INVALID)
[27]238    {
[96]239      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[27]240        {
[81]241          edgemap_to_edit=mapname;
[96]242          double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[i];
[81]243         
244          std::ostringstream ostr;
245          ostr << number;
246         
247          edgetextmap[i]->property_text().set_value(ostr.str());
[28]248        }
249
250    }
251  else
252    {
[96]253          double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[edge];
[45]254
255          std::ostringstream ostr;
256          ostr << number;
257         
258          edgetextmap[edge]->property_text().set_value(ostr.str());
[27]259    }
[28]260
[27]261  return 0;
[28]262
[27]263};
[81]264
265int GraphDisplayerCanvas::resetEdgeText (Edge edge)
266{
267  //the number in the map will be written on the edge
268  //EXCEPT when the name of the map is Default, because
269  //in that case empty string will be written, because
270  //that is the deleter map
271 
272  if(edge==INVALID)
273    {
[96]274      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[81]275        {
276          edgemap_to_edit="";
277          edgetextmap[i]->property_text().set_value("");
278        }
279
280    }
281  else
282    {
283      edgetextmap[edge]->property_text().set_value("");
284    }
285
286  return 0;
287
288};
Note: See TracBrowser for help on using the repository browser.