Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_zb_viewer 5 #define tools_sg_zb_viewer 6 7 #include "zb_action" 8 #include "viewer" 9 10 namespace tools { 11 namespace sg { 12 13 class zb_viewer : public viewer { 14 TOOLS_HEADER(zb_viewer,tools::sg::zb_viewer,viewer) 15 public: 16 zb_viewer(std::ostream& a_out,unsigned int a_width,unsigned int a_height) 17 :parent(a_out,a_width,a_height) 18 ,m_mgr_gra() 19 ,m_out_buffer_what(get_rgbs) 20 {} 21 virtual ~zb_viewer(){ 22 //WARNING : nodes may refer m_mgr_gra (to handle gstos/texs), then 23 // we have to delete them first. 24 m_sg.clear(); 25 } 26 public: 27 zb_viewer(const zb_viewer& a_from) 28 :parent(a_from) 29 ,m_mgr_gra(a_from.m_mgr_gra) 30 ,m_out_buffer_what(get_rgbs) 31 {} 32 zb_viewer& operator=(const zb_viewer& a_from){ 33 parent::operator=(a_from); 34 m_mgr_gra = a_from.m_mgr_gra; 35 m_out_buffer_what = get_rgbs; 36 m_out_buffer.clear(); 37 return *this; 38 } 39 public: 40 enum get_what { 41 get_rgbs = 0, 42 get_rgbas, 43 get_bgras 44 }; 45 bool render(get_what a_what,bool a_top_to_bottom) { 46 m_out_buffer.clear(); 47 if(!m_ww) return false; 48 if(!m_wh) return false; 49 50 zb_action action(m_mgr_gra,m_out,m_ww,m_wh); 51 action.clear_color_buffer(m_clear_color.r(),m_clear_color.g(),m_clear_color.b(),m_clear_color.a()); 52 action.clear_depth_buffer(); 53 action.set_do_transparency(false); 54 action.set_have_to_do_transparency(false); 55 m_sg.render(action); 56 if(!action.end()) { //check that matrices stack are ok. 57 m_out << "tools::sg::zb_viewer: bad zb_action end." << std::endl; 58 return false; 59 } else { 60 if(action.have_to_do_transparency()) { 61 action.set_do_transparency(true); 62 m_sg.render(action); 63 if(!action.end()) { //check that matrices stack are ok. 64 m_out << "tools::sg::zb_viewer: bad zb_action end." << std::endl; 65 return false; 66 } 67 } 68 } 69 70 m_out_buffer_what = a_what; 71 bool status = false; 72 switch(a_what) { 73 case get_rgbs: 74 status = action.get_rgbs(a_top_to_bottom,m_out_buffer); 75 break; 76 case get_rgbas: 77 status = action.get_rgbas(a_top_to_bottom,m_out_buffer); 78 break; 79 case get_bgras: 80 status = action.get_bgras(a_top_to_bottom,m_out_buffer); 81 break; 82 }\ 83 if(!status) { 84 m_out << "tools::sg::zb_viewer::render() : can't get rgb image." << std::endl; 85 m_out_buffer.clear(); 86 return false; 87 } 88 /*m_out << "size " << m_out_buffer.size() << std::endl;*/ 89 return true; 90 } 91 92 const std::vector<unsigned char>& out_buffer() const {return m_out_buffer;} 93 void out_buffer_clear() {m_out_buffer.clear();} 94 95 protected: 96 zb_manager m_mgr_gra; 97 get_what m_out_buffer_what; 98 std::vector<unsigned char> m_out_buffer; 99 }; 100 101 }} 102 103 #endif