Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
413 changes: 15 additions & 398 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/spz-pywrapper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ name = "spz"
crate-type = ["cdylib"]

[dependencies]
spz = { version = "0.0.6", default-features = false, features = [] }
spz = { path = "../spz", default-features = false, features = [] }
pyo3 = { version = "0.27", default-features = true, features = [] }

[dev-dependencies]
63 changes: 33 additions & 30 deletions crates/spz-pywrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn coord_sys_to_str(cs: &spz_rs::CoordinateSystem) -> &'static str {
#[pyclass(eq, frozen)]
#[derive(Clone, PartialEq)]
pub struct CoordinateSystem {
inner: spz_rs::CoordinateSystem,
inner: spz_rs::coord::CoordinateSystem,
}

#[pymethods]
Expand All @@ -62,7 +62,7 @@ impl CoordinateSystem {
#[allow(non_snake_case)]
fn LDB() -> Self {
Self {
inner: spz_rs::CoordinateSystem::LDB,
inner: spz_rs::coord::CoordinateSystem::LDB,
}
}

Expand All @@ -71,7 +71,7 @@ impl CoordinateSystem {
#[allow(non_snake_case)]
fn RDB() -> Self {
Self {
inner: spz_rs::CoordinateSystem::RDB,
inner: spz_rs::coord::CoordinateSystem::RDB,
}
}

Expand All @@ -80,7 +80,7 @@ impl CoordinateSystem {
#[allow(non_snake_case)]
fn LUB() -> Self {
Self {
inner: spz_rs::CoordinateSystem::LUB,
inner: spz_rs::coord::CoordinateSystem::LUB,
}
}

Expand All @@ -89,7 +89,7 @@ impl CoordinateSystem {
#[allow(non_snake_case)]
fn RUB() -> Self {
Self {
inner: spz_rs::CoordinateSystem::RUB,
inner: spz_rs::coord::CoordinateSystem::RUB,
}
}

Expand All @@ -98,7 +98,7 @@ impl CoordinateSystem {
#[allow(non_snake_case)]
fn LDF() -> Self {
Self {
inner: spz_rs::CoordinateSystem::LDF,
inner: spz_rs::coord::CoordinateSystem::LDF,
}
}

Expand All @@ -107,7 +107,7 @@ impl CoordinateSystem {
#[allow(non_snake_case)]
fn RDF() -> Self {
Self {
inner: spz_rs::CoordinateSystem::RDF,
inner: spz_rs::coord::CoordinateSystem::RDF,
}
}

Expand All @@ -116,7 +116,7 @@ impl CoordinateSystem {
#[allow(non_snake_case)]
fn LUF() -> Self {
Self {
inner: spz_rs::CoordinateSystem::LUF,
inner: spz_rs::coord::CoordinateSystem::LUF,
}
}

Expand All @@ -125,7 +125,7 @@ impl CoordinateSystem {
#[allow(non_snake_case)]
fn RUF() -> Self {
Self {
inner: spz_rs::CoordinateSystem::RUF,
inner: spz_rs::coord::CoordinateSystem::RUF,
}
}

Expand All @@ -134,7 +134,7 @@ impl CoordinateSystem {
#[allow(non_snake_case)]
fn UNSPECIFIED() -> Self {
Self {
inner: spz_rs::CoordinateSystem::UNSPECIFIED,
inner: spz_rs::coord::CoordinateSystem::UNSPECIFIED,
}
}
/*
Expand Down Expand Up @@ -213,7 +213,7 @@ impl BoundingBox {
#[pyclass]
#[derive(Clone)]
pub struct GaussianSplat {
inner: spz_rs::GaussianSplat,
inner: spz_rs::gaussian_splat::GaussianSplat,
}

#[pymethods]
Expand Down Expand Up @@ -321,7 +321,7 @@ impl GaussianSplat {
None => vec![0.0_f32; expected_sh_len],
};
Ok(Self {
inner: spz_rs::GaussianSplat {
inner: spz_rs::gaussian_splat::GaussianSplat {
num_points: num_points as i32,
spherical_harmonics_degree: sh_degree,
antialiased,
Expand Down Expand Up @@ -352,15 +352,16 @@ impl GaussianSplat {
fn load(path: &str, coordinate_system: Option<CoordinateSystem>) -> PyResult<Self> {
let coord_sys = coordinate_system
.map(|cs| cs.inner)
.unwrap_or(spz_rs::CoordinateSystem::UNSPECIFIED);
.unwrap_or(spz_rs::coord::CoordinateSystem::UNSPECIFIED);

let unpack_opts = spz_rs::UnpackOptions {
let unpack_opts = spz_rs::unpacked::UnpackOptions {
to_coord_sys: coord_sys,
};
let inner = spz_rs::GaussianSplat::load_packed_from_file(path, &unpack_opts)
.map_err(|e| {
PyValueError::new_err(format!("Failed to load SPZ file: {}", e))
})?;
let inner = spz_rs::gaussian_splat::GaussianSplat::load_packed_from_file(
path,
&unpack_opts,
)
.map_err(|e| PyValueError::new_err(format!("Failed to load SPZ file: {}", e)))?;

Ok(Self { inner })
}
Expand All @@ -379,18 +380,20 @@ impl GaussianSplat {
fn from_bytes(data: &[u8], coordinate_system: Option<CoordinateSystem>) -> PyResult<Self> {
let coord_sys = coordinate_system
.map(|cs| cs.inner)
.unwrap_or(spz_rs::CoordinateSystem::UNSPECIFIED);
.unwrap_or(spz_rs::coord::CoordinateSystem::UNSPECIFIED);

let unpack_opts = spz_rs::UnpackOptions {
let unpack_opts = spz_rs::unpacked::UnpackOptions {
to_coord_sys: coord_sys,
};
let packed = spz_rs::GaussianSplat::load_packed(data).map_err(|e| {
PyValueError::new_err(format!("Failed to parse SPZ data: {}", e))
})?;
let inner = spz_rs::GaussianSplat::new_from_packed_gaussians(&packed, &unpack_opts)
.map_err(|e| {
PyValueError::new_err(format!("Failed to unpack SPZ data: {}", e))
let packed =
spz_rs::gaussian_splat::GaussianSplat::load_packed(data).map_err(|e| {
PyValueError::new_err(format!("Failed to parse SPZ data: {}", e))
})?;
let inner = spz_rs::gaussian_splat::GaussianSplat::new_from_packed_gaussians(
&packed,
&unpack_opts,
)
.map_err(|e| PyValueError::new_err(format!("Failed to unpack SPZ data: {}", e)))?;

Ok(Self { inner })
}
Expand All @@ -409,9 +412,9 @@ impl GaussianSplat {
) -> PyResult<()> {
let coord_sys = from_coordinate_system
.map(|cs| cs.inner)
.unwrap_or(spz_rs::CoordinateSystem::UNSPECIFIED);
.unwrap_or(spz_rs::coord::CoordinateSystem::UNSPECIFIED);

let pack_opts = spz_rs::PackOptions { from: coord_sys };
let pack_opts = spz_rs::packed::PackOptions { from: coord_sys };

self.inner.save_as_packed(path, &pack_opts).map_err(|e| {
PyValueError::new_err(format!("Failed to save SPZ file: {}", e))
Expand All @@ -434,9 +437,9 @@ impl GaussianSplat {
) -> PyResult<Bound<'py, PyBytes>> {
let coord_sys = from_coordinate_system
.map(|cs| cs.inner)
.unwrap_or(spz_rs::CoordinateSystem::UNSPECIFIED);
.unwrap_or(spz_rs::coord::CoordinateSystem::UNSPECIFIED);

let pack_opts = spz_rs::PackOptions { from: coord_sys };
let pack_opts = spz_rs::packed::PackOptions { from: coord_sys };

let bytes = self
.inner
Expand Down
25 changes: 6 additions & 19 deletions crates/spz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,23 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
rustversion = { version = "1.0", default-features = true, features = [] }
anyhow = { version = "1.0", default-features = true, features = [] }
thiserror = { version = "2.0", default-features = true, features = [] }
clap = { version = "4.5", default-features = true, features = [
"env",
"unicode",
"derive",
] }
memmap2 = { version = "0.9", default-features = true, features = [] }
libc = { version = "0.2", default-features = true, features = [] }
flate2 = { version = "1.1", default-features = true, features = [] }
serde_json = { version = "1.0", default-features = true, features = [
"float_roundtrip",
] }
serde = { version = "1.0", default-features = true, features = ["derive"] }
static_assertions = { version = "1.1", default-features = true, features = [] }
rayon = { version = "1.11", default-features = true, features = [] }
tokio = { version = "1.48", default-features = true, features = ["full"] }
likely_stable = { version = "0.1", default-features = true, features = [] }
arbitrary = { version = "1.4", default-features = true, features = ["derive"] }
arbitrary = { version = "1.4", default-features = true, features = ["derive"], optional = true }
futures = { version = "0.3", default-features = false, features = ["std"] }

[features]
fuzzing = ["dep:arbitrary"]

[dev-dependencies]
criterion = { version = "0.8", default-features = true, features = [
"html_reports",
"async_tokio",
] }
codspeed-criterion-compat = { version = "4.1.0", default-features = true, features = [
"async",
"async_tokio",
] }
codspeed-criterion-compat = { version = "4.1.0", default-features = true, features = [] }
rstest = { version = "0.26", default-features = true, features = [] }
approx = { version = "0.5", default-features = true, features = [] }
rand = { version = "0.9", default-features = true, features = [] }
Expand Down
6 changes: 0 additions & 6 deletions crates/spz/benches/benchmarks/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use codspeed_criterion_compat::Criterion;
use spz::{packed::PackOptions, prelude::GaussianSplat, unpacked::UnpackOptions};
use tokio::runtime::Runtime;

use crate::util;

Expand All @@ -24,12 +23,7 @@ pub fn bench_cloud_load_n(c: &mut Criterion) {
}

pub fn bench_load_packed_from_file(c: &mut Criterion) {
let rt = Runtime::new().unwrap();

c.bench_function("load_packed_from_file", |b| {
b.iter(|| util::load_packed_from_file());
});
c.bench_function("load_packed_from_file_async", |b| {
b.to_async(&rt).iter(|| util::load_packed_from_file_async());
});
}
24 changes: 6 additions & 18 deletions crates/spz/benches/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use anyhow::Result;
use rand::{Rng, SeedableRng, rngs::StdRng};
use spz::{coord::CoordinateSystem, gaussian_splat::GaussianSplat, math, unpacked::UnpackOptions};
use spz::{
coord::CoordinateSystem, errors::SpzError, gaussian_splat::GaussianSplat, math,
unpacked::UnpackOptions,
};

pub fn create_splat(num_points: i32) -> GaussianSplat {
let sh_degree = 2_i32;
Expand Down Expand Up @@ -42,27 +44,13 @@ pub fn create_splat(num_points: i32) -> GaussianSplat {
}
}

pub fn load_packed_from_file() -> Result<GaussianSplat> {
pub fn load_packed_from_file() -> Result<GaussianSplat, SpzError> {
GaussianSplat::builder()
.filepath("../../assets/racoonfamily.spz")
.packed(true)?
.unpack_options(
UnpackOptions::builder()
.to_coord_system(CoordinateSystem::default())
.build(),
)
.load()
}

pub async fn load_packed_from_file_async() -> Result<GaussianSplat> {
GaussianSplat::builder()
.filepath("../../assets/racoonfamily.spz")
.packed(true)?
.unpack_options(
UnpackOptions::builder()
.to_coord_system(CoordinateSystem::default())
.build(),
)
.load_async()
.await
.load("../../assets/racoonfamily.spz")
}
20 changes: 10 additions & 10 deletions crates/spz/examples/load_spz.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

use std::path::{Path, PathBuf};
use std::path::PathBuf;

use anyhow::Result;
use spz::{coord::CoordinateSystem, gaussian_splat::GaussianSplat, unpacked::UnpackOptions};
use spz::{
coord::CoordinateSystem, errors::SpzError, gaussian_splat::GaussianSplat,
unpacked::UnpackOptions,
};

fn main() -> Result<()> {
fn main() -> Result<(), SpzError> {
let mut sample_spz = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
sample_spz.push("assets/racoonfamily.spz");

let _gs = GaussianSplat::builder()
.filepath(sample_spz)
.packed(true)?
.unpack_options(
UnpackOptions::builder()
.to_coord_system(CoordinateSystem::default())
.build(),
)
.load()?;
.load(sample_spz)?;

Ok(())
}

#[allow(unused)]
async fn load_spz_async<P>(spz_file: P) -> Result<GaussianSplat>
async fn load_spz_async<R>(reader: R) -> Result<GaussianSplat, SpzError>
where
P: AsRef<Path>,
R: futures::io::AsyncRead + Unpin,
{
GaussianSplat::builder()
.filepath(spz_file)
.packed(true)?
.unpack_options(
UnpackOptions::builder()
.to_coord_system(CoordinateSystem::default())
.build(),
)
.load_async()
.load_async(reader)
.await
}
Loading