g4tools  5.4.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tools::sg::plots_viewer Class Reference
Inheritance diagram for tools::sg::plots_viewer:
Inheritance graph
[legend]
Collaboration diagram for tools::sg::plots_viewer:
Collaboration graph
[legend]

Public Types

typedef bool(* png_writer) (std::ostream &, const std::string &, unsigned char *, unsigned int, unsigned int, unsigned int)
 
typedef bool(* jpeg_writer) (std::ostream &, const std::string &, unsigned char *, unsigned int, unsigned int, unsigned int, int)
 

Public Member Functions

virtual void set_size (unsigned int a_width, unsigned int a_height)
 
 plots_viewer (std::ostream &a_out, const base_freetype &a_ttf, unsigned int a_cols=1, unsigned int a_rows=1, unsigned int a_width=500, unsigned int a_height=500)
 
virtual ~plots_viewer ()
 
 plots_viewer (const plots_viewer &a_from)
 
plots_vieweroperator= (const plots_viewer &a_from)
 
sg::zb_managerzb_manager ()
 
sg::gl2ps_managergl2ps_manager ()
 
bool write_inzb_png (png_writer a_writer, const std::string &a_file, unsigned int a_width, unsigned int a_height)
 
bool write_inzb_png (png_writer a_writer, const std::string &a_file)
 
bool write_inzb_jpeg (jpeg_writer a_writer, const std::string &a_file, unsigned int a_width, unsigned int a_height, int a_quality=100)
 
bool write_inzb_jpeg (jpeg_writer a_writer, const std::string &a_file, int a_quality=100)
 
bool write_inzb_ps (const std::string &a_file, unsigned int a_width, unsigned int a_height, bool a_anonymous=false)
 
bool write_inzb_ps (const std::string &a_file, bool a_anonymous=false)
 
bool open_inzb_ps_file (const std::string &a_file, bool a_anonymous=false)
 
bool write_inzb_ps_page (unsigned int a_width, unsigned int a_height)
 
bool write_inzb_ps_page ()
 
bool close_inzb_ps_file ()
 
bool write_gl2ps (const std::string &a_file, int a_gl2ps_format, unsigned int a_width, unsigned int a_height)
 
bool write_gl2ps (const std::string &a_file, int a_gl2ps_format)
 
- Public Member Functions inherited from tools::sg::viewer
virtual void * cast (const std::string &a_class) const
 
virtual bool set_cursor_shape (cursor_shape)
 
 viewer (std::ostream &a_out, unsigned int a_width, unsigned int a_height)
 
virtual ~viewer ()
 
 viewer (const viewer &a_from)
 
vieweroperator= (const viewer &a_from)
 
bool set_default_cursor_shape ()
 
groupsg ()
 
const groupsg () const
 
unsigned int width () const
 
unsigned int height () const
 
bool screen2aspect (int a_x, int a_y, float &a_wx, float &a_wy) const
 
void set_clear_color (float a_r, float a_g, float a_b, float a_a=1)
 
void set_clear_color (const colorf &a_color)
 
void get_clear_color (float &a_r, float &a_g, float &a_b, float &a_a)
 
const colorfbackground () const
 
std::ostream & out () const
 
const std::string & out_dir () const
 
void set_produce_out_jpeg (bool a_value)
 
bool produce_out_jpeg () const
 
void set_produce_out_png (bool a_value)
 
bool produce_out_png () const
 
void set_produce_out_file (const std::string &a_file)
 
const std::string & produce_out_file () const
 
void set_produce_out_bpp (unsigned int a_bpp)
 
unsigned int produce_out_bpp () const
 

Protected Member Functions

void create_sg ()
 

Protected Attributes

sg::zb_manager m_zb_mgr
 
sg::gl2ps_manager m_gl2ps_mgr
 
ortho m_camera
 
sg::plots m_plots
 
wps m_wps
 
- Protected Attributes inherited from tools::sg::viewer
std::ostream & m_out
 
colorf m_clear_color
 
unsigned int m_ww
 
unsigned int m_wh
 
group m_sg
 
std::string m_out_dir
 
bool m_use_gsto
 
bool m_produce_out_jpeg
 
bool m_produce_out_png
 
std::string m_produce_out_file
 
unsigned int m_produce_out_bpp
 

Detailed Description

Definition at line 28 of file plots_viewer.

Member Typedef Documentation

◆ jpeg_writer

