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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/write_paper (Version 11.3.0) and /externals/g4tools/include/tools/sg/write_paper (Version 8.3.p1)


  1 // Copyright (C) 2018, Guy Barrand. All rights    
  2 // See the file tools.license for terms.          
  3                                                   
  4 #ifndef tools_sg_write_paper                      
  5 #define tools_sg_write_paper                      
  6                                                   
  7 //  To traverse a scene graph and "export" it     
  8 // by using various rendering actions.            
  9 //  For example by using gl2ps_action, handle     
 10 //    gl2ps_eps: gl2ps producing eps              
 11 //    gl2ps_ps:  gl2ps producing ps               
 12 //    gl2ps_pdf: gl2ps producing pdf              
 13 //    gl2ps_svg: gl2ps producing svg              
 14 //    gl2ps_tex: gl2ps producing tex              
 15 //    gl2ps_pgf: gl2ps producing pgf              
 16 // By using the zb_action (zb for zbuffer):       
 17 //    inzb_ps: tools::sg offscreen zbuffer put    
 18 //    inzb_png: zbuffer put in a png file. It     
 19 //    inzb_jpeg: zbuffer put in a jpeg file. I    
 20                                                   
 21 #include "zb_action"                              
 22 #include "node"                                   
 23 #include "gl2ps_action"                           
 24 #include "../wps"                                 
 25 #include "../typedefs"                            
 26 #include "../touplow"                             
 27                                                   
 28 namespace tools {                                 
 29 namespace sg {                                    
 30                                                   
 31 typedef bool (*png_writer)(std::ostream&,const    
 32                            unsigned char*,unsi    
 33                                                   
 34 typedef bool (*jpeg_writer)(std::ostream&,cons    
 35                             unsigned char*,uns    
 36                                                   
 37 inline bool write_paper(std::ostream& a_out,      
 38                         gl2ps_manager& a_gl2ps    
 39                         png_writer a_png_write    
 40                         float a_back_r,float a    
 41                         node& a_scene_graph,      
 42                         unsigned int a_width,u    
 43                         const std::string& a_f    
 44                         bool a_do_transparency    
 45                         bool a_top_to_bottom,     
 46                         const std::string& a_o    
 47   if(!a_width || !a_height) return false;         
 48   std::string a_format = a__format;               
 49   tolowercase(a_format);  //handle legacy.        
 50   int gl2ps_format;                               
 51   if(gl2ps_s2format(a_format,gl2ps_format)) {     
 52     int sort = -1;                                
 53     if(a_opts_1.size() && !gl2ps_s2sort(a_opts    
 54       a_out << "tools::sg::write_paper: bad gl    
 55       return false;                               
 56     }                                             
 57     int options = -1;                             
 58     if(a_opts_2.size() && !gl2ps_s2options(a_o    
 59       a_out << "tools::sg::write_paper: bad gl    
 60       return false;                               
 61     }                                             
 62     gl2ps_action action(a_gl2ps_mgr,a_out,a_wi    
 63     action.clear_color(a_back_r,a_back_g,a_bac    
 64     if(!action.open(a_file,gl2ps_format,sort,o    
 65     action.set_do_transparency(false);            
 66     action.set_have_to_do_transparency(false);    
 67     a_scene_graph.render(action);                 
 68     if(!action.end()) { //check that matrices     
 69       a_out << "tools::sg::write_paper: bad gl    
 70       action.close();                             
 71       return false;                               
 72     } else if(a_do_transparency) {                
 73       if(action.have_to_do_transparency()) {      
 74         //a_out << "tools::sg::write_paper: wa    
 75         action.set_do_transparency(true);         
 76         a_scene_graph.render(action);             
 77         if(!action.end()) { //check that matri    
 78           a_out << "tools::sg::write_paper: ba    
 79           action.close();                         
 80           return false;                           
 81         }                                         
 82       }                                           
 83     }                                             
 84     action.close();                               
 85     return true;                                  
 86   }                                               
 87                                                   
 88   zb_action action(a_zb_mgr,a_out,a_width,a_he    
 89   action.clear_color_buffer(a_back_r,a_back_g,    
 90   action.clear_depth_buffer();                    
 91   action.set_do_transparency(false);              
 92   action.set_have_to_do_transparency(false);      
 93   a_scene_graph.render(action);                   
 94   if(!action.end()) { //check that matrices st    
 95     a_out << "tools::sg::write_paper: bad zb_a    
 96     return false;                                 
 97   } else if(a_do_transparency) {                  
 98     if(action.have_to_do_transparency()) {        
 99       action.set_do_transparency(true);           
100       a_scene_graph.render(action);               
101       if(!action.end()) { //check that matrice    
102         a_out << "tools::sg::write_paper: bad     
103         return false;                             
104       }                                           
105     }                                             
106   }                                               
107                                                   
108   if((a_format=="zb_ps")||(a_format=="inzb_ps"    
109     wps wps(a_out);                               
110     if(!wps.open_file(a_file)) {                  
111       a_out << "tools::sg::write_paper : can't    
112       return false;                               
113     }                                             
114     wps.PS_BEGIN_PAGE();                          
115     wps.PS_PAGE_SCALE(float(a_width),float(a_h    
116     wps.PS_IMAGE(a_width,a_height,wps::rgb_4,z    
117     wps.PS_END_PAGE();                            
118     wps.close_file();                             
119     return true;                                  
120   }                                               
121                                                   
122   if((a_format=="zb_png")||(a_format=="inzb_pn    
123     if(!a_png_writer) {                           
124       a_out << "tools::sg::write_paper : no pn    
125       return false;                               
126     }                                             
127                                                   
128     std::vector<unsigned char> buffer;            
129     if(!action.get_rgbas(a_top_to_bottom,buffe    
130       a_out << "tools::sg::write_paper : can't    
131       return false;                               
132     }                                             
133                                                   
134     if(!a_png_writer(a_out,a_file,vec_data(buf    
135       a_out << "tools::sg::write_paper : tools    
136       return false;                               
137     }                                             
138     return true;                                  
139   }                                               
140                                                   
141   if((a_format=="zb_jpeg")||(a_format=="zb_jpg    
142                                                   
143     if(!a_jpeg_writer) {                          
144       a_out << "tools::sg::write_paper : no jp    
145       return false;                               
146     }                                             
147                                                   
148     std::vector<unsigned char> buffer;            
149     if(!action.get_rgbs(a_top_to_bottom,buffer    
150       a_out << "tools::sg::write_paper : can't    
151       return false;                               
152     }                                             
153                                                   
154     if(!a_jpeg_writer(a_out,a_file,vec_data(bu    
155       a_out << "tools::sg::write_paper : tools    
156       return false;                               
157     }                                             
158     return true;                                  
159   }                                               
160                                                   
161   a_out << "tools::sg::write_paper : unknown f    
162   return false;                                   
163 }                                                 
164                                                   
165 inline bool write_paper(std::ostream& a_out,      
166                         gl2ps_manager& a_gl2ps    
167                         png_writer a_png_write    
168                         const tools::colorf& a    
169                         node& a_scene_graph,      
170                         unsigned int a_width,u    
171                         const std::string& a_f    
172                         bool a_do_transparency    
173                         const std::string& a_o    
174   return tools::sg::write_paper(a_out,a_gl2ps_    
175                                 a_png_writer,a    
176                                 a_back.r(),a_b    
177                                 a_scene_graph,    
178                                 a_do_transpare    
179 }                                                 
180                                                   
181 inline bool write_paper(std::ostream& a_out,      
182                         gl2ps_manager& a_gl2ps    
183                         png_writer a_png_write    
184                         const tools::colorf& a    
185                         node& a_scene_graph,      
186                         unsigned int a_width,u    
187                         const std::string& a_f    
188   return tools::sg::write_paper(a_out,a_gl2ps_    
189                                 a_png_writer,a    
190                                 a_back.r(),a_b    
191                                 a_scene_graph,    
192                                 true,true,std:    
193 }                                                 
194                                                   
195 }}                                                
196                                                   
197 #endif