Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/render_gstos 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_render_gstos
0005 #define tools_sg_render_gstos
0006 
0007 #include "gstos"
0008 #include "render_action"
0009 
0010 #include "gstos_add"
0011 
0012 namespace tools {
0013 namespace sg {
0014 
0015 class render_gstos : public gstos {
0016   typedef gstos parent;
0017 public:
0018   virtual void visit(gstos_add& a_visitor,draw_type a_style) = 0;
0019 protected: //gstos
0020   virtual unsigned int create_gsto(std::ostream&,sg::render_manager& a_mgr) {
0021     std::vector<float> gsto_data;
0022 
0023     gstos_add _add;
0024     visit(_add,draw_points);
0025     append(gsto_data,_add.m_xyzs);
0026     m_gstos_points_sz = _add.m_xyzs.size();
0027 
0028     _add.clear();
0029     visit(_add,draw_lines);
0030     append(gsto_data,_add.m_xyzs);
0031     m_gstos_lines_sz = _add.m_xyzs.size();
0032 
0033     _add.clear();
0034     visit(_add,draw_filled);
0035     append(gsto_data,_add.m_xyzs);
0036     m_gstos_tris_sz = _add.m_xyzs.size();
0037     append(gsto_data,_add.m_nms);
0038     m_gstos_nms_sz = _add.m_nms.size();
0039 
0040     if(gsto_data.empty()) return 0;
0041 
0042     return a_mgr.create_gsto_from_data(gsto_data);
0043   }
0044 public: //node
0045   bool gstos_render(render_action& a_action) {
0046     const state& state = a_action.state();
0047 
0048     bool draw_edges = false;
0049     if(state.m_draw_type==draw_filled) draw_edges = state.m_GL_LIGHTING?false:true;
0050 
0051     if(state.m_use_gsto) {
0052       unsigned int _id = get_gsto_id(a_action.out(),a_action.render_manager());
0053       if(_id) {
0054         bufpos pxyzs = 0;
0055         bufpos plines = pxyzs+m_gstos_points_sz*sizeof(float);
0056         bufpos ptris = plines+m_gstos_lines_sz*sizeof(float);
0057         bufpos pnms  = ptris+m_gstos_tris_sz*sizeof(float);
0058 
0059         a_action.begin_gsto(_id);
0060         if(draw_edges) {
0061           a_action.color4f(0,0,0,1); //if lighten, then rendered grey.
0062           a_action.line_width(1);
0063 
0064           a_action.draw_gsto_v(gl::lines(),m_gstos_lines_sz/3,plines);
0065 
0066           //pushes back the filled polygons to avoid z-fighting with lines
0067           a_action.set_polygon_offset(true);
0068 
0069           a_action.color4f(state.m_color);
0070           a_action.line_width(state.m_line_width);
0071         }
0072         if(state.m_draw_type==draw_points) {
0073           a_action.draw_gsto_v(gl::points(),m_gstos_points_sz/3,pxyzs);
0074         } else if(state.m_draw_type==draw_lines) {
0075           a_action.draw_gsto_v(gl::lines(),m_gstos_lines_sz/3,plines);
0076         } else {
0077           a_action.draw_gsto_vn(gl::triangles(),m_gstos_tris_sz/3,ptris,pnms);
0078         }
0079         if(draw_edges) a_action.set_polygon_offset(state.m_GL_POLYGON_OFFSET_FILL);
0080         a_action.end_gsto();
0081         return true;
0082 
0083       } else { //!_id
0084         // use immediate rendering.
0085       }
0086 
0087     } else {
0088       clean_gstos(&a_action.render_manager());
0089     }
0090     return false;
0091   }
0092   bool gstos_render_no_style(render_action& a_action) { //for sg::markers.
0093     const state& state = a_action.state();
0094     if(state.m_use_gsto) {
0095       unsigned int _id = get_gsto_id(a_action.out(),a_action.render_manager());
0096       if(_id) {
0097         bufpos pxyzs = 0;
0098         bufpos plines = pxyzs+m_gstos_points_sz*sizeof(float);
0099         bufpos ptris = plines+m_gstos_lines_sz*sizeof(float);
0100         bufpos pnms  = ptris+m_gstos_tris_sz*sizeof(float);
0101 
0102         a_action.begin_gsto(_id);
0103         a_action.draw_gsto_v(gl::points(),m_gstos_points_sz/3,pxyzs);
0104         a_action.draw_gsto_v(gl::lines(),m_gstos_lines_sz/3,plines);
0105         a_action.draw_gsto_vn(gl::triangles(),m_gstos_tris_sz/3,ptris,pnms);
0106         a_action.end_gsto();
0107         return true;
0108 
0109       } else { //!_id
0110         // use immediate rendering.
0111       }
0112 
0113     } else {
0114       clean_gstos(&a_action.render_manager());
0115     }
0116     return false;
0117   }
0118 public:
0119   render_gstos():parent(),m_gstos_points_sz(0),m_gstos_lines_sz(0),m_gstos_tris_sz(0),m_gstos_nms_sz(0) {}
0120   virtual ~render_gstos() {}
0121 public:
0122   render_gstos(const render_gstos& a_from):parent(a_from),m_gstos_points_sz(0),m_gstos_lines_sz(0),m_gstos_tris_sz(0),m_gstos_nms_sz(0) {}
0123   render_gstos& operator=(const render_gstos& a_from){
0124     parent::operator=(a_from);
0125     m_gstos_points_sz = 0;
0126     m_gstos_lines_sz = 0;
0127     m_gstos_tris_sz = 0;
0128     m_gstos_nms_sz = 0;
0129     return *this;
0130   }
0131 protected:
0132   size_t m_gstos_points_sz;
0133   size_t m_gstos_lines_sz;
0134   size_t m_gstos_tris_sz;
0135   size_t m_gstos_nms_sz;
0136 };
0137 
0138 }}
0139 
0140 #endif