PLearn 0.1
|
#include <GhostScript.h>
Public Member Functions | |
GhostScript (int width=200, int height=200) | |
opens an X11 ghostscript window | |
GhostScript (const string &filename, real x1, real y1, real x2, real y2) | |
creates an eps file with the (x1,y1;x2,y2) bounding box | |
~GhostScript () | |
void | flush () |
PStream & | operator<< (char *str) |
void | run (const char *filename) |
void | copypage () |
void | showpage () |
void | gsave () |
void | grestore () |
void | translate (real x, real y) |
void | scale (real x, real y) |
void | moveto (real x, real y) |
void | rotate (real angle) |
void | mapping (real sourcex, real sourcey, real sourcewidth, real sourceheight, real destx, real desty, real destwidth, real destheight) |
void | show (const char *str) |
void | show (const string &str) |
void | show (real x, real y, const char *str, char halign='l', char valign='b') |
halign can be 'l' (left), 'c' (center) or 'r' (right) valign can be 't' (top), 'm' (middle) or 'b' (bottom) | |
void | show (real x, real y, const string &str, char halign='l', char valign='b') |
void | centerShow (real x, real y, const char *str) |
void | centerShow (real x, real y, const string &str) |
void | multilineShow (real x, real y, const string &text, real newlinesize, char halign='l', char valign='b') |
accepts multiple line text (lines separated by ) | |
void | show (real x, real y, Vec v) |
void | centerShow (real x, real y, Vec v) |
void | erasepage () |
void | setcolor (real r, real g, real b) |
void | setcolor (real rgb) |
takes color in rgb real as returned by rgb2real | |
void | setcolor (char *colorname) |
void | setgray (real g) |
void | setlinewidth (real w) |
void | setdash (Vec ary, real x=0) |
sets the dash pattern: ary contains the cyclic on-off distances of the dashes, which begin after an offset_of x units from the current point | |
void | drawLine (real x1, real y1, real x2, real y2) |
void | drawArrow (real x1, real y1, real x2, real y2) |
void | drawBox (real x, real y, real width, real height) |
void | fillBox (real x, real y, real width, real height) |
void | drawCross (real x, real y, real r, bool vertical=false, real ry=-1) |
void | drawCircle (real x, real y, real r) |
void | fillCircle (real x, real y, real r) |
void | displayBlack (const Mat &bm, real x, real y, real w, real h, bool painton1=true) |
void | displayGray (const Mat &bm, real x, real y, real w, real h) |
values in bm indicate quantity of light between 0.0 (black) and 1.0 (white) | |
void | displayRGB (const Mat &bm, real x, real y, real w, real h) |
values in bm are those obtained using the rgb2real function (see above) | |
void | usefont (const char *fontname="Times-Roman", real pointsize=12.0) |
Protected Types | |
typedef ios::char_type | char_type |
Static Protected Member Functions | |
static void | writeBitmapHexString1Bit (const Mat &bm, PStream &out, bool lastrowfirst=false) |
static void | writeBitmapHexString8Bits (const Mat &bm, PStream &out, bool lastrowfirst=false) |
static void | writeBitmapHexString24Bits (const Mat &bm, PStream &out, bool lastrowfirst=false) |
Protected Attributes | |
FILE * | gs_cstream |
PStream | togs |
char | command_string [1000] |
bool | isfile |
Definition at line 64 of file GhostScript.h.
typedef ios::char_type PLearn::GhostScript::char_type [protected] |
Definition at line 79 of file GhostScript.h.
opens an X11 ghostscript window
Definition at line 81 of file GhostScript.cc.
References command_string, gs_cstream, PLearn::PStream::outmode, PLearn::PStream::raw_ascii, and togs.
:isfile(false) { static char command_string[1000]; // sprintf(command_string,"gs -sDEVICE=x11 -g%d%c%d - > /dev/null",width,'x',height); sprintf(command_string,"gs -sDEVICE=x11 -g%d%c%d > /dev/null",width,'x',height); gs_cstream = popen(command_string,"w"); togs = new FdPStreamBuf(-1, fileno(gs_cstream)); togs.outmode=PStream::raw_ascii; }
creates an eps file with the (x1,y1;x2,y2) bounding box
Definition at line 93 of file GhostScript.cc.
References PLearn::endl(), gs_cstream, PLearn::PStream::raw_ascii, and togs.
:isfile(true) // :gs_cstream(0), togs(filename.c_str()) { gs_cstream= fopen(filename.c_str(), "w"); togs = new FdPStreamBuf(-1, fileno(gs_cstream)); togs.outmode=PStream::raw_ascii; togs << "%!PS-Adobe-2.0 EPSF-2.0" << endl; togs << "%%BoundingBox: " << x1 << " " << y1 << " " << x2 << " " << y2 << endl; }
PLearn::GhostScript::~GhostScript | ( | ) |
Definition at line 104 of file GhostScript.cc.
References PLearn::endl(), gs_cstream, isfile, and togs.
{ if(gs_cstream) { if(!isfile) togs << "\nquit" << endl; fclose(gs_cstream); } }
Definition at line 154 of file GhostScript.h.
Referenced by PLearn::displayVarGraph(), and PLearn::OldDisplayVarGraph().
{ show(x,y,str,'c','m'); }
Definition at line 157 of file GhostScript.h.
{ show(x,y,str,'c','m'); }
Definition at line 166 of file GhostScript.h.
References PLearn::endl().
{ togs << "\n" << x << " " << y << " moveto (" << v << ") dup stringwidth exch -2 div exch -2 div rmoveto show" << endl; }
void PLearn::GhostScript::copypage | ( | ) | [inline] |
Definition at line 106 of file GhostScript.h.
References PLearn::endl().
Referenced by flush().
void PLearn::GhostScript::displayBlack | ( | const Mat & | bm, |
real | x, | ||
real | y, | ||
real | w, | ||
real | h, | ||
bool | painton1 = true |
||
) |
if painton1 is true, then all matrix cells that are different from 0 will be painted in the current color. If painton1 is false, then all cells that are equal to 0 will be painted
Definition at line 178 of file GhostScript.cc.
References PLearn::endl(), PLearn::TMat< T >::length(), togs, PLearn::TMat< T >::width(), and writeBitmapHexString1Bit().
{ togs << "\ngsave\n" << "/pstr " << bm.width() << " string def\n" << x << " " << y << " translate\n" << w << " " << h << " scale\n" << bm.width() << " " << bm.length() << " " << (painton1 ?"true" :"false") << " " << "[" << bm.width() << " 0 0 " << bm.length() << " 0 0 ]\n"; // * Version using huge string togs << "<"; writeBitmapHexString1Bit(bm,togs,true); togs << ">\nimage\ngrestore" << endl; // * Version using procedure // togs << "{currentfile pstr readhexstring pop} imagemask\n"; // writeBitmapHexString1Bit(bm,togs,true); // togs << "\ngrestore\n"; }
values in bm indicate quantity of light between 0.0 (black) and 1.0 (white)
Definition at line 196 of file GhostScript.cc.
References PLearn::endl(), PLearn::TMat< T >::length(), togs, PLearn::TMat< T >::width(), and writeBitmapHexString8Bits().
Referenced by PLearn::displayDecisionSurface(), and PLearn::Grapher::plot_2D_classification().
{ togs << "\ngsave\n" << "/pstr " << bm.width() << " string def\n" << x << " " << y << " translate\n" << w << " " << h << " scale\n" << bm.width() << " " << bm.length() << " 8 " << "[" << bm.width() << " 0 0 " << bm.length() << " 0 0 ]\n"; // * Version using huge string togs << "<"; writeBitmapHexString8Bits(bm,togs,true); togs << ">\nimage\ngrestore" << endl; // * Version using procedure // togs << "{currentfile pstr readhexstring pop} image\n"; // writeBitmapHexString8Bits(bm,togs,true); // togs << "\ngrestore\n"; }
values in bm are those obtained using the rgb2real function (see above)
Definition at line 214 of file GhostScript.cc.
References PLearn::TMat< T >::length(), togs, PLearn::TMat< T >::width(), and writeBitmapHexString24Bits().
Referenced by PLearn::Grapher::plot_2D_classification().
{ togs << "\ngsave\n" << "/pstr " << 3*bm.width() << " string def\n" << x << " " << y << " translate\n" << w << " " << h << " scale\n" << bm.width() << " " << bm.length() << " 8 " << "[" << bm.width() << " 0 0 " << bm.length() << " 0 0 ]\n"; // * Version using huge string // togs << "<"; // writeBitmapHexString24Bits(bm,togs); // togs << ">\nfalse 3 image\ngrestore" << endl; // * Version using procedure togs << "{currentfile pstr readhexstring pop} false 3 colorimage\n"; writeBitmapHexString24Bits(bm,togs,true); togs << "\ngrestore\n"; }
Definition at line 203 of file GhostScript.h.
Referenced by PLearn::displayVarGraph(), and PLearn::OldDisplayVarGraph().
{ drawLine(x1,y1,x2,y2); drawCircle(x2,y2,2); }
Definition at line 298 of file GhostScript.cc.
References PLearn::endl(), and togs.
Referenced by PLearn::displayVarGraph(), and PLearn::OldDisplayVarGraph().
{ togs << "\n" << x << " " << y << " moveto " << x+width << " " << y << " lineto " << x+width << " " << y+height << " lineto " << x << " " << y+height << " lineto " << x << " " << y << " lineto " << "stroke" << endl; }
Definition at line 318 of file GhostScript.cc.
References PLearn::endl(), moveto(), and togs.
Referenced by PLearn::displayDecisionSurface().
Definition at line 324 of file GhostScript.cc.
References drawLine(), and M_SQRT2.
Referenced by PLearn::displayPoints().
{ if (ry<0) ry=r; if(vertical) { drawLine(x-r,y,x+r,y); drawLine(x,y-ry,x,y+ry); } else // diagonal { r /= M_SQRT2; // M_SQRT2 == sqrt(2.0) drawLine(x-r,y-ry,x+r,y+ry); drawLine(x-r,y+ry,x+r,y-ry); } }
Definition at line 200 of file GhostScript.h.
References PLearn::endl().
Referenced by drawCross().
void PLearn::GhostScript::erasepage | ( | ) | [inline] |
Definition at line 169 of file GhostScript.h.
References PLearn::endl().
Definition at line 308 of file GhostScript.cc.
References PLearn::endl(), and togs.
{ togs << "\n" << x << " " << y << " moveto " << x+width << " " << y << " lineto " << x+width << " " << y+height << " lineto " << x << " " << y+height << " lineto " << x << " " << y << " lineto " << "fill" << endl; }
Definition at line 340 of file GhostScript.cc.
References PLearn::endl(), moveto(), and togs.
Referenced by PLearn::Grapher::plot_2D_classification().
void PLearn::GhostScript::flush | ( | ) |
Definition at line 114 of file GhostScript.cc.
References copypage(), PLearn::PStream::flush(), gs_cstream, and togs.
{ togs.flush(); if(gs_cstream) copypage(); }
void PLearn::GhostScript::grestore | ( | ) | [inline] |
Definition at line 115 of file GhostScript.h.
Referenced by PLearn::displayDecisionSurface().
{ togs << "\ngrestore\n"; }
void PLearn::GhostScript::gsave | ( | ) | [inline] |
Definition at line 112 of file GhostScript.h.
Referenced by PLearn::displayDecisionSurface().
{ togs << "\ngsave\n"; }
void PLearn::GhostScript::mapping | ( | real | sourcex, |
real | sourcey, | ||
real | sourcewidth, | ||
real | sourceheight, | ||
real | destx, | ||
real | desty, | ||
real | destwidth, | ||
real | destheight | ||
) | [inline] |
transforms coordinate system such that the source rectangle will be mapped to the destination rectangle (i.e. you can then use the source coordinate system to do your drawings, and they will be rendered in the destination rectangle).
Definition at line 134 of file GhostScript.h.
Referenced by PLearn::displayDecisionSurface(), and PLearn::Grapher::plot_2D_classification().
{ scale(destwidth/sourcewidth, destheight/sourceheight); translate(-sourcex+destx*sourcewidth/destwidth,-sourcey+desty*sourceheight/destheight); }
Definition at line 124 of file GhostScript.h.
Referenced by drawCircle(), and fillCircle().
{ togs << "\n" << x << " " << y << " moveto\n"; }
void PLearn::GhostScript::multilineShow | ( | real | x, |
real | y, | ||
const string & | text, | ||
real | newlinesize, | ||
char | halign = 'l' , |
||
char | valign = 'b' |
||
) |
accepts multiple line text (lines separated by
)
Definition at line 287 of file GhostScript.cc.
References i, show(), and PLearn::split().
{ vector<string> splits = split(text, '\n'); vector<string>::size_type nsplits = splits.size(); for(unsigned int i=0; i<nsplits; i++) { show(x,y,splits[i].c_str(),halign,valign); y -= newlinesize; } }
PStream& PLearn::GhostScript::operator<< | ( | char * | str | ) | [inline] |
Definition at line 100 of file GhostScript.h.
{ return togs<<str; }
void PLearn::GhostScript::rotate | ( | real | angle | ) | [inline] |
Definition at line 127 of file GhostScript.h.
{ togs << "\n" << angle << " rotate\n"; }
void PLearn::GhostScript::run | ( | const char * | filename | ) | [inline] |
Definition at line 103 of file GhostScript.h.
References PLearn::endl().
Definition at line 121 of file GhostScript.h.
{ togs << "\n" << x << " " << y << " scale\n"; }
Definition at line 172 of file GhostScript.h.
Referenced by PLearn::displayPoints(), PLearn::Grapher::plot_2D_classification(), and setcolor().
{ togs << "\n/DeviceRGB setcolorspace " << r << " " << g << " " << b << " setcolor\n"; }
void PLearn::GhostScript::setcolor | ( | real | rgb | ) | [inline] |
takes color in rgb real as returned by rgb2real
Definition at line 176 of file GhostScript.h.
References b, g, and PLearn::real2rgb().
void PLearn::GhostScript::setcolor | ( | char * | colorname | ) |
< default is black
Definition at line 271 of file GhostScript.cc.
References setcolor().
{ if(!strcmp(colorname,"white")) setcolor(1,1,1); else if(!strcmp(colorname,"black")) setcolor(0,0,0); else if(!strcmp(colorname,"gray")) setcolor(.5,.5,.5); else if(!strcmp(colorname,"darkgray")) setcolor(.25,.25,.25); else if(!strcmp(colorname,"lightgray")) setcolor(.75,.75,.75); else if(!strcmp(colorname,"red")) setcolor(1,0,0); else if(!strcmp(colorname,"green")) setcolor(0,1,0); else if(!strcmp(colorname,"blue")) setcolor(0,0,1); else if(!strcmp(colorname,"magenta")) setcolor(1,0,1); else if(!strcmp(colorname,"yellow")) setcolor(1,1,0); else if(!strcmp(colorname,"cyan")) setcolor(0,1,1); else setcolor(0,0,0); }
sets the dash pattern: ary contains the cyclic on-off distances of the dashes, which begin after an offset_of x units from the current point
Definition at line 192 of file GhostScript.h.
References PLearn::TVec< T >::isEmpty(), and x.
Referenced by PLearn::displayDecisionSurface().
{ if(ary.isEmpty()) togs << "[ 3 3 ] " << x << " setdash\n"; else togs << "[ " << ary << " ] " << x << " setdash\n"; }
void PLearn::GhostScript::setgray | ( | real | g | ) | [inline] |
Definition at line 185 of file GhostScript.h.
Referenced by PLearn::Grapher::plot_2D_classification().
{ togs << "\n" << g << " setgray\n"; }
void PLearn::GhostScript::setlinewidth | ( | real | w | ) | [inline] |
Definition at line 188 of file GhostScript.h.
Referenced by PLearn::displayDecisionSurface().
{ togs << "\n" << w << " setlinewidth\n"; }
Definition at line 163 of file GhostScript.h.
References PLearn::endl().
void PLearn::GhostScript::show | ( | real | x, |
real | y, | ||
const char * | str, | ||
char | halign = 'l' , |
||
char | valign = 'b' |
||
) |
halign can be 'l' (left), 'c' (center) or 'r' (right) valign can be 't' (top), 'm' (middle) or 'b' (bottom)
Definition at line 232 of file GhostScript.cc.
References PLearn::endl(), PLERROR, and togs.
{ togs << "\n" << x << " " << y << " moveto "; togs << "(" << str << ") dup stringwidth "; switch(valign) { case 't': togs << " neg "; break; case 'm': togs << " -2 div "; break; case 'b': togs << " pop 0 "; break; default: PLERROR("In GhostScript::show wrong valign parameter '%c'",valign); } togs << " exch "; switch(halign) { case 'l': togs << " pop 0 "; break; case 'c': togs << " -2 div "; break; case 'r': togs << " neg "; break; default: PLERROR("In GhostScript::show wrong halign parameter '%c'",halign); } togs << " exch rmoveto show" << endl; }
void PLearn::GhostScript::show | ( | const string & | str | ) | [inline] |
Definition at line 144 of file GhostScript.h.
References PLearn::endl().
void PLearn::GhostScript::show | ( | const char * | str | ) | [inline] |
Definition at line 141 of file GhostScript.h.
References PLearn::endl().
Referenced by multilineShow().
void PLearn::GhostScript::show | ( | real | x, |
real | y, | ||
const string & | str, | ||
char | halign = 'l' , |
||
char | valign = 'b' |
||
) | [inline] |
Definition at line 151 of file GhostScript.h.
References show().
Referenced by show().
{ show(x,y,str.c_str(), halign, valign); }
void PLearn::GhostScript::showpage | ( | ) | [inline] |
Definition at line 109 of file GhostScript.h.
References PLearn::endl().
Definition at line 118 of file GhostScript.h.
{ togs << "\n" << x << " " << y << " translate\n"; }
void PLearn::GhostScript::usefont | ( | const char * | fontname = "Times-Roman" , |
real | pointsize = 12.0 |
||
) | [inline] |
Definition at line 229 of file GhostScript.h.
References PLearn::endl().
Referenced by PLearn::displayVarGraph(), and PLearn::OldDisplayVarGraph().
void PLearn::GhostScript::writeBitmapHexString1Bit | ( | const Mat & | bm, |
PStream & | out, | ||
bool | lastrowfirst = false |
||
) | [static, protected] |
Definition at line 121 of file GhostScript.cc.
References i, j, PLearn::TMat< T >::length(), PLearn::PStream::put(), PLearn::TMat< T >::rowdata(), PLearn::TMat< T >::width(), and PLearn::PStream::writeAsciiHexNum().
Referenced by displayBlack().
{ unsigned char bitmask = 128; unsigned char value = 0; for(int i=0; i<bm.length(); i++) { const real* bm_i = lastrowfirst ?bm.rowdata(bm.length()-1-i) :bm.rowdata(i); for(int j=0; j<bm.width(); j++) { if(bm_i[j]>0) value |= bitmask; bitmask = bitmask>>1; if(bitmask==0) { out.writeAsciiHexNum((unsigned char)value); out.put(' '); bitmask = 128; value = 0; } } if(bitmask!=128) { out.writeAsciiHexNum((unsigned char)value); bitmask = 128; value = 0; } } }
void PLearn::GhostScript::writeBitmapHexString24Bits | ( | const Mat & | bm, |
PStream & | out, | ||
bool | lastrowfirst = false |
||
) | [static, protected] |
Definition at line 161 of file GhostScript.cc.
References b, g, i, j, PLearn::TMat< T >::length(), PLearn::real2rgb(), PLearn::TMat< T >::rowdata(), PLearn::TMat< T >::width(), and PLearn::PStream::writeAsciiHexNum().
Referenced by displayRGB().
{ for(int i=0; i<bm.length(); i++) { const real* bm_i = lastrowfirst ?bm.rowdata(bm.length()-1-i) :bm.rowdata(i); for( int j=0; j<bm.width(); j++) { real r,g,b; // values between 0 and 255 real2rgb(bm_i[j],r,g,b); out.writeAsciiHexNum((unsigned char)(r*255.99)); out.writeAsciiHexNum((unsigned char)(g*255.99)); out.writeAsciiHexNum((unsigned char)(b*255.99)); } out << "\n"; } }
void PLearn::GhostScript::writeBitmapHexString8Bits | ( | const Mat & | bm, |
PStream & | out, | ||
bool | lastrowfirst = false |
||
) | [static, protected] |
Definition at line 150 of file GhostScript.cc.
References i, j, PLearn::TMat< T >::length(), PLearn::TMat< T >::rowdata(), PLearn::TMat< T >::width(), and PLearn::PStream::writeAsciiHexNum().
Referenced by displayGray().
{ for(int i=0; i<bm.length(); i++) { const real* bm_i = lastrowfirst ?bm.rowdata(bm.length()-1-i) :bm.rowdata(i); for( int j=0; j<bm.width(); j++) out.writeAsciiHexNum((unsigned char)(bm_i[j]*255.99)); out << "\n"; } }
char PLearn::GhostScript::command_string[1000] [protected] |
Definition at line 69 of file GhostScript.h.
Referenced by GhostScript().
FILE* PLearn::GhostScript::gs_cstream [protected] |
Definition at line 67 of file GhostScript.h.
Referenced by flush(), GhostScript(), and ~GhostScript().
bool PLearn::GhostScript::isfile [protected] |
Definition at line 70 of file GhostScript.h.
Referenced by ~GhostScript().
PStream PLearn::GhostScript::togs [protected] |
Definition at line 68 of file GhostScript.h.
Referenced by displayBlack(), displayGray(), displayRGB(), drawBox(), drawCircle(), fillBox(), fillCircle(), flush(), GhostScript(), show(), and ~GhostScript().