Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_offscreen_sg_viewer 4 #ifndef tools_offscreen_sg_viewer 5 #define tools_offscreen_sg_viewer 5 #define tools_offscreen_sg_viewer 6 6 7 #include "session" 7 #include "session" 8 8 9 #include "../sg/viewer" 9 #include "../sg/viewer" 10 #include "../sg/zb_manager" 10 #include "../sg/zb_manager" 11 #include "../sg/gl2ps_manager" 11 #include "../sg/gl2ps_manager" 12 #include "../sg/write_paper" 12 #include "../sg/write_paper" 13 13 14 namespace tools {namespace sg {class device_in 14 namespace tools {namespace sg {class device_interactor;}} 15 15 16 namespace tools { 16 namespace tools { 17 namespace offscreen { 17 namespace offscreen { 18 18 19 class sg_viewer : public sg::viewer, public of 19 class sg_viewer : public sg::viewer, public offscreen::viewer { 20 typedef sg::viewer parent; 20 typedef sg::viewer parent; 21 protected: 21 protected: 22 virtual void render() {write_paper();} 22 virtual void render() {write_paper();} 23 public: 23 public: 24 sg_viewer(session& a_session, 24 sg_viewer(session& a_session, 25 int /*a_x*/ = 0,int /*a_y*/ = 0, 25 int /*a_x*/ = 0,int /*a_y*/ = 0, 26 unsigned int a_width = 500,unsigne 26 unsigned int a_width = 500,unsigned int a_height = 500, 27 const std::string& /*a_win_title*/ 27 const std::string& /*a_win_title*/ = "") 28 :parent(a_session.out(),a_width,a_height) 28 :parent(a_session.out(),a_width,a_height) 29 ,m_session(a_session) 29 ,m_session(a_session) 30 ,m_file_format("zb_ps") 30 ,m_file_format("zb_ps") 31 ,m_file_name("out_zb.ps") 31 ,m_file_name("out_zb.ps") 32 ,m_png_writer(0) 32 ,m_png_writer(0) 33 ,m_jpeg_writer(0) 33 ,m_jpeg_writer(0) 34 ,m_do_transparency(true) 34 ,m_do_transparency(true) 35 ,m_top_to_bottom(true) 35 ,m_top_to_bottom(true) 36 {} 36 {} 37 virtual ~sg_viewer() {} 37 virtual ~sg_viewer() {} 38 protected: 38 protected: 39 sg_viewer(const sg_viewer& a_from) 39 sg_viewer(const sg_viewer& a_from) 40 :parent(a_from) 40 :parent(a_from) 41 ,offscreen::viewer(a_from) 41 ,offscreen::viewer(a_from) 42 ,m_session(a_from.m_session) 42 ,m_session(a_from.m_session) 43 ,m_zb_mgr(a_from.m_zb_mgr) 43 ,m_zb_mgr(a_from.m_zb_mgr) 44 ,m_gl2ps_mgr(a_from.m_gl2ps_mgr) 44 ,m_gl2ps_mgr(a_from.m_gl2ps_mgr) 45 ,m_file_format(a_from.m_file_format) 45 ,m_file_format(a_from.m_file_format) 46 ,m_file_name(a_from.m_file_name) 46 ,m_file_name(a_from.m_file_name) 47 ,m_png_writer(a_from.m_png_writer) 47 ,m_png_writer(a_from.m_png_writer) 48 ,m_jpeg_writer(a_from.m_jpeg_writer) 48 ,m_jpeg_writer(a_from.m_jpeg_writer) 49 ,m_do_transparency(a_from.m_do_transparency) 49 ,m_do_transparency(a_from.m_do_transparency) 50 ,m_top_to_bottom(a_from.m_top_to_bottom) 50 ,m_top_to_bottom(a_from.m_top_to_bottom) 51 ,m_opts_1(a_from.m_opts_1) 51 ,m_opts_1(a_from.m_opts_1) 52 ,m_opts_2(a_from.m_opts_2) 52 ,m_opts_2(a_from.m_opts_2) 53 {} 53 {} 54 sg_viewer& operator=(const sg_viewer& a_from 54 sg_viewer& operator=(const sg_viewer& a_from){ 55 parent::operator=(a_from); 55 parent::operator=(a_from); 56 m_file_format = a_from.m_file_format; 56 m_file_format = a_from.m_file_format; 57 m_file_name = a_from.m_file_name; 57 m_file_name = a_from.m_file_name; 58 m_png_writer = a_from.m_png_writer; 58 m_png_writer = a_from.m_png_writer; 59 m_jpeg_writer = a_from.m_jpeg_writer; 59 m_jpeg_writer = a_from.m_jpeg_writer; 60 m_do_transparency = a_from.m_do_transparen 60 m_do_transparency = a_from.m_do_transparency; 61 m_top_to_bottom = a_from.m_top_to_bottom; 61 m_top_to_bottom = a_from.m_top_to_bottom; 62 m_opts_1 = a_from.m_opts_1; 62 m_opts_1 = a_from.m_opts_1; 63 m_opts_2 = a_from.m_opts_2; 63 m_opts_2 = a_from.m_opts_2; 64 return *this; 64 return *this; 65 } 65 } 66 public: 66 public: 67 bool has_window() const {return true;} 67 bool has_window() const {return true;} 68 68 69 bool show() { 69 bool show() { 70 m_session.to_render(this); 70 m_session.to_render(this); 71 return true; 71 return true; 72 } 72 } 73 73 74 void win_render() { 74 void win_render() { 75 m_session.to_render(this); 75 m_session.to_render(this); 76 } 76 } 77 77 78 void set_device_interactor(sg::device_intera 78 void set_device_interactor(sg::device_interactor*) {} 79 79 80 public: 80 public: 81 void set_file_format(const std::string& a_fi 81 void set_file_format(const std::string& a_file_format) {m_file_format = a_file_format;} 82 void set_file_name(const std::string& a_file 82 void set_file_name(const std::string& a_file_name) {m_file_name = a_file_name;} 83 const std::string& file_format() const {retu 83 const std::string& file_format() const {return m_file_format;} 84 const std::string& file_name() const {return 84 const std::string& file_name() const {return m_file_name;} 85 void set_png_writer(sg::png_writer a_png_wri 85 void set_png_writer(sg::png_writer a_png_writer) {m_png_writer = a_png_writer;} 86 void set_jpeg_writer(sg::jpeg_writer a_jpeg_ 86 void set_jpeg_writer(sg::jpeg_writer a_jpeg_writer) {m_jpeg_writer = a_jpeg_writer;} 87 void set_do_transparency(bool a_do_transpare 87 void set_do_transparency(bool a_do_transparency) {m_do_transparency = a_do_transparency;} 88 void set_top_to_bottom(bool a_top_to_bottom) 88 void set_top_to_bottom(bool a_top_to_bottom) {m_top_to_bottom = a_top_to_bottom;} 89 void set_opts_1(const std::string& a_opts) { 89 void set_opts_1(const std::string& a_opts) {m_opts_1 = a_opts;} 90 void set_opts_2(const std::string& a_opts) { 90 void set_opts_2(const std::string& a_opts) {m_opts_2 = a_opts;} 91 91 92 bool write_paper() { 92 bool write_paper() { 93 if(!m_ww) return false; 93 if(!m_ww) return false; 94 if(!m_wh) return false; 94 if(!m_wh) return false; 95 return sg::write_paper(m_out,m_gl2ps_mgr,m 95 return sg::write_paper(m_out,m_gl2ps_mgr,m_zb_mgr, 96 m_png_writer,m_jpeg 96 m_png_writer,m_jpeg_writer, 97 m_clear_color.r(), 97 m_clear_color.r(), 98 m_clear_color.g(), 98 m_clear_color.g(), 99 m_clear_color.b(), 99 m_clear_color.b(), 100 m_clear_color.a(), 100 m_clear_color.a(), 101 m_sg,m_ww,m_wh, 101 m_sg,m_ww,m_wh, 102 m_file_name,m_file_ 102 m_file_name,m_file_format, 103 m_do_transparency,m 103 m_do_transparency,m_top_to_bottom, 104 m_opts_1,m_opts_2); 104 m_opts_1,m_opts_2); 105 } 105 } 106 protected: 106 protected: 107 session& m_session; 107 session& m_session; 108 sg::zb_manager m_zb_mgr; 108 sg::zb_manager m_zb_mgr; 109 sg::gl2ps_manager m_gl2ps_mgr; 109 sg::gl2ps_manager m_gl2ps_mgr; 110 std::string m_file_format; 110 std::string m_file_format; 111 std::string m_file_name; 111 std::string m_file_name; 112 sg::png_writer m_png_writer; 112 sg::png_writer m_png_writer; 113 sg::jpeg_writer m_jpeg_writer; 113 sg::jpeg_writer m_jpeg_writer; 114 bool m_do_transparency; 114 bool m_do_transparency; 115 bool m_top_to_bottom; 115 bool m_top_to_bottom; 116 std::string m_opts_1; 116 std::string m_opts_1; 117 std::string m_opts_2; 117 std::string m_opts_2; 118 }; 118 }; 119 119 120 }} 120 }} 121 121 122 #endif 122 #endif 123 123