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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/g4tools/include/tools/sg/viewer (Version 11.3.0) and /externals/g4tools/include/tools/sg/viewer (Version 11.1.1)


  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_viewer                             4 #ifndef tools_sg_viewer
  5 #define tools_sg_viewer                             5 #define tools_sg_viewer
  6                                                     6 
  7 #include "group"                                    7 #include "group"
  8                                                     8 
  9 #ifdef TOOLS_MEM                                    9 #ifdef TOOLS_MEM
 10 #include "../mem"                                  10 #include "../mem"
 11 #endif                                             11 #endif
 12                                                    12 
 13 #include "cursor_shape"                            13 #include "cursor_shape"
 14                                                    14 
 15 namespace tools {                                  15 namespace tools {
 16 namespace sg {                                     16 namespace sg {
 17                                                    17 
 18 class viewer {                                     18 class viewer {
 19 public:                                            19 public:
 20   TOOLS_SCLASS(tools::sg::viewer)                  20   TOOLS_SCLASS(tools::sg::viewer)
 21   virtual void* cast(const std::string& a_clas     21   virtual void* cast(const std::string& a_class) const {
 22     if(void* p = cmp_cast<viewer>(this,a_class     22     if(void* p = cmp_cast<viewer>(this,a_class)) {return p;}
 23     else return 0;                                 23     else return 0;
 24   }                                                24   }
 25 public:                                            25 public:
 26   virtual void set_size(unsigned int a_w,unsig     26   virtual void set_size(unsigned int a_w,unsigned int a_h) {
 27     //m_out << "debug : tools::sg::viewer::set     27     //m_out << "debug : tools::sg::viewer::set_size :"
 28     //      << " ww " << a_w                       28     //      << " ww " << a_w
 29     //      << " wh " << a_h                       29     //      << " wh " << a_h
 30     //      << std::endl;                          30     //      << std::endl;
 31     size_event e(m_ww,m_wh,a_w,a_h);               31     size_event e(m_ww,m_wh,a_w,a_h);
 32     m_ww = a_w;                                    32     m_ww = a_w;
 33     m_wh = a_h;                                    33     m_wh = a_h;
 34     event_action action(m_out,m_ww,m_wh,e);        34     event_action action(m_out,m_ww,m_wh,e);
 35     action.set_do_switch_children(true); //And     35     action.set_do_switch_children(true); //Android : rot device : GUI & scene.
 36     m_sg.event(action); //used by m_plots in p     36     m_sg.event(action); //used by m_plots in plots_viewer.
 37   }                                                37   }
 38                                                    38 
 39   virtual bool set_cursor_shape(cursor_shape)      39   virtual bool set_cursor_shape(cursor_shape) {return false;}
 40 public:                                            40 public:
 41   viewer(std::ostream& a_out,unsigned int a_wi     41   viewer(std::ostream& a_out,unsigned int a_width,unsigned int a_height)
 42   :m_out(a_out)                                    42   :m_out(a_out)
 43   ,m_clear_color(1,1,1)                            43   ,m_clear_color(1,1,1)
 44   ,m_ww(a_width)                                   44   ,m_ww(a_width)
 45   ,m_wh(a_height)                                  45   ,m_wh(a_height)
 46   ,m_use_gsto(false)                               46   ,m_use_gsto(false)
 47   ,m_produce_out_jpeg(false)                       47   ,m_produce_out_jpeg(false)
 48   ,m_produce_out_png(false)                        48   ,m_produce_out_png(false)
 49   ,m_produce_out_file()                            49   ,m_produce_out_file()
 50   ,m_produce_out_bpp(4)                            50   ,m_produce_out_bpp(4)
 51   {                                                51   {
 52 #ifdef TOOLS_MEM                                   52 #ifdef TOOLS_MEM
 53     mem::increment(s_class().c_str());             53     mem::increment(s_class().c_str());
 54 #endif                                             54 #endif
 55   }                                                55   }
 56   virtual ~viewer(){                               56   virtual ~viewer(){
 57     m_sg.clear(); //we must delete node before     57     m_sg.clear(); //we must delete node before m_zb_mgr (and any render_manager).
 58 #ifdef TOOLS_MEM                                   58 #ifdef TOOLS_MEM
 59     mem::decrement(s_class().c_str());             59     mem::decrement(s_class().c_str());
 60 #endif                                             60 #endif
 61   }                                                61   }
 62 public:                                            62 public:
 63   viewer(const viewer& a_from)                     63   viewer(const viewer& a_from)
 64   :m_out(a_from.m_out)                             64   :m_out(a_from.m_out)
 65   ,m_clear_color(a_from.m_clear_color)             65   ,m_clear_color(a_from.m_clear_color)
 66   ,m_ww(a_from.m_ww)                               66   ,m_ww(a_from.m_ww)
 67   ,m_wh(a_from.m_wh)                               67   ,m_wh(a_from.m_wh)
 68   ,m_sg(a_from.m_sg)                               68   ,m_sg(a_from.m_sg)
 69   ,m_use_gsto(a_from.m_use_gsto)                   69   ,m_use_gsto(a_from.m_use_gsto)
 70   ,m_produce_out_jpeg(a_from.m_produce_out_jpe     70   ,m_produce_out_jpeg(a_from.m_produce_out_jpeg)
 71   ,m_produce_out_png(a_from.m_produce_out_png)     71   ,m_produce_out_png(a_from.m_produce_out_png)
 72   ,m_produce_out_file(a_from.m_produce_out_fil     72   ,m_produce_out_file(a_from.m_produce_out_file)
 73   ,m_produce_out_bpp(a_from.m_produce_out_bpp)     73   ,m_produce_out_bpp(a_from.m_produce_out_bpp)
 74   {                                                74   {
 75 #ifdef TOOLS_MEM                                   75 #ifdef TOOLS_MEM
 76     mem::increment(s_class().c_str());             76     mem::increment(s_class().c_str());
 77 #endif                                             77 #endif
 78   }                                                78   }
 79   viewer& operator=(const viewer& a_from){         79   viewer& operator=(const viewer& a_from){
 80     m_clear_color = a_from.m_clear_color;          80     m_clear_color = a_from.m_clear_color;
 81     m_ww = a_from.m_ww;                            81     m_ww = a_from.m_ww;
 82     m_wh = a_from.m_wh;                            82     m_wh = a_from.m_wh;
 83     m_sg = a_from.m_sg;                            83     m_sg = a_from.m_sg;
 84     m_use_gsto = a_from.m_use_gsto;                84     m_use_gsto = a_from.m_use_gsto;
 85     m_produce_out_jpeg = a_from.m_produce_out_     85     m_produce_out_jpeg = a_from.m_produce_out_jpeg;
 86     m_produce_out_png = a_from.m_produce_out_p     86     m_produce_out_png = a_from.m_produce_out_png;
 87     m_produce_out_file = a_from.m_produce_out_     87     m_produce_out_file = a_from.m_produce_out_file;
 88     m_produce_out_bpp = a_from.m_produce_out_b     88     m_produce_out_bpp = a_from.m_produce_out_bpp;
 89     return *this;                                  89     return *this;
 90   }                                                90   }
 91 public:                                            91 public:
 92   bool set_default_cursor_shape() {return set_     92   bool set_default_cursor_shape() {return set_cursor_shape(cursor_default);}
 93                                                    93 
 94   group& sg() {return m_sg;}                       94   group& sg() {return m_sg;}
 95   const group& sg() const {return m_sg;}           95   const group& sg() const {return m_sg;}
 96                                                    96 
 97   unsigned int width() const {return m_ww;}        97   unsigned int width() const {return m_ww;}
 98   unsigned int height() const {return m_wh;}       98   unsigned int height() const {return m_wh;}
 99                                                    99 
100   bool screen2aspect(int a_x,int a_y,float& a_    100   bool screen2aspect(int a_x,int a_y,float& a_wx,float& a_wy) const {
101     // convert screen point in [aspect,1] coor    101     // convert screen point in [aspect,1] coordinates.
102     //if(!m_ww) {a_wx = a_wy = 0;return false;    102     //if(!m_ww) {a_wx = a_wy = 0;return false;}
103     //if(!m_wh) {a_wx = a_wy = 0;return false;    103     //if(!m_wh) {a_wx = a_wy = 0;return false;}
104     float aspect = float(m_ww)/float(m_wh);       104     float aspect = float(m_ww)/float(m_wh);
105     float wch = 1;                                105     float wch = 1;
106     float wcw = wch*aspect;                       106     float wcw = wch*aspect;
107     a_wx = float(a_x) * wcw/float(m_ww);          107     a_wx = float(a_x) * wcw/float(m_ww);
108     a_wy = float(a_y) * wch/float(m_wh);          108     a_wy = float(a_y) * wch/float(m_wh);
109     return true;                                  109     return true;
110   }                                               110   }
111                                                   111 
112   void set_clear_color(float a_r,float a_g,flo    112   void set_clear_color(float a_r,float a_g,float a_b,float a_a = 1) {
113     m_clear_color = colorf(a_r,a_g,a_b,a_a);      113     m_clear_color = colorf(a_r,a_g,a_b,a_a);
114   }                                               114   }
115   void set_clear_color(const colorf& a_color)     115   void set_clear_color(const colorf& a_color) {
116     m_clear_color = a_color;                      116     m_clear_color = a_color;
117   }                                               117   }
118   void get_clear_color(float& a_r,float& a_g,f    118   void get_clear_color(float& a_r,float& a_g,float& a_b,float& a_a) {
119     a_r = m_clear_color.r();                      119     a_r = m_clear_color.r();
120     a_g = m_clear_color.g();                      120     a_g = m_clear_color.g();
121     a_b = m_clear_color.b();                      121     a_b = m_clear_color.b();
122     a_a = m_clear_color.a();                      122     a_a = m_clear_color.a();
123   }                                               123   }
124                                                   124 
125   const colorf& background() const {return m_c    125   const colorf& background() const {return m_clear_color;}
126                                                   126 
127   std::ostream& out() const {return m_out;}       127   std::ostream& out() const {return m_out;}
128                                                   128 
129   const std::string& out_dir() const {return m    129   const std::string& out_dir() const {return m_out_dir;}
130                                                   130 
131                                                   131 
132   void set_produce_out_jpeg(bool a_value) {m_p    132   void set_produce_out_jpeg(bool a_value) {m_produce_out_jpeg = a_value;}
133   bool produce_out_jpeg() const {return m_prod    133   bool produce_out_jpeg() const {return m_produce_out_jpeg;}
134                                                   134 
135   void set_produce_out_png(bool a_value) {m_pr    135   void set_produce_out_png(bool a_value) {m_produce_out_png = a_value;}
136   bool produce_out_png() const {return m_produ    136   bool produce_out_png() const {return m_produce_out_png;}
137                                                   137 
138   void set_produce_out_file(const std::string&    138   void set_produce_out_file(const std::string& a_file) {m_produce_out_file = a_file;}
139   const std::string& produce_out_file() const     139   const std::string& produce_out_file() const {return m_produce_out_file;}
140                                                   140 
141   void set_produce_out_bpp(unsigned int a_bpp)    141   void set_produce_out_bpp(unsigned int a_bpp) {m_produce_out_bpp = a_bpp;}
142   unsigned int produce_out_bpp() const {return    142   unsigned int produce_out_bpp() const {return m_produce_out_bpp;}
143 protected:                                        143 protected:
144   // iPod : 320 x 480                             144   // iPod : 320 x 480
145   // iPad : 768 x 1024                            145   // iPad : 768 x 1024
146   // SGS : API-1 : 320 x 533, API-5 : 480 x 80    146   // SGS : API-1 : 320 x 533, API-5 : 480 x 800
147   // SGT : 1024 x 600 ?                           147   // SGT : 1024 x 600 ?
148                                                   148 
149   // LRI WILD : borders w = 100 x h = 120. 4x8    149   // LRI WILD : borders w = 100 x h = 120. 4x8 screens with 2560x1600 pixels.
150   // LAL ARTS : borders 88x100. 2x4 screens of    150   // LAL ARTS : borders 88x100. 2x4 screens of 1920 x 1080
151                                                   151 
152   //bool is_iPad() const {                        152   //bool is_iPad() const {
153   //  if( (m_ww==768) && (m_wh==1024) ) return    153   //  if( (m_ww==768) && (m_wh==1024) ) return true;
154   //  if( (m_wh==768) && (m_ww==1024) ) return    154   //  if( (m_wh==768) && (m_ww==1024) ) return true;
155   //  return false;                               155   //  return false;
156   //}                                             156   //}
157   //bool is_SGS() const {                         157   //bool is_SGS() const {
158   //  //API : 1                                   158   //  //API : 1
159   //  //if( (m_ww==320) && (m_wh==533) ) retur    159   //  //if( (m_ww==320) && (m_wh==533) ) return true;
160   //  //if( (m_wh==320) && (m_ww==533) ) retur    160   //  //if( (m_wh==320) && (m_ww==533) ) return true;
161   //                                              161   //
162   //  //API : 5                                   162   //  //API : 5
163   //  if( (m_ww==480) && (m_wh==800) ) return     163   //  if( (m_ww==480) && (m_wh==800) ) return true;
164   //  if( (m_wh==480) && (m_ww==800) ) return     164   //  if( (m_wh==480) && (m_ww==800) ) return true;
165   //  return false;                               165   //  return false;
166   //}                                             166   //}
167                                                   167 
168 protected:                                        168 protected:
169   std::ostream& m_out;                            169   std::ostream& m_out;
170   colorf m_clear_color;                           170   colorf m_clear_color;
171   unsigned int m_ww;                              171   unsigned int m_ww;
172   unsigned int m_wh;                              172   unsigned int m_wh;
173   group m_sg;                                     173   group m_sg;
174   std::string m_out_dir;                          174   std::string m_out_dir;
175   bool m_use_gsto;                                175   bool m_use_gsto;
176   bool m_produce_out_jpeg;                        176   bool m_produce_out_jpeg;
177   bool m_produce_out_png;                         177   bool m_produce_out_png;
178   std::string m_produce_out_file;                 178   std::string m_produce_out_file;
179   unsigned int m_produce_out_bpp;                 179   unsigned int m_produce_out_bpp;
180 };                                                180 };
181                                                   181 
182 }}                                                182 }}
183                                                   183 
184 #include "../pointer"                             184 #include "../pointer"
185                                                   185 
186 namespace tools {                                 186 namespace tools {
187 namespace sg {                                    187 namespace sg {
188                                                   188 
189 // used with Python and lua :                     189 // used with Python and lua :
190 inline viewer* cast_viewer(const std::string&     190 inline viewer* cast_viewer(const std::string& a_s) {
191   void* p;                                        191   void* p;
192   if(!to_pointer(a_s,p)) return 0; //read with    192   if(!to_pointer(a_s,p)) return 0; //read with %lx and, if failure, with %lu.
193   return (viewer*)p;                              193   return (viewer*)p;
194 }                                                 194 }
195                                                   195 
196 }}                                                196 }}
197                                                   197 
198 #endif                                            198 #endif
199                                                   199