API Reference#
All reader functions return an object with the following structure:
Field |
Type |
Description |
|---|---|---|
|
|
Interleaved XYZ vertex positions for all streamlines |
|
|
Start index of each streamline in |
|
|
Data-per-streamline (TRX, TRK) |
|
|
Data-per-vertex (TRX, TRK) |
|
|
Data-per-group (TRX only) |
|
|
Parsed |
Reader Functions#
readTRK#
- readTRK(buffer)#
Read a TrackVis (.trk) file from an ArrayBuffer.
Handles uncompressed, gzip-compressed, and zstd-compressed TRK files. Parses the 1000-byte header (scalars, properties, voxel-to-RAS matrix), reads vertex positions, and applies the voxel-to-RAS transform.
- Arguments:
buffer (ArrayBuffer) – Raw file data (may be gzip/zstd compressed; decompressed automatically).
- Returns:
StreamlineData – An object with pts, offsetPt0, dps, and dpv.
readTCK#
- readTCK(buffer)#
Read an MRtrix (.tck) file from an ArrayBuffer.
Parses the text header up to the END marker, then reads float32 vertex positions. Streamlines are terminated by NaN (continue) or Infinity (stop) values in the X position.
- Arguments:
buffer (ArrayBuffer) – Raw file data.
- Returns:
StreamlineData – An object with pts and offsetPt0.
readVTK#
- readVTK(buffer)#
Read a VTK legacy (.vtk) file from an ArrayBuffer.
Supports both ASCII and binary formats. Handles POLYDATA with LINES (classic and DiPy OFFSETS-style), TRIANGLE_STRIPS, and POLYGONS. Binary VTK files are expected in big-endian byte order.
- Arguments:
buffer (ArrayBuffer) – Raw file data.
- Returns:
StreamlineData|Object – For streamline data (LINES) returns {pts, offsetPt0}. For mesh data (TRIANGLE_STRIPS, POLYGONS) returns {positions, indices}.
readTRX#
- readTRX(url, urlIsLocalFile=false)#
Read a TRX (.trx) file — the modern tractography format.
This is an async function. It fetches the TRX zip container, decompresses it, reads header.json, and parses positions, offsets, and per-group/per-streamline/per-vertex data arrays.
Supports all numeric types including float16 (automatically converted to float32) and uint64/int64 (lower 32 bits only; warns on overflow).
- Arguments:
url (string) – URL or local file path (behavior controlled by urlIsLocalFile).
urlIsLocalFile (boolean) – If true, reads from local filesystem via fs.readFileSync.
- Returns:
Promise.<StreamlineData> – A promise resolving to an object with pts, offsetPt0, dpg, dps, dpv, and header.
readTT#
- readTT(buffer)#
Read a DSI Studio (.tt / .fib) file.
Parses the Matlab V4 container, applies incremental zigzag decoding, and transforms voxel coordinates to RAS (mm) space using the trans_to_mni and voxel_size matrices.
- Arguments:
buffer (ArrayBuffer) – Raw file data (may be gzip-compressed; decompressed automatically).
- Returns:
StreamlineData – An object with pts and offsetPt0.