alpar@1971
|
1 |
/* -*- C++ -*-
|
alpar@1971
|
2 |
*
|
alpar@1971
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@1971
|
4 |
*
|
alpar@1971
|
5 |
* Copyright (C) 2003-2006
|
alpar@1971
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@1971
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@1971
|
8 |
*
|
alpar@1971
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@1971
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@1971
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@1971
|
12 |
*
|
alpar@1971
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@1971
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@1971
|
15 |
* purpose.
|
alpar@1971
|
16 |
*
|
alpar@1971
|
17 |
*/
|
alpar@1971
|
18 |
|
alpar@1971
|
19 |
#ifndef LEMON_EPS_H
|
alpar@1971
|
20 |
#define LEMON_EPS_H
|
alpar@1971
|
21 |
|
alpar@1971
|
22 |
#include<string>
|
alpar@1971
|
23 |
#include<iostream>
|
alpar@1971
|
24 |
#include<fstream>
|
alpar@1971
|
25 |
#include<sstream>
|
alpar@1971
|
26 |
#include<lemon/color.h>
|
alpar@1971
|
27 |
#include<lemon/xy.h>
|
alpar@1971
|
28 |
|
alpar@1971
|
29 |
///\ingroup io_group
|
alpar@1971
|
30 |
///\file
|
alpar@1971
|
31 |
///\brief Simple tool to create \c .eps files
|
alpar@1971
|
32 |
///
|
alpar@1971
|
33 |
///\author Alpar Juttner
|
alpar@1971
|
34 |
|
alpar@1971
|
35 |
namespace lemon {
|
alpar@1971
|
36 |
|
alpar@1971
|
37 |
///\ingroup io_group
|
alpar@1971
|
38 |
///\brief A simple tool to create \c .eps files
|
alpar@1971
|
39 |
///
|
alpar@1971
|
40 |
///A simple tool to create \c .eps files
|
alpar@1971
|
41 |
///\author Alpar Juttner
|
alpar@1971
|
42 |
class EpsDrawer
|
alpar@1971
|
43 |
{
|
alpar@1971
|
44 |
void defMacros();
|
alpar@1971
|
45 |
void init(int x1,int y1,int x2,int y2);
|
alpar@1971
|
46 |
void init(double x1,double y1,double x2,double y2);
|
alpar@1971
|
47 |
bool local_stream;
|
alpar@1971
|
48 |
public:
|
alpar@1971
|
49 |
|
alpar@1971
|
50 |
std::ostream &out;
|
alpar@1971
|
51 |
|
alpar@1971
|
52 |
///\e
|
alpar@1971
|
53 |
|
alpar@1971
|
54 |
///The generated file is put to \c os.
|
alpar@1971
|
55 |
///
|
alpar@1971
|
56 |
/// \c x and \c y determine the upper
|
alpar@1971
|
57 |
///right corner of the bounding box. The lower left corner is (0,0).
|
alpar@1971
|
58 |
EpsDrawer(std::ostream &os,int x,int y);
|
alpar@1971
|
59 |
///\e
|
alpar@1971
|
60 |
|
alpar@1971
|
61 |
///The generated file is put to \c os.
|
alpar@1971
|
62 |
///
|
alpar@1971
|
63 |
///(x1,y1) and (x2,y2)
|
alpar@1971
|
64 |
/// determine the lower left and the upper right corners of
|
alpar@1971
|
65 |
///the bounding box, respectively.
|
alpar@1971
|
66 |
EpsDrawer(std::ostream &os,int x1,int y1,int x2,int y2);
|
alpar@1971
|
67 |
///\e
|
alpar@1971
|
68 |
|
alpar@1971
|
69 |
///The generated file is put to \c os.
|
alpar@1971
|
70 |
///
|
alpar@1971
|
71 |
///\c s determines the upper
|
alpar@1971
|
72 |
///right corner of the bounding box. The lower left corner is (0,0).
|
alpar@1971
|
73 |
EpsDrawer(std::ostream &os,xy<double> s);
|
alpar@1971
|
74 |
///\e
|
alpar@1971
|
75 |
|
alpar@1971
|
76 |
///The generated file is put to \c os.
|
alpar@1971
|
77 |
///
|
alpar@1971
|
78 |
///\c a and \c b
|
alpar@1971
|
79 |
/// determine the lower left and the upper right corners of
|
alpar@1971
|
80 |
///the bounding box, respectively.
|
alpar@1971
|
81 |
EpsDrawer(std::ostream &os,xy<double> a, xy<double> b);
|
alpar@1971
|
82 |
///\e
|
alpar@1971
|
83 |
|
alpar@1971
|
84 |
///The generated picture is put to the file \c name.
|
alpar@1971
|
85 |
///
|
alpar@1971
|
86 |
///\c x and \c y determine the upper
|
alpar@1971
|
87 |
///right corner of the bounding box. The lower left corner is (0,0).
|
alpar@1971
|
88 |
EpsDrawer(const std::string &name,int x,int y);
|
alpar@1971
|
89 |
///\e
|
alpar@1971
|
90 |
|
alpar@1971
|
91 |
///The generated picture is put to the file \c name.
|
alpar@1971
|
92 |
///
|
alpar@1971
|
93 |
///(x1,y1) and (x2,y2)
|
alpar@1971
|
94 |
/// determine the lower left and the upper right corners of
|
alpar@1971
|
95 |
///the bounding box, respectively.
|
alpar@1971
|
96 |
EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2);
|
alpar@1971
|
97 |
///\e
|
alpar@1971
|
98 |
|
alpar@1971
|
99 |
///The generated picture is put to the file \c name.
|
alpar@1971
|
100 |
///
|
alpar@1971
|
101 |
///\c s determines the upper
|
alpar@1971
|
102 |
///right corner of the bounding box. The lower left corner is (0,0).
|
alpar@1971
|
103 |
EpsDrawer(const std::string &name,xy<double> s);
|
alpar@1971
|
104 |
///\e
|
alpar@1971
|
105 |
|
alpar@1971
|
106 |
///The generated picture is put to the file \c name.
|
alpar@1971
|
107 |
///
|
alpar@1971
|
108 |
///\c a and \c b
|
alpar@1971
|
109 |
/// determine the lower left and the upper right corners of
|
alpar@1971
|
110 |
///the bounding box, respectively.
|
alpar@1971
|
111 |
EpsDrawer(const std::string &name,xy<double> a, xy<double> b);
|
alpar@1971
|
112 |
|
alpar@1971
|
113 |
// template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b)
|
alpar@1971
|
114 |
// template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b);
|
alpar@1971
|
115 |
|
alpar@1971
|
116 |
~EpsDrawer();
|
alpar@1971
|
117 |
|
alpar@1971
|
118 |
///Save the current graphic state.
|
alpar@1971
|
119 |
|
alpar@1971
|
120 |
///This function saves the current coordinate system, and the parameters
|
alpar@1971
|
121 |
///set by \ref color(), \ref lineWidth() etc.
|
alpar@1971
|
122 |
///The can be \ref restore "restore()"d later.
|
alpar@1971
|
123 |
///
|
alpar@1971
|
124 |
///The \ref save() - \ref restore() pairs can be nested.
|
alpar@1971
|
125 |
///
|
alpar@1971
|
126 |
EpsDrawer &save();
|
alpar@1971
|
127 |
///Restore the saves graphic state.
|
alpar@1971
|
128 |
|
alpar@1971
|
129 |
EpsDrawer &restore();
|
alpar@1971
|
130 |
|
alpar@1971
|
131 |
///Draw a line
|
alpar@1971
|
132 |
EpsDrawer &line(double x1,double y1,double x2,double y2);
|
alpar@1971
|
133 |
///Draw a line from the current point
|
alpar@1971
|
134 |
EpsDrawer &lineTo(double x1,double y1);
|
alpar@1971
|
135 |
///Move the current point
|
alpar@1971
|
136 |
EpsDrawer &moveTo(double x1,double y1);
|
alpar@1971
|
137 |
///Draw a circle
|
alpar@1971
|
138 |
EpsDrawer &circle(double x,double y, double r);
|
alpar@1971
|
139 |
|
alpar@1971
|
140 |
///Draw a line
|
alpar@1971
|
141 |
template<class T> EpsDrawer &line(xy<T> p1,xy<T> p2)
|
alpar@1971
|
142 |
{
|
alpar@1971
|
143 |
return line(p1.x,p1.y,p2.x,p2.y);
|
alpar@1971
|
144 |
}
|
alpar@1971
|
145 |
///Draw a line from the current point
|
alpar@1971
|
146 |
template<class T> EpsDrawer &lineTo(xy<T> p)
|
alpar@1971
|
147 |
{
|
alpar@1971
|
148 |
return lineTo(p.x,p.y);
|
alpar@1971
|
149 |
}
|
alpar@1971
|
150 |
///Move the current point
|
alpar@1971
|
151 |
template<class T> EpsDrawer &moveTo(xy<T> p)
|
alpar@1971
|
152 |
{
|
alpar@1971
|
153 |
return moveTo(p.x,p.y);
|
alpar@1971
|
154 |
}
|
alpar@1971
|
155 |
///Draw a circle
|
alpar@1971
|
156 |
template<class T> EpsDrawer &circle(xy<T> p, double r)
|
alpar@1971
|
157 |
{
|
alpar@1971
|
158 |
return circle(p.x,p.y,r);
|
alpar@1971
|
159 |
}
|
alpar@1971
|
160 |
|
alpar@1971
|
161 |
///Set the font size
|
alpar@1971
|
162 |
EpsDrawer &fontSize(double si);
|
alpar@1971
|
163 |
///Set the fint type
|
alpar@1971
|
164 |
EpsDrawer &font(std::string );
|
alpar@1971
|
165 |
///Sets whether text output is centerized of not
|
alpar@1971
|
166 |
|
alpar@1971
|
167 |
///Sets whether text output is centerized of not.
|
alpar@1971
|
168 |
///
|
alpar@1971
|
169 |
///\warning \ref save() doesn't save this setting.
|
alpar@1971
|
170 |
///
|
alpar@1971
|
171 |
EpsDrawer ¢erMode(bool m);
|
alpar@1971
|
172 |
///Turn to collect mode.
|
alpar@1971
|
173 |
|
alpar@1971
|
174 |
///If you call this function, then the drawing operations like \ref line(),
|
alpar@1971
|
175 |
///\ref lineTo(), \ref moveTo() will not take place immediately, but istead
|
alpar@1971
|
176 |
///they
|
alpar@1971
|
177 |
///are collected. These operations form a \e path.
|
alpar@1971
|
178 |
///Then you can \ref stroke(), \ref fill(), \ref eofill(), \ref clip() or
|
alpar@1971
|
179 |
///\ref eoclip() it.
|
alpar@1971
|
180 |
///When drawing, you can also use \ref closePath() to - surprise - close the
|
alpar@1971
|
181 |
///current path.
|
alpar@1971
|
182 |
///
|
alpar@1971
|
183 |
///This example draws a red filled diamond.
|
alpar@1971
|
184 |
///\code
|
alpar@1971
|
185 |
/// EpsDraw ed("diamond.eps",-1,-1,1,1);
|
alpar@1971
|
186 |
/// ed.color(1,0,0,).collect().line(0,-1,1,0).lineTo(0,1)
|
alpar@1971
|
187 |
/// .lineTo(-1,0).closePath().fill();
|
alpar@1971
|
188 |
///\endcode
|
alpar@1971
|
189 |
EpsDrawer &collect();
|
alpar@1971
|
190 |
///Close the current drawing path
|
alpar@1971
|
191 |
EpsDrawer &closePath();
|
alpar@1971
|
192 |
///Stroke (draw) a path
|
alpar@1971
|
193 |
|
alpar@1971
|
194 |
///Stroke (draw) a path.
|
alpar@1971
|
195 |
///\sa collect
|
alpar@1971
|
196 |
///
|
alpar@1971
|
197 |
EpsDrawer &stroke();
|
alpar@1971
|
198 |
///Fill a path
|
alpar@1971
|
199 |
|
alpar@1971
|
200 |
///Fill a path.
|
alpar@1971
|
201 |
///\sa collect
|
alpar@1971
|
202 |
///
|
alpar@1971
|
203 |
EpsDrawer &fill();
|
alpar@1971
|
204 |
///Even-odd fill a path
|
alpar@1971
|
205 |
|
alpar@1971
|
206 |
///Even-odd fill a path.
|
alpar@1971
|
207 |
///\sa collect
|
alpar@1971
|
208 |
///
|
alpar@1971
|
209 |
EpsDrawer &eoFill();
|
alpar@1971
|
210 |
///Set a clipping area.
|
alpar@1971
|
211 |
|
alpar@1971
|
212 |
///This function sets a clipping area. After that, the drawing operations
|
alpar@1971
|
213 |
///will affect only this area.
|
alpar@1971
|
214 |
///\sa collect
|
alpar@1971
|
215 |
///
|
alpar@1971
|
216 |
EpsDrawer &clip();
|
alpar@1971
|
217 |
///Set a clipping area using even-odd rule.
|
alpar@1971
|
218 |
|
alpar@1971
|
219 |
///This function sets a clipping area using even-odd rule.
|
alpar@1971
|
220 |
///After that, the drawing operations
|
alpar@1971
|
221 |
///will affect only this area.
|
alpar@1971
|
222 |
///\sa collect
|
alpar@1971
|
223 |
///
|
alpar@1971
|
224 |
EpsDrawer &eoClip();
|
alpar@1971
|
225 |
|
alpar@1971
|
226 |
///Set the line width.
|
alpar@1971
|
227 |
EpsDrawer &lineWidth(double w);
|
alpar@1971
|
228 |
///Set the style of the line ends
|
alpar@1971
|
229 |
|
alpar@1971
|
230 |
///\param i It can be 0, 1 or 2
|
alpar@1971
|
231 |
///
|
alpar@1971
|
232 |
EpsDrawer &lineCap(int i);
|
alpar@1971
|
233 |
///Set the style of the line joins
|
alpar@1971
|
234 |
|
alpar@1971
|
235 |
///\param i It can be 0, 1 or 2
|
alpar@1971
|
236 |
///
|
alpar@1971
|
237 |
EpsDrawer &lineJoin(int i);
|
alpar@1971
|
238 |
///Set the cut length of near parallel joining lines.
|
alpar@1971
|
239 |
EpsDrawer &miterLimit(double w);
|
alpar@1971
|
240 |
|
alpar@1971
|
241 |
///Set the drawing color
|
alpar@1971
|
242 |
EpsDrawer &color(double r, double g, double b);
|
alpar@1971
|
243 |
///Set the drawing color
|
alpar@1971
|
244 |
EpsDrawer &color(Color c)
|
alpar@1971
|
245 |
{
|
alpar@1971
|
246 |
return color(c.red(),c.green(),c.blue());
|
alpar@1971
|
247 |
}
|
alpar@1971
|
248 |
|
alpar@1971
|
249 |
///Translate the coordinate system
|
alpar@1971
|
250 |
EpsDrawer &translate(double x,double y);
|
alpar@1971
|
251 |
///Translate the coordinate system
|
alpar@1971
|
252 |
template<class T> EpsDrawer &translate(xy<T> p)
|
alpar@1971
|
253 |
{
|
alpar@1971
|
254 |
return translate(p.x,p.y);
|
alpar@1971
|
255 |
}
|
alpar@1971
|
256 |
///Rotate the coordinate system
|
alpar@1971
|
257 |
EpsDrawer &rotate(double r);
|
alpar@1971
|
258 |
///Scale the coordinate system
|
alpar@1971
|
259 |
EpsDrawer &scale(double sx, double sy);
|
alpar@1971
|
260 |
///Scale the coordinate system
|
alpar@1971
|
261 |
EpsDrawer &scale(double s) { return scale(s,s); }
|
alpar@1971
|
262 |
///Scale the coordinate system
|
alpar@1971
|
263 |
template<class T> EpsDrawer &scale(xy<T> p)
|
alpar@1971
|
264 |
{
|
alpar@1971
|
265 |
return scale(p.x,p.y);
|
alpar@1971
|
266 |
}
|
alpar@1971
|
267 |
|
alpar@1971
|
268 |
///\e
|
alpar@1971
|
269 |
EpsDrawer &flush();
|
alpar@1971
|
270 |
///Clear the image
|
alpar@1971
|
271 |
EpsDrawer &clear();
|
alpar@1971
|
272 |
|
alpar@1971
|
273 |
///Print a text at the current point
|
alpar@1971
|
274 |
EpsDrawer &operator<<(const std::string &s);
|
alpar@1971
|
275 |
///Print a text at the current point
|
alpar@1971
|
276 |
EpsDrawer &operator<<(const char *s);
|
alpar@1971
|
277 |
///Print a number at the current point
|
alpar@1971
|
278 |
EpsDrawer &operator<<(int i);
|
alpar@1971
|
279 |
///Print a number at the current point
|
alpar@1971
|
280 |
EpsDrawer &operator<<(double d);
|
alpar@1971
|
281 |
///Print a coordinate at the current point
|
alpar@1971
|
282 |
template<class T>
|
alpar@1971
|
283 |
EpsDrawer &operator<<(xy<T> p)
|
alpar@1971
|
284 |
{
|
alpar@1971
|
285 |
out << "((" << p.x << ',' << p.y <<")) show\n";
|
alpar@1971
|
286 |
return *this;
|
alpar@1971
|
287 |
}
|
alpar@1971
|
288 |
|
alpar@1971
|
289 |
};
|
alpar@1971
|
290 |
|
alpar@1971
|
291 |
}
|
alpar@1971
|
292 |
|
alpar@1971
|
293 |
#endif
|