# Use VTK to get some data data_source = vtkRTAnalyticSource() data_source.Update() # <= Execute source to produce an output dataset = data_source.GetOutput() # Use helper to get a volume structure that can be passed as-is to a Volume volume_state = to_volume_state(dataset) # No need to select field content = dash_vtk.View([ dash_vtk.VolumeRepresentation([ # GUI to control Volume Rendering # + Setup good default at startup dash_vtk.VolumeController(), # Actual volume dash_vtk.ShareDataSet([ dash_vtk.Volume(state=volume_state), ]), ]), dash_vtk.SliceRepresentation(iSlice=10, children=[ dash_vtk.ShareDataSet(), ]), dash_vtk.SliceRepresentation(jSlice=10, children=[ dash_vtk.ShareDataSet(), ]), dash_vtk.SliceRepresentation(kSlice=10, children=[ dash_vtk.ShareDataSet(), ]), ])
import dash_vtk from dash_vtk.utils import to_volume_state # Place a DICOM series (a set of per-file slices) in a directory. ITK sorts, sets spatial metadata, etc. demo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) itk_image = itk.imread(os.path.join(demo_dir, "data", "ct_lung")) # Convert itk.Image to vtkImageData vtk_image = itk.vtk_image_from_image(itk_image) volume_state = to_volume_state(vtk_image) vtk_view = dash_vtk.View( dash_vtk.VolumeRepresentation( children=[dash_vtk.VolumeController(), dash_vtk.Volume(state=volume_state),] ) ) app = dash.Dash(__name__) server = app.server app.layout = html.Div( style={"height": "calc(100vh - 50px)", "width": "100%"}, children=[html.Div(vtk_view, style={"height": "100%", "width": "100%"})], ) if __name__ == "__main__": app.run_server(debug=True)
def dcm_to_volume(dir_path): itk_image = itk.imread(dir_path) vtk_image = itk.vtk_image_from_image(itk_image) volume_state = to_volume_state(vtk_image) return volume_state # Place a DICOM series (a set of per-file slices) in a directory. ITK sorts, sets spatial metadata, etc. demo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) volume_state = dcm_to_volume(os.path.join(demo_dir, "data", "mri_pancreas")) app = dash.Dash(__name__) server = app.server vtk_view = dash_vtk.View( dash_vtk.VolumeRepresentation( [dash_vtk.VolumeController(), dash_vtk.Volume(state=volume_state)] ) ) app.layout = html.Div( style={"height": "calc(100vh - 50px)", "width": "100%"}, children=[html.Div(style={"height": "100%", "width": "100%"}, children=vtk_view)], ) if __name__ == "__main__": app.run_server(debug=True)
children=dbc.Row([ dbc.Col(dbc.FormGroup([dbc.Label(label), component])) for label, component in sliders.items() ]), ) slice_property = {"colorWindow": 4095, "colorLevel": 1000} slice_view = dash_vtk.View( id="slice-view", cameraPosition=[1, 0, 0], cameraViewUp=[0, 0, -1], cameraParallelProjection=False, background=[0.9, 0.9, 1], children=[ dash_vtk.ShareDataSet(dash_vtk.Volume(state=volume_state)), dash_vtk.SliceRepresentation( id="slice-repr-i", iSlice=128, property=slice_property, children=dash_vtk.ShareDataSet(), ), dash_vtk.SliceRepresentation( id="slice-repr-j", jSlice=128, property=slice_property, children=dash_vtk.ShareDataSet(), ), dash_vtk.SliceRepresentation( id="slice-repr-k", kSlice=47,