Пример #1
0
content = dash_vtk.View([
    dash_vtk.GeometryRepresentation(
        children=[
            dash_vtk.PolyData(
                points=[
                  0,0,0,
                  1,0,0,
                  0,1,0,
                  1,1,0,
                ],
                lines=[3, 1, 3, 2],
                polys=[3, 0, 1, 2],
                children=[
                    dash_vtk.PointData([
                        dash_vtk.DataArray(
                            #registration='setScalars', # To activate field
                            name='onPoints',
                            values=[0, 0.33, 0.66, 1],
                        )
                    ]),
                    dash_vtk.CellData([
                        dash_vtk.DataArray(
                            # registration='setScalars', # To activate field
                            name='onCells',
                            values=[0, 1],
                        )
                    ])
                ],
            ),
        ],
    ),
])
Пример #2
0
import dash
import dash_vtk
import dash_html_components as html
from dash.dependencies import Input, Output

# Get it here: https://github.com/plotly/dash-vtk/blob/master/demos/data/cow-nonormals.obj
with open("datasets/cow-nonormals.obj", 'r') as file:
    txt_content = file.read()

view = dash_vtk.View(
    id="click-info-view",
    pickingModes=["click"],
    children=[
        dash_vtk.GeometryRepresentation(id="cow-geometry", children=[
            dash_vtk.Reader(
                vtkClass="vtkOBJReader",
                parseAsText=txt_content,
            ),
        ]),
    ],
)

# Dash setup
app = dash.Dash(__name__)
server = app.server

app.layout = html.Div([
    html.Div(view, style={"width": "100%", "height": "300px"}),
    html.B("Output of clickInfo (try clicking on the object above):"),
    html.Pre(
        id="click-info-output",
        style={'overflowX': 'scroll'}
Пример #3
0
import dash_vtk
from dash_vtk.utils import to_mesh_state

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 mesh structure that can be passed as-is to a Mesh
# RTData is the name of the field
mesh_state = to_mesh_state(dataset)

content = dash_vtk.View([
    dash_vtk.GeometryRepresentation([dash_vtk.Mesh(state=mesh_state)]),
])

# Dash setup
app = dash.Dash(__name__)
server = app.server

app.layout = html.Div(
    style={
        "width": "100%",
        "height": "calc(100vh - 15px)"
    },
    children=[content],
)

if __name__ == "__main__":
Пример #4
0
server = app.server

# -----------------------------------------------------------------------------
# Populate scene
# -----------------------------------------------------------------------------

# vehicle geometry
vehicle_vtk = []
for filename in glob.glob(os.path.join(DATA_PATH, 'vehicle') + '/*.vtp'):
    mesh = _load_vtp(filename)
    part_name = filename.split('/')[-1].replace('.vtp', '')
    child = dash_vtk.GeometryRepresentation(
        id=f"{part_name}-rep",
        colorMapPreset="erdc_rainbow_bright",
        colorDataRange=[0, 100],
        property={'opacity': 1},
        children=[dash_vtk.Mesh(
            id=f"{part_name}-mesh",
            state=mesh,
        )])
    vehicle_vtk.append(child)

# isosurfaces
isosurfs_vtk = []
for filename in glob.glob(os.path.join(DATA_PATH, 'isosurfaces') + '/*.vtp'):
    mesh = _load_vtp(filename)

    surf_name = filename.split('/')[-1].replace('.vtp', '')
    child = dash_vtk.GeometryRepresentation(
        id=f"{surf_name}-rep",
        property={
Пример #5
0
import dash_core_components as dcc
import dash_html_components as html
import vtk
import dash_vtk
from dash_vtk.utils import to_mesh_state

reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName("./data/flow_pyevtk.vtu")
reader.Update()  # Needed because of GetScalarRange
output = reader.GetOutput()

mesh_state = to_mesh_state(reader.GetOutput())
vtk_view = dash_vtk.View(
    id="vtk-view",
    children=[
        dash_vtk.GeometryRepresentation(
            children=[dash_vtk.Mesh(state=mesh_state)], )
    ],
)

app = dash.Dash(__name__, external_stylesheets=[])
app.layout = html.Div(
    style={
        "height": "calc(100vh - 16px)",
        "width": "100%"
    },
    children=[html.Div(vtk_view, style={
        "height": "100%",
        "width": "100%"
    })],
)
Пример #6
0
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,
                    children=[
                        dash_vtk.PointData([
                            dash_vtk.DataArray(
                                id="vtk-array",
                                registration="setScalars",
                                name="elevation",
                                values=elevation,
                            )
                        ])
                    ],
                )
            ],
            colorMapPreset="erdc_blue2green_muted",
            colorDataRange=color_range,
            property={
                "edgeVisibility": True,
            },
        )
    ],
)
Пример #7
0
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server

