⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eeg_contours_engine.m

📁 Matlab下的EEG处理程序库
💻 M
📖 第 1 页 / 共 2 页
字号:
            colorbar
            
            H.p = p;
            H.p.mesh.plotSurf = 0;
            set(H.gui,'userdata',H);
            
            SaveGraphics(H.gui,'_3Delec_',p);
            if isequal(exist('mouse_rotate'),2),
                mouse_rotate;
            else
                rotate3D;
            end
            if isequal(exist('gui_topo_animate'),2),
                gui_topo_animate('init',p);
            end
        end
        
        
        % Plot a mesh surface
        
        if p.mesh.plotSurf,
            
            [p.mesh.current,meshExists] = mesh_check(p,'scalp');
            
            p = eeg_plot_surf(p);
            
            return
        end
    end
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Contour in 2-D
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %CONTOUR(Z,N) and CONTOUR(X,Y,Z,N) draw N contour lines, 
    %overriding the automatic value.
    %CONTOUR(Z,V) and CONTOUR(X,Y,Z,V) draw LENGTH(V) contour lines 
    %at the values specified in vector V. 
    
    if isequal(p.contour.raw2D,1),
        
        if ~isequal(p.volt.sampleTime,0),
            name = sprintf('2-D Contour: %s @ %8.2f msec',p.volt.file, p.volt.sampleTime);
        else
            name = sprintf('2-D Contour: %s',p.volt.file);
        end
        fig = figure('NumberTitle','off','Name',name); colormap(p.colorMap.map);
        set(gca,'Projection','perspective')
        %set(gca,'Projection','orthographic')
        set(gca,'DataAspectRatio',[1 1 1]);
        
        %trisurf(delaunay(Xp,Yp),Xp,Yp,Zp,V,'EdgeColor','none','FaceColor','interp');
        %hold on, plot3(Xp,Yp,Zp,'.');
        %contour(Xi,Yi,Vi, p.contour.Nsteps) %, colorbar, hold on
        
        [c,ch,cf] = contourf(Xi,Yi,Vi,p.contour.levels);
        absmax = max(max(abs(Vi)));caxis([-absmax absmax]);
        %[C,CH,CF] = CONTOURF(...) also returns a column vector CH of handles
        %to PATCH objects and the contour matrix CF for the filled areas. The
        %UserData property of each object contains the height value for each
        %contour.
        
        % FaceColor is the contour patch color
        % EdgeColor is the contour line color
        for i=1:size(ch),
            height = get(ch(i),'UserData');
            
            if     (height > 0),
                set(ch(i),'LineStyle', '-'); % options are: -, --, :, -., none
                set(ch(i),'EdgeColor',[1 1 1]) % white contour lines, black = [0 0 0] (ie, [R G B])
            elseif (height < 0),
                set(ch(i),'LineStyle', ':'); % options are: -, --, :, -., none
            else
                set(ch(i),'LineStyle', '-'); % options are: -, --, :, -., none
                set(ch(i),'LineWidth',2);
            end
        end
        
        set(gca,'Visible','off'); %hold on; DrawHead(Xrad,'black'); hold off;
        colorbar
        
        SaveGraphics(fig,'_2D_',p);
        if isequal(exist('mouse_rotate'),2),
            mouse_rotate;
        else
            rotate3D;
        end
    end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Projected Contour in 2-D
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    if isequal(p.contour.plot2D,1)
        
        % Project 3D electrode locations onto 2D plane.
        [X2p,Y2p] = elec_3d_2d(Xp,Yp,Zp,Zrad);
        m = max(abs([X2p;Y2p]));
        m = ceil(m);
        if (p.grid.method == 2)
            % Use grid resolution method
            X2g = -m:p.grid.res:m;
        else
            % Use grid size method
            X2g = linspace( -m, m, p.grid.size );
        end
        Y2g = X2g';
        [X2i Y2i V2i] = griddata(X2p,Y2p,V,X2g,Y2g,p.interpMethod);
        
        if ~isequal(p.volt.sampleTime,0),
            name = sprintf('Projected 2D Contours: %s @ %8.2f msec',p.volt.file, p.volt.sampleTime);
        else
            name = sprintf('Projected 2D Contours: %s',p.volt.file);
        end
        fig = figure('NumberTitle','off','Name',name);
        set(gca,'Projection','perspective')
        %set(gca,'Projection','orthographic')
        set(gca,'DataAspectRatio',[1 1 1]);
        
        colormap(p.colorMap.map);
    	contourf(X2i,Y2i,V2i, p.contour.Nsteps);
        absmax = max(max(abs(V2i)));caxis([-absmax absmax]);colorbar
    	xlabel('X'); ylabel('Y');
        
        SaveGraphics(fig,'_proj2D_',p);
    end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Projected Contour in 3-D
