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