lemon/eps.h
author deba
Wed, 28 Jun 2006 15:38:45 +0000
changeset 2113 48ec8161f9e1
parent 2008 0820d8168cbb
child 2174 f9e43b5cc617
permissions -rw-r--r--
Some modification in the documentation.
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
deba@2084
    29
  ///\ingroup eps_io
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
  
deba@2084
    37
  ///\ingroup eps_io
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@2008
    52
    ///Node shapes
alpar@2008
    53
    ///
alpar@2008
    54
    enum NodeShapes { 
alpar@2008
    55
      /// = 0
alpar@2008
    56
      ///\image html nodeshape_0.png
alpar@2008
    57
      ///\image latex nodeshape_0.eps "CIRCLE shape (0)" width=2cm
alpar@2008
    58
      CIRCLE=0, 
alpar@2008
    59
      /// = 1
alpar@2008
    60
      ///\image html nodeshape_1.png
alpar@2008
    61
      ///\image latex nodeshape_1.eps "SQUARE shape (1)" width=2cm
alpar@2008
    62
      ///
alpar@2008
    63
      SQUARE=1, 
alpar@2008
    64
      /// = 2
alpar@2008
    65
      ///\image html nodeshape_2.png
alpar@2008
    66
      ///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm
alpar@2008
    67
      ///
alpar@2008
    68
      DIAMOND=2,
alpar@2008
    69
      /// = 3
alpar@2008
    70
      ///\image html nodeshape_3.png
alpar@2008
    71
      ///\image latex nodeshape_2.eps "MALE shape (4)" width=2cm
alpar@2008
    72
      ///
alpar@2008
    73
      ///\warning Not implemented
alpar@2008
    74
      MALE=3,
alpar@2008
    75
      /// = 4
alpar@2008
    76
      ///\image html nodeshape_4.png
alpar@2008
    77
      ///\image latex nodeshape_2.eps "FEMALE shape (4)" width=2cm
alpar@2008
    78
      ///
alpar@2008
    79
      ///\warning Not implemented
alpar@2008
    80
      FEMALE=4
alpar@2008
    81
    };
alpar@1971
    82
    ///\e 
alpar@1971
    83
alpar@1971
    84
    ///The generated file is put to \c os.
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(std::ostream &os,int x,int y);
alpar@1971
    89
    ///\e
alpar@1971
    90
alpar@1971
    91
    ///The generated file is put to \c os.
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(std::ostream &os,int x1,int y1,int x2,int y2);
alpar@1971
    97
    ///\e
alpar@1971
    98
alpar@1971
    99
    ///The generated file is put to \c os.
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(std::ostream &os,xy<double> s);
alpar@1971
   104
    ///\e
alpar@1971
   105
alpar@1971
   106
    ///The generated file is put to \c os.
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(std::ostream &os,xy<double> a, xy<double> b);
alpar@1971
   112
    ///\e
alpar@1971
   113
alpar@1971
   114
    ///The generated picture is put to the file \c name.
alpar@1971
   115
    ///
alpar@1971
   116
    ///\c x and \c y determine the upper
alpar@1971
   117
    ///right corner of the bounding box. The lower left corner is (0,0).
alpar@1971
   118
    EpsDrawer(const std::string &name,int x,int y);
alpar@1971
   119
    ///\e
alpar@1971
   120
alpar@1971
   121
    ///The generated picture is put to the file \c name.
alpar@1971
   122
    ///
alpar@1971
   123
    ///(x1,y1) and (x2,y2)
alpar@1971
   124
    /// determine the lower left and the upper right corners of
alpar@1971
   125
    ///the bounding box, respectively.
alpar@1971
   126
    EpsDrawer(const std::string &name,int x1,int y1,int x2,int y2);
alpar@1971
   127
    ///\e
alpar@1971
   128
alpar@1971
   129
    ///The generated picture is put to the file \c name.
alpar@1971
   130
    ///
alpar@1971
   131
    ///\c s determines the upper
alpar@1971
   132
    ///right corner of the bounding box. The lower left corner is (0,0).