typedef bool(* tools::sg::plots_viewer::jpeg_writer) (std::ostream &, const std::string &, unsigned char *, unsigned int, unsigned int, unsigned int, int)

Definition at line 121 of file plots_viewer.

◆ png_writer

typedef bool(* tools::sg::plots_viewer::png_writer) (std::ostream &, const std::string &, unsigned char *, unsigned int, unsigned int, unsigned int)

Definition at line 78 of file plots_viewer.

Constructor & Destructor Documentation

◆ plots_viewer() [1/2]

tools::sg::plots_viewer::plots_viewer ( std::ostream &  a_out,
const base_freetype a_ttf,
unsigned int  a_cols = 1,
unsigned int  a_rows = 1,
unsigned int  a_width = 500,
unsigned int  a_height = 500 
)
inline

Definition at line 36 of file plots_viewer.

39  :parent(a_out,a_width,a_height)
40  ,m_plots(a_ttf)
41  ,m_wps(a_out)
42  {
43  create_sg();
44  m_plots.cols = a_cols;
45  m_plots.rows = a_rows;
47  }

◆ ~plots_viewer()

virtual tools::sg::plots_viewer::~plots_viewer ( )
inlinevirtual

Definition at line 48 of file plots_viewer.

48  {
49  //WARNING : nodes may refer m_zb_mgr,m_gl2ps_mgr (to handle gstos/texs), then we have to delete them first.
50  m_sg.clear();
51  m_plots.clear_sg();
52  }

◆ plots_viewer() [2/2]

tools::sg::plots_viewer::plots_viewer ( const plots_viewer a_from)
inline

Definition at line 54 of file plots_viewer.

55  :parent(a_from)
56  ,m_camera(a_from.m_camera)
57  ,m_plots(a_from.m_plots)
58  ,m_wps(a_from.m_out)
59  {
60  create_sg();
62  }

Member Function Documentation

◆ close_inzb_ps_file()

bool tools::sg::plots_viewer::close_inzb_ps_file ( )
inline

Definition at line 208 of file plots_viewer.

208 {return m_wps.close_file();}

◆ create_sg()

void tools::sg::plots_viewer::create_sg ( )
inlineprotected

Definition at line 221 of file plots_viewer.

221  {
222  m_sg.clear();
223 
224  m_camera.height = 1;
225  float z = 10*1;
226  m_camera.znear = 0.1f*z;
227  m_camera.zfar = 10*z; //100*z induces problems with lego rendering.
228  m_camera.position = vec3f(0,0,z);
229  m_camera.orientation = rotf(vec3f(0,0,1),0);
230  m_camera.focal = z;
231  m_sg.add(new noderef(m_camera));
232 
233  m_sg.add(new noderef(m_plots));
234  }

◆ gl2ps_manager()

sg::gl2ps_manager& tools::sg::plots_viewer::gl2ps_manager ( )
inline

Definition at line 75 of file plots_viewer.

75 {return m_gl2ps_mgr;}

◆ open_inzb_ps_file()

bool tools::sg::plots_viewer::open_inzb_ps_file ( const std::string &  a_file,
bool  a_anonymous = false 
)
inline

Definition at line 188 of file plots_viewer.

188  {
189  if(!m_wps.open_file(a_file,a_anonymous)) {
190  m_out << "tools::plots_viewer::open_inzb_ps_file : can't open " << a_file << "." << std::endl;
191  return false;
192  }
193  return true;
194  }

◆ operator=()

plots_viewer& tools::sg::plots_viewer::operator= ( const plots_viewer a_from)
inline

Definition at line 63 of file plots_viewer.

63  {
64  parent::operator=(a_from);
65  m_camera = a_from.m_camera;
66  m_plots = a_from.m_plots;
67  create_sg();
69  return *this;
70  }

◆ set_size()

virtual void tools::sg::plots_viewer::set_size ( unsigned int  a_width,
unsigned int  a_height 
)
inlinevirtual

Reimplemented from tools::sg::viewer.

Definition at line 31 of file plots_viewer.

31  {
32  parent::set_size(a_width,a_height);
33  m_plots.adjust_size(a_width,a_height);
34  }

◆ write_gl2ps() [1/2]

bool tools::sg::plots_viewer::write_gl2ps ( const std::string &  a_file,
int  a_gl2ps_format 
)
inline

Definition at line 218 of file plots_viewer.

218 {return write_gl2ps(a_file,a_gl2ps_format,width(),height());}

◆ write_gl2ps() [2/2]

