Skip to main content

3d geometry made easy.

Project description

visu3d - 3D geometry made easy

Unittests PyPI version

visu3d is an abstraction layer between TF/Jax/Numpy and your program. It provides:

  • Standard primitives for 3d geometry (Ray, Camera, Transform,...). You can combine those standard primitives with your custom ones.
  • Everything is trivially visualizable with zero boilerplate. Inspect & debug camera poses, trajectories,...
  • All primitives are dataclass_array, dataclasses which can be reshaped, sliced,... as if they were numpy arrays.
  • Everything is extensible, you can gradually opt-in only for the features you need, and replace any standard primitive by your custom ones.

Core features

Everything is a v3d.DataclassArray: dataclass behave like np.array (with indexing, slicing, shape manipulation, vectorization,...).

# Single ray
ray = v3d.Ray(pos=[0, 0, 0], dir=[1, 1, 1])
assert rays.shape == ()

# Multiple rays batched together
rays = v3d.Ray(pos=np.zeros((B, H, W, 3)), dir=np.ones((B, H, W, 3)))
assert rays.shape == (B, H, W)

rays = rays.reshape('b h w -> b (h w)')  #  Native `einops` support

top_left_ray = rays[..., 0, 0]  #  (b, h, w) -> (b,)

rays = rays.flatten()
rays = rays[rays.norm() > 0]  # Filter invalid rays

Everything is visualizable interactively

Every object has a .fig property for interactive visualization:

rays.fig  # Plot the rays

Display multiple objects together:

v3d.make_fig([cam, rays, point_cloud])

Auto-plot figures with Colab magic:

v3d.auto_plot_figs()  # Once at the start of the Colab

cam, rays, point_cloud  # Tuple auto-displayed without `v3d.make_fig` call

Same code seamlessly works across Jax, TensorFlow, Numpy (please help us for torch support).

rays = rays.as_jax()  # .as_tf(), as_np(), .as_jax()
assert isinstance(rays.pos, jnp.ndarray)
assert rays.xnp is jnp

rays = rays.as_tf()
assert isinstance(rays.pos, tf.Tensor)
assert rays.xnp is tf.experimental.numpy

With native support for auto-diff, jax.vmap, jax.tree_utils,...

Privitives

Common primitives (Ray, Camera, Transform,...), so user can express intent, instead of math.

H, W = (256, 1024)
cam_spec = v3d.PinholeCamera.from_focal(
    resolution=(H, W),
    focal_in_px=35.,
)
cam = v3d.Camera.from_look_at(
    spec=cam_spec,
    pos=[5, 5, 5],
    target=[0, 0, 0],  # Camera looks at the scene center
)

rays = cam.rays()  # Rays in world coordinates

# Project `(*shape, 3)` world coordinates into `(*shape, 2)` pixel coordinates.
px_coords = cam.px_from_world @ point_cloud

See the API for a full list of primitive.

Creating your own primitives is trivial.

Converting any dataclass to dataclass array is trivial:

  • Inherit from v3d.DataclassArray
  • Use etils.array_types to annotate the array fields (or exlicitly use my_field: Any = dca.field(shape=, dtype=) instead of dataclasses.field)
from etils.array_types import FloatArray


@dataclasses.dataclass(frozen=True)
class MyRay(v3d.DataclassArray):
  pos: FloatArray[..., 3]
  dir: FloatArray[..., 3]


rays = MyRay(pos=jnp.zeros((H, W, 3)), dir=jnp.ones((H, W, 3)))
assert rays.shape == (H, W)

v3d makes it easy to opt-in to the feature you need by implementing the corresponding protocol.

Documentation

The best way to get started is to try the Colab tutorials (in the docs/):

Installation:

pip install visu3d

Usage:

import visu3d as v3d

Installation

pip install visu3d

This is not an official Google product.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

visu3d-1.3.0.tar.gz (39.0 kB view details)

Uploaded Source

Built Distribution

visu3d-1.3.0-py3-none-any.whl (60.7 kB view details)

Uploaded Python 3

File details

Details for the file visu3d-1.3.0.tar.gz.

File metadata

  • Download URL: visu3d-1.3.0.tar.gz
  • Upload date:
  • Size: 39.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for visu3d-1.3.0.tar.gz
Algorithm Hash digest
SHA256 8b3350f8e58b69c47693cfcc1b0a5a773796d224e26ded920a04076d467cd71b
MD5 dab3f8b3b795d83822a67681165f1959
BLAKE2b-256 f5961f8bf9f7df5e91c4a71564a673c875068c9e89cbc32bbefcf0fad7ce60a6

See more details on using hashes here.

File details

Details for the file visu3d-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: visu3d-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 60.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for visu3d-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22e6328b6c461fb9650ada045c764dbf7a0c0a5ec9f77354e3053b804a12bf3c
MD5 645f28d7f7c7f3cd7bb350a793510547
BLAKE2b-256 79ecdb1ad063841cf5c21686821345d9df9a90d81793eaa61c0d43b908908c04

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page