3d geometry made easy.
Project description
Visu3d
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 usemy_field: Any = v3d.array_field(shape=, dtype=)
instead ofdataclasses.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file visu3d-1.1.0.tar.gz
.
File metadata
- Download URL: visu3d-1.1.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f7ac882cc97ce56b75d40fdf67af2f770772c068d046884f0adc0a0b37be5c4 |
|
MD5 | b0870e223a283002b272940185ebc278 |
|
BLAKE2b-256 | 76eb3b6005e98585470c273317b0d5c5f207344aa0879e62018752a2d6d16986 |
File details
Details for the file visu3d-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: visu3d-1.1.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97c76e7a54b256808495a900010b1c24c4b74fb5ca659bfe4fbeaf61249b1732 |
|
MD5 | 5a4ae9e58e053ce0c864d10ddade9649 |
|
BLAKE2b-256 | d6bd273d66b93e68ec15257d48e34c9e9640ddd2c65775a280484917ab1aa8a1 |