0001 function [vh,vi,xyr_pt]= simulate_2d_movement( n_sims, fmdl, rad_pr, movefcn )
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
0034
0035 if nargin <1
0036 n_sims = 200;
0037 end
0038
0039 if nargin<2 || isempty(fmdl)
0040 n_circles = 36;
0041 n_elec= 16;
0042 fmdl= mk_fwd_model(n_circles, n_elec);
0043 end
0044
0045 if nargin<3 || isempty(rad_pr)
0046 radius= 2/3;
0047 rp= .05;
0048 else
0049 radius= rad_pr(1);
0050 rp= rad_pr(2);
0051 end
0052
0053 if nargin<4
0054 movefcn = 1;
0055 end
0056 if isnumeric(movefcn)
0057 if movefcn==1
0058 movefcn = @rotation_path;
0059 elseif movefcn==2
0060 movefcn = @straight_out;
0061 else
0062 error('value of movefcn not understood');
0063 end
0064 else
0065
0066 end
0067
0068 n_elems= size(fmdl.elems,1);
0069 img= eidors_obj('image','simulate_movement', ...
0070 'fwd_model', fmdl, ...
0071 'elem_data', ones(n_elems,1) );
0072 vh= fwd_solve(img);
0073
0074 if 0
0075 np= 256;
0076 maxxy= max(fmdl.nodes);
0077 minxy= min(fmdl.nodes);
0078 [x,y]=meshgrid( linspace(minxy(1),maxxy(1),np), ...
0079 linspace(minxy(2),maxxy(2),np) );
0080 [eptr,vol]= img_mapper2(fmdl.nodes', fmdl.elems', np, np);
0081 else
0082
0083 mdl_pts = interp_mesh( fmdl, 8);
0084 x= squeeze( mdl_pts(:,1,:) );
0085 y= squeeze( mdl_pts(:,2,:) );
0086 end
0087
0088
0089
0090
0091
0092
0093
0094 target_conductivity= .1;
0095
0096 for i=1:n_sims
0097 f_frac= (i-1)/n_sims;
0098 fprintf('simulating %d / %d \n',i,n_sims);
0099
0100 [xp,yp]= feval(movefcn, f_frac, radius);
0101
0102 if 0
0103 xyr_pt(:,i)= [xp;-yp;rp];
0104 ff= find( (x(:)-xp).^2 + (y(:)-yp).^2 <= rp^2 )';
0105 obj_n= sparse( eptr(ff)+1,1,1, n_elems+1, 1);
0106 obj_n= full(obj_n(2:end));
0107
0108 img.elem_data= 1 + target_conductivity * (obj_n./vol);
0109 else
0110 xyr_pt(:,i)= [xp;yp;rp];
0111 ff= (x-xp).^2 + (y-yp).^2 <= rp^2;
0112 img.elem_data= 1 + target_conductivity * mean(ff,2);
0113 end
0114
0115 vi(i)= fwd_solve( img );
0116
0117 end
0118
0119
0120 vi= [vi(:).meas];
0121 vh= [vh(:).meas];
0122
0123
0124
0125
0126 function [xp,yp] = rotation_path(f_frac, radius);
0127 xp= radius * cos(f_frac*2*pi);
0128 yp= radius * sin(f_frac*2*pi);
0129
0130 function [xp,yp] = straight_out(f_frac, radius);
0131 xp= radius*f_frac;
0132 yp= 0;
0133
0134
0135
0136
0137 function [EPTR,VOL]= img_mapper2(NODE, ELEM, npx, npy );
0138 xmin = min(NODE(1,:)); xmax = max(NODE(1,:));
0139 xmean= mean([xmin,xmax]); xrange= xmax-xmin;
0140
0141 ymin = min(NODE(2,:)); ymax = max(NODE(2,:));
0142 ymean= mean([ymin,ymax]); yrange= ymax-ymin;
0143
0144 range= max([xrange, yrange]);
0145 [x y]=meshgrid( ...
0146 linspace( xmean - range*0.50, xmean + range*0.50, npx ), ...
0147 linspace( ymean + range*0.50, ymean - range*0.50, npy ) );
0148 v_yx= [-y(:) x(:)];
0149 turn= [0 -1 1;1 0 -1;-1 1 0];
0150 EPTR=zeros(npy,npx);
0151
0152
0153
0154
0155
0156 e= size(ELEM,2);
0157 VOL= zeros(e,1);
0158 for j= 1:e
0159
0160 xy= NODE(:,ELEM(:,j))';
0161
0162
0163 endr=find( y(:)<=max(xy(:,2)) & y(:)>=min(xy(:,2)) ...
0164 & x(:)<=max(xy(:,1)) & x(:)>=min(xy(:,1)) );
0165
0166 a= xy([2;3;1],1).*xy([3;1;2],2)- xy([3;1;2],1).*xy([2;3;1],2);
0167 VOL(j)= abs(sum(a));
0168
0169 aa= sum(abs(ones(length(endr),1)*a'+ ...
0170 v_yx(endr,:)*xy'*turn)');
0171 endr( abs( ( VOL(j)-aa ) ./ VOL(j) ) >1e-8)=[];
0172 EPTR(endr)= j;
0173 end
0174
0175
0176 function mdl_2d= mk_fwd_model(n_circles, n_elec)
0177 params= mk_circ_tank(n_circles, [], n_elec);
0178 n_rings= 1;
0179 options= {'no_meas_current','no_rotate_meas','do_redundant'};
0180 [st, els]= mk_stim_patterns(n_elec, n_rings, '{ad}','{ad}', options, 10);
0181 params.stimulation= st;
0182 params.meas_select= els;
0183 params.solve= 'aa_fwd_solve';
0184 params.system_mat= 'aa_calc_system_mat';
0185 params.jacobian= 'aa_calc_jacobian';
0186 params.normalize_measurements= 1;
0187 params.np_fwd_solve.perm_sym= '{n}';
0188 mdl_2d = eidors_obj('fwd_model', params);