Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

GhostScript.h

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // PLearn (A C++ Machine Learning Library) 00004 // Copyright (C) 1998 Pascal Vincent 00005 // Copyright (C) 1999-2002 Pascal Vincent, Yoshua Bengio and University of Montreal 00006 // 00007 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 00037 00038 00039 /* ******************************************************* 00040 * $Id: GhostScript.h,v 1.10 2004/07/21 16:30:51 chrish42 Exp $ 00041 * AUTHORS: Pascal Vincent & Yoshua Bengio 00042 * This file is part of the PLearn library. 00043 ******************************************************* */ 00044 00045 00048 #ifndef GHOSTSCRIPT_INC 00049 #define GHOSTSCRIPT_INC 00050 00051 //#include "general.h" 00052 //#include <cstdio> 00053 //#include <fstream> 00054 //#include "pl_io.h" 00055 #include <plearn/math/Mat.h> 00056 00057 namespace PLearn { 00058 using namespace std; 00059 00064 real rgb2real(real r, real g, real b); 00065 void real2rgb(real colorval, real& r, real& g, real& b); 00066 00067 class GhostScript 00068 { 00069 protected: 00070 FILE* gs_cstream; 00071 PStream togs; 00072 char command_string[1000]; 00073 bool isfile; 00074 static void writeBitmapHexString1Bit(const Mat& bm, PStream& out, bool lastrowfirst=false); 00075 static void writeBitmapHexString8Bits(const Mat& bm, PStream& out, bool lastrowfirst=false); 00076 static void writeBitmapHexString24Bits(const Mat& bm, PStream& out, bool lastrowfirst=false); 00077 00078 // norman: win32 compiler knows ios::char_type! :) 00079 #if __GNUC__ > 2 && !defined(WIN32) 00080 typedef ios::char_type char_type; 00081 #else 00082 typedef ios::char_type char_type; 00083 #endif 00084 // old: 00085 //#if __GNUC__ < 3 00086 // typedef _IO_wchar_t char_type; 00087 //#else 00088 // typedef ios::char_type char_type; 00089 //#endif 00090 00091 public: 00092 00094 GhostScript(int width=200, int height=200); 00095 00097 GhostScript(const string& filename, real x1, real y1, real x2, real y2); 00098 00099 ~GhostScript(); 00100 00101 void flush(); 00102 00103 PStream& operator<<(char* str) 00104 { return togs<<str; } 00105 00106 void run(const char* filename) 00107 { togs << "\n(" << filename << ") run " << endl; } 00108 00109 void copypage() 00110 { togs << "\ncopypage" << endl; } 00111 00112 void showpage() 00113 { togs << "\nshowpage" << endl; } 00114 00115 void gsave() 00116 { togs << "\ngsave\n"; } 00117 00118 void grestore() 00119 { togs << "\ngrestore\n"; } 00120 00121 void translate(real x, real y) 00122 { togs << "\n" << x << " " << y << " translate\n"; } 00123 00124 void scale(real x, real y) 00125 { togs << "\n" << x << " " << y << " scale\n"; } 00126 00127 void moveto(real x, real y) 00128 { togs << "\n" << x << " " << y << " moveto\n"; } 00129 00130 void rotate(real angle) 00131 { togs << "\n" << angle << " rotate\n"; } 00132 00137 void mapping(real sourcex, real sourcey, real sourcewidth, real sourceheight, 00138 real destx, real desty, real destwidth, real destheight) 00139 { 00140 scale(destwidth/sourcewidth, destheight/sourceheight); 00141 translate(-sourcex+destx*sourcewidth/destwidth,-sourcey+desty*sourceheight/destheight); 00142 } 00143 00144 void show(const char* str) 00145 { togs << "(" << str << ") show" << endl; } 00146 00149 void show(real x, real y, const char* str, char halign='l', char valign='b'); 00150 00151 void centerShow(real x, real y, const char* str) 00152 { show(x,y,str,'c','m'); } 00153 00155 void multilineShow(real x, real y, const string& text, real newlinesize, char halign='l', char valign='b'); 00156 00157 void show(real x, real y, Vec v) 00158 { togs << "\n" << x << " " << y << " moveto (" << v << ") show" << endl; } 00159 00160 void centerShow(real x, real y, Vec v) 00161 { togs << "\n" << x << " " << y << " moveto (" << v << ") dup stringwidth exch -2 div exch -2 div rmoveto show" << endl; } 00162 00163 void erasepage() 00164 { togs << "\nerasepage" << endl; } 00165 00166 void setcolor(real r, real g, real b) 00167 { togs << "\n/DeviceRGB setcolorspace " << r << " " << g << " " << b << " setcolor\n"; } 00168 00170 void setcolor(real rgb) 00171 { 00172 real r,g,b; 00173 real2rgb(rgb,r,g,b); 00174 setcolor(r,g,b); 00175 } 00176 00177 void setcolor(char* colorname); 00178 00179 void setgray(real g) 00180 { togs << "\n" << g << " setgray\n"; } 00181 00182 void setlinewidth(real w) 00183 { togs << "\n" << w << " setlinewidth\n"; } 00184 00186 void setdash(Vec ary, real x=0) 00187 { 00188 if(ary.isEmpty()) 00189 togs << "[ 3 3 ] " << x << " setdash\n"; 00190 else 00191 togs << "[ " << ary << " ] " << x << " setdash\n"; 00192 } 00193 00194 void drawLine(real x1, real y1, real x2, real y2) 00195 { togs << "\n" << x1 << " " << y1 << " moveto " << x2 << " " << y2 << " lineto stroke" << endl; } 00196 00197 void drawArrow(real x1, real y1, real x2, real y2) 00198 { 00199 drawLine(x1,y1,x2,y2); 00200 drawCircle(x2,y2,2); 00201 } 00202 00203 void drawBox(real x, real y, real width, real height); 00204 void fillBox(real x, real y, real width, real height); 00205 00206 void drawCross(real x, real y, real r, bool vertical=false, real ry=-1); // default ry=r 00207 00208 void drawCircle(real x, real y, real r); 00209 void fillCircle(real x, real y, real r); 00210 00215 void displayBlack(const Mat& bm, real x, real y, real w, real h, bool painton1=true); 00216 00218 void displayGray(const Mat& bm, real x, real y, real w, real h); 00219 00221 void displayRGB(const Mat& bm, real x, real y, real w, real h); 00222 00223 void usefont(const char* fontname="Times-Roman", real pointsize=12.0) 00224 { togs << "\n/" << fontname << " findfont " << pointsize << " scalefont setfont" << endl; } 00225 }; 00226 00227 } // end of namespace PLearn 00228 00229 #endif 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239

Generated on Tue Aug 17 15:54:29 2004 for PLearn by doxygen 1.3.7