Create an iterator over the tracts of a DTI tract file.
Source:R/dti_tracks_utils.R
dti.track.iterator.RdReads a TRK, TCK or TSF file tract by tract, so that a
tractogram of any size can be processed with a constant amount of memory.
This is the low-level interface behind dti.track.count and
friends, use it when neither reading a subset
(max_tracks, skip_tracks, bbox in
read.dti.tck) nor one of the aggregate functions fits your
use case.
The returned object is an environment with the following entries:
next.track(): returns the next tract (a n x 3 matrix for TCK, a numeric vector of per-point values for TSF, and a list with the entriescoords,num_points,scalarsandpropertiesfor TRK, just liketracks[[i]]does for the readers), orNULLwhen there are no more tracts.close(): closes the underlying file connection. It is safe to call this more than once, and it is also called automatically when the iterator is garbage collected.tracks.read: the number of tracts returned so far.filepath,format: the file and its detected format.
Arguments
- filepath
character string, path to the
TCKorTSFfile to read. Gzip-compressed files (i.e.,.tck.gz) are supported and the compression is detected from the file content, not the file name.- skip_tracks
integer, the number of tracks to skip before reading any. Skipped tracks are never held in memory.
- bbox
numeric vector of length 6 or NULL. If given, only tracks that have at least one point inside the box are read, the box is given as
c(xmin, xmax, ymin, ymax, zmin, zmax)in the coordinate system of the stored data. This has no effect for TSF files, which store no coordinates. The number of matching tracks cannot be known in advance, so for very large files this should be combined with amax_tracksvalue that is known to be safe.- chunk_values
integer, the number of payload values that are read per chunk. This is an advanced tuning parameter that does not change the result, only the peak memory usage (at most one chunk is buffered at a time) and the granularity of the file reads. The default of 4e6 values corresponds to about 32 MB of doubles. Lower it on a machine with very little free memory.