summaryrefslogtreecommitdiffstats
path: root/applications/rview/rviewDModes.hh
blob: 67c8807acc74171677eb652ca04451887217f0e8 (plain)
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
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
/*
* This file is part of rasdaman community.
*
* Rasdaman community 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 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community 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 rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
/

/**
 *  PURPOSE:
 *
 *  Class definitions for the regular object viewers and their support
 *  classes:
 *  	- rviewImage hierarchy, including pixmapCanvas, rendererControl
 *    	  and rviewImageSetup. Source in rviewImage.cpp.
 *  	- rviewChart (chartCanvas). Source in rviewChart.cpp.
 *  	- rviewTable (tableCanvas). Source in rviewTable.cpp.
 *  COMMENTS:
 *			None
 */


#ifndef _RVIEW_DMODES_H_
#define _RVIEW_DMODES_H_




#include "rasodmg/ref.hh"
#include "rasodmg/marray.hh"
#include "rasodmg/gmarray.hh"

#include "labelManager.hh"
#include "rviewUtils.hh"
#include "rviewDisplay.hh"
#include "rviewColMap.hh"



#ifdef __VISUALC__
struct vertex;
struct vertex_fp;
struct graph_env;
struct tex_desc;
struct voxel_desc;
struct mesh_desc;
struct mdd_desc;
#else
typedef struct vertex;
typedef struct vertex_fp;
typedef struct graph_env;
typedef struct tex_desc;
typedef struct voxel_desc;
typedef struct mesh_desc;
typedef struct mdd_desc;
#endif





class rviewImage;
class rviewRenderImage;



// Possible display formats
enum rviewImageMode {
  rim_none,
  rim_surf,
  rim_voxel
};


// Flags for light direction
#define RVIEW_LIGHTDIR_LEFT	1
#define RVIEW_LIGHTDIR_RIGHT	2
#define RVIEW_LIGHTDIR_DOWN	4
#define RVIEW_LIGHTDIR_UP	8
#define RVIEW_LIGHTDIR_FRONT	16
#define RVIEW_LIGHTDIR_BACK	32

typedef struct rview_image_setup {
  unsigned long zpro, clipz;
  double pixelThresholdLow, pixelThresholdHigh, weightThreshold;
  int weightQuantisation;
  bool useRgbBrightness;
  bool useLights;
  double lightsAmbient;
  double lightsGain;
  double lightsAngle;
  double lightsScintAngle;
  int lightsDir;
  int lightsDist;
  int kernelSize, kernelType;
  bool useVoxCol;
  double voxColour;
  int gridSize;
  double scaleHeight;
} rview_image_setup;


/*
 *  Image setup window for customizing the renderer.
 */
class rviewImageSetup: public rviewFrame
{
  public:

  rviewImageSetup(rview_image_setup *ris, rviewRenderImage *parentWin);
  ~rviewImageSetup(void);

  void unlinkParent(void);

  void OnSize(int w, int h);

  void label(void);
  int process(wxObject &obj, wxEvent &evt);

  void updateSettings(const rview_image_setup &ris);
  void readNewSetup(void);

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;

  static int parseLightDirection(const char *dir);

  // constants
  // Borders used in setup window
  static const int imgset_border;
  // Height of text widgets in setup window
  static const int imgset_theight;
  // Height of checkboxes in setup window
  static const int imgset_chkheight;
  // Height of group boxes in setup window
  static const int imgset_renheight;
  static const int imgset_voxheight;
  static const int imgset_hgtheight;
  // Dimensions of buttons in setup window
  static const int imgset_bwidth;
  static const int imgset_bheight;
  // Dimensions of checkboxes in setup window
  static const int imgset_chowidth;
  static const int imgset_choheight;
  // Setup window dimensions
  static const int imgset_width;
  static const int imgset_height;


  protected:

