0001 function [fmdl,c2f_idx]= crop_model( axis_handle, fcn_handle );
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 usage_graphics= 1;
0028 try if axis_handle.type == 'fwd_model'
0029 usage_graphics= 0;
0030 end; end
0031
0032 if usage_graphics
0033 if isempty(axis_handle)
0034 axis_handle= gca;
0035 end
0036 crop_graphics_model(axis_handle, fcn_handle);
0037 else
0038 [fmdl,c2f_idx]= crop_fwd_model(axis_handle, fcn_handle);
0039 end
0040
0041
0042 function crop_graphics_model(axis_handle, fcn_handle);
0043 kk= get(axis_handle,'Children');
0044
0045
0046
0047 for k= kk(:)'
0048 try
0049 x= get(k,'XData');
0050 y= get(k,'YData');
0051 z= get(k,'ZData');
0052 c= get(k,'CData');
0053 idx= ~all( feval(fcn_handle,x,y,z) );
0054 if any(size(c)>[1,1])
0055 set(k,'Xdata', x(:,idx), ...
0056 'Ydata', y(:,idx), ...
0057 'Zdata', z(:,idx), ...
0058 'Cdata', c(:,idx));
0059 else
0060 set(k,'Xdata', x(:,idx), ...
0061 'Ydata', y(:,idx), ...
0062 'Zdata', z(:,idx));
0063 end
0064 end
0065 end
0066
0067
0068 function [fmdl1,c2f_idx]= crop_fwd_model(fmdl0, fcn_handle);
0069 fmdl1= fmdl0;
0070
0071
0072 nodes= fmdl0.nodes;
0073 [n,d]= size(nodes);
0074 n2xyz= eye(d,3);
0075 xyz= nodes*n2xyz;
0076 idx0= ~all( feval(fcn_handle,xyz(:,1), ...
0077 xyz(:,2), ...
0078 xyz(:,3)),2);
0079
0080 fmdl1.nodes(idx0,:) = [];
0081
0082
0083 idx1= zeros(n,1);
0084 idx1(~idx0)= 1:sum(~idx0);
0085
0086 fmdl1.elems(:) = idx1(fmdl0.elems);
0087 remove= any( fmdl1.elems == 0, 2);
0088 fmdl1.elems(remove,:)= [];
0089
0090 c2f_idx= find(~remove);
0091
0092 fmdl1.boundary(:) = idx1(fmdl0.boundary);
0093 remove= any( fmdl1.boundary == 0, 2);
0094 fmdl1.boundary(remove,:)= [];
0095
0096
0097 if isfield(fmdl1,'electrode');
0098 for i=1:length(fmdl1.electrode)
0099 el_nodes= fmdl0.electrode(i).nodes;
0100 el_nodes(:)= idx1(el_nodes);
0101 if any(el_nodes==0);
0102 error('crop_model: nodes in electrode are removed');
0103 end
0104 fmdl1.electrode(i).nodes= el_nodes;
0105 end
0106 end
0107