def build_view_child(dimensions, spacing, origin, field, enabled, i, j, k, window, level): slice_prop = {"colorWindow": window, "colorLevel": level} child = [ dash_vtk.ShareDataSet( dash_vtk.ImageData( dimensions=dimensions, spacing=spacing, origin=origin, children=dash_vtk.PointData( dash_vtk.DataArray(registration="setScalars", values=field)), ), ), ] if "Volume" in enabled: child.append( dash_vtk.VolumeRepresentation( [dash_vtk.VolumeController(), dash_vtk.ShareDataSet()], )) if "i" in enabled: child.append( dash_vtk.SliceRepresentation( iSlice=int(round(i)), property=slice_prop, children=dash_vtk.ShareDataSet(), )) if "j" in enabled: child.append( dash_vtk.SliceRepresentation( jSlice=int(round(j)), property=slice_prop, children=dash_vtk.ShareDataSet(), )) if "k" in enabled: child.append( dash_vtk.SliceRepresentation( kSlice=int(round(k)), property=slice_prop, children=dash_vtk.ShareDataSet(), )) return child
import dash_vtk content = dash_vtk.View([ dash_vtk.VolumeRepresentation([ # GUI to control Volume Rendering # + Setup good default at startup dash_vtk.VolumeController(), # Actual Imagedata dash_vtk.ImageData( dimensions=[5, 5, 5], origin=[-2, -2, -2], spacing=[1, 1, 1], children=[ dash_vtk.PointData([ dash_vtk.DataArray( registration="setScalars", values=list(range(5*5*5)), ) ]) ], ), ]), ]) # Dash setup app = dash.Dash(__name__) server = app.server app.layout = html.Div( style={"width": "100%", "height": "calc(100vh - 15px)"},
field = [random.random() * i for i in range(10 * 10 * 10)] content = dash_vtk.View( [ dash_vtk.VolumeRepresentation( [ dash_vtk.VolumeController(), dash_vtk.ShareDataSet( [ dash_vtk.ImageData( dimensions=[10, 10, 10], spacing=[1, 1, 1], origin=[-4, -4, -4], children=[ dash_vtk.PointData( [ dash_vtk.DataArray( registration="setScalars", values=field, ) ] ) ], ), ] ), ] ), dash_vtk.SliceRepresentation( property={"colorWindow": 500, "colorLevel": 200}, iSlice=5, children=[dash_vtk.ShareDataSet()], ),
field = fd.u origin = [fd.x.mean(), fd.y.mean(), fd.z.mean()] ranges = np.array([axis.ptp() for axis in [fd.x, fd.y, fd.z]]) dimensions = np.array( [np.unique(axis).shape[0] for axis in [fd.x, fd.y, fd.z]]) x, y, z = dimensions spacing = np.round(ranges / dimensions).astype(int) content = dash_vtk.View( dash_vtk.VolumeRepresentation([ dash_vtk.VolumeController(), dash_vtk.ImageData( dimensions=dimensions, spacing=spacing, origin=origin, children=dash_vtk.PointData( dash_vtk.DataArray(registration="setScalars", values=field)), ), ])) # Dash setup app = dash.Dash(__name__) server = app.server app.layout = html.Div( style={ "width": "100%", "height": "calc(100vh - 15px)" }, children=[content],