  rviewRenderImage *parent;
  wxPanel *panel;
  wxGroupBox *renderGroup, *voxelGroup, *heightGroup;
  rviewText *zproWidget, *clipzWidget;
  rviewText *pixThreshLowWidget, *pixThreshHighWidget, *wgtThreshWidget, *wgtQuantWidget;
  rviewCheckBox *useRgbBrightness;
  rviewCheckBox *useLights;
  rviewChoice *kernelSize, *kernelType;
  rviewText *lightsAmbient, *lightsGain, *lightsAngle, *lightsScintAngle;
  rviewText *lightsDir, *lightsDist;
  rviewCheckBox *useVoxCol;
  rviewText *voxColour;
  rviewText *gridSize, *scaleHeight;
  rviewButton *okBut, *cancelBut;
  rview_image_setup oldSetup, *imgSetup;

  static const char *normalKernelSizes[];
  static const keyword_to_ident_c normalKernelTypes[];
};



/*
 *  Renderer playback control window
 */
class rendererControl: public rviewFrame
{
  public:

  rendererControl(float drx, float dry, float drz, int mode, rviewRenderImage *parentWin);
  ~rendererControl(void);

  void unlinkParent(void);
  void setActiveMode(int mode);

  void OnSize(int w, int h);

  void label(void);
  int process(wxObject &obj, wxEvent &evt);

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;

  // constants
  // Borders used in renderer control window
  static const int rctrl_border;
  // Button dimensions
  static const int rctrl_bwidth;
  static const int rctrl_bheight;
  // Reset button dimensions
  static const int rctrl_rwidth;
  static const int rctrl_rheight;
  // Slider height
  static const int rctrl_sheight;
  // Window dimensions
  static const int rctrl_width;
  static const int rctrl_height;


  protected:

  void updateParameters(void);

  wxPanel *panel;
  rviewSlider *rotx, *roty, *rotz;
  rviewButton *resetX, *resetY, *resetZ;
  rviewButton *actionBut, *closeBut;
  rviewRenderImage *parent;
  int active;
};


/*
 *  Renderer current view window (rotation, offset, scale)
 */
class rendererCurrentView: public rviewFrame
{
  public:

  rendererCurrentView(const vertex_fp &angles, long off, double scale, rviewRenderImage *parentWin);
  ~rendererCurrentView(void);

  void unlinkParent(void);
  
  void OnSize(int w, int h);

  void label(void);
  int process(wxObject &obj, wxEvent &evt);

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;

  void updateView(const vertex_fp &angles, long off, double scale);

  // constants
  // Borders used in renderer view window
  static const int rcview_border;
  // Button dimensions
  static const int rcview_bwidth;
  static const int rcview_bheight;
  // Text widget height
  static const int rcview_theight;
  // Window dimensions
  static const int rcview_width;
  static const int rcview_height;


  protected:
  
  void updateParameters(void);

  wxPanel *panel;
  rviewButton *applyButton, *closeButton;
  rviewText *rotx, *roty, *rotz;
  rviewText *zoff;
  rviewText *cubeScale;
  rviewRenderImage *parent;
};



class wxPixmap;

/*
 *  Container class for wxPixmap.
 */
class pixmapCanvas: public wxCanvas
{
  public:

  pixmapCanvas(rviewImage *parent, int x, int y, int w, int h, long style=0);
  ~pixmapCanvas(void);

  void setPixmap(wxPixmap *pmap);
  void updateDisplay(bool borders=FALSE);

  void OnPaint(void);
  void OnEvent(wxMouseEvent &mevt);
  
  void SetAspectRatio(double ratio);	// 0 for none
  void ToggleDragBox(bool clearMode);
  void SetDragBox(int x0, int y0, int x1, int y1);
  bool HasDragBox(void) const;
  bool GetDragBox(int &x0, int &y0, int &x1, int &y1) const;
  void UpdateDragBox(int x1, int y1);
  void AdjustDragBox(int x1, int y1);


  protected:

  void paintCore(int x, int y);
  void adjustBoxToRatio(void);

  wxPixmap *pixmap;
  wxDC *myDC;
  wxBrush brush;
  wxBrush border;
  wxBrush textBack;
  wxPen bpen;
  wxPen fpen;
  wxFont *font;
  rviewImage *parentWin;
  int pixWidth, pixHeight;
  int offX, offY;
  int rect_x0, rect_y0, rect_x1, rect_y1;
  double aspectRatio;
  wxRect textBBox;
};


// Flags used when settings are updated
#define RVIEW_IFLAG_VOXEL	1
#define RVIEW_IFLAG_LIGHT	2
#define RVIEW_IFLAG_HEIGHT	4

