[8]  1  %'plot_object': draws a projection object (points, line, plane...)


 2  %


 3  % function [ObjectData_out,hh]=plot_object(ObjectData,hplot,col)


 4  %


 5  %OUTPUT


 6  % hh: handles of the graphic object (core part)


 7  %


 8  %INPUT:


 9  %


 10  % ObjectDataIn: structure representing the object properties:


[379]  11  % .Type : style of projection object


[8]  12  % .Coord: set of coordinates defining the object position;


 13  % .ProjMode=type of projection ;


 14  % .ProjAngle=angle of projection;


 15  % .DX,.DY,.DZ=increments;


 16  % .YMax,YMin: min and max Y


 17  % ProjObject: projection object corresponding to the current plot (e. g. plane)


 18  % hplot: handle of the object plot to modify or if it is an axis, the axis


 19  % where the object must be plotted, or if it is a figure the plotting figure


 20  % col: color of the plot, e;g; 'm', 'b' ..;


 21 


 22  %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


 23  % Copyright Joel Sommeria, 2008, LEGI / CNRSUJFINPG, sommeria@coriolislegi.org.


 24  %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


 25  % This file is part of the toolbox UVMAT.


 26  %


 27  % UVMAT is free software; you can redistribute it and/or modify


 28  % it under the terms of the GNU General Public License as published by


 29  % the Free Software Foundation; either version 2 of the License, or


 30  % (at your option) any later version.


 31  %


 32  % UVMAT is distributed in the hope that it will be useful,


 33  % but WITHOUT ANY WARRANTY; without even the implied warranty of


 34  % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the


 35  % GNU General Public License (file UVMAT/COPYING.txt) for more details.


 36  %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA


 37 


 38  function [hh]=plot_object(ObjectDataIn,ProjObject,hplot,col)


[156]  39  %% default output


[8]  40  hh=[];%default output


[379]  41  if ~isfield(ObjectDataIn,'Type') isequal(ProjObject,ObjectDataIn)% object representation does not appear in its own projection plot


[8]  42  return


 43  end


[379]  44  if ~isfield(ProjObject,'Type')


[8]  45  ObjectData=ObjectDataIn;


[379]  46  elseif isequal(ProjObject.Type,'plane')


[8]  47  ObjectData=ObjectDataIn;% TODO: modify take into account rotation of axis


 48  else


[183]  49  return % object representation only available in a plane


[8]  50  end


[379]  51  if ~isfield(ObjectData,'Type')isempty(ObjectData.Type)~ischar(ObjectData.Type)


 52  msgbox_uvmat('ERROR','undefined ObjectData.Type in plot_object.m')


[8]  53  return


 54  end


[379]  55  if ~isfield(ObjectData,'Type')isempty(ObjectData.Type)~ischar(ObjectData.Type)


 56  msgbox_uvmat('ERROR','undefined ObjectData.Type in plot_object.m')


[8]  57  return


 58  end


 59  XMin=0;%default


 60  XMax=0;


 61  YMin=0;


 62  YMax=0;


 63  ZMin=0;


 64  ZMax=0;


 65 


[156]  66  %% determine the plotting axes (with handle 'haxes')


[8]  67  test_newobj=1;


 68  if ishandle(hplot)


[156]  69  if isequal(get(hplot,'Tag'),'proj_object')% hplot is the handle of an object representation


[8]  70  test_newobj=0;


 71  haxes=get(hplot,'parent');


[231]  72  currentfig=get(haxes,'parent');


[156]  73  elseif isequal(get(hplot,'Type'),'axes')% hplot is the handle of an axis


[231]  74  haxes=hplot;


[156]  75  currentfig=get(hplot,'parent');


[231]  76  % set(0,'CurrentFigure',currentfig)


 77 


 78  % set(currentfig,'CurrentAxes',haxes);


[156]  79  elseif isequal(get(hplot,'Type'),'figure')% hplot is the handle of a figure


 80  set(0,'CurrentFigure',hplot);%set the input figure as the current one


