File: BrainModelOpenGL.h

package info (click to toggle)
caret 5.6.4~dfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 31,904 kB
  • ctags: 28,901
  • sloc: cpp: 378,050; python: 6,718; ansic: 5,507; makefile: 333; sh: 46
file content (945 lines) | stat: -rw-r--r-- 38,434 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
/*LICENSE_START*/
/*
 *  Copyright 1995-2002 Washington University School of Medicine
 *
 *  http://brainmap.wustl.edu
 *
 *  This file is part of CARET.
 *
 *  CARET is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  CARET is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with CARET; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
/*LICENSE_END*/

#ifndef __BRAIN_MODEL_OPENGL_H__
#define __BRAIN_MODEL_OPENGL_H__

#include <vector>

#include <QGLWidget>  // includes OpenGL includes ;)
#include <QMutex>
#include <GL/glu.h>

#include "BorderFile.h"
#include "BrainModel.h"
#include "BrainModelOpenGLSelectedItem.h"
#include "ColorFile.h"
#include "VolumeFile.h"

class BrainModelContours;
class BrainModelSurface;
class BrainModelSurfaceAndVolume;
class BrainModelSurfaceNodeColoring;
class BrainModelVolume;
class BrainSet;
class CellFile;
class CellProjectionFile;
class ContourFile;
class CoordinateFile;
class DisplaySettingsCells;
class QImage;
class TopologyFile;
class VtkModelFile;

/// This class is used to draw BrainModels using OpenGL
class BrainModelOpenGL {
   public:
      /// bitmasks for selecting objects
      enum /* SELECTION_MASK */ {
          SELECTION_MASK_OFF                        =    0,
          SELECTION_MASK_NODE                       =    1,   
          SELECTION_MASK_BORDER                     =    2,
          SELECTION_MASK_CELL_PROJECTION            =    4,
          SELECTION_MASK_FOCUS_PROJECTION           =    8,
          SELECTION_MASK_PALETTE_METRIC            =   16,
          SELECTION_MASK_PALETTE_SHAPE             =   32,
          SELECTION_MASK_CUT                        =   64,
          SELECTION_MASK_CONTOUR                    =   128,
          SELECTION_MASK_CONTOUR_CELL               =  256,   // 2^8
          SELECTION_MASK_VOXEL_UNDERLAY             =  512,
          SELECTION_MASK_VOXEL_OVERLAY_SECONDARY    =  1024,
          SELECTION_MASK_VOXEL_OVERLAY_PRIMARY      = 2048,
          SELECTION_MASK_VOXEL_FUNCTIONAL_CLOUD     = 4096,
          SELECTION_MASK_TILE                       = 8192,
          SELECTION_MASK_LINK                       = 16384,
          SELECTION_MASK_VOLUME_BORDER              = 32768,
          SELECTION_MASK_VOLUME_CELL                = 65536,  // 2^16
          SELECTION_MASK_VOLUME_FOCI                = 131072,
          SELECTION_MASK_TRANSFORMATION_MATRIX_AXES = 262144,
          SELECTION_MASK_VTK_MODEL                  = 524288,
          SELECTION_MASK_TRANSFORM_CELL             = 1048576,
          SELECTION_MASK_TRANSFORM_FOCI             = 2097152,
          SELECTION_MASK_TRANSFORM_CONTOUR_CELL     = 4194304,
          SELECTION_MASK_TRANSFORM_CONTOUR          = 8388608, // 2^23
          SELECTION_MASK_ALL                        = 0xffffffff  // ALL bitmasks ON
      };
      
      /// Constructor
      BrainModelOpenGL();
      
      /// Destructor
      ~BrainModelOpenGL();
      
      /// Draw a brain model for WebCaret
      void drawBrainModelWebCaret(BrainSet* bs,
                                  BrainModel* bm,
                                  const int viewingWindowNumberIn,
                                  const int viewportIn[4]);
      
      /// Draw a brain model
      void drawBrainModel(BrainSet* bs,
                          BrainModel* bm,
                          const int viewingWindowNumberIn,
                          const int viewportIn[4],
                          QGLWidget* glWidgetIn);
      
      /// select something in the brain model for WebCaret
      void selectBrainModelItemWebCaret(BrainSet* bs,
                                        BrainModel* bm,
                                        const int viewportIn[4],
                                        const unsigned long selectionMaskIn,
                                        const int selectionXIn, 
                                        const int selectionYIn);
      