/*
 *  Abstract base class for all windows containing an image + controls
 */
class rviewImage: public rviewDisplay
{
  public:

  rviewImage(mdd_frame *mf, int es, unsigned int flags=0);
  virtual ~rviewImage(void);

  virtual int openViewer(void);

  virtual void label(void);
  virtual int process(wxObject &obj, wxEvent &evt);
  virtual void processMouseEvent(wxMouseEvent &mevt);
  virtual int userEvent(const user_event &ue);
  virtual void prepareToDie(void);
  virtual int newProjection(void)=0;
  virtual int requestQuit(int level);

  virtual void OnSize(int w, int h);
  virtual void OnMenuCommand(int id);
  virtual bool OnClose(void);	// overload from rviewFrame

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;

  // Default flags for wxPixmap class (dithering etc)
  static int getPixmapFlags(void);

  // constants
  // Slider dimensions
  static const int image_swidth;
  static const int image_sheight;
  // Playback buttons dimensions
  static const int image_pbwidth;
  static const int image_pbheight;
  // Minimum size of image
  static const int image_minwidth;
  static const int image_minheight;
  // Checkbox dimensions
  static const int image_chkwidth;
  static const int image_chkheight;
  // Bounding box checkbox dimensions
  static const int image_bbwidth;
  static const int image_bbheight;
  // Text field dimensions
  static const int image_twidth;
  static const int image_theight;
  // Button dimensions
  static const int image_bwidth;
  static const int image_bheight;
  // Offsets of drag box in canvas
  static const int image_dragtoff;
  static const int image_dragtspace;
  // Distance from the border at which to autoscroll
  static const int image_draghotzone;
  // Extra space reserved on control panel
  static const int image_ctrly;
  static const int image_totaly;


  protected:

  void updatePixmap(char *oldData, char *newData);
  void configureCspace(bool state);
  void setCspaceProjMode(bool pmode);
  void resizeImage(void);
  void openViewerEpilogue(rviewFrameType ft);
  int freeDimsFromProjection(int &dim1, int &dim2, r_Point *map);
  void ensureViewCspace(void);
  void deleteViewCspace(void);
  virtual void projectObjectHook(void);
  virtual void configureMode(void);
  virtual char *initMode(void)=0;
  virtual bool cspaceRangeHook(bool suggest);
  virtual char *movieNewFrame(void);
  virtual void rotateObject(wxMouseEvent &mevt);
  virtual int fileMenuInitHook(wxMenu *menu);
  virtual int configMenuInitHook(wxMenu *menu);
  // Query viewer capabilities
  virtual bool modeNeedsCspace(rviewBaseType bt) const;
  virtual bool canRotateObject(void) const;
  virtual bool moviePossible(void) const;
  virtual bool showScaleSlider(void) const;
  // view management
  virtual int saveView(FILE *fp);
  virtual int readView(const char *key, const char *value);
  virtual void loadViewFinished(void);

  wxPixmap *pixmap;
  pixmapCanvas *pcanv;
  rviewSlider *scaleSlider;
  int pixWidth, pixHeight, pixPitch, pixPad, pixDepth;
  int virtualPitch;
  char *imgData;
  double scaleValue;
  int scrollx, scrolly;
  float mousex, mousey;
  int mousebut;
  unsigned int freeDims;
  // For intensity to RGB translations (ushort)
  colourspaceMapper *csmap;
  bool doValToCspace;
  bool doFullRangeCspace;
  bool doProjRangeCspace;
  // base type allows cspace mapping?
  bool cspaceForType;
  // image fully initialized?
  bool initPhaseFinished;
  r_Minterval *csInterv;
  // shared by flat and height field which don't have a shared derivation path
  rviewButton *playFwd, *playBack, *playStop;
  int playDirection;
  int lastMovieMode;
  // colourspace parameters for view loading
  colourspace_params *cspar;

  // view parameters
  static const char *view_ScrollPos;
  static const char *view_UseCspace;
  static const char *view_CspaceFull;
  static const char *view_CspaceProj;
  static const char *view_CspaceMeans;
  static const char *view_CspaceSigmas;
  static const char *view_CspaceType;
  static const char *view_CspaceRange;
  static const char *view_ScaleValue;
};


