latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 /* ----------------------------------------------------------------------- 00024 * project ....: LTI Digitale Bild/Signal Verarbeitungsbibliothek 00025 * file .......: ltiEpsDraw.h 00026 * authors ....: Jochen Wickel 00027 * organization: LTI, RWTH Aachen 00028 * creation ...: 20.7.2002 00029 * revisions ..: $Id: ltiEpsDraw.h,v 1.10 2006/02/08 11:03:24 ltilib Exp $ 00030 */ 00031 #ifndef _LTI_EPS_DRAW_H 00032 #define _LTI_EPS_DRAW_H 00033 00034 #ifdef _LTI_MSC_6 00035 #pragma warning ( disable : 4786 ) 00036 #endif 00037 00038 #include <vector> 00039 #include <string> 00040 #include <fstream> 00041 #include <list> 00042 #include <map> 00043 00044 #include "ltiDrawBase.h" 00045 00046 #include "ltiTypes.h" 00047 #include "ltiHTypes.h" 00048 #include "ltiCMYKColor.h" 00049 #include "ltiColors.h" 00050 #include "ltiContour.h" 00051 #include "ltiIoHandler.h" 00052 #include "ltiLocation.h" 00053 #include "ltiDataCodec.h" 00054 00055 00056 namespace lti { 00057 00058 /** 00059 * Object for drawing lines and points and geometric objects 00060 * to an (E)PS file. 00061 * 00062 * Example: 00063 * 00064 * if you want to draw some rectanglees, you can create an instance of 00065 * epsDraw-object this way: 00066 * 00067 * \code 00068 * lti::epsDraw<cmykColor> drawer(std::cout); // dump EPS to stdout 00069 * 00070 * drawer.rectangle(10,10,200,200); // draw a large rectangle 00071 * drawer.rectangle(50,50,100,150); // and a smaller one 00072 * \endcode 00073 * The natural coordinate system uses points (pt, 1pt=1/72 inch) as basic 00074 * unit. All values are specified in pt. 00075 */ 00076 template<class T> 00077 class epsDraw : public drawBase<T> { 00078 public: 00079 00080 00081 /** 00082 * This is used for setting the vertical alignment of text. 00083 */ 00084 enum vAlignType { 00085 valignBottom, ///< reference point is the bottom line of the text 00086 valignMiddle, ///< reference point is the middle of the text 00087 valignTop ///< reference point is the top of the text 00088 }; 00089 00090 /** 00091 * This is used for setting the horizontal alignment of text. 00092 */ 00093 enum alignType { 00094 alignLeft, ///< reference point is at the left 00095 alignCenter, ///< reference point is at the left 00096 alignRight ///< reference point is at the left 00097 }; 00098 00099 00100 /** 00101 * The encoding used for embedded bitmaps. 00102 */ 00103 enum imageCoding { 00104 asciiHex, ///< uses ASCII Hex digits (simple, but huge) 00105 ascii85, ///< uses ASCII Hex digits (a little bit more efficient) 00106 runLength, ///< uses runlength compression 00107 #if HAVE_LIBZ 00108 flate, ///< uses zLib deflate compression (Postscript Level 3 only) 00109 #endif 00110 jpeg ///< uses JPEG compression 00111 }; 00112 00113 00114 00115 /** 00116 * The width of an ISO A4 sheet in points (1pt = 1/72in) 00117 */ 00118 static const int a4Width; 00119 /** 00120 * The height of an ISO A4 sheet in points (1pt = 1/72in) 00121 */ 00122 static const int a4Height; 00123 00124 /** 00125 * The default resolution of the PostScript interpreter 00126 */ 00127 static const float defaultResolution; 00128 00129 /** 00130 * Constructor. It gets a drawing area, the bounding box. 00131 * The stuff that is drawn is scaled to that area if 00132 * scale is true. Otherwise, it is simply clipped. 00133 */ 00134 epsDraw(std::ostream &os, const point& drawingArea, 00135 bool scale=true, bool eps=true); 00136 00137 /** 00138 * Constructor. It determines the size of the bounding box 00139 * from the stuff that is being drawn. 00140 */ 00141 epsDraw(std::ostream &os, bool scale=true, bool eps=true); 00142 00143 /** 00144 * destructor 00145 */ 00146 ~epsDraw(); 00147 00148 /** 00149 * Set the title of this drawing. 00150 */ 00151 void setTitle(const std::string &t) { 00152 title=t; 00153 } 00154 00155 /** 00156 * Set the font size that is used for text. At present, only 00157 * a single font size is allowed in each EPS document. 00158 */ 00159 void setFontSize(int t) { 00160 fontSize=t; 00161 } 00162 00163 /** 00164 * get name of this type. 00165 */ 00166 const char* getTypeName() const; 00167 00168 /** 00169 * Specifies the line width. Default is 0, which is the thinnest 00170 * line an output device can generate. 00171 */ 00172 void setLineWidth(float f); 00173 00174 /** 00175 * Specifies the clipping rectangle and enables clipping. 00176 * If not called, there is no clipping. 00177 */ 00178 void setClip(const trectangle<int>& rc); 00179 00180 /** 00181 * Specifies the size of the drawing area in pt. The complete figure 00182 * is scaled and moved such that it fits tightly into a box of this size. 00183 */ 00184 void setSize(const point& dim); 00185 00186 /** 00187 * Specifies the resolution of the figure. By default, each pixel 00188 * is considered an PostScript point (1/72 inch). By setting the, 00189 * resolution, you can enlarge or shrink the entire EPS figure. 00190 * This value can be set independently from the remaining parameters, 00191 * most notably the transform, because it only involves the 00192 * PostScript coordinate to device coordinate conversion, not the 00193 * image coordinate to PostScript coordinate conversion. 00194 */ 00195 void setResolution(float r); 00196 00197 /** 00198 * Adds a comment to the (E)PS file. 00199 */ 00200 void addComment(const std::string& msg); 00201 00202 /** 00203 * returns the size of the drawing area 00204 */ 00205 point getCanvasSize(); 00206 00207 00208 /** 00209 * Sets the transform for the coordinates. With this, you 00210 * override the default transform. 00211 */ 00212 void setTransform(const tpoint<float>& offset=tpoint<float>(0.0f,0.0f), 00213 const tpoint<float>& scale=tpoint<float>(1.0f,1.0f)); 00214 00215 /** 00216 * Specifies color to be used. 00217 */ 00218 void setColor(const T& color); 00219 00220 void setColor(const char* color); 00221 00222 /** 00223 * Specifies grayscale level to be used (range from 0 to 1) for 00224 * the next graphics objects. If you want to specify a gray 00225 * value, you should always use this method instead of setColor 00226 * with grey RGB values. The reason for this is a PostScript 00227 * convention: Most color printers mix colors by subtractive 00228 * colors. If you specify RGB, you will get black mixed out of 00229 * the colors of the printer. If you specify the grey value by 00230 * setGray, you will get simple black ink. (An alternative 00231 * is to use setColor with cmyk values, setting cmy to zero and 00232 * k to the gray level. 00233 */ 00234 void setGray(const float k); 00235 00236 00237 /** 00238 * Set pixel at x,y. 00239 * @param x x-coordinate of the point 00240 * @param y y-coordinate of the point 00241 */ 00242 void set(const int x, const int y); 00243 00244 /** 00245 * Set pixel at p. 00246 */ 00247 void set(const point& p) { 00248 set(p.x,p.y); } 00249 00250 /** 00251 * Set pixels at all positions in c 00252 */ 00253 void set(const pointList& c, const point& offset=point(0,0)) { 00254 drawBase<T>::set(c,offset); } 00255 00256 /** 00257 * Set pixel at p. If no style is given, the color and symbol 00258 * type set by the respective methods are used, else the style 00259 * given as an argument is used. 00260 * @param p coordinates of the pixel to be set 00261 */ 00262 template<class U> 00263 void set(const hPoint2D<U>& p) 00264 {set(p.x/p.h,p.y/p.h);}; 00265 00266 /** 00267 * Draw a location. 00268 * 00269 * @param loc location with position, angle and radius 00270 * @param showAngleLine if true, a line from the middle point of the 00271 * location (given by loc.position) with the angle given by 00272 * loc.angle will be drawn. 00273 */ 00274 void set(const location& loc,const bool showAngleLine = false) { 00275 drawBase<T>::set(loc,showAngleLine); 00276 } 00277 00278 /** 00279 * Draws a rectLocation 00280 * 00281 * @param loc location with position, angle and radius 00282 * @param showAngleLine if true, a line from the middle point of the 00283 * location (given by loc.position) with the angle given by 00284 * loc.angle will be drawn. 00285 */ 00286 void set(const rectLocation& loc,const bool showAngleLine = false) { 00287 drawBase<T>::set(loc,showAngleLine); 00288 } 00289 00290 /** 00291 * Draws a list of locations 00292 */ 00293 void set(const std::list<location>& locs, 00294 const bool showAngleLine = false) { 00295 drawBase<T>::set(locs,showAngleLine); 00296 } 00297 00298 /** 00299 * Draw the contents of the vector using the whole image 00300 * @param vct the vector to be shown 00301 * @param forceAxis0 if true, both axis will be shown, i.e. the value 0 for 00302 * the vector will be always shown. If false, only the 00303 * required value-range will be shown 00304 */ 00305 void set(const vector<int>& vct, 00306 const bool& forceAxis0 = true); 00307 00308 /** 00309 * Draws an image, using RGB color pixels. The image is drawn 00310 * in the coordinate space from (offset.x,offset.y) to 00311 * (offset.x+img.columns,offset.y+img.rows) 00312 */ 00313 void drawImage(const image& img, 00314 const imageCoding code=ascii85, 00315 const point& offset=point(0,0)); 00316 00317 /** 00318 * Draws an image, using grayscale pixels. The image is drawn 00319 * in the coordinate space from (offset.x,offset.y) to 00320 * (offset.x+img.columns,offset.y+img.rows) 00321 * If blackWhite is set to true, the resulting image will be 00322 * pure black-and-white. Which pixel is black is defined by t, 00323 * all values < t whill appear white, all values > t will appear black. 00324 */ 00325 inline void drawImage(const channel& img, 00326 const imageCoding code=ascii85, 00327 const point& offset=point(0,0), 00328 bool blackWhite=false, 00329 const float t=0.5) { 00330 channel8 tmp; 00331 tmp.castFrom(img); 00332 drawImage(tmp,code,offset,blackWhite,int(t*256+0.5)); 00333 } 00334 00335 /** 00336 * Draws an image, using grayscale pixels. The image is drawn 00337 * in the coordinate space from (offset.x,offset.y) to 00338 * (offset.x+img.columns,offset.y+img.rows) 00339 * If blackWhite is set to true, the resulting image will be 00340 * pure black-and-white. Which pixel is black is defined by t, 00341 * all values < t whill appear white, all values > t will appear black. 00342 */ 00343 void drawImage(const channel8& img, 00344 const imageCoding code=ascii85, 00345 const point& offset=point(0,0), 00346 bool blackWhite=false, 00347 const int t=128); 00348 00349 /** 00350 * Draws a polygon. 00351 */ 00352 void polygon(const point plist[], int n, bool closed=true, bool filled=false); 00353 00354 /** 00355 * Draw a line from the point (fx,fy) to point (tx,ty). 00356 * The "last point" will be defined with the last "set", "line" or 00357 * "lineTo" method. 00358 */ 00359 void line(const int fx, const int fy, 00360 const int tx, const int ty); 00361 00362 /** 00363 * Draw a line from the point p to point p2. 00364 * The "last point" will be defined with the last "set", "line" or 00365 * "lineTo" method. 00366 */ 00367 void line(const point& p1,const point& p2) { 00368 line(p1.x,p1.y,p2.x,p2.y); 00369 }; 00370 00371 /** 00372 * Draw a line from the last point to (x,y). 00373 * The "last point" will be defined with the last "set", "line" or 00374 * "lineTo" method. 00375 */ 00376 void lineTo(const int x, const int y); 00377 00378 /** 00379 * Draw a line from the last point to point p. 00380 * The "last point" will be defined with the last "set", "line" or 00381 * "lineTo" method. 00382 */ 00383 void lineTo(const point& p) {lineTo(p.x,p.y);}; 00384 00385 /** 00386 * Draws a grid in the image. 00387 * The interpretation of delta depends on the value of interval. 00388 * if interval is true, the values are taken as number of pixels 00389 * between two grid lines in x and y direction. Otherwise, it 00390 * is used as number of grid lines. For drawing, the alternate 00391 * color is used. 00392 */ 00393 void grid(const point& delta, const bool interval=true); 00394 00395 /** 00396 * Draws a vertical line from (x,y1) to (x,y2). 00397 */ 00398 void verticalLine(const int x, const int y1, const int y2); 00399 00400 void verticalLine(const point& p1, const point& p2) { 00401 verticalLine(p1.x,p1.y,p2.y); 00402 } 00403 00404 /** 00405 * Draws a horizontal line from (x1,y) to (x2,y) 00406 */ 00407 void horizontalLine(const int x1, const int x2, const int y); 00408 00409 void horizontalLine(const point& p1, const point& p2) { 00410 horizontalLine(p1.x,p2.x,p1.y); 00411 } 00412 00413 00414 /** 00415 * draw a box 00416 * 00417 * \deprecated use rectangle(int, int, int, int, const bool&) instead! 00418 * 00419 */ 00420 void box(const int x1, const int y1, const int x2, const int y2, 00421 const bool& filled=false) { 00422 rectangle(x1,y1,x2,y2,filled); 00423 } 00424 00425 /** 00426 * draw a box 00427 * 00428 * \deprecated use rectangle(rectangle&, const bool&) instead! 00429 * 00430 * @see box(int,int,int,int,const bool&) 00431 */ 00432 void box(const trectangle<int>& r, const bool& filled=false) 00433 {box(r.ul.x,r.ul.y,r.br.x,r.br.y,filled);} 00434 00435 /** 00436 * draw a box 00437 * 00438 * \deprecated use rectangle(point&, point&, const bool&) instead! 00439 * 00440 * @see box(int,int,int,int,const bool&) 00441 */ 00442 void box(const point& upperLeft, const point& bottomRight, 00443 const bool& filled=false) 00444 {box(upperLeft.x,upperLeft.y,bottomRight.x,bottomRight.y,filled);} 00445 00446 /** 00447 * draw a rectangle 00448 * 00449 * @param x1 left x-coordinate. 00450 * @param y1 upper y-coordinate. 00451 * @param x2 right x-coordinate. 00452 * @param y2 bottom y-coordinate. 00453 * @param filled if true box is filled 00454 */ 00455 void rectangle(const int x1, const int y1, const int x2, const int y2, 00456 const bool& filled=false); 00457 00458 /** 00459 * draw a rectangle. 00460 * the rectangle must contain the upper left and the bottom right point 00461 * @param r rectangle to be drawn 00462 * @param filled if true rectangle is filled 00463 */ 00464 void rectangle(const trectangle<int>& r, const bool& filled=false) 00465 {rectangle(r.ul.x,r.ul.y,r.br.x,r.br.y,filled);} 00466 00467 /** 00468 * draw a rectangle 00469 * @param upperLeft upper left corner of the rectangle 00470 * @param bottomRight bottom right corner of the rectangle 00471 * @param filled if true rectangle is filled 00472 */ 00473 void rectangle(const point& upperLeft, const point& bottomRight, 00474 const bool& filled=false) 00475 {rectangle(upperLeft.x,upperLeft.y,bottomRight.x,bottomRight.y,filled);} 00476 00477 /** 00478 * draw a circle with circle center 'p1' and radius 'r' 00479 */ 00480 void circle(const point& p1,const int r, const bool& filled=false); 00481 00482 /** 00483 * draw a circle with circle center '(x,y)' and radius 'r' 00484 */ 00485 void circle(const int x,const int y,const int r, const bool& filled=false){ 00486 circle(point(x,y),r,filled); }; 00487 00488 /** 00489 * draw an ellipse with center 'p1' and main axes 'aX' and 'aY' 00490 */ 00491 void ellipse(const point& p1,const int aX, const int aY, 00492 const bool& filled=false); 00493 00494 /** 00495 * draw an ellipse with center 'p1' and main axes 'aX' and 'aY' 00496 * @see ellipse() 00497 * @param p1 center of the ellipse 00498 * @param aX length of the main axis 00499 * @param aY length of the secondary axis 00500 * @param angle between the main axis and the horizontal axis 00501 * @param filled indicates if the ellipse should be draw filled or not 00502 */ 00503 void ellipse(const point& p1,const int aX, const int aY, 00504 const float& angle, const bool& filled=false); 00505 00506 /** 00507 * draw an arc from 'pA' to 'pB', clockwise around center 'p1'. 00508 */ 00509 void arc(const point& p1, const point& pA, const point& pB); 00510 00511 /** 00512 * draw an integer <code>num</code> at position 'p1'. The alignment 00513 * is left/bottom. 00514 * @see text() 00515 * @param num the number to be written 00516 * @param p1 the position where the number will be drawn 00517 */ 00518 void number(const int num, 00519 const point& p1 = point(0,0)); 00520 00521 /** 00522 * draw an integer <code>num</code> at position 'x'/'y'. 00523 * @see text() 00524 */ 00525 void number(const int num, 00526 const int x, 00527 const int y); 00528 00529 /** 00530 * Draw the given text at the position <code>upperleft</code>. 00531 * @param txt the output text 00532 * @param pos the position where the text will be written 00533 * @param a the alignType of the horizonal alignment. 00534 * @param b the vAlignType of the vertical alignment. 00535 */ 00536 void text(const std::string txt, 00537 const point& pos = point(0,0), 00538 const alignType a=alignLeft, 00539 const vAlignType b=valignTop) { 00540 text(txt,pos.x,pos.y,a,b); 00541 } 00542 00543 /** 00544 * Draw the given text at the position <code>upperleft</code>. 00545 * @param txt the output text 00546 * @param x the x coordinate in the image where the text will be 00547 * written 00548 * @param y the y coordinate in the image where the text will be 00549 * written 00550 * @param a the alignType of the horizonal alignment. 00551 * @param b the vAlignType of the vertical alignment. 00552 */ 00553 void text(const std::string txt, 00554 const int x, const int y, 00555 const alignType a, 00556 const vAlignType b); 00557 00558 00559 /** 00560 * Draw the given text at the position <code>upperleft</code>. 00561 * @param txt the output text 00562 * @param x the x coordinate in the image where the text will be 00563 * written 00564 * @param y the y coordinate in the image where the text will be 00565 * written 00566 */ 00567 void text(const std::string txt, 00568 const int x, const int y) { 00569 text(txt,x,y,alignLeft,valignTop); 00570 } 00571 00572 /** 00573 * draw an arrow. arrow tip will be at (tx,ty). 00574 * If size<1.0 then tipsize will be the relative portion of arrow length. 00575 * If size>1.0 then tipsize will be (int)size, independent of arrow length. 00576 */ 00577 void arrow(const int fx, const int fy, 00578 const int tx, const int ty, 00579 const float& size=0.2f); 00580 00581 00582 void arrow(const point& p1,const point& p2,const float& size=0.2f){ 00583 arrow(p1.x,p1.y,p2.x,p2.y,size); 00584 }; 00585 00586 /** 00587 * Closes this object. At this time, all Postscript objects are 00588 * written to the output stream. 00589 */ 00590 void close(); 00591 00592 /** 00593 * Sets the pattern for drawing lines. All subsequent lines 00594 * will be drawn in the given pattern. The default is the 00595 * continuous line. 00596 * @param pat pattern for drawing lines. 00597 */ 00598 virtual void setLinePattern(const linePattern& pat); 00599 00600 /** 00601 * Sets the pattern for filling areas. All subsequenly filled 00602 * areas will be filled with the given pattern. The default 00603 * pattern is a homogenouos fill. 00604 * @param pat pattern for filling areas. 00605 */ 00606 virtual void setFillPattern(const fillPattern& pat); 00607 00608 00609 protected: 00610 /** 00611 * Returns the name of the given line pattern. 00612 * This name can be used as 00613 * PostScript command to switch to the given pattern. The method 00614 * will ensure that the PS header contains the required command 00615 * definition. 00616 */ 00617 const std::string& getLinePatName(const linePattern& c); 00618 00619 /** 00620 * Returns the name of the given fill pattern. 00621 * This name can be used as 00622 * PostScript command to switch to the given pattern. The method 00623 * will ensure that the PS header contains the required command 00624 * definition. 00625 */ 00626 const std::string& getFillPatName(const fillPattern& c); 00627 00628 /** 00629 * Returns the name of the color c. This name can be used as 00630 * PostScript command to switch to the given color. The method 00631 * will ensure that the PS header contains the required command 00632 * definition. 00633 */ 00634 const std::string& getColorName(const rgbColor& c); 00635 00636 00637 /** 00638 * Returns the name of the color c. This name can be used as 00639 * PostScript command to switch to the given color. The method 00640 * will ensure that the PS header contains the required command 00641 * definition. 00642 */ 00643 const std::string& getColorName(const cmykColor& c); 00644 00645 00646 /** 00647 * draws the actual symbol at the actual position actX,actY 00648 */ 00649 void drawSymbol(const int x,const int y); 00650 00651 void drawSymbol(const int x, const int y,const int width, 00652 const typename drawBase<T>::eMarkerType t); 00653 00654 void drawSymbol(const int x, const int y,const int width,const char* pT); 00655 00656 protected: 00657 00658 /** 00659 * this is a list of strings that contain the postscript command 00660 * sequence for a graphical object 00661 */ 00662 std::list<std::string> objects; 00663 00664 /** 00665 * this is a map from colors to the corresponding postscript command. 00666 */ 00667 std::map<rgbColor,std::string> rgbColorNames; 00668 00669 /** 00670 * this is a map from colors to the corresponding postscript command. 00671 */ 00672 std::map<cmykColor,std::string> cmykColorNames; 00673 00674 /** 00675 * A map for storing line pattern definitions. 00676 */ 00677 std::map<linePattern, std::string, graphicsPattern::less> linePatternNames; 00678 00679 /** 00680 * A map for storing fill pattern definitions. 00681 */ 00682 std::map<fillPattern, std::string, graphicsPattern::less> fillPatternNames; 00683 00684 // the number of colors 00685 int colorCount; 00686 00687 // the number of fill patterns 00688 int fillpatCount; 00689 00690 // the number of line patterns 00691 int linepatCount; 00692 00693 // two temporary buffers that are used in the methods 00694 std::string tmp; 00695 char numBuffer[256]; 00696 00697 // the number of graphical objects 00698 int objCount; 00699 00700 // the clipping rectangle, which is used only if doClip==true 00701 trectangle<int> clipRect; 00702 bool doClip; 00703 00704 // this is not the EPS bounding box, but the 00705 // bounding box of the stuff that has been drawn. 00706 // the EPS bounding box is always set to that which has been 00707 // set to the drawing area 00708 trectangle<int> bbox; 00709 00710 // the size of the drawing area in pt 00711 point dimension; 00712 00713 // the coordinate transform from user coordinates to pt 00714 float xScale,yScale, xOffset, yOffset; 00715 bool autoScale; 00716 00717 // flag denoting if we want an EPS file or a printable page. 00718 bool isEps; 00719 // the output stream 00720 std::ostream& out; 00721 // the currently active color 00722 std::string currentColor; 00723 00724 // the currently active line pattern 00725 std::string currentlpat; 00726 00727 // the currently active fill pattern 00728 std::string currentfpat; 00729 00730 // the title of the figure 00731 std::string title; 00732 // the global font size 00733 int fontSize; 00734 00735 // the resolution in dots per point (dots per 1/72 inch) 00736 // this value is used at two points: 1. the computation of the 00737 // bounding box and 2. for computing the final scale variables 00738 float resolution; 00739 00740 // contains the names of the postscript command 00741 static const char* alignCmd[3][3]; 00742 00743 // internal stuff 00744 00745 // expands the bounding box to include the given point, if necessary 00746 void adjustBoundingBox(int x, int y); 00747 00748 // expands the bounding box to include the given point, if necessary 00749 inline void adjustBoundingBox(const point& p) { 00750 adjustBoundingBox(p.x,p.y); 00751 } 00752 00753 // expands the bounding box to include the given points, if necessary 00754 inline void adjustBoundingBox(int x1, int y1, int x2, int y2) { 00755 adjustBoundingBox(x1,y1); 00756 adjustBoundingBox(x2,y2); 00757 } 00758 00759 // expands the bounding box to include the given points, if necessary 00760 inline void adjustBoundingBox(const point& p1, const point& p2) { 00761 adjustBoundingBox(p1); 00762 adjustBoundingBox(p2); 00763 } 00764 00765 // sets a new active point, initializes the given string 00766 void moveTo(std::string& tmp, int x, int y, bool init=true); 00767 // appends a line segment to the path in tmp 00768 void lineTo(std::string& tmp, int x, int y); 00769 // appends a line segment to the path in tmp 00770 void rlineTo(std::string& tmp, int x, int y); 00771 // sets a new active point, initializes the given string 00772 void moveTo(std::string& tmp, float x, float y, bool init=true); 00773 // appends a line segment to the path in tmp 00774 void lineTo(std::string& tmp, float x, float y); 00775 // appends a line segment to the path in tmp 00776 void rlineTo(std::string& tmp, float x, float y); 00777 // closes the path in tmp 00778 void closePath(std::string& tmp); 00779 00780 // adds a command 00781 inline void addCmd(const std::string& x) { 00782 objects.push_back(x); 00783 } 00784 00785 // strokes the path in x 00786 inline void stroke(const std::string& x) { 00787 objects.push_back(x+" s"); 00788 } 00789 00790 // fills the path in x 00791 inline void fill(const std::string& x) { 00792 objects.push_back(x+" f"); 00793 } 00794 00795 // returns the bounding box in a format as in the PS header 00796 std::string getBoundingBox(); 00797 00798 // dumps the PS header 00799 void writeHeader(); 00800 00801 // dumps the prolog 00802 void writeProlog(); 00803 00804 // dumps the color definitions 00805 void writeColorDefinitions(); 00806 00807 // dumps the color definitions 00808 void writePatternDefinitions(); 00809 00810 // computes the transform from user coordinates to pt 00811 void makeTransform(); 00812 00813 // writes the EPS setup 00814 void writeSetup(); 00815 00816 // writes the EPS trailer 00817 void writeTrailer(); 00818 00819 // writes the graphical objects 00820 void writeObjects(); 00821 00822 // issues a PS comment 00823 inline void cmt(const std::string& x) { 00824 out << "% " << x << std::endl; 00825 } 00826 00827 // issues a PS command 00828 inline void cmd(const std::string& x) { 00829 out << x << std::endl; 00830 } 00831 00832 // issues a PS command with a gsave/grestore wrapper 00833 inline void unsafecmd(const std::string& x) { 00834 out << "gsave\n" << x << std::endl << "grestore\n"; 00835 } 00836 00837 // inserts a dsc comment 00838 inline void dsc(const std::string& x) { 00839 out << "%%" << x << std::endl; 00840 } 00841 00842 // inserts a dsc comment with argument 00843 inline void dsc(const std::string& x, const std::string& arg) { 00844 out << "%%" << x << ": " << arg << std::endl; 00845 } 00846 00847 // binds and defines a command 00848 inline void bdef(const std::string& name, const std::string& def) { 00849 cmd("/"+name+" { "+def+" } bd"); 00850 } 00851 00852 // loads and defines a command 00853 inline void ldef(const std::string& name, const std::string& def) { 00854 cmd("/"+name+" /"+def+" ld"); 00855 } 00856 00857 // makes a definition 00858 inline void def(const std::string& name, const std::string& def) { 00859 cmd("/"+name+" "+def+" def"); 00860 } 00861 00862 bool addImageCommand(bool color, int width, int height, 00863 imageCoding comp, const point& offset, 00864 const dataCodec::buffer& src, 00865 const bool blackWhite=false); 00866 00867 }; 00868 } 00869 00870 //#include "ltiEpsDraw_template.h" 00871 00872 #endif