Geant4  10.01.p03
SoMarkerSet.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 #ifdef G4VIS_BUILD_OI_DRIVER
27 
28 /*----------------------------HEPVis----------------------------------------*/
29 /* */
30 /* Node: SoMarkerSet */
31 /* Author: Guy Barrand */
32 /* */
33 /*--------------------------------------------------------------------------*/
34 
35 // this :
36 #include <HEPVis/nodes/SoMarkerSet.h>
37 
38 #include <Inventor/errors/SoDebugError.h>
39 #include <Inventor/misc/SoState.h>
40 #include <Inventor/actions/SoGLRenderAction.h>
41 #include <Inventor/nodes/SoPointSet.h>
42 
43 #include <Inventor/elements/SoCoordinateElement.h>
44 #include <Inventor/elements/SoCacheElement.h>
45 #include <Inventor/elements/SoLazyElement.h>
46 
47 #include <HEPVis/SbGL.h>
48 #include <HEPVis/actions/SoGL2PSAction.h>
49 
50 static void drawMarker(SoAction*,int);
51 static GLubyte* getBitmap(int,int,char []);
52 
53 /*
54  " x "
55  " x "
56  "xxxxx"
57  " x "
58  " x "
59 
60  Should produce bitmap :
61  0x20,0x20,0xf8,0x20,0x20
62 
63  The rows will be rendered down to top ; first row at bottom, last at top.
64  In the below, '-' means that glBitmap will move the pointer to next byte.
65 
66  32103210 32103210 32103210 32103210 32103210
67  ..1..--- ..1..--- 11111--- ..1..--- ..1..---
68 
69  0x20 0x20 0xf8 0x20 0x20
70 */
71 
75 static char plus_5_5[] = {
76  " x "
77  " x "
78  "xxxxx"
79  " x "
80  " x "
81 };
82 static char asterisk_5_5[] = {
83  "x x x"
84  " xxx "
85  " x "
86  " xxx "
87  "x x x"
88 };
89 static char cross_5_5[] = {
90  "x x"
91  " x x "
92  " x "
93  " x x "
94  "x x"
95 };
96 static char star_5_5[] = {
97  "x x x"
98  " xxx "
99  "xxxxx"
100  " xxx "
101  "x x x"
102 };
103 static char circle_line_5_5[] = {
104  " xxx "
105  "x x"
106  "x x"
107  "x x"
108  " xxx "
109 };
110 static char circle_filled_5_5[] = {
111  " xxx "
112  "xxxxx"
113  "xxxxx"
114  "xxxxx"
115  " xxx "
116 };
117 static char triangle_up_line_5_5[] = { //OpenGL will draw with y reversed.
118  "xxxxx"
119  " x x "
120  " x x "
121  " x "
122  " x "
123 };
124 static char triangle_up_filled_5_5[] = {
125  "xxxxx"
126  " xxx "
127  " xxx "
128  " x "
129  " x "
130 };
131 static char triangle_down_line_5_5[] = {
132  " x "
133  " x "
134  " x x "
135  " x x "
136  "xxxxx"
137 };
138 static char triangle_down_filled_5_5[] = {
139  " x "
140  " x "
141  " xxx "
142  " xxx "
143  "xxxxx"
144 };
145 static char david_star_line_5_5[] = {
146  " x "
147  "xxxxx"
148  " x x "
149  "xxxxx"
150  " x "
151 };
152 static char david_star_filled_5_5[] = {
153  " x "
154  "xxxxx"
155  " xxx "
156  "xxxxx"
157  " x "
158 };
159 static char swiss_cross_line_5_5[] = {
160  " xxx "
161  "xx xx"
162  "x x"
163  "xx xx"
164  " xxx "
165 };
166 static char swiss_cross_filled_5_5[] = {
167  " xxx "
168  "xxxxx"
169  "xxxxx"
170  "xxxxx"
171  " xxx "
172 };
173 static char diamond_line_5_5[] = {
174  " x "
175  " x x "
176  "x x"
177  " x x "
178  " x "
179 };
180 static char diamond_filled_5_5[] = {
181  " x "
182  " xxx "
183  "xxxxx"
184  " xxx "
185  " x "
186 };
187 static char square_line_5_5[] = {
188  "xxxxx"
189  "x x"
190  "x x"
191  "x x"
192  "xxxxx"
193 };
194 static char square_filled_5_5[] = {
195  "xxxxx"
196  "xxxxx"
197  "xxxxx"
198  "xxxxx"
199  "xxxxx"
200 };
204 static char plus_7_7[] = {
205  " x "
206  " x "
207  " x "
208  "xxxxxxx"
209  " x "
210  " x "
211  " x "
212 };
213 static char asterisk_7_7[] = {
214  "x x x"
215  " x x x "
216  " xxx "
217  " x "
218  " xxx "
219  " x x x "
220  "x x x"
221 };
222 static char cross_7_7[] = {
223  "x x"
224  " x x "
225  " xxx "
226  " x "
227  " xxx "
228  " x x "
229  "x x"
230 };
231 static char star_7_7[] = {
232  "x x x"
233  " x x x "
234  " xxx "
235  "xxxxxxx"
236  " xxx "
237  " x x x "
238  "x x x"
239 };
240 static char circle_line_7_7[] = {
241  " xxxxx "
242  "x x"
243  "x x"
244  "x x"
245  "x x"
246  "x x"
247  " xxxxx "
248 };
249 static char circle_filled_7_7[] = {
250  " xxxxx "
251  "xxxxxxx"
252  "xxxxxxx"
253  "xxxxxxx"
254  "xxxxxxx"
255  "xxxxxxx"
256  " xxxxx "
257 };
258 static char triangle_up_line_7_7[] = { //OpenGL will draw with y reversed.
259  "xxxxxxx"
260  " x x "
261  " x x "
262  " x x "
263  " x x "
264  " x "
265  " x "
266 };
267 static char triangle_up_filled_7_7[] = {
268  "xxxxxxx"
269  " xxxxx "
270  " xxxxx "
271  " xxx "
272  " xxx "
273  " x "
274  " x "
275 };
276 static char triangle_down_line_7_7[] = {
277  " x "
278  " x "
279  " x x "
280  " x x "
281  " x x "
282  " x x "
283  "xxxxxxx"
284 };
285 static char triangle_down_filled_7_7[] = {
286  " x "
287  " x "
288  " xxx "
289  " xxx "
290  " xxxxx "
291  " xxxxx "
292  "xxxxxxx"
293 };
294 static char david_star_line_7_7[] = {
295  " x "
296  "xxxxxxx"
297  " x x "
298  " x x "
299  " x x "
300  "xxxxxxx"
301  " x "
302 };
303 static char david_star_filled_7_7[] = {
304  " x "
305  "xxxxxxx"
306  " xxxxx "
307  " xxx "
308  " xxxxx "
309  "xxxxxxx"
310  " x "
311 };
312 static char swiss_cross_line_7_7[] = {
313  " xxx "
314  " x x "
315  "xxx xxx"
316  "x x"
317  "xxx xxx"
318  " x x "
319  " xxx "
320 };
321 static char swiss_cross_filled_7_7[] = {
322  " xxx "
323  " xxx "
324  "xxxxxxx"
325  "xxxxxxx"
326  "xxxxxxx"
327  " xxx "
328  " xxx "
329 };
330 static char diamond_line_7_7[] = {
331  " x "
332  " x x "
333  " x x "
334  "x x"
335  " x x "
336  " x x "
337  " x "
338 };
339 static char diamond_filled_7_7[] = {
340  " x "
341  " xxx "
342  " xxxxx "
343  "xxxxxxx"
344  " xxxxx "
345  " xxx "
346  " x "
347 };
348 static char square_line_7_7[] = {
349  "xxxxxxx"
350  "x x"
351  "x x"
352  "x x"
353  "x x"
354  "x x"
355  "xxxxxxx"
356 };
357 static char square_filled_7_7[] = {
358  "xxxxxxx"
359  "xxxxxxx"
360  "xxxxxxx"
361  "xxxxxxx"
362  "xxxxxxx"
363  "xxxxxxx"
364  "xxxxxxx"
365 };
366 
370 static char plus_9_9[] = {
371  " x "
372  " x "
373  " x "
374  " x "
375  "xxxxxxxxx"
376  " x "
377  " x "
378  " x "
379  " x "
380 };
381 static char asterisk_9_9[] = {
382  "x x x"
383  " x x x "
384  " x x x "
385  " xxx "
386  " x "
387  " xxx "
388  " x x x "
389  " x x x "
390  "x x x"
391 };
392 static char cross_9_9[] = {
393  "x x"
394  " x x "
395  " x x "
396  " x x "
397  " x "
398  " x x "
399  " x x "
400  " x x "
401  "x x"
402 };
403 static char star_9_9[] = {
404  "x x x"
405  " x x x "
406  " x x x "
407  " xxx "
408  "xxxxxxxxx"
409  " xxx "
410  " x x x "
411  " x x x "
412  "x x x"
413 };
414 static char circle_line_9_9[] = {
415  " xxx "
416  " xx xx "
417  " x x "
418  "x x"
419  "x x"
420  "x x"
421  " x x "
422  " xx xx "
423  " xxx "
424 };
425 static char circle_filled_9_9[] = {
426  " xxx "
427  " xxxxxxx "
428  " xxxxxxx "
429  "xxxxxxxxx"
430  "xxxxxxxxx"
431  "xxxxxxxxx"
432  " xxxxxxx "
433  " xxxxxxx "
434  " xxx "
435 };
436 static char triangle_up_line_9_9[] = { //OpenGL will draw with y reversed.
437  "xxxxxxxxx"
438  " x x "
439  " x x "
440  " x x "
441  " x x "
442  " x x "
443  " x x "
444  " x "
445  " x "
446 };
447 static char triangle_up_filled_9_9[] = {
448  "xxxxxxxxx"
449  " xxxxxxx "
450  " xxxxxxx "
451  " xxxxx "
452  " xxxxx "
453  " xxx "
454  " xxx "
455  " x "
456  " x "
457 };
458 static char triangle_down_line_9_9[] = {
459  " x "
460  " x "
461  " x x "
462  " x x "
463  " x x "
464  " x x "
465  " x x "
466  " x x "
467  "xxxxxxxxx"
468 };
469 static char triangle_down_filled_9_9[] = {
470  " x "
471  " x "
472  " xxx "
473  " xxx "
474  " xxxxx "
475  " xxxxx "
476  " xxxxxxx "
477  " xxxxxxx "
478  "xxxxxxxxx"
479 };
480 static char david_star_line_9_9[] = {
481  " x "
482  " x x "
483  "xxxxxxxxx"
484  " x x "
485  " x x "
486  " x x "
487  "xxxxxxxxx"
488  " x x "
489  " x "
490 };
491 static char david_star_filled_9_9[] = {
492  " x "
493  " xxx "
494  "xxxxxxxxx"
495  " xxxxxxx "
496  " xxxxx "
497  " xxxxxxx "
498  "xxxxxxxxx"
499  " xxx "
500  " x "
501 };
502 static char swiss_cross_line_9_9[] = {
503  " xxx "
504  " x x "
505  " x x "
506  "xxxx xxxx"
507  "x x"
508  "xxxx xxxx"
509  " x x "
510  " x x "
511  " xxx "
512 };
513 static char swiss_cross_filled_9_9[] = {
514  " xxx "
515  " xxx "
516  " xxx "
517  "xxxxxxxxx"
518  "xxxxxxxxx"
519  "xxxxxxxxx"
520  " xxx "
521  " xxx "
522  " xxx "
523 };
524 static char diamond_line_9_9[] = {
525  " x "
526  " x x "
527  " x x "
528  " x x "
529  "x x"
530  " x x "
531  " x x "
532  " x x "
533  " x "
534 };
535 static char diamond_filled_9_9[] = {
536  " x "
537  " xxx "
538  " xxxxx "
539  " xxxxxxx "
540  "xxxxxxxxx"
541  " xxxxxxx "
542  " xxxxx "
543  " xxx "
544  " x "
545 };
546 static char square_line_9_9[] = {
547  "xxxxxxxxx"
548  "x x"
549  "x x"
550  "x x"
551  "x x"
552  "x x"
553  "x x"
554  "x x"
555  "xxxxxxxxx"
556 };
557 static char square_filled_9_9[] = {
558  "xxxxxxxxx"
559  "xxxxxxxxx"
560  "xxxxxxxxx"
561  "xxxxxxxxx"
562  "xxxxxxxxx"
563  "xxxxxxxxx"
564  "xxxxxxxxx"
565  "xxxxxxxxx"
566  "xxxxxxxxx"
567 };
568 
569 static char* sFigures[54] = {
570  plus_5_5, //0
571  asterisk_5_5,
572  cross_5_5,
573  star_5_5,
574  circle_line_5_5,
575  circle_filled_5_5,
576  triangle_up_line_5_5,
577  triangle_up_filled_5_5,
578  triangle_down_line_5_5,
579  triangle_down_filled_5_5,
580  david_star_line_5_5,
581  david_star_filled_5_5,
582  swiss_cross_line_5_5,
583  swiss_cross_filled_5_5,
584  diamond_line_5_5,
585  diamond_filled_5_5,
586  square_line_5_5,
587  square_filled_5_5, //17
588  plus_7_7,
589  asterisk_7_7,
590  cross_7_7,
591  star_7_7,
592  circle_line_7_7,
593  circle_filled_7_7,
594  triangle_up_line_7_7,
595  triangle_up_filled_7_7,
596  triangle_down_line_7_7,
597  triangle_down_filled_7_7,
598  david_star_line_7_7,
599  david_star_filled_7_7,
600  swiss_cross_line_7_7,
601  swiss_cross_filled_7_7,
602  diamond_line_7_7,
603  diamond_filled_7_7,
604  square_line_7_7,
605  square_filled_7_7, //35
606  plus_9_9,
607  asterisk_9_9,
608  cross_9_9,
609  star_9_9,
610  circle_line_9_9,
611  circle_filled_9_9,
612  triangle_up_line_9_9,
613  triangle_up_filled_9_9,
614  triangle_down_line_9_9,
615  triangle_down_filled_9_9,
616  david_star_line_9_9,
617  david_star_filled_9_9,
618  swiss_cross_line_9_9,
619  swiss_cross_filled_9_9,
620  diamond_line_9_9,
621  diamond_filled_9_9,
622  square_line_9_9,
623  square_filled_9_9 //53
624 };
625 
626 SO_NODE_SOURCE(HEPVis_SoMarkerSet)
628 void HEPVis_SoMarkerSet::initClass (
629 )
632 {
633  SO_NODE_INIT_CLASS(HEPVis_SoMarkerSet,SoPointSet,"PointSet");
634 }
636 HEPVis_SoMarkerSet::HEPVis_SoMarkerSet (
637 )
640 {
641  SO_NODE_CONSTRUCTOR(HEPVis_SoMarkerSet);
642 
643  SO_NODE_ADD_FIELD(markerIndex,(CROSS_5_5));
644 }
646 HEPVis_SoMarkerSet::~HEPVis_SoMarkerSet (
647 )
650 {
651 }
653 void HEPVis_SoMarkerSet::GLRender (
654  SoGLRenderAction* aAction
655 )
658 {
659  SoState* state = aAction->getState();
660 
661  const SoCoordinateElement* coordinateElement =
662  SoCoordinateElement::getInstance(state);
663  if(coordinateElement==NULL) return;
664 
665  if(aAction->isOfType(SoGL2PSAction::getClassTypeId())) {
666  SoCacheElement::invalidate(state);
667  }
668 
669  const SbColor& color = SoLazyElement::getDiffuse(aAction->getState(),0);
670  float red,green,blue;
671  color.getValue(red,green,blue);
672 
673  int mark = markerIndex[0];
674 
675  int starti = startIndex.getValue();
676  int pointn = numPoints.getValue();
677  int pointi;
678 
679  glPushAttrib( (GLbitfield)(GL_CURRENT_BIT | GL_ENABLE_BIT));
680  glDisable(GL_LIGHTING);
681  glColor3f(red,green,blue);
682 
683 #ifdef WIN32
684  //WIN32 : depth test is out over bitmap !
685  glDisable(GL_DEPTH_TEST);
686 #endif
687 
688  glPixelStorei(GL_UNPACK_ALIGNMENT,1);
689  for(pointi=starti;pointi<pointn;pointi++){
690  const SbVec3f& vec = coordinateElement->get3(pointi);
691  glRasterPos3f(vec[0],vec[1],vec[2]);
692  // Do a push, pop to correct a deffect of Mesa-3.1.
693  // If not, further line drawing will have bad colors.
694  // The glPopAttrib will compell a reinitialisation of
695  // some internal Mesa state.
696  //glPushAttrib(GL_ALL_ATTRIB_BITS);
697  //glPopAttrib();
698  //
699  drawMarker(aAction,mark);
700  }
701 
702  glPopAttrib();
703 }
705 void drawMarker(
706  SoAction* aAction
707 ,int aStyle
708 )
711 {
712  GLsizei w = 0,h = 0;
713  GLfloat xorig = 0,yorig = 0;
714  GLfloat xmove = 0,ymove = 0;
715 
716  if((aStyle>=0)&&(aStyle<18)) {
717  w = h = 5;
718  xorig = yorig = 2;
719  GLubyte* bitmap = getBitmap(w,h,sFigures[aStyle]);
720  glBitmap(w,h,xorig,yorig,0.,0.,bitmap);
721  delete [] bitmap;
722  } else if((aStyle>=18)&&(aStyle<36)) {
723  w = h = 7;
724  xorig = yorig = 3;
725  GLubyte* bitmap = getBitmap(w,h,sFigures[aStyle]);
726  glBitmap(w,h,xorig,yorig,0.,0.,bitmap);
727  delete [] bitmap;
728  } else if((aStyle>=36)&&(aStyle<54)) {
729  w = h = 9;
730  xorig = yorig = 4;
731  GLubyte* bitmap = getBitmap(w,h,sFigures[aStyle]);
732  glBitmap(w,h,xorig,yorig,0.,0.,bitmap);
733  delete [] bitmap;
734  } else {
735  return;
736  }
737 
738  if(aAction->isOfType(SoGL2PSAction::getClassTypeId())) {
739  ((SoGL2PSAction*)aAction)->addBitmap(w,h,xorig,yorig,xmove,ymove);
740  }
741 
742 }
744 GLubyte* getBitmap(
745  int aW
746 ,int aH
747 ,char aFigure[]
748 )
749 {
752  int index = 0;
753  GLubyte* bitmap = new GLubyte[aW * aH + 1];
754  int ichar = 0;
755  int ibit = 0;
756  unsigned char byte = 0;
757  for ( int row = 0; row < aH; row++ ){
758  for ( int col = 0; col < aW; col++){
759  unsigned char c = aFigure[ichar];
760  ichar++;
761  if(c==' ') {
762  ibit++;
763  } else {
764  byte += (1<<(7-ibit));
765  ibit++;
766  }
767  if(ibit==8) {
768  //unsigned char h = byte / 16;
769  //unsigned char l = byte % 16;
770  //printf("0x%x%x\n",h,l);
771  bitmap[index] = byte;
772  index++;
773  ibit = 0;
774  byte = 0;
775  }
776 
777  }
778  if(ibit!=8) { //Jump to next byte.
779  //unsigned char h = byte / 16;
780  //unsigned char l = byte % 16;
781  //printf("0x%x%x\n",h,l);
782  bitmap[index] = byte;
783  index++;
784  ibit = 0;
785  byte = 0;
786  }
787  }
788  return bitmap;
789 }
790 
791 #endif
Definition: test07.cc:36
Definition: test07.cc:36