Skip to content

Commit 0aa1d48

Browse files
Merge pull request #16 from TileDB-Inc/mbrs-visualization
MBRS visualization added
2 parents bc5cc7a + 0cf3287 commit 0aa1d48

File tree

16 files changed

+6673
-6059
lines changed

16 files changed

+6673
-6059
lines changed

README.md

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
[![Build Status](https://dev.azure.com/TileDB-Inc/CI/_apis/build/status/TileDB-Inc.TileDB-PyBabylonJS?branchName=main)](https://dev.azure.com/TileDB-Inc/CI/_build/latest?definitionId=37&branchName=main)
66

77

8-
BabylonJS widget
8+
The TileDB-PyBabylonJS library is a geospatial data visualization Python library that interactively visualizes TileDB arrays with [Babylon.js](https://www.babylonjs.com) in a Jupyter notebook widget.
99

1010
## Installation
1111

12-
You can install using `pip`:
12+
This project is available from [PyPI](https://pypi.org/project/pybabylonjs/) and can be installed with `pip`:
13+
You can install using `pip`:`
1314

1415
```bash
1516
pip install pybabylonjs
@@ -29,21 +30,21 @@ conda create -n pybabylonjs-dev -c conda-forge nodejs yarn python jupyterlab
2930
conda activate pybabylonjs-dev
3031
```
3132

32-
Install the python. This will also build the TS package.
33+
Fork or clone the repo. Install the Python package. This will also build the TS package.
3334
```bash
3435
pip install -e ".[test, examples]"
3536
```
3637

3738
When developing your extensions, you need to manually enable your extensions with the
38-
notebook / lab frontend. For lab, this is done by the command:
39+
notebook / lab frontend. For jupyter lab, this is done by the command:
3940

4041
```
4142
jupyter labextension install @jupyter-widgets/jupyterlab-manager
4243
yarn run build
4344
jupyter labextension install .
4445
```
4546

46-
For classic notebook, you need to run:
47+
For a classic notebook, you need to run:
4748

4849
```
4950
jupyter nbextension install --sys-prefix --symlink --overwrite --py pybabylonjs
@@ -71,3 +72,63 @@ After a change wait for the build to finish and then refresh your browser and th
7172

7273
#### Python:
7374
If you make a change to the python code then you will need to restart the notebook kernel to have it take effect.
75+
76+
## Usage
77+
78+
Currently two data visualizations are supported for LiDAR point clouds:
79+
80+
* 3D point cloud visualization
81+
* 3D MBRS visualization
82+
83+
Full examples can be found it the example notebooks [here]](https://github.com/TileDB-Inc/TileDB-PyBabylonJS/tree/main/examples).
84+
85+
### 3D point cloud visualization
86+
87+
To create this visualization load a slice of the data and create a dictionary with the coordinates of the points and the RGB values:
88+
89+
```python
90+
from pybabylonjs import Show as show
91+
92+
with tiledb.open("autzen1") as arr:
93+
df = pd.DataFrame(arr[636800:637800, 851000:853000, 406.14:615.26])
94+
95+
data = {
96+
'X': df['X'],
97+
'Y': df['Y'],
98+
'Z': df['Z'],
99+
'Red': df['Red'] / 255.0,
100+
'Green': df['Green'] / 255.0,
101+
'Blue': df['Blue'] / 255.0
102+
}
103+
```
104+
105+
Visualize the 3D point cloud with `pybabylonjs.Show.from_dict()` by specifying `data` and the `style` to use. Optional parameters are the `width` and `height` of the frame, the scaling factor `z_scale` of the z-axis and the wheel precision `wheel_precision`:
106+
107+
```python
108+
show.from_dict(data=data,
109+
style = 'pointcloud',
110+
width = 800,
111+
height = 600,
112+
z_scale = .3,
113+
wheel_precision = 50)
114+
```
115+
116+
This creates an interactive visualization in a notebook widget of which the below is a screenshot:
117+
118+
<img src="examples/pointcloud.png" width="400" height="300" />
119+
120+
### 3D MBRS visualization
121+
122+
This visualization is created directly from a sparse array by specifying the `array`, the style as `mbrs` and optional `height` and `width` parameters:
123+
124+
```python
125+
show.from_array(array='autzen',
126+
style='mbrs',
127+
width=800,
128+
height=600,
129+
z_scale = 0.5)
130+
```
131+
132+
Which creates the below interactive visualization in a notebook widget of which the below is a screenshot:
133+
134+
<img src="examples/mbrs.png" width="400" height="300" />

examples/gltf.ipynb

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "b69d7104-541f-474d-b30d-06a83c4d120e",
6+
"metadata": {},
7+
"source": [
8+
"# GLTF -> TileDB demo\n",
9+
"\n",
10+
"We will start by importing the required libraries;"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "c9da5366-077c-40c8-b136-816ee9ddab9c",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"import json\n",
21+
"import numpy as np\n",
22+
"from pybabylonjs import Show as show\n",
23+
"import tiledb"
24+
]
25+
},
26+
{
27+
"cell_type": "markdown",
28+
"id": "570ce59b-1968-439b-ae7e-f9a4840031dd",
29+
"metadata": {},
30+
"source": [
31+
"The BabylonJS viewer reads GLTF so we will read the FBX file as a GLTF model"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"id": "b73aebb0-fed5-4b62-b87a-9d2c9d94bf0f",
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"with open(\"gltf/farmhouse.gltf\") as f:\n",
42+
" gltf_data = f.read()"
43+
]
44+
},
45+
{
46+
"cell_type": "markdown",
47+
"id": "f4839324-1a52-408f-a25b-1771235a38ec",
48+
"metadata": {},
49+
"source": [
50+
"Create a point cloud ground surface for this building"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": null,
56+
"id": "8530408b-6d1c-4ca8-97ce-be8dc98b2450",
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"# create surface for model\n",
61+
"(minx, maxx), (miny, maxy), (minz, maxz) = ((-80, 80), (-150, 150), (-30, 40))\n",
62+
"extent = 50.\n",
63+
"num_vals = 1000\n",
64+
"\n",
65+
"xs = np.random.default_rng().uniform(minx - extent, maxx + extent, num_vals)\n",
66+
"ys = np.random.default_rng().uniform(miny - extent, maxy + extent, num_vals)\n",
67+
"zs = np.random.default_rng().uniform(-5., 0., num_vals)\n",
68+
"\n",
69+
"data = {\n",
70+
" \"X\": xs,\n",
71+
" \"Y\": ys,\n",
72+
" \"Z\": zs,\n",
73+
" \"Red\": np.random.default_rng().uniform(0., 1., num_vals),\n",
74+
" \"Green\": np.random.default_rng().uniform(0., 1., num_vals),\n",
75+
" \"Blue\": np.random.default_rng().uniform(0., 1., num_vals)\n",
76+
"}"
77+
]
78+
},
79+
{
80+
"cell_type": "markdown",
81+
"id": "99f1d235-a073-47b8-9ae6-a0b5a1730cc0",
82+
"metadata": {},
83+
"source": [
84+
"And render;"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": null,
90+
"id": "36c4d496-2bf8-40e0-92ca-944d08c9c191",
91+
"metadata": {},
92+
"outputs": [],
93+
"source": [
94+
"show.from_dict(data=data,\n",
95+
" style = 'pointcloud',\n",
96+
" gltf_data = gltf_data,\n",
97+
" point_size = 5)"
98+
]
99+
}
100+
],
101+
"metadata": {
102+
"kernelspec": {
103+
"display_name": "Python 3 (ipykernel)",
104+
"language": "python",
105+
"name": "python3"
106+
},
107+
"language_info": {
108+
"codemirror_mode": {
109+
"name": "ipython",
110+
"version": 3
111+
},
112+
"file_extension": ".py",
113+
"mimetype": "text/x-python",
114+
"name": "python",
115+
"nbconvert_exporter": "python",
116+
"pygments_lexer": "ipython3",
117+
"version": "3.10.2"
118+
}
119+
},
120+
"nbformat": 4,
121+
"nbformat_minor": 5
122+
}

examples/gltf/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Farmhouse data from https://open3dmodel.com/3d-models/fbx

examples/gltf/farmhouse.gltf

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

examples/introduction.ipynb

Lines changed: 0 additions & 162 deletions
This file was deleted.

examples/mbrs.png

376 KB
Loading

examples/pointcloud.png

1.07 MB
Loading

examples/points.pickle

-77.7 MB
Binary file not shown.

0 commit comments

Comments
 (0)