Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/zb_viewer is written in an unsupported language. File is not indexed.

0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003 
0004 #ifndef tools_sg_zb_viewer
0005 #define tools_sg_zb_viewer
0006 
0007 #include "zb_action"
0008 #include "viewer"
0009 
0010 namespace tools {
0011 namespace sg {
0012 
0013 class zb_viewer : public viewer {
0014   TOOLS_HEADER(zb_viewer,tools::sg::zb_viewer,viewer)
0015 public:
0016   zb_viewer(std::ostream& a_out,unsigned int a_width,unsigned int a_height)
0017   :parent(a_out,a_width,a_height)
0018   ,m_mgr_gra()
0019   ,m_out_buffer_what(get_rgbs)
0020   {}
0021   virtual ~zb_viewer(){
0022     //WARNING : nodes may refer m_mgr_gra (to handle gstos/texs), then
0023     //          we have to delete them first.
0024     m_sg.clear();
0025   }
0026 public:
0027   zb_viewer(const zb_viewer& a_from)
0028   :parent(a_from)
0029   ,m_mgr_gra(a_from.m_mgr_gra)
0030   ,m_out_buffer_what(get_rgbs)
0031   {}
0032   zb_viewer& operator=(const zb_viewer& a_from){
0033     parent::operator=(a_from);
0034     m_mgr_gra = a_from.m_mgr_gra;
0035     m_out_buffer_what = get_rgbs;
0036     m_out_buffer.clear();
0037     return *this;
0038   }
0039 public:
0040   enum get_what {
0041     get_rgbs = 0,
0042     get_rgbas,
0043     get_bgras
0044   };
0045   bool render(get_what a_what,bool a_top_to_bottom) {
0046     m_out_buffer.clear();
0047     if(!m_ww) return false;
0048     if(!m_wh) return false;
0049 
0050     zb_action action(m_mgr_gra,m_out,m_ww,m_wh);
0051     action.clear_color_buffer(m_clear_color.r(),m_clear_color.g(),m_clear_color.b(),m_clear_color.a());
0052     action.clear_depth_buffer();
0053     action.set_do_transparency(false);
0054     action.set_have_to_do_transparency(false);
0055     m_sg.render(action);
0056     if(!action.end()) { //check that matrices stack are ok.
0057       m_out << "tools::sg::zb_viewer: bad zb_action end." << std::endl;
0058       return false;
0059     } else {
0060       if(action.have_to_do_transparency()) {
0061         action.set_do_transparency(true);
0062         m_sg.render(action);
0063         if(!action.end()) { //check that matrices stack are ok.
0064           m_out << "tools::sg::zb_viewer: bad zb_action end." << std::endl;
0065           return false;
0066         }
0067       }
0068     }
0069 
0070     m_out_buffer_what = a_what;
0071     bool status = false;
0072     switch(a_what) {
0073     case get_rgbs:
0074       status = action.get_rgbs(a_top_to_bottom,m_out_buffer);
0075       break;
0076     case get_rgbas:
0077       status = action.get_rgbas(a_top_to_bottom,m_out_buffer);
0078       break;
0079     case get_bgras:
0080       status = action.get_bgras(a_top_to_bottom,m_out_buffer);
0081       break;
0082     }\
0083     if(!status) {
0084       m_out << "tools::sg::zb_viewer::render() : can't get rgb image." << std::endl;
0085       m_out_buffer.clear();
0086       return false;
0087     }
0088     /*m_out << "size " << m_out_buffer.size() << std::endl;*/
0089     return true;
0090   }
0091   
0092   const std::vector<unsigned char>& out_buffer() const {return m_out_buffer;}
0093   void out_buffer_clear() {m_out_buffer.clear();}
0094   
0095 protected:
0096   zb_manager m_mgr_gra;
0097   get_what m_out_buffer_what;
0098   std::vector<unsigned char> m_out_buffer;
0099 };
0100 
0101 }}
0102 
0103 #endif