Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/atb_vertices 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_atb_vertices
0005 #define tools_sg_atb_vertices
0006 
0007 #include "vertices"
0008 
0009 namespace tools {
0010 namespace sg {
0011 
0012 class atb_vertices : public vertices {
0013   TOOLS_NODE(atb_vertices,tools::sg::atb_vertices,vertices)
0014 public:
0015   mf<float> rgbas;
0016   mf<float> nms;
0017   sf<bool> do_back;
0018   sf<float> epsilon;
0019   sf<bool> draw_edges;
0020 public:
0021   virtual const desc_fields& node_desc_fields() const {
0022     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::atb_vertices)
0023     static const desc_fields s_v(parent::node_desc_fields(),5, //WARNING : take care of count.
0024       TOOLS_ARG_FIELD_DESC(rgbas),
0025       TOOLS_ARG_FIELD_DESC(nms),
0026       TOOLS_ARG_FIELD_DESC(do_back),
0027       TOOLS_ARG_FIELD_DESC(epsilon),
0028       TOOLS_ARG_FIELD_DESC(draw_edges)
0029     );
0030     return s_v;
0031   }
0032   virtual void protocol_one_fields(std::vector<field*>& a_fields) const {
0033     parent::protocol_one_fields(a_fields);
0034     const field* _draw_edges = static_cast<const field*>(&draw_edges);
0035     removep<field>(a_fields,_draw_edges);
0036   }
0037 private:
0038   void add_fields(){
0039     add_field(&rgbas);
0040     add_field(&nms);
0041     add_field(&do_back);
0042     add_field(&epsilon);
0043     add_field(&draw_edges);
0044   }
0045 protected: //gstos
0046   virtual unsigned int create_gsto(std::ostream&,sg::render_manager& a_mgr) {
0047     std::vector<float> gsto_data;
0048 
0049     if(rgbas.size()) {
0050       if(nms.size()) {
0051         if(do_back.value()) {
0052           append(gsto_data,xyzs.values());
0053           append(gsto_data,nms.values());
0054           append(gsto_data,m_back_xyzs);
0055           append(gsto_data,m_back_nms);
0056           append(gsto_data,rgbas.values());
0057         } else {
0058           append(gsto_data,xyzs.values());
0059           append(gsto_data,nms.values());
0060           append(gsto_data,rgbas.values());
0061         }
0062         if(draw_edges.value()) {
0063           // allocate edges :
0064           size_t pos_edges = gsto_data.size();
0065           append(gsto_data,xyzs.values());
0066           append(gsto_data,xyzs.values());
0067           float* pxyz = xyzs.values().data();
0068           float* pedges = (gsto_data.data())+pos_edges;
0069           size_t npt = xyzs.values().size()/3;
0070           size_t ntri = npt/3;
0071           for(size_t itri=0;itri<ntri;itri++) {
0072             // first edge :
0073             *pedges = *(pxyz+0);pedges++;
0074             *pedges = *(pxyz+1);pedges++;
0075             *pedges = *(pxyz+2);pedges++;
0076 
0077             *pedges = *(pxyz+3);pedges++;
0078             *pedges = *(pxyz+4);pedges++;
0079             *pedges = *(pxyz+5);pedges++;
0080 
0081             // second edge :
0082             *pedges = *(pxyz+3);pedges++;
0083             *pedges = *(pxyz+4);pedges++;
0084             *pedges = *(pxyz+5);pedges++;
0085 
0086             *pedges = *(pxyz+6);pedges++;
0087             *pedges = *(pxyz+7);pedges++;
0088             *pedges = *(pxyz+8);pedges++;
0089 
0090             // third edge :
0091             *pedges = *(pxyz+6);pedges++;
0092             *pedges = *(pxyz+7);pedges++;
0093             *pedges = *(pxyz+8);pedges++;
0094 
0095             *pedges = *(pxyz+0);pedges++;
0096             *pedges = *(pxyz+1);pedges++;
0097             *pedges = *(pxyz+2);pedges++;
0098 
0099             pxyz += 9;
0100           }
0101 
0102         }
0103       } else {
0104         append(gsto_data,xyzs.values());
0105         append(gsto_data,rgbas.values());
0106       }
0107     } else {
0108       if(nms.size()) {
0109         append(gsto_data,xyzs.values());
0110         append(gsto_data,nms.values());
0111       } else {
0112         append(gsto_data,xyzs.values());
0113       }
0114     }
0115     return a_mgr.create_gsto_from_data(gsto_data);
0116   }
0117 
0118 public:
0119   virtual void render(render_action& a_action) {
0120     if(touched()) {
0121       if(do_back.value()) gen_back();
0122       if(draw_edges.value()) gen_edges();
0123       m_all_a_one = true;
0124      {for(auto it = rgbas.values().cbegin(); it != rgbas.values().cend();) {
0125         if(*(it+3)!=1) {m_all_a_one = false;break;}
0126         it += 4;
0127       }}
0128       clean_gstos();
0129       reset_touched();
0130     }
0131     if(xyzs.empty()) return;
0132 
0133     if(!have_to_render(a_action)) return;
0134 
0135     const state& state = a_action.state();
0136 
0137     if(state.m_use_gsto) {
0138       unsigned int _id = get_gsto_id(a_action.out(),a_action.render_manager());
0139       if(_id) {
0140         a_action.begin_gsto(_id);
0141         if(rgbas.size()) {
0142           if(nms.size()) {
0143             size_t npt = xyzs.values().size()/3;
0144             bufpos pos_xyzs = 0;
0145             bufpos pos_nms = 0;
0146             bufpos pos_back_xyzs = 0;
0147             bufpos pos_back_nms = 0;
0148             bufpos pos_rgbas = 0;
0149             bufpos pos_edges = 0;
0150            {size_t sz = npt*3;
0151             if(do_back.value()) {
0152               pos_xyzs = 0;
0153               pos_nms = pos_xyzs+sz*sizeof(float);  //bytes
0154               pos_back_xyzs = pos_nms+sz*sizeof(float);
0155               pos_back_nms = pos_back_xyzs+sz*sizeof(float);
0156               pos_rgbas = pos_back_nms+sz*sizeof(float);
0157             } else {
0158               pos_xyzs = 0;
0159               pos_nms = pos_xyzs+sz*sizeof(float);
0160               pos_rgbas = pos_nms+sz*sizeof(float);
0161             }}
0162             if(draw_edges.value()) {
0163               pos_edges = pos_rgbas+npt*4*sizeof(float);
0164             }
0165             if(gl::is_line(mode.value())) {
0166               //Same logic as Inventor SoLightModel.model = BASE_COLOR.
0167               a_action.set_lighting(false);
0168               if(do_back.value()) a_action.draw_gsto_vcn(mode.value(),npt,pos_back_xyzs,pos_rgbas,pos_back_nms);
0169               a_action.draw_gsto_vcn(mode.value(),npt,pos_xyzs,pos_rgbas,pos_nms);
0170               a_action.set_lighting(state.m_GL_LIGHTING);
0171             } else if(mode.value()==gl::triangles()) {
0172               if(draw_edges.value()) {
0173                 a_action.color4f(0,0,0,1);
0174                 a_action.line_width(1);
0175                 a_action.draw_gsto_v(gl::lines(),2*npt,pos_edges);
0176                 //pushes back the filled polygons to avoid z-fighting with lines
0177                 a_action.set_polygon_offset(true);
0178 
0179                 a_action.color4f(state.m_color);
0180                 a_action.line_width(state.m_line_width);
0181               }
0182               if(do_back.value()) a_action.draw_gsto_vcn(mode.value(),npt,pos_back_xyzs,pos_rgbas,pos_back_nms);
0183               a_action.draw_gsto_vcn(mode.value(),npt,pos_xyzs,pos_rgbas,pos_nms);
0184               if(draw_edges.value()) a_action.set_polygon_offset(state.m_GL_POLYGON_OFFSET_FILL);
0185             } else {
0186               if(do_back.value()) a_action.draw_gsto_vcn(mode.value(),npt,pos_back_xyzs,pos_rgbas,pos_back_nms);
0187               a_action.draw_gsto_vcn(mode.value(),npt,pos_xyzs,pos_rgbas,pos_nms);
0188             }
0189 
0190           } else {
0191             size_t npt = xyzs.values().size()/3;
0192             bufpos pos_xyzs = 0;
0193             bufpos pos_rgbas = npt*3*sizeof(float);
0194             if(gl::is_line(mode.value())) {
0195               //Same logic as Inventor SoLightModel.model = BASE_COLOR.
0196               a_action.set_lighting(false);
0197               a_action.draw_gsto_vc(mode.value(),npt,pos_xyzs,pos_rgbas);
0198               a_action.set_lighting(state.m_GL_LIGHTING);
0199             } else {
0200               a_action.draw_gsto_vc(mode.value(),npt,pos_xyzs,pos_rgbas);
0201             }
0202           }
0203         } else { //rgbas.empty()
0204           if(nms.size()) {
0205             size_t npt = xyzs.values().size()/3;
0206             bufpos pos_xyzs = 0;
0207             bufpos pos_nms = npt*3*sizeof(float);
0208             if(gl::is_line(mode.value())) {
0209               //Same logic as Inventor SoLightModel.model = BASE_COLOR.
0210               a_action.set_lighting(false);
0211               a_action.draw_gsto_vn(mode.value(),npt,pos_xyzs,pos_nms);
0212               a_action.set_lighting(state.m_GL_LIGHTING);
0213             } else {
0214               a_action.draw_gsto_vn(mode.value(),npt,pos_xyzs,pos_nms);
0215             }
0216           } else {
0217             size_t npt = xyzs.values().size()/3;
0218             bufpos pos = 0;
0219             if(gl::is_line(mode.value())) {
0220               //Same logic as Inventor SoLightModel.model = BASE_COLOR.
0221               a_action.set_lighting(false);
0222               a_action.draw_gsto_v(mode.value(),npt,pos);
0223               a_action.set_lighting(state.m_GL_LIGHTING);
0224             } else {
0225               a_action.draw_gsto_v(mode.value(),npt,pos);
0226             }
0227           }
0228         }
0229         a_action.end_gsto();
0230         return;
0231 
0232       } else { //!_id
0233         // use immediate rendering.
0234       }
0235 
0236     } else {
0237       clean_gstos(&a_action.render_manager());
0238     }
0239 
0240     // immediate rendering :
0241     if(rgbas.size()) {
0242 
0243 
0244       if(nms.size()) {
0245           if(gl::is_line(mode.value())) {
0246             //Same logic as Inventor SoLightModel.model = BASE_COLOR.
0247             a_action.set_lighting(false);
0248             if(do_back.value())
0249               a_action.draw_vertex_color_normal_array(mode.value(),m_back_xyzs,rgbas.values(),m_back_nms);
0250             a_action.draw_vertex_color_normal_array(mode.value(),xyzs.values(),rgbas.values(),nms.values());
0251             a_action.set_lighting(state.m_GL_LIGHTING);
0252           } else if(mode.value()==gl::triangles()) {
0253             if(draw_edges.value()) {
0254               a_action.color4f(0,0,0,1);
0255               a_action.line_width(1);
0256               a_action.draw_vertex_array(gl::lines(),m_edges);
0257               a_action.set_polygon_offset(true);
0258               a_action.color4f(state.m_color);
0259               a_action.line_width(state.m_line_width);
0260             }
0261             if(do_back.value()) a_action.draw_vertex_color_normal_array(mode.value(),m_back_xyzs,rgbas.values(),m_back_nms);
0262             a_action.draw_vertex_color_normal_array(mode.value(),xyzs.values(),rgbas.values(),nms.values());
0263             if(draw_edges.value()) a_action.set_polygon_offset(state.m_GL_POLYGON_OFFSET_FILL);
0264           } else {
0265             if(do_back.value()) a_action.draw_vertex_color_normal_array(mode.value(),m_back_xyzs,rgbas.values(),m_back_nms);
0266             a_action.draw_vertex_color_normal_array(mode.value(),xyzs.values(),rgbas.values(),nms.values());
0267           }
0268 
0269       } else {
0270           if(gl::is_line(mode.value())) {
0271             //Same logic as Inventor SoLightModel.model = BASE_COLOR.
0272             a_action.set_lighting(false);
0273             a_action.draw_vertex_color_array(mode.value(),xyzs.values(),rgbas.values());
0274             a_action.set_lighting(state.m_GL_LIGHTING);
0275           } else {
0276             a_action.draw_vertex_color_array(mode.value(),xyzs.values(),rgbas.values());
0277           }
0278       }
0279 
0280     } else { //rgbas.empty()
0281       if(nms.size()) {
0282           if(gl::is_line(mode.value())) {
0283             //Same logic as Inventor SoLightModel.model = BASE_COLOR.
0284             a_action.set_lighting(false);
0285             a_action.draw_vertex_normal_array(mode.value(),xyzs.values(),nms.values());
0286             a_action.set_lighting(state.m_GL_LIGHTING);
0287           } else {
0288             a_action.draw_vertex_normal_array(mode.value(),xyzs.values(),nms.values());
0289           }
0290       } else {
0291           if(gl::is_line(mode.value())) {
0292             //Same logic as Inventor SoLightModel.model = BASE_COLOR.
0293             a_action.set_lighting(false);
0294             a_action.draw_vertex_array(mode.value(),xyzs.values());
0295             a_action.set_lighting(state.m_GL_LIGHTING);
0296           } else {
0297             a_action.draw_vertex_array(mode.value(),xyzs.values());
0298           }
0299       }
0300 
0301     }
0302 
0303   }
0304 public:
0305   atb_vertices()
0306   :parent()
0307   ,do_back(false)
0308   ,epsilon(0)
0309   ,draw_edges(false)
0310   ,m_xyzs_pos(0)
0311   ,m_rgbas_pos(0)
0312   ,m_nms_pos(0)
0313   ,m_all_a_one(true)
0314   {
0315     add_fields();
0316   }
0317   virtual ~atb_vertices(){
0318   }
0319 public:
0320   atb_vertices(const atb_vertices& a_from)
0321   :parent(a_from)
0322   ,rgbas(a_from.rgbas)
0323   ,nms(a_from.nms)
0324   ,do_back(a_from.do_back)
0325   ,epsilon(a_from.epsilon)
0326   ,draw_edges(a_from.draw_edges)
0327   ,m_xyzs_pos(a_from.m_xyzs_pos)
0328   ,m_rgbas_pos(a_from.m_rgbas_pos)
0329   ,m_nms_pos(a_from.m_nms_pos)
0330   ,m_all_a_one(true)
0331   {
0332     add_fields();
0333   }
0334   atb_vertices& operator=(const atb_vertices& a_from){
0335     parent::operator=(a_from);
0336     rgbas = a_from.rgbas;
0337     nms = a_from.nms;
0338     do_back = a_from.do_back;
0339     epsilon = a_from.epsilon;
0340     draw_edges = a_from.draw_edges;
0341     m_xyzs_pos = a_from.m_xyzs_pos;
0342     m_rgbas_pos = a_from.m_rgbas_pos;
0343     m_nms_pos = a_from.m_nms_pos;
0344     return *this;
0345   }
0346 public:
0347   void add_pos_color(float a_x,float a_y,float a_z,float a_r,float a_g,float a_b,float a_a) {
0348     xyzs.add(a_x);
0349     xyzs.add(a_y);
0350     xyzs.add(a_z);
0351     rgbas.add(a_r);
0352     rgbas.add(a_g);
0353     rgbas.add(a_b);
0354     rgbas.add(a_a);
0355   }
0356 
0357   template <class COLOR>
0358   void add_pos_color(float a_x,float a_y,float a_z,const COLOR& a_col) {
0359     xyzs.add(a_x);
0360     xyzs.add(a_y);
0361     xyzs.add(a_z);
0362     rgbas.add(a_col.r());
0363     rgbas.add(a_col.g());
0364     rgbas.add(a_col.b());
0365     rgbas.add(a_col.a());
0366   }
0367 
0368   template <class VEC,class COLOR>
0369   void add_pos_color(const VEC& a_pos,const COLOR& a_col) {
0370     xyzs.add(a_pos.x());
0371     xyzs.add(a_pos.y());
0372     xyzs.add(a_pos.z());
0373     rgbas.add(a_col.r());
0374     rgbas.add(a_col.g());
0375     rgbas.add(a_col.b());
0376     rgbas.add(a_col.a());
0377   }
0378 
0379   void allocate_pos_color(size_t a_npt) {
0380     xyzs.values().resize(a_npt*3);
0381     rgbas.values().resize(a_npt*4);
0382     m_xyzs_pos = 0;
0383     m_rgbas_pos = 0;
0384   }
0385 
0386   template <class VEC,class COLOR>
0387   void add_pos_color_allocated(const VEC& a_pos,const COLOR& a_col) {
0388    {std::vector<float>& v = xyzs.values();
0389     v[m_xyzs_pos] = a_pos.x();m_xyzs_pos++;
0390     v[m_xyzs_pos] = a_pos.y();m_xyzs_pos++;
0391     v[m_xyzs_pos] = a_pos.z();m_xyzs_pos++;
0392     xyzs.touch();}
0393    {std::vector<float>& v = rgbas.values();
0394     v[m_rgbas_pos] = a_col.r();m_rgbas_pos++;
0395     v[m_rgbas_pos] = a_col.g();m_rgbas_pos++;
0396     v[m_rgbas_pos] = a_col.b();m_rgbas_pos++;
0397     v[m_rgbas_pos] = a_col.a();m_rgbas_pos++;
0398     rgbas.touch();}
0399   }
0400 
0401   template <class VEC,class COLOR>
0402   void add_pos_color_normal(const VEC& a_pos,const COLOR& a_col,const VEC& a_nm) {
0403     xyzs.add(a_pos.x());
0404     xyzs.add(a_pos.y());
0405     xyzs.add(a_pos.z());
0406     rgbas.add(a_col.r());
0407     rgbas.add(a_col.g());
0408     rgbas.add(a_col.b());
0409     rgbas.add(a_col.a());
0410     nms.add(a_nm.x());
0411     nms.add(a_nm.y());
0412     nms.add(a_nm.z());
0413   }
0414 
0415   void allocate_pos_color_normal(size_t a_npt) {
0416     xyzs.values().resize(a_npt*3);
0417     rgbas.values().resize(a_npt*4);
0418     nms.values().resize(a_npt*3);
0419     m_xyzs_pos = 0;
0420     m_rgbas_pos = 0;
0421     m_nms_pos = 0;
0422   }
0423 
0424   template <class VEC,class COLOR>
0425   void add_pos_color_normal_allocated(const VEC& a_pos,const COLOR& a_col,const VEC& a_nm) {
0426    {std::vector<float>& v = xyzs.values();
0427     v[m_xyzs_pos] = a_pos.x();m_xyzs_pos++;
0428     v[m_xyzs_pos] = a_pos.y();m_xyzs_pos++;
0429     v[m_xyzs_pos] = a_pos.z();m_xyzs_pos++;
0430     xyzs.touch();}
0431    {std::vector<float>& v = rgbas.values();
0432     v[m_rgbas_pos] = a_col.r();m_rgbas_pos++;
0433     v[m_rgbas_pos] = a_col.g();m_rgbas_pos++;
0434     v[m_rgbas_pos] = a_col.b();m_rgbas_pos++;
0435     v[m_rgbas_pos] = a_col.a();m_rgbas_pos++;
0436     rgbas.touch();}
0437    {std::vector<float>& v = nms.values();
0438     v[m_nms_pos] = a_nm.x();m_nms_pos++;
0439     v[m_nms_pos] = a_nm.y();m_nms_pos++;
0440     v[m_nms_pos] = a_nm.z();m_nms_pos++;
0441     nms.touch();}
0442   }
0443 
0444   void add_rgba(float a_r,float a_g,float a_b,float a_a) {
0445     rgbas.add(a_r);
0446     rgbas.add(a_g);
0447     rgbas.add(a_b);
0448     rgbas.add(a_a);
0449   }
0450   void add_color(const colorf& a_col) {
0451     rgbas.add(a_col.r());
0452     rgbas.add(a_col.g());
0453     rgbas.add(a_col.b());
0454     rgbas.add(a_col.a());
0455   }
0456 
0457   void add_normal(float a_x,float a_y,float a_z) {
0458     nms.add(a_x);
0459     nms.add(a_y);
0460     nms.add(a_z);
0461   }
0462   template <class VEC>
0463   void add_normal(const VEC& a_nm) {
0464     nms.add(a_nm.x());
0465     nms.add(a_nm.y());
0466     nms.add(a_nm.z());
0467   }
0468 
0469   void add_rgba_allocated(size_t& a_pos,float a_r,float a_g,float a_b,float a_a) {
0470     std::vector<float>& v = rgbas.values();
0471     v[a_pos] = a_r;a_pos++;
0472     v[a_pos] = a_g;a_pos++;
0473     v[a_pos] = a_b;a_pos++;
0474     v[a_pos] = a_a;a_pos++;
0475     rgbas.touch();
0476   }
0477   void add_normal_allocated(size_t& a_pos,float a_x,float a_y,float a_z) {
0478     std::vector<float>& v = nms.values();
0479     v[a_pos] = a_x;a_pos++;
0480     v[a_pos] = a_y;a_pos++;
0481     v[a_pos] = a_z;a_pos++;
0482     nms.touch();
0483   }
0484 
0485   template <class VEC>
0486   void add_pos_normal(const VEC& a_pos,const VEC& a_nm) {
0487     xyzs.add(a_pos.x());
0488     xyzs.add(a_pos.y());
0489     xyzs.add(a_pos.z());
0490     nms.add(a_nm.x());
0491     nms.add(a_nm.y());
0492     nms.add(a_nm.z());
0493   }
0494 
0495   bool add_dashed_line_rgba(float a_bx,float a_by,float a_bz,
0496                             float a_ex,float a_ey,float a_ez,
0497                             unsigned int a_num_dash,
0498                             float a_r,float a_g,float a_b,float a_a) {
0499     if(!parent::add_dashed_line(a_bx,a_by,a_bz,a_ex,a_ey,a_ez,a_num_dash)) return false;
0500     for(unsigned int index=0;index<a_num_dash;index++) {
0501       add_rgba(a_r,a_g,a_b,a_a);
0502       add_rgba(a_r,a_g,a_b,a_a);
0503     }
0504     return true;
0505   }
0506 
0507   void clear() {
0508     rgbas.clear();
0509     nms.clear();
0510     parent::clear();
0511   }
0512 protected:
0513   bool have_to_render(render_action& a_action) {
0514     bool transparent = false;
0515     if(rgbas.size()) {
0516       if(!m_all_a_one) transparent = true;
0517     } else {
0518       if(a_action.state().m_color.a()!=1) transparent = true;
0519     }
0520     if(transparent) {
0521       if(a_action.do_transparency()) return true;
0522       a_action.set_have_to_do_transparency(true);
0523       return false;
0524     } else {
0525       if(a_action.do_transparency()) return false;
0526     }
0527     return true;
0528   }
0529     
0530   void gen_back(){
0531     m_back_xyzs.clear();
0532     m_back_nms.clear();
0533 
0534     clean_gstos(); //must reset for all render_manager.
0535 
0536     std::vector<float>& _xyzs = xyzs.values();
0537     std::vector<float>& _nms = nms.values();
0538 
0539     if(_xyzs.empty()) return;
0540 
0541     m_back_xyzs.resize(_xyzs.size(),0);
0542     m_back_nms.resize(_nms.size(),0);
0543 
0544     float epsil = epsilon.value();
0545 
0546     if(mode.value()==gl::triangle_fan()) { //reverse after first point.
0547 
0548       m_back_xyzs[0] = _xyzs[0] - _nms[0] * epsil;
0549       m_back_xyzs[1] = _xyzs[1] - _nms[1] * epsil;
0550       m_back_xyzs[2] = _xyzs[2] - _nms[2] * epsil;
0551 
0552      {std::vector<float>::const_iterator it = _xyzs.begin()+3;
0553       std::vector<float>::const_iterator _end = _xyzs.end();
0554       std::vector<float>::const_iterator itn = _nms.begin()+3;
0555       std::vector<float>::reverse_iterator it2 = m_back_xyzs.rbegin();
0556       for(;it!=_end;it2+=3) {
0557         *(it2+2) = *it - *itn * epsil; it++;itn++; //x
0558         *(it2+1) = *it - *itn * epsil; it++;itn++; //y
0559         *(it2+0) = *it - *itn * epsil; it++;itn++; //z
0560       }}
0561 
0562       m_back_nms[0] = _nms[0] * -1.0f;
0563       m_back_nms[1] = _nms[1] * -1.0f;
0564       m_back_nms[2] = _nms[2] * -1.0f;
0565 
0566      {std::vector<float>::const_iterator it = _nms.begin()+3;
0567       std::vector<float>::const_iterator _end = _nms.end();
0568       std::vector<float>::reverse_iterator it2 = m_back_nms.rbegin();
0569       for(;it!=_end;it2+=3) {
0570         *(it2+2) = *it * -1.0f; it++;
0571         *(it2+1) = *it * -1.0f; it++;
0572         *(it2+0) = *it * -1.0f; it++;
0573       }}
0574 
0575     } else {
0576 
0577      {std::vector<float>::const_iterator it = _xyzs.begin();
0578       std::vector<float>::const_iterator _end = _xyzs.end();
0579       std::vector<float>::const_iterator itn = _nms.begin();
0580       std::vector<float>::reverse_iterator it2 = m_back_xyzs.rbegin();
0581       for(;it!=_end;it2+=3) {
0582         *(it2+2) = *it - *itn * epsil; it++;itn++; //x
0583         *(it2+1) = *it - *itn * epsil; it++;itn++; //y
0584         *(it2+0) = *it - *itn * epsil; it++;itn++; //z
0585       }}
0586 
0587      {std::vector<float>::const_iterator it = _nms.begin();
0588       std::vector<float>::const_iterator _end = _nms.end();
0589       std::vector<float>::reverse_iterator it2 = m_back_nms.rbegin();
0590       for(;it!=_end;it2+=3) {
0591         *(it2+2) = *it * -1.0f; it++;
0592         *(it2+1) = *it * -1.0f; it++;
0593         *(it2+0) = *it * -1.0f; it++;
0594       }}
0595 
0596     }
0597   }
0598 
0599   void gen_edges(){
0600     m_edges.clear();
0601 
0602     clean_gstos(); //must reset for all render_manager.
0603 
0604     std::vector<float>& _xyzs = xyzs.values();
0605     if(_xyzs.empty()) return;
0606 
0607     m_edges.resize(2*_xyzs.size(),0);
0608 
0609     float* pxyz = xyzs.values().data();
0610     float* pedges = m_edges.data();
0611 
0612     size_t npt = xyzs.values().size()/3;
0613     size_t ntri = npt/3;
0614     for(size_t itri=0;itri<ntri;itri++) {
0615       // first edge :
0616       *pedges = *(pxyz+0);pedges++;
0617       *pedges = *(pxyz+1);pedges++;
0618       *pedges = *(pxyz+2);pedges++;
0619 
0620       *pedges = *(pxyz+3);pedges++;
0621       *pedges = *(pxyz+4);pedges++;
0622       *pedges = *(pxyz+5);pedges++;
0623 
0624       // second edge :
0625       *pedges = *(pxyz+3);pedges++;
0626       *pedges = *(pxyz+4);pedges++;
0627       *pedges = *(pxyz+5);pedges++;
0628 
0629       *pedges = *(pxyz+6);pedges++;
0630       *pedges = *(pxyz+7);pedges++;
0631       *pedges = *(pxyz+8);pedges++;
0632 
0633       // third edge :
0634       *pedges = *(pxyz+6);pedges++;
0635       *pedges = *(pxyz+7);pedges++;
0636       *pedges = *(pxyz+8);pedges++;
0637 
0638       *pedges = *(pxyz+0);pedges++;
0639       *pedges = *(pxyz+1);pedges++;
0640       *pedges = *(pxyz+2);pedges++;
0641 
0642       pxyz += 9;
0643     }
0644   }
0645 protected:
0646   std::vector<float> m_back_xyzs;
0647   std::vector<float> m_back_nms;
0648   std::vector<float> m_edges;
0649 protected:
0650   size_t m_xyzs_pos;
0651   size_t m_rgbas_pos;
0652   size_t m_nms_pos;
0653   bool m_all_a_one;
0654 };
0655 
0656 }}
0657 
0658 #endif