drawShape

PURPOSE ^

drawShape Draw shapes to figure

SYNOPSIS ^

function drawShape(sType,begPt,sLength, color, thickness,sStyle,verbose)

DESCRIPTION ^

drawShape Draw shapes to figure

 drawShape(sType,begPt,sLength, color, thickness,sStyle,verbose)
 
INPUTS
 sType         Shape type ('rect', 'line', 'circle')
 begPt         Coordinate of start point [x y]
 sLength       Shape length [x length, y length]
 color         Shape color
 thickness     Shape edge thickness
 sStyle        Shape style
   DASHL           Dashed edge
   DASHM           Dashed edge
   DASHS           Dash dot edge
   DOTTD           Dotted edge
   PLAIN           Solid edge

OPTIONAL INPUT
 verbose       verboseFlag (Default = fasle0

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function drawShape(sType,begPt,sLength, color, thickness,sStyle,verbose)
0002 %drawShape Draw shapes to figure
0003 %
0004 % drawShape(sType,begPt,sLength, color, thickness,sStyle,verbose)
0005 %
0006 %INPUTS
0007 % sType         Shape type ('rect', 'line', 'circle')
0008 % begPt         Coordinate of start point [x y]
0009 % sLength       Shape length [x length, y length]
0010 % color         Shape color
0011 % thickness     Shape edge thickness
0012 % sStyle        Shape style
0013 %   DASHL           Dashed edge
0014 %   DASHM           Dashed edge
0015 %   DASHS           Dash dot edge
0016 %   DOTTD           Dotted edge
0017 %   PLAIN           Solid edge
0018 %
0019 %OPTIONAL INPUT
0020 % verbose       verboseFlag (Default = fasle0
0021 %
0022 if ~exist('verbose','var')
0023     verbose = false;
0024 end
0025 global CB_MAP_OUTPUT
0026 global mapHandle
0027 if nargin < 4
0028     color = 'b';
0029     display('No color specified');
0030 elseif strcmp(CB_MAP_OUTPUT, 'matlab')
0031     color = (1/255)*color;
0032 end
0033 if verbose
0034     if strcmp(sStyle,'DASHL')
0035         display('DASHL');
0036         style = '--';
0037         dashArray = '30, 20';
0038     elseif strcmp(sStyle,'DASHM')
0039         display('DASHM');
0040         style = '--';
0041         dashArray = '20, 20';
0042     elseif strcmp(sStyle,'DASHS')
0043         display('DASHS');
0044         style = '-.';
0045         dashArray = '10, 15';
0046     elseif strcmp(sStyle,'DOTTD')
0047         display('DOTTD');
0048         style = ':';
0049         dashArray = '0, 20';
0050     elseif strcmp(sStyle,'PLAIN')
0051         display('PLAIN');
0052         style = '-';
0053         dashArray = '';
0054     else
0055         style = '-';
0056         dashArray = '';
0057         display('Unknown Style');
0058     end
0059 else
0060     if strcmp(sStyle,'DASHL')
0061         style = '--';
0062         dashArray = '30, 20';
0063     elseif strcmp(sStyle,'DASHM')
0064         style = '--';
0065         dashArray = '20, 20';
0066     elseif strcmp(sStyle,'DASHS')
0067         style = '-.';
0068         dashArray = '10, 15';
0069     elseif strcmp(sStyle,'DOTTD')
0070         style = ':';
0071         dashArray = '0, 20';
0072     elseif strcmp(sStyle,'PLAIN')
0073         style = '-';
0074         dashArray = '';
0075     else
0076         style = '-';
0077         dashArray = '';
0078     end
0079 end
0080 
0081 if strcmp(CB_MAP_OUTPUT, 'matlab')
0082     thickness = thickness/7;
0083     begPt(1,2) = -begPt(1,2);
0084     sLength(1,1) = -sLength(1,1);
0085     switch lower(sType{1})
0086         case 'line'
0087             line([begPt(1,1),(begPt(1,1)+sLength(1,2))],[begPt(1,2),(begPt(1,2)+sLength(1,1))],'Color',color,'LineWidth',thickness,'LineStyle',style);
0088         case {'rect', 'rectangle'}
0089             line([begPt(1,1),begPt(1,1)],[begPt(1,2),(begPt(1,2)+sLength(1,1))],'Color',color,'LineWidth',thickness,'LineStyle',style);
0090             line([begPt(1,1),(begPt(1,1)+sLength(1,2))],[begPt(1,2),begPt(1,2)],'Color',color,'LineWidth',thickness,'LineStyle',style);
0091             line([(begPt(1,1)+sLength(1,2)),(begPt(1,1)+sLength(1,2))],[begPt(1,2),(begPt(1,2)+sLength(1,1))],'Color',color,'LineWidth',thickness,'LineStyle',style);
0092             line([begPt(1,1),(begPt(1,1)+sLength(1,2))],[(begPt(1,2)+sLength(1,1)),(begPt(1,2)+sLength(1,1))],'Color',color,'LineWidth',thickness,'LineStyle',style);
0093         case 'circle'
0094             i = 0:pi/100:2*pi;
0095             x = .5*sLength(1,2)*cos(i)+begPt(1);
0096             y = .5*sLength(1,1)*sin(i)-begPt(2);
0097             plot(x,y,style);
0098         otherwise
0099             display('error: Unknown Shape Type');
0100     end
0101 elseif strcmp(CB_MAP_OUTPUT, 'java')
0102     % fill in code
0103     
0104     %setData(mapHandle, 400+randn(1000,1)*130, 300+randn(1000,1)*90, rand(1000,1)*220, ones(1000,1)*80);
0105     %setDataVector(mapHandle,begPt(1,1),endPt(1,1),begPt(2,1),endPt(2,1),220,80);
0106     x1=begPt(1,1);
0107     x2=endPt(1,1);
0108     y1=begPt(2,1);
0109     y2=endPt(2,1);
0110     %setbkgrnd(mapHandle,100);
0111     %settrans(mapHandle,xmin,xmax,ymax,ymin);
0112     setDataVector(mapHandle,x1,y1,x2,y2);
0113     
0114 elseif strcmp(CB_MAP_OUTPUT, 'svg')
0115     if ischar(color)
0116         colorStroke = color;
0117     else if isvector(color)
0118             colorStroke = strcat('rgb(',num2str(color(1)),',',num2str(color(2)),',',num2str(color(3)),')');
0119         end
0120     end
0121     switch lower(sType{1})
0122         case 'line'
0123             fprintf(mapHandle,['<g style="stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 20; '...
0124                 'fill: %s; stroke: %s; stroke-width: %d; stroke-dasharray: %s;">\n'],colorStroke,colorStroke,thickness,dashArray);
0125             fprintf(mapHandle,'<line x1="%.2f" y1="%.2f" x2="%.2f" y2="%.2f" />\n</g>\n',begPt(1,1),begPt(1,2),begPt(1,1)+sLength(1,2),begPt(1,2)+sLength(1,1));
0126         case {'rect', 'rectangle'}
0127             fprintf(mapHandle,['<g style="stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 20; '...
0128                 'fill: none; stroke: %s; stroke-width: %d; stroke-dasharray: %s;">\n'],colorStroke,thickness,dashArray);
0129             fprintf(mapHandle,'<rect x="%.2f" y="%.2f" width="%.2f" height="%.2f" />\n</g>\n',begPt(1,1),begPt(1,2),sLength(1,2),sLength(1,1));
0130         case 'circle'
0131             fprintf(mapHandle,['<g style="stroke-linecap: round; stroke-linejoin: round; stroke-miterlimit: 20; '...
0132                 'fill: none; stroke: %s; stroke-width: %d; stroke-dasharray: %s;">\n'],colorStroke,thickness,dashArray);
0133             fprintf(mapHandle,'<ellipse cx="%.2f" cy="%.2f" rx="%.2f" ry="%.2f" />\n</g>\n',begPt(1,1)+(.5*sLength(1,2)),begPt(1,2)+(.5*sLength(1,1)),.5*sLength(1,2),.5*sLength(1,1));
0134         otherwise
0135             display('Error: Unknown Shape Type');
0136     end
0137     
0138 else
0139     display('Error: Invalid Output');
0140 end

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003