0001 function job_view_cortex_plot( key )
0002
0003
0004
0005
0006
0007
0008
0009
0010 H = get( gcf, 'UserData' );
0011
0012 brain = get( H.braindata, 'UserData' );
0013 act = get( H.actdata, 'UserData' );
0014 area = get( H.areadata, 'UserData' );
0015 selection = get( H.selectdata, 'UserData' );
0016 param = get( H.paramdata, 'UserData' );
0017
0018
0019 case 'original'
0020 V = brain.V;
0021 case 'inflate'
0022 V = brain.Vinflate;
0023 end
0024
0025
0026 case 'L'
0027 F = brain.F.F3L;
0028 case 'R'
0029 F = brain.F.F3R;
0030 case 'LR'
0031 F = brain.F.F3;
0032 end
0033
0034
0035 if isempty(area.masking)
0036 mask = [1:length(brain.V)];
0037 else
0038 mask = unique( [ area.source(area.masking).Vi ] );
0039 end
0040
0041
0042 switch key
0043
0044 case 'brain'
0045 cla;
0046 job_view_cortex_plot_brain_model( V, F, brain.S, mask, param );
0047 job_view_cortex_plot_brain_act_area( V, F, brain.Va, act, area,...
0048 mask, param, key );
0049 job_view_cortex_plot_brain_selected( V, F, selection.Vi, mask, param );
0050 selected = get( H.activation_plotted_list, 'Value' );
0051 job_view_cortex_plot_brain_act_highlight( act, param,...
0052 act.plotted( selected ) );
0053 selected = get( H.area_plotted_list, 'Value' );
0054 job_view_cortex_plot_brain_area_highlight( V, F, area, mask, param,...
0055 area.plotted( selected ) );
0056 alpha(1.0);
0057
0058 case { 'act', 'area' }
0059 job_view_cortex_plot_brain_act_area( V, F, brain.Va, act, area,...
0060 mask, param, key );
0061 job_view_cortex_plot_brain_selected( V, F, selection.Vi, mask, param );
0062 selected = get( H.activation_plotted_list, 'Value' );
0063 job_view_cortex_plot_brain_act_highlight( act, param,...
0064 act.plotted( selected ) );
0065 selected = get( H.area_plotted_list, 'Value' );
0066 job_view_cortex_plot_brain_area_highlight( V, F, area, mask, param,...
0067 area.plotted( selected ) );
0068 alpha(1.0);
0069
0070 case 'selection'
0071 job_view_cortex_plot_brain_selected( V, F, selection.Vi, mask, param );
0072 selected = get( H.activation_plotted_list, 'Value' );
0073 job_view_cortex_plot_brain_act_highlight( act, param,...
0074 act.plotted( selected ) );
0075 selected = get( H.area_plotted_list, 'Value' );
0076 job_view_cortex_plot_brain_area_highlight( V, F, area, mask, param,...
0077 area.plotted( selected ) );
0078
0079 case 'highlight act'
0080 selected = get( H.activation_plotted_list, 'Value' );
0081 job_view_cortex_plot_brain_act_highlight( act,...
0082 param, act.plotted( selected ) );
0083
0084 case 'highlight area'
0085 selected = get( H.area_plotted_list, 'Value' );
0086 job_view_cortex_plot_brain_area_highlight( V, F, area, mask, param,...
0087 area.plotted( selected ) );
0088
0089 end
0090
0091 material dull;
0092 lighting phong;
0093
0094
0095
0096
0097
0098
0099
0100
0101 function job_view_cortex_plot_brain_model( V, F, S, mask, param )
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115 switch param.model_type
0116 case 'original'
0117 Vshrink = vb_shrink_cortex_for_plot(V, FF);
0118 patch( 'Faces', FF, 'Vertices', Vshrink, 'FaceColor', param.brain_color,...
0119 'EdgeColor', 'none', 'Tag', 'brain', 'Clipping', 'off' );
0120 case 'inflate'
0121 switch param.sulcus_visibility
0122 case 'visible'
0123 colors = ( ones(length(V),1) - S' ) * param.brain_color...
0124 + S' * param.sulcus_color;
0125 Vshrink = vb_shrink_cortex_for_plot(V, FF, true);
0126 patch( 'Faces', FF, 'Vertices', Vshrink, 'FaceColor', 'interp',...
0127 'EdgeColor', 'none', 'FaceVertexCData', colors,...
0128 'Tag', 'brain', 'Clipping', 'off' );
0129 case 'invisible'
0130 patch( 'Faces', FF, 'Vertices', V, 'FaceColor', param.brain_color,...
0131 'EdgeColor', 'none', 'Tag', 'brain', 'Clipping', 'off' );
0132 end
0133 end
0134
0135 switch param.lighting
0136 case 'on'
0137 h = camlight(0, 0);
0138 set(h, 'UserData', 'light1');
0139 h2 = camlight(0, 180);
0140 set(h2, 'UserData', 'light2');
0141 end
0142
0143
0144
0145
0146
0147
0148 function job_view_cortex_plot_brain_act_area( V, F, Va, act, area, mask, param, key )
0149
0150
0151
0152
0153 switch param.act_area_priority
0154 case 'activation'
0155 switch key
0156 case 'act'
0157 job_view_cortex_plot_brain_activation( V, F, Va, act, mask, param );
0158 case { 'brain', 'area' }
0159 job_view_cortex_plot_brain_area( V, F, area, mask, param );
0160 job_view_cortex_plot_brain_activation( V, F, Va, act, mask, param );
0161 end
0162 case 'area'
0163 switch key
0164 case { 'brain', 'act' }
0165 job_view_cortex_plot_brain_area( V, F, area, mask, param );
0166 job_view_cortex_plot_brain_activation( V, F, Va, act, mask, param );
0167 case 'area'
0168 job_view_cortex_plot_brain_area( V, F, area, mask, param );
0169 end
0170 end
0171
0172
0173
0174
0175
0176
0177 function job_view_cortex_plot_brain_activation( V, F, Va, act, mask, param )
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211 delete( findobj( gca, 'Tag', 'act' ) );
0212
0213 if isempty( act.plotted ); return; end;
0214
0215
0216 switch param.act_relative_mode
0217 case 'each'
0218 Jabsmax = max( abs( [ act.source(act.plotted).J ] ) );
0219 case 'all'
0220 Jabsmax = max( abs( [ act.source(act.candidate).J ] ) );
0221 end
0222
0223
0224
0225 J = act.source(id).J;
0226
0227
0228 switch param.act_normalize
0229 case 'meshsize'
0230 J = J ./ Va;
0231 end
0232
0233
0234
0235
0236 case 'absolute'
0237 ind = intersect( ind, find( abs(J) >= param.act_min ) );
0238 case 'relative'
0239 ind = intersect( ind, find( abs(J) >= Jabsmax * param.act_min ) );
0240 end
0241
0242
0243 switch param.act_colormap_max_mode
0244 case 'absolute'
0245 cmax = param.act_colormap_max;
0246 case 'relative'
0247 cmax = Jabsmax * param.act_colormap_max;
0248 end
0249
0250 switch param.act_colormap_type
0251 case 'hot'
0252 colormap(hot);
0253 case 'jet'
0254 colormap(jet);
0255 end
0256
0257
0258 switch param.act_sign_mode
0259 case 'signed'
0260 caxis( [ -cmax cmax ] );
0261 case 'unsigned'
0262 J = abs(J);
0263 caxis( [ 0 cmax ] );
0264 end
0265
0266
0267 switch param.paint
0268 case 'dot'
0269 tmp = scatter3( V(ind,1), V(ind,2), V(ind,3), 1, J(ind), '.', 'filled' );
0270 set( tmp, 'MarkerSize', param.markersize, 'Tag', 'act', 'UserData', id,...
0271 'HitTest', 'off', 'Clipping', 'off' );
0272 case 'patch'
0273 FF = vb_patch_select2(ind,F,length(V));
0274 patch( 'Faces', FF, 'Vertices', V, 'FaceColor', 'interp',...
0275 'FaceVertexCData', J', 'EdgeColor', 'none', 'FaceAlpha', 0.99,...
0276 'Tag', 'act', 'UserData', id, 'HitTest', 'off', 'Clipping', 'off' );
0277 alpha(findobj( gca, 'Tag', 'brain' ), 0.99);
0278 end
0279
0280 end
0281
0282
0283
0284
0285
0286
0287
0288 function job_view_cortex_plot_brain_area( V, F, area, mask, param )
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299 delete( findobj( gca, 'Tag', 'area' ) );
0300
0301 if isempty( area.plotted ); return; end;
0302
0303 area_colors = [ 1 0 0; 0 1 0; 0 0 1; 1 1 0; 1 0 1; 0 1 1;
0304 1 1 0.5; 0.5 0 0; 0 0.5 1; 0.5 1 0; 1 0.5 1; 0 0 0.5;
0305 1 0.5 0; 0 1 0.5; 0.5 0 1; 0 0.5 0; 0.5 1 1; 1 0 0.5;
0306 1 0.5 0.5; 0 0.5 0.5; 0.5 1 0.5;
0307 0.5 0 0.5; 0.5 0.5 1; 0.5 0.5 0 ];
0308
0309 for id = area.plotted
0310
0311 ind = intersect( area.source(id).Vi, mask );
0312
0313
0314 ind = intersect( ind, unique(F) );
0315
0316 if isfield(area.source(id), 'color')
0317 color = area.source(id).color;
0318 else
0319 color = area_colors(1+mod(id-1,length(area_colors)),:);
0320 end
0321
0322
0323 case 'dot'
0324 plot3( V(ind,1), V(ind,2), V(ind,3), '.',...
0325 'MarkerFaceColor', color, 'MarkerEdgeColor', color,...
0326 'MarkerSize', param.markersize, 'Tag', 'area', 'UserData', id,...
0327 'HitTest', 'off', 'Clipping', 'off' );
0328 case 'patch'
0329 FF = vb_patch_select2( ind, F, length(V) );
0330 patch( 'Faces', FF, 'Vertices', V,...
0331 'FaceColor', color, 'EdgeColor', 'none', 'FaceLighting', 'none',...
0332 'FaceAlpha', param.area_alpha, 'Tag', 'area', 'UserData', id,...
0333 'HitTest', 'off', 'Clipping', 'off' );
0334 alpha(findobj( gca, 'Tag', 'brain' ), 0.99);
0335 end
0336
0337
0338
0339 end
0340
0341
0342
0343
0344
0345
0346 function job_view_cortex_plot_brain_act_highlight( act, param, selected )
0347
0348
0349
0350
0351
0352
0353
0354 if isempty( selected ); return; end;
0355 if strcmp( param.act_show_highlight, 'off' ); return; end;
0356
0357 for id = act.plotted
0358 if ismember( id, selected )
0359 set( findobj( gca, 'Tag', 'act', 'UserData', id ), 'FaceAlpha', 0.99 );
0360 else
0361 set( findobj( gca, 'Tag', 'act', 'UserData', id ),...
0362 'FaceAlpha', param.act_non_highlight_alpha );
0363 end
0364 end
0365
0366
0367 function job_view_cortex_plot_brain_area_highlight( V, F, area, mask,...
0368 param, selected )
0369
0370
0371
0372
0373
0374 delete( findobj( 'Tag', 'area_highlight' ) );
0375
0376 if isempty( area.plotted ) | isempty( selected ); return; end;
0377 if strcmp( param.area_show_highlight, 'off' ); return; end;
0378
0379 Vx = V(:,1); Vy = V(:,2); Vz = V(:,3);
0380
0381 for id = selected
0382
0383 Vi = intersect( area.source(id).Vi, mask );
0384 FF = vb_patch_select2( Vi, F, length(V) );
0385 FL = [ FF(:,1), FF(:,2); FF(:,2), FF(:,3); FF(:,3), FF(:,1) ];
0386 FL_inv = [ FL(:,2), FL(:,1) ];
0387 FL = setdiff( FL, FL_inv, 'rows' );
0388 [ FL_unq, I, J ] = unique( FL, 'rows' );
0389 edge = setdiff( FL_unq, FL( setdiff( [1:size(FL,1)], I ), : ), 'rows' );
0390
0391
0392
0393
0394
0395
0396
0397
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426 line( Vx(edge'), Vy(edge'), Vz(edge'), 'Color', [0.3,0.3,0.3],...
0427 'Tag', 'area_highlight', 'UserData', id );
0428 end
0429
0430
0431
0432
0433
0434
0435
0436
0437 function job_view_cortex_plot_brain_selected( V, F, Vi, mask, param )
0438
0439
0440
0441
0442
0443
0444
0445 delete( findobj( gca, 'Tag', 'selected' ) );
0446
0447 if isempty( Vi )
0448 return;
0449 end
0450
0451 ind = intersect( Vi, mask );
0452
0453
0454 Vi = intersect( ind, unique(F) );
0455
0456 color = param.selection_color;
0457
0458
0459 plot3( V(Vi,1), V(Vi,2), V(Vi,3), '.',...
0460 'MarkerFaceColor', color, 'MarkerEdgeColor', color,...
0461 'MarkerSize', param.markersize, 'Tag', 'selected',...
0462 'HitTest', 'off', 'CLipping', 'off' );
0463 else
0464 FF = vb_patch_select2( ind, F, length(V) );
0465 patch( 'Faces', FF, 'Vertices', V,...
0466 'FaceColor', color, 'EdgeColor', 'none', 'FaceAlpha', 0.99,...
0467 'Tag', 'selected', 'HitTest', 'off', 'Clipping', 'off' );
0468 end
0469
0470
0471
0472
0473
0474
0475 function Fnew = vb_patch_select2(Vix,F,Nvertex)
0476 Itrans = zeros(Nvertex,1);
0477 Itrans(Vix) = 1;
0478 Fnew = Itrans(F);
0479 ix = find(sum(Fnew,2));
0480 Fnew = F(ix,:);