Surface Scouts Definition

Dear Brainstorm developers and users,

I have two quite technical questions about how to draw surface scouts directly with Matlab. I'm defining multiple scouts for each patient and would like to plot them directly on the cortex without having to import them into brainstorm first. I found a very easy way to do it, if I have volume scouts (taking a cue from https://github.com/brainstorm-tools/brainstorm3/blob/master/toolbox/gui/panel_scout.m#L4371, with the following commands:

Coord=volume.GridLoc(scout.Vertices,:);
Faces_boundary = boundary(Coord, 0.7);
hold on
trisurf(Faces_boundary,Coord(:,1),Coord(:,2),Coord(:,3),'Facecolor','blue')

by first opening a window with the cortex surface from brainstorm.

I would like to do the same with surface scouts but I have seen that the procedure is more complex since a preventive expansion is needed to not have scouts inside the cortex. May I ask what are the essential command lines to use to create a surface scout starting from its coordinates?
The second question concerns the command to add multiple vertices to a scout (at the bottom of the scout panel). What methodology is used to choose the vertices to add?

All my best,
Margherita

Hi Margherita,

You can do it with the script below. As with your lines of code, first open a figure with the cortex surface from Brainstorm.

% Scout vertices
sScout.Vertices = [1932,1933,1977,2073,2127,2166];

% Get Surface definition
TessInfo = getappdata(gcf, 'Surface'); % Consider only current figure
sSurface = TessInfo(1);                % Consider only first surface
% Get Surface vertices
[Vertices, Faces, VertexNormals, iVisibleVert] = panel_surface('GetSurfaceVertices', sSurface.hPatch, 0);
% Get visible scouts vertices
iScoutVert = intersect(sScout.Vertices, iVisibleVert);
% Expand slightly to avoid the exact overlap of the vertices
patchVertices = panel_scout('GetScoutPosition', Vertices, VertexNormals, iScoutVert, 0.0002);
% Get all the full faces in the scout patch
vertMask = false(length(Vertices),1);
vertMask(iScoutVert) = true;
% This syntax is faster but equivalent to: 
% patchFaces = Faces(all(vertMask(Faces),2),:);
iFacesTmp = find(vertMask(Faces(:,1)));
iFacesTmp = iFacesTmp(vertMask(Faces(iFacesTmp,2)));
iFacesTmp = iFacesTmp(vertMask(Faces(iFacesTmp,3)));
patchFaces = Faces(iFacesTmp,:);
% patchFaces as Scout vertices
[~, patchFaces] = ismember(patchFaces, iScoutVert);

% Plot
hold on
trisurf(patchFaces, patchVertices(:,1), patchVertices(:,2), patchVertices(:,3), 'Facecolor', 'blue')

Best,
Raymundo

[>]: Add the closest vertex (with respect to the seed) to the current scout.
[>>]: Grow scout in all directions. (Enlarge a scout by adding the next set of adjacent vertices)