# -----------------------------------------------------------------------------
# Populate scene
# -----------------------------------------------------------------------------

# vehicle geometry
vehicle_vtk = []
for filename in glob.glob(os.path.join(DATA_PATH, "vehicle") + "/*.vtp"):
    mesh = _load_vtp(filename, point_arrays=['U', 'p'])
    part_name = filename.split("/")[-1].replace(".vtp", "")
    child = dash_vtk.GeometryRepresentation(
        id=f"{part_name}",
        colorMapPreset="erdc_rainbow_bright",
        colorDataRange=[0, 100],
        mapper={"scalarVisibility": False},
        children=[dash_vtk.Mesh(state=mesh, )],
    )
    vehicle_vtk.append(child)

cone_pointer = dash_vtk.GeometryRepresentation(
    property={"color": [1, 0, 0]},
    children=[dash_vtk.Algorithm(id="pointer", vtkClass="vtkConeSource")])

# -----------------------------------------------------------------------------
# 3D Viz
# -----------------------------------------------------------------------------

vtk_view = dash_vtk.View(id="vtk-view",
                         pickingModes=['hover'],
Пример #8
0
 id="vtk-view",
 pickingModes=["hover"],
 children=[
     dash_vtk.GeometryRepresentation(
         id="vtk-representation",
         children=[
             dash_vtk.PolyData(
                 id="vtk-polydata",
                 points=points,
                 polys=polys,
                 children=[
                     dash_vtk.PointData([
                         dash_vtk.DataArray(
                             id="vtk-array",
                             registration="setScalars",
                             name="elevation",
                             values=elevation,
                         )
                     ])
                 ],
             )
         ],
         colorMapPreset="erdc_blue2green_muted",
         colorDataRange=color_range,
         property={"edgeVisibility": True},
         showCubeAxes=True,
         cubeAxesStyle={"axisLabels": ["", "", "Altitude"]},
     ),
     dash_vtk.GeometryRepresentation(
         id="pick-rep",
         actor={"visibility": False},
Пример #9
0
import dash
import dash_html_components as html
import dash_vtk

content = dash_vtk.View(
    [
        dash_vtk.GeometryRepresentation(
            children=[
                dash_vtk.PolyData(
                    points=[0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0,],
                    lines=[3, 1, 3, 2],
                    polys=[3, 0, 1, 2],
                ),
            ],
        ),
    ]
)

# Dash setup
app = dash.Dash(__name__)
server = app.server
app.layout = html.Div(
    style={"width": "100%", "height": "calc(100vh - 15px)"}, children=[content],
)

if __name__ == "__main__":
    app.run_server(debug=True)
Пример #10
0
import dash_vtk

content = dash_vtk.View([
    dash_vtk.GeometryRepresentation(
        mapper={
            'colorByArrayName': 'layer',
            'scalarMode': 4,
            'interpolateScalarsBeforeMapping': False,
        },
        colorMapPreset="jet",
        colorDataRange=[0.2, 0.9],
        children=[
            dash_vtk.Algorithm(
                vtkClass="vtkConcentricCylinderSource",
                state={
                    'height': 0.25,
                    'radius': [0.2, 0.3, 0.4, 0.6, 0.7, 0.8, 0.9, 1],
                    'cellFields': [0, 0.2, 0.4, 0.6, 0.7, 0.8, 0.9, 1],
                    'mask': [1, 0, 1, 0, 1, 0, 1, 1],
                    'resolution': 60,
                    'skipInnerFaces': True,
                    'startTheta': 45,
                    'endTheta': 315,
                    'center': [0, 0, 0.5],
                },
            ),
        ]),
])

# Dash setup
app = dash.Dash(__name__)
 dash_vtk.GeometryRepresentation(
     children=[
         dash_vtk.PolyData(
             points=[
                 0,
                 0,
                 0,
                 1,
                 0,
                 0,
                 0,
                 1,
                 0,
                 1,
                 1,
                 0,
             ],
             lines=[3, 1, 3, 2],
             polys=[3, 0, 1, 2],
             children=[
                 dash_vtk.PointData([
                     dash_vtk.DataArray(
                         registration="setScalars",
                         name="onPoints",
                         values=[0, 0.33, 0.66, 1],
                     )
                 ]),
                 dash_vtk.CellData([
                     dash_vtk.DataArray(
                         # registration='setScalars',
                         name="onCells",
                         values=[0, 1],
                     )
                 ]),
             ],
         ),
     ], ),
Пример #12
0
import dash_core_components as dcc
from dash.dependencies import Input, Output, State

random.seed(42)

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

vtk_view = dash_vtk.View(
    id="geometry-view",
    children=[
        dash_vtk.GeometryRepresentation([
            dash_vtk.Algorithm(
                id="vtk-algorithm",
                vtkClass="vtkConeSource",
                state={
                    "capping": False,
                    "resolution": 60
                },
            )
        ])
    ],
)

controls = dbc.Card([
    dbc.CardHeader("Controls"),
    dbc.CardBody([
        html.P("Resolution:"),
        dcc.Slider(
            id="slider-resolution",
            min=10,
            max=100,
Пример #13
0
import dash
import dash_html_components as html
import dash_vtk
import random

xyz = []
for i in range(10000):
    xyz.append(random.random())  # x
    xyz.append(random.random())  # y
    xyz.append(random.random() * 0.01)  # z

content = dash_vtk.View(children=[
    dash_vtk.GeometryRepresentation(
        property={"pointSize": 3},
        children=[
            dash_vtk.PolyData(points=xyz, connectivity="points"),
        ],
    ),
], )

# Dash setup
app = dash.Dash(__name__)
server = app.server

app.layout = html.Div(
    style={
        "width": "100%",
        "height": "calc(100vh - 15px)"
    },
    children=[content],
)
    def fea_vtk_upload(node_contents, elem_contents, elem_data_contents,
                       cs_name, rng_slide, toggle_edges, is_cleared):
        ctx = dash.callback_context
        if not ctx.triggered:
            raise PreventUpdate

        trig_id = ctx.triggered[0]['prop_id'].split('.')[0]
        # scenario 1: nodes data, but elems wasnt cleared (clears elems)
        if trig_id == f'{APP_ID}_nodes_upload' and not is_cleared[0]:
            return [dash.no_update, [True], dash.no_update, None]

        # scenario 2: elems data, but nodes wasnt cleared (clears nodes)
        if trig_id == f'{APP_ID}_elems_upload' and not is_cleared[0]:
            return [dash.no_update, [True], None, dash.no_update]

        # scenario 3: nodes data, but no elems data
        if trig_id == f'{APP_ID}_nodes_upload' and elem_contents is None:
            raise PreventUpdate

        # scenario 4: elems data, but no nodes data
        if trig_id == f'{APP_ID}_elems_upload' and node_contents is None:
            raise PreventUpdate

        # scenario 5: data for both mesh, but no results
        if all([
                node_contents is not None, elem_contents is not None,
                is_cleared[0], elem_data_contents is None
        ]):
            uGrid, _ = ns_export_to_uGrid(node_contents, elem_contents)

            mesh_state = to_mesh_state(uGrid)

            return [
                dash_vtk.GeometryRepresentation(
                    [dash_vtk.Mesh(state=mesh_state)],
                    property={
                        "edgeVisibility": False,
                        "opacity": 0.25,
                        'representation': 2
                    }),
                [False],
                dash.no_update,
                dash.no_update,
            ]

        # scenario 6: data for the whole shebang
        if all([
                node_contents is not None, elem_contents is not None,
                elem_data_contents is not None
        ]):
            uGrid, rng = ns_export_to_uGrid(node_contents, elem_contents,
                                            elem_data_contents)

            mesh_state1 = to_mesh_state(uGrid)
            if rng_slide[0] == 0. and rng_slide[1] != 1.:
                # threshold to keep values below upper value of range slider
                thresh = uGrid.threshold_percent(rng_slide[1], invert=True)
            elif rng_slide[0] != 0. and rng_slide[1] == 1.:
                # threshold to keep values above lower value of range slider
                thresh = uGrid.threshold_percent(rng_slide[0])
            elif rng_slide[0] == 0. and rng_slide[1] == 1.:
                thresh = uGrid.copy()
            else:
                # threshold to keep values in range
                thresh = uGrid.threshold_percent(rng_slide)
            mesh_state2 = to_mesh_state(thresh, field_to_keep='my_array')

            if 1 in toggle_edges:
                show_edges = True
            else:
                show_edges = False

            return [
                [
                    # this is the ghost display to see the outline of the part
                    dash_vtk.GeometryRepresentation(
                        [dash_vtk.Mesh(state=mesh_state1)],
                        property={
                            "edgeVisibility": False,
                            "opacity": .15
                        },
                    ),
                    # this is the threshold solid elements within the range slider values
                    dash_vtk.GeometryRepresentation(
                        [dash_vtk.Mesh(state=mesh_state2)],
                        property={
                            "edgeVisibility": show_edges,
                            "opacity": 1
                        },
                        colorMapPreset=cs_name,
                        showCubeAxes=False,
                        colorDataRange=rng),
                ],
                [False],
                dash.no_update,
                dash.no_update,
            ]
Пример #15
0
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server
viz = Viz(os.path.join(os.path.dirname(__file__), "data"))

# -----------------------------------------------------------------------------
# 3D Viz
# -----------------------------------------------------------------------------

vtk_view = dash_vtk.View(
    id="vtk-view",
    children=[
        dash_vtk.GeometryRepresentation(
            id="bike-rep",
            children=[dash_vtk.Mesh(
                id="bike",
                state=viz.getBikeMesh(),
            )],
        ),
        dash_vtk.GeometryRepresentation(
            id="tubes-rep",
            colorMapPreset="erdc_rainbow_bright",
            colorDataRange=viz.getColorRange(),
            children=[
                dash_vtk.Mesh(
                    id="tubes-mesh",
                    state=viz.getTubesMesh("p"),
                )
            ],
        ),
        dash_vtk.GeometryRepresentation(
Пример #16
0
import dash
import dash_html_components as html
import dash_vtk
import random

xyz = []
for i in range(10000):
    xyz.append(random.random())  # x
    xyz.append(random.random())  # y
    xyz.append(random.random() * 0.01)  # z

content = dash_vtk.View(children=[
    dash_vtk.GeometryRepresentation(
        property={'pointSize': 3},
        children=[dash_vtk.PolyData(points=xyz, connectivity='points')],
    ),
], )

# Dash setup
app = dash.Dash(__name__)
server = app.server

app.layout = html.Div(
    style={
        "width": "100%",
        "height": "calc(100vh - 15px)"
    },
    children=[content],
)

if __name__ == "__main__":
Пример #17
0
import dash_vtk

content = dash_vtk.View([
    dash_vtk.GeometryRepresentation(
        mapper={
            "colorByArrayName": "layer",
            "scalarMode": 4,
            "interpolateScalarsBeforeMapping": False,
        },
        colorMapPreset="jet",
        colorDataRange=[0.2, 0.9],
        children=[
            dash_vtk.Algorithm(
                vtkClass="vtkConcentricCylinderSource",
                state={
                    "height": 0.25,
                    "radius": [0.2, 0.3, 0.4, 0.6, 0.7, 0.8, 0.9, 1],
                    "cellFields": [0, 0.2, 0.4, 0.6, 0.7, 0.8, 0.9, 1],
                    "mask": [1, 0, 1, 0, 1, 0, 1, 1],
                    "resolution": 60,
                    "skipInnerFaces": True,
                    "startTheta": 45,
                    "endTheta": 315,
                    "center": [0, 0, 0.5],
                },
            ),
        ],
    ),
])

# Dash setup
Пример #18
0
# Data file path
files = [
    'cow-nonormals.obj', 'pumpkin_tall_10k.obj', 'teapot.obj', 'teddy.obj'
]
root_repo_path = os.path.dirname(
    os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
obj_file = os.path.join(root_repo_path, "demos", "data", files[0])

txt_content = None
with open(obj_file, 'r') as file:
    txt_content = file.read()

content = dash_vtk.View([
    dash_vtk.GeometryRepresentation([
        dash_vtk.Reader(
            vtkClass="vtkOBJReader",
            parseAsText=txt_content,
        ),
    ]),
])

# Dash setup
app = dash.Dash(__name__)
server = app.server

app.layout = html.Div(
    style={
        "width": "100%",
        "height": "calc(100vh - 15px)"
    },
    children=[content],
)
Пример #19
0
# -----------------------------------------------------------------------------
# Populate scene
# -----------------------------------------------------------------------------

# vehicle geometry
vehicle_vtk = []
for filename in glob.glob(os.path.join(DATA_PATH, "vehicle") + "/*.vtp"):
    mesh = _load_vtp(filename, point_arrays=["U", "p"])
    part_name = filename.split("/")[-1].replace(".vtp", "")
    child = dash_vtk.GeometryRepresentation(
        id=f"{part_name}-rep",
        colorMapPreset="erdc_rainbow_bright",
        colorDataRange=[0, 100],
        actor={"visibility": 1},
        mapper={"scalarVisibility": False},
        children=[dash_vtk.Mesh(
            id=f"{part_name}-mesh",
            state=mesh,
        )],
    )
    vehicle_vtk.append(child)

# isosurfaces
isosurfs_vtk = []
for filename in glob.glob(os.path.join(DATA_PATH, "isosurfaces") + "/*.vtp"):
    mesh = _load_vtp(filename)

    surf_name = filename.split("/")[-1].replace(".vtp", "")
    child = dash_vtk.GeometryRepresentation(
        id=f"{surf_name}-rep",
Пример #20
0
server = app.server

app.layout = html.Div(
    style={
        "width": "100%",
        "height": "calc(100vh - 16px)"
    },
    children=[
        dash_vtk.View(
            id="view",
            children=[
                dash_vtk.GeometryRepresentation([
                    dash_vtk.Algorithm(
                        vtkClass="vtkConeSource",
                        state={
                            "resolution": 64,
                            "capping": False,
                        },
                    )
                ]),
                dash_vtk.GeometryRepresentation(
                    property={
                        "color": [0.4, 0.4, 0.4],
                    },
                    actor={
                        "position": [0.5, 0.2, 0.4],
                        "scale": [0.3, 0.3, 0.3],
                    },
                    children=[
                        dash_vtk.Reader(
                            vtkClass="vtkOBJReader",