pub trait WriteIterGaussian: IterGaussian {
// Required method
fn write_to(&self, writer: &mut impl Write) -> Result<()>;
// Provided method
fn write_to_file(&self, path: impl AsRef<Path>) -> Result<()> { ... }
}Expand description
A trait of representing a IterGaussian that can be written to a buffer.
Required Methods§
Provided Methods§
Sourcefn write_to_file(&self, path: impl AsRef<Path>) -> Result<()>
fn write_to_file(&self, path: impl AsRef<Path>) -> Result<()>
Write to a file.
Examples found in repository?
examples/write_ply.rs (line 51)
12fn main() {
13 let model_path = std::env::args()
14 .nth(1)
15 .unwrap_or_else(|| "target/output.ply".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 let gaussians = gs::PlyGaussians::from(
42 gaussians
43 .iter()
44 .map(gs::Gaussian::to_ply)
45 .collect::<Vec<_>>(),
46 );
47
48 println!("Writing {} gaussians to {}", gaussians.0.len(), model_path);
49
50 gaussians
51 .write_to_file(&model_path)
52 .expect("write PLY file");
53}More examples
examples/write_spz.rs (line 60)
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}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.