Beispiel #1
0
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
Beispiel #2
0
    # Old VTK
    from vtk.vtkImagingCore import vtkRTAnalyticSource

# 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=[
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
            kSlice=47,
            property=slice_property,
            children=dash_vtk.ShareDataSet(),
        ),
    ],
)

volume_view = dash_vtk.View(
    id="volume-view",
    background=[0, 0, 0],
    cameraPosition=[1, 0, 0],
    cameraViewUp=[0, 0, -1],
    cameraParallelProjection=False,
    children=[
        dash_vtk.VolumeRepresentation([
            html.Div(dash_vtk.VolumeController(), style={"display": "none"}),
            dash_vtk.ShareDataSet(),
        ])
    ],
)

app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server

app.layout = dbc.Container(
    fluid=True,
    style={"height": "calc(100vh - 30px)"},
    children=[
        html.Div(
            style={
                "height": "20%",