function convexprop(action) % get button descriptors weakhandle = findobj(gcbf,'Tag','Weakbutton'); stronghandle = findobj(gcbf,'Tag','Strongbutton'); % get the polygon data from the figure polyhandle = findobj(gcbf,'Tag','Bpolygon'); pp = [get(polyhandle,'XData'); get(polyhandle,'YData')]; switch(action) case 'strong', % find the order of the spline (default 3) t = get(polyhandle,'UserData'); if isempty(t) k=4; else k=t(1); end for i=1:size(pp,2)-k+1 index = convhull(pp(1,i:i+k-1),pp(2,i:i+k-1)); fillhandle = fill(pp(1,i-1+index),pp(2,i-1+index),[.8 .8 .8]); set(fillhandle,'Tag','Strongpolygon'); set(fillhandle,'ButtonDownFcn','drawbspline(''start'')') end % move polygon to front h = line(pp(1,:),pp(2,:),'Color','r','LineStyle','--'); set(h,'Tag','Bpolygon2') set(h,'ButtonDownFcn','drawbspline(''start'')') % redefine pushbutton set(stronghandle,'String','Erase Strong CH') set(stronghandle,'Callback','convexprop(''clearstrong'')') case 'weak' index = convhull(pp(1,:),pp(2,:)); fillhandle = fill(pp(1,index),pp(2,index),[.9 .9 .9]); set(fillhandle,'Tag','Weakpolygon'); set(fillhandle,'ButtonDownFcn','drawbspline(''start'')') % move polygon to front h = line(pp(1,:),pp(2,:),'Color','r','LineStyle','--'); set(h,'Tag','Bpolygon2') set(h,'ButtonDownFcn','drawbspline(''start'')') % redefine pushbutton set(weakhandle,'String','Erase Weak CH') set(weakhandle,'Callback','convexprop(''clearweak'')') case 'clearweak' delete(findobj(gcbf,'Tag','Weakpolygon')); delete(findobj(gcbf,'Tag','Bpolygon2')); set(weakhandle,'String','Weak Convex Hull') set(weakhandle,'Callback','convexprop(''weak'')') case 'clearstrong' delete(findobj(gcbf,'Tag','Strongpolygon')); delete(findobj(gcbf,'Tag','Bpolygon2')); set(stronghandle,'String','Strong Convex Hull') set(stronghandle,'Callback','convexprop(''strong'')') end