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