bool tools::sg::plots_viewer::write_gl2ps ( const std::string &  a_file,
int  a_gl2ps_format,
unsigned int  a_width,
unsigned int  a_height 
)
inline

Definition at line 210 of file plots_viewer.

210  {
211  gl2ps_action action(m_gl2ps_mgr,m_out,a_width,a_height);
212  action.clear_color(m_clear_color.r(),m_clear_color.g(),m_clear_color.b(),m_clear_color.a());
213  if(!action.open(a_file,a_gl2ps_format)) return false;
214  sg().render(action);
215  action.close();
216  return true;
217  }

◆ write_inzb_jpeg() [1/2]

bool tools::sg::plots_viewer::write_inzb_jpeg ( jpeg_writer  a_writer,
const std::string &  a_file,
int  a_quality = 100 
)
inline

Definition at line 161 of file plots_viewer.

161  {
162  return write_inzb_jpeg(a_writer,a_file,width(),height(),a_quality);
163  }

◆ write_inzb_jpeg() [2/2]

bool tools::sg::plots_viewer::write_inzb_jpeg ( jpeg_writer  a_writer,
const std::string &  a_file,
unsigned int  a_width,
unsigned int  a_height,
int  a_quality = 100 
)
inline

Definition at line 124 of file plots_viewer.

124  {
125  // for example :
126  // #include <tools/jpeg>
127  // ...
128  // viewer.write_inzb_jpeg(tools::jpeg::write,"out.jpeg");
129  //
130  zb_action action(m_zb_mgr,m_out,a_width,a_height);
131  action.zbuffer().clear_color_buffer(0);
132  action.add_color(m_clear_color.r(),m_clear_color.g(),m_clear_color.b(),m_clear_color.a());
133  action.zbuffer().clear_depth_buffer();
134  sg().render(action);
135 
136  unsigned int bpp = 3;
137  uchar* buffer = new unsigned char[a_width*a_height*bpp];
138  if(!buffer) {
139  m_out << "tools::sg::plots_viewer::write_inzb_jpeg : can't alloc buffer." << std::endl;
140  return false;
141  }
142  unsigned char* pos = buffer;
143  zb_action::VCol r,g,b;
144  for(unsigned int row=0;row<a_height;row++) {
145  for(unsigned int col=0;col<a_width;col++) {
146  zb_action::get_rgb(&action,col,a_height-row-1,r,g,b);
147  *pos = (uchar)(255.0F*r);pos++;
148  *pos = (uchar)(255.0F*g);pos++;
149  *pos = (uchar)(255.0F*b);pos++;
150  }
151  }
152 
153  bool status = (*a_writer)(m_out,a_file,buffer,a_width,a_height,bpp,a_quality);
154  if(!status) {
155  m_out << "tools::sg::plots_viewer::write_inzb_jpeg : can't write " << a_file << "." << std::endl;
156  }
157  delete [] buffer;
158  return status;
159  }

◆ write_inzb_png() [1/2]

bool tools::sg::plots_viewer::write_inzb_png ( png_writer  a_writer,
const std::string &  a_file 
)
inline

Definition at line 117 of file plots_viewer.

117  {
118  return write_inzb_png(a_writer,a_file,width(),height());
119  }

◆ write_inzb_png() [2/2]

bool tools::sg::plots_viewer::write_inzb_png ( png_writer  a_writer,
const std::string &  a_file,
unsigned int  a_width,
unsigned int  a_height 
)
inline

Definition at line 81 of file plots_viewer.

81  {
82  // for example :
83  // #include <tools/png>
84  // ...
85  // viewer.write_inzb_png(tools::png::write,"out.png");
86  //
87  zb_action action(m_zb_mgr,m_out,a_width,a_height);
88  action.zbuffer().clear_color_buffer(0);
89  action.add_color(m_clear_color.r(),m_clear_color.g(),m_clear_color.b(),m_clear_color.a());
90  action.zbuffer().clear_depth_buffer();
91  sg().render(action);
92 
93  unsigned int bpp = 3;
94  uchar* buffer = new unsigned char[a_width*a_height*bpp];
95  if(!buffer) {
96  m_out << "tools::sg::plots_viewer::write_inzb_png : can't alloc buffer." << std::endl;
97  return false;
98  }
99  unsigned char* pos = buffer;
100  zb_action::VCol r,g,b;
101  for(unsigned int row=0;row<a_height;row++) {
102  for(unsigned int col=0;col<a_width;col++) {
103  zb_action::get_rgb(&action,col,a_height-row-1,r,g,b);
104  *pos = (uchar)(255.0F*r);pos++;
105  *pos = (uchar)(255.0F*g);pos++;
106  *pos = (uchar)(255.0F*b);pos++;
107  }
108  }
109 
110  bool status = (*a_writer)(m_out,a_file,buffer,a_width,a_height,bpp);
111  if(!status) {
112  m_out << "tools::sg::plots_viewer::write_inzb_png : can't write " << a_file << "." << std::endl;
113  }
114  delete [] buffer;
115  return status;
116  }

