0001 function out = mk_head_model(str, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
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=='-')
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
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
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