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