Changeset 625 for trunk/src/plot_object.m
 Timestamp:
 May 2, 2013, 7:51:42 PM (10 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/plot_object.m
r622 r625 54 54 return 55 55 end 56 XMin=0;%default 56 XMin=0;%default range for the graph 57 57 XMax=0; 58 58 YMin=0; … … 60 60 ZMin=0; 61 61 ZMax=0; 62 XMinRange=[];%default range set by input 63 XMaxRange=[]; 64 YMinRange=[]; 65 YMaxRange=[]; 66 ZMinRange=[]; 67 ZMaxRange=[]; 62 68 63 69 %% determine the plotting axes (with handle 'haxes') … … 99 105 XMax=max(ObjectData.RangeX); 100 106 XMin=min(ObjectData.RangeX); 107 XMaxRange=max(ObjectData.RangeX); 108 if numel(ObjectData.RangeX)==2 109 XMinRange=min(ObjectData.RangeX); 110 end 101 111 end 102 112 if isfield(ObjectData,'RangeY')&&~isempty(ObjectData.RangeY) 103 113 YMax=max(ObjectData.RangeY); 104 114 YMin=min(ObjectData.RangeY); 115 YMaxRange=max(ObjectData.RangeY); 116 if numel(ObjectData.RangeY)==2 117 YMinRange=min(ObjectData.RangeY); 118 end 105 119 end 106 120 if isfield(ObjectData,'RangeZ')&&~isempty(ObjectData.RangeZ) 107 121 ZMax=max(ObjectData.RangeZ); 108 122 ZMin=min(ObjectData.RangeZ); 109 end 110 switch ObjectData.Type 111 case 'points' 112 if strcmp(ObjectData.ProjMode,'projection') 113 YMax=max(XMax,YMax); 114 YMax=max(YMax,ZMax); 115 end 116 case {'rectangle','ellipse','volume'} 117 % if isequal(YMax,0) 118 % ylim=get(haxes,'YLim'); 119 % YMax=(ylim(2)ylim(1))/100; 120 % end 121 % if isequal(XMax,0) 122 % XMax=YMax;%default 123 % end 124 case 'plane' 125 if isequal(XMax,0) 126 xlim=get(haxes,'XLim'); 127 XMax=xlim(2); 128 end 129 if isequal(YMax,0) 130 ylim=get(haxes,'YLim'); 131 YMax=ylim(2); 132 end 123 ZMaxRange=max(ObjectData.RangeZ); 124 ZMinRange=min(ObjectData.RangeZ); 125 end 126 if strcmp(ObjectData.Type,'points') && strcmp(ObjectData.ProjMode,'projection') 127 YMax=max(XMax,YMax); 128 YMax=max(YMax,ZMax); 133 129 end 134 130 sizcoord=size(ObjectData.Coord); … … 147 143 yline=[yline; ObjectData.Coord(1,2)]; 148 144 elseif isequal(ObjectData.Type,'plane') isequal(ObjectData.Type,'volume') 145 if ~isfield(ObjectData,'Angle') 146 ObjectData.Angle=[0 0 0]; 147 end 149 148 phi=ObjectData.Angle(3)*pi/180;%angle in radians 150 Xend_x=xline(1)+XMax*cos(phi); 151 Xend_y=yline(1)+XMax*sin(phi); 152 Xbeg_x=xline(1)+XMin*cos(phi); 153 Xbeg_y=yline(1)+XMin*sin(phi); 154 Yend_x=xline(1)YMax*sin(phi); 155 Yend_y=yline(1)+YMax*cos(phi); 156 Ybeg_x=xline(1)YMin*sin(phi); 157 Ybeg_y=yline(1)+YMin*cos(phi); 158 xline=[Xbeg_x Xend_x NaN Ybeg_x Yend_x]; 159 yline=[Xbeg_y Xend_y NaN Ybeg_y Yend_y]; 149 x0=xline(1); y0=yline(1); 150 xlim=get(haxes,'XLim'); 151 ylim=get(haxes,'YLim'); 152 graph_scale=max(abs(xlim(2)xlim(1)),abs(ylim(2)ylim(1)))/2;% estimate the length of axes plots 153 XMax=graph_scale; 154 YMax=graph_scale; 155 XMin=graph_scale; 156 YMin=graph_scale; 157 if ~isempty(XMaxRange) 158 XMax=XMaxRange; 159 end 160 if ~isempty(XMinRange) 161 XMin=XMinRange; 162 end 163 if ~isempty(YMaxRange) 164 YMax=YMaxRange; 165 end 166 if ~isempty(YMinRange) 167 YMin=YMinRange; 168 end 169 % axes lines 170 xline=NaN(1,13); 171 xline(1)=x0+min(0,XMin)*cos(phi); % min end of the x axes 172 yline(1)=y0+min(0,XMin)*sin(phi); 173 xline(2)=x0+XMax*cos(phi);% max end of the x axes 174 yline(2)=y0+XMax*sin(phi); 175 xline(8)=x0min(0,YMin)*sin(phi);% min end of the y axes 176 yline(8)=y0+min(0,YMin)*cos(phi); 177 xline(9)=x0YMax*sin(phi);% max end of the y axes 178 yline(9)=y0+YMax*cos(phi); 179 180 %arrows on x axis 181 arrow_scale=graph_scale/20; 182 xline(3)=xline(2)arrow_scale*cos(phipi/8); 183 yline(3)=yline(2)arrow_scale*sin(phipi/8); 184 xline(5)=xline(2); 185 yline(5)=yline(2); 186 xline(6)=xline(2)arrow_scale*cos(phi+pi/8); 187 yline(6)=yline(2)arrow_scale*sin(phi+pi/8); 188 189 %arrows on y axis 190 xline(10)=xline(9)arrow_scale*cos(phi+pi/2pi/8); 191 yline(10)=yline(9)arrow_scale*sin(phi+pi/2pi/8); 192 xline(12)=xline(9); 193 yline(12)=yline(9); 194 xline(13)=xline(9)arrow_scale*cos(phi+pi/2+pi/8); 195 yline(13)=yline(9)arrow_scale*sin(phi+pi/2+pi/8); 196 %xline=[Xbeg_x Xend_x NaN Ybeg_x Yend_x]; 197 %yline=[Xbeg_y Xend_y NaN Ybeg_y Yend_y]; 198 % dashed lines indicating bounds 199 xsup=NaN(1,5); 200 ysup=NaN(1,5); 201 if ~isempty(XMaxRange) 202 xsup(1)=xline(2)YMin*sin(phi); 203 ysup(1)=yline(2)+YMin*cos(phi); 204 xsup(2)=xline(2)YMax*sin(phi); 205 ysup(2)=yline(2)+YMax*cos(phi); 206 end 207 if ~isempty(YMaxRange) 208 xsup(2)=xline(2)YMax*sin(phi); 209 ysup(2)=yline(2)+YMax*cos(phi); 210 xsup(3)=xline(9)+XMin*cos(phi); 211 ysup(3)=yline(9)+XMin*sin(phi); 212 end 213 if ~isempty(XMinRange) 214 xsup(3)=xline(9)+XMin*cos(phi); 215 ysup(3)=yline(9)+XMin*sin(phi); 216 xsup(4)=x0+XMin*cos(phi)YMin*sin(phi); 217 ysup(4)=y0+XMin*sin(phi)+YMin*cos(phi); 218 end 219 if ~isempty(YMinRange) 220 xsup(4)=x0+XMin*cos(phi)YMin*sin(phi); 221 ysup(4)=y0+XMin*sin(phi)+YMin*cos(phi); 222 xsup(5)=xline(8)YMin*sin(phi); 223 ysup(5)=yline(8)+YMin*cos(phi); 224 end 160 225 end 161 226 SubLineStyle='none';%default … … 258 323 if test_newobj==0; 259 324 hh=hplot; 260 PlotData=get(hplot,'UserData'); 325 PlotData=get(hplot,'UserData'); 261 326 if test_line 262 327 set(hplot,'XData',xline) 263 328 set(hplot,'YData',yline) 264 %modify subobjects 265 if isfield(PlotData,'SubObject') 266 if length(PlotData.SubObject)==2 && ~isequal(ObjectData.Type,'points')&& ~isequal(ObjectData.Type,'plane'); 329 %modify subobjects 330 if isfield(PlotData,'SubObject') 331 if isequal(ObjectData.Type,'points') 332 if ~isequal(YMax,0) 333 for ipt=1:min(length(PlotData.SubObject),size(ObjectData.Coord,1)) 334 set(PlotData.SubObject(ipt),'Position',[ObjectData.Coord(ipt,1)YMax ObjectData.Coord(ipt,2)YMax 2*YMax 2*YMax]) 335 end 336 %complement missing points 337 if length(PlotData.SubObject)>nbpoints% fpoints in excess on the graph 338 for ii=nbpoints+1: length(PlotData.SubObject); 339 if ishandle(PlotData.SubObject(ii)) 340 delete(PlotData.SubObject(ii)) 341 end 342 end 343 end 344 % NbDeformPoint=nbpoints; 345 346 if nbpoints>length(PlotData.SubObject) 347 for ipt=length(PlotData.SubObject)+1:nbpoints 348 PlotData.SubObject(ipt)=rectangle('Curvature',[1 1],... 349 'Position',[ObjectData.Coord(ipt,1)YMax ObjectData.Coord(ipt,2)YMax 2*YMax 2*YMax],'EdgeColor',col,... 350 'LineStyle',SubLineStyle,'Tag','proj_object'); 351 end 352 end 353 end 354 elseif length(PlotData.SubObject)==2 267 355 set(PlotData.SubObject(1),'XData',xinf); 268 356 set(PlotData.SubObject(1),'YData',yinf); 269 357 set(PlotData.SubObject(2),'XData',xsup); 270 358 set(PlotData.SubObject(2),'YData',ysup); 271 elseif isequal(ObjectData.Type,'points')&& ~isequal(YMax,0) 272 for ipt=1:min(length(PlotData.SubObject),size(ObjectData.Coord,1)) 273 set(PlotData.SubObject(ipt),'Position',[ObjectData.Coord(ipt,1)YMax ObjectData.Coord(ipt,2)YMax 2*YMax 2*YMax]) 274 end 275 %complement missing points 276 if length(PlotData.SubObject)>nbpoints% fpoints in excess on the graph 277 for ii=nbpoints+1: length(PlotData.SubObject); 278 if ishandle(PlotData.SubObject(ii)) 279 delete(PlotData.SubObject(ii)) 280 end 281 end 282 % NbDeformPoint=nbpoints; 283 end 284 if nbpoints>length(PlotData.SubObject) 285 for ipt=length(PlotData.SubObject)+1:nbpoints 286 PlotData.SubObject(ipt)=rectangle('Curvature',[1 1],... 287 'Position',[ObjectData.Coord(ipt,1)YMax ObjectData.Coord(ipt,2)YMax 2*YMax 2*YMax],'EdgeColor',col,... 288 'LineStyle',SubLineStyle,'Tag','proj_object'); 289 end 290 end 291 end 359 elseif length(PlotData.SubObject)==1 360 set(PlotData.SubObject(1),'XData',xsup); 361 set(PlotData.SubObject(1),'YData',ysup); 362 end 292 363 end 293 364 if isfield(PlotData,'DeformPoint') 294 365 NbDeformPoint=length(PlotData.DeformPoint); 295 if NbDeformPoint>nbpoints% fpoints in excess on the graph296 for ii=nbpoints+1:NbDeformPoint;297 if ishandle(PlotData.DeformPoint(ii))366 if NbDeformPoint>nbpoints% fpoints in excess on the graph 367 for ii=nbpoints+1:NbDeformPoint; 368 if ishandle(PlotData.DeformPoint(ii)) 298 369 delete(PlotData.DeformPoint(ii)) 299 end300 end301 NbDeformPoint=nbpoints;302 end303 for ipt=1:NbDeformPoint304 if ishandle(PlotData.DeformPoint(ipt))305 if nbpoints>=ipt370 end 371 end 372 NbDeformPoint=nbpoints; 373 end 374 for ipt=1:NbDeformPoint 375 if ishandle(PlotData.DeformPoint(ipt)) 376 if nbpoints>=ipt 306 377 set(PlotData.DeformPoint(ipt),'XData',xline(ipt),'YData',yline(ipt)); 307 378 end 308 end309 end310 if nbpoints>length(PlotData.DeformPoint)311 for ipt=length(PlotData.DeformPoint)+1:nbpoints379 end 380 end 381 if nbpoints>length(PlotData.DeformPoint) 382 for ipt=length(PlotData.DeformPoint)+1:nbpoints 312 383 PlotData.DeformPoint(ipt)=line(xline(ipt),yline(ipt),'Color',col,'LineStyle','.','Tag','DeformPoint',... 313 384 'SelectionHighlight','off','UserData',hplot); 314 end315 set(hplot,'UserData',PlotData)316 end385 end 386 set(hplot,'UserData',PlotData) 387 end 317 388 end 318 389 elseif (isequal(ObjectData.Type,'rectangle')isequal(ObjectData.Type,'ellipse'))&&XMax>0 && YMax>0 319 set(hplot,'Position',[ObjectData.Coord(1,1)XMax ObjectData.Coord(1,2)YMax 2*XMax 2*YMax]) 320 end 321 if test_patch 390 set(hplot,'Position',[ObjectData.Coord(1,1)XMax ObjectData.Coord(1,2)YMax 2*XMax 2*YMax]) 391 end 392 if test_patch 322 393 for iobj=1:length(PlotData.SubObject) 323 394 objtype=get(PlotData.SubObject(iobj),'Type'); … … 353 424 set(hother,'Color','b'); 354 425 set(hother,'Selected','off') 355 if isequal(ObjectData.Type,'points') 356 hh=line(ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color',col,'LineStyle','.','Marker','+'); 357 for ipt=1:length(xline) 358 PlotData.DeformPoint(ipt)=line(ObjectData.Coord(ipt,1),ObjectData.Coord(ipt,2),'Color',... 359 col,'LineStyle','.','SelectionHighlight','off','UserData',hh,'Tag','DeformPoint'); 360 %create circle around each point 361 if ~isequal(YMax,0) 362 PlotData.SubObject(ipt)=rectangle('Curvature',[1 1],... 363 'Position',[ObjectData.Coord(ipt,1)YMax ObjectData.Coord(ipt,2)YMax 2*YMax 2*YMax],'EdgeColor',col,... 364 'LineStyle',SubLineStyle,'Tag','proj_object'); 365 end 366 end 367 elseif strcmp(ObjectData.Type,'line')strcmp(ObjectData.Type,'polyline')... 368 strcmp(ObjectData.Type,'polygon') strcmp(ObjectData.Type,'plane')strcmp(ObjectData.Type,'volume')% (isequal(ObjectData.Type,'polygon') & ~test_patch) isequal(ObjectData.Type,'plane') 369 hh=line(xline,yline,'Color',col); 370 if ~strcmp(ObjectData.Type,'plane') && ~strcmp(ObjectData.Type,'volume') 371 PlotData.SubObject(1)=line(xinf,yinf,'Color',col,'LineStyle',SubLineStyle,'Tag','proj_object');%draw sublines 372 PlotData.SubObject(2)=line(xsup,ysup,'Color',col,'LineStyle',SubLineStyle,'Tag','proj_object'); 373 for ipt=1:sizcoord(1) 426 switch ObjectData.Type 427 case 'points' 428 hh=line(ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color',col,'LineStyle','.','Marker','+'); 429 for ipt=1:length(xline) 374 430 PlotData.DeformPoint(ipt)=line(ObjectData.Coord(ipt,1),ObjectData.Coord(ipt,2),'Color',... 375 col,'LineStyle','none','Marker','.','Tag','DeformPoint','SelectionHighlight','off','UserData',hh); 376 end 377 end 378 379 elseif strcmp(ObjectData.Type,'rectangle') 380 hh=rectangle('Position',[ObjectData.Coord(1,1)XMax ObjectData.Coord(1,2)YMax 2*XMax 2*YMax],'EdgeColor',col); 381 elseif strcmp(ObjectData.Type,'ellipse') 382 hh=rectangle('Curvature',[1 1],'Position',[ObjectData.Coord(1,1)XMax ObjectData.Coord(1,2)YMax 2*XMax 2*YMax],'EdgeColor',col); 383 else 384 msgbox_uvmat('ERROR','unknown ObjectData.Type in plot_object.m') 385 return 431 col,'LineStyle','.','SelectionHighlight','off','UserData',hh,'Tag','DeformPoint'); 432 %create circle around each point 433 if ~isequal(YMax,0) 434 PlotData.SubObject(ipt)=rectangle('Curvature',[1 1],... 435 'Position',[ObjectData.Coord(ipt,1)YMax ObjectData.Coord(ipt,2)YMax 2*YMax 2*YMax],'EdgeColor',col,... 436 'LineStyle',SubLineStyle,'Tag','proj_object'); 437 end 438 end 439 case {'line','polyline','polygon'} 440 hh=line(xline,yline,'Color',col); 441 PlotData.SubObject(1)=line(xinf,yinf,'Color',col,'LineStyle',SubLineStyle,'Tag','proj_object');%draw sublines 442 PlotData.SubObject(2)=line(xsup,ysup,'Color',col,'LineStyle',SubLineStyle,'Tag','proj_object'); 443 for ipt=1:sizcoord(1) 444 PlotData.DeformPoint(ipt)=line(ObjectData.Coord(ipt,1),ObjectData.Coord(ipt,2),'Color',... 445 col,'LineStyle','none','Marker','.','Tag','DeformPoint','SelectionHighlight','off','UserData',hh); 446 end 447 case {'plane','volume'} 448 hh=line(xline,yline,'Color',col); 449 PlotData.SubObject(1)=line(xsup,ysup,'Color',col,'LineStyle',SubLineStyle,'Tag','proj_object'); 450 case 'rectangle' 451 hh=rectangle('Position',[ObjectData.Coord(1,1)XMax ObjectData.Coord(1,2)YMax 2*XMax 2*YMax],'LineWidth',2,'EdgeColor',col); 452 case 'ellipse' 453 hh=rectangle('Curvature',[1 1],'Position',[ObjectData.Coord(1,1)XMax ObjectData.Coord(1,2)YMax 2*XMax 2*YMax],'EdgeColor',col); 454 otherwise 455 msgbox_uvmat('ERROR','unknown ObjectData.Type in plot_object.m') 456 return 386 457 end 387 458 set(hh,'Tag','proj_object')
Note: See TracChangeset
for help on using the changeset viewer.