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