#[non_exhaustive]pub enum Mode {
Int8 = 0,
Int16 = 1,
Float32 = 2,
Int16Complex = 3,
Float32Complex = 4,
Uint16 = 6,
Float16 = 12,
Packed4Bit = 101,
}Expand description
MRC data mode defining the on-disk representation of voxel values.
§Example
use mrc::Mode;
let mode = Mode::Float32;
assert_eq!(mode.byte_size(), 4);
assert!(mode.is_float());
assert!(!mode.is_integer());Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Int8 = 0
Signed 8-bit integer (Mode 0).
Int16 = 1
Signed 16-bit integer (Mode 1).
Float32 = 2
32-bit floating point (Mode 2).
Int16Complex = 3
Complex number with 16-bit integer components (Mode 3)
§Byte Order
The layout is [real i16 (2 bytes), imag i16 (2 bytes)] which matches the
de facto standard used by CCP4, IMOD, and other MRC implementations.
This is not explicitly specified in MRC2014 but is universally adopted.
Float32Complex = 4
Complex number with 32-bit float components (Mode 4)
§Byte Order
The layout is [real f32 (4 bytes), imag f32 (4 bytes)] which matches the
de facto standard used by CCP4, IMOD, and other MRC implementations.
This is not explicitly specified in MRC2014 but is universally adopted.
Uint16 = 6
Unsigned 16-bit integer (Mode 6).
Float16 = 12
16-bit floating point (Mode 12).
Packed4Bit = 101
4-bit data packed two values per byte (Mode 101).
Each byte stores two 4-bit nibbles: low nibble = first pixel,
high nibble = second pixel. Read via slices_u8
or convert::<f32>(); write via
write_u4_block.
Implementations§
Source§impl Mode
impl Mode
Sourcepub const fn as_i32(self) -> i32
pub const fn as_i32(self) -> i32
Return the MRC mode constant as an i32 value.
§Example
use mrc::Mode;
assert_eq!(Mode::Int8.as_i32(), 0);
assert_eq!(Mode::Float32.as_i32(), 2);Sourcepub fn byte_size(&self) -> usize
pub fn byte_size(&self) -> usize
Number of bytes required to store one voxel in this mode.
For Packed4Bit this returns 1 (two voxels per byte);
use byte_size_for_count for per-voxel sizing.
§Example
use mrc::Mode;
assert_eq!(Mode::Int16.byte_size(), 2);
assert_eq!(Mode::Float32Complex.byte_size(), 8);Sourcepub fn is_complex(&self) -> bool
pub fn is_complex(&self) -> bool
Returns true if this mode stores complex numbers (real + imaginary components).
§Example
use mrc::Mode;
assert!(Mode::Int16Complex.is_complex());
assert!(!Mode::Float32.is_complex());Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true if this mode stores integer-valued data (including complex integers).
§Example
use mrc::Mode;
assert!(Mode::Uint16.is_integer());
assert!(!Mode::Float32.is_integer());Sourcepub fn is_float(&self) -> bool
pub fn is_float(&self) -> bool
Returns true if this mode stores floating-point data (including complex float).
§Example
use mrc::Mode;
assert!(Mode::Float16.is_float());
assert!(!Mode::Int8.is_float());Sourcepub fn byte_size_for_count(&self, n: usize) -> usize
pub fn byte_size_for_count(&self, n: usize) -> usize
Byte size for a given number of voxels.
For most modes this is n * byte_size(), but Packed4Bit
stores two voxels per byte so the result is n.div_ceil(2).
§Example
use mrc::Mode;
assert_eq!(Mode::Int16.byte_size_for_count(3), 6);
assert_eq!(Mode::Packed4Bit.byte_size_for_count(3), 2);Trait Implementations§
impl Copy for Mode
impl Eq for Mode
impl StructuralPartialEq for Mode
Auto Trait Implementations§
impl Freeze for Mode
impl RefUnwindSafe for Mode
impl Send for Mode
impl Sync for Mode
impl Unpin for Mode
impl UnsafeUnpin for Mode
impl UnwindSafe for Mode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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