bundle.gs3d.ply =============== .. py:module:: bundle.gs3d.ply .. autoapi-nested-parse:: 3D Gaussian Splatting PLY reader and writer. The 3DGS PLY layout (as produced by inria-graphdeco/gaussian-splatting, 3DGRUT, gsplat, and most other trainers) stores one vertex per Gaussian with the following float32 properties: x, y, z -- centre position nx, ny, nz -- (optional) ignored on read, written as zeros f_dc_0, f_dc_1, f_dc_2 -- spherical-harmonics DC term (RGB) f_rest_0 .. f_rest_44 -- SH degrees 1..3 (3 channels * 15 coefficients) opacity -- logit-space opacity scale_0, scale_1, scale_2 -- log-space anisotropic scale rot_0, rot_1, rot_2, rot_3 -- wxyz quaternion (not normalised) This module reads/writes that format using a numpy structured array. The in-memory container is :class:`GaussianCloudArrays`, a plain dataclass that exists only to wrap the buffer and provide convenience accessors. It is deliberately *not* a :class:`bundle.core.data.Data` subclass — it owns non-JSON-serialisable arrays. Numpy is an optional dependency. Importing this module without numpy installed will raise a helpful :class:`ImportError` only at call time. Attributes ---------- .. autoapisummary:: bundle.gs3d.ply.log Classes ------- .. autoapisummary:: bundle.gs3d.ply.GaussianCloudArrays Functions --------- .. autoapisummary:: bundle.gs3d.ply.sh_rest_count bundle.gs3d.ply.property_names bundle.gs3d.ply.read_ply_header bundle.gs3d.ply.read_ply bundle.gs3d.ply.write_ply Module Contents --------------- .. py:data:: log .. py:function:: sh_rest_count(sh_degree: int) -> int Number of ``f_rest_*`` coefficients for a given SH degree. SH degree N has ``(N+1)**2`` coefficients per channel; the DC term accounts for one of them. Three RGB channels gives the total below. .. py:function:: property_names(sh_degree: int) -> list[str] Ordered PLY property names for a given SH degree. .. py:class:: GaussianCloudArrays In-memory Gaussian splat cloud backed by a numpy structured array. This is intentionally not a ``Data`` subclass: it owns numpy buffers that should never be JSON-serialised. Use :func:`write_ply` to persist. .. attribute:: data Structured array with one record per Gaussian. The dtype is built from :func:`property_names` for the requested SH degree. .. attribute:: sh_degree SH degree the array was allocated for. .. py:attribute:: data :type: numpy.ndarray .. py:attribute:: sh_degree :type: int :value: 3 .. py:method:: empty(count: int, sh_degree: int = 3) -> GaussianCloudArrays :classmethod: Allocate an uninitialised cloud of ``count`` Gaussians. .. py:property:: positions :type: GaussianCloudArrays.positions.np View into ``(N, 3)`` xyz positions. .. py:method:: bbox() -> tuple[tuple[float, float, float], tuple[float, float, float]] Axis-aligned bounding box ``(min_xyz, max_xyz)``. .. py:method:: to_metadata(path: pathlib.Path) -> bundle.gs3d.data.GaussianCloud Build a :class:`GaussianCloud` metadata record for ``path``. .. py:function:: read_ply_header(path: pathlib.Path) -> bundle.gs3d.data.GaussianCloud :async: Read just the PLY header and return a :class:`GaussianCloud` record. This avoids loading the (potentially huge) vertex payload — useful for ``bundle gs3d info`` and other tools that only need metadata. .. py:function:: read_ply(path: pathlib.Path) -> GaussianCloudArrays :async: Read a 3DGS PLY file fully into a :class:`GaussianCloudArrays`. Only binary little-endian PLYs are supported (the universal 3DGS format). .. py:function:: write_ply(path: pathlib.Path, arrays: GaussianCloudArrays) -> bundle.gs3d.data.GaussianCloud :async: Write a :class:`GaussianCloudArrays` to disk in the 3DGS PLY format. Returns the populated :class:`GaussianCloud` metadata record.