      /// Identify something in the brain model for WebCaret
      QString identifyBrainModelItemWebCaret(BrainSet* bs,
                                        BrainModel* bm,
                                        const int viewingWindowNumberIn,
                                        const int viewportIn[4],
                                        const unsigned long selectionMaskIn,
                                        const int selectionXIn, 
                                        const int selectionYIn,
                                        const bool enableHtml,
                                        const bool enableVocabularyLinks);
      
      /// select something in the brain model           
      void selectBrainModelItem(BrainSet* bs,
                                BrainModel* bm,
                                const int viewingWindowNumberIn,
                                const int viewportIn[4],
                                QGLWidget* glWidgetIn,
                                const unsigned long selectionMaskIn,
                                const int selectionXIn, 
                                const int selectionYIn,
                                const bool viewModeFlag);

      /// identify items in the brain model (returns text for ID display)           
      QString identifyBrainModelItem(BrainSet* bs,
                                     BrainModel* bm,
                                     BrainModel* allWindowBrainModelsForIdentificationIn[BrainModel::NUMBER_OF_BRAIN_MODEL_VIEW_WINDOWS],
                                     const int viewingWindowNumberIn,
                                     const int viewportIn[4],
                                     QGLWidget* glWidgetIn,
                                     const unsigned long selectionMaskIn,
                                     const int selectionXIn, 
                                     const int selectionYIn,
                                     const bool viewModeFlag,
                                     const bool enableHtml,
                                     const bool enableVocabularyLinks);

      
      /// all brain models displayed in windows for identification
      /// ONLY VALID WHEN ::identifyBrainModel... called
      BrainModel* getBrainModelInWindowNumberForIdentification(const int windowNumber);
     
       /// Draw all fiducial surface brain models
      void drawAllFiducialSurfaceBrainModels(std::vector<BrainSet*> brainSets,
                                             const int viewingWindowNumberIn,
                                             const int viewportIn[4],
                                             QGLWidget* glWidgetIn);
      
      /// Get a 3D point on a surface at a screen X/Y.
      bool getSurfacePointAtDisplayXY(BrainSet* bs,
                                    BrainModelSurface* bms,
                                    const int viewingWindowNumberIn,
                                    const int viewportIn[4],
                                    const int displayX, 
                                    const int displayY,
                                    float pointOut[3]);
      
      /// initialize OpenGL (should only call one time)
      void initializeOpenGL(const bool offScreenRenderingFlagIn);
      
      // set the image subregion box/display
      void setImageSubRegion(const int box[4], const bool showFlag);
      
      /// get the editing segmentation volume flag
      bool getEditingSegmentationVolumeFlag() const { return editingSegmentationVolumeFlag; }
      
      /// set the editing segmentation volume flag
      void setEditingSegmentationVolumeFlag(const bool b) { editingSegmentationVolumeFlag = b; }

      /// get the editing paint volume flag
      bool getEditingPaintVolumeFlag() const { return editingPaintVolumeFlag; }
      
      /// set the editing paint volume flag
      void setEditingPaintVolumeFlag(const bool b) { editingPaintVolumeFlag = b; }

      /// get the orthographic size
      void getOrtho(float& orthoRight, float& orthoTop) const;
      
      /// Update the orthographic window size.
      void updateOrthoSize(const int windowNumber, const int width, const int height);
   
      /// get caption displayed in main window
      QString getMainWindowCaption() const { return mainWindowCaption; }

      /// set caption displayed in main window
      void setMainWindowCaption(const QString& s) { mainWindowCaption = s; }

      /// selected node
      BrainModelOpenGLSelectedItem getSelectedNode() const { return selectedNode; }
       
      /// selected border (first)
      BrainModelOpenGLSelectedItem getSelectedBorder1() const { return selectedBorder1; }
       
      /// selected border (second)
      BrainModelOpenGLSelectedItem getSelectedBorder2() const { return selectedBorder2; }
       
      /// selected border (volume)
      BrainModelOpenGLSelectedItem getSelectedVolumeBorder() const { return selectedVolumeBorder; }
       
      /// selected cell projection
      BrainModelOpenGLSelectedItem getSelectedCellProjection() const { return selectedCellProjection; }
       
      /// selected cell (volume)
      BrainModelOpenGLSelectedItem getSelectedVolumeCell() const { return selectedVolumeCell; }
       
      /// selected cut
      BrainModelOpenGLSelectedItem getSelectedCut() const { return selectedCut; }
       