◆ write_inzb_ps() [1/2]

bool tools::sg::plots_viewer::write_inzb_ps ( const std::string &  a_file,
bool  a_anonymous = false 
)
inline

Definition at line 184 of file plots_viewer.

184  {
185  return write_inzb_ps(a_file,width(),height(),a_anonymous);
186  }

◆ write_inzb_ps() [2/2]

bool tools::sg::plots_viewer::write_inzb_ps ( const std::string &  a_file,
unsigned int  a_width,
unsigned int  a_height,
bool  a_anonymous = false 
)
inline

Definition at line 165 of file plots_viewer.

165  {
166  zb_action action(m_zb_mgr,m_out,a_width,a_height);
167  action.zbuffer().clear_color_buffer(0);
168  action.add_color(m_clear_color.r(),m_clear_color.g(),m_clear_color.b(),m_clear_color.a());
169  action.zbuffer().clear_depth_buffer();
170  sg().render(action);
171  wps wps(m_out);
172  if(!wps.open_file(a_file,a_anonymous)) {
173  m_out << "tools::viewplot::write_inzb_ps : can't open " << a_file << "." << std::endl;
174  return false;
175  }
176  wps.PS_BEGIN_PAGE();
177  wps.PS_PAGE_SCALE(float(a_width),float(a_height));
178  wps.PS_IMAGE(a_width,a_height,wps::rgb_4,sg::zb_action::get_rgb,&action);
179  wps.PS_END_PAGE();
180  wps.close_file();
181  return true;
182  }

◆ write_inzb_ps_page() [1/2]

bool tools::sg::plots_viewer::write_inzb_ps_page ( )
inline

Definition at line 207 of file plots_viewer.

207 {return write_inzb_ps_page(width(),height());}

◆ write_inzb_ps_page() [2/2]

bool tools::sg::plots_viewer::write_inzb_ps_page ( unsigned int  a_width,
unsigned int  a_height 
)
inline

Definition at line 195 of file plots_viewer.

195  {
196  sg::zb_action action(m_zb_mgr,m_out,a_width,a_height);
197  action.zbuffer().clear_color_buffer(0);
198  action.add_color(m_clear_color.r(),m_clear_color.g(),m_clear_color.b(),m_clear_color.a());
199  action.zbuffer().clear_depth_buffer();
200  sg().render(action);
202  m_wps.PS_PAGE_SCALE(float(a_width),float(a_height));
203  m_wps.PS_IMAGE(a_width,a_height,wps::rgb_4,sg::zb_action::get_rgb,&action);
204  m_wps.PS_END_PAGE();
205  return true;
206  }

◆ zb_manager()

sg::zb_manager& tools::sg::plots_viewer::zb_manager ( )
inline

Definition at line 74 of file plots_viewer.

74 {return m_zb_mgr;}

Member Data Documentation

◆ m_camera

ortho tools::sg::plots_viewer::m_camera
protected

Definition at line 239 of file plots_viewer.

◆ m_gl2ps_mgr

sg::gl2ps_manager tools::sg::plots_viewer::m_gl2ps_mgr
protected

Definition at line 238 of file plots_viewer.

◆ m_plots

sg::plots tools::sg::plots_viewer::m_plots
protected

Definition at line 240 of file plots_viewer.

◆ m_wps

wps tools::sg::plots_viewer::m_wps
protected

Definition at line 241 of file plots_viewer.

◆ m_zb_mgr

sg::zb_manager tools::sg::plots_viewer::m_zb_mgr
protected

Definition at line 237 of file plots_viewer.


