-
Notifications
You must be signed in to change notification settings - Fork 0
/
pick3d.pro
1252 lines (1083 loc) · 33.3 KB
/
pick3d.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
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
;*************************************************************************
; Copyright (c) 2002 The University of Chicago, as Operator of Argonne
; National Laboratory.
; Copyright (c) 2002 The Regents of the University of California, as
; Operator of Los Alamos National Laboratory.
; This file is distributed subject to a Software License Agreement found
; in the file LICENSE that is included with this distribution.
;*************************************************************************
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha,
; 10-05-2003 bkc Add features of automatic ascii/xdr/tiff files generation
;-
; @read_scan.pro.R2.4
@view3d_2d.pro
@panimage.pro
PRO pick3d_report_imascii,im,xa,ya,fn
sz = size(im)
f0_0 = '('+strtrim(sz(2),2)+'g17.8)'
f0_1 = '('+strtrim(sz(1),2)+'g17.8)'
openw,1,fn
printf,1,'Xaxis:'
printf,1,format=f0_1,xa
printf,1,'Yaxis:'
printf,1,format=f0_0,ya
printf,1,'Rows='+strtrim(sz(1),2), ' Cols='+strtrim(sz(2),2)
for i=0,sz(1)-1 do begin
lineA = reform(im(i,*))
printf,1,format=f0_0,lineA
end
close,1
END
PRO parse_num0,instring,ids,sep=sep
Keysepar = '-'
if keyword_set(sep) then Keysepar = sep
res = strpos(instring,keysepar)
if res ne -1 then begin
str = str_sep(instring,keysepar,/trim)
no = fix(str(1)) - fix(str(0)) + 1
ids = indgen(no) + fix(str(0))
endif else begin
com = strpos(instring,',')
if com ne -1 then begin
str = str_sep(instring,',')
ids = fix(str)
endif else begin
str = str_sep(instring,' ')
ids = fix(str)
end
end
END
; parse by sep1 first then by sep2
; default sep1=',' sep2='-'
; instring = '1,2:5,7'
; instring = '1,2-5,7'
PRO parse_num,instring,res,sep1=sep1,sep2=sep2
d_sep1 = ','
d_sep2 = '-'
if keyword_set(sep1) then d_sep1 = sep1
if keyword_set(sep2) then d_sep2 = sep2
str = str_sep(instring,d_sep1,/trim)
res = fix(str(0))
for i=0,n_elements(str)-1 do begin
newstr = strtrim(str(i),2)
if strlen(newstr) gt 0 then begin
parse_num0,newstr,ids,sep=d_sep2
if i eq 0 then begin
if n_elements(ids) gt 1 then res = ids
end
if i gt 0 then res = [res,ids]
end
end
END
PRO pick3d_XdrRpt,rpt_state,TIFF=TIFF
pick3d_state = rpt_state.state
det_list = *rpt_state.det_list
slc_list = *rpt_state.slc_list
TVLCT,R,G,B,/get
if keyword_set(TIFF) then window,1,xsize=350,ysize=350,retain=2,/pixmap
axis = pick3d_state.panaxis
det = where(pick3d_state.id_def(*,0) > 0)
last_det = det(n_elements(det)-1)
for i=0,n_elements(det_list)-1 do begin
if det_list(i) le (last_det+1) then begin
pick3d_state.pickDet = det_list(i)
view3d_pickDet,pick3d_state,data
data = *(pick3d_state.data)
sz = size(data)
prefix = strmid(pick3d_state.class,0,strlen(pick3d_state.class)-4)
if keyword_set(TIFF) then $
path = pick3d_state.path+'TIFF'+!os.file_sep else $
path = pick3d_state.path+'XDR'+!os.file_sep
file_mkdir,path
xa = *pick3d_state.x
ya = *pick3d_state.y
if axis eq 1 then ya = *pick3d_state.z
if axis eq 0 then begin
xa = ya
ya = *pick3d_state.z
end
for j=0,n_elements(slc_list)-1 do begin
jj = slc_list(j)
if axis eq 2 then begin
if jj le sz(3) then begin
im = data(*,*,jj-1)
if keyword_set(TIFF) then $
fn = path+prefix+'.'+ $
pick3d_state.detname(det_list(i)-1) + $
'.Zs'+ strtrim(jj,2)+'.tif' else $
fn = path+prefix+'.'+ $
pick3d_state.detname(det_list(i)-1) + $
'.Zs'+ strtrim(jj,2)+'.xdr'
print,fn
end
end
if axis eq 1 then begin
if jj le sz(2) then begin
im = reform(data(*,jj-1,*))
if keyword_set(TIFF) then $
fn = path+prefix+'.'+ $
pick3d_state.detname(det_list(i)-1) + $
'.Ys'+ strtrim(jj,2)+'.tif' else $
fn = path+prefix+'.'+ $
pick3d_state.detname(det_list(i)-1) + $
'.Ys'+ strtrim(jj,2)+'.xdr'
print,fn
end
end
if axis eq 0 then begin
if (jj le sz(1)) then begin
im = reform(data(jj-1,*,*))
if keyword_set(TIFF) then $
fn = path+prefix+'.'+ $
pick3d_state.detname(det_list(i)-1) + $
'.Xs'+ strtrim(jj,2)+'.tif' else $
fn = path+prefix+'.'+ $
pick3d_state.detname(det_list(i)-1) + $
'.Xs'+ strtrim(jj,2)+'.xdr'
print,fn
end
end
; write TIFF/XDR
if keyword_set(TIFF) then begin
wset,1
tvscl,congrid(im,350,350)
write_tiff,fn,tvrd(),red=R,green=G,blue=B
endif else begin
xdr_open,unit,fn,/write
xdr_write,unit,im
xdr_close,unit
end
end
end
end
wdelete,1
END
PRO pick3d_asciiRpt,rpt_state
pick3d_state = rpt_state.state
det_list = *rpt_state.det_list
slc_list = *rpt_state.slc_list
file_mkdir,pick3d_state.path+'ASCII'
axis = pick3d_state.panaxis
det = where(pick3d_state.id_def(*,0) > 0)
last_det = det(n_elements(det)-1)
for i=0,n_elements(det_list)-1 do begin
if det_list(i) le (last_det+1) then begin
pick3d_state.pickDet = det_list(i)
view3d_pickDet,pick3d_state,data
data = *(pick3d_state.data)
sz = size(data)
; prefix = strmid(pick3d_state.filename,0,strlen(pick3d_state.filename)-4)
prefix = strmid(pick3d_state.class,0,strlen(pick3d_state.class)-4)
path = pick3d_state.path+'ASCII'+!os.file_sep
file_mkdir,path
xa = *pick3d_state.x
ya = *pick3d_state.y
if axis eq 1 then ya = *pick3d_state.z
if axis eq 0 then begin
xa = ya
ya = *pick3d_state.z
end
for j=0,n_elements(slc_list)-1 do begin
jj = slc_list(j)
if axis eq 2 then begin
if jj le sz(3) then begin
im = data(*,*,jj-1)
fn = path+prefix+'.'+ $
pick3d_state.detname(det_list(i)-1) + $
'.Zs'+ strtrim(jj,2)+'.txt'
print,fn
pick3d_report_imascii,im,xa,ya,fn
end
end
if axis eq 1 then begin
if jj le sz(2) then begin
im = reform(data(*,jj-1,*))
fn = path+prefix+'.'+ $
pick3d_state.detname(det_list(i)-1) + $
'.Ys'+ strtrim(jj,2)+'.txt'
print,fn
pick3d_report_imascii,im,xa,ya,fn
end
end
if axis eq 0 then begin
if (jj le sz(1)) then begin
im = reform(data(jj-1,*,*))
fn = path+prefix+'.'+ $
pick3d_state.detname(det_list(i)-1) + $
'.Xs'+ strtrim(jj,2)+'.txt'
print,fn
pick3d_report_imascii,im,xa,ya,fn
end
end
end
end
end
END
PRO pick3d_report_Event, Event
WIDGET_CONTROL,Event.top,GET_UVALUE=rpt_state
WIDGET_CONTROL,Event.Id,GET_UVALUE=Ev
CASE Ev OF
'FIELD5': BEGIN
Print, 'Event for Detectors:'
END
'FIELD6': BEGIN
Print, 'Event for Slices:'
END
'pick3d_sliceXdr_accept': BEGIN
widget_control,rpt_state.det_WID,get_value=st1
widget_control,rpt_state.slc_WID,get_value=st2
sep2='-'
if strcmp(st1,':') eq 1 then sep2=':'
parse_num,st1,det_list,sep2=sep2
sep2='-'
if strcmp(st2,':') eq 1 then sep2=':'
parse_num,st2,slc_list,sep2=sep2
*rpt_state.det_list = det_list
*rpt_state.slc_list = slc_list
pick3d_XdrRpt,rpt_state
WIDGET_CONTROL,Event.top,/DESTROY
END
'pick3d_sliceTiff_accept': BEGIN
widget_control,rpt_state.det_WID,get_value=st1
widget_control,rpt_state.slc_WID,get_value=st2
sep2='-'
if strcmp(st1,':') eq 1 then sep2=':'
parse_num,st1,det_list,sep2=sep2
sep2='-'
if strcmp(st2,':') eq 1 then sep2=':'
parse_num,st2,slc_list,sep2=sep2
*rpt_state.det_list = det_list
*rpt_state.slc_list = slc_list
pick3d_XdrRpt,rpt_state,/TIFF
WIDGET_CONTROL,Event.top,/DESTROY
END
'pick3d_sliceRpt_accept': BEGIN
widget_control,rpt_state.det_WID,get_value=st1
widget_control,rpt_state.slc_WID,get_value=st2
sep2='-'
if strcmp(st1,':') eq 1 then sep2=':'
parse_num,st1,det_list,sep2=sep2
sep2='-'
if strcmp(st2,':') eq 1 then sep2=':'
parse_num,st2,slc_list,sep2=sep2
*rpt_state.det_list = det_list
*rpt_state.slc_list = slc_list
pick3d_asciiRpt,rpt_state
WIDGET_CONTROL,Event.top,/DESTROY
END
'pick3d_sliceRpt_done': BEGIN
WIDGET_CONTROL,Event.top,/DESTROY
END
ENDCASE
END
PRO pick3d_report, pick3d_state,GROUP=Group
IF N_ELEMENTS(Group) EQ 0 THEN GROUP=0
junk = { CW_PDMENU_S, flags:0, name:'' }
pick3d_reportB = WIDGET_BASE(GROUP_LEADER=Group, $
ROW=1, $
MAP=1, $
UVALUE='pick3d_reportB')
BASE2 = WIDGET_BASE(pick3d_reportB, $
COLUMN=1, $
MAP=1, $
UVALUE='BASE2')
LABEL3 = WIDGET_LABEL( BASE2, $
UVALUE='LABEL3', $
VALUE='Pick3d Report Generation')
LABEL4 = WIDGET_LABEL( BASE2, $
UVALUE='LABEL4', $
VALUE='Filename: fullpathfilename')
FieldVal257 = [ $
pick3d_state.pickDet ]
FIELD5 = CW_FIELD( BASE2,VALUE=FieldVal257, $
ROW=1, $
STRING=1, $
TITLE='Detectors:', $
UVALUE='FIELD5')
FieldVal322 = [ $
'1, 3-5' ]
FIELD6 = CW_FIELD( BASE2,VALUE=FieldVal322, $
ROW=1, $
STRING=1, $
TITLE='Slices:', $
UVALUE='FIELD6')
BASE11 = WIDGET_BASE(BASE2, $
ROW=1, $
MAP=1, $
UVALUE='BASE11')
BUTTON11 = WIDGET_BUTTON( BASE11, $
UVALUE='pick3d_sliceXdr_accept', $
VALUE='XDR')
BUTTON11 = WIDGET_BUTTON( BASE11, $
UVALUE='pick3d_sliceTiff_accept', $
VALUE='TIFF')
BUTTON12 = WIDGET_BUTTON( BASE11, $
UVALUE='pick3d_sliceRpt_accept', $
VALUE='Ascii')
BUTTON13 = WIDGET_BUTTON( BASE11, $
UVALUE='pick3d_sliceRpt_done', $
VALUE='Done')
rpt_state = { parent: Group, $
state: pick3d_state, $
det_WID: FIELD5, $
slc_WID: FIELD6, $
det_list: ptr_new(/ALLOCATE_HEAP), $
slc_list: ptr_new(/ALLOCATE_HEAP) $
}
WIDGET_CONTROL, pick3d_reportB, /REALIZE
WIDGET_CONTROL,pick3d_reportB,SET_UVALUE=rpt_state
XMANAGER, 'pick3d_report', pick3d_reportB
END
PRO pick3d_writeConfig,state
openw,unit,'pick3d.config',/get_lun
printf,unit,state.filename
printf,unit,state.path
printf,unit,''
free_lun,unit
END
PRO pick3d_readConfig,filename,path
filename=''
path=''
openr,unit,'pick3d.config',/get_lun
readf,unit,filename
readf,unit,path
free_lun,unit
END
PRO pick3dToxdr,pick3d_state,xdrname,append=append
data = *(pick3d_state.data)
xdr_open,unit,xdrname ,/write, append=append
xdr_write,unit,data
xdr_close,unit
END
PRO scan3d_Writexdr,pick3d_state,xdrname
det = where(pick3d_state.id_def,0)
for i=0,n_elements(det)-1 do begin
pick3d_state.pickDet = det(i)+1
view3d_pickDet,pick3d_state,data
data = *(pick3d_state.data)
if i gt 0 then xdr_open,unit,xdrname ,/write,/append else $
xdr_open,unit,xdrname ,/write
xdr_write,unit,data
xdr_close,unit
end
END
PRO scan3d_Readxdr,pick3d_state,xdrname,Event
if pick3d_state.dim ne 3 then begin
r = dialog_message('Load 3D scan file in first',/error)
return
end
det = where(pick3d_state.id_def,0)
dnames = pick3d_state.detname(det)
; print,pick3d_state.npts, pick3d_state.pickZind, pick3d_state.panAxis
npts = pick3d_state.npts
ndet = n_elements(det)
title='3D_Pick_'
if pick3d_state.panAxis eq 0 then begin
image_array = make_array(npts(1),npts(2),ndet)
title = 'X_Axis_:_'
end
if pick3d_state.panAxis eq 1 then begin
image_array = make_array(npts(0),npts(2),ndet)
title = 'Y_Axis_:_'
end
if pick3d_state.panAxis eq 2 then begin
image_array = make_array(npts(0),npts(1),ndet)
title = 'Z_Axis_:_'
end
title = title+'Slice #'+string(pick3d_state.pickZind)
xdr_open,unit,xdrname
point_lun,unit,0
for i=0,ndet-1 do begin
t1=systime(1)
xdr_read,unit,data
print,'Read time =',systime(1)-t1, ' for Detector : ',Det(i), i
if pick3d_state.panAxis eq 0 then begin
image_array(*,*,i) = data(pick3d_state.pickZind,*,*)
xv = *pick3d_state.y
yv = *pick3d_state.z
end
if pick3d_state.panAxis eq 1 then begin
image_array(*,*,i) = data(*,pick3d_state.pickZind,*)
xv = *pick3d_state.x
yv = *pick3d_state.z
end
if pick3d_state.panAxis eq 2 then begin
image_array(*,*,i) = data(*,*,pick3d_state.pickZind)
xv = *pick3d_state.x
yv = *pick3d_state.y
end
end
xdr_close,unit
;help,image_array
def = make_array(ndet,value=1,/int)
panimage,image_array,def,title= title+'_(All_Di)'
if pick3d_state.realaxis eq 0 then $
calibration_factor,image_array,def,dnames=dnames, $
title=title,Group=Event.top else $
calibration_factor,image_array,def,dnames=dnames, $
title=title,Group=Event.top, $
xv = xv, yv=yv
END
PRO view3d_pickDet,pick3d_state, data, Event ;file,det,data
WIDGET_CONTROL,/HOURGLASS
;if n_elements(Scan3D) ne 0 then begin
; rank = *Scan3D.dim
; ptr_free,Scan3D.scanno
; ptr_free,Scan3D.dim
; ptr_free,Scan3D.npts
; ptr_free,Scan3D.cpt
; ptr_free,Scan3D.id_def
; ptr_free,Scan3D.pv
; ptr_free,Scan3D.labels
; for i=0,rank-1 do begin
; ptr_free,(*Scan3D.pa)[i]
; ptr_free,(*Scan3D.da)[i]
; end
; ptr_free,Scan3D.pa
; ptr_free,Scan3D.da
; ptr_free,Scan3D
; heap_gc
;end
file = pick3d_state.filename
det = pick3d_state.pickDet
t1=systime(1)
r = read_scan(file,Scan3D,pickDet=det,dump=pick3d_state.debug)
print,'Time used in read_scan = ',systime(1)-t1,' Detector',det
if r lt 0 then begin
ret = dialog_message('Read failed on: '+pick3d_state.filename,/error)
return
end
pick3d_state.dim = *Scan3D.dim
if pick3d_state.dim ne 3 then begin
ret = dialog_message('Sorry! '+pick3d_state.filename+' is not a 3D scan file.',/error)
return
end
def = *Scan3D.id_def
pick3d_state.id_def = def(4:89-1,*)
pick3d_state.labels = *Scan3D.labels
pick3d_state.pv = *Scan3D.pv
pick3d_state.npts = *Scan3D.npts
pick3d_state.pickDet = det
pick3d_state.scanno = *Scan3D.scanno ;r
data = *(*Scan3D.da)[0]
*(pick3d_state.da1D) = *(*Scan3D.da)[2]
*(pick3d_state.da2D) = *(*Scan3D.da)[1]
*(pick3d_state.data) = data
;help,data
z = *(*Scan3D.pa)[2]
*(pick3d_state.z) = z(0:pick3d_state.npts(2)-1)
y = *(*Scan3D.pa)[1]
*(pick3d_state.y) = y(0:pick3d_state.npts(1)-1)
x= *(*Scan3D.pa)[0]
*(pick3d_state.x) = x(0:pick3d_state.npts(0)-1)
free_scanAlloc,Scan3D
if ptr_valid(Scan3D) then ptr_free,Scan3D
pick3d_sensitive_on,pick3d_state
if n_elements(Event) then begin
if pick3d_state.id_def(pick3d_state.pickDet-1,0) eq 0 then begin
ex = where(pick3d_state.id_def(*,0))
xst = 'Defined detector : '+pick3d_state.detname(ex)
xs = ['Wrong detector picked : '+pick3d_state.detname(pick3d_state.pickDet-1)]
xst = [xs,'',xst,'']
xst = [xst,'Please select the correct detector #']
res = dialog_message(xst,/info)
; WIDGET_CONTROL,pick3d_state.listWID,SET_LIST_SELECT=ex(0)
; pick3d_state.pickDet = ex(0)+1
return
end
rank = pick3d_state.panAxis
xv = *(pick3d_state.x)
yv = *(pick3d_state.y)
zv = *(pick3d_state.z)
str = '(vs Values)'
if pick3d_state.realaxis eq 0 then begin
xv = indgen(pick3d_state.npts(0))
yv = indgen(pick3d_state.npts(1))
zv = indgen(pick3d_state.npts(2))
str = '(vs Index #)'
end
title=pick3d_state.class+':'+pick3d_state.detname(pick3d_state.pickDet-1) + str
view3d_2D,data,rank,xv,yv,zv, title=title, Group=Event.top
end
END
PRO pick3d_sensitive_off,pick3d_state
WIDGET_CONTROL,pick3d_state.dataWID,SENSITIVE= 0
; WIDGET_CONTROL,pick3d_state.allZlistWID,SENSITIVE= 0
; WIDGET_CONTROL,pick3d_state.calibWID,SENSITIVE= 0
END
PRO pick3d_sensitive_on,pick3d_state
WIDGET_CONTROL,pick3d_state.dataWID,SENSITIVE= 1
; WIDGET_CONTROL,pick3d_state.calibWID,SENSITIVE= 1
; WIDGET_CONTROL,pick3d_state.allZlistWID, SENSITIVE=1, $
SET_VALUE=indgen(pick3d_state.npts(pick3d_state.panAxis),/string)
END
PRO PICK3D_2DMENU_Event, Event,pick3d_state
if n_elements(*(pick3d_state.da2D)) eq 0 then return
da2d = *(pick3d_state.da2D)
x = *(pick3d_state.y)
y = *(pick3d_state.z)
title=pick3d_state.class+':'+pick3d_state.detname(pick3d_state.pickDet-1) + '_(3D_2D)'
CASE Event.Value OF
'3D_2D Menu.Pick 2D...': BEGIN
pick2d,da2d,x,y,GROUP=Event.top,class=pick3d_state.class, $
path=pick3d_state.outpath
END
'3D_2D Menu.PanImages...': BEGIN
sz = size(da2d)
def = pick3d_state.id_def(0:sz(3)-1,1)
panimage_sel,da2d,def,title= title+'_(All_Di)'
id_def = pick3d_state.id_def
det_def = id_def(*,1)
nd = max(where(det_def > 0))
labels = pick3d_state.labels
x_lbl = reform(labels(*,1),89,3)
y_lbl = reform(labels(*,2),89,3)
xdescs = x_lbl(0,0)
zdescs = x_lbl(4:4+sz(3)-1,1)
if x_lbl(0,1) ne '' then xdescs = xdescs+ ' '+ x_lbl(0,1)
ydescs = y_lbl(0,0)
if y_lbl(0,1) ne '' then ydescs = ydescs+ ' '+ y_lbl(0,1)
image2d,da2d,x,y,title=title,xdescs=xdescs,ydescs=ydescs, $
zdescs=zdescs,group=Event.top
END
'3D_2D Menu.CALIB2D...': BEGIN
sz = size(da2d)
def = pick3d_state.id_def(0:sz(3)-1,1)
panimage,da2d,def,title= title+'_(All_Di)'
if pick3d_state.realaxis eq 0 then $
calibration_factor,da2d,def, $
title=title,Group=Event.top else $
calibration_factor,da2d,def, $
title=title,Group=Event.top, $
xv = x, yv=y
END
'3D_2D Menu.Plot/Pick 1D...': BEGIN
x = *(pick3d_state.z)
sz = size(da1d)
plot1d,x,da1d,Group=Event.top,/data
END
'3D_2D Menu.CALIB1D...': BEGIN
da1d = *(pick3d_state.da1D)
sz = size(da1d)
def = make_array(sz(2),value=1,/int)
x = *(pick3d_state.z)
help,da1d,x,def
; if pick3d_state.realaxis eq 0 then $
; calibration_factor,da1d,def, $
; title=title,Group=Event.top else $
calibration_factor,da1d,def, $
title='3D_2D_(All_1D_Di)',Group=Event.top, $
xv = x
END
ENDCASE
END
PRO PICK3D_Event, Event
WIDGET_CONTROL, Event.top, GET_UVALUE=pick3d_state
WIDGET_CONTROL,Event.Id,GET_UVALUE=Ev
CASE Ev OF
'PICK3D_2DMENU': BEGIN
PICK3D_2DMENU_Event, Event, pick3d_state
END
'PICK3D_NEXT': BEGIN
pick3d_sensitive_off,pick3d_state
no = pick3d_state.scanno +1
pick3d_state.scanno = no
seqno = strtrim(no,2)
st = '0000'
strput,st,seqno,4-strlen(seqno)
pick3d_state.class = pick3d_state.prefix+st+pick3d_state.suffix
if pick3d_state.last lt no then pick3d_state.last = no
file = pick3d_state.path+pick3d_state.class
found = findfile(file,count=ct)
if ct le 0 then begin
res=dialog_message(file+' not found!',/error)
endif else WIDGET_CONTROL,pick3d_state.fileWID,set_value=file
pick3d_state.filename = file
det = pick3d_state.pickDet
view3d_pickDet, pick3d_state, data, Event
END
'PICK3D_PREV': BEGIN
pick3d_sensitive_off,pick3d_state
no = pick3d_state.scanno -1
if no lt 1 then return
pick3d_state.scanno = no
seqno = strtrim(no,2)
st = '0000'
strput,st,seqno,4-strlen(seqno)
pick3d_state.class = pick3d_state.prefix+st+pick3d_state.suffix
file = pick3d_state.path+pick3d_state.class
found = findfile(file,count=ct)
if ct le 0 then begin
res=dialog_message(file+' not found!',/error)
return
endif else WIDGET_CONTROL,pick3d_state.fileWID,set_value=file
pick3d_state.filename = file
det = pick3d_state.pickDet
view3d_pickDet, pick3d_state, data, Event
END
'PICK3D_PICKFILE': BEGIN
pick3d_sensitive_off,pick3d_state
flt = '*'+pick3d_state.suffix+'*'
file = dialog_pickfile(get_path=p,/read,/must_exist,path=pick3d_state.path, $
filter=flt,title='Select 3D Scan File Only')
if file eq '' then return
pick3d_state.path = p
pick3d_state.filename = file
id = strpos(file,!os.file_sep,/reverse_search)
pick3d_state.class = strmid(file,id+1,strlen(file)-id)
ip = strpos(pick3d_state.class,'_',/reverse_search)
pick3d_state.prefix = strmid(pick3d_state.class,0,ip+1)
ip = strpos(file,'.',/reverse_search)
pick3d_state.suffix = strmid(file,ip,strlen(file)-ip)
WIDGET_CONTROL,pick3d_state.fileWID,SET_VALUE=file
; set hardware type
det = pick3d_state.pickDet
view3d_pickDet, pick3d_state, data, Event
END
'PICK3D_LOADCT': BEGIN
XLOADCT,group=Event.top
END
'PICK3D_FILENAME': BEGIN
pick3d_sensitive_off,pick3d_state
WIDGET_CONTROL,pick3d_state.fileWID,GET_VALUE=file
pick3d_state.filename = file
id = strpos(file,!os.file_sep,/reverse_search)
pick3d_state.class = strmid(file,id+1,strlen(file)-id)
ip = strpos(pick3d_state.class,'_',/reverse_search)
pick3d_state.prefix = strmid(pick3d_state.class,0,ip+1)
det = pick3d_state.pickDet
view3d_pickDet, pick3d_state, data, Event
END
'PICK3D_READALLXDR': BEGIN
xdrname = pick3d_state.xdrname
scan3d_Readxdr,pick3d_state,xdrname,Event
END
'PICK3D_ALLXDR': BEGIN
if pick3d_state.dim ne 3 then begin
r = dialog_message('Load 3D scan file in first',/error)
return
end
xdrname = pick3d_state.xdrname
scan3d_Writexdr,pick3d_state,xdrname
END
'PICK3D_PANZINDEX': BEGIN
r = WIDGET_INFO(Event.Id,/LIST_SELECT)
pick3d_state.pickZind = r
END
'PICK3D_PICKDET': BEGIN
if pick3d_state.filename eq '' then begin
res = dialog_message('Please select scan file first!',/error)
return
end
r = WIDGET_INFO(Event.Id,/LIST_SELECT)
if r ge 0 then pick3d_state.pickDet = r + 1
if r ge 0 and pick3d_state.id_def(r,0) eq 0 then begin
res = dialog_message('Detector not defined in this scan',/error)
goto,resetuv
end
view3d_pickDet, pick3d_state, data, Event
if pick3d_state.dim ne 3 then return
WIDGET_CONTROL,pick3d_state.dataWID,SENSITIVE= 1
END
'PICK3D_2D': BEGIN
if n_elements(*(pick3d_state.data)) gt 3 then begin
data = *(pick3d_state.data)
rank = pick3d_state.panAxis
xv = *(pick3d_state.x)
yv = *(pick3d_state.y)
zv = *(pick3d_state.z)
str = '(vs Values)'
if pick3d_state.realaxis eq 0 then begin
xv = indgen(pick3d_state.npts(0))
yv = indgen(pick3d_state.npts(1))
zv = indgen(pick3d_state.npts(2))
str = '(vs Index #)'
end
title=pick3d_state.class+':'+pick3d_state.detname(pick3d_state.pickDet-1) + str
view3d_2D,data,rank,xv,yv,zv, title=title, Group=Event.top
end
END
'PICK3D_VIEWREPORT': BEGIN
file = dialog_pickfile(get_path=p,/read,/must_exist,path=pick3d_state.path, $
filter='*txt',title='Select Image Slicer Only')
if file eq '' then return
xdisplayfile,file,Group=Event.top
END
'PICK3D_REPORT': BEGIN
pick3d_report,pick3d_state,GROUP=Event.top
END
'PICK3D_XDR': BEGIN
if pick3d_state.dim ne 3 then return
xdrname = pick3d_state.detname(pick3d_state.pickDet-1)+'.xdr'
pick3dToxdr,pick3d_state,xdrname
dir = pick3d_state.outpath+'XDR'
outname=pick3d_state.class+'.'+xdrname
rename_dialog,dir,xdrname,outname,GROUP=Event.top
END
'PICK3D_DEBUG': BEGIN
IF Event.Select THEN Sel = 'On' ELSE Sel = 'Off'
pick3d_state.debug = Event.Select
CASE Event.Value OF
0: Print,'Button Debug Turned ', Sel
ELSE: Message,'Unknown button pressed'
ENDCASE
END
'PICK3D_DONE': BEGIN
pick3d_writeConfig,pick3d_state
WIDGET_CONTROL,Event.Top,/DESTROY
ptr_free,pick3d_state.x
ptr_free,pick3d_state.y
ptr_free,pick3d_state.z
ptr_free,pick3d_state.da1d
ptr_free,pick3d_state.da2d
ptr_free,pick3d_state.data
heap_gc
exit
END
'PICK3D_REALAXIS': BEGIN
pick3d_state.realaxis = Event.Value
END
'PICK3D_PANAXIS': BEGIN
pick3d_state.panAxis = Event.Value
nl = pick3d_state.npts(pick3d_state.panAxis)
if pick3d_state.pickZind ge nl then pick3d_state.pickZind=0
; WIDGET_CONTROL,pick3d_state.allZlistWID, $
; SET_VALUE=indgen(nl,/string), $
; SET_LIST_SELECT=pick3d_state.pickZind
goto,resetuv
END
'PICK3D_PANIMAGE': BEGIN
if pick3d_state.dim eq 3 then begin
pick3d_panimage,pick3d_state,Event
return
end
END
'PICK3D_HELP': BEGIN
str = getenv('EPICS_EXTENSIONS')
new = getenv('EPICS_EXTENSIONS_PVT')
if strlen(new) gt 3 then str = new
str = str +!os.file_sep+'doc'+!os.file_sep+'pick3d_help.txt'
xdisplayfile,str,GROUP=Event.top
return
END
ENDCASE
resetuv:
WIDGET_CONTROL,Event.Top,SET_UVALUE=pick3d_state,bad_id=bad_id
END
PRO pick3d_panimage,pick3d_state,Event
data = *pick3d_state.data
x = *pick3d_state.x
y = *pick3d_state.y
z = *pick3d_state.z
npts = pick3d_state.npts
scanno = pick3d_state.scanno
pv = pick3d_state.pv
labels = pick3d_state.labels
id_def = pick3d_state.id_def
xv = indgen(npts(0))
yv = indgen(npts(1))
zv = indgen(npts(2))
if pick3d_state.realaxis then begin
xv = x
yv = y
zv = z
if max(xv) eq min(xv) then xv = indgen(npts(0))
if max(yv) eq min(yv) then yv = indgen(npts(1))
if max(zv) eq min(zv) then zv = indgen(npts(2))
end
sz = size(data)
title = pick3d_state.class+":" + pick3d_state.detname(pick3d_state.pickDet-1)
CASE pick3d_state.panAxis OF
0: begin
id_def = make_array(npts(0),value=1,/int)
image_data = reform(data,npts(0),npts(1)*npts(2))
image_data = transpose(image_data)
image_data = reform(image_data,npts(1),npts(2),npts(0))
title = title+'_(All_X_slices)'
xdescs = pv[1]
ydescs = pv[2]
zdescs = 'S#'+ strtrim(indgen(sz(1))+1,2)
image2d,image_data,yv,zv,title=title,scanno=scanno,Group=Event.top, $
xdescs=xdescs,ydescs=ydescs,zdescs=zdescs,/seqnm
; wid = pick3d_state.panwin(0)
; panimage,image_data,id_def,title=title,new_win=wid
; pick3d_state.panwin(0) = wid
end
1: begin
id_def = make_array(npts(1),value=1,/int)
image_data = make_array(npts(0),npts(2),npts(1))
for k=0,npts(1)-1 do begin
da = reform(data(*,k,*))
image_data(*,*,k) = da(*,*)
end
title = title+'_(All_Y_slices)'
xdescs = pv[0]
ydescs = pv[2]
zdescs = 'S#'+ strtrim(indgen(sz(2))+1,2)
image2d,image_data,xv,zv,title=title,scanno=scanno,Group=Event.top, $
xdescs=xdescs,ydescs=ydescs,zdescs=zdescs,/seqnm
; wid = pick3d_state.panwin(1)
; panimage,image_data,id_def,title=title,new_win=wid
; pick3d_state.panwin(1) = wid
end
2: begin
id_def = make_array(npts(2),value=1,/int)
title = title+'_(All_Z_slices)'
image_data = data
xdescs = pv[0]
ydescs = pv[1]
zdescs = 'S#'+ strtrim(indgen(sz(3))+1,2)
image2d,image_data,xv,yv,title=title,scanno=scanno,Group=Event.top, $
xdescs=xdescs,ydescs=ydescs,zdescs=zdescs,/seqnm
; wid = pick3d_state.panwin(2)
; panimage,image_data,id_def,title=title,new_win=wid
; pick3d_state.panwin(2) = wid
end
ELSE: Message,'Unknown button pressed'
ENDCASE
END
PRO pick3d_closeReset,wid
widget_control,wid,get_uvalue=state
if state.parent then $
widget_control,state.parent,sensitive=1
END
PRO pick3d,file=file,path=path,debug=debug,pickDet=pickDet,Group=group
;+
; NAME:
; pick3d
;
; PURPOSE:
; This dialog allows the user dynamically picks the desired
; detector numbers out of a 3D scan file. A user can freely
; view the 3D data of the selected detector by the view3d_2D
; program.
;
; CALLING SEQUENCE:
; pick3d [,File=file] [,PickDet=pickDet] [,Path=path]
; [,Debug=debug] [,Group=group]
;
; KEYWORDS:
; PickDet: The default selected detector is detector number 16 which is
; detector D01. If different detector is desired it must be
; defined in database and falls in (1,85).
; File: Specifies the initial 3D scan file on command line
; Path: Full path specifies the starting file directory where the scan
; files are stored.
; Group: Specifies the parent widget ID. If specified, the destroy of
; parent window resulted the destroy of Pick3d window.
; Debug: If specified, dump the scan read information
;
; RESTRICTIONS:
; The scan file must be automatically generated by the IOC scan software
; by version 1.2 format. The file selected must be a 3D scan.
;
; EXAMPLE:
; PICK3D,path='/home/beams/CHA/data/xxx'
;
; MODIFICATION HISTORY:
; Written by: Ben-chin Cha, Feb 1, 2001.
; 02-15-2001 Add 3D_2D button to view 2D image data