[8]  81  haxes=findobj(hplot,'Type','axes');%look for axes in the figure


 82  haxes=haxes(1);


[231]  83  currentfig=hplot;


 84  % set(hplot,'CurrentAxes',haxes);%set the first found axis as the current one


[8]  85  else


[231]  86  currentfig=figure; %create new figure


[8]  87  hplot=axes;%create new axes


 88  haxes=hplot;


 89  end


 90  else


[231]  91  currentfig=figure; %create new figure


[8]  92  hplot=axes;%create new axes


 93  haxes=hplot;


 94  end


[231]  95  set(0,'CurrentFigure',currentfig)%set the currentfigure as the current one


 96  set(currentfig,'CurrentAxes',haxes);%set the current axes in the current figure


[8]  97 


[156]  98  %% default input parameters


[177]  99  if ~isfield(ObjectData,'ProjMode')isempty(ObjectData.ProjMode)


[8]  100  ObjectData.ProjMode='projection';%default


 101  end


[177]  102  if ~isfield(ObjectData,'Coord')isempty(ObjectData.Coord)


[8]  103  ObjectData.Coord=[0 0 0];%default


 104  end


[379]  105  % if ~isfield(ObjectData,'Phi')isempty(ObjectData.Phi)


 106  % ObjectData.Phi=0;%default


 107  % end


 108  % if ~isfield(ObjectData,'Range')


 109  % ObjectData.Range(1,1)=0; %edfault


 110  % end


 111  % if size(ObjectData.Range,2)>=2


 112  % YMax=ObjectData.Range(1,2);%default


 113  % end


 114  % if size(ObjectData.Range,2)>=2 & size(ObjectData.Range,1)>=2


 115  % YMin=ObjectData.Range(2,2);


 116  % else


 117  % YMin=0;


 118  % end


 119  if isfield(ObjectData,'RangeX') && ~isempty(ObjectData.RangeX)


 120  XMax=max(ObjectData.RangeX);


 121  XMin=min(ObjectData.RangeX);


[8]  122  end


[379]  123  if isfield(ObjectData,'RangeY')&&~isempty(ObjectData.RangeY)


 124  YMax=max(ObjectData.RangeY);


 125  YMin=min(ObjectData.RangeY);


[8]  126  end


[379]  127  if isfield(ObjectData,'RangeZ')&&~isempty(ObjectData.RangeZ)


 128  ZMax=max(ObjectData.RangeZ);


 129  ZMin=min(ObjectData.RangeZ);


[8]  130  end


[379]  131  switch ObjectData.Type


 132  case 'points'


 133  if strcmp(ObjectData.ProjMode,'projection')


 134  YMax=max(XMax,YMax);


 135  YMax=max(YMax,ZMax);


 136  end


 137  case {'rectangle','ellipse','volume'}


 138  if isequal(YMax,0)


 139  ylim=get(haxes,'YLim');


 140  YMax=(ylim(2)ylim(1))/100;


 141  end


 142  if isequal(XMax,0)


 143  XMax=YMax;%default


 144  end


 145  case 'plane'


 146  if isequal(XMax,0)


 147  xlim=get(haxes,'XLim');


 148  XMax=xlim(2);


 149  end


 150  if isequal(YMax,0)


 151  ylim=get(haxes,'YLim');


 152  YMax=ylim(2);


 153  end


[8]  154  end


 155  sizcoord=size(ObjectData.Coord);


 156 


[156]  157  %% determine the coordinates xline, yline,xsup,xinf, yinf,ysup determining the new object plot


[379]  158  test_line= isequal(ObjectData.Type,'points')isequal(ObjectData.Type,'line')isequal(ObjectData.Type,'polyline')...


 159  isequal(ObjectData.Type,'polygon') isequal(ObjectData.Type,'plane') isequal(ObjectData.Type,'volume');


 160  test_patch=isequal(ObjectData.ProjMode,'inside')isequal(ObjectData.ProjMode,'outside')isequal(ObjectData.Type,'volume')...


