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

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

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

Initial import of Stark code.

Line 
1 function h=numelems(fem_grid_struct,ps)
2 %NUMELEMS number elements on current axes in viewing region.
3 %
4 %  INPUT : fem_grid_struct - (from LOADGRID, see FEM_GRID_STRUCT)
5 %          ps              - point size for screen text numbers
6 %                            (optional, def=15)
7 %
8 % OUTPUT : h - vector of handle to text objects drawn (optional)
9 %
10 %   CALL : h=numelems(fem_grid_struct,ps);
11 %
12 % Written by: Brian O. Blanton
13 % Summer 1997
14 %
15
16 % DEFINE ERROR STRINGS
17 err1=['Not enough input arguments; need atleast fem_grid_struct'];
18 err2=['Too many input arguments; type "help numelems"'];
19 warn1=['The current axes is too dense for the  '
20        'node numbers to be readable.  CONTINUE?'];
21            
22 % check arguments
23 if nargin ==0
24    error(err1);
25 elseif nargin >2
26    error(err2);
27 elseif nargin==1
28    ps=15;
29 end
30
31 if ~is_valid_struct(fem_grid_struct)
32    error('    Argument to NUMELEMS must be a valid fem_grid_struct.')
33 end
34  
35 % Extract grid fields from fem_grid_struct
36 %
37 elems=fem_grid_struct.e;
38 x=fem_grid_struct.x;
39 y=fem_grid_struct.y;
40
41 % compute centroid of each element
42 i=1:length(elems(:,1));
43 xcent=(x(elems(i,1))+x(elems(i,2))+x(elems(i,3)))/3;
44 ycent=(y(elems(i,1))+y(elems(i,2))+y(elems(i,3)))/3;
45  
46 % get indices of centroids within viewing window defined by X,Y
47 X=get(gca,'XLim');
48 Y=get(gca,'YLim');
49 filt=find((xcent>X(1)&xcent<X(2))&(ycent>Y(1)&ycent<Y(2)));
50  
51 % determine if viewing window is zoomed-in enough for element
52 % numbers to be meaningful;
53 set(gca,'Units','points');      % get viewing window width in point size
54 rect=get(gca,'Position');       % point units (1/72 inches)
55 set(gca,'Units','normalized');  % reset viewing window units
56 xr=rect(3)-rect(1);
57 yr=rect(4)-rect(2);;
58 xden=xr/sqrt(length(filt));
59 yden=yr/sqrt(length(filt));
60 den=sqrt(xden*xden+yden*yden);
61 if den < 5*ps
62    click=questdlg(warn1,'Continue??','Yes','No','Cancel','No');
63    if strcmp(click,'No')|strcmp(click,'Cancel'),
64       if nargout==1,h=[];,end
65       return
66    end
67 end
68
69 % Build string matrix
70 strlist=num2str(filt,6);
71
72 xx=xcent(filt);yy=ycent(filt);
73
74 format long e
75 % label only those nodes that lie within viewing window.
76 htext=text(xx,yy,strlist,...
77                  'FontSize',ps,...
78                  'HorizontalAlignment','center',...
79                  'VerticalAlignment','middle',...
80                  'Color','k',...
81                  'Tag','Element #');
82 if nargout==1,h=htext;,end
83 return
84 %
85 %        Brian O. Blanton
86 %        Department of Marine Sciences
87 %        15-1A Venable Hall
88 %        CB# 3300
89 %        Uni. of North Carolina
90 %        Chapel Hill, NC
91 %                 27599-3300
92 %
93 %        919-962-4466
94 %        blanton@marine.unc.edu
95 %
96 %        Summer 1997
97 %
98
99
Note: See TracBrowser for help on using the browser.