/*
 *  Base class for flat images, i.e. 2D orthogonal projections
 */
class rviewFlatBaseImage: public rviewImage
{
  public:

  rviewFlatBaseImage(mdd_frame *mf, int es, unsigned int flags=0);
  virtual ~rviewFlatBaseImage(void);

  virtual int newProjection(void);
  virtual int openViewer(void);

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;


  protected:

  virtual char *initMode(void);
  char *projectImage(void);
};


/*
 *  Standard flat images
 */
class rviewFlatImage: public rviewFlatBaseImage
{
  public:

  rviewFlatImage(mdd_frame *mf, unsigned int flags=0);
  ~rviewFlatImage(void);
  
  void OnSize(int w, int h); 

  virtual int openViewer(void);
  virtual void label(void);
  virtual int process(wxObject &obj, wxEvent &evt);

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;
  virtual int getViewerType(void) const;


  protected:

  virtual char *initMode(void);
  virtual bool moviePossible(void) const;
  virtual char *movieNewFrame(void);
};


/*
 *  Abstract base class for all rendered images (voxel, height field, whatever...)
 */
class rviewRenderImage: public rviewImage
{
  public:

  rviewRenderImage(mdd_frame *mf, int es, unsigned int flags=0);
  virtual ~rviewRenderImage(void);

  virtual void label(void);
  virtual int process(wxObject &obj, wxEvent &evt);
  virtual int newProjection(void);
  virtual void prepareToDie(void);
  virtual int requestQuit(int level);
  virtual int userEvent(const user_event &ue);
  virtual void OnSize(int w, int h);
  virtual void OnMenuCommand(int id);
  virtual bool OnClose(void);

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;

  void closeEditor(bool newSetup);
  void updateSettings(int setFlags);

  void closeRendererControls(void);
  void setAutoRotation(float rx, float ry, float rz);
  void setCurrentView(const vertex_fp &angles, long off, double scale);


  protected:

  virtual char *initMode(void);
  virtual char *setupEnvironment(int w, int h)=0;
  virtual void rotateObject(wxMouseEvent &mevt);
  virtual bool doUpdate(int updateFlags)=0;
  virtual void redrawSettingsChanged(void);
  virtual void fillBuffer(void)=0;
  virtual void fillBackgroundCore(rviewBaseType bt, double minVal);
  virtual int configMenuInitHook(wxMenu *menu);
  virtual int viewMenuInitHook(wxMenu *menu);
  virtual bool canRotateObject(void) const;
  virtual void updateCurrentView(void);

  int setupEnvBase(int w, int h, r_Ref<r_GMarray> &mdd, colourspaceMapper **csm, r_Minterval *csdom);
  char *setupGraphEnv(void);
  void fillBufferBackground(bool doCspace, bool &cspaceOK, r_Ref<r_GMarray>& obj, colourspaceMapper **csm, r_Minterval *csdom, rviewBaseType bt, bool fullRange, double *useMinVal=NULL);
  void translateBufferToCspace(rviewBaseType bt, double *useMinVal=NULL, double *useMaxVal=NULL);
  static void rotateCube(int axis, float angle, vertex_fp *matrix);
  void rotateCube(int axis, float angle);
  void getLightPos(vertex_fp *lpos);

  virtual int saveView(FILE *fp);
  virtual int readView(const char *key, const char *value);
  virtual void loadViewFinished(void);

  // convert rotation matrix to angles and back
  void matrixToAngles(vertex_fp &angles) const;
  void anglesToMatrix(const vertex_fp &angles);

  int rendererPlayback;
  vertex_fp *geomData, *geomUse;
  vertex_fp *rot;
  graph_env *graphEnv;
  union {unsigned long l; float f; double d;} voxColour;
  long zoff;
  double cubeScale;
  // Rotation angle increments for renderer playback
  float drx, dry, drz;
  // Setup options
  rview_image_setup setup;
  rviewImageSetup *setupWindow;
  rendererControl *rcontrol;
  rendererCurrentView *rcurview;

  // view keywords
  static const char *view_ZProject;
  static const char *view_ZClip;
  static const char *view_PixThreshLow;
  static const char *view_PixThreshHigh;
  static const char *view_WeightThresh;
  static const char *view_WeightQuant;
  static const char *view_UseRGBBright;
  static const char *view_UseLighting;
  static const char *view_LightAmbient;
  static const char *view_LightGain;
  static const char *view_LightAngle;
  static const char *view_LightScint;
  static const char *view_LightDir;
  static const char *view_LightDist;
  static const char *view_KernelSize;
  static const char *view_KernelType;
  static const char *view_UseVoxColour;
  static const char *view_VoxColour;
  static const char *view_GridSize;
  static const char *view_ScaleHeight;
  static const char *view_Rotation;
  static const char *view_ZOffset;
};


/*
 *  Class for visualizations of volumetric images (3D texture mapper &
 *  voxel renderer).
 */
class rviewVolumeImage: public rviewRenderImage
{
  public:

  rviewVolumeImage(mdd_frame *mf, unsigned int flags=0);
  virtual ~rviewVolumeImage(void);

  virtual void label(void);
  virtual int process(wxObject &obj, wxEvent &evt);
  virtual void OnSize(int w, int h);
  virtual void OnMenuCommand(int id);
  virtual int openViewer(void);
  
  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;
  virtual int getViewerType(void) const;


  protected:

  virtual char *initMode(void);
  virtual char *setupEnvironment(int w, int h);
  virtual bool doUpdate(int updateFlags);
  virtual void fillBuffer(void);

  virtual int saveView(FILE *fp);
  virtual int readView(const char *key, const char *value);
  virtual void loadViewFinished(void);

  rviewCheckBox *boundingBox;
  rviewImageMode imode;
  int lastMode;
  tex_desc *texDesc;
  voxel_desc *voxDesc;
  bool initVoxParams;
  bool doBoundingBox;

  static const char *view_VolumeMode;
  static const char *view_UseBBox;
};


/*
 * Class for visualizing data as heightfields.
 */
class rviewHeightImage: public rviewRenderImage
{
  public:

  rviewHeightImage(mdd_frame *mf, unsigned int flags=0);
  virtual ~rviewHeightImage(void);

  virtual void label(void);
  virtual int process(wxObject &obj, wxEvent &evt);
  virtual int newProjection(void);
  virtual void prepareToDie(void);
  virtual int requestQuit(int level);
  virtual int openViewer(void);

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;
  virtual int getViewerType(void) const;


  protected:

  int depthForHeightfield(void) const;
  virtual char *initMode(void);
  virtual char *setupEnvironment(int w, int h);
  virtual char *movieNewFrame(void);
  virtual bool doUpdate(int updateFlags);
  virtual void redrawSettingsChanged(void);
  virtual void fillBackgroundCore(rviewBaseType bt, double minVal);
  virtual void fillBuffer(void);
  virtual bool cspaceRangeHook(bool suggest);
  virtual bool moviePossible(void) const;
  virtual bool modeNeedsCspace(rviewBaseType bt) const;

  mdd_desc *mddDesc;
  mesh_desc *meshDesc;
  // for colourspace mapping of heightfields.
  r_Ref<r_GMarray> dummyMDD;
};



/*
 *  An image scaled by the DBMS
 */
class r_Fast_Base_Scale;

class rviewScaledImage: public rviewFlatBaseImage
{
  public:

  rviewScaledImage(collection_desc *cd, r_Fast_Base_Scale *scaler, unsigned int flags=0);
  ~rviewScaledImage(void);

  virtual void processMouseEvent(wxMouseEvent &mevt);
  virtual void label(void);
  virtual int process(wxObject &obj, wxEvent &evt);
  virtual int openViewer(void);
  virtual void OnSize(int w, int h);
  virtual int newProjection(void);

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;
  virtual int getViewerType(void) const;
  virtual const r_Minterval &getVirtualDomain(void) const;


  protected:

  virtual char *initMode(void);
  virtual void projectObjectHook(void);

  char *projectImage(void);
  bool showScaleSlider(void) const;
  void scaleViewBy(double scale);
  void newView(bool loadImage=TRUE);
  void projectionStringForView(void);
  double getLastScale(void) const;

