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 #include "cursor_shape"
0009 
0010 namespace tools {
0011 namespace sg {
0012 
0013 class viewer {
0014 public:
0015   TOOLS_SCLASS(tools::sg::viewer)
0016   virtual void* cast(const std::string& a_class) const {
0017     if(void* p = cmp_cast<viewer>(this,a_class)) {return p;}
0018     else return 0;
0019   }
0020 public:
0021   virtual void set_size(unsigned int a_w,unsigned int a_h) {
0022     size_event e(m_ww,m_wh,a_w,a_h);
0023     m_ww = a_w;
0024     m_wh = a_h;
0025     event_action action(m_out,m_ww,m_wh,e);
0026     action.set_do_switch_children(true); //Android : rot device : GUI & scene.
0027     m_sg.event(action); //used by m_plots in plots_viewer.
0028   }
0029 
0030   virtual bool set_cursor_shape(cursor_shape) {return false;}
0031 
0032 public:
0033   viewer(std::ostream& a_out,unsigned int a_width,unsigned int a_height)
0034   :m_out(a_out)
0035   ,m_clear_color(1,1,1)
0036   ,m_ww(a_width)
0037   ,m_wh(a_height)
0038   ,m_use_gsto(false)
0039   ,m_produce_out_jpeg(false)
0040   ,m_produce_out_png(false)
0041   ,m_produce_out_file()
0042   ,m_produce_out_bpp(4)
0043   {
0044   }
0045   virtual ~viewer(){
0046     m_sg.clear(); //we must delete node before m_zb_mgr (and any render_manager).
0047   }
0048 public:
0049   viewer(const viewer& a_from)
0050   :m_out(a_from.m_out)
0051   ,m_clear_color(a_from.m_clear_color)
0052   ,m_ww(a_from.m_ww)
0053   ,m_wh(a_from.m_wh)
0054   ,m_sg(a_from.m_sg)
0055   ,m_use_gsto(a_from.m_use_gsto)
0056   ,m_produce_out_jpeg(a_from.m_produce_out_jpeg)
0057   ,m_produce_out_png(a_from.m_produce_out_png)
0058   ,m_produce_out_file(a_from.m_produce_out_file)
0059   ,m_produce_out_bpp(a_from.m_produce_out_bpp)
0060   {
0061   }
0062   viewer& operator=(const viewer& a_from){
0063     m_clear_color = a_from.m_clear_color;
0064     m_ww = a_from.m_ww;
0065     m_wh = a_from.m_wh;
0066     m_sg = a_from.m_sg;
0067     m_use_gsto = a_from.m_use_gsto;
0068     m_produce_out_jpeg = a_from.m_produce_out_jpeg;
0069     m_produce_out_png = a_from.m_produce_out_png;
0070     m_produce_out_file = a_from.m_produce_out_file;
0071     m_produce_out_bpp = a_from.m_produce_out_bpp;
0072     return *this;
0073   }
0074 public:
0075   bool set_default_cursor_shape() {return set_cursor_shape(cursor_default);}
0076 
0077   group& sg() {return m_sg;}
0078   const group& sg() const {return m_sg;}
0079 
0080   unsigned int width() const {return m_ww;}
0081   unsigned int height() const {return m_wh;}
0082 
0083   bool screen2aspect(int a_x,int a_y,float& a_wx,float& a_wy) const {
0084     // convert screen point in [aspect,1] coordinates.
0085     float aspect = float(m_ww)/float(m_wh);
0086     float wch = 1;
0087     float wcw = wch*aspect;
0088     a_wx = float(a_x) * wcw/float(m_ww);
0089     a_wy = float(a_y) * wch/float(m_wh);
0090     return true;
0091   }
0092 
0093   void set_clear_color(float a_r,float a_g,float a_b,float a_a = 1) {
0094     m_clear_color = colorf(a_r,a_g,a_b,a_a);
0095   }
0096   void set_clear_color(const colorf& a_color) {
0097     m_clear_color = a_color;
0098   }
0099   void get_clear_color(float& a_r,float& a_g,float& a_b,float& a_a) {
0100     a_r = m_clear_color.r();
0101     a_g = m_clear_color.g();
0102     a_b = m_clear_color.b();
0103     a_a = m_clear_color.a();
0104   }
0105 
0106   const colorf& background() const {return m_clear_color;}
0107 
0108   std::ostream& out() const {return m_out;}
0109 
0110   const std::string& out_dir() const {return m_out_dir;}
0111 
0112 
0113   void set_produce_out_jpeg(bool a_value) {m_produce_out_jpeg = a_value;}
0114   bool produce_out_jpeg() const {return m_produce_out_jpeg;}
0115 
0116   void set_produce_out_png(bool a_value) {m_produce_out_png = a_value;}
0117   bool produce_out_png() const {return m_produce_out_png;}
0118 
0119   void set_produce_out_file(const std::string& a_file) {m_produce_out_file = a_file;}
0120   const std::string& produce_out_file() const {return m_produce_out_file;}
0121 
0122   void set_produce_out_bpp(unsigned int a_bpp) {m_produce_out_bpp = a_bpp;}
0123   unsigned int produce_out_bpp() const {return m_produce_out_bpp;}
0124 
0125 protected:
0126   std::ostream& m_out;
0127   colorf m_clear_color;
0128   unsigned int m_ww;
0129   unsigned int m_wh;
0130   group m_sg;
0131   std::string m_out_dir;
0132   bool m_use_gsto;
0133   bool m_produce_out_jpeg;
0134   bool m_produce_out_png;
0135   std::string m_produce_out_file;
0136   unsigned int m_produce_out_bpp;
0137 };
0138 
0139 }}
0140 
0141 #endif
0142