The documentation for this class was generated from the following file:
tools::sg::plots_viewer::write_gl2ps
bool write_gl2ps(const std::string &a_file, int a_gl2ps_format, unsigned int a_width, unsigned int a_height)
Definition: plots_viewer:210
tools::sg::zb_action::get_rgb
static bool get_rgb(void *a_tag, unsigned int a_col, unsigned int a_row, VCol &a_r, VCol &a_g, VCol &a_b)
Definition: zb_action:296
tools::sg::plots::adjust_size
void adjust_size(unsigned int a_ww, unsigned int a_wh)
Definition: plots:271
tools::sg::base_camera::orientation
sf_rotf orientation
Definition: base_camera:33
tools::sg::plots_viewer::write_inzb_jpeg
bool write_inzb_jpeg(jpeg_writer a_writer, const std::string &a_file, unsigned int a_width, unsigned int a_height, int a_quality=100)
Definition: plots_viewer:124
tools::wps::close_file
bool close_file()
Definition: wps:125
tools::sg::base_camera::position
sf_vec3f position
Definition: base_camera:29
tools::sg::plots_viewer::m_plots
sg::plots m_plots
Definition: plots_viewer:240
tools::sg::ortho::height
sf< float > height
Definition: ortho:24
tools::sg::plots_viewer::write_inzb_png
bool write_inzb_png(png_writer a_writer, const std::string &a_file, unsigned int a_width, unsigned int a_height)
Definition: plots_viewer:81
tools::wps::PS_PAGE_SCALE
void PS_PAGE_SCALE(float a_width, float a_height, bool a_portrait=true)
Definition: wps:137
tools::wps::PS_END_PAGE
void PS_END_PAGE()
Definition: wps:185
tools::sg::plots_viewer::write_inzb_ps
bool write_inzb_ps(const std::string &a_file, unsigned int a_width, unsigned int a_height, bool a_anonymous=false)
Definition: plots_viewer:165
tools::colorf::g
float g() const
Definition: colorf:33
tools::wps::open_file
bool open_file(const std::string &a_name, bool a_anonymous=false)
Definition: wps:59
tools::sg::base_camera::zfar
sf< float > zfar
Definition: base_camera:28
tools::sg::plots_viewer::m_gl2ps_mgr
sg::gl2ps_manager m_gl2ps_mgr
Definition: plots_viewer:238
tools::sg::zb_action::VCol
float VCol
Definition: zb_action:294
tools::sg::group::render
virtual void render(render_action &a_action)
Definition: group:24
tools::uchar
unsigned char uchar
Definition: typedefs:99
tools::sg::plots_viewer::m_zb_mgr
sg::zb_manager m_zb_mgr
Definition: plots_viewer:237
tools::wps::PS_BEGIN_PAGE
void PS_BEGIN_PAGE()
Definition: wps:179
tools::sg::viewer::m_sg
group m_sg
Definition: viewer:173
tools::sg::group::add
void add(node *a_node)
Definition: group:96
tools::sg::plots_viewer::create_sg
void create_sg()
Definition: plots_viewer:221
tools::wps::rgb_4
@ rgb_4
Definition: wps:193
tools::sg::viewer::sg
group & sg()
Definition: viewer:94
tools::colorf::a
float a() const
Definition: colorf:35
tools::wps::PS_IMAGE
void PS_IMAGE(Uint a_width, Uint a_height, rgb_nbit a_nbit, rgb_func a_proc, void *a_tag)
Definition: wps:197
tools::sg::base_camera::focal
sf< float > focal
Definition: base_camera:39
tools::sg::plots_viewer::m_wps
wps m_wps
Definition: plots_viewer:241
tools::sg::viewer::m_out
std::ostream & m_out
Definition: viewer:169
tools::sg::plots_viewer::write_inzb_ps_page
bool write_inzb_ps_page()
Definition: plots_viewer:207
tools::sg::plots_viewer::m_camera
ortho m_camera
Definition: plots_viewer:239
tools::sg::group::clear
void clear()
Definition: group:235
tools::colorf::r
float r() const
Definition: colorf:32
tools::sg::viewer::height
unsigned int height() const
Definition: viewer:98
tools::sg::viewer::width
unsigned int width() const
Definition: viewer:97
tools::sg::base_camera::znear
sf< float > znear
Definition: base_camera:27
tools::sg::plots::rows
sf< unsigned int > rows
Definition: plots:22
tools::sg::plots::clear_sg
void clear_sg()
Definition: plots:919
tools::sg::viewer::m_clear_color
colorf m_clear_color
Definition: viewer:170
tools::sg::plots::cols
sf< unsigned int > cols
Definition: plots:21
tools::colorf::b
float b() const
Definition: colorf:34