visu3d


Namevisu3d JSON
Version 1.5.3 PyPI version JSON
download
home_page
Summary3d geometry made easy.
upload_time2023-07-26 16:06:06
maintainer
docs_urlNone
author
requires_python>=3.9
license
keywords 3d visu3d visualization neural rendering nerf
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # visu3d - 3D geometry made easy

[![Unittests](https://github.com/google-research/visu3d/actions/workflows/pytest_and_autopublish.yml/badge.svg)](https://github.com/google-research/visu3d/actions/workflows/pytest_and_autopublish.yml)
[![PyPI version](https://badge.fury.io/py/visu3d.svg)](https://badge.fury.io/py/visu3d)
[![Documentation Status](https://readthedocs.org/projects/visu3d/badge/?version=latest)](https://visu3d.readthedocs.io/en/latest/?badge=latest)

`visu3d` is an abstraction layer between Torch/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`](https://github.com/google-research/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

<section class="zippy">

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

```python
# 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
```

</section>
<section class="zippy">

Everything is **visualizable interactively**

Every object has a `.fig` property for interactive visualization:

```python
rays.fig  # Plot the rays
```

Display multiple objects together:

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

Auto-plot figures with Colab magic:

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

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

</section>
<section class="zippy">

Same code seamlessly **works across Torch, Jax, TensorFlow, Numpy**.

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

rays = rays.as_torch()
assert isinstance(rays.pos, torch.Tensor)
assert rays.xnp is torch
```

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

</section>

### Privitives

<section class="zippy">

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

```python
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](https://github.com/google-research/visu3d/tree/main/visu3d/__init__.py)<!-- {.external} !-->
for a full list of primitive.

</section>
<section class="zippy">

Creating your own primitives is trivial.

Converting any dataclass to dataclass array is trivial:

*   Inherit from `v3d.DataclassArray`
*   Use
    [`etils.array_types`](https://github.com/google/etils/blob/main/etils/array_types/README.md)
    to annotate the array fields (or exlicitly use `my_field: Any =
    dca.field(shape=, dtype=)` instead of `dataclasses.field`)

```python
from etils.array_types import FloatArray


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.

<!-- See [the tutorial]() for more info. -->

</section>

### Documentation

The best way to get started is to try the Colab tutorials (in the
[documentation](https://visu3d.readthedocs.io/)):

*   [Intro](https://visu3d.readthedocs.io/en/latest/intro.html) ([Colab](https://colab.research.google.com/github/google-research/visu3d/blob/main/docs/intro.ipynb))
    <!-- {.external} !-->
*   [Transform](https://visu3d.readthedocs.io/en/latest/transform.html) ([Colab](https://colab.research.google.com/github/google-research/visu3d/blob/main/docs/transform.ipynb))
    <!-- {.external} !-->
*   [Create your primitives](https://visu3d.readthedocs.io/en/latest/dataclass.html) ([Colab](https://colab.research.google.com/github/google-research/visu3d/blob/main/docs/dataclass.ipynb))
    <!-- {.external} !-->

Installation:

```sh
pip install visu3d
```

Usage:

```python
import visu3d as v3d
```

## Installation

```sh
pip install visu3d
```

*This is not an official Google product.*


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "visu3d",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "3d,visu3d,visualization,neural rendering,nerf",
    "author": "",
    "author_email": "Visu3d team <visu3d@google.com>",
    "download_url": "https://files.pythonhosted.org/packages/ab/48/c052e6df66e5079009871f6722ab9b0acccfa66ea5522961ba7dace9c290/visu3d-1.5.3.tar.gz",
    "platform": null,
    "description": "# visu3d - 3D geometry made easy\n\n[![Unittests](https://github.com/google-research/visu3d/actions/workflows/pytest_and_autopublish.yml/badge.svg)](https://github.com/google-research/visu3d/actions/workflows/pytest_and_autopublish.yml)\n[![PyPI version](https://badge.fury.io/py/visu3d.svg)](https://badge.fury.io/py/visu3d)\n[![Documentation Status](https://readthedocs.org/projects/visu3d/badge/?version=latest)](https://visu3d.readthedocs.io/en/latest/?badge=latest)\n\n`visu3d` is an abstraction layer between Torch/TF/Jax/Numpy and your program.\nIt provides:\n\n*   Standard primitives for 3d geometry (`Ray`, `Camera`, `Transform`,...).\n    You can combine those standard primitives with your custom ones.\n*   Everything is trivially visualizable with zero boilerplate. Inspect & debug\n    camera poses, trajectories,...\n*   All primitives are\n    [`dataclass_array`](https://github.com/google-research/dataclass_array),\n    dataclasses which can be reshaped, sliced,... as if they were numpy arrays.\n*   Everything is extensible, you can gradually opt-in only for the features you\n    need, and replace any standard primitive by your custom ones.\n\n### Core features\n\n<section class=\"zippy\">\n\nEverything is a `v3d.DataclassArray`: **dataclass behave like `np.array`** (with\nindexing, slicing, shape manipulation, vectorization,...).\n\n```python\n# Single ray\nray = v3d.Ray(pos=[0, 0, 0], dir=[1, 1, 1])\nassert rays.shape == ()\n\n# Multiple rays batched together\nrays = v3d.Ray(pos=np.zeros((B, H, W, 3)), dir=np.ones((B, H, W, 3)))\nassert rays.shape == (B, H, W)\n\nrays = rays.reshape('b h w -> b (h w)')  #  Native `einops` support\n\ntop_left_ray = rays[..., 0, 0]  #  (b, h, w) -> (b,)\n\nrays = rays.flatten()\nrays = rays[rays.norm() > 0]  # Filter invalid rays\n```\n\n</section>\n<section class=\"zippy\">\n\nEverything is **visualizable interactively**\n\nEvery object has a `.fig` property for interactive visualization:\n\n```python\nrays.fig  # Plot the rays\n```\n\nDisplay multiple objects together:\n\n```python\nv3d.make_fig([cam, rays, point_cloud])\n```\n\nAuto-plot figures with Colab magic:\n\n```python\nv3d.auto_plot_figs()  # Once at the start of the Colab\n\ncam, rays, point_cloud  # Tuple auto-displayed without `v3d.make_fig` call\n```\n\n</section>\n<section class=\"zippy\">\n\nSame code seamlessly **works across Torch, Jax, TensorFlow, Numpy**.\n\n```python\nrays = rays.as_jax()  # .as_tf(), as_np(), .as_jax()\nassert isinstance(rays.pos, jnp.ndarray)\nassert rays.xnp is jnp\n\nrays = rays.as_torch()\nassert isinstance(rays.pos, torch.Tensor)\nassert rays.xnp is torch\n```\n\nWith native support for auto-diff, `jax.vmap`, `jax.tree_utils`,...\n\n</section>\n\n### Privitives\n\n<section class=\"zippy\">\n\nCommon primitives (`Ray`, `Camera`, `Transform`,...), so user can express\nintent, instead of math.\n\n```python\nH, W = (256, 1024)\ncam_spec = v3d.PinholeCamera.from_focal(\n    resolution=(H, W),\n    focal_in_px=35.,\n)\ncam = v3d.Camera.from_look_at(\n    spec=cam_spec,\n    pos=[5, 5, 5],\n    target=[0, 0, 0],  # Camera looks at the scene center\n)\n\nrays = cam.rays()  # Rays in world coordinates\n\n# Project `(*shape, 3)` world coordinates into `(*shape, 2)` pixel coordinates.\npx_coords = cam.px_from_world @ point_cloud\n```\n\nSee [the API](https://github.com/google-research/visu3d/tree/main/visu3d/__init__.py)<!-- {.external} !-->\nfor a full list of primitive.\n\n</section>\n<section class=\"zippy\">\n\nCreating your own primitives is trivial.\n\nConverting any dataclass to dataclass array is trivial:\n\n*   Inherit from `v3d.DataclassArray`\n*   Use\n    [`etils.array_types`](https://github.com/google/etils/blob/main/etils/array_types/README.md)\n    to annotate the array fields (or exlicitly use `my_field: Any =\n    dca.field(shape=, dtype=)` instead of `dataclasses.field`)\n\n```python\nfrom etils.array_types import FloatArray\n\n\nclass MyRay(v3d.DataclassArray):\n  pos: FloatArray[..., 3]\n  dir: FloatArray[..., 3]\n\n\nrays = MyRay(pos=jnp.zeros((H, W, 3)), dir=jnp.ones((H, W, 3)))\nassert rays.shape == (H, W)\n```\n\n`v3d` makes it easy to opt-in to the feature you need by implementing the\ncorresponding protocol.\n\n<!-- See [the tutorial]() for more info. -->\n\n</section>\n\n### Documentation\n\nThe best way to get started is to try the Colab tutorials (in the\n[documentation](https://visu3d.readthedocs.io/)):\n\n*   [Intro](https://visu3d.readthedocs.io/en/latest/intro.html) ([Colab](https://colab.research.google.com/github/google-research/visu3d/blob/main/docs/intro.ipynb))\n    <!-- {.external} !-->\n*   [Transform](https://visu3d.readthedocs.io/en/latest/transform.html) ([Colab](https://colab.research.google.com/github/google-research/visu3d/blob/main/docs/transform.ipynb))\n    <!-- {.external} !-->\n*   [Create your primitives](https://visu3d.readthedocs.io/en/latest/dataclass.html) ([Colab](https://colab.research.google.com/github/google-research/visu3d/blob/main/docs/dataclass.ipynb))\n    <!-- {.external} !-->\n\nInstallation:\n\n```sh\npip install visu3d\n```\n\nUsage:\n\n```python\nimport visu3d as v3d\n```\n\n## Installation\n\n```sh\npip install visu3d\n```\n\n*This is not an official Google product.*\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "3d geometry made easy.",
    "version": "1.5.3",
    "project_urls": {
        "changelog": "https://github.com/google-research/visu3d/blob/main/CHANGELOG.md",
        "documentation": "https://visu3d.readthedocs.io",
        "homepage": "https://github.com/google-research/visu3d",
        "repository": "https://github.com/google-research/visu3d"
    },
    "split_keywords": [
        "3d",
        "visu3d",
        "visualization",
        "neural rendering",
        "nerf"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8b33d1a3feedec734e56ebb171c5fdf3ac6d1a509751b67f962b0bf7f6ca6b32",
                "md5": "65f8f615e35ce8894b8d18d1dd260654",
                "sha256": "16564695d365911ffc9900c8c786d7c91c7abea1fa7907f62553136250da4289"
            },
            "downloads": -1,
            "filename": "visu3d-1.5.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "65f8f615e35ce8894b8d18d1dd260654",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 49432,
            "upload_time": "2023-07-26T16:06:05",
            "upload_time_iso_8601": "2023-07-26T16:06:05.340969Z",
            "url": "https://files.pythonhosted.org/packages/8b/33/d1a3feedec734e56ebb171c5fdf3ac6d1a509751b67f962b0bf7f6ca6b32/visu3d-1.5.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ab48c052e6df66e5079009871f6722ab9b0acccfa66ea5522961ba7dace9c290",
                "md5": "5783b272c9e85733f6832dc35a77562e",
                "sha256": "8bcf1f935d4ca45becad745edf83840ac544476c7feed047a20db13657ea49f5"
            },
            "downloads": -1,
            "filename": "visu3d-1.5.3.tar.gz",
            "has_sig": false,
            "md5_digest": "5783b272c9e85733f6832dc35a77562e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 34450,
            "upload_time": "2023-07-26T16:06:06",
            "upload_time_iso_8601": "2023-07-26T16:06:06.831505Z",
            "url": "https://files.pythonhosted.org/packages/ab/48/c052e6df66e5079009871f6722ab9b0acccfa66ea5522961ba7dace9c290/visu3d-1.5.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-26 16:06:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "google-research",
    "github_project": "visu3d",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "visu3d"
}
        
Elapsed time: 0.19121s