Home > bioelectromagnetism > eeg_plot_surf.m

eeg_plot_surf

PURPOSE ^

eeg_plot_surf - Plot a patch surface with voltage colourmap

SYNOPSIS ^

function[p] = eeg_plot_surf(p)

DESCRIPTION ^

 eeg_plot_surf - Plot a patch surface with voltage colourmap
 
[p] = eeg_plot_surf(p)
 
 fields of p struct used:
   
   p.rangeMethod   - initialised by eeg_toolbox_defaults
   p.colorMap.map  - initialised by eeg_toolbox_defaults
   
   p.volt.sampleTime
   p.mesh.data.vertices{p.mesh.current}
   p.mesh.data.faces{p.mesh.current}
   p.mesh.data.timeseries{p.mesh.current}

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function[p] = eeg_plot_surf(p)
0002 
0003 % eeg_plot_surf - Plot a patch surface with voltage colourmap
0004 %
0005 %[p] = eeg_plot_surf(p)
0006 %
0007 % fields of p struct used:
0008 %
0009 %   p.rangeMethod   - initialised by eeg_toolbox_defaults
0010 %   p.colorMap.map  - initialised by eeg_toolbox_defaults
0011 %
0012 %   p.volt.sampleTime
0013 %   p.mesh.data.vertices{p.mesh.current}
0014 %   p.mesh.data.faces{p.mesh.current}
0015 %   p.mesh.data.timeseries{p.mesh.current}
0016 %
0017 
0018 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:33 $
0019 
0020 % Licence:  GNU GPL, no express or implied warranties
0021 % History:  10/2002, Darren.Weber_at_radiology.ucsf.edu
0022 %
0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0024 
0025 fprintf('\nEEG_PLOT_SURF...\n'); tic;
0026 
0027 
0028 % confirm that a patch surface is available
0029 if isfield(p,'mesh'),
0030   if isfield(p.mesh,'data'),
0031     if isfield(p.mesh.data,'timeseries'),
0032       if isempty(p.mesh.data.Cdata{p.mesh.current}),
0033         msg = sprintf('...p.mesh.data.Cdata{%d} is empty\n',p.mesh.current);
0034         error(msg);
0035       end
0036     end
0037   end
0038 else
0039   error('...p.mesh.data is empty - load mesh first\n');
0040 end
0041 
0042 
0043 
0044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0045 % Determine/validate the min, max surface color data range
0046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0047 
0048 % Select mesh timeseries values at samplePoint
0049 switch p.mesh.data.meshtype{p.mesh.current},
0050   case {'scalp','elec'},
0051     samplePoint = p.volt.samplePoint;
0052     sampleTime  = p.volt.sampleTime;
0053   otherwise
0054     samplePoint = p.mesh.samplePoint;
0055     sampleTime  = p.mesh.sampleTime;
0056 end
0057 
0058 % get number of vertices
0059 nvert = size(p.mesh.data.vertices{p.mesh.current},1);
0060 % Assume more vertices than time points
0061 [s1,s2] = size(p.mesh.data.Cdata{p.mesh.current});
0062 if isequal(nvert,s1), % vertices in rows, timepoints in columns
0063   meshCdata = p.mesh.data.Cdata{p.mesh.current}(:,samplePoint);
0064 else,                 % vertices in columns, timeseries in rows
0065   meshCdata = p.mesh.data.Cdata{p.mesh.current}(samplePoint,:)';
0066 end
0067 
0068 % Use absolute values for cortical surfaces
0069 switch p.mesh.data.meshtype{p.mesh.current},
0070   case {'scalp','elec'},
0071   otherwise
0072     meshCdata = abs(meshCdata);
0073 end
0074 
0075 
0076 switch p.rangeMethod
0077   case 'minmaxall', % Min/Max,all points
0078     fprintf('...estimating color data range, min/max all time points.\n');
0079     p.maximumIntensity = max(max(p.mesh.data.Cdata{p.mesh.current}));
0080     p.minimumIntensity = min(min(p.mesh.data.Cdata{p.mesh.current}));
0081   case 'minmaxone', % Min/Max, single point
0082     fprintf('...estimating color data range, min/max single time point.\n');
0083     % get number of vertices
0084     p.maximumIntensity = max(max(meshCdata));
0085     p.minimumIntensity = min(min(meshCdata));
0086   case 'minmaxabs', % Min/Max, Absolute
0087     fprintf('...estimating color data range, abs min/max single time point.\n');
0088     absmax = max(max(abs(meshCdata)));
0089     p.maximumIntensity =  absmax;
0090     p.minimumIntensity = -absmax;
0091   otherwise
0092     % check that specified intensity range is defined
0093     fprintf('...checking predefined color data range.\n');
0094     if isempty(p.maximumIntensity),
0095       fprintf('...estimating color data range, min/max single time point.\n');
0096       p.maximumIntensity = max(max(meshCdata)); end
0097     if isempty(p.minimumIntensity),
0098       fprintf('...estimating color data range, min/max single time point.\n');
0099       p.minimumIntensity = min(min(meshCdata)); end
0100 end
0101 
0102 
0103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0104 % Plot the surface patch
0105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0106 
0107 
0108 fprintf('...plotting the surface.\n');
0109 
0110 
0111 % Set the window title name
0112 if sampleTime,
0113   if p.volt.data,
0114     data = sprintf('%s %s',p.volt.file,p.mesh.data.meshtype{p.mesh.current});
0115     name = sprintf('Surface: %s @ %8.2f msec',data, sampleTime);
0116   else
0117     data = sprintf('%s',p.mesh.data.meshtype{p.mesh.current});
0118     name = sprintf('Surface: %s @ %8.2f msec',data, sampleTime);
0119   end
0120 else
0121   if p.volt.data,
0122     data = sprintf('%s %s',p.volt.file,p.mesh.data.meshtype{p.mesh.current});
0123     name = sprintf('Surface: %s',data);
0124   else
0125     data = sprintf('%s',p.mesh.data.meshtype{p.mesh.current});
0126     name = sprintf('Surface: %s',data);
0127   end
0128 end
0129 
0130 
0131 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0132 % Plot it
0133 
0134 % create the figure window
0135 H.gui = figure('NumberTitle','off','Name',name,'color',[0 0 0]);
0136 
0137 % Create the patch
0138 p.mesh.patch = patch('vertices',p.mesh.data.vertices{p.mesh.current},...
0139   'faces',p.mesh.data.faces{p.mesh.current},...
0140   'facevertexCdata',meshCdata,...
0141   'facecolor','interp','EdgeColor','none',...
0142   'FaceLighting','phong');
0143 
0144 %data = interp3(Vscalp,3,'cubic');
0145 %isonormals(Vscalp,p.mesh.patch)
0146 
0147 set(gca,'Projection','perspective')
0148 set(gca,'DataAspectRatio',[1 1 1]);
0149 axis off tight vis3d
0150 
0151 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0152 % Lighting
0153 
0154 lighting phong
0155 set(H.gui,'RendererMode','auto')
0156 
0157 % Create a light above the z axis
0158 %H.light = light('style','infinite','position',[0 0 10000]);
0159 
0160 H.light(1) = camlight(-20, 30,'infinite');
0161 H.light(2) = camlight( 20, 30,'infinite');
0162 H.light(3) = camlight(-20,-30,'infinite');
0163 for i = 1:length(H.light),
0164   % mute the intensity of the lights
0165   set(H.light(i),'color',[.8 1 1]/length(H.light)/1.2);
0166 end
0167 
0168 
0169 
0170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0171 % Colormap
0172 
0173 meshtype = lower(p.mesh.data.meshtype{p.mesh.current});
0174 switch meshtype,
0175   case 'scalp',
0176     set(gca,'AmbientLightColor',[.9 .8 .7]);  % skin color
0177     colormap(p.colorMap.map);
0178   case {'cortex','pial','white','smoothwm','orig'},
0179     % Ambient, Diffusion, Specular, spec exp, spec reflect (see material)
0180     %MaterialBack =   [0.5 0.7 0.3 10 1]; % qualities of the background image
0181     %MaterialSource = [0.8 0.7 0.8 20 1]; % qualities for the data
0182     
0183     if exist('bluehot'),
0184       p.colorMap.map = grayish(bluehot(128),.33); % brainstorm cmap
0185       p.colorMap.map = grayish(hot(128),.33); % brainstorm cmap
0186       p.colorMap.map = hot(128);
0187       colormap(p.colorMap.map);
0188     else
0189       set(gca,'AmbientLightColor',[.6 .6 .6]);  % grey color
0190       colormap(p.colorMap.map);
0191     end
0192     
0193   otherwise
0194     set(gca,'AmbientLightColor',[.9 .9 .9]);  % white light
0195 end
0196 
0197 caxis([p.minimumIntensity p.maximumIntensity]);
0198 colorbar
0199 
0200 
0201 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0202 % Surface Properties
0203 
0204 p.reflect{1} = 0.9;
0205 p.reflect{2} = 0.2;
0206 p.reflect{3} = 0.0;
0207 p.reflect{4} = 500;
0208 p.reflect{5} = 0;
0209 set(p.mesh.patch,'AmbientStrength',p.reflect{1});
0210 set(p.mesh.patch,'DiffuseStrength',p.reflect{2});
0211 set(p.mesh.patch,'SpecularStrength',p.reflect{3});
0212 set(p.mesh.patch,'SpecularExponent',p.reflect{4});
0213 set(p.mesh.patch,'SpecularColorReflectance',p.reflect{5});
0214 
0215 
0216 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0217 % Surface Contours
0218 
0219 if (p.contour.plot3D == 1),
0220  [p] = eeg_plot_surf_contours(p);
0221 end
0222 
0223 
0224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0225 % Additional controls
0226 
0227 H.p = p;
0228 
0229 set(H.gui,'userdata',H);
0230 set(gca,'Visible','off');
0231 
0232 if isequal(exist('mouse_rotate'),2),
0233   mouse_rotate('init',H);
0234 else
0235   rotate3d on;
0236 end
0237 if isequal(exist('gui_topo_animate'),2),
0238   gui_topo_animate('init',p);
0239 end
0240 
0241 
0242 t = toc;
0243 fprintf('...done (%6.2f sec).\n\n',t);
0244 
0245 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003