  // view management
  virtual int saveView(FILE *fp);
  virtual int readView(const char *key, const char *value);
  virtual void loadViewFinished(void);
  void ensureLoadedView(void);

  rviewButton *zoomInBut;
  rviewButton *zoomOutBut;
  rviewButton *lastZoomBut;
  rviewButton *zoomBoxBut;
  rviewText *scaleString;

  bool boxState;

  typedef struct {
    double scale;
    r_Point low, high;
    int dim1, dim2;
  } view_desc_t;

  bool compareViews(const view_desc_t &v1, const view_desc_t &v2);

  // The current view
  view_desc_t thisView;
  r_Minterval fullDomain;
  bool dontLoad;
  double initialScale;
  view_desc_t *loadedView;

  DynamicStack<view_desc_t> viewHistory;

  r_Fast_Base_Scale *scaleObject;

  collection_desc *collDesc;

  static const double scaleStep;

  // view parameters
  static const char *view_CurrentBox;
  static const char *view_BoxScale;
};


// Structure for static conversion of MDD -> pixmap
typedef struct rviewFlatProjEnv {
  // initialized by caller
  r_GMarray *mddPtr;
  r_Point pt1, pt2;
  int dim1, dim2;
  rviewBaseType bt;
  double scale;
  bool doCspace;
  colourspaceMapper *csmap;
  int cspaceState;
  // initialized by prepareFlatProjection()
  int width, height;
  int pitch, pad, depth;
} rviewFlatProjEnv;

// Setup variables for projecting images
int rviewPrepareFlatProjection(rviewFlatProjEnv &penv);
// Project an MDD object into an image bitmap
int rviewPerformFlatProjection(rviewFlatProjEnv &env, char *data);






enum rviewChartMode {
  rcm_none,
  rcm_bar,
  rcm_line,
  rcm_spline
};

/*
 *  Canvas displaying a chart
 */

class chartCanvas: public wxCanvas
{
  public:

  chartCanvas(wxWindow *parent, int x, int y, int w, int h, long style=0);
  ~chartCanvas(void);

  void setData(mdd_frame *mf, rviewBaseType bt);
  void setVars(int s, double cs, int ds, bool cy, rviewChartMode cm);
  int  setProjection(r_Point &p1, r_Point &p2);
  void OnPaint(void);

  // constants
  // Space reserved on top / bottom of chart
  static const int chcanv_cospace;
  // Length of a corrdinate axis marker line
  static const int chcanv_colength;
  // Start exponential axis numbering when |exponent| >= x
  static const int chcanv_exponents;


  protected:

  // Core-functionality of chart modes
  void redrawBar(wxDC *cdc, int height, int dim, int startOff, int endOff, float scale, float posx, float stepx, float orgy);
  void redrawLine(wxDC *cdc, int dim, int startOff, int endOff, float scale, float posx, float stepx, float orgy);
  void redrawSpline(wxDC *cdc, int dim, int startOff, int endOff, float scale, float posx, float stepx, float orgy);

  r_Ref<r_GMarray> mddObj;
  int step, dimMDD;
  r_Point pt1, pt2;
  double min, max, costep;
  rviewBaseType baseType;
  rviewChartMode cmode;
  wxBrush brush, back;
  wxBrush brush_r, brush_g, brush_b;
  wxPen pen, pen_r, pen_g, pen_b;
  wxFont *font;
  bool cosys;
  char format[10];
  int coleft, datastep;
  int scroll;
};


/*
 *  A class for drawing charts
 */

class rviewChart: public rviewDisplay
{
  public:

  rviewChart(mdd_frame *mf, unsigned int flags=0);
  ~rviewChart(void);

  void label(void);
  int process(wxObject &obj, wxEvent &evt);
  int newProjection(void);
  virtual int openViewer(void);

  void OnSize(int w, int h);
  void OnMenuCommand(int id);

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;
  virtual int getViewerType(void) const;

  // constants
  // Text widget dimensions (step)
  static const int chart_twidth;
  static const int chart_theight;
  // checkbox dims
  static const int chart_cwidth;
  static const int chart_cheight;
  // Minimum size of viewer
  static const int chart_minwidth;
  static const int chart_minheight;
  static const int chart_ctrly;
  static const int chart_totaly;


