NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/VIZICQ4_1.2/vizicq4_volume.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function vizicq4_volume(command,option)
2
3 get_VIZICQ4_handles;
4 setptr(VIZICQ4_Figure,'watch')
5
6 switch command
7
8 case 'SelRegion'
9 % Mouse-driven region selection
10
11 %FORCE AXES ROTATION OFF
12    set(VIZICQ4_Slicer_Rotation,'ToolTipString','Deactivate 3-D Rotation')
13    set(VIZICQ4_Slicer_Rotation,'String','Rotate On')
14    axes(VIZICQ4_Slice_Axes)
15    rotate3d off
16
17    delete(findobj(VIZICQ4_Figure,'Type','line','Tag','VIZICQ4_Region_Box'))
18    %Make GRID Axes vis and current
19    % move axes off-screen
20    invisaxstdpos=get(VIZICQ4_LabCont,'UserData');
21    axstdpos=get(VIZICQ4_DelCont,'UserData');
22    set(VIZICQ4_Grid_Axes,'Position',axstdpos)
23    set(VIZICQ4_Slice_Axes,'Position',invisaxstdpos)
24    set(VIZICQ4_Grid_Axes,'Visible','on')
25    set(VIZICQ4_Slice_Axes,'Visible','off')
26    axes(VIZICQ4_Grid_Axes)
27    str='Click and drag mouse to select region (lower-left to upper-right)';
28    vizicq4_guts('Info',str)
29    waitforbuttonpress;
30    Pt1=get(gca,'CurrentPoint');
31    rbbox([get(gcf,'CurrentPoint') 0 0],get(gcf,'CurrentPoint'));
32    Pt2=get(gca,'CurrentPoint');
33    vizicq4_guts('Info',[''])
34
35    % Draw box around drogue grid
36    line([Pt1(1) Pt2(1) Pt2(1) Pt1(1) Pt1(1)],...
37         [Pt1(3) Pt1(3) Pt2(3) Pt2(3) Pt1(3)],'Tag','VIZICQ4_Region_Box')
38      
39    xmin=Pt1(1);
40    ymin=Pt1(3);
41    xmax=Pt2(1);
42    ymax=Pt2(3);
43  
44    set(VIZICQ4_Region_Xmin,'String',xmin,'Enable','on')
45    set(VIZICQ4_Region_Xmax,'String',xmax,'Enable','on')
46    set(VIZICQ4_Region_Ymin,'String',ymin,'Enable','on')
47    set(VIZICQ4_Region_Ymax,'String',ymax,'Enable','on')
48
49 case 'MapScalar'
50    % Determine which component of the .icq4 has been selected.
51    state=get(VIZICQ4_icq4_select_button,'Value');
52    field=[];
53    for i=1:length(state)
54       if state{i}==1
55          field=get(VIZICQ4_icq4_select_button(i),'String');
56          break
57       end
58    end
59    if isempty(field)
60       vizicq4_guts('Error','No Icq4 Var selected.');
61       break
62    end
63    
64    badlist={'HMID';'UMID';'VMID';'HOLD';'UOLD';'VOLD';'ZMID';'ZOLD'};
65    if any(strcmp(badlist,field))
66       vizicq4_guts('Error',['Field ' field ' not yet supported.']);
67       break
68    end       
69    
70    vizicq4_guts('Error',['']);
71    
72    % If the basis is not yet computed, compute it.
73    basis_struct=get(VIZICQ4_Comp_Basis,'UserData');
74    if isempty(basis_struct)
75      vizicq4_volume('CompBasis')
76      basis_struct=get(VIZICQ4_Comp_Basis,'UserData');
77    end 
78    
79        jXY=basis_struct.jXY;
80        X3D=basis_struct.X3D;
81        Y3D=basis_struct.Y3D;
82        Z3D=basis_struct.Z3D;
83        phi=basis_struct.phi;
84         N1=basis_struct.N1_3D;
85         N2=basis_struct.N2_3D;
86         B1=basis_struct.B1_3D;
87         B2=basis_struct.B2_3D;
88    FDZgrid=basis_struct.sgrid;
89          
90    fem_icq4_struct=get(VIZICQ4_Slice_Axes,'UserData');
91    eval(['scalar=fem_icq4_struct.' eval('field') ';'])
92
93    fem_grid_struct=get(VIZICQ4_Grid_Axes,'UserData');
94
95    [m,n,p]=size(X3D);
96    ztemp=reshape(Z3D(1,1,:),1,p)';
97    S=map_scalar_mex5(phi,N1,N2,...
98                      B1,B2,FDZgrid,...
99                      ztemp,scalar,fem_grid_struct.e,jXY);
100    
101    % Store FD volume
102    set(VIZICQ4_Map_Scalar,'UserData',S)
103    
104    vizicq4_guts('Info',['Field ' field ' mapped to FD grid.']);
105    set(VIZICQ4_Ix_GO,'ForeGroundColor','g');
106    set(VIZICQ4_Iy_GO,'ForeGroundColor','g');
107    set(VIZICQ4_Iz_GO,'ForeGroundColor','g');
108    set(VIZICQ4_ALL_GO,'ForeGroundColor','g');
109  
110 case 'MakeVolume'
111    basis_struct=get(VIZICQ4_Comp_Basis,'UserData');
112    S=get(VIZICQ4_Map_Scalar,'UserData');
113    if isempty(S)
114       vizicq4_guts('Error','No Scalar Mapped');
115    else 
116    
117       % move axes off-screen
118       invisaxstdpos=get(VIZICQ4_LabCont,'UserData');
119       axstdpos=get(VIZICQ4_DelCont,'UserData');
120       set(VIZICQ4_Grid_Axes,'Position',invisaxstdpos)
121       set(VIZICQ4_Slice_Axes,'Position',axstdpos)
122       set(VIZICQ4_Grid_Axes,'Visible','off')
123       set(VIZICQ4_Slice_Axes,'Visible','on')
124      
125       % Get current shade setting
126       shadeval=find([get(VIZICQ4_Volume_Shading_Interp,'Value');
127                     get(VIZICQ4_Volume_Shading_Flat,'Value');
128                     get(VIZICQ4_Volume_Shading_Faceted,'Value')]);
129      
130       if isempty(shadeval),shadeval=3;,end
131       switch shadeval
132          case 1
133             ec='none';fc='interp';
134          case 2
135             ec='none';fc='flat';
136          case 3
137             ec='flat';fc='flat';
138       end
139      
140       axes(VIZICQ4_Slice_Axes)
141       hold on
142       colormap(jet(16))
143       jXY=basis_struct.jXY;
144       X3D=basis_struct.X3D;
145       Y3D=basis_struct.Y3D;
146       Z3D=basis_struct.Z3D;
147       ix=eval(get(VIZICQ4_Ix,'String'));
148       iy=eval(get(VIZICQ4_Iy,'String'));
149       iz=eval(get(VIZICQ4_Iz,'String'));
150       xunique=X3D(1,:,1);
151       yunique=Y3D(:,1,1);
152       zunique=Z3D(1,1,:);
153       if any(ix>length(xunique))
154          vizicq4_guts('Error',['Ix exceeds x-discretization']);
155       elseif any(iy>length(yunique))
156          vizicq4_guts('Error',['Iy exceeds y-discretization']);
157       elseif any(iz>length(zunique))
158          vizicq4_guts('Error',['Iz exceeds z-discretization']);
159       else
160          xslice=xunique(ix);
161          yslice=yunique(iy);
162          zslice=zunique(iz);
163          switch option
164          case 'X'
165             h=slice(X3D,Y3D,Z3D,S,xslice,0,0,'linear');
166             l=length(h);
167             delete(h([l-1 l]));h([l-1 l])=[];
168          case 'Y' 
169             h=slice(X3D,Y3D,Z3D,S,0,yslice,0,'linear');
170             l=length(h);
171             delete(h([1 l]));h([1 l])=[];
172          case 'Z'
173             h=slice(X3D,Y3D,Z3D,S,0,0,zslice,'linear');
174             delete(h(1:2));h(1:2)=[];
175          case 'ALL'
176             h=slice(X3D,Y3D,Z3D,S,xslice,yslice,zslice,'linear');
177          otherwise, 
178             disp('Hole on Make Slice switch')   
179          end
180          set(h,'Tag','VIZICQ4_Volume');     
181          set(h,'EdgeColor',ec,'FaceColor',fc);
182       end
183    end
184
185 case 'CompBasis'
186
187    fem_grid_struct=get(VIZICQ4_Grid_Axes,'UserData');
188    fem_icq4_struct=get(VIZICQ4_Slice_Axes,'UserData');
189    if isempty(fem_grid_struct)
190       vizicq4_guts('Error','No Domain Loaded');
191    elseif isempty(fem_icq4_struct)
192       vizicq4_guts('Error','No Icq4 File Loaded');
193    else
194    
195       % Set "GO!!" buttins to RED
196       set(VIZICQ4_Ix_GO,'ForeGroundColor','r');
197       set(VIZICQ4_Iy_GO,'ForeGroundColor','r');
198       set(VIZICQ4_Iz_GO,'ForeGroundColor','r');
199       set(VIZICQ4_ALL_GO,'ForeGroundColor','r');
200       drawnow
201      
202       vizicq4_guts('Info','Computing 3-D interp basis...');
203       % Get Nx, Ny, Nz
204       nx=eval(get(VIZICQ4_Nx,'String'));
205       ny=eval(get(VIZICQ4_Ny,'String'));
206       nz=eval(get(VIZICQ4_Nz,'String'));
207
208       % Get region limits from Volume Popup
209       minx=eval(get(VIZICQ4_Region_Xmin,'String'));
210       maxx=eval(get(VIZICQ4_Region_Xmax,'String'));
211       miny=eval(get(VIZICQ4_Region_Ymin,'String'));
212       maxy=eval(get(VIZICQ4_Region_Ymax,'String'));
213       minz=min(fem_grid_struct.z);
214       maxz=0;
215      
216       S=fd_cube([nx ny nz],[minx maxx miny maxy minz maxz]);
217       X3D=S.X3D;Y3D=S.Y3D;Z3D=S.Z3D;
218       X2D=squeeze(X3D(:,:,1));
219       Y2D=squeeze(Y3D(:,:,1));
220      
221       jXY=findelem(fem_grid_struct,[X2D(:) Y2D(:)]);
222       jXY=reshape(jXY,nx+1,ny+1);
223       phi=basis2d(fem_grid_struct,[X2D(:) Y2D(:)],jXY(:)) ;
224
225       zmesh=fem_icq4_struct.ZMID;
226       nnv=fem_icq4_struct.nnv;
227
228       % Get bottom depth below X2D,Y2D
229       temp=interp_scalar(fem_grid_struct,fem_grid_struct.z,X2D,Y2D,jXY);
230       zbot=reshape(temp,nx+1,ny+1);
231       temp=interp_scalar(fem_grid_struct,zmesh(:,nnv),X2D,Y2D,jXY);
232       zeta=reshape(temp,nx+1,ny+1);
233      
234       dzbl=zmesh(1,2)-zmesh(1,1);
235       FDZgrid=-sinegrid(zbot(:),zeta(:),nnv,dzbl);
236       FDZgrid=reshape(FDZgrid,nx+1,ny+1,nnv);
237      
238       N1_3D=NaN*ones(size(X3D));
239       B1_3D=NaN*ones(size(X3D));
240       N2_3D=NaN*ones(size(X3D));
241       B2_3D=NaN*ones(size(X3D));
242
243 %      [N1_3D,B1_3D,N2_3D,B2_3D]=comp_basis3d_mex5(FDZgrid,jXY,Z3D);
244 %      hwaitbar=waitbar(0.,'Computing Basis...');
245       tic;
246       for i=1:(nx+1)
247 %         waitbar((i-1)/nx)
248          for j=1:(ny+1)
249             if ~isnan(jXY(i,j))
250                zref=FDZgrid(i,j,:);
251                for k=1:nz+1
252                   [b2,n2,b1,n1]=basis1d2(zref,Z3D(i,j,k));
253                   N1_3D(i,j,k)=n1;
254                   B1_3D(i,j,k)=b1;
255                   N2_3D(i,j,k)=n2;
256                   B2_3D(i,j,k)=b2;
257                end
258             end
259          end
260       end
261       elapsed_time=toc;
262 %      delete(hwaitbar)
263      
264       % Store basis information on "Comp Basis" button UserData
265       basis_struct.jXY=jXY;
266       basis_struct.X3D=X3D;
267       basis_struct.Y3D=Y3D;
268       basis_struct.Z3D=Z3D;
269       basis_struct.phi=phi;
270       basis_struct.sgrid=FDZgrid;
271       basis_struct.N1_3D=N1_3D;
272       basis_struct.N2_3D=N2_3D;
273       basis_struct.B1_3D=B1_3D;
274       basis_struct.B2_3D=B2_3D;
275       set(VIZICQ4_Comp_Basis,'UserData',basis_struct)
276       str=['Done: elapsed time (sec) = ' num2str(elapsed_time) '. Map Scalar.'];
277       vizicq4_guts('Info',str);
278            
279     %   otherwise,
280     %      vizicq4_guts('Error','No mouse selection yet enabled');
281     %   end
282    end
283 case 'Rotate_Toggle'
284    state=get(VIZICQ4_Rotation,'String');
285    if strcmp(state,'Rotate On')
286       % move axes off-screen
287       invisaxstdpos=get(VIZICQ4_LabCont,'UserData');
288       axstdpos=get(VIZICQ4_DelCont,'UserData');
289       set(VIZICQ4_Grid_Axes,'Position',invisaxstdpos)
290       set(VIZICQ4_Slice_Axes,'Position',axstdpos)
291       set(VIZICQ4_Grid_Axes,'Visible','off')
292       set(VIZICQ4_Slice_Axes,'Visible','on')
293       set(VIZICQ4_Rotation,'String','Rotate Off')
294       set(VIZICQ4_Rotation,'ToolTipString','Activate 3-D Rotation')
295       axes(VIZICQ4_Slice_Axes)
296       rotate3d on
297    else     
298       set(VIZICQ4_Rotation,'ToolTipString','Deactivate 3-D Rotation')
299       set(VIZICQ4_Rotation,'String','Rotate On')
300       axes(VIZICQ4_Slice_Axes)
301       rotate3d off
302    end
303
304 case 'Reset_View'
305    axes(VIZICQ4_Grid_Axes);view(2)
306    axes(VIZICQ4_Slice_Axes);view(2)
307  
308 case 'Shading'
309    % move axes off-screen
310    invisaxstdpos=get(VIZICQ4_LabCont,'UserData');
311    axstdpos=get(VIZICQ4_DelCont,'UserData');
312    set(VIZICQ4_Grid_Axes,'Position',invisaxstdpos)
313    set(VIZICQ4_Slice_Axes,'Position',axstdpos)
314    set(VIZICQ4_Grid_Axes,'Visible','off')
315    set(VIZICQ4_Slice_Axes,'Visible','on')
316    axes(VIZICQ4_Slice_Axes)
317    switch option
318      case 'Flat'
319        shading flat
320        set(VIZICQ4_Volume_Shading_Faceted,'Value',0)
321        set(VIZICQ4_Volume_Shading_Interp,'Value',0)
322      case 'Interp'
323        shading interp
324        set(VIZICQ4_Volume_Shading_Faceted,'Value',0)
325        set(VIZICQ4_Volume_Shading_Flat,'Value',0)
326      case 'Faceted'
327        shading faceted
328        set(VIZICQ4_Volume_Shading_Interp,'Value',0)
329        set(VIZICQ4_Volume_Shading_Flat,'Value',0)
330    end
331    
332 case 'Pop'
333    % Toggle the visibility of the volume popup figure
334    % Get current visibility state.
335    state=get(VIZICQ4_Volume_Fig,'Visible');
336    if strcmp(state,'on')
337      set(VIZICQ4_Volume_Fig,'Visible','off');
338    else
339      set(VIZICQ4_Volume_Fig,'Visible','on');
340    end 
341  
342 case 'Colorbar'
343    delete(VIZICQ4_Colorbar_Axes)
344    h=axes('Parent',VIZICQ4_Figure,...
345          'Units','normalized',...
346          'Position',[.825 .15 .15 .025],...
347          'Tag','VIZICQ4_Colorbar_Axes');
348    
349    axes(VIZICQ4_Slice_Axes)
350    colorbar(h)
351    set(h,'Tag','VIZICQ4_Colorbar_Axes')
352
353 case 'DelVolume'
354    VIZICQ4_Slice=findobj(VIZICQ4_Slice_Axes,'Tag','VIZICQ4_Slice');
355    if isempty(VIZICQ4_Slice)
356       vizicq4_guts('Info','No Slices to Delete');
357    else
358       set(VIZICQ4_Rotation,'ToolTipString','Deactivate 3-D Rotation')
359       set(VIZICQ4_Rotation,'String','Rotate On')
360       rotate3d off
361       switch option
362       case 'one'
363          vizicq4_guts('Info','Click on Slice to Delete');
364          waitforbuttonpress;
365          target=get(gco,'Tag');
366          if strcmp(target,'VIZICQ4_Slice')
367             delete(gco)
368          else
369             vizicq4_guts('Info','Target NOT a VIZICQ4_Slice');
370          end
371       case 'all'
372          delete(VIZICQ4_Slice)
373       end
374    end
375 case 'Close'
376    set(VIZICQ4_Volume_Fig','Visible','off')
377    
378 case 'Help'
379    disp('Help on Volume not yet available')
380
381 otherwise
382    disp('argument fallthrough in vizicq4_volume')
383 end
384 setptr(VIZICQ4_Figure,'arrow')
Note: See TracBrowser for help on using the browser.