vul_psfile.h
Go to the documentation of this file.
1 // This is core/vul/vul_psfile.h
2 #ifndef vul_psfile_h_
3 #define vul_psfile_h_
4 //:
5 // \file
6 // \brief write out images, points, lines, circles and/or ellipses to PostScript
7 // \author Alan S. Liu
8 //
9 // \verbatim
10 // Modifications
11 // 7 Jan 2003 - Peter Vanroose - bug fix in image output: complete rewrite of
12 // print_greyscale_image() & print_color_image()
13 // \endverbatim
14 
15 #include <string>
16 #include <fstream>
17 #ifdef _MSC_VER
18 # include <vcl_msvc_warnings.h>
19 #endif
20 
21 //: Write a PostScript file
22 class vul_psfile: public std::ofstream
23 {
24  public:
25  enum paper_type {
27  A4,
28  B5,
29  A3,
39  MAX };
40 
41  vul_psfile(char const* filename, bool debug_output=false);
42  ~vul_psfile() override;
43  operator bool() { return static_cast<bool>(output_filestream); }
44 
49  //: set the horizontal scaling (in percent); no scaling is 100.
50  void set_scale_x(float sx) {scale_x = sx * .01f;}
51  //: set the vertical scaling (in percent); no scaling is 100.
52  void set_scale_y(float sy) {scale_y = sy * .01f;}
53  void set_fg_color(float r, float g, float b) {fg_r = r; fg_g = g; fg_b = b;}
54  void set_bg_color(float r, float g, float b) {bg_r = r; bg_g = g; bg_b = b;}
55  void set_line_width(float f_width) {line_width_ = f_width;}
56  float line_width() const { return line_width_; }
57 
58  //: Write 8 bit grey scale image.
59  void print_greyscale_image(const unsigned char* data, int sizex, int sizey);
60  //: Write 24 bit colour image.
61  void print_color_image(const unsigned char* data, int sizex, int sizey);
62 
63  //: Add a line between the given points to the Postscript file.
64  void line(float x1, float y1, float x2, float y2);
65  //: Add a point at the given coordinates to the Postscript file.
66  void point(float x, float y, float point_size = 0);
67  //: Add an ellipse to the Postscript file.
68  void ellipse(float x, float y, float a_axis, float b_axis, int angle = 0);
69  //: Add a circle with the given centre point and radius to the Postscript file.
70  void circle(float x, float y, float radius);
71 
72  void reset_bounding_box();
73 
74  protected:
75  void set_min_max_xy(float x, float y);
76  void set_min_max_xy(int x, int y);
77  bool set_parameters(int sizex, int sizey);
78 
79  //: PostScript file header. Automatically called by the constructor.
80  void postscript_header();
81 
82  //: Set graphic coordinate (translate and rotate to local coordinate).
83  void graphic_header();
84  //: Utility program used in point(), line(), ellipse() and circle()
85  void sobj_rgb_params(char const* str, bool filled);
86  //: the defined procedure for PostScript script use.
87  void print_graphics_prolog();
88 
89  private:
90  void compute_bounding_box();
91 
95  void done();
96 
97  std::ofstream output_filestream;
98 
99  float fg_r, fg_g, fg_b;
100  float bg_r, bg_g, bg_b;
101  float line_width_;
102  float scale_x, scale_y;
103  int ox, oy, iw, ih;
104  double iwf, ihf;
105  double psizex, psizey; /* current paper size, in inches */
106  double pos_inx, pos_iny; /* top-left offset of image, in inches */
107  int width, height; /* image width and height */
108  std::string filename; /* postscript path/filename */
113  bool doneps;
114  int min_x, min_y;
115  int max_x, max_y;
117 
118  private: /*even more*/
119 
120  std::streampos translate_pos;
121  std::streampos sobj_t_pos;
122  std::streampos header_pos;
123 
127 };
128 
129 #endif // vul_psfile_h_
float bg_b
Definition: vul_psfile.h:100
std::streampos header_pos
Definition: vul_psfile.h:122
void set_paper_layout(vul_psfile::paper_layout layout)
Definition: vul_psfile.h:46
std::streampos sobj_t_pos
Definition: vul_psfile.h:121
std::string filename
Definition: vul_psfile.h:108
float fg_r
Definition: vul_psfile.h:99
void reset_bounding_box()
Rewrite output bounding box parameters.
Definition: vul_psfile.cxx:99
void set_scale_x(float sx)
set the horizontal scaling (in percent); no scaling is 100.
Definition: vul_psfile.h:50
double pos_iny
Definition: vul_psfile.h:106
void point(float x, float y, float point_size=0)
Add a point at the given coordinates to the Postscript file.
Definition: vul_psfile.cxx:621
void circle(float x, float y, float radius)
Add a circle with the given centre point and radius to the Postscript file.
Definition: vul_psfile.cxx:661
std::streampos translate_pos
Definition: vul_psfile.h:120
void line(float x1, float y1, float x2, float y2)
Add a line between the given points to the Postscript file.
Definition: vul_psfile.cxx:605
void set_line_width(float f_width)
Definition: vul_psfile.h:55
void set_scale_y(float sy)
set the vertical scaling (in percent); no scaling is 100.
Definition: vul_psfile.h:52
double ihf
Definition: vul_psfile.h:104
bool graphics_prolog_exists
Definition: vul_psfile.h:124
float fg_b
Definition: vul_psfile.h:99
float scale_x
Definition: vul_psfile.h:102
paper_type printer_paper_type
Definition: vul_psfile.h:109
int box_height
Definition: vul_psfile.h:116
float scale_y
Definition: vul_psfile.h:102
void graphic_header()
Set graphic coordinate (translate and rotate to local coordinate).
Definition: vul_psfile.cxx:485
bool exist_image
Definition: vul_psfile.h:125
double psizey
Definition: vul_psfile.h:105
paper_orientation printer_paper_orientation
Definition: vul_psfile.h:110
void print_greyscale_image(const unsigned char *data, int sizex, int sizey)
Write 8 bit grey scale image.
Definition: vul_psfile.cxx:225
float line_width() const
Definition: vul_psfile.h:56
void sobj_rgb_params(char const *str, bool filled)
Utility program used in point(), line(), ellipse() and circle().
Definition: vul_psfile.cxx:592
void print_graphics_prolog()
the defined procedure for PostScript script use.
Definition: vul_psfile.cxx:678
void set_paper_orientation(vul_psfile::paper_orientation o)
Definition: vul_psfile.h:47
void set_reduction_factor(int rf)
Definition: vul_psfile.h:48
void set_paper_type(vul_psfile::paper_type type)
Definition: vul_psfile.h:45
void set_bg_color(float r, float g, float b)
Definition: vul_psfile.h:54
void compute_bounding_box()
Recalculate bounding box and scale x and y (if necessary).
Definition: vul_psfile.cxx:125
float fg_g
Definition: vul_psfile.h:99
void set_fg_color(float r, float g, float b)
Definition: vul_psfile.h:53
Write a PostScript file.
Definition: vul_psfile.h:22
float bg_g
Definition: vul_psfile.h:100
bool set_parameters(int sizex, int sizey)
Set ox, oy , iw, ih, iwf, ihf parameters for PostScript file use.
Definition: vul_psfile.cxx:538
void object_translate_and_scale()
Set object translate and scale.
Definition: vul_psfile.cxx:520
void reset_postscript_header()
Reset PostScript header file.
Definition: vul_psfile.cxx:573
float line_width_
Definition: vul_psfile.h:101
float bg_r
Definition: vul_psfile.h:100
double psizex
Definition: vul_psfile.h:105
void ellipse(float x, float y, float a_axis, float b_axis, int angle=0)
Add an ellipse to the Postscript file.
Definition: vul_psfile.cxx:635
vul_psfile(char const *filename, bool debug_output=false)
Default constructor.
Definition: vul_psfile.cxx:54
double pos_inx
Definition: vul_psfile.h:106
~vul_psfile() override
Destructor.
Definition: vul_psfile.cxx:88
void image_translate_and_scale()
Set Image translate and scale.
Definition: vul_psfile.cxx:500
int reduction_factor
Definition: vul_psfile.h:112
void postscript_header()
PostScript file header. Automatically called by the constructor.
Definition: vul_psfile.cxx:554
int box_width
Definition: vul_psfile.h:116
void set_min_max_xy(float x, float y)
Set Bounding Box Min and Max x, y.
Definition: vul_psfile.cxx:203
std::ofstream output_filestream
Definition: vul_psfile.h:97
paper_layout printer_paper_layout
Definition: vul_psfile.h:111
bool doneps
Definition: vul_psfile.h:113
void print_color_image(const unsigned char *data, int sizex, int sizey)
Write 24 bit colour image.
Definition: vul_psfile.cxx:323
bool exist_objs
Definition: vul_psfile.h:126
double iwf
Definition: vul_psfile.h:104