0001 function img= mk_image(mdl, elem_data, params, name)
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 if ischar(mdl) && strcmp(mdl,'UNIT_TEST'); do_unit_test; return; end
0027
0028 default_params = no_params;
0029 default_name = 'Created by mk_image';
0030 if nargin<3
0031 name = default_name;
0032 params = default_params;
0033 elseif nargin < 4
0034 if ismember(params,supported_params)
0035 name = default_name;
0036 else
0037 name = params;
0038 params = default_params;
0039 end
0040 end
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 switch mdl.type
0051 case 'inv_model'
0052 if nargin == 1
0053 img = calc_jacobian_bkgnd(mdl);
0054 return
0055 else
0056 mdl = mdl.fwd_model;
0057
0058 end
0059 case 'fwd_model'
0060 mdl = mdl;
0061 case 'image'
0062 if nargin == 1
0063 img = data_mapper(mdl);
0064 return
0065 end
0066 mdl = mdl.fwd_model;
0067 otherwise; error('mk_image: no inv_model, fwd_model or image object');
0068 end
0069
0070 img = eidors_obj('image',name);
0071 img.fwd_model = mdl;
0072 if isfield(mdl,'show_slices');
0073 img.show_slices = mdl.show_slices;
0074 end
0075 img = fill_in_data(img,elem_data,params);
0076
0077
0078
0079 img = eidors_obj('set', img);
0080
0081 function str = no_params
0082 str = 'unspecified';
0083
0084 function img = fill_in_data(img,elem_data,params)
0085
0086
0087 if size(elem_data,1) == 1 && ...
0088 size(elem_data,2) > 1
0089 elem_data = elem_data.';
0090 end
0091 switch size(elem_data,1)
0092 case 1
0093 sz = size(img.fwd_model.elems,1);
0094 elem_data_mat = NaN*ones(sz,1);
0095 elem_data_mat(:) = elem_data;
0096 if strcmp(params,no_params);
0097 img.elem_data = elem_data_mat;
0098 else
0099 img.(params).elem_data = elem_data_mat;
0100 end
0101
0102 case num_elems( img )
0103 if strcmp(params,no_params);
0104 img.elem_data = elem_data;
0105 else
0106 img.(params).elem_data = elem_data;
0107 end
0108
0109 case num_nodes( img )
0110 if strcmp(params,no_params);
0111 img.node_data = elem_data;
0112 else
0113 img.(params).node_data = elem_data;
0114 end
0115
0116 case size(img.fwd_model.coarse2fine,2)
0117 if strcmp(params,no_params);
0118 img.elem_data = elem_data;
0119 else
0120 img.(params).elem_data = elem_data;
0121 end
0122
0123 otherwise
0124 error('Don''t understand number of elements.');
0125 end
0126
0127
0128 function do_unit_test
0129 imdl = mk_common_model('a2c2',8);
0130 im0 = mk_image( imdl );
0131 unit_test_cmp('im1',im0.elem_data, ones(64,1) );
0132
0133 im0 = mk_image( imdl, 2 );
0134 unit_test_cmp('im2',im0.elem_data, 2*ones(64,1) );
0135
0136 im0 = mk_image( imdl.fwd_model, 3*ones(64,1) );
0137 unit_test_cmp('im3',im0.elem_data, 3*ones(64,1) );
0138
0139 im0 = mk_image(im0);
0140 unit_test_cmp('im4',im0.elem_data, 3*ones(64,1) );
0141
0142 im0.conductivity.elem_data = im0.elem_data;
0143 im0 = rmfield(im0, 'elem_data');
0144 im1 = mk_image(im0);
0145 unit_test_cmp('im5',im1.elem_data, 3*ones(64,1) );
0146
0147 im0.resistivity.node_data = 5;
0148 im0.data_mapper = 'resistivity';
0149 im1 = mk_image(im0);
0150 unit_test_cmp('im6',im1.node_data(5), 5 );
0151
0152 imdl.jacobian_bkgnd = rmfield(imdl.jacobian_bkgnd, 'value');
0153 imdl.jacobian_bkgnd.conductivity = im0.conductivity;
0154 im2 = mk_image(imdl);
0155 unit_test_cmp('im7',im2.conductivity.elem_data, 3*ones(64,1) );
0156
0157 im0 = mk_image( imdl.fwd_model, 3*ones(64,1),'my_name' );
0158 unit_test_cmp('im8a',im0.elem_data, 3*ones(64,1) );
0159
0160 im0 = mk_image( imdl.fwd_model, 3*ones(64,1),'resistivity' );
0161 unit_test_cmp('im8b',im0.resistivity.elem_data, 3*ones(64,1) );
0162
0163 im0 = mk_image( imdl.fwd_model, 2*ones(64,3),'resistivity' );
0164 unit_test_cmp('im8c',im0.resistivity.elem_data, 2*ones(64,3) );
0165
0166 im0 = mk_image( imdl.fwd_model, 3*ones(64,1),'resistivity','my name' );
0167 unit_test_cmp('im9a',im0.resistivity.elem_data, 3*ones(64,1) );
0168 unit_test_cmp('im9b',im0.name, 'my name' );