[8]  161  isequal(ObjectData.ProjMode,'mask_inside')isequal(ObjectData.ProjMode,'mask_outside');


 162  if test_line


 163  xline=ObjectData.Coord(:,1);


 164  yline=ObjectData.Coord(:,2);


[177]  165  nbpoints=numel(xline);


[379]  166  if isequal(ObjectData.Type,'polygon')


[8]  167  xline=[xline; ObjectData.Coord(1,1)];%closing the line


 168  yline=[yline; ObjectData.Coord(1,2)];


[379]  169  elseif isequal(ObjectData.Type,'plane') isequal(ObjectData.Type,'volume')


[397]  170  phi=ObjectData.Angle(3)*pi/180;%angle in radians


[8]  171  Xend_x=xline(1)+XMax*cos(phi);


 172  Xend_y=yline(1)+XMax*sin(phi);


 173  Xbeg_x=xline(1)+XMin*cos(phi);


 174  Xbeg_y=yline(1)+XMin*sin(phi);


 175  Yend_x=xline(1)YMax*sin(phi);


 176  Yend_y=yline(1)+YMax*cos(phi);


 177  Ybeg_x=xline(1)YMin*sin(phi);


 178  Ybeg_y=yline(1)+YMin*cos(phi);


 179  xline=[Xbeg_x Xend_x NaN Ybeg_x Yend_x];


 180  yline=[Xbeg_y Xend_y NaN Ybeg_y Yend_y];


 181  end


 182  SubLineStyle='none';%default


 183  if isfield(ObjectData,'ProjMode')


 184  if isequal(ObjectData.ProjMode,'projection')


 185  SubLineStyle=''; %range of projection marked by dash


 186  if isfield (ObjectData,'DX')


[177]  187  ObjectData=rmfield(ObjectData,'DX');


[8]  188  end


 189  if isfield (ObjectData,'DY')


[177]  190  ObjectData=rmfield(ObjectData,'DY');


[8]  191  end


 192  elseif isequal(ObjectData.ProjMode,'filter')


 193  SubLineStyle=':';%range of projection not visible


 194  end


 195  end


[379]  196  if isequal(ObjectData.Type,'line')isequal(ObjectData.Type,'polyline')isequal(ObjectData.Type,'polygon')


[8]  197  if length(xline)<2


 198  theta=0;


 199  else


[187]  200  theta=angle(diff(xline)+1i*diff(yline));


[8]  201  theta(length(xline))=theta(length(xline)1);


 202  end


 203  xsup(1)=xline(1)+YMax*sin(theta(1));


 204  xinf(1)=xline(1)YMax*sin(theta(1));


 205  ysup(1)=yline(1)YMax*cos(theta(1));


 206  yinf(1)=yline(1)+YMax*cos(theta(1));


 207  for ip=2:length(xline)


 208  xsup(ip)=xline(ip)+YMax*sin((theta(ip)+theta(ip1))/2)/cos((theta(ip1)theta(ip))/2);


 209  xinf(ip)=xline(ip)YMax*sin((theta(ip)+theta(ip1))/2)/cos((theta(ip1)theta(ip))/2);


 210  ysup(ip)=yline(ip)YMax*cos((theta(ip)+theta(ip1))/2)/cos((theta(ip1)theta(ip))/2);


 211  yinf(ip)=yline(ip)+YMax*cos((theta(ip)+theta(ip1))/2)/cos((theta(ip1)theta(ip))/2);


 212  end


 213  end


 214  end


 215 


[156]  216  %% shading image


[8]  217  if test_patch


 218  npMx=512;


 219  npMy=512;


 220  flag=zeros(npMy,npMx);


[379]  221  if isequal(ObjectData.Type,'ellipse')


[8]  222  XimaMin=ObjectData.Coord(1,1)XMax;


 223  XimaMax=ObjectData.Coord(1,1)+XMax;


 224  YimaMin=ObjectData.Coord(1,2)YMax;


 225  YimaMax=ObjectData.Coord(1,2)+YMax;


 226  xlim=[1.2*XimaMin0.2*XimaMax 1.2*XimaMax0.2*XimaMin];%create an image around the ellipse


 227  ylim=[1.2*YimaMin0.2*YimaMax 1.2*YimaMax0.2*YimaMin];


 228  scale_x=2*1.4*XMax/npMx;


 229  scale_y=2*1.4*YMax/npMy;


