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