% Draw the contour lines,
%   Get the contours in 2-D.
%   For each point in each contour line, know x,y
%   Calculate z for the x,y from ellipse formula
%   Plot3 point x,y,z
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    if (p.contour.plot3D == 1)
        
        
        % Project 3-D electrode locations onto 2-D plane.
        [X2p,Y2p] = elec_3d_2d(Xp,Yp,Zp,Zrad);
        m = max(abs([X2p;Y2p]));
        m = ceil(m);
        if isequal(p.grid.method,2)
            % Use grid resolution method
            X2g = -m:p.grid.res:m;
        else
            % Use grid size method
            X2g = linspace( -m, m, p.grid.size );
        end
        Y2g = X2g';
        
        [X2i Y2i V3i] = griddata(Xp, Yp, V,X2g,Y2g,p.interpMethod);
        
        % Caculate the contour matrix
        C = contourc(X2g, Y2g, V3i, p.contour.Nsteps);
        
        if ~isequal(p.volt.sampleTime,0),
            name = sprintf('3D Contours: %s @ %8.2f msec',p.volt.file, p.volt.sampleTime);
        else
            name = sprintf('3D Contours: %s',p.volt.file);
        end
        
        %fig = figure('NumberTitle','off','Name',name);
        %set(gca,'Projection','perspective')
        %set(gca,'DataAspectRatio',[1 1 1]);
        %[C,Cpatch] = contourf(X2g, Y2g, V3i, p.contour.Nsteps);
        %get(Cpatch(1))
        %P.cdata    = get(Cpatch,'CData');
        %P.vertices = get(Cpatch,'Vertices');
        %P.faces    = get(Cpatch,'Faces');
        %close(fig);
        %fig = figure('NumberTitle','off','Name',name); hold on
        %i = 0;
        %while i < (length(Cpatch) - 1),
            %%vertices = P.vertices{i};
            %i = i + 1;
            %vertices = [P.vertices{i}; P.vertices{i+1}];
            %Xc = vertices(:,1);
            %Yc = vertices(:,2);
            %[X3,Y3,Z3] = elec_2d_3d(Xc,Yc,Xrad,Yrad,Zrad);
            %tri = delaunay(X3,Y3);
            %Htri = trisurf(tri,X3,Y3,Z3,P.cdata{i},'EdgeColor','none','FaceColor','flat');
            
            %%vertices = [X3 Y3 Z3];
            %%Hpatch = patch('Vertices',vertices,'Faces',P.faces{i},'CData',P.cdata{i},'FaceColor','flat');
            %contourValues(i) = P.cdata{i};
        %end
        
        %view(0,90), axis tight, rotate3d
        %set(gca,'Visible','off');
        %colormap(p.colorMap.map);
        %absmax = max(abs(contourValues));
        %caxis([-absmax absmax]);colorbar;
        
        
        
        
        fig = figure('NumberTitle','off','Name',name); hold on
        set(gca,'Projection','perspective')
        %set(gca,'Projection','orthographic')
        set(gca,'DataAspectRatio',[1 1 1]);
        
        % When we view the contour lines, those on the other side of
        % the head can be seen, which makes it confusing.
        
        % The array C is 2-row, x on 1st, y on 2nd.
        % Each contour set has a preceeding column, where
        % 1st is value of contour and 2nd is number of points.
        %
        % We need to get each contour separately, and calculate
        % Z for each X,Y.
        i = 1; j = 0;
        limit = size(C,2);
        while (i < limit),
            
            j = j + 1; contourValues(j) = C(1,i);
            
        	numberPoints = C(2,i);
            
        	endContourSet = i + numberPoints;
            
        	Xc = [ C(1,i+1:endContourSet) ]';
        	Yc = [ C(2,i+1:endContourSet) ]';
            
        	%cdata = contourValues(j) + 0*Xc;  % Make cdata the same size as xdata

        	% Given each X,Y we project back from 2D to 3D.
        	[X3,Y3,Z3] = elec_2d_3d(Xc,Yc,Xrad,Yrad,Zrad);
            
        	if (contourValues(j) < 0)
        		% Values < 0 with dashed black line
        		if isequal(p.colorMap.style,'Gray')
        			line(X3,Y3,Z3,'LineStyle',':','LineWidth',0.5,'Color','black');
        		else
        			line(X3,Y3,Z3,'LineStyle',':','LineWidth',0.5,'Color','blue');
        		end
            elseif (contourValues(j) > 0)
        		% Values > 0 with solid black line
        		if isequal(p.colorMap.style,'Gray')
        			line(X3,Y3,Z3,'LineStyle','-','LineWidth',0.5,'Color','black');
        		else
        			line(X3,Y3,Z3,'LineStyle','-','LineWidth',0.5,'Color','red');
        		end
            else
        		% Values = 0 with thicker solid black line
     			line(X3,Y3,Z3,'LineStyle','-','LineWidth',0.75,'Color','black');
        	end
        	i = endContourSet + 1;
        end

        view(0,90), axis tight, rotate3d
        set(gca,'Visible','off');
        %colormap(p.colorMap.map); H = colorbar;
        %absmax = max(abs(contourValues));
        
        SaveGraphics(fig,'_3D_',p);
    end

return    



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function DrawHead(Hradius, Hcolor)
    
    switch Hcolor
    case 'black'
        HCOLOR = [0 0 0];
    case 'white'
        HCOLOR = [1 1 1];
    otherwise
        HCOLOR = [0 0 0];
    end
	HLINEWIDTH = 30;
    
    rmax = 0.95 * Hradius;
    
	% Plot Head
    
    theta1 = linspace(0,2*pi,50);       % 360 degree rotation
    thetad = (theta1(2) - theta1(1))/2; % provide staggered rotation
    theta = [theta1, theta1 + thetad];
    
	plot(cos(theta).*rmax,sin(theta).*rmax,'color',HCOLOR,'LineWidth',HLINEWIDTH);
    
	% Plot Nose
    width = rmax * 0.1;
    tip   = rmax * 1.075;
    base  = rmax * 1.005;
    
	plot([width;0;-width],[rmax;tip;rmax],'Color',HCOLOR,'LineWidth',HLINEWIDTH);
return

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function SaveGraphics(F,type,p)
    if ~isequal(p.saveGraphics,'No Save Plots'),
        
        [path,file,ext] = fileparts(strcat(p.volt.path, filesep, p.volt.file));
        file = strcat(file, type, num2str(p.volt.samplePoint),'.',p.saveGraphics);
        file = fullfile(path,file);
        saveas(F,file);
    end
return

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -