Py.Cafe

kolibril13/

tutorial_juneE-new

Interactive 3D Voxel Visualization

DocsPricing
  • app.py
  • requirements.txt
  • widget.css
  • widget.js
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import anywidget
from traitlets import  Any
from pathlib import Path
import numpy as np

size = 17


def f(i,j,k):
    return (1+np.cos(i*j*0.1))*0.5

voxelarray = np.fromfunction(f, (size, size, size))

# voxelarray = np.random.rand(size, size, size)

voxelarray_int = np.uint8(voxelarray * 255)

class HelloWidget(anywidget.AnyWidget):
    _esm = Path("widget.js")
    voxel_data = Any().tag(sync=True)


voxel_data_list = voxelarray_int.tolist()

three_viewer = HelloWidget()

three_viewer.voxel_data = voxel_data_list
page = three_viewer