mergeprofiles

PURPOSE ^

MERGEPROFILES - morge profiles

SYNOPSIS ^

function [A,numprofiles,numpoints,closed]=mergeprofiles(A,numprofiles,numpoints,closed,prevplot,root);

DESCRIPTION ^

MERGEPROFILES - morge profiles

   this script is used by expmaster as an elementary operation
   on an ARGUS profile. The user must select the two tips that
   he/she wants to merge

   Usage:
      [A,numprofiles,numpoints,closed]=mergeprofiles(A,numprofiles,numpoints,closed,prevplot,root)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [A,numprofiles,numpoints,closed]=mergeprofiles(A,numprofiles,numpoints,closed,prevplot,root);
0002 %MERGEPROFILES - morge profiles
0003 %
0004 %   this script is used by expmaster as an elementary operation
0005 %   on an ARGUS profile. The user must select the two tips that
0006 %   he/she wants to merge
0007 %
0008 %   Usage:
0009 %      [A,numprofiles,numpoints,closed]=mergeprofiles(A,numprofiles,numpoints,closed,prevplot,root)
0010 
0011     hold on
0012     loop=1;
0013 
0014     %Take all the tips coordinates
0015     tips=zeros(2*numprofiles,4);
0016     for i=1:numprofiles
0017         %x and y coord, profile number, 1 if beginning, 2 and if end
0018         tips(2*i-1,:)=[A(i).x(1)   A(i).y(1)   i  1];
0019         tips(2*i,:) = [A(i).x(end) A(i).y(end) i  2];
0020     end
0021     %remove the closed profiles fron the list
0022     tips([2*find(closed)-1;2*find(closed)],:)=[];
0023 
0024     if size(tips,1)<2
0025         disp('at least one unclosed profiles are required')
0026         return
0027     end
0028 
0029     %plot the tips
0030     plot(tips(:,1),tips(:,2),'rs','Markersize',10);
0031     firsttip=1;
0032 
0033     %loop (at least 2 clicks needed)
0034     while loop
0035     
0036         %some checks
0037         if size(tips,1)<2
0038             disp('at least one unclosed profiles are required')
0039             return
0040         end
0041 
0042         %select a point
0043         if firsttip
0044             title('click on the first tip, RETURN to exit','FontSize',14)
0045         else
0046             title('click on the second tip, RETURN to exit','FontSize',14)
0047         end
0048 
0049         [xi,yi] = ginput(1);
0050 
0051         if ~isempty(xi)
0052 
0053             if firsttip
0054                 %find the selected tip
0055                 distance=(xi-tips(:,1)).^2+(yi-tips(:,2)).^2;
0056                 [dmin tip1]=min(distance);
0057                 numprofile1=tips(tip1,3);
0058                 firsttip=0;
0059 
0060                 %remove tip1 grom tips list
0061                 newtips=tips;
0062                 newtips(tip1,:)=[];
0063 
0064                 %plot selected tip
0065                 plot(tips(tip1,1),tips(tip1,2),'bs','MarkerSize',10);
0066                 plot(A(numprofile1).x,A(numprofile1).y,'-g');
0067 
0068             %second selection
0069             else
0070                 distance=(xi-newtips(:,1)).^2+(yi-newtips(:,2)).^2;
0071                 [dmin tip2]=min(distance);
0072                 numprofile2=newtips(tip2,3);
0073 
0074                 %reverse if necessary
0075                 if numprofile2<numprofile1
0076                     fakeprofile=numprofile2;
0077                     numprofile2=numprofile1;
0078                     numprofile1=fakeprofile;
0079                 end
0080 
0081                 if numprofile1==numprofile2
0082                     %close the profile
0083                     A(numprofile1).x(end+1)=A(numprofile1).x(1);
0084                     A(numprofile1).y(end+1)=A(numprofile1).y(1);
0085                     numpoints=numpoints+1;
0086                     closed(numprofile1)=1;
0087 
0088                 else
0089 
0090                     if tips(tip1,4)==1 & newtips(tip2,4)==1,
0091                         A(numprofile1).x=[flipud(A(numprofile2).x); A(numprofile1).x];
0092                         A(numprofile1).y=[flipud(A(numprofile2).y); A(numprofile1).y];
0093                         numprofiles=numprofiles-1;
0094                         closed(numprofile1)=1;
0095 
0096                     elseif tips(tip1,4)==1 & newtips(tip2,4)==2,
0097                         A(numprofile1).x=[A(numprofile2).x; A(numprofile1).x];
0098                         A(numprofile1).y=[A(numprofile2).y; A(numprofile1).y];
0099                         numprofiles=numprofiles-1;
0100                         closed(numprofile1)=1;
0101 
0102                     elseif tips(tip1,4)==2 & newtips(tip2,4)==1,
0103                         A(numprofile1).x=[A(numprofile1).x; A(numprofile2).x];
0104                         A(numprofile1).y=[A(numprofile1).y; A(numprofile2).y];
0105                         numprofiles=numprofiles-1;
0106                         closed(numprofile1)=1;
0107 
0108                     elseif tips(tip1,4)==2 & newtips(tip2,4)==2,
0109                         A(numprofile1).x=[A(numprofile1).x; flipud(A(numprofile2).x)];
0110                         A(numprofile1).y=[A(numprofile1).y; flipud(A(numprofile2).y)];
0111                         numprofiles=numprofiles-1;
0112                         closed(numprofile1)=1;
0113                     end
0114 
0115                     %delete profile2
0116                     A(numprofile2)=[];
0117                     closed(numprofile2)=[];
0118 
0119                 end
0120 
0121                 %update tips
0122                 tips=newtips;
0123                 tips(tip2,:)=[];
0124                 tips(find(tips(:,3)==numprofile2),3)=numprofile1;
0125 
0126                 %plot new profile
0127                 undoplots(prevplot);
0128                 for i=1:numprofiles
0129                     plot(A(i).x,A(i).y,'-r','MarkerSize',10);
0130                 end
0131                 plot(tips(:,1),tips(:,2),'rs','Markersize',10);
0132 
0133                 %back to beginning
0134                 firsttip=1;
0135             end
0136         else
0137             %RETRUN-> quit
0138             loop=0;
0139         end
0140     end
0141 end

Generated on Sun 29-Mar-2009 20:22:55 by m2html © 2003