0001 function out = mk_library_model(shape,elec_pos,elec_shape,maxsz,nfft)
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 if ischar(shape)
0028 switch shape
0029 case 'LIBRARY_PATH'
0030 switch nargin
0031 case 1
0032 out = get_path;
0033 case 2
0034 set_path(elec_pos);
0035 end
0036 case 'list'
0037 out = list_predef_model_strings;
0038 case 'UNIT_TEST'
0039 out = do_unit_test; return;
0040 otherwise
0041 out = predef_model(shape);
0042 end
0043 else
0044 if ~iscell(shape)
0045 shape = {shape, 'boundary'};
0046 elseif numel(shape) == 1
0047 shape{2} = 'boundary';
0048 end
0049 fname = make_filename(shape,elec_pos,elec_shape,maxsz);
0050 fname = [get_path '/' fname '.mat'];
0051 if exist(fname,'file')
0052 eidors_msg('MK_LIBRARY_MODEL: Using stored model');
0053 load(fname);
0054 out = fmdl;
0055 else
0056 s_shape = split_var_strings(shape(2:end));
0057 shapes = shape_library('get',shape{1},s_shape(1,:));
0058 if ~iscell(shapes), shapes = {shapes}; end
0059
0060 for i = 1:numel(shapes)
0061 eval(['shapes{i} = shapes{i}' s_shape{2,i} ';']);
0062 end
0063 if ischar(elec_pos) && strcmp(elec_pos,'original')
0064 el = shape_library('get',shape{1},'electrodes');
0065 electh= atan2(el(:,2),el(:,1))*180/pi;
0066 elec_pos = [electh,0.5*ones(size(electh))];
0067 end
0068 if nargin < 5
0069 nfft = 50;
0070 end
0071 [fmdl, mat_idx] = ng_mk_extruded_model({1,shapes,[4,nfft],maxsz},...
0072 elec_pos,elec_shape);
0073 fmdl.mat_idx = mat_idx;
0074 save(fname,'fmdl');
0075 out = fmdl;
0076 end
0077 end
0078
0079
0080
0081 function out = list_predef_model_strings
0082 out = {
0083 'adult_male_16el';
0084 'adult_male_32el';
0085 'adult_male_16el_lungs';
0086 'adult_male_32el_lungs';
0087 'cylinder_16x1el_coarse';
0088 'cylinder_16x1el_fine';
0089 'cylinder_16x1el_vfine';
0090 'cylinder_16x2el_coarse';
0091 'cylinder_16x2el_fine';
0092 'cylinder_16x2el_vfine';
0093 'neonate_16el';
0094 'neonate_32el';
0095 'neonate_16el_lungs';
0096 'neonate_32el_lungs';
0097 'pig_23kg_16el';
0098 'pig_23kg_32el';
0099 'pig_23kg_16el_lungs';
0100 'pig_23kg_32el_lungs';
0101 };
0102
0103
0104
0105 function out = predef_model(str)
0106 switch str
0107 case 'adult_male_16el'
0108 out = mk_library_model({'adult_male','boundary'},...
0109 [16 1 0.5],[0.05],0.08);
0110 case 'adult_male_32el'
0111 out = mk_library_model({'adult_male','boundary'},...
0112 [32 1 0.5],[0.05],0.08);
0113 case 'adult_male_16el_lungs'
0114 out = mk_library_model({'adult_male','boundary','left_lung','right_lung'},...
0115 [16 1 0.5],[0.05],0.08);
0116 case 'adult_male_32el_lungs'
0117 out = mk_library_model({'adult_male','boundary','left_lung','right_lung'},...
0118 [32 1 0.5],[0.05],0.08);
0119
0120 case 'cylinder_16x1el_coarse'
0121 out = ng_mk_cyl_models([10,15],[16,5],[0.5,0,0.18]);
0122 case 'cylinder_16x1el_fine'
0123 out = ng_mk_cyl_models([10,15,1.1],[16,5],[0.5,0,0.15]);
0124 case 'cylinder_16x1el_vfine'
0125 out = ng_mk_cyl_models([10,15,0.8],[16,5],[0.5,0,0.08]);
0126 case 'cylinder_16x2el_coarse'
0127 out = ng_mk_cyl_models([30,15],[16,10,20],[0.5,0,0.18]);
0128 case 'cylinder_16x2el_fine'
0129 out = ng_mk_cyl_models([30,15,1.5],[16,10,20],[0.5,0,0.15]);
0130 case 'cylinder_16x2el_vfine'
0131 out = ng_mk_cyl_models([30,15,0.8],[16,10,20],[0.5,0,0.08]);
0132
0133
0134 case 'neonate_16el'
0135 out = mk_library_model({'neonate','boundary'},[16 1 0.5],0.1,0.08,49);
0136 case 'neonate_32el'
0137 out = mk_library_model({'neonate','boundary'},[32 1 0.5],0.07,0.08,49);
0138 case 'neonate_16el_lungs'
0139 out = mk_library_model({'neonate','boundary','left_lung','right_lung'},[16 1 0.5],0.1,0.08,49);
0140 case 'neonate_32el_lungs'
0141 out = mk_library_model({'neonate','boundary','left_lung','right_lung'},[32 1 0.5],0.07,0.08,49);
0142
0143 case 'pig_23kg_16el'
0144 out = mk_library_model({'pig_23kg','boundary'},...
0145 [16 1 0.5],[0.05],0.08);
0146 case 'pig_23kg_32el'
0147 out = mk_library_model({'pig_23kg','boundary'},...
0148 [32 1 0.5],[0.05],0.08);
0149 case 'pig_23kg_16el_lungs'
0150 out = mk_library_model({'pig_23kg','boundary','lungs(1:2:end,:)'},...
0151 [16 1 0.5],[0.05],0.08);
0152 case 'pig_23kg_32el_lungs'
0153 out = mk_library_model({'pig_23kg','boundary','lungs(1:2:end,:)'},...
0154 [32 1 0.5],[0.05],0.08); case 'pig_23kg_16el'
0155 out = mk_library_model({'pig_23kg','boundary'},...
0156 [16 1 0.5],[0.05],0.08);
0157 case 'pig_23kg_32el'
0158 out = mk_library_model({'pig_23kg','boundary'},...
0159 [32 1 0.5],[0.05],0.08);
0160 case 'pig_23kg_16el_lungs'
0161 out = mk_library_model({'pig_23kg','boundary','lungs(1:2:end,:)'},...
0162 [16 1 0.5],[0.05],0.08);
0163 case 'pig_23kg_32el_lungs'
0164 out = mk_library_model({'pig_23kg','boundary','lungs(1:2:end,:)'},...
0165 [32 1 0.5],[0.05],0.08);
0166 otherwise
0167 error('No such model');
0168 end
0169
0170 out.name = str;
0171
0172
0173 function str = make_filename(shape, elec_pos, elec_shape, maxsz)
0174
0175 str = shape{1};
0176 shape(1) = [];
0177 shape = sort(shape);
0178 for i = 1:numel(shape)
0179 str = [str '_' shape{i}];
0180 end
0181 str = [str '_EP'];
0182 for i = 1:numel(elec_pos)
0183 str = [str '_' num2str(elec_pos(i))];
0184 end
0185 str = [str '_ES'];
0186 if ischar(elec_shape)
0187 str = [str '_' elec_shape];
0188 else
0189 for i = 1:numel(elec_shape)
0190 str = [str '_' num2str(elec_shape(i))];
0191 end
0192 end
0193 if ~isempty(maxsz)
0194 str = [str '_maxsz_' num2str(maxsz)];
0195 end
0196
0197
0198 str = strrep(str,':','-');
0199
0200 function clean = split_var_strings(strc)
0201 for i = 1:numel(strc)
0202 [clean{1,i} clean{2,i}] = strtok(strc{i},'([{');
0203 end
0204
0205
0206 function out = get_path
0207 global eidors_objects
0208 out = eidors_objects.model_cache;
0209
0210 function set_path(val)
0211 global eidors_objects
0212 eidors_objects.model_cache = val;
0213
0214 if ~exist(val,'dir')
0215 mkdir(val);
0216 end
0217
0218 function out = do_unit_test
0219 models = mk_library_model('list');
0220 for i = 1:numel(models)
0221 mdl = mk_library_model(models{i});
0222 img = mk_image(mdl,1);
0223 try n = numel(mdl.mat_idx); catch n =1; end
0224 if n >1
0225 for j = 2:n
0226 img.elem_data(mdl.mat_idx{j}) = 0.25;
0227 end
0228 end
0229 figure
0230 show_fem(img,[0,1,0]);
0231 title(models{i},'Interpreter','none');
0232 end
0233
0234
0235 out = mk_library_model({'pig_23kg','boundary','lungs(1:2:end,:)'},[32 1 0.5],[0.05],0.08);
0236