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 function str = no_params
0079 str = 'unspecified';
0080
0081 function img = fill_in_data(img,elem_data,params)
0082
0083
0084 if size(elem_data,1) == 1 && ...
0085 size(elem_data,2) > 1
0086 elem_data = elem_data.';
0087 end
0088 switch size(elem_data,1)
0089 case 1
0090 sz = size(img.fwd_model.elems,1);
0091 elem_data_mat = NaN*ones(sz,1);
0092 elem_data_mat(:) = elem_data;
0093 if strcmp(params,no_params);
0094 img.elem_data = elem_data_mat;
0095 else
0096 img.(params).elem_data = elem_data_mat;
0097 end
0098
0099 case num_elems( img )
0100 if strcmp(params,no_params);
0101 img.elem_data = elem_data;
0102 else
0103 img.(params).elem_data = elem_data;
0104 end
0105
0106 case num_nodes( img )
0107 if strcmp(params,no_params);
0108 img.node_data = elem_data;
0109 else
0110 img.(params).node_data = elem_data;
0111 end
0112
0113 case size(img.fwd_model.coarse2fine,2)
0114 if strcmp(params,no_params);
0115 img.elem_data = elem_data;
0116 else
0117 img.(params).elem_data = elem_data;
0118 end
0119
0120 otherwise
0121 error('Don''t understand number of elements.');
0122 end
0123
0124
0125 function do_unit_test
0126 imdl = mk_common_model('a2c2',8);
0127 im0 = mk_image( imdl );
0128 unit_test_cmp('im1',im0.elem_data, ones(64,1) );
0129
0130 im0 = mk_image( imdl, 2 );
0131 unit_test_cmp('im2',im0.elem_data, 2*ones(64,1) );
0132
0133 im0 = mk_image( imdl.fwd_model, 3*ones(64,1) );
0134 unit_test_cmp('im3',im0.elem_data, 3*ones(64,1) );
0135
0136 im0 = mk_image(im0);
0137 unit_test_cmp('im4',im0.elem_data, 3*ones(64,1) );
0138
0139 im0.conductivity.elem_data = im0.elem_data;
0140 im0 = rmfield(im0, 'elem_data');
0141 im1 = mk_image(im0);
0142 unit_test_cmp('im5',im1.elem_data, 3*ones(64,1) );
0143
0144 im0.resistivity.node_data = 5;
0145 im0.data_mapper = 'resistivity';
0146 im1 = mk_image(im0);
0147 unit_test_cmp('im6',im1.node_data(5), 5 );
0148
0149 imdl.jacobian_bkgnd = rmfield(imdl.jacobian_bkgnd, 'value');
0150 imdl.jacobian_bkgnd.conductivity = im0.conductivity;
0151 im2 = mk_image(imdl);
0152 unit_test_cmp('im7',im2.conductivity.elem_data, 3*ones(64,1) );
0153
0154 im0 = mk_image( imdl.fwd_model, 3*ones(64,1),'my_name' );
0155 unit_test_cmp('im8a',im0.elem_data, 3*ones(64,1) );
0156
0157 im0 = mk_image( imdl.fwd_model, 3*ones(64,1),'resistivity' );
0158 unit_test_cmp('im8b',im0.resistivity.elem_data, 3*ones(64,1) );
0159
0160 im0 = mk_image( imdl.fwd_model, 2*ones(64,3),'resistivity' );
0161 unit_test_cmp('im8c',im0.resistivity.elem_data, 2*ones(64,3) );
0162
0163 im0 = mk_image( imdl.fwd_model, 3*ones(64,1),'resistivity','my name' );
0164 unit_test_cmp('im9a',im0.resistivity.elem_data, 3*ones(64,1) );
0165 unit_test_cmp('im9b',im0.name, 'my name' );