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