Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/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_viewer
0005 #define tools_sg_viewer
0006 
0007 #include "group"
0008 
0009 #ifdef TOOLS_MEM
0010 #include "../mem"
0011 #endif
0012 
0013 #include "cursor_shape"
0014 
0015 namespace tools {
0016 namespace sg {
0017 
0018 class viewer {
0019 public:
0020   TOOLS_SCLASS(tools::sg::viewer)
0021   virtual void* cast(const std::string& a_class) const {
0022     if(void* p = cmp_cast<viewer>(this,a_class)) {return p;}
0023     else return 0;
0024   }
0025 public:
0026   virtual void set_size(unsigned int a_w,unsigned int a_h) {
0027     //m_out << "debug : tools::sg::viewer::set_size :"
0028     //      << " ww " << a_w
0029     //      << " wh " << a_h
0030     //      << std::endl;
0031     size_event e(m_ww,m_wh,a_w,a_h);
0032     m_ww = a_w;
0033     m_wh = a_h;
0034     event_action action(m_out,m_ww,m_wh,e);
0035     action.set_do_switch_children(true); //Android : rot device : GUI & scene.
0036     m_sg.event(action); //used by m_plots in plots_viewer.
0037   }
0038 
0039   virtual bool set_cursor_shape(cursor_shape) {return false;}
0040 public:
0041   viewer(std::ostream& a_out,unsigned int a_width,unsigned int a_height)
0042   :m_out(a_out)
0043   ,m_clear_color(1,1,1)
0044   ,m_ww(a_width)
0045   ,m_wh(a_height)
0046   ,m_use_gsto(false)
0047   ,m_produce_out_jpeg(false)
0048   ,m_produce_out_png(false)
0049   ,m_produce_out_file()
0050   ,m_produce_out_bpp(4)
0051   {
0052 #ifdef TOOLS_MEM
0053     mem::increment(s_class().c_str());
0054 #endif
0055   }
0056   virtual ~viewer(){
0057     m_sg.clear(); //we must delete node before m_zb_mgr (and any render_manager).
0058 #ifdef TOOLS_MEM
0059     mem::decrement(s_class().c_str());
0060 #endif
0061   }
0062 public:
0063   viewer(const viewer& a_from)
0064   :m_out(a_from.m_out)
0065   ,m_clear_color(a_from.m_clear_color)
0066   ,m_ww(a_from.m_ww)
0067   ,m_wh(a_from.m_wh)
0068   ,m_sg(a_from.m_sg)
0069   ,m_use_gsto(a_from.m_use_gsto)
0070   ,m_produce_out_jpeg(a_from.m_produce_out_jpeg)
0071   ,m_produce_out_png(a_from.m_produce_out_png)
0072   ,m_produce_out_file(a_from.m_produce_out_file)
0073   ,m_produce_out_bpp(a_from.m_produce_out_bpp)
0074   {
0075 #ifdef TOOLS_MEM
0076     mem::increment(s_class().c_str());
0077 #endif
0078   }
0079   viewer& operator=(const viewer& a_from){
0080     m_clear_color = a_from.m_clear_color;
0081     m_ww = a_from.m_ww;
0082     m_wh = a_from.m_wh;
0083     m_sg = a_from.m_sg;
0084     m_use_gsto = a_from.m_use_gsto;
0085     m_produce_out_jpeg = a_from.m_produce_out_jpeg;
0086     m_produce_out_png = a_from.m_produce_out_png;
0087     m_produce_out_file = a_from.m_produce_out_file;
0088     m_produce_out_bpp = a_from.m_produce_out_bpp;
0089     return *this;
0090   }
0091 public:
0092   bool set_default_cursor_shape() {return set_cursor_shape(cursor_default);}
0093 
0094   group& sg() {return m_sg;}
0095   const group& sg() const {return m_sg;}
0096 
0097   unsigned int width() const {return m_ww;}
0098   unsigned int height() const {return m_wh;}
0099 
0100   bool screen2aspect(int a_x,int a_y,float& a_wx,float& a_wy) const {
0101     // convert screen point in [aspect,1] coordinates.
0102     //if(!m_ww) {a_wx = a_wy = 0;return false;}
0103     //if(!m_wh) {a_wx = a_wy = 0;return false;}
0104     float aspect = float(m_ww)/float(m_wh);
0105     float wch = 1;
0106     float wcw = wch*aspect;
0107     a_wx = float(a_x) * wcw/float(m_ww);
0108     a_wy = float(a_y) * wch/float(m_wh);
0109     return true;
0110   }
0111 
0112   void set_clear_color(float a_r,float a_g,float a_b,float a_a = 1) {
0113     m_clear_color = colorf(a_r,a_g,a_b,a_a);
0114   }
0115   void set_clear_color(const colorf& a_color) {
0116     m_clear_color = a_color;
0117   }
0118   void get_clear_color(float& a_r,float& a_g,float& a_b,float& a_a) {
0119     a_r = m_clear_color.r();
0120     a_g = m_clear_color.g();
0121     a_b = m_clear_color.b();
0122     a_a = m_clear_color.a();
0123   }
0124 
0125   const colorf& background() const {return m_clear_color;}
0126 
0127   std::ostream& out() const {return m_out;}
0128 
0129   const std::string& out_dir() const {return m_out_dir;}
0130 
0131 
0132   void set_produce_out_jpeg(bool a_value) {m_produce_out_jpeg = a_value;}
0133   bool produce_out_jpeg() const {return m_produce_out_jpeg;}
0134 
0135   void set_produce_out_png(bool a_value) {m_produce_out_png = a_value;}
0136   bool produce_out_png() const {return m_produce_out_png;}
0137 
0138   void set_produce_out_file(const std::string& a_file) {m_produce_out_file = a_file;}
0139   const std::string& produce_out_file() const {return m_produce_out_file;}
0140 
0141   void set_produce_out_bpp(unsigned int a_bpp) {m_produce_out_bpp = a_bpp;}
0142   unsigned int produce_out_bpp() const {return m_produce_out_bpp;}
0143 protected:
0144   // iPod : 320 x 480
0145   // iPad : 768 x 1024
0146   // SGS : API-1 : 320 x 533, API-5 : 480 x 800
0147   // SGT : 1024 x 600 ?
0148 
0149   // LRI WILD : borders w = 100 x h = 120. 4x8 screens with 2560x1600 pixels.
0150   // LAL ARTS : borders 88x100. 2x4 screens of 1920 x 1080
0151 
0152   //bool is_iPad() const {
0153   //  if( (m_ww==768) && (m_wh==1024) ) return true;
0154   //  if( (m_wh==768) && (m_ww==1024) ) return true;
0155   //  return false;
0156   //}
0157   //bool is_SGS() const {
0158   //  //API : 1
0159   //  //if( (m_ww==320) && (m_wh==533) ) return true;
0160   //  //if( (m_wh==320) && (m_ww==533) ) return true;
0161   //
0162   //  //API : 5
0163   //  if( (m_ww==480) && (m_wh==800) ) return true;
0164   //  if( (m_wh==480) && (m_ww==800) ) return true;
0165   //  return false;
0166   //}
0167 
0168 protected:
0169   std::ostream& m_out;
0170   colorf m_clear_color;
0171   unsigned int m_ww;
0172   unsigned int m_wh;
0173   group m_sg;
0174   std::string m_out_dir;
0175   bool m_use_gsto;
0176   bool m_produce_out_jpeg;
0177   bool m_produce_out_png;
0178   std::string m_produce_out_file;
0179   unsigned int m_produce_out_bpp;
0180 };
0181 
0182 }}
0183 
0184 #include "../pointer"
0185 
0186 namespace tools {
0187 namespace sg {
0188 
0189 // used with Python and lua :
0190 inline viewer* cast_viewer(const std::string& a_s) {
0191   void* p;
0192   if(!to_pointer(a_s,p)) return 0; //read with %lx and, if failure, with %lu.
0193   return (viewer*)p;
0194 }
0195 
0196 }}
0197 
0198 #endif
0199