      /// selected foci projection
      BrainModelOpenGLSelectedItem getSelectedFocusProjection() const { return selectedFocusProjection; }
       
      /// selected foci (volume)
      BrainModelOpenGLSelectedItem getSelectedVolumeFoci() const { return selectedVolumeFoci; }
       
      /// selected palette for metric
      BrainModelOpenGLSelectedItem getSelectedPaletteMetric() const { return selectedPaletteMetric; }
       
      /// selected palette for shape
      BrainModelOpenGLSelectedItem getSelectedPaletteShape() const { return selectedPaletteShape; }
       
      /// selected contour
      BrainModelOpenGLSelectedItem getSelectedContour() const { return selectedContour; }
       
      /// selected contour cell
      BrainModelOpenGLSelectedItem getSelectedContourCell() const { return selectedContourCell; }
       
      /// selected voxel underlay
      BrainModelOpenGLSelectedItem getSelectedVoxelUnderlay() const { return selectedVoxelUnderlay; }
       
      /// selected voxel overlay secondary
      BrainModelOpenGLSelectedItem getSelectedVoxelOverlaySecondary() const { return selectedVoxelOverlaySecondary; }
       
      /// selected voxel overlay primary
      BrainModelOpenGLSelectedItem getSelectedVoxelOverlayPrimary() const { return selectedVoxelOverlayPrimary; }
       
      /// selected functional voxel (surface and volume cloud)
      BrainModelOpenGLSelectedItem getSelectedVoxelFunctionalCloud() const { return selectedVoxelFunctionalCloud; }
       
      /// selected surface tile
      BrainModelOpenGLSelectedItem getSelectedSurfaceTile() const { return selectedSurfaceTile; }
       
      /// selected link (index 1 & 2 are nodes)
      BrainModelOpenGLSelectedItem getSelectedLink() const { return selectedLink; }
      
      /// selected transformation axes
      BrainModelOpenGLSelectedItem getSelectedTransformationMatrixAxes() const { return selectedTransformationMatrixAxes; }
      
      /// selected transformation cell
      BrainModelOpenGLSelectedItem getSelectedTransformationCell() const { return selectedTransformCell; }
      
      /// selected transformation foci
      BrainModelOpenGLSelectedItem getSelectedTransformationFoci() const { return selectedTransformFoci; }
      
      /// selected transformation contour
      BrainModelOpenGLSelectedItem getSelectedTransformationContour() const { return selectedTransformContour; }
      
      /// selected transformation contour cell
      BrainModelOpenGLSelectedItem getSelectedTransformationContourCell() const { return selectedTransformContourCell; }
      
      /// selected vtk model
      BrainModelOpenGLSelectedItem getSelectedVtkModel() const { return selectedVtkModel; }
      
      /// get the selection modelview matrix
      GLdouble* getSelectionModelviewMatrix(const int viewWindowNumber)
                        { return selectionModelviewMatrix[viewWindowNumber]; }
      
      /// get the selection projection matrix
      GLdouble* getSelectionProjectionMatrix(const int viewWindowNumber)
                        { return selectionProjectionMatrix[viewWindowNumber]; }
      
      /// get the selection viewport
      GLint* getSelectionViewport(const int viewWindowNumber) 
                        { return selectionViewport[viewWindowNumber]; }
         
      /// Get the dimensions of the surface orthographic projection
      void getOrthographicBox(const int modelViewNumber,
                              double& orthoLeft,   double& orthoRight,
                              double& orthoBottom, double& orthoTop,
                              double& orthoNear,   double& orthoFar) const;
   
      /// set the linear object for drawing borders, cuts, etc.
      void setLinearObject(const Border& lo) { linearObjectBeingDrawn = lo; }
      
      /// set the linear object valid
      void setDrawLinearObjectOnly(const bool loo) { drawLinearObjectOnly = loo; }
      
      /// set node special highlighting
      void setNodeSpecialHighlighting(const std::vector<int>& nsh)
                                      { nodeSpecialHighlighting = nsh; }
      
      /// set OpenGL text enabled
      static void setOpenGLTextEnabled(const bool b) { openGLTextEnabledFlag = b; }
      
      /// get the default ortho right and top for command line scene generation
      static void getDefaultOrthoRightAndTop(const int windowWidthIn,
                                             const int windowHeightIn,
                                             double& orthoRightOut,
                                             double& orthoTopOut);

