Skip to content

Commit 1a87c95

Browse files
committed
add webinar code sample
1 parent d981889 commit 1a87c95

File tree

8 files changed

+313
-0
lines changed

8 files changed

+313
-0
lines changed

docs/tutorials/s00_point_cloud.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import dash
2+
import dash_html_components as html
3+
import dash_vtk
4+
import random
5+
6+
xyz = []
7+
for i in range(10000):
8+
xyz.append(random.random()) # x
9+
xyz.append(random.random()) # y
10+
xyz.append(random.random() * 0.01) # z
11+
12+
content = dash_vtk.View(
13+
children=[
14+
dash_vtk.GeometryRepresentation(
15+
property={ 'pointSize': 3 },
16+
children=[dash_vtk.PolyData(points=xyz, connectivity='points')],
17+
),
18+
],
19+
)
20+
21+
# Dash setup
22+
app = dash.Dash(__name__)
23+
server = app.server
24+
25+
app.layout = html.Div(
26+
style={"width": "100%", "height": "calc(100vh - 15px)"},
27+
children=[content],
28+
)
29+
30+
if __name__ == "__main__":
31+
app.run_server(debug=True)
32+
33+
34+

docs/tutorials/s01_mesh.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import dash
2+
import dash_html_components as html
3+
import dash_vtk
4+
5+
content = dash_vtk.View([
6+
dash_vtk.GeometryRepresentation(
7+
children=[
8+
dash_vtk.PolyData(
9+
points=[
10+
0, 0, 0,
11+
1, 0, 0,
12+
0, 1, 0,
13+
1, 1, 0,
14+
],
15+
lines=[3, 1, 3, 2],
16+
polys=[3, 0, 1, 2],
17+
),
18+
],
19+
),
20+
])
21+
22+
# Dash setup
23+
app = dash.Dash(__name__)
24+
server = app.server
25+
app.layout = html.Div(
26+
style={"width": "100%", "height": "calc(100vh - 15px)"},
27+
children=[content],
28+
)
29+
30+
if __name__ == "__main__":
31+
app.run_server(debug=True)

docs/tutorials/s02_mesh_field.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import dash
2+
import dash_html_components as html
3+
4+
import dash_vtk
5+
6+
content = dash_vtk.View([
7+
dash_vtk.GeometryRepresentation(
8+
children=[
9+
dash_vtk.PolyData(
10+
points=[
11+
0, 0, 0,
12+
1, 0, 0,
13+
0, 1, 0,
14+
1, 1, 0,
15+
],
16+
lines=[3, 1, 3, 2],
17+
polys=[3, 0, 1, 2],
18+
children=[
19+
dash_vtk.PointData([
20+
dash_vtk.DataArray(
21+
registration='setScalars',
22+
name='onPoints',
23+
values=[0, 0.33, 0.66, 1],
24+
)
25+
]),
26+
dash_vtk.CellData([
27+
dash_vtk.DataArray(
28+
# registration='setScalars',
29+
name='onCells',
30+
values=[0, 1],
31+
)
32+
])
33+
],
34+
),
35+
],
36+
),
37+
])
38+
39+
# Dash setup
40+
app = dash.Dash(__name__)
41+
server = app.server
42+
43+
app.layout = html.Div(
44+
style={"width": "100%", "height": "calc(100vh - 15px)"},
45+
children=[content],
46+
)
47+
48+
if __name__ == "__main__":
49+
app.run_server(debug=True)

docs/tutorials/s03_volume.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import dash
2+
import random
3+
import dash_html_components as html
4+
import dash_vtk
5+
6+
field = [random.random()*i for i in range(10*10*10)]
7+
8+
content = dash_vtk.View([
9+
dash_vtk.VolumeRepresentation([
10+
dash_vtk.VolumeController(),
11+
dash_vtk.ImageData(
12+
dimensions=[10, 10, 10],
13+
spacing=[1,1,1],
14+
origin=[-4,-4,-4],
15+
children=[
16+
dash_vtk.PointData([
17+
dash_vtk.DataArray(
18+
registration='setScalars',
19+
values=field,
20+
)
21+
])
22+
],
23+
),
24+
]),
25+
])
26+
27+
# Dash setup
28+
app = dash.Dash(__name__)
29+
server = app.server
30+
31+
app.layout = html.Div(
32+
style={"width": "100%", "height": "calc(100vh - 15px)"},
33+
children=[content],
34+
)
35+
36+
if __name__ == "__main__":
37+
app.run_server(debug=True)