alpar@1971
   133
    EpsDrawer(const std::string &name,xy<double> s);
alpar@1971
   134
    ///\e
alpar@1971
   135
alpar@1971
   136
    ///The generated picture is put to the file \c name.
alpar@1971
   137
    ///
alpar@1971
   138
    ///\c a and \c b
alpar@1971
   139
    /// determine the lower left and the upper right corners of
alpar@1971
   140
    ///the bounding box, respectively.
alpar@1971
   141
    EpsDrawer(const std::string &name,xy<double> a, xy<double> b);
alpar@1971
   142
alpar@1971
   143
//     template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b) 
alpar@1971
   144
//     template<class T> EpsDrawer(std::ostream &os,BoundingBox<T> b);
alpar@1971
   145
    
alpar@1971
   146
    ~EpsDrawer();
alpar@1971
   147
    
alpar@1971
   148
    ///Save the current graphic state.
alpar@1971
   149
alpar@1971
   150
    ///This function saves the current coordinate system, and the parameters
alpar@1971
   151
    ///set by \ref color(), \ref lineWidth() etc.
alpar@1971
   152
    ///The can be \ref restore "restore()"d later.
alpar@1971
   153
    ///
alpar@1971
   154
    ///The \ref save() - \ref restore() pairs can be nested.
alpar@1971
   155
    ///
alpar@1971
   156
    EpsDrawer &save();
alpar@1971
   157
    ///Restore the saves graphic state.
alpar@1971
   158
alpar@1971
   159
    EpsDrawer &restore();
alpar@1971
   160
    
alpar@1971
   161
    ///Draw a line
alpar@1971
   162
    EpsDrawer &line(double x1,double y1,double x2,double y2);
alpar@1971
   163
    ///Draw a line from the current point
alpar@1971
   164
    EpsDrawer &lineTo(double x1,double y1);
alpar@1971
   165
    ///Move the current point
alpar@1971
   166
    EpsDrawer &moveTo(double x1,double y1);
alpar@1971
   167
    ///Draw a circle
alpar@1971
   168
    EpsDrawer &circle(double x,double y, double r);
alpar@1971
   169
    
alpar@1971
   170
    ///Draw a line
alpar@1971
   171
    template<class T> EpsDrawer &line(xy<T> p1,xy<T> p2) 
alpar@1971
   172
    {
alpar@1971
   173
      return line(p1.x,p1.y,p2.x,p2.y);
alpar@1971
   174
    }
alpar@1971
   175
    ///Draw a line from the current point
alpar@1971
   176
    template<class T> EpsDrawer &lineTo(xy<T> p)
alpar@1971
   177
    {
alpar@1971
   178
      return lineTo(p.x,p.y);
alpar@1971
   179
    }
alpar@1971
   180
    ///Move the current point
alpar@1971
   181
    template<class T> EpsDrawer &moveTo(xy<T> p)
alpar@1971
   182
    {
alpar@1971
   183
      return moveTo(p.x,p.y);
alpar@1971
   184
    }
alpar@1971
   185
    ///Draw a circle
alpar@1971
   186
    template<class T> EpsDrawer &circle(xy<T> p, double r)
alpar@1971
   187
    {
alpar@1971
   188
      return circle(p.x,p.y,r);
alpar@1971
   189
    }
alpar@1971
   190
    
alpar@1971
   191
    ///Set the font size
alpar@1971
   192
    EpsDrawer &fontSize(double si);
alpar@1971
   193
    ///Set the fint type
alpar@1971
   194
    EpsDrawer &font(std::string );
alpar@1971
   195
    ///Sets whether text output is centerized of not
alpar@1971
   196
alpar@1971
   197
    ///Sets whether text output is centerized of not.
alpar@1971
   198
    ///
alpar@1971
   199
    ///\warning \ref save() doesn't save this setting.
alpar@1971
   200
    ///
alpar@1971
   201
    EpsDrawer &centerMode(bool m);
alpar@1971
   202
    ///Turn to collect mode.
alpar@1971
   203
alpar@1971
   204
    ///If you call this function, then the drawing operations like \ref line(),
