mk_head_model

PURPOSE ^

MK_HEAD_MODEL FEM models of the head

SYNOPSIS ^

function out = mk_head_model(str, varargin)

DESCRIPTION ^

MK_HEAD_MODEL FEM models of the head

 MK_HEAD_MODEL provides a shorthand to predefined head FEMs and 
 for using contributed models with PLACE_ELEC_ON_SURF. You may be asked
 to download missing files. Specialized MK_HEAD_MODEL_* functions provide
 additional presets and options.

 MK_HEAD_MODEL(shapestr,elec_pos, elec_shape, maxh) where:
  shapestr    - a string specifying the underlying model.
                Run MK_HEAD_MODEL('list_shapes') for a list.
  elec_pos    - a vector specifying electrode positions.
                See PLACE_ELEC_ON_SURF for details.
  elec_shape  - a vector specifying electrode shapes.
                See PLACE_ELEC_ON_SURF for details.
  This usage returns a fwd_model structure.

 MK_HEAD_MODEL(modelstr) provides quick access to predefined models.
 Run MK_HEAD_MODEL('list') for a list. This usage returns either a 
 fwd_model or an image structure. Specialized MK_HEAD_MODEL_* functions
 provide additional presets.

 MK_HEAD_MODEL('list_shapes') lists available thorax shapes without 
  electrodes.

 MK_HEAD_MODEL('list') lists available predefined models.

 See also: MK_HEAD_MODEL_ADULT, PLACE_ELEC_ON_SURF

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function out = mk_head_model(str, varargin)
0002 %MK_HEAD_MODEL FEM models of the head
0003 %
0004 % MK_HEAD_MODEL provides a shorthand to predefined head FEMs and
0005 % for using contributed models with PLACE_ELEC_ON_SURF. You may be asked
0006 % to download missing files. Specialized MK_HEAD_MODEL_* functions provide
0007 % additional presets and options.
0008 %
0009 % MK_HEAD_MODEL(shapestr,elec_pos, elec_shape, maxh) where:
0010 %  shapestr    - a string specifying the underlying model.
0011 %                Run MK_HEAD_MODEL('list_shapes') for a list.
0012 %  elec_pos    - a vector specifying electrode positions.
0013 %                See PLACE_ELEC_ON_SURF for details.
0014 %  elec_shape  - a vector specifying electrode shapes.
0015 %                See PLACE_ELEC_ON_SURF for details.
0016 %  This usage returns a fwd_model structure.
0017 %
0018 % MK_HEAD_MODEL(modelstr) provides quick access to predefined models.
0019 % Run MK_HEAD_MODEL('list') for a list. This usage returns either a
0020 % fwd_model or an image structure. Specialized MK_HEAD_MODEL_* functions
0021 % provide additional presets.
0022 %
0023 % MK_HEAD_MODEL('list_shapes') lists available thorax shapes without
0024 %  electrodes.
0025 %
0026 % MK_HEAD_MODEL('list') lists available predefined models.
0027 %
0028 % See also: MK_HEAD_MODEL_ADULT, PLACE_ELEC_ON_SURF
0029 
0030 % (C) 2015-2024 Bartlomiej Grychtol. License: GPL version 2 or 3
0031 % $Id: mk_head_model.m 7124 2024-12-29 15:18:32Z aadler $
0032 
0033 if nargin>0 && ischar(str) 
0034    switch(str)
0035       case 'UNIT_TEST'
0036          do_unit_test; return;
0037       case 'list_shapes'
0038          out = list_basic_shapes; return;
0039       case 'list'
0040          out = list_predef_models; return;
0041    end
0042 end
0043 
0044 opt.fstr = 'mk_head_model';
0045 out = eidors_cache(@do_mk_head_model,[{str}, varargin(:)'],opt);
0046 switch out.type
0047    case 'image'
0048       out.fwd_model = mdl_normalize(out.fwd_model, 'default');
0049    case 'fwd_model'
0050       out = mdl_normalize(out, 'default');
0051    otherwise
0052       error('Produced struct with unrecognized type');
0053 end
0054 end
0055 
0056 function out = do_mk_head_model(str, elec_pos, elec_shape, maxh)
0057 
0058 if ismember(str,list_predef_models)
0059    out = build_predef_models(str);
0060    return
0061 end
0062 
0063 if ~ismember(str, list_basic_shapes)
0064    error('Shape str "%s" not understood.',str);
0065 end
0066 
0067 if ~any(str=='-') % basic shaps have no hyphens
0068    out = build_basic_model(str);
0069    if nargin > 1
0070       out = place_elec_on_surf(out,elec_pos,elec_shape,[],maxh);
0071       out = fix_boundary(out);
0072    end
0073 else
0074    out = build_advanced_model(str, elec_pos, elec_shape, maxh);
0075 end
0076 
0077 end
0078 
0079 function ls = list_basic_shapes
0080    ls = {'adult', 'adult-organs'};
0081 end
0082 
0083 function out = build_basic_model(str)
0084 switch(str)
0085    case 'adult'
0086       out = mk_head_model_adult();
0087 end
0088 end
0089 
0090 function out = build_advanced_model(str, elec_pos, elec_shape, maxh)
0091 switch(str)
0092    case {'adult-organs'}
0093       out = mk_head_model_adult(elec_pos, elec_shape, maxh, 'coarse');
0094 end
0095 end
0096 
0097 function ls = list_predef_models
0098    ls = {'adult_10-10'
0099          'adult_2x16'
0100          'adult_1x32'
0101         };
0102 end
0103 
0104 function out = build_predef_models(str)
0105 switch str
0106    case 'adult_10-10'
0107       out = mk_head_model_adult('10-10','coarse');
0108    case 'adult_2x16'
0109       out = mk_head_model_adult('2x16_planar','coarse');
0110    case 'adult_1x32'
0111       out = mk_head_model_adult('1x32_ring', 'coarse');
0112 end
0113 end
0114 
0115 function do_unit_test
0116 test_predef_models
0117 end
0118 
0119 function test_predef_models
0120    models = mk_head_model('list');
0121    n_models = numel(models);
0122 %    sqrt_n_models = ceil(sqrt(n_models));
0123    error_list = {};
0124    for i = 1:numel(models)
0125       eidors_msg('\n\n\n DOING  MODEL (%s)\n\n\n',models{i},0);
0126       try
0127          mdl = mk_head_model(models{i});
0128       catch
0129          error_list = [error_list, models(i)];
0130          continue;
0131       end
0132    
0133 %       subplot(sqrt_n_models, sqrt_n_models,i);
0134       show_fem(mdl,[0,1,0]); axis off;
0135       title(models{i},'Interpreter','none');
0136       drawnow
0137    end
0138    if ~isempty(error_list)
0139       disp('There were errors in generating the following models:')
0140       disp(error_list);
0141    end
0142 end
0143

Generated on Sun 29-Dec-2024 11:41:59 by m2html © 2005