[177]  230  xi=(0.5:npMx0.5)*scale_x+xlim(1);


 231  yi=(0.5:npMy0.5)*scale_y+ylim(1);


[8]  232  [Xi,Yi]=meshgrid(xi,yi);


 233  X2Max=XMax*XMax;


 234  Y2Max=YMax*YMax;


 235  distX=(XiObjectData.Coord(1,1));


 236  distY=(YiObjectData.Coord(1,2));


 237  flag=(distX.*distX/X2Max+distY.*distY/Y2Max)<1;


[379]  238  elseif isequal(ObjectData.Type,'rectangle')isequal(ObjectData.Type,'volume')


[8]  239  XimaMin=ObjectData.Coord(1,1)XMax;


 240  XimaMax=ObjectData.Coord(1,1)+XMax;


 241  YimaMin=ObjectData.Coord(1,2)YMax;


 242  YimaMax=ObjectData.Coord(1,2)+YMax;


 243  xlim=[1.2*XimaMin0.2*XimaMax 1.2*XimaMax0.2*XimaMin];%create an image around the ellipse


 244  ylim=[1.2*YimaMin0.2*YimaMax 1.2*YimaMax0.2*YimaMin];


 245  scale_x=2*1.4*XMax/npMx;


 246  scale_y=2*1.4*YMax/npMy;


[177]  247  xi=(0.5:npMx0.5)*scale_x+xlim(1);


 248  yi=(0.5:npMy0.5)*scale_y+ylim(1);


[8]  249  [Xi,Yi]=meshgrid(xi,yi);


 250  distX=abs(XiObjectData.Coord(1,1));


 251  distY=abs(YiObjectData.Coord(1,2));


 252  flag=distX<XMax & distY< YMax;


[379]  253  elseif isequal(ObjectData.Type,'polygon')


[8]  254  XimaMin=min(ObjectData.Coord(:,1));


 255  XimaMax=max(ObjectData.Coord(:,1));


 256  YimaMin=min(ObjectData.Coord(:,2));


 257  YimaMax=max(ObjectData.Coord(:,2));


 258  xlim=[1.2*XimaMin0.2*XimaMax 1.2*XimaMax0.2*XimaMin];


 259  ylim=[1.2*YimaMin0.2*YimaMax 1.2*YimaMax0.2*YimaMin];


 260  [Xlim,Ylim]=meshgrid(linspace(xlim(1),xlim(2),npMx),linspace(ylim(1),ylim(2),npMy));


 261  %flag=roipoly(xlim,ylim,flag,ObjectData.Coord(:,1),ObjectData.Coord(:,2));%=1 inside the polygon, 0 outsid


 262  flag=inpolygon(Xlim,Ylim,ObjectData.Coord(:,1),ObjectData.Coord(:,2));%=1 inside the polygon, 0 outsid


 263  end


 264  if isequal(ObjectData.ProjMode,'outside')isequal(ObjectData.ProjMode,'mask_outside')


 265  flag=~flag;


 266  end


 267  imflag=zeros(npMx,npMy,3);


 268  imflag(:,:,3)=flag; % blue color


 269  if isequal(col,'m')


 270  imflag(:,:,1)=flag; % magenta color


 271  end


 272  dx=(xlim(2)xlim(1))/npMx;


 273  dy=(ylim(2)ylim(1))/npMy;


 274  end


 275 


 276  PlotData=[];%default


[177]  277 


[156]  278  %% MODIFY AN EXISTING OBJECT PLOT


[8]  279  if test_newobj==0;


 280  hh=hplot;


 281  PlotData=get(hplot,'UserData');


 282  if test_line


 283  set(hplot,'XData',xline)


 284  set(hplot,'YData',yline)


 285  %modify subobjects


 286  if isfield(PlotData,'SubObject')


