SpzGaussians

Struct SpzGaussians 

Source
pub struct SpzGaussians {
    pub header: SpzGaussiansHeader,
    pub positions: SpzGaussiansPositions,
    pub scales: Vec<[u8; 3]>,
    pub rotations: SpzGaussiansRotations,
    pub alphas: Vec<u8>,
    pub colors: Vec<[u8; 3]>,
    pub shs: SpzGaussiansShs,
}
Expand description

A collection of Gaussians in SPZ format.

Fields§

§header: SpzGaussiansHeader§positions: SpzGaussiansPositions§scales: Vec<[u8; 3]>

(x, y, z) each as 8-bit log-encoded integer.

§rotations: SpzGaussiansRotations§alphas: Vec<u8>

8-bit unsigned integer.

§colors: Vec<[u8; 3]>

(r, g, b) each as 8-bit unsigned integer.

§shs: SpzGaussiansShs

Implementations§

Source§

impl SpzGaussians

Source

pub fn len(&self) -> usize

Get the number of Gaussians.

Source

pub fn is_empty(&self) -> bool

Check if there are no Gaussians.

Source

pub fn read_decompressed(reader: &mut impl Read) -> Result<Self, Error>

Read a SPZ from a decompressed buffer.

reader should be decompressed SPZ buffer.

Source

pub fn read_header(reader: &mut impl Read) -> Result<SpzGaussiansHeader, Error>

Read a SPZ header.

reader should be decompressed SPZ buffer.

Source

pub fn read_gaussians( reader: &mut impl Read, header: SpzGaussiansHeader, ) -> Result<Self, Error>

Read the SPZ Gaussians.

reader should be decompressed SPZ buffer positioned after the header.

header may be parsed by calling SpzGaussians::read_header.

Source

pub fn write_decompressed(&self, writer: &mut impl Write) -> Result<(), Error>

Write the Gaussians to a SPZ buffer.

writer will receive the decompressed SPZ buffer.

Source

pub fn from_gaussians( gaussians: impl IntoIterator<Item = impl AsRef<Gaussian>>, ) -> Self

Convert from a slice of Gaussians.

Source

pub fn from_gaussians_with_options( gaussians: impl IntoIterator<Item = impl AsRef<Gaussian>>, options: &SpzGaussiansFromGaussianSliceOptions, ) -> Result<Self, Error>

Convert from a slice of Gaussians with options.

Examples found in repository?
examples/write_spz.rs (lines 42-48)
12fn main() {
13    let model_path = std::env::args()
14        .nth(1)
15        .unwrap_or_else(|| "target/output.spz".to_string());
16
17    let gaussians = [
18        gs::Gaussian {
19            rot: Quat::from_axis_angle((Vec3::X + Vec3::Y / 2.0 + Vec3::Z).normalize(), 0.5),
20            pos: Vec3::ZERO,
21            scale: Vec3::new(0.5, 1.0, 0.75),
22            color: U8Vec4::new(255, 0, 0, 255),
23            sh: [Vec3::ZERO; 15],
24        },
25        gs::Gaussian {
26            rot: Quat::from_axis_angle((Vec3::X + Vec3::Z / 3.0).normalize(), 0.3),
27            pos: Vec3::new(0.0, 8.0, 4.0),
28            scale: Vec3::new(1.0, 1.9, 0.75),
29            color: U8Vec4::new(0, 255, 0, 255),
30            sh: [Vec3::ZERO; 15],
31        },
32        gs::Gaussian {
33            rot: Quat::from_axis_angle((Vec3::X - Vec3::Z).normalize(), 0.2),
34            pos: Vec3::new(4.0, 0.0, 6.0),
35            scale: Vec3::new(1.0, 1.1, 0.8),
36            color: U8Vec4::new(0, 0, 255, 255),
37            sh: [Vec3::ZERO; 15],
38        },
39    ];
40
41    // Alternatively, use `SpzGaussians::from_gaussians` for default options.
42    let gaussians = gs::SpzGaussians::from_gaussians_with_options(
43        gaussians.as_slice(),
44        &gs::SpzGaussiansFromGaussianSliceOptions {
45            version: 2,
46            ..Default::default()
47        },
48    )
49    .expect("valid options");
50
51    println!("Header: {:?}", gaussians.header);
52
53    println!(
54        "Writing {} gaussians to {}",
55        gaussians.header.num_points(),
56        model_path
57    );
58
59    gaussians
60        .write_to_file(&model_path)
61        .expect("write SPZ file");
62}
Source

pub fn from_iter( header: SpzGaussiansHeader, iter: impl IntoIterator<Item = SpzGaussian>, ) -> Result<Self, SpzGaussiansFromIterError>

Convert from an IntoIterator of SpzGaussians.

Source

pub fn iter<'a>( &'a self, ) -> impl ExactSizeIterator<Item = SpzGaussianRef<'a>> + 'a

Get an iterator over Gaussian references.

Trait Implementations§

Source§

impl Clone for SpzGaussians

Source§

fn clone(&self) -> SpzGaussians

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpzGaussians

Source§

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

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

impl From<SpzGaussians> for Gaussians

Source§

fn from(value: SpzGaussians) -> Self

Converts to this type from the input type.
Source§

impl<G: AsRef<Gaussian>> FromIterator<G> for SpzGaussians

Source§

fn from_iter<T: IntoIterator<Item = G>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl IterGaussian for SpzGaussians

Source§

fn iter_gaussian(&self) -> impl ExactSizeIterator<Item = Gaussian> + '_

Iterate over Gaussian.
Source§

impl PartialEq for SpzGaussians

Source§

fn eq(&self, other: &SpzGaussians) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ReadIterGaussian for SpzGaussians

Source§

fn read_from(reader: &mut impl BufRead) -> Result<Self>

Read from a buffer.
Source§

fn read_from_file(path: impl AsRef<Path>) -> Result<Self>

Read from a file.
Source§

impl WriteIterGaussian for SpzGaussians

Source§

fn write_to(&self, writer: &mut impl Write) -> Result<()>

Write to a buffer.
Source§

fn write_to_file(&self, path: impl AsRef<Path>) -> Result<()>

Write to a file.
Source§

impl StructuralPartialEq for SpzGaussians

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,