You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: tess_bem.m
    path of file: ./repos/brainstorm3/toolbox/anatomy
    
    the code of the file until where you have to start completion: function isOk = tess_bem(iSubject, BemOptions, DEBUG)
% TESS_BEM: Reconstruct 3 layers of BEM surfaces based on cortex+scalp envelopes
%
% USAGE:  tess_bem(iSubject, BemOptions)
%         tess_bem(iSubject)
%
% INPUTS: 
%    - iSubject  : Indice of the subject to process in database
%    - BemOptions: Options structure, with the following fields
%        |- nvert     : [nScalp, nOuterskull, nInnerskull] Number of vertices for each layer
%        |- thickness : [tScalp, tOuterskull, tInnerskull] Relative thickness of each layer
%                      => Values are scaled to the size of the brain/head distance
%
% DESCRIPTION:
%    - Inner skull: 1) Compute the cortex convex envelope for both the subject's and the default anatomies
%                   2) Compute the transformation cortex envelope -> inner skull for the default anatomy
%                   3) Apply the same transformation to the subject's cortex envelope
%                   4) Make sure the distance between the cortex and the inner skull is around 4mm 
%    - Outer skull: Dilatation of 5mm of the inner skull surface
%    - Skin : Re-create the head mask and tesselate its edge

% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
% 
% Copyright (c) University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3

    
function isOk = tess_bem(iSubject, BemOptions, DEBUG)
% TESS_BEM: Reconstruct 3 layers of BEM surfaces based on cortex+scalp envelopes
%
% USAGE:  tess_bem(iSubject, BemOptions)
%         tess_bem(iSubject)
%
% INPUTS: 
%    - iSubject  : Indice of the subject to process in database
%    - BemOptions: Options structure, with the following fields
%        |- nvert     : [nScalp, nOuterskull, nInnerskull] Number of vertices for each layer
%        |- thickness : [tScalp, tOuterskull, tInnerskull] Relative thickness of each layer
%                      => Values are scaled to the size of the brain/head distance
%
% DESCRIPTION:
%    - Inner skull: 1) Compute the cortex convex envelope for both the subject's and the default anatomies
%                   2) Compute the transformation cortex envelope -> inner skull for the default anatomy
%                   3) Apply the same transformation to the subject's cortex envelope
%                   4) Make sure the distance between the cortex and the inner skull is around 4mm 
%    - Outer skull: Dilatation of 5mm of the inner skull surface
%    - Skin : Re-create the head mask and tesselate its edge

% @=============================================================================
% This function is part of the Brainstorm software:
% https://neuroimage.usc.edu/brainstorm
% 
% Copyright (c) University of Southern California & McGill University
% This software is distributed under the terms of the GNU General Public License
% as published by the Free Software Foundation. Further details on the GPLv3
% license can be found at http://www.gnu.org/copyleft/gpl.html.
% 
% FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE
% UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY
% WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
% MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY
% LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE.
%
% For more information type "brainstorm license" at command prompt.
% =============================================================================@
%
% Authors: Francois Tadel, 2011-2012

%% ===== PARSE INPUTS =====
isOk = 0;
if (nargin < 2) || isempty(BemOptions)
    % Ask options to the user
    BemOptions = gui_show_dialog('BEM surfaces options', @panel_bem);
    if isempty(BemOptions)
        return;
    end