[379]  287  if length(PlotData.SubObject)==2 && ~isequal(ObjectData.Type,'points')&& ~isequal(ObjectData.Type,'plane');


[8]  288  set(PlotData.SubObject(1),'XData',xinf);


 289  set(PlotData.SubObject(1),'YData',yinf);


 290  set(PlotData.SubObject(2),'XData',xsup);


 291  set(PlotData.SubObject(2),'YData',ysup);


[379]  292  elseif isequal(ObjectData.Type,'points')&& ~isequal(YMax,0)


[8]  293  for ipt=1:min(length(PlotData.SubObject),size(ObjectData.Coord,1))


 294  set(PlotData.SubObject(ipt),'Position',[ObjectData.Coord(ipt,1)YMax ObjectData.Coord(ipt,2)YMax 2*YMax 2*YMax])


 295  end


 296  %complement missing points


 297  if size(ObjectData.Coord,1)>length(PlotData.SubObject)


 298  for ipt=length(PlotData.SubObject)+1:size(ObjectData.Coord,1)


 299  PlotData.SubObject(ipt)=rectangle('Curvature',[1 1],...


 300  'Position',[ObjectData.Coord(ipt,1)YMax ObjectData.Coord(ipt,2)YMax 2*YMax 2*YMax],'EdgeColor',col,...


 301  'LineStyle',SubLineStyle,'Tag','proj_object');


 302  end


 303  end


 304  end


 305  end


 306  if isfield(PlotData,'DeformPoint')


 307  for ipt=1:length(PlotData.DeformPoint)


 308  if ishandle(PlotData.DeformPoint(ipt))


[177]  309  if nbpoints>=ipt


[8]  310  set(PlotData.DeformPoint(ipt),'XData',xline(ipt),'YData',yline(ipt));


 311  end


 312  end


 313  end


[177]  314  if nbpoints>length(PlotData.DeformPoint)


 315  for ipt=length(PlotData.DeformPoint)+1:nbpoints


[8]  316  PlotData.DeformPoint(ipt)=line(xline(ipt),yline(ipt),'Color',col,'LineStyle','.','Tag','DeformPoint',...


 317  'SelectionHighlight','off','UserData',hplot);


 318  end


 319  set(hplot,'UserData',PlotData)


 320  end


 321  end


[379]  322  elseif isequal(ObjectData.Type,'rectangle')isequal(ObjectData.Type,'ellipse')


[8]  323  set(hplot,'Position',[ObjectData.Coord(1,1)XMax ObjectData.Coord(1,2)YMax 2*XMax 2*YMax])


 324  end


 325  if test_patch


 326  for iobj=1:length(PlotData.SubObject)


 327  objtype=get(PlotData.SubObject(iobj),'Type');


 328  if isequal(objtype,'image')


 329  set(PlotData.SubObject(iobj),'CData',imflag,'AlphaData',(flag)*0.2)


 330  set(PlotData.SubObject(iobj),'XData',[xlim(1)+dx/2 xlim(2)dx/2])


 331  set(PlotData.SubObject(iobj),'YData',[ylim(1)+dy/2 ylim(2)dy/2])


 332  end


 333  end


 334  end


 335  end


 336 


[156]  337  %% create the object


[8]  338  if test_newobj


[231]  339  % axes(haxes)


[8]  340  hother=findobj('Tag','proj_object');%find all the proj objects


 341  for iobj=1:length(hother)


[177]  342  if strcmp(get(hother(iobj),'Type'),'rectangle') strcmp(get(hother(iobj),'Type'),'patch')


[8]  343  set(hother(iobj),'EdgeColor','b')


 344  if isequal(get(hother(iobj),'FaceColor'),'m')


 345  set(hother(iobj),'FaceColor','b')


 346  end


 347  elseif isequal(get(hother(iobj),'Type'),'image')


 348  Acolor=get(hother(iobj),'CData');


 349  Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));


 350  set(hother(iobj),'CData',Acolor);


 351  else


 352  set(hother(iobj),'Color','b')


 353  end


 354  set(hother(iobj),'Selected','off')


 355  end


 356  hother=findobj('Tag','DeformPoint');


 357  set(hother,'Color','b');


 358  set(hother,'Selected','off')


