elem_select

PURPOSE ^

ELEM_SELECT: select element fractions inside a function

SYNOPSIS ^

function memb_frac = elem_select( fmdl, select_fcn )

DESCRIPTION ^

 ELEM_SELECT: select element fractions inside a function
   memb_frac = elem_select( fmdl, select_fcn )

  memb_frac = fraction of each element within the fcn
  fmdl =      fwd_model structure
  select_fcn = function to describe membership, 
              can also be a cell array of functions, but all must accept
              x, y, and z

 parameters
   fwd_model.elem_select.interp_no  - interpolation density

 Example:
   img = mk_image(mk_common_model('b2d1c',8));
   select_fcn = inline('(x-0.2).^2+(y-0.5).^2<0.2^2','x','y','z');
   memb_frac = elem_select( img.fwd_model, select_fcn)
   img.elem_data = 1 + memb_frac*0.1;
   show_fem(img);

 See Also:
   mk_c2f_circ_mapping

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function memb_frac = elem_select( fmdl, select_fcn )
0002 % ELEM_SELECT: select element fractions inside a function
0003 %   memb_frac = elem_select( fmdl, select_fcn )
0004 %
0005 %  memb_frac = fraction of each element within the fcn
0006 %  fmdl =      fwd_model structure
0007 %  select_fcn = function to describe membership,
0008 %              can also be a cell array of functions, but all must accept
0009 %              x, y, and z
0010 %
0011 % parameters
0012 %   fwd_model.elem_select.interp_no  - interpolation density
0013 %
0014 % Example:
0015 %   img = mk_image(mk_common_model('b2d1c',8));
0016 %   select_fcn = inline('(x-0.2).^2+(y-0.5).^2<0.2^2','x','y','z');
0017 %   memb_frac = elem_select( img.fwd_model, select_fcn)
0018 %   img.elem_data = 1 + memb_frac*0.1;
0019 %   show_fem(img);
0020 %
0021 % See Also:
0022 %   mk_c2f_circ_mapping
0023 
0024 if isstr(fmdl) && strcmp(fmdl,'UNIT_TEST'); do_unit_test; return; end
0025 
0026 
0027 % 4 for 2D, 3 for 3D
0028 dims = size(fmdl.nodes,2);
0029 interp_no = 6 - dims;
0030 try 
0031    interp_no = fmdl.elem_select.interp_no;
0032 end
0033 
0034 pts = interp_mesh( fmdl, interp_no );
0035 x = squeeze(pts(:,1,:));
0036 y = squeeze(pts(:,2,:));
0037 if dims ==2;
0038   z = 0*x;
0039 else
0040   z = squeeze(pts(:,3,:));
0041 end
0042 if ~iscell(select_fcn) 
0043     % the normal case
0044     memb_frac = mean( feval(select_fcn,x,y,z), 2);
0045 else
0046     % many functions case
0047     memb_val = ones(size(x));
0048     for i = 1:numel(select_fcn)
0049         memb_val = memb_val .* feval(select_fcn{i},x,y,z);
0050     end
0051     memb_frac = mean(memb_val,2);
0052 end
0053 
0054 
0055 function do_unit_test;
0056     imdl = mk_common_model('a2c2',8);
0057     select_fcn = inline('(x-0.2).^2+(y-0.5).^2<0.2^2','x','y','z');
0058     memb_frac = elem_select( imdl.fwd_model, select_fcn);
0059     unit_test_cmp('a2c2',find(memb_frac), [5, 10,18,26,27]');
0060 
0061     select_fcn2= inline('y<0.4','x','y','z');
0062     memb_frac = elem_select( imdl.fwd_model, {select_fcn,select_fcn2});
0063     unit_test_cmp('a2c2 (2fcns)',find(memb_frac), [5, 10,18,27]');
0064 
0065     imdl = mk_common_model('n3r2',8);
0066     select_fcn = inline('(x-0.2).^2+(y-0.5).^2 + (z-1).^2<0.1^2','x','y','z');
0067     memb_frac = elem_select( imdl.fwd_model, select_fcn);
0068     unit_test_cmp('n3r2',find(memb_frac), [156 159 162 168 431 434 437 503]');
0069 
0070 
0071 
0072

Generated on Tue 09-Aug-2011 11:38:31 by m2html © 2005