I followed your suggestion @jourdain and modified the synthetic-volume-rendering example.
In principle, I managed to render my data. However, there is a number of things I can’t figure out:
- How can I use variables
mesh_x
, mesh_y
, mesh_z
to define the dimensions of the mesh? The spacing
property of dash_vtk.VolumeDataRepresentation
does not seem to help.
- Is it possible to hard-set the range for the legend/colour coding? The interactive tool is nice and useful for some situations but not so much for my use-case.
- How would I render similar data but in cylindrical mesh? E.i. instead of
mesh_x,y,z
I would have mesh_r,z,theta
.
Is there any resource you could point me to? I feel a bit overwhelmed by all the VTK libraries available (vtk, vtk-js, react-vtk-js). For example, I was searching for ‘VolumeDataRepresentation’ in vtk-js API docs but could not find it.
Thanks for help!
Attaching my code…
import numpy as np
import dash
import dash_vtk
import dash_html_components as html
# scalar field to render
scalar_field = np.array([
[[np.nan, np.nan],
[ np.nan, np.nan],
[ np.nan, np.nan],
[1.79262189e+11, 2.18837278e+11]],
[[np.nan, np.nan],
[ np.nan, np.nan],
[1.64769069e+11, 2.45624800e+11],
[1.32300079e+11, 2.02066001e+11]],
[[np.nan, np.nan],
[ np.nan, np.nan],
[1.78280539e+11, 2.30927911e+11],
[1.22644125e+11, 1.86903883e+11]],
[[np.nan, np.nan],
[1.75734696e+11, 2.11878382e+11],
[1.23296506e+11, 1.91324625e+11],
[1.19355336e+11, 2.19288506e+11]],
[[1.57526826e+11, 1.90905892e+11],
[1.49056114e+11, 1.76250712e+11],
[1.37917697e+11, 2.42316416e+11],
[1.44338944e+11, 2.04583689e+11]],
[[1.45091530e+11, 1.83404823e+11],
[1.41719705e+11, 1.98748866e+11],
[1.53608949e+11, 2.24170679e+11],
[1.50438981e+11, 2.31340499e+11]]
])
# coordinates of mesh nodes in cm
mesh_x = np.array([-169.5, -166.7, -163.9, -161.0, -158.2, -155.4, -152.6])
mesh_y = np.array([-167.1, -164.4, -161.6, -158.8, -156.0])
mesh_z = np.array([792.5, 794.6, 796.7])
app = dash.Dash(__name__)
server = app.server
volume_view = dash_vtk.View(
children=dash_vtk.VolumeDataRepresentation(
dimensions=[scalar_field.shape[2], scalar_field.shape[1], scalar_field.shape[0]],
scalars=np.log10(scalar_field.flatten())
)
)
app.layout = html.Div(
style={"height": "calc(100vh - 16px)"},
children=[
html.Div(children=volume_view, style={"height": "100%", "width": "100%"})
],
)
if __name__ == "__main__":
app.run_server(debug=True, port=8051)