[379]  359  if isequal(ObjectData.Type,'points')


[8]  360  hh=line(ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color',col,'LineStyle','.','Marker','+');


 361  for ipt=1:length(xline)


 362  PlotData.DeformPoint(ipt)=line(ObjectData.Coord(ipt,1),ObjectData.Coord(ipt,2),'Color',...


 363  col,'LineStyle','.','SelectionHighlight','off','UserData',hh,'Tag','DeformPoint');


 364  %create circle around each point


 365  if ~isequal(YMax,0)


 366  PlotData.SubObject(ipt)=rectangle('Curvature',[1 1],...


 367  'Position',[ObjectData.Coord(ipt,1)YMax ObjectData.Coord(ipt,2)YMax 2*YMax 2*YMax],'EdgeColor',col,...


 368  'LineStyle',SubLineStyle,'Tag','proj_object');


 369  end


 370  end


[379]  371  elseif strcmp(ObjectData.Type,'line')strcmp(ObjectData.Type,'polyline')...


 372  strcmp(ObjectData.Type,'polygon') strcmp(ObjectData.Type,'plane')strcmp(ObjectData.Type,'volume')% (isequal(ObjectData.Type,'polygon') & ~test_patch) isequal(ObjectData.Type,'plane')


[8]  373  hh=line(xline,yline,'Color',col);


[379]  374  if ~strcmp(ObjectData.Type,'plane') && ~strcmp(ObjectData.Type,'volume')


[177]  375  PlotData.SubObject(1)=line(xinf,yinf,'Color',col,'LineStyle',SubLineStyle,'Tag','proj_object');%draw sublines


 376  PlotData.SubObject(2)=line(xsup,ysup,'Color',col,'LineStyle',SubLineStyle,'Tag','proj_object');


[8]  377  for ipt=1:sizcoord(1)


 378  PlotData.DeformPoint(ipt)=line(ObjectData.Coord(ipt,1),ObjectData.Coord(ipt,2),'Color',...


 379  col,'LineStyle','none','Marker','.','Tag','DeformPoint','SelectionHighlight','off','UserData',hh);


 380  end


 381  end


 382 


[379]  383  elseif strcmp(ObjectData.Type,'rectangle')


[8]  384  hh=rectangle('Position',[ObjectData.Coord(1,1)XMax ObjectData.Coord(1,2)YMax 2*XMax 2*YMax],'EdgeColor',col);


[379]  385  elseif strcmp(ObjectData.Type,'ellipse')


[8]  386  hh=rectangle('Curvature',[1 1],'Position',[ObjectData.Coord(1,1)XMax ObjectData.Coord(1,2)YMax 2*XMax 2*YMax],'EdgeColor',col);


 387  else


[379]  388  msgbox_uvmat('ERROR','unknown ObjectData.Type in plot_object.m')


[8]  389  return


 390  end


 391  set(hh,'Tag','proj_object')


[187]  392  if test_patch


 393  hold on


[8]  394  hhh=image([xlim(1)+dx/2 xlim(2)dx/2],[ylim(1)+dy/2 ylim(2)dy/2],imflag,'Tag','proj_object','HitTest','off');


[187]  395  set(hhh,'AlphaData',(flag)*0.2)% set partial transparency to the filling color


 396  PlotData.SubObject=hhh;


 397  end


[8]  398  if isfield(PlotData,'SubObject')


 399  set(PlotData.SubObject,'UserData',hh)%record the parent handles in the SubObjects


 400  end


 401  if isfield(PlotData,'DeformPoint')


 402  for ipt=1:sizcoord(1)


 403  set(PlotData.DeformPoint(ipt),'UserData',hh);%record the parent handles in the SubObjects


 404  end


 405  set(PlotData.DeformPoint,'UserData',hh)%record the parent handles in the SubObjects


 406  end


 407  end


 408  set(hh,'UserData',PlotData)