docs/tutorials/s04_slice.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import dash
2+
import random
3+
import dash_html_components as html
4+
import dash_vtk
5+
6+
field = [random.random()*i for i in range(10*10*10)]
7+
8+
content = dash_vtk.View([
9+
dash_vtk.SliceRepresentation(
10+
property={'colorWindow':500, 'colorLevel':200},
11+
iSlice=5,
12+
children=[
13+
dash_vtk.ImageData(
14+
dimensions=[10, 10, 10],
15+
spacing=[1, 1, 1],
16+
origin=[-4, -4, -4],
17+
children=[
18+
dash_vtk.PointData([
19+
dash_vtk.DataArray(
20+
registration='setScalars',
21+
values=field,
22+
)
23+
])
24+
],
25+
),
26+
],
27+
),
28+
])
29+
30+
# Dash setup
31+
app = dash.Dash(__name__)
32+
server = app.server
33+
34+
app.layout = html.Div(
35+
style={"width": "100%", "height": "calc(100vh - 15px)"},
36+
children=[content],
37+
)
38+
39+
if __name__ == "__main__":
40+
app.run_server(debug=True)

docs/tutorials/s05_volume_slice.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import dash
2+
import random
3+
import dash_html_components as html
4+
import dash_vtk
5+
6+
field = [random.random()*i for i in range(10*10*10)]
7+
8+
content = dash_vtk.View([
9+
dash_vtk.VolumeRepresentation([
10+
dash_vtk.VolumeController(),
11+
dash_vtk.ShareDataSet([
12+
dash_vtk.ImageData(
13+
dimensions=[10, 10, 10],
14+
spacing=[1, 1, 1],
15+
origin=[-4, -4, -4],
16+
children=[
17+
dash_vtk.PointData([
18+
dash_vtk.DataArray(
19+
registration='setScalars',
20+
values=field,
21+
)
22+
])
23+
],
24+
),
25+
]),
26+
]),
27+
dash_vtk.SliceRepresentation(
28+
property={'colorWindow':500, 'colorLevel':200},
29+
iSlice=5,
30+
children=[dash_vtk.ShareDataSet()],
31+
),
32+
])
33+
34+
# Dash setup
35+
app = dash.Dash(__name__)
36+
server = app.server
37+
38+
app.layout = html.Div(
39+
style={"width": "100%", "height": "calc(100vh - 15px)"},
40+
children=[content],
41+
)
42+
43+
if __name__ == "__main__":
44+
app.run_server(debug=True)

docs/tutorials/s06_vtk_mesh.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import vtk
2+
import os
3+
import dash
4+
import dash_vtk
5+
from dash_vtk.utils import to_mesh_state
6+
import dash_html_components as html
7+
8+
repo_path = os.path.dirname(os.path.dirname(
9+
os.path.dirname(os.path.abspath(__file__))))
10+
head_vti = os.path.join(repo_path, 'demos', 'data', 'head.vti')
11+
12+
# Load dataset from dist
13+
reader = vtk.vtkXMLImageDataReader()
14+
reader.SetFileName(head_vti)
15+
reader.Update()
16+
17+
# Extract iso-mesh from image
18+
contour = vtk.vtkContourFilter()
19+
contour.SetInputConnection(reader.GetOutputPort())
20+
contour.SetNumberOfContours(1)
21+
contour.SetValue(0, 1500)
22+
contour.Update()
23+
24+
# Get mesh to dash_vtk
25+
mesh_state = to_mesh_state(contour.GetOutput())
26+
27+
content = dash_vtk.View([
28+
dash_vtk.GeometryRepresentation([
29+
dash_vtk.Mesh(state=mesh_state)
30+
]),
31+
])
32+
33+
# Dash setup
34+
app = dash.Dash(__name__)
35+
server = app.server
36+
app.layout = html.Div(
37+
style={"width": "100%", "height": "calc(100vh - 15px)"},
38+
children=[content],
39+
)
40+
41+
if __name__ == "__main__":
42+
app.run_server(debug=True)

docs/tutorials/s07_vtk_volume.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import vtk
2+
import os
3+
import dash
4+
import dash_vtk
5+
from dash_vtk.utils import to_volume_state
6+
import dash_html_components as html
7+
8+
repo_path = os.path.dirname(os.path.dirname(
9+
os.path.dirname(os.path.abspath(__file__))))
10+
head_vti = os.path.join(repo_path, 'demos', 'data', 'head.vti')
11+
12+
# Load dataset from dist
13+
reader = vtk.vtkXMLImageDataReader()
14+
reader.SetFileName(head_vti)
15+
reader.Update()
16+
17+
# Get mesh to dash_vtk
18+
volume_state = to_volume_state(reader.GetOutput())
19+
20+
content = dash_vtk.View([
21+
dash_vtk.VolumeRepresentation([
22+
dash_vtk.VolumeController(),
23+
dash_vtk.Volume(state=volume_state)
24+
]),
25+
])
26+
27+
# Dash setup
28+
app = dash.Dash(__name__)
29+
server = app.server
30+
app.layout = html.Div(
31+
style={"width": "100%", "height": "calc(100vh - 15px)"},
32+
children=[content],
33+
)
34+
35+
if __name__ == "__main__":
36+
app.run_server(debug=True)

0 commit comments

Comments
 (0)