0001 function param = np_fwd_parameters( fwd_model )
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 param = eidors_obj('get-cache', fwd_model, 'np_fwd_parameters');
0028
0029 if ~isempty(param)
0030 eidors_msg('np_fwd_parameters: using cached value', 3);
0031 return
0032 end
0033
0034 param = calc_param( fwd_model );
0035
0036 eidors_obj('set-cache', fwd_model, 'np_fwd_parameters', param);
0037 eidors_msg('np_fwd_parameters: setting cached value', 3);
0038
0039
0040 function param= calc_param( fwd_model );
0041
0042 vtx= fwd_model.nodes;
0043 simp= fwd_model.elems;
0044
0045 n_elem= size(simp,1);
0046 n_elec= length(fwd_model.electrode );
0047 n_node = size(fwd_model.nodes,1);
0048 n_stim = length(fwd_model.stimulation );
0049 n_meas = 0;
0050
0051
0052 df= zeros(n_stim,1);
0053 for i=1:n_stim;
0054 df(i) = size(fwd_model.stimulation(i).meas_pattern ,1);
0055 n_meas = n_meas + df(i);
0056 end
0057
0058 elec= [];
0059 zc = zeros(n_elec, 1);
0060
0061 if isfield(fwd_model,'boundary')
0062 srf = fwd_model.boundary;
0063 else
0064 srf= find_boundary(simp);
0065 end
0066
0067 max_elec_nodes=0;
0068
0069 for i=1:n_elec
0070 elec_nodes= fwd_model.electrode(i).nodes;
0071 if length(elec_nodes)>1
0072 e_bdy = bdy_with_nodes(srf, elec_nodes );
0073 n_bdy = srf(e_bdy,:)';
0074 else
0075 n_bdy= elec_nodes;
0076 end
0077
0078 en_list{i}= n_bdy(:)';
0079 if length(n_bdy) > max_elec_nodes
0080 max_elec_nodes = length(n_bdy);
0081 end
0082
0083
0084 zc(i) = fwd_model.electrode(i).z_contact;
0085 end
0086
0087 elec= zeros(n_elec, max_elec_nodes);
0088 for i=1:n_elec
0089 en= en_list{i};
0090 elec(i,1:length(en)) = en;
0091 end
0092
0093
0094 indH= zeros(n_stim, 2);
0095 idx=0;
0096 for i=1:n_stim
0097 meas_pat= fwd_model.stimulation(i).meas_pattern';
0098
0099 sourcepos= find(meas_pat(:)== 1);
0100 sourcepos= rem( sourcepos-1 , n_elec) + 1;
0101
0102 sinkpos = find(meas_pat(:)==-1);
0103 sinkpos = rem( sinkpos -1 , n_elec) + 1;
0104
0105 indH( idx+(1:df(i)) , : ) = [sourcepos, sinkpos];
0106 idx= idx+ df(i);
0107 end
0108
0109
0110 I = zeros( n_elec + n_node, n_stim );
0111 idx=0;
0112 for i=1:n_stim
0113 I( n_node + (1:n_elec), i ) = ...
0114 fwd_model.stimulation(i).stim_pattern;
0115 end
0116 I(fwd_model.gnd_node,:) = 0;
0117 Ib= I( n_node + (1:n_elec), : );
0118
0119
0120 param.n_elem = n_elem;
0121 param.n_elec = n_elec;
0122 param.n_node = n_node;
0123 param.n_stim = n_stim;
0124 param.n_meas = n_meas;
0125 param.vtx = vtx;
0126 param.simp = simp;
0127 param.srf = srf;
0128 param.df = df;
0129 param.elec = elec;
0130 param.zc = zc;
0131 param.indH = indH;
0132 param.I = I;
0133 param.Ib = Ib;
0134 try
0135 param.perm_sym = fwd_model.np_fwd_solve.perm_sym;
0136 catch
0137 param.perm_sym = '{n}';
0138 end
0139 param.gnd_ind = fwd_model.gnd_node;
0140
0141 if isfield(fwd_model,'normalize_measurements')
0142 param.normalize = fwd_model.normalize_measurements;
0143 else
0144 param.normalize = 0;
0145 end
0146
0147
0148
0149
0150 function e_bdy = bdy_with_nodes(bdy, elec_nodes );
0151 mbdy= zeros(size(bdy));
0152 for n= elec_nodes(:)'
0153 mbdy= mbdy + (bdy == n);
0154 end
0155 e_bdy = find( all(mbdy') );
0156
0157
0158
0159
0160
0161
0162 if isempty(e_bdy)
0163 e_bdy = find( sum(mbdy')>=2 );
0164 end
0165 if isempty(e_bdy)
0166 e_bdy = find( any(mbdy') );
0167 end