      /// get minimum/maximum point size
      static void getMinMaxPointSize(float& minSizeOut, float& maxSizeOut);

      /// get minimum/maximum line width
      static void getMinMaxLineWidth(float& minWidthOut, float& maxWidthOut);
                                             
   protected:
      /// Draw a brain model
      void drawBrainModelPrivate(BrainModel* bm,
                          const int viewingWindowNumberIn,
                          const int viewportIn[4],
                          QGLWidget* glWidgetIn);
      
      /// draw contours
      void drawBrainModelContours(BrainModelContours* bmc);
      
      /// draw surface
      void drawBrainModelSurface(BrainModelSurface* bms,
                                 BrainModelSurfaceAndVolume* bmsv,
                                 const bool drawTheSurface,
                                 const bool surfaceInVolumeAllViewFlag);
      
      /// draw surface and volume
      void drawBrainModelSurfaceAndVolume(BrainModelSurfaceAndVolume* bmsv);
      
      /// draw volume
      void drawBrainModelVolume(BrainModelVolume* bmv);
      
      /// draw volume in montage
      void drawBrainModelVolumeMontage(BrainModelVolume* bmv);
      
      /// draw volume with all axis
      void drawBrainModelVolumeAllAxis(BrainModelVolume* bmv);
      
      /// draw volume with oblique axis montage
      void drawBrainModelVolumeObliqueAxisMontage(BrainModelVolume* bmv,
                                                  const bool selectFlag);
      
      /// draw volume with oblique axis
      void drawBrainModelVolumeObliqueAxis(BrainModelVolume* bmv);
      
      /// draw volume with oblique ALL axis
      void drawBrainModelVolumeObliqueAllAxis(BrainModelVolume* bmv);
      
      /// draw volume with oblique axis slice
      void drawBrainModelVolumeObliqueAxisSlice(BrainModelVolume* bmv,
                                                VolumeFile::VOLUME_AXIS axis,
                                                const int montageOffset,
                                                const bool selectFlag);
                                                  
      /// Draw volume crosshairs
      void drawVolumeCrosshairs(BrainModelVolume* bmv,
                                const VolumeFile* vf,
                                const VolumeFile::VOLUME_AXIS volumeSliceAxis);
      
      /// Draw volume crosshair coordinates
      void drawVolumeCrosshairCoordinates(BrainModelVolume* bmv,
                                          const VolumeFile* vf,
                                          const int viewportHeight);
      
      /// Draw the volume cropping lines
      void drawVolumeCroppingLines(BrainModelVolume* bmv,
                                             VolumeFile* vf,
                                             VolumeFile::VOLUME_AXIS volumeSliceAxis);
      
      /// stuff for web caret
      void webCaretCommon(BrainSet* bs,
                          const int viewport[4]);
                          
      /// Create a sphere quadric and put it in a display list.
      void createSphereQuadricAndDisplayList();
      
      /// Create a disk quadric and put it in a display list.
      void createDiskQuadricAndDisplayList();
      
      /// Create a cone quadic and put it in a display list
      void createConeQuadricAndDisplayList();
      
      /// Create a cylinder quadric and put it in a display list
      void createCylinderQuadricAndDisplayList();
      
      /// Create a square and put it in a display list
      void createSquareDisplayList();
      
      /// Create a box and put it in a display list
      void createBoxDisplayList();
      
      /// Create a ring and put it in a display list
      void createRingQuadricAndDisplayList();
      
      /// Create a diamond and put it in a display list
      void createDiamondQuadricAndDisplayList();
      
      /// Execute OpenGL commands to draw a sphere.
      void drawingCommandsSphere();
      
      /// Execute OpenGL commands to draw a disk.
      void drawingCommandsDisk();
      
      /// Execute OpenGL commands to draw a cone
      void drawingCommandsCone();
      
      /// Execute OpenGL commands to draw a cylinder
      void drawingCommandsCylinder();
      
      /// Execute OpenGL commands to draw a box
      void drawingCommandsBox();
      
      /// Execute OpenGL commands to draw a ring
      void drawingCommandsRing();
      
      /// Execute OpenGL commands to draw a diamond
      void drawingCommandsDiamond();
      
      /// Execute OpenGL commands to draw a square
      void drawingCommandsSquare();
      
      /// Draw the surface as points.
      void drawSurfaceNodes(const BrainModelSurfaceNodeColoring* bs,
                            const int modelNumber,
                            const CoordinateFile* cf, 
                            const int numCoords,
                            const bool drawInSurfaceEditColor);
      
