// Copyright (C) 2010, Guy Barrand. All rights reserved. // See the file tools.license for terms. #ifndef tools_sg_plots_viewer #define tools_sg_plots_viewer // used in geant4 offscreen plotting. #include "viewer" #include "ortho" #include "plots" #include "h2plot_cp" #include "f2plot" #include "xy2plot" #include "fit2plot" #include "cloud2plot_cp" #include "zb_action" #include "../wps" #include "gl2ps_action" namespace tools { namespace sg { class plots_viewer : public viewer { TOOLS_HEADER(plots_viewer,tools::sg::plots_viewer,viewer) public: virtual void set_size(unsigned int a_width,unsigned int a_height) { parent::set_size(a_width,a_height); m_plots.adjust_size(a_width,a_height); } public: 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) :parent(a_out,a_width,a_height) ,m_plots(a_ttf) ,m_wps(a_out) { create_sg(); m_plots.cols = a_cols; m_plots.rows = a_rows; m_plots.adjust_size(width(),height()); } virtual ~plots_viewer() { //WARNING : nodes may refer m_zb_mgr,m_gl2ps_mgr (to handle gstos/texs), then we have to delete them first. m_sg.clear(); m_plots.clear_sg(); } public: plots_viewer(const plots_viewer& a_from) :parent(a_from) ,m_camera(a_from.m_camera) ,m_plots(a_from.m_plots) ,m_wps(a_from.m_out) { create_sg(); m_plots.adjust_size(width(),height()); } plots_viewer& operator=(const plots_viewer& a_from){ parent::operator=(a_from); m_camera = a_from.m_camera; m_plots = a_from.m_plots; create_sg(); m_plots.adjust_size(width(),height()); return *this; } public: #include sg::zb_manager& zb_manager() {return m_zb_mgr;} sg::gl2ps_manager& gl2ps_manager() {return m_gl2ps_mgr;} public: typedef bool (*png_writer)(std::ostream&,const std::string&, unsigned char*,unsigned int,unsigned int,unsigned int); bool write_inzb_png(png_writer a_writer,const std::string& a_file,unsigned int a_width,unsigned int a_height) { // for example : // #include // ... // viewer.write_inzb_png(toolx::png::write,"out.png"); // zb_action action(m_zb_mgr,m_out,a_width,a_height); action.clear_color_buffer(m_clear_color); action.clear_depth_buffer(); sg().render(action); unsigned int bpp = 3; uchar* buffer = new unsigned char[a_width*a_height*bpp]; if(!buffer) { m_out << "tools::sg::plots_viewer::write_inzb_png : can't alloc buffer." << std::endl; return false; } unsigned char* pos = buffer; float r,g,b; for(unsigned int row=0;row // ... // viewer.write_inzb_jpeg(toolx::jpeg::write,"out.jpeg"); // zb_action action(m_zb_mgr,m_out,a_width,a_height); action.clear_color_buffer(m_clear_color); action.clear_depth_buffer(); sg().render(action); unsigned int bpp = 3; uchar* buffer = new unsigned char[a_width*a_height*bpp]; if(!buffer) { m_out << "tools::sg::plots_viewer::write_inzb_jpeg : can't alloc buffer." << std::endl; return false; } unsigned char* pos = buffer; float r,g,b; for(unsigned int row=0;row