www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgdatasetnode/private/pr_PlotSurface.m
function pr_PlotSurface(ax,lim,ef,Sx,Sy,Sd,Px,Py,Pd,SPd) % pr_PlotSurface(ax,lim,ef,Sx,Sy,Sd,Px,Py,Pd,SPd); % ef = error flag % Copyright 2000-2014 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin<7 Px = []; Py = []; Pd = []; end if nargin<10 SPd = []; end wn = warning; warning('off','all'); ch = get(ax,'Children'); delete(ch); um = get(ax,'UIContextMenu'); view =get(ax,'View'); if all(view==[0 90]) view = [-37 30]; end if ef % adjust Z lim err = Pd-SPd; diff1 = lim.Zlim(1) - min(err(:)); diff2 = lim.Zlim(2) - max(err(:)); if diff1>0 lim.Zlim = lim.Zlim - diff1; elseif diff2<0 lim.Zlim = lim.Zlim - diff2; end end builtin('set', ax , 'xlim' , lim.Xlim, 'ylim' , lim.Ylim , 'zlim',lim.Zlim,... 'xgrid','on','ygrid','on','zgrid','on',... 'view' , view,... 'camerapositionmode','auto','cameratargetmode','auto',... 'xgrid','on',... 'ygrid','on',... 'zgrid','on',... 'Box','on',... 'ztickmode','auto','zticklabelmode','auto',... 'xtickmode','auto','xticklabelmode','auto',... 'ytickmode','auto','yticklabelmode','auto'); mv_rotate3d(ax , 'ON'); % Plot surface if ef %Box around zero line('Parent',ax,'XData',[lim.Xlim lim.Xlim(2) lim.Xlim(1) lim.Xlim(1)],... 'YData',[lim.Ylim(1) lim.Ylim lim.Ylim(2) lim.Ylim(1)],... 'ZData',zeros(1,5),'Visible','on','Color','k','LineStyle','-',... 'LineWidth',2,'UIContextMenu',um); end %do the plotting %'surface' - now call delaunayn, as delaunay is just a gateway function to % delaunayn try tri = delaunayn([Sx(:),Sy(:)]); catch % On the rare occasions this fails, add a point at infinity to see if % we can get the surface to plot tri = delaunayn([Sx(:), Sy(:)], {'Qt','Qbb','Qc','Qz'}); end if ~isempty(tri) && ~ef % Do colours TestData = Sd(:); cmap = parula(64); %cmap = obj.HotMap(:,[3 1 2]); mx = max(TestData); mn = min(TestData); %Sort out the cdata stuff... n = size(cmap,1); evec = mn:((mx-mn)/n):mx; [~,bin] = histc(TestData , [-inf evec(2:end-1) inf]); bin(bin==0)=1; vert = [Sx(:) Sy(:) Sd(:)]; coldata = cmap(bin(:),:); patch('Parent',ax,... 'Faces',tri,'Vertices',vert,'FaceVertexCData',coldata,... 'EdgeColor','interp',... 'UIContextMenu',um,... 'Marker','none' , 'Visible' , 'on' , 'FaceLighting' , 'gouraud','FaceColor','interp'); end % 'points' if ~isempty(Px) col = 'm'; % work out where to draw stems if ef % Draw stems to zero Pd = Pd - SPd; Zdata = zeros(length(Pd),1); elseif ~isempty(SPd) % stemdata contains value for model/strategy evaluated at op.points Zdata = SPd; else % Draw stems down to lower z limit Zdata = repmat(lim.Zlim(1),length(Pd),1); end % nans give gaps in line xd = [Px';Px';NaN(1,length(Px))]; yd = [Py';Py';NaN(1,length(Py))]; dd = [Zdata';Pd';NaN(1,length(Pd))]; % lines line('Parent', ax,... 'XData',xd(:),'YData',yd(:),'ZData',dd(:),... 'UIContextMenu',um,... 'Visible' , 'on', ... 'LineStyle', '-', 'Marker', 'none','Color',col,... 'Tag','deletetag','LineWidth',2); % blobs line('Parent', ax,... 'XData',xd(1,:),'YData',yd(1,:),'ZData',dd(2,:),... 'UIContextMenu',um,... 'Visible' , 'on', ... 'LineStyle', 'none', 'Marker', '.','MarkerSize',20,... 'Color',col,'Tag','deletetag'); end shading(ax, 'faceted'); %shading flat; % shading faceted; % lighting gouraud; warning(wn);