      /// Draw the surface as links.
      void drawSurfaceLinks(const BrainModelSurfaceNodeColoring* bs,
                            const int modelNumber,
                            const CoordinateFile* cf,
                            const TopologyFile* tf, const int numTiles,
                            const bool drawEdgesOnly,
                            const bool drawInSurfaceEditColor);
                                   
      /// Draw the surface as links with hidden line removal.
      void drawSurfaceLinksNoBackside(const BrainModelSurfaceNodeColoring* bs,
                                      const int modelNumber,
                                      const CoordinateFile* cf,
                                      const TopologyFile* tf, const int numTiles);
                                      
      /// Draw the surface as tiles, possibly with lighting.
      void drawSurfaceTiles(const BrainModelSurfaceNodeColoring* bs,
                                   const BrainModelSurface* s,
                                   const CoordinateFile* cf,
                                   TopologyFile* tf, const int numTiles,
                                   const int numCoords);
                                   
      /// Draw the surface normals
      void drawSurfaceNormals(const BrainModelSurface* bms,
                              const CoordinateFile* cf,
                              const int numCoords);
                              
      /// Draw the surface forces
      void drawSurfaceForces(const CoordinateFile* cf,
                             const int numCoords);
                                    
      /// draw a sphere
      void drawSphere(const float diameter);
      
      /// draw a 2D disk (filled circle)
      void drawDisk(const float diameter);
      
      /// draw a cone
      void drawCone();
      
      /// draw cylinder
      void drawCylinder();
      
      /// draw a box
      void drawBox();
      
      /// draw a ring
      void drawRing();
      
      /// draw a square
      void drawSquare();
      
      /// draw a diamond
      void drawDiamond();
      
      /// draw a symbol
      void drawSymbol(const ColorFile::ColorStorage::SYMBOL symbol,
                      const float x,
                      const float y,
                      const float z,
                      const float size,
                      const BrainModel* bm);
                      
      /// Draw node highlighting.
      void drawNodeHighlighting(const BrainModelSurface* bms, const int numCoords);
      
      /// Draw Surface ROI members.
      void drawSurfaceROIMembers(const BrainModelSurface* bms, const int numCoords);
      
      /// Draw a transformation cell or foci file
      void drawTransformationCellOrFociFile(BrainModel* bm,
                              CellFile* cellFile, 
                              ColorFile* colorFile,
                              const DisplaySettingsCells* dsc,
                              const int transformFileNumber,
                              const int selectionMask);
      
      // Draw a cell or foci projection file
      void drawCellOrFociProjectionFile(BrainModelSurface* bms,
                                        CellProjectionFile* cellProjectionFile, 
                                        ColorFile* colorFile,
                                        const DisplaySettingsCells* dsc,
                                        const bool fociFileFlag);

      /// Draw cell projection and foci projections
      void drawCellAndFociProjections(BrainModelSurface* s);
      
      /// draw the geodesic path.
      void drawGeodesicPath(const CoordinateFile* cf);
      
      /// Draw a surface outline and transform axes over the volume.
      void drawVolumeSurfaceOutlineAndTransformationMatrixAxes(
                                    const BrainModelVolume* bmv,
                                    const VolumeFile::VOLUME_AXIS axis,
                                    const float axisCoord);
                                    
      /// Draw a cuts file.
      void drawCuts();
      
      /// Draw the borders.
      void drawBorders(BrainModelSurface* s);
      
      /// draw main window caption
      void drawMainWindowCaption();
      
      /// Draw the Surface Shape palette colorbar.
      void drawShapePalette(const int modelNumber);

      /// Draw the metric's palette colorbar.
      void drawMetricPalette(const int modelNumber,
                             const bool surfaceFlag);
                             
      /// Display a QImage in the OpenGL window.
      void displayAnImage(QImage* image);

      /// Display background and splash images
      void displayImages();
      
      /// Draw the linear object (typically used while drawing borders)
      void drawLinearObject();
      
      /// Draw transformation data files
      void drawTransformationDataFiles(const TransformationMatrix* tm);
      
      /// Draw all the VTK models.
      void drawAllVtkModels();

      /// Draw a VTK model file
      void drawVtkModelFile(VtkModelFile* vmf, const int modelNum);
      
      /// Draw the transformation axes
      void drawTransformationMatrixAxes(const BrainModel* bm);
      
