gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Change the order of the Palette constructor parameters
0 2 0
default
2 files changed with 2 insertions and 2 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
1 1
/* -*- C++ -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library
4 4
 *
5 5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
/// \ingroup demos
20 20
/// \file
21 21
/// \brief Demo of the graph grawing function \ref graphToEps()
22 22
///
23 23
/// This demo program shows examples how to  use the function \ref
24 24
/// graphToEps(). It takes no input but simply creates  six
25 25
/// <tt>.eps</tt> files demonstrating the capability of \ref
26 26
/// graphToEps(), and showing how to draw directed/graphs,
27 27
/// how to handle parallel egdes, how to change the properties (like
28 28
/// color, shape, size, title etc.) of nodes and arcs individually
29 29
/// using appropriate \ref maps-page "graph maps".
30 30
///
31 31
/// \include graph_to_eps_demo.cc
32 32

	
33 33
#include <lemon/math.h>
34 34

	
35 35
#include<lemon/graph_to_eps.h>
36 36
#include<lemon/list_graph.h>
37 37
#include<lemon/graph_utils.h>
38 38

	
39 39
using namespace std;
40 40
using namespace lemon;
41 41

	
42 42
int main()
43 43
{
44 44
  Palette palette;
45
  Palette paletteW(-1,true);
45
  Palette paletteW(true);
46 46

	
47 47
  ListDigraph g;
48 48
  typedef ListDigraph::Node Node;
49 49
  typedef ListDigraph::NodeIt NodeIt;
50 50
  typedef ListDigraph::Arc Arc;
51 51
  typedef dim2::Point<int> Point;
52 52
  
53 53
  Node n1=g.addNode();
54 54
  Node n2=g.addNode();
55 55
  Node n3=g.addNode();
56 56
  Node n4=g.addNode();
57 57
  Node n5=g.addNode();
58 58

	
59 59
  ListDigraph::NodeMap<Point> coords(g);
60 60
  ListDigraph::NodeMap<double> sizes(g);
61 61
  ListDigraph::NodeMap<int> colors(g);
62 62
  ListDigraph::NodeMap<int> shapes(g);
63 63
  ListDigraph::ArcMap<int> ecolors(g);
64 64
  ListDigraph::ArcMap<int> widths(g);
65 65
  
66 66
  coords[n1]=Point(50,50);  sizes[n1]=1; colors[n1]=1; shapes[n1]=0;
67 67
  coords[n2]=Point(50,70);  sizes[n2]=2; colors[n2]=2; shapes[n2]=2;
68 68
  coords[n3]=Point(70,70);  sizes[n3]=1; colors[n3]=3; shapes[n3]=0;
69 69
  coords[n4]=Point(70,50);  sizes[n4]=2; colors[n4]=4; shapes[n4]=1;
70 70
  coords[n5]=Point(85,60);  sizes[n5]=3; colors[n5]=5; shapes[n5]=2;
71 71
  
72 72
  Arc e;
73 73

	
74 74
  e=g.addArc(n1,n2); ecolors[e]=0; widths[e]=1;
75 75
  e=g.addArc(n2,n3); ecolors[e]=0; widths[e]=1;
76 76
  e=g.addArc(n3,n5); ecolors[e]=0; widths[e]=3;
77 77
  e=g.addArc(n5,n4); ecolors[e]=0; widths[e]=1;
78 78
  e=g.addArc(n4,n1); ecolors[e]=0; widths[e]=1;
79 79
  e=g.addArc(n2,n4); ecolors[e]=1; widths[e]=2;
80 80
  e=g.addArc(n3,n4); ecolors[e]=2; widths[e]=1;
81 81
  
82 82
  IdMap<ListDigraph,Node> id(g);
83 83

	
84 84
  cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl;
85 85
  graphToEps(g,"graph_to_eps_demo_out_pure.eps").
86 86
    //scale(10).
87 87
    coords(coords).
88 88
    title("Sample .eps figure").
89 89
    copyright("(C) 2003-2007 LEMON Project").
90 90
    run();
91 91

	
92 92
  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
93 93
  graphToEps(g,"graph_to_eps_demo_out.eps").
94 94
    //scale(10).
95 95
    coords(coords).
96 96
    title("Sample .eps figure").
97 97
    copyright("(C) 2003-2007 LEMON Project").
98 98
    absoluteNodeSizes().absoluteArcWidths().
99 99
    nodeScale(2).nodeSizes(sizes).
100 100
    nodeShapes(shapes).
101 101
    nodeColors(composeMap(palette,colors)).
102 102
    arcColors(composeMap(palette,ecolors)).
103 103
    arcWidthScale(.4).arcWidths(widths).
104 104
    nodeTexts(id).nodeTextSize(3).
105 105
    run();
106 106

	
107 107

	
108 108
  cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
109 109
  graphToEps(g,"graph_to_eps_demo_out_arr.eps").
110 110
    //scale(10).
111 111
    title("Sample .eps figure (with arrowheads)").
112 112
    copyright("(C) 2003-2007 LEMON Project").
113 113
    absoluteNodeSizes().absoluteArcWidths().
114 114
    nodeColors(composeMap(palette,colors)).
115 115
    coords(coords).
116 116
    nodeScale(2).nodeSizes(sizes).
117 117
    nodeShapes(shapes).
118 118
    arcColors(composeMap(palette,ecolors)).
119 119
    arcWidthScale(.4).arcWidths(widths).
120 120
    nodeTexts(id).nodeTextSize(3).
121 121
    drawArrows().arrowWidth(1).arrowLength(1).
122 122
    run();
123 123

	
124 124
  e=g.addArc(n1,n4); ecolors[e]=2; widths[e]=1;
125 125
  e=g.addArc(n4,n1); ecolors[e]=1; widths[e]=2;
126 126

	
127 127
  e=g.addArc(n1,n2); ecolors[e]=1; widths[e]=1;
128 128
  e=g.addArc(n1,n2); ecolors[e]=2; widths[e]=1;
129 129
  e=g.addArc(n1,n2); ecolors[e]=3; widths[e]=1;
130 130
  e=g.addArc(n1,n2); ecolors[e]=4; widths[e]=1;
131 131
  e=g.addArc(n1,n2); ecolors[e]=5; widths[e]=1;
132 132
  e=g.addArc(n1,n2); ecolors[e]=6; widths[e]=1;
133 133
  e=g.addArc(n1,n2); ecolors[e]=7; widths[e]=1;
134 134

	
135 135
  cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
136 136
  graphToEps(g,"graph_to_eps_demo_out_par.eps").
137 137
    //scale(10).
138 138
    title("Sample .eps figure (parallel arcs)").
139 139
    copyright("(C) 2003-2007 LEMON Project").
140 140
    absoluteNodeSizes().absoluteArcWidths().
141 141
    nodeShapes(shapes).
Ignore white space 192 line context
... ...
@@ -26,182 +26,182 @@
26 26

	
27 27
///\ingroup misc
28 28
///\file
29 29
///\brief Tools to manage RGB colors.
30 30
///
31 31
///\author Alpar Juttner
32 32

	
33 33
namespace lemon {
34 34

	
35 35

	
36 36
  /// \addtogroup misc
37 37
  /// @{
38 38

	
39 39
  ///Data structure representing RGB colors.
40 40

	
41 41
  ///Data structure representing RGB colors.
42 42
  class Color
43 43
  {
44 44
    double _r,_g,_b;
45 45
  public:
46 46
    ///Default constructor
47 47
    Color() {}
48 48
    ///Constructor
49 49
    Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
50 50
    ///Set the red component
51 51
    double & red() {return _r;}
52 52
    ///Return the red component
53 53
    const double & red() const {return _r;}
54 54
    ///Set the green component
55 55
    double & green() {return _g;}
56 56
    ///Return the green component
57 57
    const double & green() const {return _g;}
58 58
    ///Set the blue component
59 59
    double & blue() {return _b;}
60 60
    ///Return the blue component
61 61
    const double & blue() const {return _b;}
62 62
    ///Set the color components
63 63
    void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
64 64
  };
65 65

	
66 66
  /// White color constant
67 67
  extern const Color WHITE;  
68 68
  /// Black color constant
69 69
  extern const Color BLACK;
70 70
  /// Red color constant
71 71
  extern const Color RED;
72 72
  /// Green color constant
73 73
  extern const Color GREEN;
74 74
  /// Blue color constant
75 75
  extern const Color BLUE;
76 76
  /// Yellow color constant
77 77
  extern const Color YELLOW;
78 78
  /// Magenta color constant
79 79
  extern const Color MAGENTA;
80 80
  /// Cyan color constant
81 81
  extern const Color CYAN;
82 82
  /// Grey color constant
83 83
  extern const Color GREY;
84 84
  /// Dark red color constant
85 85
  extern const Color DARK_RED;
86 86
  /// Dark green color constant
87 87
  extern const Color DARK_GREEN;
88 88
  /// Drak blue color constant
89 89
  extern const Color DARK_BLUE;
90 90
  /// Dark yellow color constant
91 91
  extern const Color DARK_YELLOW;
92 92
  /// Dark magenta color constant
93 93
  extern const Color DARK_MAGENTA;
94 94
  /// Dark cyan color constant
95 95
  extern const Color DARK_CYAN;
96 96

	
97 97
  ///Map <tt>int</tt>s to different \ref Color "Color"s
98 98

	
99 99
  ///This map assigns one of the predefined \ref Color "Color"s to
100 100
  ///each <tt>int</tt>. It is possible to change the colors as well as
101 101
  ///their number. The integer range is cyclically mapped to the
102 102
  ///provided set of colors.
103 103
  ///
104 104
  ///This is a true \ref concepts::ReferenceMap "reference map", so
105 105
  ///you can also change the actual colors.
106 106

	
107 107
  class Palette : public MapBase<int,Color>
108 108
  {
109 109
    std::vector<Color> colors;
110 110
  public:
111 111
    ///Constructor
112 112

	
113 113
    ///Constructor 
114 114
    ///\param num the number of the allocated colors. If it is \c -1,
115 115
    ///the default color configuration is set up (26 color plus the
116 116
    ///white).  If \c num is less then 26/27 then the default color
117 117
    ///list is cut. Otherwise the color list is filled repeatedly with
118 118
    ///the default color list.  (The colors can be changed later on.)
119 119
    ///\param have_white indicates whether white is amongst the
120 120
    ///provided color (\c true) or not (\c false). If it is true,
121 121
    ///white will be assigned to \c 0.
122
    Palette(int num=-1,bool have_white=false)
122
    Palette(bool have_white=false,int num=-1)
123 123
    {
124 124
      if (num==0) return;
125 125
      do {
126 126
        if(have_white) colors.push_back(Color(1,1,1));
127 127

	
128 128
        colors.push_back(Color(0,0,0));
129 129
        colors.push_back(Color(1,0,0));
130 130
        colors.push_back(Color(0,1,0));
131 131
        colors.push_back(Color(0,0,1));
132 132
        colors.push_back(Color(1,1,0));
133 133
        colors.push_back(Color(1,0,1));
134 134
        colors.push_back(Color(0,1,1));
135 135
      
136 136
        colors.push_back(Color(.5,0,0));
137 137
        colors.push_back(Color(0,.5,0));
138 138
        colors.push_back(Color(0,0,.5));
139 139
        colors.push_back(Color(.5,.5,0));
140 140
        colors.push_back(Color(.5,0,.5));
141 141
        colors.push_back(Color(0,.5,.5));
142 142
      
143 143
        colors.push_back(Color(.5,.5,.5));
144 144
        colors.push_back(Color(1,.5,.5));
145 145
        colors.push_back(Color(.5,1,.5));
146 146
        colors.push_back(Color(.5,.5,1));
147 147
        colors.push_back(Color(1,1,.5));
148 148
        colors.push_back(Color(1,.5,1));
149 149
        colors.push_back(Color(.5,1,1));
150 150
      
151 151
        colors.push_back(Color(1,.5,0));
152 152
        colors.push_back(Color(.5,1,0));
153 153
        colors.push_back(Color(1,0,.5));
154 154
        colors.push_back(Color(0,1,.5));
155 155
        colors.push_back(Color(0,.5,1));
156 156
        colors.push_back(Color(.5,0,1));
157 157
      } while(int(colors.size())<num);
158 158
      //    colors.push_back(Color(1,1,1));
159 159
      if(num>=0) colors.resize(num);
160 160
    }
161 161
    ///\e
162 162
    Color &operator[](int i)
163 163
    {
164 164
      return colors[i%colors.size()];
165 165
    }
166 166
    ///\e
167 167
    const Color &operator[](int i) const
168 168
    {
169 169
      return colors[i%colors.size()];
170 170
    }
171 171
    ///\e
172 172
    void set(int i,const Color &c)
173 173
    {
174 174
      colors[i%colors.size()]=c;
175 175
    }
176 176
    ///\e
177 177
    void add(const Color &c) 
178 178
    {
179 179
      colors.push_back(c);
180 180
    }
181 181

	
182 182
    ///Sets the number of the exiting colors.
183 183
    void resize(int s) { colors.resize(s);}
184 184
    ///Returns the number of the existing colors.
185 185
    int size() const { return int(colors.size());}
186 186
  };
187 187

	
188 188
  ///Returns a visible distinct \ref Color
189 189

	
190 190
  ///Returns a \ref Color which is as different from the given parameter
191 191
  ///as it is possible.
192 192
  inline Color distantColor(const Color &c) 
193 193
  {
194 194
    return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
195 195
  }
196 196
  ///Returns black for light colors and white for the dark ones.
197 197

	
198 198
  ///Returns black for light colors and white for the dark ones.
199 199
  inline Color distantBW(const Color &c){
200 200
    return (.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5 ? WHITE : BLACK;
201 201
  }
202 202

	
203 203
  /// @}
204 204

	
205 205
} //END OF NAMESPACE LEMON
206 206

	
207 207
#endif // LEMON_COLOR_H
0 comments (0 inline)