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

root/gliderproc/trunk/MATLAB/opnml/FEM/colormesh3d.m

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

Initial import of Stark code.

Line 
1 %
2 % COLORMESH3D draw FEM mesh in 3-d given, colored by a scalar field.
3
4 %     INPUT : fem_grid_struct (from LOADGRID, see FEM_GRID_STRUCT)
5 %             Q         - scalar to color with (optional)
6 %             "nofill"  - flag (optional)
7 %
8 %             With no scalar specified to contour, COLORMESH2D
9 %             defaults to the bathymetry fem_grid_struct.z
10 %
11 %   Output : hp - vector of handles, one for each element patch drawn.
12 %
13 %            COLORMESH3D colors the mesh using the scalar Q.  If Q
14 %            is omitted from the argument list, COLORMESH3D uses
15 %            the bathymetry z to color the surface. 
16 %
17 %            The default viewpoint is Azimuth = -27. degrees,
18 %            Elevation = 30 degrees.  See the MATLAB VIEW command for
19 %            more information.
20 %
21 %     NOTE : This is one of the few (2 or 3) OPNML MATLAB functions
22 %            that deletes existing patch objects in the current axes
23 %            before rendering the surface.  This is to avoid having
24 %            an unmanageable number of patch objects on the screen.
25 %
26 %  Call as : >> hp=colormesh3d(fem_grid_struct,Q,'nofill')
27 %
28 %   Author : Brian O. Blanton
29 %
30 function retval=colormesh3d(fem_grid_struct,Q,sarg)
31
32 % DEFINE ERROR STRINGS
33 err1=['more than 1 column in x-coordinate vector'];
34 err2=['more than 1 column in y-coordinate vector'];
35 err3=['more than 1 column in z-coordinate vector'];
36 err4=['node coordinate vectors must be the same length (len(x)~=len(y))'];
37 err5=['node coordinate vectors must be the same length (len(x|y)~=len(z))'];
38 err6=['scalar to be contoured must be 1-D'];
39 err7=['length of scalar must be the same length as coordinate vectors'];
40 err8=str2mat('??? Error using ==> colormesh3d',...
41              'COLORMESH3D is confused by the number of columns in ',...
42              'the element file.  It must be only three (i1 i2 i3) ',...
43              'or four (node# i1 i2 i3)');
44 err9=str2mat('??? Error using ==> colormesh3d',...
45              'COLORMESH3D needs atleast 4 input arguments.',...
46              'Input : elems - element list (.ele or .tri type)',...
47              '        x     - x-coordinate list',...
48              '        y     - y-coordinate list',...
49              '        z     - z-coordinate list (bathymetry)',...
50              '        Q     - scalar to color with (optional)',...
51              '    "nofill"  - no-interior triangles flag (optional)');
52 err10=str2mat('??? Error using ==> colormesh3d',...
53              'COLORMESH3D optional flag argument must',...
54              'be the string "nofill".');
55              
56              
57 % VERIFY INCOMING STRUCTURE
58 %
59 if ~isstruct(fem_grid_struct)
60    error(err11)
61 end
62 if ~is_valid_struct(fem_grid_struct)
63    error('    fem_grid_struct to COLORMESH2D invalid.')
64 end
65  
66 e=fem_grid_struct.e;
67 x=fem_grid_struct.x;
68 y=fem_grid_struct.y;
69 z=fem_grid_struct.z;
70
71 x=x(:);
72 y=y(:);
73 z=z(:);
74
75 if exist('Q')
76    if isstr(Q)
77       if strcmp(Q,'nofill')
78          Q=z;
79          sarg='nofill';
80       else
81          disp(err10)
82          return
83       end
84    else
85       Q=Q(:);
86    end
87 else
88    Q=z;
89 end
90
91 [nrowQ,ncolQ]=size(Q);
92 if ncolQ~=1&nrowQ~=1
93    error(err6);
94 end
95 if nrowQ ~= length(x)
96    error(err7)
97 end
98
99 e=e';
100 [m,n]=size(e);
101 xt=x(e);
102 yt=y(e);
103 zt=z(e);
104 Qt=Q(e);
105 xt=reshape(xt,m,n);
106 yt=reshape(yt,m,n);
107 zt=reshape(zt,m,n);
108 Qt=reshape(Qt,m,n);
109
110 % delete previous colorsurf objects
111 % The commented line below will only work in 4.2c or greater.
112 delete(findobj(gca,'Type','patch','Tag','colorsurf'))
113
114  
115 % Create patch object
116 %
117 if exist('sarg')
118    if strcmp(sarg,'nofill')
119       hp=patch(xt,yt,zt,Qt,'EdgeColor','interp',...
120                'FaceColor','none','Tag','colorsurf');
121    end
122 else
123    hp=patch(xt,yt,zt,Qt,'EdgeColor','interp','Tag','colorsurf');
124 end
125
126
127 % Output if requested.
128 if nargout==1,retval=hp;,end
129 %
130 %        Brian O. Blanton
131 %        Curriculum in Marine Science
132 %        Ocean Processes Numerical Modeling Laboratory
133 %        15-1A Venable Hall
134 %        CB# 3300
135 %        Uni. of North Carolina
136 %        Chapel Hill, NC
137 %                 27599-3300
138 %
139 %        919-962-4466
140 %        blanton@marine.unc.edu
141 %
142 %        Jan 1995
143 %
Note: See TracBrowser for help on using the browser.