      /// Draw the surface axes
      void drawSurfaceAxes(const BrainModelSurface* bms);
      
      /// Draw the deformation field vectors.
      void drawDeformationFieldVectors(BrainModelSurface* bms);

      /// Draw the vectors in 3d
      void drawVectorFile3D(BrainModelSurface* bms);

      /// check a vectors orientation (true if orientation is valid for display)
      bool checkVectorOrientation(const float vector[3]);

      /// Draw an arrow symbol
      void drawArrowSymbol(const float xyz[3],
                           const float tipXYZ[3],
                           const float radius);

      /// Draw a cylinder symbol
      void drawCylinderSymbol(const float xyz[3],
                              const float tipXYZ[3],
                              const float radius);

      /// Draw the volume foci file.
      void drawVectorsOnVolume(const VolumeFile::VOLUME_AXIS axis,
                               const float axisCoord,
                               const float voxelSize);

      /// Convert from volume item XYZ to screen XYZ
      void convertVolumeItemXYZToScreenXY(const VolumeFile::VOLUME_AXIS axis,
                                             float xyz[3]);
      
      /// Draw the volume border file
      void drawVolumeBorderFile(const VolumeFile::VOLUME_AXIS axis,
                                const float axisCoord,
                                const float voxelSize);
      
      /// Draw the volume contour file
      void drawVolumeContourFile(const VolumeFile::VOLUME_AXIS axis,
                                 const float axisCoord,
                                 const float voxelSize);
                                        
      /// Draw the volume cell file
      void drawVolumeCellFile(const VolumeFile::VOLUME_AXIS axis,
                              const float axisCoord,
                              const float voxelSize);
      
      /// Draw the volume foci file
      void drawVolumeFociFile(const VolumeFile::VOLUME_AXIS axis,
                              const float axisCoord,
                              const float voxelSize);
      
      /// Draw the oblique volume cell file
      void drawObliqueVolumeCellFile(const VolumeFile::VOLUME_AXIS axis,
                                     const CellFile* cf,
                                     const DisplaySettingsCells* dsc,
                                     const ColorFile* colorFile,
                                     const float voxelSize,
                                     const TransformationMatrix* tm,
                                     const float sliceCornerCoords[4][3],
                                     const int transformDataFileIndex = -1);
                                           
      /// Draw the oblique volume foci file
      void drawObliqueVolumeFociFile(const VolumeFile::VOLUME_AXIS axis,
                                     const float voxelSize,
                                     const TransformationMatrix* tm,
                                     const float sliceCornerCoords[4][3]);
                                           
      /// Draw the oblique volume contour file.
      void drawObliqueContourFile(const VolumeFile::VOLUME_AXIS axis,
                                  const ContourFile* cf,
                                  const float voxelSize,
                                  const TransformationMatrix* tm,
                                  const float sliceCornerCoords[4][3]);
                                  
      /// Draw the volume identify symbols
      void drawVolumeIdentifySymbols(const VolumeFile::VOLUME_AXIS axis,
                                     const float axisCoord);
                                            
      /// Draw a volume file slice
      void drawVolumeFileSlice(VolumeFile* vf, const VolumeFile::VOLUME_AXIS axis,
                          const int currentSlice,
                          const unsigned long maskForThisUnderlayOrOverlay,
                          const bool overlayFlag);
                                 
      /// Draw the contours that are being aligned.
      void drawModelContoursAlignment(BrainModelContours* bmc,
                                      const int alignmentSectionNumber);
      
      /// process hits made while selecting objects with mouse
      void processSelectedItems(const int numItems);
       
      /// Draw a volume slice
      void drawVolumeSliceOverlayAndUnderlay(BrainModelVolume* bmv,
                           const VolumeFile::VOLUME_AXIS volumeSliceAxis, 
                           const int currentSlice,
                           VolumeFile* &firstVolume);

      /// check for an OpenGL Error
      void checkForOpenGLError(const BrainModel* bm, const QString& msg = "");
      
      /// get valid line width
      GLfloat getValidLineWidth(const GLfloat widthIn) const;
      
      /// get valid point size
      GLfloat getValidPointSize(const GLfloat pointSizeIn) const;
      
      // enable the surface clipping planes
      void enableSurfaceClippingPlanes(BrainModelSurface* bms);

      // disable the surface clipping planes
      void disableSurfaceClippingPlanes();

      /// linear (border, cut, contour) being drawn
      Border linearObjectBeingDrawn;
       
