bevy_gaussian_splatting icon indicating copy to clipboard operation
bevy_gaussian_splatting copied to clipboard

convert higher degree SH to lower degree SH

Open github-actions[bot] opened this issue 6 months ago • 1 comments

https://github.com/mosure/bevy_gaussian_splatting/blob/507a28dda771518415d762f85db7607ea60bfbe8/src/io/ply.rs#L65



    fn set_property(&mut self, key: String, property: Property) {
        match (key.as_ref(), property) {
            ("x", Property::Float(v))           => self.position_visibility.position[0] = v,
            ("y", Property::Float(v))           => self.position_visibility.position[1] = v,
            ("z", Property::Float(v))           => self.position_visibility.position[2] = v,
            ("f_dc_0", Property::Float(v))      => self.spherical_harmonic.set(0, v),
            ("f_dc_1", Property::Float(v))      => self.spherical_harmonic.set(1, v),
            ("f_dc_2", Property::Float(v))      => self.spherical_harmonic.set(2, v),
            ("scale_0", Property::Float(v))     => self.scale_opacity.scale[0] = v,
            ("scale_1", Property::Float(v))     => self.scale_opacity.scale[1] = v,
            ("scale_2", Property::Float(v))     => self.scale_opacity.scale[2] = v,
            ("opacity", Property::Float(v))     => self.scale_opacity.opacity = 1.0 / (1.0 + (-v).exp()),
            ("rot_0", Property::Float(v))       => self.rotation.rotation[0] = v,
            ("rot_1", Property::Float(v))       => self.rotation.rotation[1] = v,
            ("rot_2", Property::Float(v))       => self.rotation.rotation[2] = v,
            ("rot_3", Property::Float(v))       => self.rotation.rotation[3] = v,
            (_, Property::Float(v)) if key.starts_with("f_rest_") => {
                let i = key[7..].parse::<usize>().unwrap();

                // interleaved
                // if (i + 3) < SH_COEFF_COUNT {
                //     self.spherical_harmonic.coefficients[i + 3] = v;
                // }

                // planar
                let channel = i / SH_COEFF_COUNT_PER_CHANNEL;
                let coefficient = if SH_COEFF_COUNT_PER_CHANNEL == 1 {
                    1
                } else {
                    (i % (SH_COEFF_COUNT_PER_CHANNEL - 1)) + 1
                };

                let interleaved_idx = coefficient * SH_CHANNELS + channel;

                if interleaved_idx < SH_COEFF_COUNT {
                    self.spherical_harmonic.set(interleaved_idx, v);
                } else {
                    // TODO: convert higher degree SH to lower degree SH
                }
            }
            (_, _) => {},

github-actions[bot] avatar Jan 02 '24 07:01 github-actions[bot]