alpar@1971
   205
    ///\ref lineTo(), \ref moveTo() will not take place immediately, but istead
alpar@1971
   206
    ///they
alpar@1971
   207
    ///are collected. These operations form a \e path.
alpar@1971
   208
    ///Then you can \ref stroke(), \ref fill(), \ref eofill(), \ref clip() or
alpar@1971
   209
    ///\ref eoclip() it.
alpar@1971
   210
    ///When drawing, you can also use \ref closePath() to - surprise - close the
alpar@1971
   211
    ///current path.
alpar@1971
   212
    ///
alpar@1971
   213
    ///This example draws a red filled diamond.
alpar@1971
   214
    ///\code
alpar@1971
   215
    ///  EpsDraw ed("diamond.eps",-1,-1,1,1);
alpar@1971
   216
    ///  ed.color(1,0,0,).collect().line(0,-1,1,0).lineTo(0,1)
alpar@1971
   217
    ///    .lineTo(-1,0).closePath().fill();
alpar@1971
   218
    ///\endcode
alpar@1971
   219
    EpsDrawer &collect();
alpar@1971
   220
    ///Close the current drawing path
alpar@1971
   221
    EpsDrawer &closePath();
alpar@1971
   222
    ///Stroke (draw) a path
alpar@1971
   223
alpar@1971
   224
    ///Stroke (draw) a path.
alpar@1971
   225
    ///\sa collect
alpar@1971
   226
    ///
alpar@1971
   227
    EpsDrawer &stroke();
alpar@1971
   228
    ///Fill a path
alpar@1971
   229
alpar@1971
   230
    ///Fill a path.
alpar@1971
   231
    ///\sa collect
alpar@1971
   232
    ///
alpar@1971
   233
    EpsDrawer &fill();
alpar@1971
   234
    ///Even-odd fill a path
alpar@1971
   235
alpar@1971
   236
    ///Even-odd fill a path.
alpar@1971
   237
    ///\sa collect
alpar@1971
   238
    ///
alpar@1971
   239
    EpsDrawer &eoFill();
alpar@1971
   240
    ///Set a clipping area.
alpar@1971
   241
alpar@1971
   242
    ///This function sets a clipping area. After that, the drawing operations
alpar@1971
   243
    ///will affect only this area.
alpar@1971
   244
    ///\sa collect
alpar@1971
   245
    ///
alpar@1971
   246
    EpsDrawer &clip();
alpar@1971
   247
    ///Set a clipping area using even-odd rule.
alpar@1971
   248
alpar@1971
   249
    ///This function sets a clipping area using even-odd rule.
alpar@1971
   250
    ///After that, the drawing operations
alpar@1971
   251
    ///will affect only this area.
alpar@1971
   252
    ///\sa collect
alpar@1971
   253
    ///
alpar@1971
   254
    EpsDrawer &eoClip();
alpar@1971
   255
    
alpar@1971
   256
    ///Set the line width.
alpar@1971
   257
    EpsDrawer &lineWidth(double w);
alpar@1971
   258
    ///Set the style of the line ends
alpar@1971
   259
alpar@1971
   260
    ///\param i It can be 0, 1 or 2
alpar@1971
   261
    ///
alpar@1971
   262
    EpsDrawer &lineCap(int i);
alpar@1971
   263
    ///Set the style of the line joins
alpar@1971
   264
alpar@1971
   265
    ///\param i It can be 0, 1 or 2
alpar@1971
   266
    ///
alpar@1971
   267
    EpsDrawer &lineJoin(int i);
alpar@1971
   268
    ///Set the cut length of near parallel joining lines.
alpar@1971
   269
    EpsDrawer &miterLimit(double w);
alpar@1971
   270
    
alpar@1971
   271
    ///Set the drawing color
alpar@1971
   272
    EpsDrawer &color(double r, double g, double b);
alpar@1971
   273
    ///Set the drawing color
alpar@1971
   274
    EpsDrawer &color(Color c)
alpar@1971
   275
    {
alpar@1971
   276
      return color(c.red(),c.green(),c.blue());
alpar@1971
   277
    }