      /// resampling density of linear object being drawn
      float linearObjectBeingDrawnSampling;
       
      /// linear object augment border count
      int linearObjectAugmentBorderCount;
       
      /// draw linear object flag
      bool drawLinearObjectOnly;
       
      /// draw image sub region box
      bool drawImageSubRegionBoxFlag;
      
      /// image sub region box
      int imageSubRegionBox[4];
      
      /// quadric containing a sphere
      GLUquadricObj* sphereQuadric;
      
      /// quadric containing a 2D disk (filled circle)
      GLUquadricObj* diskQuadric;
      
      /// quadric containing a cone
      GLUquadricObj* coneQuadric;
      
      /// quadric containing a cylinder
      GLUquadricObj* cylinderQuadric;
      
      /// quadric containing a diamond
      GLUquadricObj* diamondQuadric;
      
      /// quadric containing a ring
      GLUquadricObj* ringQuadric;
      
      /// display list containing a sphere
      GLuint sphereDisplayList;

      /// display list containing a 2D disk (filled circle)
      GLuint diskDisplayList;

      /// display list containing a cone
      GLuint coneDisplayList;
      
      /// display list for a cylinder
      GLuint cylinderDisplayList;
      
      /// display list for a square
      GLuint squareDisplayList;
      
      /// display list for a box
      GLuint boxDisplayList;
      
      /// display list for a diamond
      GLuint diamondDisplayList;
      
      /// display list for a ring
      GLuint ringDisplayList;
      
      /// version number of OpenGL
      static float versionOfOpenGL;
      
      /// the brain set
      BrainSet* brainSet;
      
      /// the selection mask
      unsigned long selectionMask;
      
      /// node special highlighting (used when adding tiles with mouse)
      std::vector<int> nodeSpecialHighlighting;
      
      /// the main window flag
      bool mainWindowFlag;
      
      /// the viewport
      int viewport[4];
      
      /// QT OpenGL widget being drawn into (may be NULL)
      QGLWidget* glWidget;
      
      /// selection x coordinate
      int selectionX;
      
      /// selection y coordinate
      int selectionY;

      /// viewing window number (0 = main window)
      int viewingWindowNumber;

      /// default orthographic window size
      static float defaultOrthoWindowSize;
       
      /// orthographic projection box for model
      double orthographicLeft[BrainModel::NUMBER_OF_BRAIN_MODEL_VIEW_WINDOWS];
      double orthographicRight[BrainModel::NUMBER_OF_BRAIN_MODEL_VIEW_WINDOWS];
      double orthographicBottom[BrainModel::NUMBER_OF_BRAIN_MODEL_VIEW_WINDOWS];
      double orthographicTop[BrainModel::NUMBER_OF_BRAIN_MODEL_VIEW_WINDOWS];
      double orthographicFar[BrainModel::NUMBER_OF_BRAIN_MODEL_VIEW_WINDOWS];
      double orthographicNear[BrainModel::NUMBER_OF_BRAIN_MODEL_VIEW_WINDOWS];
       
      /// Modelview matrix created when display last drawn.
      /// Used for projecting items selected with the mouse.
      GLdouble selectionModelviewMatrix[BrainModel::NUMBER_OF_BRAIN_MODEL_VIEW_WINDOWS][16];
      
      /// Projection matrix created when last resize event received.
      /// Used for projecting items selected with the mouse.
      GLdouble selectionProjectionMatrix[BrainModel::NUMBER_OF_BRAIN_MODEL_VIEW_WINDOWS][16];
      
      /// Viewport set when last resize event received.
      /// Used for projecting items selected with the mouse.
      GLint selectionViewport[BrainModel::NUMBER_OF_BRAIN_MODEL_VIEW_WINDOWS][4];
      
      /// Mutex to allow only one model to be drawn at a time
      QMutex paintMutex;
       
      /// volume slice axis
      //VolumeFile::VOLUME_AXIS volumeSliceAxis;

      /// volume slice coordinate
      float volumeSliceCoordinate;
       
      /// editing segmentation volume flag
      bool editingSegmentationVolumeFlag;
       
      /// editing paint volume flag
      bool editingPaintVolumeFlag;
      
      /// selection buffer size
      enum { SELECTION_BUFFER_SIZE = 5000};
       
      /// selection buffer
      GLuint selectionBuffer[SELECTION_BUFFER_SIZE];
       
      /// selected node
      BrainModelOpenGLSelectedItem selectedNode;
       
