Skip to main content

TrxFile

Struct TrxFile 

Source
pub struct TrxFile<P: TrxScalar> { /* private fields */ }
Expand description

Core TRX container, generic over the position scalar type P.

Owns all memory-mapped (or heap-allocated) backings. Typed views borrow from self — no explicit lifetime annotations needed.

§Field ordering

_tempdir must be declared AFTER mmap fields so it is dropped last, keeping the temp directory alive while mmaps reference files within it.

Implementations§

Source§

impl<P: TrxScalar> TrxFile<P>

Source

pub fn empty(header: Header) -> Self

Create an empty TrxFile with the given header.

Source

pub fn header(&self) -> &Header

Source

pub fn with_updated_header(self, header: Header) -> Self

Return a new TrxFile with the header replaced. All data arrays and positions are shared by reference-counted backing (owned copies).

Source

pub fn positions(&self) -> &[[P; 3]]

Positions as a flat slice of [P; 3] arrays.

Source

pub fn positions_2d(&self) -> TypedView2D<'_, P>

Positions as a TypedView2D with 3 columns.

Source

pub fn positions_bytes(&self) -> &[u8]

Raw position bytes for direct GPU buffer upload.

Source

pub fn nb_vertices(&self) -> usize

Number of vertices (points) across all streamlines.

Source

pub fn offsets(&self) -> &[u32]

Offsets as a slice of u32. Length is nb_streamlines + 1. The i-th streamline spans positions[offsets[i]..offsets[i+1]].

Source

pub fn offsets_vec(&self) -> Vec<u32>

Source

pub fn nb_streamlines(&self) -> usize

Number of streamlines.

Source

pub fn streamline(&self, i: usize) -> &[[P; 3]]

Get the i-th streamline as a slice of [P; 3] points.

Source

pub fn streamlines(&self) -> StreamlineIter<'_, P>

Iterate over all streamlines.

Source

pub fn streamline_lengths(&self) -> Vec<usize>

Length (number of points) of each streamline.

Source

pub fn dps<T: Pod>(&self, name: &str) -> Result<TypedView2D<'_, T>>

Get a DPS (data-per-streamline) array cast to type T.

Source

pub fn dpv<T: Pod>(&self, name: &str) -> Result<TypedView2D<'_, T>>

Get a DPV (data-per-vertex) array cast to type T.

Source

pub fn group(&self, name: &str) -> Result<&[u32]>

Get group member indices (always u32).

Source

pub fn dpg<T: Pod>(&self, group: &str, name: &str) -> Result<TypedView2D<'_, T>>

Get a DPG (data-per-group) array cast to type T.

Source

pub fn dps_names(&self) -> Vec<&str>

List DPS field names.

Source

pub fn dpv_names(&self) -> Vec<&str>

List DPV field names.

Source

pub fn group_names(&self) -> Vec<&str>

List group names.

Source

pub fn dpg_group_names(&self) -> Vec<&str>

List DPG group names.

Source

pub fn iter_dps(&self) -> impl Iterator<Item = (&str, DataArrayInfo)> + '_

Source

pub fn iter_dpv(&self) -> impl Iterator<Item = (&str, DataArrayInfo)> + '_

Source

pub fn iter_groups(&self) -> impl Iterator<Item = (&str, &[u32])> + '_

Iterate over groups, yielding (name, &[u32]) pairs.

§Safety note

This performs a raw byte reinterpretation via cast_slice::<u32>(). If the on-disk group dtype is not uint32 (e.g. int64), the returned slice will contain mangled values. Prefer [group_entries_owned] which handles dtype conversion correctly.

Source

pub fn dpg_entries(&self, group: &str) -> Result<Vec<(String, DataArrayInfo)>>

Source

pub fn dps_info(&self, name: &str) -> Result<DataArrayInfo>

Source

pub fn dps_array(&self, name: &str) -> Result<&DataArray>

Source

pub fn dpv_info(&self, name: &str) -> Result<DataArrayInfo>

Source

pub fn dpv_array(&self, name: &str) -> Result<&DataArray>

Source

pub fn group_info(&self, name: &str) -> Result<DataArrayInfo>

Source

pub fn group_array(&self, name: &str) -> Result<&DataArray>

Source

pub fn dpg_info(&self, group: &str, name: &str) -> Result<DataArrayInfo>

Source

pub fn dpg_array(&self, group: &str, name: &str) -> Result<&DataArray>

Source

pub fn scalar_dps_f32(&self, name: &str) -> Result<Vec<f32>>

Source

pub fn scalar_dpv_f32(&self, name: &str) -> Result<Vec<f32>>

Source

pub fn group_entries_owned(&self) -> Vec<(String, Vec<u32>)>

Source

pub fn load(path: &Path) -> Result<Self>

Load a TRX file from a directory or .trx zip archive.

Source

pub fn save_to_directory(&self, path: &Path) -> Result<()>

Save to a directory. The offsets.* array is written as uint32 if every offset fits in u32, otherwise as uint64.

Source

pub fn save_to_zip(&self, path: &Path) -> Result<()>

Save to a .trx zip archive. All entries are Stored (no compression): DEFLATE rarely pays off on float-heavy tractography data. The offsets.* array width is auto-picked (uint32 if it fits, else uint64).

Source

pub fn save_to_zip_deflate_groups(&self, path: &Path) -> Result<()>

Save to a .trx zip archive, applying DEFLATE only to groups/ entries. Everything else is Stored.

Source

pub fn save_to_zip_stored(&self, path: &Path) -> Result<()>

Deprecated alias for [save_to_zip] — kept for backward compatibility.

Source

pub fn save(&self, path: &Path) -> Result<()>

Save — auto-detects format from extension (.trx = zip, otherwise directory).

Source

pub fn is_file_backed(&self) -> bool

Trait Implementations§

Source§

impl<P: TrxScalar> Debug for TrxFile<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: TrxScalar> From<&TrxFile<P>> for Tractogram

Source§

fn from(value: &TrxFile<P>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<P> Freeze for TrxFile<P>

§

impl<P> RefUnwindSafe for TrxFile<P>
where P: RefUnwindSafe,

§

impl<P> Send for TrxFile<P>
where P: Send,

§

impl<P> Sync for TrxFile<P>
where P: Sync,

§

impl<P> Unpin for TrxFile<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for TrxFile<P>

§

impl<P> UnwindSafe for TrxFile<P>
where P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.