Home > utility > feClipFibersToVolume.m

feClipFibersToVolume

PURPOSE ^

Clip fibers to be constrained within a Volume.

SYNOPSIS ^

function [fg, kept] = feClipFibersToVolume(fg,coords,maxVolDist)

DESCRIPTION ^

 Clip fibers to be constrained within a Volume.

  function fibers = feClipFibersToVolume(fibers,coords,maxVolDist)

 INPUTS:
        fibers         - A cell array of fibers, each defined as a 3xN array
                         of x,y,z coordinates. E.g., fg.fibers.
        coords         - A volume of defined as a 3xN array of x,y,z coordinates.
        maxVolDist     - The farther distance (in mm) from the volume a node can
                         be to be kept in the fiber.
        
 OUTPUTS:
        fibersOut      - A cell-array of fibers clipped within the volume 
                        defined by coords.
        kept           - fibers that were kept out of the original fiber
                         group. Because fibers left with no nodes in coords
                         are deleted the numbe rof kept fibes can be less
                         then the original number of fibers,

 SEE ALSO: feClipFiberNodes.m, feConnectomePreprocess.m


 Copyright (2013-2014), Franco Pestilli, Stanford University, pestillifranco@gmail.com.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [fg, kept] = feClipFibersToVolume(fg,coords,maxVolDist)
0002 % Clip fibers to be constrained within a Volume.
0003 %
0004 %  function fibers = feClipFibersToVolume(fibers,coords,maxVolDist)
0005 %
0006 % INPUTS:
0007 %        fibers         - A cell array of fibers, each defined as a 3xN array
0008 %                         of x,y,z coordinates. E.g., fg.fibers.
0009 %        coords         - A volume of defined as a 3xN array of x,y,z coordinates.
0010 %        maxVolDist     - The farther distance (in mm) from the volume a node can
0011 %                         be to be kept in the fiber.
0012 %
0013 % OUTPUTS:
0014 %        fibersOut      - A cell-array of fibers clipped within the volume
0015 %                        defined by coords.
0016 %        kept           - fibers that were kept out of the original fiber
0017 %                         group. Because fibers left with no nodes in coords
0018 %                         are deleted the numbe rof kept fibes can be less
0019 %                         then the original number of fibers,
0020 %
0021 % SEE ALSO: feClipFiberNodes.m, feConnectomePreprocess.m
0022 %
0023 %
0024 % Copyright (2013-2014), Franco Pestilli, Stanford University, pestillifranco@gmail.com.
0025 
0026 fibers    = fg.fibers;
0027 
0028 % Make sure the coordinates were passed with the expected dimesnions
0029 if ~((size(coords,1) == 3) && (size(coords,2)>=3))
0030   coords = coords';
0031 end
0032 
0033 parfor ii = 1:length(fibers)
0034   % Compute the squared distance between each node on fiber ii and the
0035   % nearest roi coordinate
0036   [~, nodesSqDistance] = nearpoints(fibers{ii}, coords);
0037   
0038   % Keep the nodes in the fiber less than the wanted distance
0039   nodesToKeep = (sqrt(nodesSqDistance) <= maxVolDist);
0040   fibers{ii}  = fibers{ii}(:,nodesToKeep);
0041 end
0042 fg.fibers     = fibers; clear fibers;
0043 
0044 % Remove the empty fibers, fibers that had no nodes in the volume
0045 kept = (~cellfun('isempty',fg.fibers));
0046 if sum(kept) < length(kept)
0047 fg           = fgExtract(fg,kept,'keep');
0048 end
0049 
0050 end % Main function

Generated on Wed 16-Jul-2014 19:56:13 by m2html © 2005