      /// selected border (first)
      BrainModelOpenGLSelectedItem selectedBorder1;
       
      /// selected border (second)
      BrainModelOpenGLSelectedItem selectedBorder2;
       
      /// selected border (volume)
      BrainModelOpenGLSelectedItem selectedVolumeBorder;
       
      /// selected cell projection
      BrainModelOpenGLSelectedItem selectedCellProjection;
       
      /// selected cell (volume)
      BrainModelOpenGLSelectedItem selectedVolumeCell;
       
      /// selected cut
      BrainModelOpenGLSelectedItem selectedCut;
       
      /// selected foci projection
      BrainModelOpenGLSelectedItem selectedFocusProjection;
       
      /// selected foci (volume)
      BrainModelOpenGLSelectedItem selectedVolumeFoci;
       
      /// selected palette for metric
      BrainModelOpenGLSelectedItem selectedPaletteMetric;
       
      /// selected palette for shape
      BrainModelOpenGLSelectedItem selectedPaletteShape;
       
      /// selected contour
      BrainModelOpenGLSelectedItem selectedContour;
       
      /// selected contour cell
      BrainModelOpenGLSelectedItem selectedContourCell;
       
      /// selected voxel underlay
      BrainModelOpenGLSelectedItem selectedVoxelUnderlay;
       
      /// selected voxel overlay secondary
      BrainModelOpenGLSelectedItem selectedVoxelOverlaySecondary;
       
      /// selected voxel overlay primary
      BrainModelOpenGLSelectedItem selectedVoxelOverlayPrimary;
       
      /// selected functional voxel (surface and volume cloud)
      BrainModelOpenGLSelectedItem selectedVoxelFunctionalCloud;
       
      /// selected surface tile
      BrainModelOpenGLSelectedItem selectedSurfaceTile;
       
      /// selected link (index 1 & 2 are nodes)
      BrainModelOpenGLSelectedItem selectedLink;
      
      /// selected transformation axes
      BrainModelOpenGLSelectedItem selectedTransformationMatrixAxes;
      
      /// selected vtk model
      BrainModelOpenGLSelectedItem selectedVtkModel;
      
      /// selected transform cell
      BrainModelOpenGLSelectedItem selectedTransformCell;
      
      /// selected transform foci
      BrainModelOpenGLSelectedItem selectedTransformFoci;
      
      /// selected transform contour
      BrainModelOpenGLSelectedItem selectedTransformContour;
      
      /// selected transform contour cell
      BrainModelOpenGLSelectedItem selectedTransformContourCell;
      
      /// the brain model being drawn
      BrainModel* brainModel;
      
      /// all brain models displayed in windows for identification
      /// ONLY VALID WHEN ::identifyBrainModel... called
      BrainModel* allWindowBrainModelsForIdentification[BrainModel::NUMBER_OF_BRAIN_MODEL_VIEW_WINDOWS];

      /// disable clearing flag (used my draw all fiducial mode)
      bool disableClearingFlag;
       
      /// initialization completed flag
      bool initializationCompletedFlag;
      
      /// offScreen rendering (WebCaret, caret_command)
      bool offScreenRenderingFlag;
      
      /// use display lists for shapes (spheres, boxes, rings, etc)
      bool useDisplayListsForShapes;
      
      /// surface edit drawing color
      static unsigned char surfaceEditDrawColor[3];
      
      /// stippling for polygon
      static GLubyte polygonStipple[128];
      
      /// OpenGL text enabled
      static bool openGLTextEnabledFlag;
      
      /// maximum point size
      float maximumPointSize;
      
      /// minimum point size
      float minimumPointSize;
      
      /// maximum line width
      float maximumLineWidth;
      
      /// minimum line width
      float minimumLineWidth;
      
      /// caption displayed in main window
      QString mainWindowCaption;
};

#ifdef __BRAIN_MODEL_OPENGL_MAIN__
float BrainModelOpenGL::versionOfOpenGL = 0.0;
float BrainModelOpenGL::defaultOrthoWindowSize = 125.0;
unsigned char BrainModelOpenGL::surfaceEditDrawColor[3] = { 0, 0, 255 };
GLubyte BrainModelOpenGL::polygonStipple[128];
bool BrainModelOpenGL::openGLTextEnabledFlag = true;

#endif // __BRAIN_MODEL_OPENGL_MAIN__

#endif // __BRAIN_MODEL_OPENGL_H__