Hi all,
First of all, thanks for creating Dash. It is very useful.
What I am trying to do is use Dash to do some mesh manipulations interactively. The mesh is in obj
format and so I decided to use dash-vtk
. I started with the demo apps and could do simple reading and visualization. But when I try to, for example, scale it, the mesh just disappears.
Here’s the code I used. I used the slider to control the scale factor.
import dash
import dash_vtk
import dash_bootstrap_components as dbc
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
from pyvista import examples
from vtk.util.numpy_support import vtk_to_numpy
# Get point cloud data from PyVista
uniformGrid = examples.download_crater_topo()
subset = uniformGrid.extract_subset((500, 900, 400, 800, 0, 0), (5, 5, 1))
def updateWarp(factor=1):
terrain = subset.warp_by_scalar()
polydata = terrain.extract_geometry()
points = polydata.points.ravel() * factor
polys = vtk_to_numpy(polydata.GetPolys().GetData())
return (points, polys)
points, polys = updateWarp(1)
# Setup VTK rendering of PointCloud
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server
vtk_view = dash_vtk.View(
id="vtk-view",
children=[
dash_vtk.GeometryRepresentation(
id="vtk-representation",
children=[
dash_vtk.PolyData(
id="vtk-polydata",
points=points,
polys=polys,
)
],
),
],
)
app.layout = dbc.Container(
fluid=True,
style={"height": "100vh"},
children=[
dbc.Row(
[
dbc.Col(
children=dcc.Slider(
id="scale-factor",
min=0.1,
max=5,
step=0.1,
value=1,
marks={0.1: "0.1", 5: "5"},
)
),
],
style={"height": "12%", "alignItems": "center"},
),
html.Div(
html.Div(vtk_view, style={"height": "100%", "width": "100%"}),
style={"height": "88%"},
),
],
)
@app.callback(
[
Output("vtk-polydata", "points"),
Output("vtk-polydata", "polys"),
],
[
Input("scale-factor", "value"),
],
)
def updatePresetName(scale_factor):
points, polys = updateWarp(scale_factor)
return (
points,
polys,
)
if __name__ == "__main__":
app.run_server(debug=True)