-
Notifications
You must be signed in to change notification settings - Fork 0
/
sliceomatic.m
1491 lines (1380 loc) · 44.1 KB
/
sliceomatic.m
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
function sliceomatic(p1,p2,xmesh,ymesh,zmesh)
% SLICEOMATIC - Slice and isosurface volume exploration GUI
%
% SLICEOMATIC(DATA) - Use 3D double matrix DATA as a volume data
%
% Example:
%
% [x,y,z] = meshgrid(-2:.2:2, -2:.25:2, -2:.16:2);
% v = x .* exp(-x.^2 - y.^2 - z.^2);
% sliceomatic(v)
%
% Using SLICEOMATIC with no arguments is equivalent to the above
% example.
%
% SLICEOMATIC(DATA, X, Y, Z) - Run sliceomatic using the specified data
% coordinates for the volume DATA. X, Y, and Z are the vectors over which
% DATA is defined.
%
% ex:
% x = -2:.2:2; y = -2:.25:2; z = -2:.16:2;
% [X,Y,Z] = meshgrid(x,y,z);
% v = X .* exp(-X.^2 - Y.^2 - Z.^2);
% sliceomatic(v,x,y,z)
%
%
% Using the GUI:
% -------------
%
% Create/Delete slices:
%
% The white bars on the top, left, and right allow insertion of
% new slices on the X, Y, and Z planes. Click in an empty area to
% add a new slice or surface. Right click on a control arrow to
% reconfigure or delete that slice.
%
% Create/Delete isosurfaces:
%
% The colored bar at the bottom is used to place and position an
% isosurface. The color in the bar indicates a position (as seen
% in the slice) where the isosurface will go. Right click on a
% control arrow to reconfigure or delete the isosurface.
%
% Orientation of the view:
%
% When the rotate camera button is on, the popup menu will control
% the camera. Turn off camera rotation in order to get individual
% control over properties of the slices and isosurfaces.
%
% Changing Defaults:
%
% The defaults menu provides default features of newly created
% slices and surfaces. The AllSlices menu controls properties of
% all the slices and surfaces in the scene. Use popup menus on the
% objects themselves, or the control arrows to change individual
% properties.
%
% Color & Alpha Maps:
%
% The Colormap popdown controls the currently active colormap.
% This map is used to color the slices. The Alphamap popdown
% controls the alphamap used on the slices.
%
% Use the color or alpha maps to change how areas of your data are
% highlighted.
%
% Controls Control:
%
% The Controls menu allows you to adjust how the controls look. An
% important feature here is the "Animate" item. You can enable or
% disable an animation when some changes are made. Since this is
% decorative, it may be important to turn this off for large data
% sets.
%
% Doing Cool Stuff:
% ----------------
%
% Exploration:
% You can get a quick feel of the current data set by adding a
% slice using the ColorTexture option. Such a slice can be dragged
% through the data very quickly.
%
% Highlight an Area:
% If certain values in your data are interesting (very large, very
% small, or very median values) you can use transparency to make
% parts of your slices disappear. Choose AlphaTexture options from
% the defaults, and sweep some slices across your data. Use the
% AlphaMap to pick out certain data sets. The example given here
% looks best with the `vdown' alphamap.
%
% Contours on slices:
% You can add a contour onto a slice to further extract shapes
% from the data you are exploring. Auto-selecting contour limits
% will choose contours on a per slice basis. Auto-selecting
% contour lines from a volume arbitrarily specifies 10 levels
% based on the limits of the volume.
%
% Hidden Shapes:
% Use the isosurface control bar to create an isosurface. Be
% patient with this control. It often takes a while for the
% surface to be created. Click and hold the mouse button down
% until the first surface appears. Drag the surface through the
% values until you get something you like, then let go. If your
% data set is very large, you will need to wait while the new and
% more accurate isosurface is created.
%
% Volumes:
% You can simulate a volume object by creating lots of stacked
% slices. Simply use the proper Alphamap and transparent textures
% to highlight the correct data, and a large stack of slices will
% let you simulate a volume object.
%
% Customized Graphics:
% -------------------
%
% To add your own graphics into the sliceomatic display, whatever
% that may be, you can use the following technique:
%
% 1) click on a control arrow
% 2) use gco to get the data for that object
% slice = getappdata(gco,'arrowslice')
% 3) use GET to get the cdata and position data which you can use
% to add your own graphics.
%
% Setting Default Values:
% ----------------------
%
% If you want to change some default setup feature of sliceomatic,
% use the "Save Preferences" menu item. Future sliceomatic
% sessions will then retrieve those settings.
%
%
% BUGS:
% ----
%
% 1) Inaccurate Slice
% Sliceomatic does not use the `slice' command. All slices are
% created by explicitly extracting data from the volume. As such,
% only slices at integer values are allowed.
%
% 2) Crashes MATLAB
% Sliceomatic uses the default OpenGL setup. If you encounter
% frequent crashes you can start by enabling software OpenGL
% rendering. This should always fix the problem, and would
% likely slow things down too. You should also update your
% graphics driver for your video card. On Windows, in
% particular, drivers are updated frequently. For detail on how
% to overcome these problems, visit this web page:
% http://www.mathworks.com/support/tech-notes/1200/1201.html
%
% See Also: SLICE, ISOSURFACE, ISOCAPS, CONTOURC, COLORMAP, SURFACE
% This is version 2.3 of sliceomatic.
%
% Sliceomatic is a tool I wrote for fun. There are no warrenties
% expressed or implied.
% Written by Eric Ludlam <eludlam@mathworks.com>
% Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
% The MathWorks Inc
%
% Modified by Emiliano Spezi <emiliano.spezi@physics.org> on 22 May 2003
% Added capability: axes limits control, slice leveling controls,
% and contour level specification.
%
% Patch from David Schwartz on Sep 4, 2008
% Warning fix, and isosurface color fixes.
%
% Patch from Gerhard Stoeckel on Nov 17, 2008
% Fix colormap setting to rand.
if nargin==0
[x,y,z] = meshgrid(-2:.2:2, -2:.25:2, -2:.16:2);
v = x .* exp(-x.^2 - y.^2 - z.^2);
sliceomatic(v)
return
end
if isnumeric(p1)
% $$$ if nargin==4
% $$$ d.Xv=p1;
% $$$ d.Yv=p2;
% $$$ d.Zv=p3
% $$$ p1=p4;
% $$$ else
% $$$ d.Yv=1:size(p1,1);
% $$$ d.Xv=1:size(p1,2);
% $$$ d.Zv=1:size(p1,3);
% $$$ end
d.data=p1;
if nargin>=4
if nargin==4
zmesh=ymesh;
ymesh=xmesh;
xmesh=p2;
end
d = sliceomaticfigure(d,xmesh,ymesh,zmesh);
d = sliceomaticsetdata(d,xmesh,ymesh,zmesh);
else
d = sliceomaticfigure(d);
d = sliceomaticsetdata(d);
end
setappdata(gcf,'sliceomatic',d);
elseif isa(p1,'char')
% Interpret commands
d=getappdata(gcf,'sliceomatic');
try
switch p1
case 'Xnew'
if strcmp(get(gcf,'selectiontype'),'normal')
pt=get(gcbo,'currentpoint');
axis(gcbo);
X=pt(1,1);
newa=arrow(gcbo,'down',[X 0]);
set(gcf,'currentaxes',d.axmain);
new=localslice(d.data, X, [], []);
setappdata(new,'controlarrow',newa);
setappdata(newa(2),'arrowslice',new);
set(new,'alphadata',get(new,'cdata'),'alphadatamapping','scaled');
set(newa,'buttondownfcn','sliceomatic Xmove');
set([new newa],'uicontextmenu',d.uic);
% Make sure whatever buttonupfcn on the figure is run now to "turn
% off" whatever was going on before we got our callback on the
% arrow.
buf = get(gcf,'windowbuttonupfcn');
if ~strcmp(buf,'')
eval(buf);
end
d.draggedarrow=newa(2);
dragprep(newa(2));
setpointer(gcf,'SOM leftright');
set(d.motionmetaslice,'visible','off');
end
case 'Ynew'
if strcmp(get(gcf,'selectiontype'),'normal')
pt=get(gcbo,'currentpoint');
Y=pt(1,2);
newa=arrow(gcbo,'right',[0 Y]);
set(gcf,'currentaxes',d.axmain);
new=localslice(d.data, [], Y, []);
setappdata(new,'controlarrow',newa);
setappdata(newa(2),'arrowslice',new);
set(new,'alphadata',get(new,'cdata'),'alphadatamapping','scaled');
set(newa,'buttondownfcn','sliceomatic Ymove');
set([new newa],'uicontextmenu',d.uic);
% Make sure whatever buttonupfcn on the figure is run now to "turn
% off" whatever was going on before we got our callback on the
% arrow.
buf = get(gcf,'windowbuttonupfcn');
if ~strcmp(buf,'')
eval(buf);
end
d.draggedarrow=newa(2);
dragprep(newa(2));
setpointer(gcf,'SOM topbottom');
set(d.motionmetaslice,'visible','off');
end % if strcmp(get(gcf,
case 'Znew'
if strcmp(get(gcf,'selectiontype'),'normal')
pt=get(gcbo,'currentpoint');
Y=pt(1,2);
newa=arrow(gcbo,'left', [0 Y]);
set(gcf,'currentaxes',d.axmain);
new=localslice(d.data, [], [], Y);
set(new,'alphadata',get(new,'cdata'),'alphadatamapping','scaled');
setappdata(new,'controlarrow',newa);
setappdata(newa(2),'arrowslice',new);
set(newa,'buttondownfcn','sliceomatic Zmove');
set([new newa],'uicontextmenu',d.uic);
% Make sure whatever buttonupfcn on the figure is run now to "turn
% off" whatever was going on before we got our callback on the
% arrow.
buf = get(gcf,'windowbuttonupfcn');
if ~strcmp(buf,'')
eval(buf);
end
d.draggedarrow=newa(2);
dragprep(newa(2));
setpointer(gcf,'SOM topbottom');
set(d.motionmetaslice,'visible','off');
end % if strcmp(get(gcf,
case 'ISO'
if strcmp(get(gcf,'selectiontype'),'normal')
pt=get(gcbo,'currentpoint');
V=pt(1,1);
newa=arrow(gcbo,'up',[V 0]);
set(gcf,'currentaxes',d.axmain);
new=localisosurface(d.reducelims,d.reduce,d.reducesmooth,V);
set([newa new],'uicontextmenu',d.uiciso);
setappdata(new,'controlarrow',newa);
setappdata(new,'reduced',1);
setappdata(newa(2),'arrowiso',new);
set(newa,'buttondownfcn','sliceomatic ISOmove');
% Make sure whatever buttonupfcn on the figure is run now to "turn
% off" whatever was going on before we got our callback on the
% arrow.
buf = get(gcf,'windowbuttonupfcn');
if ~strcmp(buf,'')
eval(buf);
end
d.draggedarrow=newa(2);
dragprep(newa(2));
setpointer(gcf,'SOM leftright');
end % if strcmp(get(gcf,
case 'Xmove'
if strcmp(get(gcf,'selectiontype'),'normal')
[a s]=getarrowslice;
d.draggedarrow=a;
dragprep(a);
end
case 'Ymove'
if strcmp(get(gcf,'selectiontype'),'normal')
[a s]=getarrowslice;
d.draggedarrow=a;
dragprep(a);
end
case 'Zmove'
if strcmp(get(gcf,'selectiontype'),'normal')
[a s]=getarrowslice;
d.draggedarrow=a;
dragprep(a);
end
case 'ISOmove'
if strcmp(get(gcf,'selectiontype'),'normal')
[a s]=getarrowslice;
d.draggedarrow=a;
dragprep(a);
end
case 'up'
if strcmp(get(gcf,'selectiontype'),'normal')
dragfinis(d.draggedarrow);
end
case 'motion'
% Make sure our cursor is ok
a=d.draggedarrow; % The arrow being dragged
s=getappdata(a,'arrowslice'); % The slice to 'move'
if isempty(s)
s=getappdata(a,'arrowiso'); % or the isosurface
end
aa=get(a,'parent'); % arrow's parent axes
pos=getappdata(a,'arrowcenter'); % the line the arrow points at.
apos=get(aa,'currentpoint');
% Bind the axes position to the limits of that axes.
xlimits = get(aa,'xlim');
ylimits = get(aa,'ylim');
if apos(1,1) < xlimits(1)
apos(1,1) = xlimits(1);
elseif apos(1,1) > xlimits(2)
apos(1,1) = xlimits(2);
end
if apos(1,2) < ylimits(1)
apos(1,2) = ylimits(1);
elseif apos(1,2) > ylimits(2)
apos(1,2) = ylimits(2);
end
if aa==d.axx || aa==d.axiso
% We are moving an X slice
xdiff=apos(1,1)-pos(1,1);
v=get(a,'vertices');
v(:,1)=v(:,1)+xdiff;
set([a getappdata(a,'arrowedge')],'vertices',v);
np=[ apos(1,1) 0 ];
% This might be a slice, or an isosurface!
if aa==d.axiso
new=localisosurface(d.reducelims,d.reduce,d.reducesmooth,...
apos(1,1),s);
setappdata(new,'reduced',1);
movetipforarrow(a, aa, apos(1,1), [ apos(1,1) 6 ], 'bottom','center')
else
%disp([ 'apos = ' num2str(apos(1,1))])
%disp([ 'pos = ' num2str(pos(1,1))])
%disp([ 'change=' num2str(round(apos(1,1))~=round(pos(1,1)))]);
if round(apos(1,1))~=round(pos(1,1))
localslice(d.data, apos(1,1), [], [],s);
end
movetipforarrow(a, aa, apos(1,1), [ apos(1,1) .5 ],'top','center')
end
else
% We are moving a Y or Z slice
ydiff=apos(1,2)-pos(1,2);
v=get(a,'vertices');
v(:,2)=v(:,2)+ydiff;
set([a getappdata(a,'arrowedge')],'vertices',v);
np=[ 0 apos(1,2) ];
if aa==d.axy
if round(apos(1,2))~=round(pos(1,2))
localslice(d.data, [], apos(1,2), [], s);
end
movetipforarrow(a, aa, apos(1,2), [ 5.5 apos(1,2) ], 'middle','left');
else
if round(apos(1,2))~=round(pos(1,2))
localslice(d.data, [], [], apos(1,2), s);
end
movetipforarrow(a, aa, apos(1,2), [ .5 apos(1,2) ], 'middle','right');
end
end
setappdata(a,'arrowcenter',np);
% Question: Is anyone dependant on versions of MATLAB
% that does not support Java Figures?
%
%% This improves anaimation speed in Java Figures/R14
%% The Rule: Java Figures don't want this drawnow.
%try
% if isempty(get(gcf,'javaframe'))
% drawnow;
% end
%catch
% drawnow;
%end
%
% IsoSurface context menu items
%
case 'isotogglevisible'
[a s]=getarrowslice;
if propcheck(s,'visible','on')
set(s,'visible','off');
else
set(s,'visible','on');
end
case 'isodelete'
[a s]=getarrowslice;
if numel(a)==1
delete(getappdata(a,'arrowedge'));
end
cap=getappdata(s,'sliceomaticisocap');
if ~isempty(cap)
delete(cap);
end
delete(s);
delete(a);
case 'isoflatlight'
[a s]=getarrowslice;
set(s,'facelighting','flat');
case 'isosmoothlight'
[a s]=getarrowslice;
set(s,'facelighting','phong');
case 'isocolor'
[a s]=getarrowslice;
c=uisetcolor(get(s,'facecolor'));
slowset(s,'facecolor',c,d.animincrement);
case 'isoalpha'
[a s]=getarrowslice;
if nargin ~= 2
error('Not enough arguments to sliceomatic.');
end
slowset(s,'facealpha',eval(p2),d.animincrement);
case 'isocaps'
[a s]=getarrowslice;
cap=getappdata(s,'isosurfacecap');
if isempty(cap)
new=localisocaps(s);
set(new,'uicontextmenu',d.uiciso);
else
delete(cap);
setappdata(s,'isosurfacecap',[]);
end
%
% Now for slice context menu items
%
case 'togglevisible'
[a s]=getarrowslice;
switch get(s,'visible')
case 'on'
set(s,'visible','off');
pushset(a,'facealpha',.2);
case 'off'
set(s,'visible','on');
popset(a,'facealpha');
end
case 'setfaceted'
[a s]=getarrowslice;
set(s,'edgec','k','facec','flat');
if ischar(get(s,'facea')) && strcmp(get(s,'facea'),'texturemap')
set(s,'facea','flat');
end
textureizeslice(s,'off');
case 'setflat'
[a s]=getarrowslice;
set(s,'edgec','n','facec','flat');
if ischar(get(s,'facea')) && strcmp(get(s,'facea'),'texturemap')
set(s,'facea','flat');
end
textureizeslice(s,'off');
case 'setinterp'
[a s]=getarrowslice;
set(s,'edgec','n','facec','interp');
if ischar(get(s,'facea')) && strcmp(get(s,'facea'),'texturemap')
set(s,'facea','interp');
end
textureizeslice(s,'off');
case 'settexture'
[a s]=getarrowslice;
set(s,'facecolor','texture','edgec','none');
if ischar(get(s,'facea'))
set(s,'facealpha','texturemap');
end
textureizeslice(s,'on');
case 'setnone'
[a s]=getarrowslice;
set(s,'facecolor','none','edgec','none');
textureizeslice(s,'off');
case 'setalphanone'
[a s]=getarrowslice;
slowset(s,'facealpha',1,d.animincrement);
case 'setalphapoint5'
[a s]=getarrowslice;
slowset(s,'facealpha',.5,d.animincrement);
case 'setalphaflat'
[a s]=getarrowslice;
set(s,'facealpha','flat');
if ischar(get(s,'facec')) && strcmp(get(s,'facec'),'texturemap')
set(s,'facecolor','flat');
textureizeslice(s,'off');
end
case 'setalphainterp'
[a s]=getarrowslice;
set(s,'facealpha','interp');
if ischar(get(s,'facec')) && strcmp(get(s,'facec'),'texturemap')
set(s,'facecolor','interp');
textureizeslice(s,'off');
end
case 'setalphatexture'
[a s]=getarrowslice;
set(s,'facealpha','texturemap');
if ischar(get(s,'facec'))
set(s,'facecolor','texturemap');
textureizeslice(s,'on');
end
case 'slicecontour'
[a s]=getarrowslice;
localcontour(s, getappdata(s,'contour'));
case 'slicecontourfullauto'
[a s]=getarrowslice;
d = getappdata(gcf, 'sliceomatic');
minmax = get(d.axiso,'clim');
levels = minmax(1):(minmax(2)-minmax(1))/10:minmax(2);
setappdata(s, 'contourlevels', levels);
localcontour(s, getappdata(s,'contour'),levels);
case 'slicecontour_setauto'
[a s]=getarrowslice;
setappdata(s, 'contourlevels', []);
localcontour(s, getappdata(s,'contour'));
case 'slicecontour_setfullauto'
[a s]=getarrowslice;
minmax = get(d.axiso,'clim');
levels = minmax(1):(minmax(2)-minmax(1))/10:minmax(2);
setappdata(s, 'contourlevels', levels);
localcontour(s, getappdata(s,'contour'),levels);
case 'slicecontour_select'
[a s]=getarrowslice;
d = getappdata(gcf, 'sliceomatic');
xl = get(d.axiso,'xlim');
levels = selectcontourlevels(get(s,'cdata'), xl(1), xl(2));
setappdata(s, 'contourlevels', levels);
localcontour(s, getappdata(s,'contour'),levels);
case 'slicecontour_setlevels'
[a s]=getarrowslice;
d = getappdata(gcf, 'sliceomatic');
xl = get(d.axiso,'xlim');
levels = selectcontourlevels(get(s,'cdata'), xl(1), xl(2));
setappdata(s, 'contourlevels', levels);
localcontour(s, getappdata(s,'contour'),levels);
case 'deleteslice'
[a s]=getarrowslice;
if prod(size(a))==1
delete(getappdata(a,'arrowedge'));
end
if ~isempty(getappdata(s,'contour'))
delete(getappdata(s,'contour'));
end
delete(s);
delete(a);
case 'deleteslicecontour'
[a s]=getarrowslice;
if ~isempty(getappdata(s,'contour'))
delete(getappdata(s,'contour'));
end
temp=getappdata(s);
try
temp.contourlevels;
setappdata(s,'contourlevels',[]);
end
setappdata(s,'contour',[]);
case 'slicecontourflat'
[a s]=getarrowslice;
c = getappdata(s,'contour');
if ~isempty(c)
set(c,'edgecolor','flat');
end
case 'slicecontourinterp'
[a s]=getarrowslice;
c = getappdata(s,'contour');
if ~isempty(c)
set(c,'edgecolor','interp');
end
case 'slicecontourblack'
[a s]=getarrowslice;
c = getappdata(s,'contour');
if ~isempty(c)
set(c,'edgecolor','black');
end
case 'slicecontourwhite'
[a s]=getarrowslice;
c = getappdata(s,'contour');
if ~isempty(c)
set(c,'edgecolor','white');
end
case 'slicecontoursmooth'
[a s]=getarrowslice;
c = getappdata(s,'contour');
onoff = get(gcbo,'checked');
switch onoff
case 'off'
set(c,'linesmoothing','on');
case 'on'
set(c,'linesmoothing','off');
end
case 'slicecontourcolor'
[a s]=getarrowslice;
c = getappdata(s,'contour');
if ~isempty(c)
inputcolor = get(c,'edgecolor');
if isa(inputcolor,'char')
inputcolor=[ 1 1 1 ];
end
slowset(c,'edgecolor',uisetcolor(inputcolor),d.animincrement);
end
case 'slicecontourlinewidth'
[a s]=getarrowslice;
c = getappdata(s,'contour');
if ~isempty(c)
if isa(p2,'char')
slowset(c,'linewidth',str2num(p2),d.animincrement);
else
slowset(c,'linewidth',p2,d.animincrement);
end
end
%
% Menu All Slices
%
case 'allfacet'
s=allSlices;
set(s,'facec','flat','edgec','k');
textureizeslice(s,'off');
case 'allflat'
s=allSlices;
set(s,'facec','flat','edgec','none');
textureizeslice(s,'off');
case 'allinterp'
s=allSlices;
set(s,'facec','interp','edgec','none');
textureizeslice(s,'off');
case 'alltex'
s=allSlices;
set(s,'facec','texturemap','edgec','none');
textureizeslice(s,'on');
case 'allnone'
s=allSlices;
set(s,'facec','none','edgec','none');
textureizeslice(s,'off');
case 'alltnone'
s=allSlices;
set(s,'facea',1);
textureizeslice(s,'off');
case 'alltp5'
s=allSlices;
set(s,'facea',.5);
textureizeslice(s,'off');
case 'alltflat'
s=allSlices;
set(s,'facea','flat');
textureizeslice(s,'off');
case 'alltinterp'
s=allSlices;
set(s,'facea','interp');
textureizeslice(s,'off');
case 'allttex'
s=allSlices;
set(s,'facea','texturemap');
textureizeslice(s,'on');
%
% Menu Defaults callbacks
%
case 'defaultfaceted'
d.defcolor='faceted';
case 'defaultflat'
d.defcolor='flat';
case 'defaultinterp'
d.defcolor='interp';
case 'defaulttexture'
d.defcolor='texture';
if strcmp(d.defalpha,'flat') || strcmp(d.defalpha,'interp')
d.defalpha='texture';
end
case 'defaultinterp'
d.defcolor='none';
case 'defaulttransnone'
d.defalpha='none';
case 'defaulttransflat'
d.defalpha='flat';
case 'defaulttransinterp'
d.defalpha='interp';
case 'defaulttranstexture'
d.defalpha='texture';
d.defcolor='texture';
case 'defaultlightflat'
d.deflight='flat';
case 'defaultlightsmooth'
d.deflight='smooth';
case 'defaultcontoursmooth'
d.defaultcontoursmooth='on';
case 'defaultcontourflat'
d.defcontourcolor='flat';
case 'defaultcontourinterp'
d.defcontourcolor='interp';
case 'defaultcontourblack'
d.defcontourcolor='black';
case 'defaultcontourwhite'
d.defcontourcolor='white';
case 'defaultcontourlinewidth'
if isa(p2,'char')
d.defcontourlinewidth=str2num(p2);
else
d.defcontourlinewidth=p2;
end
%
% Camera toolbar Toggling
%
case 'cameratoolbar'
cameratoolbar('Toggle');
case 'annotationtoolbar'
if propcheck(d.toolbar,'visible','on')
set(d.toolbar,'vis','off');
else
set(d.toolbar,'vis','on');
end
%
% Controller Preferences
%
case 'controlalpha'
val=str2num(p2);
iso=findobj(d.axiso,'type','image');
if val == 0
set([d.pxx d.pxy d.pxz iso],'visible','off');
else
set([d.pxx d.pxy d.pxz iso],'visible','on');
slowset([d.pxx d.pxy d.pxz] , 'facealpha',val,d.animincrement);
slowset(iso,'alphadata',val,d.animincrement);
end
case 'toggleanimation'
if d.animincrement == 0
d.animincrement = 10;
else
d.animincrement = 0;
end
case 'controllabels'
l = get(d.axx,'xticklabel');
if isempty(l)
set([d.axx d.axiso],'xticklabelmode','auto');
set([d.axy d.axz],'yticklabelmode','auto');
else
set([d.axx d.axiso],'xticklabel',[]);
set([d.axy d.axz],'yticklabel',[]);
end
case 'controlvisible'
objs=findobj([d.axiso d.axx d.axy d.axz]);
if strcmp(get(d.axx,'visible'),'on')
set(objs,'visible','off');
set(d.axmain,'pos',[.1 .1 .9 .8]);
else
set(objs,'visible','on');
set(d.axmain,'pos',[.2 .2 .6 .6]);
end
%
% UICONTROL callbacks
%
case 'colormap'
str=get(gcbo,'string');
val=str{get(gcbo,'value')};
size(val);
if strcmp(val,'custom')
cmapeditor
else
if strcmp(val, 'rand')
cm = get(gcf, 'colormap');
val = feval(@rand, size(cm));
else
val = feval(val);
end
slowset(gcf,'colormap',val,d.animincrement);
end
case 'alphamap'
str=get(gcbo,'string');
str=str{get(gcbo,'value')};
if strcmp(str, 'rand')
val=rand(size(alphamap));
else
val=alphamap(str);
end
slowset(gcf,'alphamap',val,d.animincrement);
%
% Commands
%
case 'copy'
copyobj(gca,figure);set(gca,'pos',[.1 .1 .9 .8]);
case 'print'
newf=figure('visible','off','renderer',get(gcf,'renderer'));
copyobj(d.axmain,newf);
set(gca,'pos',[.1 .1 .9 .8])
printdlg(newf);
close(newf);
otherwise
error('Bad slice-o-matic command.');
end
catch
disp(get(0,'errormessage'));
end
setappdata(gcf,'sliceomatic',d);
else
disp('Sliceomatic data must be DOUBLE');
end
function dragprep(arrowtodrag)
arrows=findall(gcf,'tag','sliceomaticarrow');
pushset(arrows,'facecolor',[1 0 0]);
pushset(arrows,'facealpha',.2);
pushset(arrowtodrag,'facecolor',[0 1 0]);
pushset(arrowtodrag,'facealpha',.7);
slices=allSlices;
for i=1:length(slices)
fa=get(slices(i),'facea');
if isa(fa,'double') && fa>.3
pushset(slices(i),'facealpha',.3);
pushset(slices(i),'edgecolor','n');
else
pushset(slices(i),'facealpha',fa);
pushset(slices(i),'edgecolor',get(slices(i),'edgec'));
end
end
isosurfs=allIsos;
for i=1:length(isosurfs)
fa=get(isosurfs(i),'facea');
if isa(fa,'double') && fa>.3
pushset(isosurfs(i),'facealpha',.3);
pushset(isosurfs(i),'edgecolor','n');
else
pushset(isosurfs(i),'facealpha',fa);
pushset(isosurfs(i),'edgecolor',get(isosurfs(i),'edgec'));
end
cap=getappdata(isosurfs(i),'isosurfacecap');
if ~isempty(cap)
pushset(cap,'visible','off');
end
end
ss=getappdata(arrowtodrag,'arrowslice');
if isempty(ss)
ss=getappdata(arrowtodrag,'arrowiso');
end
popset(ss,'facealpha');
popset(ss,'edgecolor');
pushset(gcf,'windowbuttonupfcn','sliceomatic up');
pushset(gcf,'windowbuttonmotionfcn','sliceomatic motion');
% Doing this makes the tip invisible when visible is on.
showarrowtip(arrowtodrag);
function dragfinis(arrowtodrag)
arrows=findall(gcf,'tag','sliceomaticarrow');
popset(arrowtodrag,'facecolor');
popset(arrowtodrag,'facealpha');
popset(arrows,'facecolor');
popset(arrows,'facealpha');
ss=getappdata(arrowtodrag,'arrowslice');
if isempty(ss)
ss=getappdata(arrowtodrag,'arrowiso');
end
% These pushes are junk which will be undone when all slices or
% isosurfs are reset below.
pushset(ss,'facealpha',1);
pushset(ss,'edgecolor','k');
slices=allSlices;
if ~isempty(slices)
popset(slices,'facealpha');
popset(slices,'edgecolor');
end
isosurfs=allIsos;
if ~isempty(isosurfs)
popset(isosurfs,'facealpha');
popset(isosurfs,'edgecolor');
end
d=getappdata(gcf,'sliceomatic');
if isnan(d.xmesh)==1
for i=1:length(isosurfs)
cap=getappdata(isosurfs(i),'isosurfacecap');
if ~isempty(cap)
popset(cap,'visible');
localisocaps(isosurfs(i),cap);
end
if getappdata(isosurfs(i), 'reduced')
setappdata(isosurfs(i),'reduced',0);
localisosurface({},d.data,d.smooth,...
getappdata(isosurfs(i),'isosurfacevalue'),...
isosurfs(i));
end
end
else
for i=1:length(isosurfs)
cap=getappdata(isosurfs(i),'isosurfacecap');
if ~isempty(cap)
popset(cap,'visible');
localisocaps(isosurfs(i),cap);
end
if getappdata(isosurfs(i), 'reduced')
setappdata(isosurfs(i),'reduced',0);
realvolume={d.xmesh d.ymesh d.zmesh};
localisosurface(realvolume,d.data,d.smooth,...
getappdata(isosurfs(i),'isosurfacevalue'),...
isosurfs(i));
end
end
end
popset(gcf,'windowbuttonupfcn');
popset(gcf,'windowbuttonmotionfcn');
showarrowtip([]);
% Make sure whatever buttonupfcn on the figure is run now to "turn
% off" whatever was going on before we got our callback on the
% arrow.
buf = get(gcf,'windowbuttonupfcn');
if ~strcmp(buf,'')
eval(buf);
end
function movetipforarrow(arrow, ax, value, position, va, ha)
% Setup the current data tip for a slice arrow, and show it's
% control value
tipdata.parentaxes = ax;
tipdata.value = value;
tipdata.position = position;
tipdata.verticalalign = va;
tipdata.horizontalalign = ha;
setappdata(arrow, 'tipdata', tipdata);
showarrowtip(arrow);
% Put it onto d.axisiso so that
% it always appears on top.
%set(t,'parent',d.axiso);
function p=arrow(parent,dir,pos)
% 21012 21012 12345 12345
% 5 *-* 5 * 2 * 2 *
% 4 | | 4 / \ 1 *-*\ 1 /*-*
% 3 ** ** 3 ** ** 0 | * 0 * |
% 2 \ / 2 | | -1 *-*/ -1 \*-*
% 1 * 1 *-* -2 * -2 *
switch dir
case 'down'
pts=[ 0 1; -2 3; -1 3; -1 5; 1 5; 1 3; 2 3 ];
mp = 'SOM leftright';
case 'up'
pts=[ 0 5; 2 3; 1 3; 1 1; -1 1; -1 3; -2 3; ];
mp = 'SOM leftright';