0001 function [p] = mesh_plot(p),
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 if ~exist('p','var'),[p] = eeg_toolbox_defaults; end
0038
0039 if isfield(p,'mesh'),
0040 if isfield(p.mesh,'data'),
0041 if isempty(p.mesh.data),
0042 [p] = gui_mesh_open(p);
0043 return;
0044 end
0045 else
0046 [p] = gui_mesh_open(p);
0047 end
0048 else
0049 [p] = gui_mesh_open(p);
0050 return;
0051 end
0052
0053 if isfield(p,'mesh'),
0054 if isfield(p.mesh,'current'),
0055 if isempty(p.mesh.current),
0056 p.mesh.current = 1;
0057 end
0058 else
0059 p.mesh.current = 1;
0060 end
0061 else
0062 msg = sprintf('No mesh field in p struct.\n');
0063 error(msg);
0064 end
0065
0066
0067
0068
0069 if strmatch('scalp',p.mesh.data.meshtype{p.mesh.current}) > 0,
0070 if ~isempty(p.elec.data),
0071 [p] = mesh_fit_elec(p);
0072 p.mesh.current = mesh_check(p,'scalp');
0073 end
0074 end
0075
0076
0077
0078
0079 vertices = p.mesh.data.vertices{p.mesh.current};
0080 faces = p.mesh.data.faces{p.mesh.current};
0081
0082 if isempty(vertices),
0083 fprintf('...p.mesh.current points to an empty cell\n');
0084 return
0085 end
0086
0087
0088
0089 if isfield(p.mesh.plot,'fig'),
0090 figure(p.mesh.plot.fig);
0091 else
0092 p.mesh.plot.fig = figure;
0093 end
0094
0095 set(gcf,'color',[0 0 0]);
0096
0097 set(gca,'Projection','perspective')
0098
0099 set(gca,'DataAspectRatio',[1 1 1]);
0100
0101
0102
0103
0104 if isfield(p.mesh.plot,'Hpatch'),
0105 if p.mesh.plot.overlay,
0106
0107 hold on;
0108 else
0109
0110 hold off;
0111
0112 for i = 1:length(p.mesh.plot.Hpatch),
0113 if ishandle(p.mesh.plot.Hpatch{i}),
0114 delete(p.mesh.plot.Hpatch{i});
0115 end
0116 end
0117 p.mesh.plot.Hpatch = cell(0);
0118 end
0119 end
0120 p.mesh.plot.Hpatch{p.mesh.current} = patch('Vertices',vertices,'Faces',faces);
0121
0122
0123
0124
0125
0126 axis off tight vis3d
0127
0128
0129 set(gcf,'Renderer','opengl'); lighting phong
0130
0131
0132 if isfield(p.mesh.plot,'Hlight'),
0133 for i = 1:length(p.mesh.plot.Hlight),
0134 if ishandle(p.mesh.plot.Hlight(i)),
0135 delete(p.mesh.plot.Hlight(i));
0136 end
0137 end
0138 p.mesh.plot.Hlight = [];
0139 end
0140
0141 H.light(1) = camlight( 0, 0,'local');
0142 H.light(2) = camlight(-75, 0);
0143 H.light(3) = camlight( 75, 0);
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154 p.mesh.plot.Hlight = H.light;
0155
0156
0157
0158
0159
0160 if ~isfield(p.mesh.plot,'reflect')
0161 p.mesh.plot.ambient = 0.5;
0162 p.mesh.plot.diffuse = 0.4;
0163 p.mesh.plot.specular = 0.05;
0164 p.mesh.plot.specexp = 5;
0165 p.mesh.plot.speccolor = 1;
0166 end
0167 if ~isfield(p.mesh.plot,'edgecolor'),
0168
0169 switch p.mesh.data.meshtype{p.mesh.current},
0170 case 'cortex', p.mesh.plot.edgecolor = 'none';
0171 case 'pial', p.mesh.plot.edgecolor = 'none';
0172 case 'smoothwm', p.mesh.plot.edgecolor = 'none';
0173 case 'white', p.mesh.plot.edgecolor = 'none';
0174 otherwise, p.mesh.plot.edgecolor = '.7 .7 .7';
0175 end
0176 end
0177
0178 if ~isfield(p.mesh.plot,'facecolor'),
0179 p.mesh.plot.facecolor = '.9 .8 .7';
0180 end
0181 if ~isfield(p.mesh.plot,'facealpha'),
0182 p.mesh.plot.facealpha = '1';
0183 end
0184
0185 if findstr(p.mesh.plot.edgecolor,'none'),
0186 set(p.mesh.plot.Hpatch{p.mesh.current},'EdgeColor','none');
0187 else
0188 set(p.mesh.plot.Hpatch{p.mesh.current},'EdgeColor',str2num(p.mesh.plot.edgecolor));
0189 end
0190 if findstr(p.mesh.plot.facecolor,'none'),
0191 set(p.mesh.plot.Hpatch{p.mesh.current},'FaceColor','none');
0192 else
0193 set(p.mesh.plot.Hpatch{p.mesh.current},'FaceColor',str2num(p.mesh.plot.facecolor));
0194 end
0195 if p.mesh.plot.facealpha,
0196 set(p.mesh.plot.Hpatch{p.mesh.current},'FaceAlpha',str2num(p.mesh.plot.facealpha));
0197 else
0198 set(p.mesh.plot.Hpatch{p.mesh.current},'FaceAlpha',1);
0199 end
0200 set(p.mesh.plot.Hpatch{p.mesh.current},'AmbientStrength',p.mesh.plot.ambient);
0201 set(p.mesh.plot.Hpatch{p.mesh.current},'DiffuseStrength',p.mesh.plot.diffuse);
0202 set(p.mesh.plot.Hpatch{p.mesh.current},'SpecularStrength',p.mesh.plot.specular);
0203 set(p.mesh.plot.Hpatch{p.mesh.current},'SpecularExponent',p.mesh.plot.specexp);
0204 set(p.mesh.plot.Hpatch{p.mesh.current},'SpecularColorReflectance',p.mesh.plot.speccolor);
0205
0206
0207
0208 if strmatch('scalp',p.mesh.data.meshtype{p.mesh.current}) > 0,
0209 if ~isempty(p.elec.data),
0210 [p] = elec_plot(p);
0211 end
0212 end
0213
0214
0215
0216
0217
0218 if isequal(exist('mouse_rotate'),2),
0219 userdata = get(p.mesh.plot.fig,'userdata');
0220 if isempty(userdata),
0221 mouse_rotate('init')
0222 else
0223 mouse_rotate('init',get(p.mesh.plot.fig,'userdata'));
0224 end
0225 else
0226 rotate3d;
0227 end
0228
0229
0230 if nargout < 1,[p] = []; end
0231
0232 return
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242 function[p] = elec_plot(p),
0243
0244 elecN = mesh_check(p,'elec');
0245
0246 if isempty(elecN),
0247 warning('MESH_FIT_ELEC: No ''elec'' mesh in p struct.\n');
0248 end
0249
0250
0251
0252 elecvert = p.mesh.data.vertices{elecN};
0253
0254 x = elecvert(:,1);
0255 y = elecvert(:,2);
0256 z = elecvert(:,3);
0257
0258 hold on
0259 scatter3(x,y,z,70,'b','filled');
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308 hold off
0309 return