Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/g4tools/include/tools/sg/markers

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 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 ]

  1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.
  3 
  4 #ifndef tools_sg_markers
  5 #define tools_sg_markers
  6 
  7 #include "node"
  8 
  9 #include "sf_enum"
 10 #include "mf"
 11 #include "render_action"
 12 #include "pick_action"
 13 #include "bbox_action"
 14 #include "../mathf"
 15 #include "../lina/vec2f"
 16 #include "../lina/geom2"
 17 
 18 namespace tools {
 19 namespace sg {
 20 
 21 class markers : public node {
 22   TOOLS_NODE(markers,tools::sg::markers,node)
 23 public:
 24   sf_enum<marker_style> style;
 25   mf<float> xyzs; //[x,y,z]
 26   sf<float> size; //horizontal size in pixels.
 27 public:
 28   virtual const desc_fields& node_desc_fields() const {
 29     TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::markers)
 30     static const desc_fields s_v(parent::node_desc_fields(),3, //WARNING : take care of count.
 31       TOOLS_ARG_FIELD_DESC(style),
 32       TOOLS_ARG_FIELD_DESC(xyzs),
 33       TOOLS_ARG_FIELD_DESC(size)
 34     );
 35     return s_v;
 36   }
 37 private:
 38   void add_fields(){
 39     add_field(&style);
 40     add_field(&xyzs);
 41     add_field(&size);
 42   }
 43 public:
 44   virtual bool draw_in_frame_buffer() const {return true;}
 45 
 46   virtual void render(render_action& a_action) {
 47     size_t num = xyzs.size()/3;
 48     if(!num) return;
 49 
 50     //NOTE : gstos would not work because of project_point() that must be done at each render().
 51 
 52     const state& state = a_action.state();
 53 
 54     const std::vector<float>& _xyzs = xyzs.values();
 55 
 56     std::vector<float> pts;
 57 
 58     float sx = size.value()/float(state.m_ww); //in [-1,1]
 59     float hsx = sx*0.5f;
 60 
 61     float sy = size.value()/float(state.m_wh); //in [-1,1]
 62     float hsy = sy*0.5f;
 63 
 64     float rad  = hsx;
 65     float hsx2 = hsx*0.5f;
 66     float hsy2 = hsy*0.5f;
 67 
 68     float x,y,z,w;
 69 
 70     bool filled = false;
 71     if(style.value()==marker_circle_line) {
 72       unsigned int segs = 16;
 73       float _cos[16];float _sin[16];
 74       float dtheta = ftwo_pi()/float(segs);
 75       float theta = dtheta;
 76      {for(unsigned int i=0;i<segs;i++,theta+=dtheta) {_cos[i] = rad*fcos(theta);_sin[i] = rad*fsin(theta);}}
 77       float xprev,yprev,xnext,ynext;
 78       std::vector<float>::const_iterator it;
 79       for(it=_xyzs.begin();it!=_xyzs.end();){
 80         x = *it;it++;
 81         y = *it;it++;
 82         z = *it;it++;
 83         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
 84   xprev = x+rad;
 85   yprev = y;
 86         for(unsigned int i=0;i<segs;i++) {
 87           xnext = x+_cos[i];
 88     ynext = y+_sin[i];
 89           _add(pts,xprev,yprev,z);
 90           _add(pts,xnext,ynext,z);
 91     xprev = xnext;
 92     yprev = ynext;
 93         }
 94       }
 95 
 96     } else if(style.value()==marker_circle_filled) {
 97   //} else if((style.value()==marker_circle_filled)||(style.value()==marker_dot)) {
 98       filled = true;
 99       unsigned int segs = 16;
100       float _cos[16];float _sin[16];
101       float dtheta = ftwo_pi()/float(segs);
102       float theta = dtheta;
103      {for(unsigned int i=0;i<segs;i++,theta+=dtheta) {_cos[i] = rad*fcos(theta);_sin[i] = rad*fsin(theta);}}
104       float xprev,yprev,xnext,ynext;
105       std::vector<float>::const_iterator it;
106       for(it=_xyzs.begin();it!=_xyzs.end();){
107         x = *it;it++;
108         y = *it;it++;
109         z = *it;it++;
110         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
111   xprev = x+rad;
112   yprev = y;
113         for(unsigned int i=0;i<segs;i++) {
114           xnext = x+_cos[i];
115     ynext = y+_sin[i];
116           _add(pts,x    ,y    ,z);
117           _add(pts,xprev,yprev,z);
118           _add(pts,xnext,ynext,z);
119     xprev = xnext;
120     yprev = ynext;
121         }
122       }
123 
124     } else if(style.value()==marker_square_line) {
125       std::vector<float>::const_iterator it;
126       for(it=_xyzs.begin();it!=_xyzs.end();){
127         x = *it;it++;
128         y = *it;it++;
129         z = *it;it++;
130         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
131         _add(pts, x-hsx,y-hsy,z);
132         _add(pts, x+hsx,y-hsy,z);
133 
134         _add(pts, x+hsx,y-hsy,z);
135         _add(pts, x+hsx,y+hsy,z);
136 
137         _add(pts, x+hsx,y+hsy,z);
138         _add(pts, x-hsx,y+hsy,z);
139 
140         _add(pts, x-hsx,y+hsy,z);
141         _add(pts, x-hsx,y-hsy,z);
142       }
143   //} else if(style.value()==marker_square_filled) {
144     } else if((style.value()==marker_square_filled)||(style.value()==marker_dot)) {
145       filled = true;
146       std::vector<float>::const_iterator it;
147       for(it=_xyzs.begin();it!=_xyzs.end();){
148         x = *it;it++;
149         y = *it;it++;
150         z = *it;it++;
151         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
152         _add(pts, x-hsx,y-hsy,z);
153         _add(pts, x+hsx,y-hsy,z);
154         _add(pts, x+hsx,y+hsy,z);
155 
156         _add(pts, x-hsx,y-hsy,z);
157         _add(pts, x+hsx,y+hsy,z);
158         _add(pts, x-hsx,y+hsy,z);
159       }
160 
161     } else if(style.value()==marker_triangle_up_line) {
162       std::vector<float>::const_iterator it;
163       for(it=_xyzs.begin();it!=_xyzs.end();){
164         x = *it;it++;
165         y = *it;it++;
166         z = *it;it++;
167         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
168         _add(pts, x-hsx,y-hsy,z);
169         _add(pts, x+hsx,y-hsy,z);
170 
171         _add(pts, x+hsx,y-hsy,z);
172         _add(pts, x    ,y+hsy,z);
173 
174         _add(pts, x    ,y+hsy,z);
175         _add(pts, x-hsx,y-hsy,z);
176       }
177     } else if(style.value()==marker_triangle_up_filled) {
178       filled = true;
179       std::vector<float>::const_iterator it;
180       for(it=_xyzs.begin();it!=_xyzs.end();){
181         x = *it;it++;
182         y = *it;it++;
183         z = *it;it++;
184         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
185         _add(pts, x-hsx,y-hsy,z);
186         _add(pts, x+hsx,y-hsy,z);
187         _add(pts, x    ,y+hsy,z);
188       }
189 
190     } else if(style.value()==marker_triangle_down_line) {
191       std::vector<float>::const_iterator it;
192       for(it=_xyzs.begin();it!=_xyzs.end();){
193         x = *it;it++;
194         y = *it;it++;
195         z = *it;it++;
196         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
197         _add(pts, x-hsx,y+hsy,z);
198         _add(pts, x    ,y-hsy,z);
199 
200         _add(pts, x    ,y-hsy,z);
201   _add(pts, x+hsx,y+hsy,z);
202 
203   _add(pts, x+hsx,y+hsy,z);
204         _add(pts, x-hsx,y+hsy,z);
205       }
206     } else if(style.value()==marker_triangle_down_filled) {
207       filled = true;
208       std::vector<float>::const_iterator it;
209       for(it=_xyzs.begin();it!=_xyzs.end();){
210         x = *it;it++;
211         y = *it;it++;
212         z = *it;it++;
213         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
214         _add(pts, x-hsx,y+hsy,z);
215         _add(pts, x    ,y-hsy,z);
216         _add(pts, x+hsx,y+hsy,z);
217       }
218 
219     } else if(style.value()==marker_diamond_line) {
220       std::vector<float>::const_iterator it;
221       for(it=_xyzs.begin();it!=_xyzs.end();){
222         x = *it;it++;
223         y = *it;it++;
224         z = *it;it++;
225         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
226         _add(pts, x    ,y-hsy,z);
227         _add(pts, x+hsx,    y,z);
228 
229         _add(pts, x+hsx,    y,z);
230         _add(pts, x    ,y+hsy,z);
231 
232         _add(pts, x    ,y+hsy,z);
233   _add(pts, x-hsx,y    ,z);
234 
235   _add(pts, x-hsx,y    ,z);
236         _add(pts, x    ,y-hsy,z);
237       }
238     } else if(style.value()==marker_diamond_filled) {
239       filled = true;
240       std::vector<float>::const_iterator it;
241       for(it=_xyzs.begin();it!=_xyzs.end();){
242         x = *it;it++;
243         y = *it;it++;
244         z = *it;it++;
245         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
246         _add(pts, x    ,y-hsy,z);
247         _add(pts, x+hsx,    y,z);
248         _add(pts, x    ,y+hsy,z);
249 
250         _add(pts, x    ,y+hsy,z);
251         _add(pts, x-hsx,y    ,z);
252         _add(pts, x    ,y-hsy,z);
253       }
254 
255     } else if(style.value()==marker_swiss_cross_line) {
256       std::vector<float>::const_iterator it;
257       for(it=_xyzs.begin();it!=_xyzs.end();){
258         x = *it;it++;
259         y = *it;it++;
260         z = *it;it++;
261         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
262         _add(pts, x-hsx2,y-hsy,z);
263         _add(pts, x+hsx2,y-hsy,z);
264 
265         _add(pts, x+hsx2,y-hsy ,z);
266         _add(pts, x+hsx2,y-hsy2,z);
267 
268         _add(pts, x+hsx2,y-hsy2,z);
269         _add(pts, x+hsx ,y-hsy2,z);
270 
271         _add(pts, x+hsx ,y-hsy2,z);
272         _add(pts, x+hsx ,y+hsy2,z);
273 
274         _add(pts, x+hsx ,y+hsy2,z);
275         _add(pts, x+hsx2,y+hsy2,z);
276 
277         _add(pts, x+hsx2,y+hsy2,z);
278         _add(pts, x+hsx2,y+hsy ,z);
279 
280         _add(pts, x+hsx2,y+hsy ,z);
281         _add(pts, x-hsx2,y+hsy ,z);
282 
283         _add(pts, x-hsx2,y+hsy ,z);
284         _add(pts, x-hsx2,y+hsy2,z);
285 
286         _add(pts, x-hsx2,y+hsy2,z);
287         _add(pts, x-hsx ,y+hsy2,z);
288 
289         _add(pts, x-hsx ,y+hsy2,z);
290         _add(pts, x-hsx ,y-hsy2,z);
291 
292         _add(pts, x-hsx ,y-hsy2,z);
293         _add(pts, x-hsx2,y-hsy2,z);
294 
295         _add(pts, x-hsx2,y-hsy2,z);
296         _add(pts, x-hsx2,y-hsy, z);
297       }
298     } else if(style.value()==marker_swiss_cross_filled) {
299       filled = true;
300       std::vector<float>::const_iterator it;
301       for(it=_xyzs.begin();it!=_xyzs.end();){
302         x = *it;it++;
303         y = *it;it++;
304         z = *it;it++;
305         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
306         _add(pts, x-hsx2,y-hsy,z);
307         _add(pts, x+hsx2,y-hsy,z);
308         _add(pts, x+hsx2,y+hsy,z);
309 
310         _add(pts, x+hsx2,y+hsy,z);
311         _add(pts, x-hsx2,y+hsy,z);
312         _add(pts, x-hsx2,y-hsy,z);
313 
314         _add(pts, x-hsx ,y-hsy2,z);
315         _add(pts, x+hsx ,y-hsy2,z);
316         _add(pts, x+hsx ,y+hsy2,z);
317 
318         _add(pts, x+hsx ,y+hsy2,z);
319         _add(pts, x-hsx ,y+hsy2,z);
320         _add(pts, x-hsx ,y-hsy2,z);
321       }
322 
323     } else if(style.value()==marker_david_star_line) {
324       std::vector<float>::const_iterator it;
325       for(it=_xyzs.begin();it!=_xyzs.end();){
326         x = *it;it++;
327         y = *it;it++;
328         z = *it;it++;
329         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
330         _add(pts, x-hsx,y-hsy2,z);
331         _add(pts, x+hsx,y-hsy2,z);
332 
333         _add(pts, x+hsx,y-hsy2,z);
334         _add(pts, x    ,y+hsy ,z);
335 
336         _add(pts, x    ,y+hsy ,z);
337         _add(pts, x-hsx,y-hsy2,z);
338 
339         _add(pts, x+hsx,y+hsy2,z);
340         _add(pts, x-hsx,y+hsy2,z);
341 
342         _add(pts, x-hsx,y+hsy2,z);
343         _add(pts, x    ,y-hsy ,z);
344 
345         _add(pts, x    ,y-hsy ,z);
346         _add(pts, x+hsx,y+hsy2,z);
347       }
348     } else if(style.value()==marker_david_star_filled) {
349       filled = true;
350       std::vector<float>::const_iterator it;
351       for(it=_xyzs.begin();it!=_xyzs.end();){
352         x = *it;it++;
353         y = *it;it++;
354         z = *it;it++;
355         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
356         _add(pts, x-hsx,y-hsy2,z);
357         _add(pts, x+hsx,y-hsy2,z);
358         _add(pts, x    ,y+hsy ,z);
359 
360         _add(pts, x+hsx,y+hsy2,z);
361         _add(pts, x-hsx,y+hsy2,z);
362         _add(pts, x    ,y-hsy ,z);
363       }
364 
365     } else if(style.value()==marker_penta_star_line) {
366       float _cos[5];float _sin[5];
367       float dtheta = ftwo_pi()/5.0f;
368       float theta = fhalf_pi();
369      {for(unsigned int i=0;i<5;i++,theta+=dtheta) {_cos[i] = rad*fcos(theta);_sin[i] = rad*fsin(theta);}}
370       std::vector<float>::const_iterator it;
371       for(it=_xyzs.begin();it!=_xyzs.end();){
372         x = *it;it++;
373         y = *it;it++;
374         z = *it;it++;
375         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
376         _add(pts, x+_cos[0],y+_sin[0] ,z);
377         _add(pts, x+_cos[2],y+_sin[2] ,z);
378 
379         _add(pts, x+_cos[2],y+_sin[2] ,z);
380         _add(pts, x+_cos[4],y+_sin[4] ,z);
381 
382         _add(pts, x+_cos[4],y+_sin[4] ,z);
383         _add(pts, x+_cos[1],y+_sin[1] ,z);
384 
385         _add(pts, x+_cos[1],y+_sin[1] ,z);
386         _add(pts, x+_cos[3],y+_sin[3] ,z);
387 
388         _add(pts, x+_cos[3],y+_sin[3] ,z);
389         _add(pts, x+_cos[0],y+_sin[0] ,z);
390       }
391     } else if(style.value()==marker_penta_star_filled) {
392       filled = true;
393       float _cos[5];float _sin[5];
394       float dtheta = ftwo_pi()/5.0f;
395       float theta = fhalf_pi();
396      {for(unsigned int i=0;i<5;i++,theta+=dtheta) {_cos[i] = rad*fcos(theta);_sin[i] = rad*fsin(theta);}}
397       vec2f i3;
398      {vec2f p1(_cos[2],_sin[2]);
399       vec2f q1(_cos[4],_sin[4]);
400       vec2f p2(_cos[3],_sin[3]);
401       vec2f q2(_cos[0],_sin[0]);
402       if(!intersect(p1,q1,p2,q2,i3)) {}}
403       vec2f i4;
404      {vec2f p1(_cos[1],_sin[1]);
405       vec2f q1(_cos[4],_sin[4]);
406       vec2f p2(_cos[3],_sin[3]);
407       vec2f q2(_cos[0],_sin[0]);
408       if(!intersect(p1,q1,p2,q2,i4)) {}}
409       vec2f i0;
410      {vec2f p1(_cos[1],_sin[1]);
411       vec2f q1(_cos[4],_sin[4]);
412       vec2f p2(_cos[0],_sin[0]);
413       vec2f q2(_cos[2],_sin[2]);
414       if(!intersect(p1,q1,p2,q2,i0)) {}}
415       std::vector<float>::const_iterator it;
416       for(it=_xyzs.begin();it!=_xyzs.end();){
417         x = *it;it++;
418         y = *it;it++;
419         z = *it;it++;
420         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
421         _add(pts, x+_cos[0],y+_sin[0] ,z);
422         _add(pts, x+_cos[2],y+_sin[2] ,z);
423         _add(pts, x+ i3.x(),y+ i3.y() ,z);
424 
425         _add(pts, x+_cos[1],y+_sin[1] ,z);
426         _add(pts, x+_cos[3],y+_sin[3] ,z);
427         _add(pts, x+ i4.x(),y+ i4.y() ,z);
428 
429         _add(pts, x+ i0.x(),y+ i0.y() ,z);
430         _add(pts, x+_cos[2],y+_sin[2] ,z);
431         _add(pts, x+_cos[4],y+_sin[4] ,z);
432       }
433 
434     } else if(style.value()==marker_plus) {
435       std::vector<float>::const_iterator it;
436       for(it=_xyzs.begin();it!=_xyzs.end();){
437         x = *it;it++;
438         y = *it;it++;
439         z = *it;it++;
440         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
441         _add(pts, x-hsx,y,z);
442         _add(pts, x+hsx,y,z);
443         _add(pts, x    ,y-hsy,z);
444         _add(pts, x    ,y+hsy,z);
445       }
446     } else if(style.value()==marker_asterisk) {
447       std::vector<float>::const_iterator it;
448       for(it=_xyzs.begin();it!=_xyzs.end();){
449         x = *it;it++;
450         y = *it;it++;
451         z = *it;it++;
452         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
453         _add(pts, x    ,y-hsy ,z);
454         _add(pts, x    ,y+hsy ,z);
455         _add(pts, x-hsx,y-hsy2,z);
456         _add(pts, x+hsx,y+hsy2,z);
457         _add(pts, x-hsx,y+hsy2,z);
458         _add(pts, x+hsx,y-hsy2,z);
459       }
460     } else if(style.value()==marker_star) {
461       std::vector<float>::const_iterator it;
462       for(it=_xyzs.begin();it!=_xyzs.end();){
463         x = *it;it++;
464         y = *it;it++;
465         z = *it;it++;
466         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
467         _add(pts, x    ,y-hsy ,z);
468         _add(pts, x    ,y+hsy ,z);
469         _add(pts, x-hsx,y-hsy2,z);
470         _add(pts, x+hsx,y+hsy2,z);
471         _add(pts, x-hsx,y+hsy2,z);
472         _add(pts, x+hsx,y-hsy2,z);
473         _add(pts, x-hsx,y     ,z);
474         _add(pts, x+hsx,y     ,z);
475       }
476     } else if(style.value()==marker_minus) {
477       std::vector<float>::const_iterator it;
478       for(it=_xyzs.begin();it!=_xyzs.end();){
479         x = *it;it++;
480         y = *it;it++;
481         z = *it;it++;
482         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
483         _add(pts, x-hsx,y,z);
484         _add(pts, x+hsx,y,z);
485       }
486     } else { //marker_cross.
487       std::vector<float>::const_iterator it;
488       for(it=_xyzs.begin();it!=_xyzs.end();){
489         x = *it;it++;
490         y = *it;it++;
491         z = *it;it++;
492         a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
493         _add(pts, x-hsx,y-hsy,z);
494         _add(pts, x+hsx,y+hsy,z);
495         _add(pts, x+hsx,y-hsy,z);
496         _add(pts, x-hsx,y+hsy,z);
497       }
498     }
499 
500     a_action.load_matrices_to_identity();
501 
502     //Same logic as Inventor SoLightModel.model = BASE_COLOR.
503     a_action.set_lighting(false);
504     a_action.draw_vertex_array(filled?gl::triangles():gl::lines(),pts);
505     a_action.set_lighting(a_action.state().m_GL_LIGHTING);
506     a_action.load_matrices_from_state();
507   }
508 
509   virtual void pick(pick_action& a_action) {
510     size_t num = xyzs.size()/3;
511     if(!num) return;
512 
513     state& state = a_action.state();
514 
515     const std::vector<float>& _xyzs = xyzs.values();
516 
517     std::vector<float> pts;
518 
519     float sx = size.value()/float(state.m_ww); //in [-1,1]
520     float hsx = sx*0.5f;
521 
522     float sy = size.value()/float(state.m_wh); //in [-1,1]
523     float hsy = sy*0.5f;
524 
525     float x,y,z,w;
526 
527     std::vector<float>::const_iterator it;
528     for(it=_xyzs.begin();it!=_xyzs.end();){
529       x = *it;it++;
530       y = *it;it++;
531       z = *it;it++;
532 
533       a_action.project_point(x,y,z,w); //in [-1,1][-1,1]
534 
535       _add(pts, x-hsx,y-hsy,z);  //in [-1,1][-1,1]
536       _add(pts, x+hsx,y+hsy,z);
537       _add(pts, x+hsx,y-hsy,z);
538       _add(pts, x-hsx,y+hsy,z);
539     }
540 
541     a_action.set_matrices_to_identity();
542     a_action.add__lines(*this,pts);
543     a_action.set_matrices_from_state();
544   }
545 
546   virtual void bbox(bbox_action& a_action) {
547     const std::vector<float>& _xyzs = xyzs.values();
548     float x,y,z;
549     std::vector<float>::const_iterator it;
550     for(it=_xyzs.begin();it!=_xyzs.end();){
551       x = *it;it++;
552       y = *it;it++;
553       z = *it;it++;
554       a_action.add_one_point(x,y,z);
555     }
556   }
557 public:
558   markers()
559   :parent()
560   ,style(marker_cross)
561   ,size(10)
562   {
563 #ifdef TOOLS_MEM
564     mem::increment(s_class().c_str());
565 #endif
566     add_fields();
567   }
568   virtual ~markers(){
569 #ifdef TOOLS_MEM
570     mem::decrement(s_class().c_str());
571 #endif
572   }
573 public:
574   markers(const markers& a_from)
575   :parent(a_from)
576   ,style(a_from.style)
577   ,xyzs(a_from.xyzs)
578   ,size(a_from.size)
579   {
580 #ifdef TOOLS_MEM
581     mem::increment(s_class().c_str());
582 #endif
583     add_fields();
584   }
585   markers& operator=(const markers& a_from){
586     parent::operator=(a_from);
587     style = a_from.style;
588     xyzs = a_from.xyzs;
589     size = a_from.size;
590     return *this;
591   }
592 public:
593   template <class VEC>
594   void add(const VEC& a_v) {
595     xyzs.add(a_v.x());
596     xyzs.add(a_v.y());
597     xyzs.add(a_v.z());
598   }
599   void add(float a_x,float a_y,float a_z) {
600     xyzs.add(a_x);
601     xyzs.add(a_y);
602     xyzs.add(a_z);
603   }
604   void add_allocated(size_t& a_pos,float a_x,float a_y,float a_z) {
605     std::vector<float>& v = xyzs.values();
606     v[a_pos] = a_x;a_pos++;
607     v[a_pos] = a_y;a_pos++;
608     v[a_pos] = a_z;a_pos++;
609     xyzs.touch();
610   }
611   bool add(const std::vector<float>& a_v) {
612     std::vector<float>::size_type _number = a_v.size()/3;
613     if(3*_number!=a_v.size()) return false;
614     std::vector<float>::const_iterator it;
615     for(it=a_v.begin();it!=a_v.end();it+=3) {
616       xyzs.add(*(it+0));
617       xyzs.add(*(it+1));
618       xyzs.add(*(it+2));
619     }
620     return true;
621   }
622   size_t number() const {return xyzs.size()/3;}
623   void clear() {xyzs.clear();}
624 protected:
625   void _add(std::vector<float>& a_v,float a_x,float a_y,float a_z) {
626     a_v.push_back(a_x);
627     a_v.push_back(a_y);
628     a_v.push_back(a_z);
629   }
630 };
631 
632 }}
633 
634 #endif