Skip to main content

3d geometry made easy.

Project description

Visu3d

Unittests PyPI version

visu3d is a Python library offering:

  • An API to make @dataclass behave like array.
  • Standard primitives for 3d geometry (Ray, Camera, Transform,...).

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])

Same code seamlessly works across Jax, TensorFlow, Numpy.

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 = v3d.array_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.

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.0.0.tar.gz (4.4 MB view details)

Uploaded Source

Built Distribution

visu3d-1.0.0-py3-none-any.whl (90.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: visu3d-1.0.0.tar.gz
  • Upload date:
  • Size: 4.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for visu3d-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d12a3a5e268fa550c9a221cfc786e5686e3044f03181921c6f886325dd5fa718
MD5 98ed05ecebc18a6d449d82ee51d3d1c9
BLAKE2b-256 f9752f584d01a9ef7190e7db2185cf9b914ea2eee873c87e8016cf7e6488f460

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visu3d-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 90.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for visu3d-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f04346c8f5219ad46ac6523a339e6898e6b9d5be523e7b2cff7504e0dae06973
MD5 42cd452391c2f63251c9fae5f55948bf
BLAKE2b-256 1de55f6c6f5a57d4c1ad4e89c42ca57c366b681b64f999bdab160e54d23ae8d7

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