-
Notifications
You must be signed in to change notification settings - Fork 3
/
surf_contour.pro
969 lines (709 loc) · 30.9 KB
/
surf_contour.pro
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
;+
; NAME:
; SURF_CONTOUR
;
; PURPOSE:
; The purpose of this program is to demonstrate how to
; create a shaded surface and coutour plot in the same
; object graphics window. The contour plot should be
; able to be translated independently of the surface.
;
; AUTHOR:
; FANNING SOFTWARE CONSULTING
; David Fanning, Ph.D.
; 2642 Bradbury Court
; Fort Collins, CO 80521 USA
; Phone: 970-221-0438
; E-mail: [email protected]
; Coyote's Guide to IDL Programming: http://www.dfanning.com
;
; CATEGORY:
; Widgets, IDL 5 Object Graphics.
;
; CALLING SEQUENCE:
; SURF_CONTOUR, data, x, y
;
; REQUIRED INPUTS:
; None. Fake data will be used if no data is supplied in call.
;
; OPTIONAL INPUTS
;
; data: A 2D array of surface data.
;
; x: A vector of X data values.
;
; y: A vector of Y data values.
;
; OPTIONAL KEYWORD PARAMETERS:
;
; _EXTRA: This keyword collects otherwise undefined keywords that are
; passed to the surface initialization routine.
;
; GROUP_LEADER: The group leader for this program. When the group leader
; is destroyed, this program will be destroyed.
;
; XTITLE: A string used as the X title of the plot.
;
; YTITLE: A string used as the Y title of the plot.
;
; ZTITLE: A string used as the Z title of the plot.
; COMMON BLOCKS:
; None.
;
; SIDE EFFECTS:
; None.
;
; RESTRICTIONS:
; None.
;
; EXAMPLE:
; To use this program with your data, type:
;
; IDL> Surf_Contour, data
;
; MODIFICATION HISTORY:
; Written by David Fanning, 20 September 98.
;-
FUNCTION Normalize, range, Position=position
; This is a utility routine to calculate the scaling vector
; required to position a vector of specified range at a
; specific position given in normalized coordinates. The
; scaling vector is given as a two-element array like this:
;
; scalingVector = [translationFactor, scalingFactor]
;
; The scaling vector should be used with the [XYZ]COORD_CONV
; keywords of a graphics object or model. For example, if you
; wanted to scale an X axis into the data range of -0.5 to 0.5,
; you might type something like this:
;
; xAxis->GetProperty, Range=xRange
; xScale = Normalize(xRange, Position=[-0.5, 0.5])
; xAxis, XCoord_Conv=xScale
On_Error, 1
IF N_Params() EQ 0 THEN Message, 'Please pass range vector as argument.'
IF (N_Elements(position) EQ 0) THEN position = [0.0, 1.0] ELSE $
position=Float(position)
range = Float(range)
scale = [((position[0]*range[1])-(position[1]*range[0])) / $
(range[1]-range[0]), (position[1]-position[0])/(range[1]-range[0])]
RETURN, scale
END
;-------------------------------------------------------------------------
Pro Surf_Contour_Cleanup, tlb
; Come here when program dies. Free all created objects.
Widget_Control, tlb, Get_UValue=info
IF N_Elements(info) NE 0 THEN Obj_Destroy, info.thisContainer
END
;-------------------------------------------------------------------
PRO Surf_Contour_Draw_Events, event
; Draw widget events handled here: expose events and trackball
; events. The trackball uses RSI-supplied TRACKBALL_DEFINE.PRO
; from the IDL50/examples/object directory.
Widget_Control, event.top, Get_UValue=info, /No_Copy
drawTypes = ['PRESS', 'RELEASE', 'MOTION', 'SCROLL', 'EXPOSE']
thisEvent = drawTypes(event.type)
CASE thisEvent OF
'EXPOSE': ; Nothing required except to draw the view.
'PRESS': BEGIN
Widget_Control, event.id, Draw_Motion_Events=1 ; Motion events ON.
info.thisWindow->SetProperty, Quality=info.dragQuality ; Drag Quality to Low.
needUpdate = info.thisTrackball->Update(event, Transform=thisTransform)
IF needUpdate THEN BEGIN
info.thisModel->GetProperty, Transform=modelTransform
info.thisModel->SetProperty, Transform=modelTransform # thisTransform
ENDIF
END
'RELEASE': BEGIN
Widget_Control, event.id, Draw_Motion_Events=0 ; Motion events OFF.
info.thisWindow->SetProperty, Quality=2 ; Drag Quality to High.
needUpdate = info.thisTrackball->Update(event, Transform=thisTransform)
IF needUpdate THEN BEGIN
info.thisModel->GetProperty, Transform=modelTransform
info.thisModel->SetProperty, Transform=modelTransform # thisTransform
ENDIF
END
'MOTION': BEGIN ; Trackball events
needUpdate = info.thisTrackball->Update(event, Transform=thisTransform)
IF needUpdate THEN BEGIN
info.thisModel->GetProperty, Transform=modelTransform
info.thisModel->SetProperty, Transform=modelTransform # thisTransform
ENDIF
END
ELSE:
ENDCASE
; Draw the view.
info.thisWindow->Draw, info.thisView
;Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
;-------------------------------------------------------------------
PRO Surf_Contour_XColors, event
; Event handler to select surface style.
Widget_Control, event.top, Get_UValue=info, /No_Copy
; What kind of event is this?
thisEvent = Tag_Names(event, /Structure_Name)
CASE thisEvent OF
'WIDGET_BUTTON': XColors, Group_Leader=event.top, $
NotifyID=[event.id, event.top]
'XCOLORS_LOAD': BEGIN
; Get color vectors.
red = event.r
green = event.g
blue = event.b
; Calculate and change contour colors.
nlevels = 12
dataColors = BytScl(info.data)
colorInterval = Fix(255/Float(nlevels))
cLevelColor = (BIndGen(nlevels) + 1) * colorInterval
contourColors = BIndGen(3, nlevels)
FOR j=0,nlevels-1 DO contourColors[*,j] = [red(cLevelColor[j]), $
green(cLevelColor[j]), blue(cLevelColor[j])]
info.thisContour->SetProperty, C_Color=contourColors
; Update the colorbar colors.
info.colorbar->SetProperty, Red=red, Green=green, Blue=blue
; Redisplay the view.
info.thisWindow->Draw, info.thisView
ENDCASE
ENDCASE
;Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
;-------------------------------------------------------------------
PRO Surf_Contour_Style, event
; Event handler to select surface style.
Widget_Control, event.top, Get_UValue=info, /No_Copy
; What style is wanted?
Widget_Control, event.id, Get_UValue=newStyle
CASE newStyle OF
'FILLED': info.thisContour->SetProperty, Fill=1
'UNFILLED': info.thisContour->SetProperty, Fill=0
'ON': IF NOT info.thisModel->ISContained(info.contourModel) THEN $
info.thisModel->Add, info.contourModel
'OFF': IF info.thisModel->ISContained(info.contourModel) THEN $
info.thisModel->Remove, info.contourModel
ENDCASE
; Redraw the graphic.
info.thisWindow->Draw, info.thisView
;Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
;-------------------------------------------------------------------
PRO Surf_Contour_Surface_Style, event
; Event handler to select surface style.
Widget_Control, event.top, Get_UValue=info, /No_Copy
; What style is wanted?
Widget_Control, event.id, Get_UValue=newStyle
CASE newStyle OF
'DOTS': info.thisSurface->SetProperty, Style=0
'MESH': info.thisSurface->SetProperty, Style=1
'SOLID': info.thisSurface->SetProperty, Style=2, Shading=1
'XPARALLEL': info.thisSurface->SetProperty, Style=3
'YPARALLEL': info.thisSurface->SetProperty, Style=4
ENDCASE
; Redraw the graphic.
info.thisWindow->Draw, info.thisView
;Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
;-------------------------------------------------------------------
PRO Surf_Contour_Slider_Events, event
; Event handler to handle contour slider events.
Widget_Control, event.top, Get_UValue=info, /No_Copy
; The slider value is the new GeomZ value after it is
; scaled into the coordinate system.
val = event.value - info.sliderValue
zrange = info.zrange
info.sliderValue = event.value
scaledVal = Float(val) / (zrange[1] - zrange[0])
info.ContourModel->Translate, 0, 0, scaledVal
; Redraw the graphic.
info.thisWindow->Draw, info.thisView
;Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
;-------------------------------------------------------------------
PRO Surf_Contour_Properties, event
; Event handler to set graphic properties.
Widget_Control, event.top, Get_UValue=info, /No_Copy
; What property is wanted?
Widget_Control, event.id, Get_UValue=newProperty
CASE newProperty OF
'ORIGINAL_T3D': info.thisModel->SetProperty, Transform=info.origTransform
; Surface color.
'SBLACK': info.thisSurface->SetProperty, Color=[0,0,0]
'SWHITE': info.thisSurface->SetProperty, Color=[255,255,255]
'SGREEN': info.thisSurface->SetProperty, Color=[0,255,0]
'SCHARCOAL': info.thisSurface->SetProperty, Color=[80,80,80]
'SYELLOW': info.thisSurface->SetProperty, Color=[255,255,0]
; Background color.
'BBLACK': info.thisView->SetProperty, Color=[0,0,0]
'BWHITE': info.thisView->SetProperty, Color=[255,255,255]
'BCHARCOAL': info.thisView->SetProperty, Color=[80,80,80]
; Axes colors.
'ABLACK': BEGIN
info.xAxis->SetProperty, Color=[0,0,0]
info.yAxis->SetProperty, Color=[0,0,0]
info.zAxis->SetProperty, Color=[0,0,0]
END
'AWHITE': BEGIN
info.xAxis->SetProperty, Color=[255,255,255]
info.yAxis->SetProperty, Color=[255,255,255]
info.zAxis->SetProperty, Color=[255,255,255]
END
'AGREEN': BEGIN
info.xAxis->SetProperty, Color=[0,255,0]
info.yAxis->SetProperty, Color=[0,255,0]
info.zAxis->SetProperty, Color=[0,255,0]
END
'AYELLOW': BEGIN
info.xAxis->SetProperty, Color=[255,255,0]
info.yAxis->SetProperty, Color=[255,255,0]
info.zAxis->SetProperty, Color=[255,255,0]
END
; Color schemes.
'B/W': BEGIN
info.thisView->SetProperty, Color=[255,255,255]
info.thisSurface->SetProperty, Color=[0,0,0]
info.xAxis->SetProperty, Color=[0,0,0]
info.yAxis->SetProperty, Color=[0,0,0]
info.zAxis->SetProperty, Color=[0,0,0]
END
'W/B': BEGIN
info.thisView->SetProperty, Color=[0,0,0]
info.thisSurface->SetProperty, Color=[255,255,255]
info.xAxis->SetProperty, Color=[255,255,255]
info.yAxis->SetProperty, Color=[255,255,255]
info.zAxis->SetProperty, Color=[255,255,255]
END
'ORIGINAL_COLORS': BEGIN
info.thisView->SetProperty, Color=[80,80,80]
info.thisSurface->SetProperty, Color=[255,255,0]
info.xAxis->SetProperty, Color=[0,255,0]
info.yAxis->SetProperty, Color=[0,255,0]
info.zAxis->SetProperty, Color=[0,255,0]
END
'DRAG_LOW': BEGIN
info.dragQuality = 0
Widget_Control, info.dragLowID, Sensitive=0
Widget_Control, info.dragMedID, Sensitive=1
Widget_Control, info.dragHighID, Sensitive=1
END
'DRAG_MEDIUM': BEGIN
info.dragQuality = 1
Widget_Control, info.dragMedID, Sensitive=0
Widget_Control, info.dragLowID, Sensitive=1
Widget_Control, info.dragHighID, Sensitive=1
END
'DRAG_HIGH': BEGIN
info.dragQuality = 2
Widget_Control, info.dragMedID, Sensitive=1
Widget_Control, info.dragLowID, Sensitive=1
Widget_Control, info.dragHighID, Sensitive=0
END
ENDCASE
; Redraw the graphic.
info.thisWindow->Draw, info.thisView
;Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
;-------------------------------------------------------------------
PRO Surf_Contour_Output, event
; This event handler creates GIF and JPEG files.
Widget_Control, event.top, Get_UValue=info, /No_Copy
; Get a snapshop of window contents. (TVRD equivalent.)
info.thisWindow->GetProperty, Image_Data=snapshot
; JPEG or GIF file wanted?
Widget_Control, event.id, GET_UValue=whichFileType
CASE whichFileType OF
'GIF': BEGIN
; Because we are using RGB color for this model, we have
; a 3-m-n array. Use Color_Quan to create a 2D image and
; appropriate color tables for the GIF file.
image2D = Color_Quan(snapshot, 1, r, g, b)
filename = Dialog_Pickfile(/Write, File='idl.gif')
IF filename NE '' THEN Write_GIF, filename, image2d, r, g, b
END
'JPEG': BEGIN
filename = Dialog_Pickfile(/Write, File='idl.jpg')
IF filename NE '' THEN Write_JPEG, filename, snapshot, True=1
END
ENDCASE
;Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
;-------------------------------------------------------------------
PRO Surf_Contour_Exit, event
; Exit the program. This will cause the CLEANUP
; routine to be called automatically.
Widget_Control, event.top, /Destroy
END
;-------------------------------------------------------------------
PRO Surf_Contour_Printing, event
; PostScript printing and printer setup handled here.
Widget_Control, event.top, Get_UValue=info, /No_Copy
; Which button?
Widget_Control, event.id, Get_UValue=ButtonValue
CASE buttonValue OF
'PRINT': BEGIN
result = Dialog_PrintJob(info.thisPrinter)
IF result EQ 1 THEN BEGIN
info.thisPrinter->Draw, info.thisView
info.thisPrinter->NewDocument
ENDIF
END
'SETUP': BEGIN
result = Dialog_PrinterSetup(info.thisPrinter)
IF result EQ 1 THEN BEGIN
info.thisPrinter->Draw, info.thisView
info.thisPrinter->NewDocument
ENDIF
END
ENDCASE
; Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
;-------------------------------------------------------------------
PRO Surf_Contour_Resize, event
; The only events generated by this simple program are resize
; events, which are handled here.
; Get the info structure.
Widget_Control, event.top, Get_UValue=info, /No_Copy
; Resize the draw widget.
info.thisWindow->SetProperty, Dimension=[event.x, event.y]
; Redisplay the graphic.
info.thisWindow->Draw, info.thisView
; Update the trackball objects location in the center of the
; window.
info.thisTrackball->Reset, [event.x/2, event.y/2], $
(event.y/2) < (event.x/2)
;Put the info structure back.
Widget_Control, event.top, Set_UValue=info, /No_Copy
END
;-------------------------------------------------------------------
PRO Surf_Contour, data, x, y, _Extra=extra, XTitle=xtitle, $
YTitle=ytitle, ZTitle=ztitle, Group_Leader=groupLeader
; Check for keywords.
IF N_Elements(xtitle) EQ 0 THEN xtitle='X Axis'
IF N_Elements(ytitle) EQ 0 THEN ytitle='Y Axis'
IF N_Elements(ztitle) EQ 0 THEN ztitle='Z Axis'
; Need some data.
Catch, error
IF error NE 0 THEN BEGIN ; Can't find cgDemoData.
data = DIST(41)
x = Findgen(41)
y = Findgen(41)
IF !Error NE -154 THEN Print, !Err_String ELSE Print, 'Skipping cgDemoData call.'
ENDIF
IF N_Elements(data) EQ 0 THEN BEGIN
data = cgDemoData(2)
ENDIF
s = Size(data)
IF s(0) NE 2 THEN Message,'Must pass 2D argument. Using fake data.'
IF N_Elements(x) EQ 0 THEN x = Findgen(s(1))
IF N_Elements(y) EQ 0 THEN y = Findgen(s(2))
Catch, /Cancel
; Create a view. Use RGB color. Charcoal background.
thisView = OBJ_NEW('IDLgrView', Color=[80,80,80], $
Viewplane_Rect=[-1.2,-1.1,2.3,2.3])
; Create a model for the surface and axes and add it to the view.
; This model will rotate under the direction of the trackball object.
thisModel = OBJ_NEW('IDLgrModel')
thisView->Add, thisModel
; Create a separate model for the colorbar that doesn't rotate.
cbarModel = Obj_New('IDLgrModel')
thisView->Add, cbarModel
; Create a shaded surface object. Make it yellow.
thisSurface = OBJ_NEW('IDLgrSurface', data, x, y, Style = 2, $
Shading=1, Color=[255,255,0], _Extra=extra)
; Colors are the only way to distinguish contour intervals.
; Here I load a color table and use colors from the table
; for the different contour lines.
thisDevice = !D.Name
Set_Plot, 'Z'
LoadCT, 4
TVLCT, red, green, blue, /Get
Set_Plot, thisDevice
nlevels = 12
dataColors = BytScl(data)
colorInterval = Fix(255/Float(nlevels))
cLevelColor = (BIndGen(nlevels) + 1) * colorInterval
contourColors = BIndGen(3, nlevels)
FOR j=0,nlevels-1 DO contourColors[*,j] = [red(cLevelColor[j]), $
green(cLevelColor[j]), blue(cLevelColor[j])]
; Create a contour plot object.
xrange = [Min(x), Max(x)]
yrange = [Min(y), Max(y)]
zrange = [Min(data), Max(data)+ 0.2*Max(data)]
xs = Normalize(xrange, Position=[-0.5, 0.5])
ys = Normalize(yrange, Position=[-0.5, 0.5])
zs = Normalize(zrange)
thisContour = Obj_New('IDLgrContour', data, GeomZ=0, N_Levels=nlevels, $
Color=[255, 255, 0], /Planar, XCoord_Conv=xs, YCoord_Conv=ys, $
ZCoord_Conv=zs, C_Color=contourColors, Fill=1)
; Create a contour model.
contourModel = Obj_New('IDLgrModel')
; Create axes for the contour plot. Color them yellow.
xAxis1 = Obj_New("IDLgrAxis", 0, Color=[255,255,0], Ticklen=0.05, $
Minor=4, /NoText, Range=xrange, XCoord_Conv=xs, $
Location=[1000, -0.5, 0.0], /Exact)
xAxis2 = Obj_New("IDLgrAxis", 0, Color=[255,255,0], Ticklen=0.05, $
Minor=4, /NoText, Range=xrange, XCoord_Conv=xs, $
Location=[1000, 0.5, 0.0], TickDir=1, /Exact)
yAxis1 = Obj_New("IDLgrAxis", 1, Color=[255,255,0], Ticklen=0.05, $
Minor=4, /NoText, Range=yrange, YCoord_Conv=ys, $
Location=[-0.5, 1000, 0.0], /Exact)
yAxis2 = Obj_New("IDLgrAxis", 1, Color=[255,255,0], Ticklen=0.05, $
Minor=4, /NoText, Range=yrange, YCoord_Conv=ys, $
Location=[0.5, 1000, 0.0], TickDir=1, /Exact)
; Add the axes to the model.
contourModel->Add, xAxis1
contourModel->Add, xAxis2
contourModel->Add, yAxis1
contourModel->Add, yAxis2
; Add the contour plot to the model and the model to the main model.
contourModel->Add, thisContour
thisModel->Add, contourModel
; Create title objects for the axes and plot. Color them green.
xTitle = Obj_New('IDLgrText', xtitle, Color=[0,255,0])
yTitle = Obj_New('IDLgrText', ytitle, Color=[0,255,0])
zTitle = Obj_New('IDLgrText', ztitle, Color=[0,255,0])
; Create axes objects for the surface. Color them green.
xAxis = Obj_New("IDLgrAxis", 0, Color=[0,255,0], Ticklen=0.1, $
Minor=4, Title=xtitle, /Exact)
xAxis->GetProperty, Ticktext=xAxisText
helvetica10pt = Obj_New('IDLgrFont', 'Helvetica', Size=10)
xAxisText->SetProperty, Font=helvetica10pt
yAxis = Obj_New("IDLgrAxis", 1, Color=[0,255,0], Ticklen=0.1, $
Minor=4, Title=ytitle, /Exact)
yAxis->GetProperty, Ticktext=yAxisText
yAxisText->SetProperty, Font=helvetica10pt
zAxis = Obj_New("IDLgrAxis", 2, Color=[0,255,0], Ticklen=0.1, $
Minor=4, Title=ztitle, /Exact)
zAxis->GetProperty, Ticktext=zAxisText
zAxisText->SetProperty, Font=helvetica10pt
; Add the surface and axes objects to the model.
thisModel->Add, thisSurface
thisModel->Add, xAxis
thisModel->Add, yAxis
thisModel->Add, zAxis
; Create a trackball for surface rotations. Center it in
; the window.
thisTrackball = OBJ_NEW('Trackball', [200, 200], 200)
; Get the data ranges for the surface.
thisSurface->GetProperty,XRange=xrange,YRange=yrange;,ZRange=zrange
; Create a positional light source for this surface.
; This will make the solid surface look shaded and not flat.
thisLight = Obj_New('IDLgrLight', Type=1, $
Location=[xrange[1], yrange[1], 4*zrange[1]])
thisModel->Add, thisLight
; Create a fill light underneath the surface. Make it red.
fillLight = Obj_New('IDLgrLight',Type=1, Intensity=0.5, $
Location=[xrange[0], yrange[0], -4*zrange[1]], Color=[255,0,0])
thisModel->Add, fillLight
; Set scaling parameters for the surface and axes so that everything
; is scaled into the range -0.5 to 0.5. We do this so that when the
; surface is rotated we don't have to worry about translations. In
; other words, the rotations occur about the point (0,0,0).
xs = Normalize(xrange, Position=[-0.5,0.5])
ys = Normalize(yrange, Position=[-0.5,0.5])
zs = Normalize(zrange, Position=[-0.5,0.5])
; Set the range, location, and scaling factors for the axes.
; Note that not all values in the Location keyword are
; used. (I've put really large values into the positions
; that are not being used to demonstate this.) For
; example, with the X axis only the Y and Z locations are used.
xAxis->SetProperty, Range=xrange, Location=[9999.0, -0.5, -0.5], $
XCoord_Conv=xs
yAxis->SetProperty, Range=yrange, Location=[-0.5, 9999.0, -0.5], $
YCoord_Conv=ys
zAxis->SetProperty, Range=zrange, Location=[-0.5, 0.5, 9999.0], $
ZCoord_Conv=zs
; Scale the surface and light source.
thisSurface->SetProperty,XCoord_Conv=xs, YCoord_Conv=ys, ZCoord_Conv=zs
thisLight->SetProperty,XCoord_Conv=xs, YCoord_Conv=ys, ZCoord_Conv=zs
; Rotate the surface model to the standard surface view.
thisModel->Rotate,[1,0,0], -90 ; To get the Z-axis vertical.
thisModel->Rotate,[0,1,0], 30 ; Rotate it slightly to the right.
thisModel->Rotate,[1,0,0], 30 ; Rotate it down slightly.
; Create a horizontal colorbar for the plot.
cbarFont = Obj_New('IDLgrFont', Name='Helvetica', Size=9)
cbarTitle = Obj_New('IDLgrText', 'Meters', Color=[255,255,0],Font=cbarFont)
; Create the tick labels for the colorbar.
nDivisions = 5
step = (zRange[1] - zRange[0]) / (nDivisions - 1)
cbarTicksValues = StrArr(nDivisions)
FOR j=0,nDivisions-1 DO cbarTicksValues[j] = String(zrange[0] + j*step, Format='(I4)')
cbarTicks = Obj_New('IDLgrText', cbarTicksValues, Color=[255,255,0], Font=cbarFont)
colorbar = Obj_New('IDLgrColorbar', red, green, blue, $
Dimensions=[256, 40], YCoord_Conv=Normalize([0,39],Position=[0.80, 0.90]), $
XCoord_Conv=Normalize([0,255],Position=[-0.5,0.5]),$
Title=cbarTitle, Major=nDivisions, Color=[255,255,0], TickLen=5, $
TickText=cbarTicks, /Show_Axis)
cbarModel->Add, colorbar
; Create the widgets to view the surface. Set expose events
; on the draw widget so that it refreshes itself whenever necessary.
; Button events are on to enable trackball movement.
tlb = Widget_Base(Title='Resizeable Window Surface Example', Column=1, $
TLB_Size_Events=1, MBar=menubase)
drawID = Widget_Draw(tlb, XSize=400, YSize=400, Graphics_Level=2, Retain=0, $
Expose_Events=1, Event_Pro='Surf_Contour_Draw_Events', Button_Events=1)
zmin = Fix(Floor(Min(data)))
zmax = Fix(Ceil(Max(data) + 0.2*(Max(data))))
zmid = (zmax - zmin) / 2
zrange = [zmin, zmax]
contourSlider = Widget_Slider(tlb, Value=zmid, Max=zmax, Min=zmin, $
Scr_XSize=400, Event_Pro='Surf_Contour_Slider_Events', $
Title='Contour Position')
; Create FILE menu buttons for printing and exiting.
filer = Widget_Button(menubase, Value='File', /Menu)
pnt = Widget_Button(filer, Value='Print', $
Event_Pro='Surf_Contour_Printing', UValue='PRINT')
pntset = Widget_Button(filer, Value='Print Setup', $
Event_Pro='Surf_Contour_Printing', UValue='SETUP')
quitter = Widget_Button(filer, /Separator, Value='Exit', $
Event_Pro='Surf_Contour_Exit')
; Create STYLE menu buttons for surface style.
style = Widget_Button(menubase, Value='Surface Style', /Menu)
dummy = Widget_Button(style, Value='Dot Surface', $
Event_Pro='Surf_Contour_Surface_Style', UValue='DOTS')
dummy = Widget_Button(style, Value='Wire Mesh', $
Event_Pro='Surf_Contour_Surface_Style', UValue='MESH')
dummy = Widget_Button(style, Value='Solid', $
Event_Pro='Surf_Contour_Surface_Style', UValue='SOLID')
dummy = Widget_Button(style, Value='Parallel X Lines', $
Event_Pro='Surf_Contour_Surface_Style', UValue='XPARALLEL')
dummy = Widget_Button(style, Value='Parallel Y Lines', $
Event_Pro='Surf_Contour_Surface_Style', UValue='YPARALLEL')
; Create STYLE menu buttons for contour plot.
style = Widget_Button(menubase, Value='Contour Controls', /Menu)
dummy = Widget_Button(style, Value='Filled Contour', $
Event_Pro='Surf_Contour_Style', UValue='FILLED')
dummy = Widget_Button(style, Value='Unfilled Contour', $
Event_Pro='Surf_Contour_Style', UValue='UNFILLED')
dummy = Widget_Button(style, Value='Contour ON', $
Event_Pro='Surf_Contour_Style', UValue='ON')
dummy = Widget_Button(style, Value='Contour OFF', $
Event_Pro='Surf_Contour_Style', UValue='OFF')
dummy = Widget_Button(style, Value='Change Colors', $
Event_Pro='Surf_Contour_XCOLORS', /Separator)
; Create PROPERTIES menu buttons for surface properties.
properties = Widget_Button(menubase, Value='Properties', /Menu)
; Surface Color
scolor = Widget_Button(properties, Value='Surface Color', /Menu)
dummy = Widget_Button(scolor, Value='Black', $
Event_Pro='Surf_Contour_Properties', UValue='SBLACK')
dummy = Widget_Button(scolor, Value='White', $
Event_Pro='Surf_Contour_Properties', UValue='SWHITE')
dummy = Widget_Button(scolor, Value='Charcoal', $
Event_Pro='Surf_Contour_Properties', UValue='SCHARCOAL')
dummy = Widget_Button(scolor, Value='Yellow', $
Event_Pro='Surf_Contour_Properties', UValue='SYELLOW')
dummy = Widget_Button(scolor, Value='Green', $
Event_Pro='Surf_Contour_Properties', UValue='SGREEN')
; Background Color
bcolor = Widget_Button(properties, Value='Background Color', /Menu)
dummy = Widget_Button(bcolor, Value='Black', $
Event_Pro='Surf_Contour_Properties', UValue='BBLACK')
dummy = Widget_Button(bcolor, Value='White', $
Event_Pro='Surf_Contour_Properties', UValue='BWHITE')
dummy = Widget_Button(bcolor, Value='Charcoal', $
Event_Pro='Surf_Contour_Properties', UValue='BCHARCOAL')
; Axes Color
acolor = Widget_Button(properties, Value='Axes Color', /Menu)
dummy = Widget_Button(acolor, Value='Black', $
Event_Pro='Surf_Contour_Properties', UValue='ABLACK')
dummy = Widget_Button(acolor, Value='White', $
Event_Pro='Surf_Contour_Properties', UValue='AWHITE')
dummy = Widget_Button(acolor, Value='Yellow', $
Event_Pro='Surf_Contour_Properties', UValue='AYELLOW')
dummy = Widget_Button(acolor, Value='Green', $
Event_Pro='Surf_Contour_Properties', UValue='AGREEN')
; Color Schemes.
dummy = Widget_Button(properties, Value='Black on White', /Separator, $
Event_Pro='Surf_Contour_Properties', UValue='B/W')
dummy = Widget_Button(properties, Value='White on Black', $
Event_Pro='Surf_Contour_Properties', UValue='W/B')
dummy = Widget_Button(properties, Value='Original Colors', $
Event_Pro='Surf_Contour_Properties', UValue='ORIGINAL_COLORS')
; Original Axis rotation.
dummy = Widget_Button(properties, Value='Original Rotation', /Separator, $
Event_Pro='Surf_Contour_Properties', UValue='ORIGINAL_T3D')
; Drag Quality.
dragID = Widget_Button(properties, Value='Drag Quality', /Separator, /Menu)
dragLowID = Widget_Button(dragID, Value='Low', $
Event_Pro='Surf_Contour_Properties', UValue='DRAG_LOW')
dragMedID = Widget_Button(dragID, Value='Medium', $
Event_Pro='Surf_Contour_Properties', UValue='DRAG_MEDIUM')
dragHighID = Widget_Button(dragID, Value='High', $
Event_Pro='Surf_Contour_Properties', UValue='DRAG_HIGH')
Widget_Control, dragHighID, Sensitive=0
; Create OUTPUT menu buttons for formatted output files.
output = Widget_Button(menubase, Value='Output')
gif = Widget_Button(output, Value='GIF File', $
UValue='GIF', Event_Pro='Surf_Contour_Output')
jpeg = Widget_Button(output, Value='JPEG File', $
UValue='JPEG', Event_Pro='Surf_Contour_Output')
Widget_Control, tlb, /Realize
; Get the window destination object. The view will
; be drawn when the window is exposed.
Widget_Control, drawID, Get_Value=thisWindow
; Get a printer object for this graphic.
thisPrinter = Obj_New('IDLgrPrinter')
; Create a container object to hold all the other
; objects. This will make it easy to free all the
; objects when we are finished with the program.
thisContainer = Obj_New('IDL_Container')
; Add created objects to the container.
thisContainer->Add, thisView
thisContainer->Add, thisPrinter
thisContainer->Add, thisTrackball
thisContainer->Add, xTitle
thisContainer->Add, yTitle
thisContainer->Add, zTitle
thisContainer->Add, xAxis
thisContainer->Add, yAxis
thisContainer->Add, zAxis
thisContainer->Add, thisSurface
thisContainer->Add, thisLight
thisContainer->Add, fillLight
thisContainer->Add, contourModel
thisContainer->Add, thisContour
thisContainer->Add, thisModel
thisContainer->Add, colorbar
thisContainer->Add, helvetica10pt
thisContainer->Add, cbarTitle
thisContainer->Add, cbarFont
thisContainer->Add, cbarTicks
; Get the current transformation matrix, so it can be restored.
thisModel->GetProperty, Transform=origTransform
; Create an INFO structure to hold needed program information.
info = { origTransform:origTransform, $ ; The transformation matrix.
thisContainer:thisContainer, $ ; The object container.
thisWindow:thisWindow, $ ; The window object.
thisPrinter:thisPrinter, $ ; The printer object.
thisSurface:thisSurface, $ ; The surface object.
thisTrackball:thisTrackball, $ ; The trackball object.
thisModel:thisModel, $ ; The model object.
thisContour:thisContour, $ ; The contour object.
contourModel:contourModel, $ ; The contour model.
sliderValue:zmid, $ ; The current contour slider value.
zrange:zrange, $ ; The range of the Z axis.
colorbar:colorbar, $ ; The colorbar object.
xAxis:xAxis, $ ; The X Axis object.
yAxis:yAxis, $ ; The Y Axis object.
zAxis:zAxis, $ ; The Z Axis object.
data:data, $ ; The Z data that is being surfaced.
dragLowID:dragLowID, $ ; ID of Drag Quality Low button.
dragMedID:dragMedID, $ ; ID of Drag Quality Medium button.
dragHighID:dragHighID, $ ; ID of Drag Quality High button.
dragQuality:2, $ ; The current drag quality.
thisView:thisView } ; The view object.
; Store the info structure in the UValue of the TLB.
Widget_Control, tlb, Set_UValue=info, /No_Copy
; Call XManager. Set a cleanup routine so the objects
; can be freed upon exit from this program.
XManager, 'surf_contour', tlb, Cleanup='Surf_Contour_Cleanup', $
Event_Handler='Surf_Contour_Resize', Group_Leader=groupLeader, /No_Block
END
;-------------------------------------------------------------------