Skip to main content

BasicModifier

Struct BasicModifier 

Source
pub struct BasicModifier<G: GaussianPod, S = NoSelection> {
    pub transform_flags_buffer: TransformFlagsBuffer,
    pub basic_color_modifiers_buffer: BasicColorModifiersBuffer,
    pub rot_scale_buffer: RotScaleBuffer,
    pub modifier: BasicModifierBundle<G, S>,
}
Expand description

A struct to handle basic modifier.

This modifier holds a BasicModifierBundle along with necessary buffers, and applies the basic modifier.

Fields§

§transform_flags_buffer: TransformFlagsBuffer§basic_color_modifiers_buffer: BasicColorModifiersBuffer§rot_scale_buffer: RotScaleBuffer§modifier: BasicModifierBundle<G, S>

Implementations§

Source§

impl<G: GaussianPod> BasicModifier<G>

Source

pub fn new( device: &Device, gaussians_buffer: &GaussiansBuffer<G>, model_transform_buffer: &ModelTransformBuffer, gaussian_transform_buffer: &GaussianTransformBuffer, ) -> Self

Create a new basic modifier.

Examples found in repository?
examples/modify.rs (lines 115-120)
76async fn main() {
77    env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
78
79    let args = Args::parse();
80    let model_path = &args.model;
81
82    log::debug!("Creating wgpu instance");
83    let instance =
84        wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle_from_env());
85
86    log::debug!("Requesting adapter");
87    let adapter = instance
88        .request_adapter(&wgpu::RequestAdapterOptions::default())
89        .await
90        .expect("adapter");
91
92    log::debug!("Requesting device");
93    let (device, queue) = adapter
94        .request_device(&wgpu::DeviceDescriptor {
95            label: Some("Device"),
96            required_limits: adapter.limits(),
97            ..Default::default()
98        })
99        .await
100        .expect("device");
101
102    log::debug!("Creating gaussians");
103    let gaussians = [
104        gs::core::GaussiansSource::Ply,
105        gs::core::GaussiansSource::Spz,
106    ]
107    .into_iter()
108    .find_map(|source| gs::core::Gaussians::read_from_file(model_path, source).ok())
109    .expect("gaussians");
110
111    log::debug!("Creating editor");
112    let editor = gs::Editor::<GaussianPod>::new(&device, &gaussians);
113
114    log::debug!("Creating basic modifier");
115    let basic_modifier = gs::BasicModifier::<GaussianPod>::new(
116        &device,
117        &editor.gaussians_buffer,
118        &editor.model_transform_buffer,
119        &editor.gaussian_transform_buffer,
120    );
121
122    log::debug!("Configuring modifiers");
123    basic_modifier.basic_color_modifiers_buffer.update(
124        &queue,
125        match args.override_rgb {
126            true => gs::BasicColorRgbOverrideOrHsvModifiersPod::new_rgb_override,
127            false => gs::BasicColorRgbOverrideOrHsvModifiersPod::new_hsv_modifiers,
128        }(Vec3::from_slice(&args.rgb_or_hsv)),
129        args.alpha,
130        args.contrast,
131        args.exposure,
132        args.gamma,
133    );
134
135    log::info!("Starting editing process");
136    let time = std::time::Instant::now();
137
138    log::debug!("Editing Gaussians");
139    let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
140        label: Some("Edit Encoder"),
141    });
142
143    editor.apply(
144        &device,
145        &mut encoder,
146        [&basic_modifier as &dyn gs::Modifier<GaussianPod>],
147    );
148
149    queue.submit(Some(encoder.finish()));
150
151    device
152        .poll(wgpu::PollType::wait_indefinitely())
153        .expect("poll");
154
155    log::info!("Editing process completed in {:?}", time.elapsed());
156
157    log::debug!("Downloading Gaussians");
158    let modified_gaussians = editor
159        .gaussians_buffer
160        .download_gaussians(&device, &queue)
161        .await
162        .map(|gs| {
163            match &args.output[args.output.len().saturating_sub(4)..] {
164                ".ply" => {
165                    gs::core::Gaussians::Ply(gs::core::PlyGaussians::from_iter(gs.into_iter()))
166                }
167                ".spz" => {
168                    gs::core::Gaussians::Spz(
169                        gs::core::SpzGaussians::from_gaussians_with_options(
170                            gs,
171                            &gs::core::SpzGaussiansFromGaussianSliceOptions {
172                                version: 2, // Version 2 is more widely supported as of now
173                                ..Default::default()
174                            },
175                        )
176                        .expect("SpzGaussians from gaussians"),
177                    )
178                }
179                _ => panic!("Unsupported output file extension, expected .ply or .spz"),
180            }
181        })
182        .expect("gaussians download");
183
184    log::debug!("Writing modified Gaussians to output file");
185    modified_gaussians
186        .write_to_file(&args.output)
187        .expect("write modified Gaussians to output file");
188
189    log::info!("Modified Gaussians written to {}", args.output);
190}
Source§

impl<G: GaussianPod> BasicModifier<G, WithSelection>

Source

pub fn new_with_selection( device: &Device, gaussians_buffer: &GaussiansBuffer<G>, model_transform_buffer: &ModelTransformBuffer, gaussian_transform_buffer: &GaussianTransformBuffer, selection_buffer: &SelectionBuffer, ) -> Self

Create a new basic modifier with selection.

Trait Implementations§

Source§

impl<G: Debug + GaussianPod, S: Debug> Debug for BasicModifier<G, S>

Source§

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

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

impl<G: GaussianPod, S> Modifier<G> for BasicModifier<G, S>

Source§

fn apply( &self, device: &Device, encoder: &mut CommandEncoder, gaussians: &GaussiansBuffer<G>, model_transform: &ModelTransformBuffer, gaussian_transform: &GaussianTransformBuffer, )

Apply the modifier to the Gaussians.

Auto Trait Implementations§

§

impl<G, S> Freeze for BasicModifier<G, S>

§

impl<G, S = NoSelection> !RefUnwindSafe for BasicModifier<G, S>

§

impl<G, S> Send for BasicModifier<G, S>
where S: Send,

§

impl<G, S> Sync for BasicModifier<G, S>
where S: Sync,

§

impl<G, S> Unpin for BasicModifier<G, S>
where G: Unpin, S: Unpin,

§

impl<G, S> UnsafeUnpin for BasicModifier<G, S>

§

impl<G, S = NoSelection> !UnwindSafe for BasicModifier<G, S>

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> 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, 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,