alpar@1971
   278
    
alpar@2008
   279
    ///Draw a node shape
alpar@2008
   280
alpar@2008
   281
    ///Draw a node shape.
alpar@2008
   282
    ///
alpar@2008
   283
    ///\param t The shape of the drawn object
alpar@2008
   284
    ///\param x The \c x coordinate of the node
alpar@2008
   285
    ///\param y The \c y coordinate of the node
alpar@2008
   286
    ///\param col Color of the node. The default color is white
alpar@2008
   287
    ///\param brd Color of the node border. The default color is black
alpar@2008
   288
    EpsDrawer &node(NodeShapes t, double x, double y, double r,
alpar@2008
   289
		    Color col=Color(1,1,1), Color brd=Color(0,0,0));
alpar@2008
   290
    ///Draw a node shape
alpar@2008
   291
    
alpar@2008
   292
    ///Draw a node shape.
alpar@2008
   293
    ///
alpar@2008
   294
    ///\param t The shape of the drawn object
alpar@2008
   295
    ///\param pos Position of the node
alpar@2008
   296
    ///\param col Color of the node. The default color is white
alpar@2008
   297
    ///\param brd Color of the node border. The default color is black
alpar@2008
   298
    template<class T>
alpar@2008
   299
    EpsDrawer &node(NodeShapes t, xy<T> pos, double r,
alpar@2008
   300
		    Color col=Color(1,1,1), Color brd=Color(0,0,0))
alpar@2008
   301
    {
alpar@2008
   302
      return node(t,pos.x,pos.y,r,col,brd);
alpar@2008
   303
    }
alpar@2008
   304
alpar@1971
   305
    ///Translate the coordinate system
alpar@1971
   306
    EpsDrawer &translate(double x,double y);
alpar@1971
   307
    ///Translate the coordinate system
alpar@1971
   308
    template<class T> EpsDrawer &translate(xy<T> p)
alpar@1971
   309
    {
alpar@1971
   310
      return translate(p.x,p.y);
alpar@1971
   311
    }
alpar@1971
   312
    ///Rotate the coordinate system
alpar@1971
   313
    EpsDrawer &rotate(double r);
alpar@1971
   314
    ///Scale the coordinate system
alpar@1971
   315
    EpsDrawer &scale(double sx, double sy);
alpar@1971
   316
    ///Scale the coordinate system
alpar@1971
   317
    EpsDrawer &scale(double s) { return scale(s,s); }
alpar@1971
   318
    ///Scale the coordinate system
alpar@1971
   319
    template<class T> EpsDrawer &scale(xy<T> p)
alpar@1971
   320
    {
alpar@1971
   321
      return scale(p.x,p.y);
alpar@1971
   322
    }
alpar@1971
   323
    
alpar@1971
   324
    ///\e
alpar@1971
   325
    EpsDrawer &flush();
alpar@1971
   326
    ///Clear the image
alpar@1971
   327
    EpsDrawer &clear();
alpar@1971
   328
    
alpar@1971
   329
    ///Print a text at the current point
alpar@1971
   330
    EpsDrawer &operator<<(const std::string &s);
alpar@1971
   331
    ///Print a text at the current point
alpar@1971
   332
    EpsDrawer &operator<<(const char *s);
alpar@1971
   333
    ///Print a number at the current point
alpar@1971
   334
    EpsDrawer &operator<<(int i);
alpar@1971
   335
    ///Print a number at the current point
alpar@1971
   336
    EpsDrawer &operator<<(double d);
alpar@1971
   337
    ///Print a coordinate at the current point
alpar@1971
   338
    template<class T>
alpar@1971
   339
    EpsDrawer &operator<<(xy<T> p) 
alpar@1971
   340
    {
alpar@1971
   341
      out << "((" << p.x << ',' << p.y <<")) show\n";
alpar@1971
   342
      return *this;
alpar@1971
   343
    }
alpar@1971
   344
    
alpar@1971
   345
  };
alpar@1971
   346
  
alpar@1971
   347
}
alpar@1971
   348
alpar@1971
   349
#endif