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

vul_psfile.h

Go to the documentation of this file.
00001 // This is core/vul/vul_psfile.h
00002 #ifndef vul_psfile_h_
00003 #define vul_psfile_h_
00004 //:
00005 // \file
00006 // \brief write out images, points, lines, circles and/or ellipses to PostScript
00007 // \author Alan S. Liu
00008 //
00009 // \verbatim
00010 // Modifications
00011 //  7 Jan 2003 - Peter Vanroose - bug fix in image output: complete rewrite of
00012 //                                print_greyscale_image() & print_color_image()
00013 // \endverbatim
00014 
00015 #include <vcl_string.h>
00016 #include <vcl_fstream.h>
00017 
00018 //: Write a PostScript file
00019 class vul_psfile: public vcl_ofstream
00020 {
00021  public:
00022   enum paper_type {
00023     US_NORMAL,
00024     A4,
00025     B5,
00026     A3,
00027     US_LEGAL,
00028     ELEVEN_BY_SEVENTEEN,
00029     FOUR_BY_FIVE,
00030     THIRTY_FIVE_mm};
00031   enum paper_orientation{
00032     PORTRAIT,
00033     LANDSCAPE };
00034   enum paper_layout{
00035     CENTER,
00036     MAX };
00037 
00038   vul_psfile(char const* filename, bool debug_output=false);
00039   ~vul_psfile();
00040   operator bool() { return (void*)output_filestream!=(void*)0; }
00041 
00042   void set_paper_type(vul_psfile::paper_type type){printer_paper_type = type;}
00043   void set_paper_layout(vul_psfile::paper_layout layout) {printer_paper_layout = layout;}
00044   void set_paper_orientation(vul_psfile::paper_orientation o) {printer_paper_orientation = o;}
00045   void set_reduction_factor(int rf) {reduction_factor = rf;}
00046   //: set the horizontal scaling (in percent); no scaling is 100.
00047   void set_scale_x(float sx) {scale_x = sx * .01f;}
00048   //: set the vertical scaling (in percent); no scaling is 100.
00049   void set_scale_y(float sy) {scale_y = sy * .01f;}
00050   void set_fg_color(float r, float g, float b) {fg_r = r; fg_g = g; fg_b = b;}
00051   void set_bg_color(float r, float g, float b) {bg_r = r; bg_g = g; bg_b = b;}
00052   void set_line_width(float f_width) {line_width_ = f_width;}
00053   float line_width() const { return line_width_; }
00054 
00055   //: Write 8 bit grey scale image.
00056   void print_greyscale_image(unsigned char* data, int sizex, int sizey);
00057   //: Write 24 bit colour image.
00058   void print_color_image(unsigned char* data, int sizex, int sizey);
00059 
00060   //:  Add a line between the given points to the Postscript file.
00061   void line(float x1, float y1, float x2, float y2);
00062   //: Add a point at the given coordinates to the Postscript file.
00063   void point(float x, float y, float point_size = 0);
00064   //: Add an ellipse to the Postscript file.
00065   void ellipse(float x, float y, float a_axis, float b_axis, int angle = 0);
00066   //: Add a circle with the given centre point and radius to the Postscript file.
00067   void circle(float x, float y, float radius);
00068 
00069  protected:
00070   void set_min_max_xy(float x, float y);
00071   void set_min_max_xy(int x, int y);
00072   bool set_parameters(int sizex, int sizey);
00073 
00074   //: PostScript file header.  Automatically called by the constructor.
00075   void postscript_header();
00076 
00077   //: Set graphic coordinate (translate and rotate to local coordinate).
00078   void graphic_header();
00079   //: Utility program used in point(), line(), ellipse() and circle()
00080   void sobj_rgb_params(char const* str, bool filled);
00081   //: the defined procedure for PostScript script use.
00082   void print_graphics_prolog();
00083 
00084  private:
00085   void compute_bounding_box();
00086   void reset_bounding_box();
00087   void reset_postscript_header();
00088   void image_translate_and_scale();
00089   void object_translate_and_scale();
00090   void done();
00091 
00092   vcl_ofstream output_filestream;
00093 
00094   float fg_r, fg_g, fg_b;
00095   float bg_r, bg_g, bg_b;
00096   float line_width_;
00097   float scale_x, scale_y;
00098   int ox, oy, iw, ih;
00099   double iwf, ihf;
00100   double psizex, psizey;   /* current paper size, in inches */
00101   double pos_inx, pos_iny; /* top-left offset of image, in inches */
00102   int width, height;       /* image width and height */
00103   vcl_string filename;     /* postscript path/filename */
00104   paper_type printer_paper_type;
00105   paper_orientation printer_paper_orientation;
00106   paper_layout printer_paper_layout;
00107   int reduction_factor;
00108   bool doneps;
00109   int min_x, min_y;
00110   int max_x, max_y;
00111   int box_width, box_height;
00112 
00113  private: /*even more*/
00114 
00115   vcl_streampos translate_pos;
00116   vcl_streampos sobj_t_pos;
00117   vcl_streampos header_pos;
00118 
00119   bool graphics_prolog_exists;
00120   bool exist_image;
00121   bool exist_objs;
00122 };
00123 
00124 #endif // vul_psfile_h_

Generated on Thu Jan 10 14:41:00 2008 for core/vul by  doxygen 1.4.4