  protected:

  virtual int saveView(FILE *fp);
  virtual int readView(const char *key, const char *value);
  virtual void loadViewFinished(void);

  void checkModeMenu(void);

  chartCanvas *canvas;
  int step, datastep;
  int lastMode;
  double costep;
  int scroll;
  bool cosys;
  rviewChartMode cmode;
  rviewText *stText, *coText, *dataText;
  rviewCheckBox *csBox;

  static const char *view_StepSize;
  static const char *view_Markers;
  static const char *view_ScrollPos;
  static const char *view_CoSys;
  static const char *view_ChartMode;
};



/*
 *  Canvas for plotting text onto
 */

class textCanvas: public wxCanvas
{
  public:

  textCanvas(wxWindow *parent, int x, int y, int w, int h, long style=0);
  ~textCanvas(void);

  void setData(mdd_frame *mf, rviewBaseType bt, unsigned int bs);
  void setStep(int sx, int sy);
  void setCoSys(bool cs, int &cl, int &ct);
  void setProjection(r_Point &pt1, r_Point &pt2, unsigned int fd, r_Point *mapIndex=NULL);
  void setNumberBase(int newBase);
  void OnPaint(void);
  void CalcTextExtent(char *b, float &width, float &height);
  void EstimateCellSize(int &width, int &height);

  // constants
  // Space around coordinate system
  static const int txcanv_cospace;
  // Default space between columns
  static const int txcanv_colspace;
  // Border used in text canvas
  static const int txcanv_border;


  protected:

  r_Ref<r_GMarray> mddObj;
  int stepx, stepy, dimMDD;
  int scrollX, scrollY;
  int coleft, cotop;
  int dim1, dim2;
  unsigned int freeDims;
  r_Point pt1, pt2;
  int numberBase;
  bool cosys;
  rviewBaseType baseType;
  unsigned int baseSize;
  wxBrush fore, back;
  wxPen pen;
  wxFont *font;
};



/*
 *  Class for displaying tables
 */

class rviewTable: public rviewDisplay
{
  public:

  rviewTable(mdd_frame *mf, unsigned int flags=0);
  ~rviewTable(void);

  void label(void);
  int process(wxObject &obj, wxEvent &evt);
  int newProjection(void);
  void newTableSize(void);
  virtual int openViewer(void);

  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;
  virtual int getViewerType(void) const;

  void OnSize(int w, int h);
  void OnMenuCommand(int id);

  // constants
  // Dimensions of additional wxText items (configs)
  static const int table_twidth;
  static const int table_theight;
  // Dimensions of check box
  static const int table_cwidth;
  static const int table_cheight;
  // Minimum dimensions of table
  static const int table_minwidth;
  static const int table_minheight;
  static const int table_ctrly;
  static const int table_totaly;


  protected:

  void EstimateCellSize(int &width, int &height);

  virtual int saveView(FILE *fp);
  virtual int readView(const char *key, const char *value);
  virtual void loadViewFinished(void);

  void checkModeMenu(void);

  textCanvas *canvas;
  int stepx, stepy;
  int scrollx, scrolly;
  int fieldsx, fieldsy;
  int lastMode;
  unsigned int freeDims;
  bool cosys;
  rviewText *sxText, *syText;
  rviewCheckBox *csBox;
  int numberBase;

  static const char *view_StepSize;
  static const char *view_ScrollPos;
  static const char *view_CoSys;
  static const char *view_NumBase;
};



/*
 *  Class for displaying strings
 */

class rviewStringViewer: public rviewDisplay
{
  public:
  
  rviewStringViewer(mdd_frame *mf, unsigned int flags=0);
  ~rviewStringViewer(void);
  
  int newProjection(void);
  virtual int openViewer(void);
  
  virtual const char *getFrameName(void) const;
  virtual rviewFrameType getFrameType(void) const;
  virtual int getViewerType(void) const;
  
  void OnSize(int w, int h);
  
  // constants
  static const int strview_msgheight;
  static const int strview_minwidth;
  static const int strview_minheight;
  static const int strview_ctrly;
  static const int strview_totaly;

  
  protected:

  unsigned int freeDims;
  wxMessage *msgString;
};

#endif