Py.Cafe

maartenbreddels/

test-ladybug-vtkjs

Test importing ladybug-vtk with vtk dependency

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import sys
if "vtk" in sys.modules:
    del sys.modules["vtk"]
import vtk

from dash import Dash, Input, Output, callback, dcc, html

app = Dash(__name__)
md = """
# Dash demo

See [The dash examples index](https://dash-example-index.herokuapp.com/) for more examples.
"""

app.layout = html.Div(
    children=[
        dcc.Markdown(children=md, link_target="_blank"),
        dcc.Dropdown(id="dropdown", options=["red", "green", "blue", "orange"]),
        dcc.Markdown(id="markdown", children=["## Hello World"]),
    ]
)


@callback(
    Output("markdown", "style"),
    Input("dropdown", "value"),
)
def update_markdown_style(color):
    return {"color": color}


async def run():
    try:
        await vtk._load_js()

        import ladybug_vtk.from_geometry
        from typing import List
        from ladybug_geometry.geometry3d import Point3D, Polyline3D, Arc3D, LineSegment3D,\
            Mesh3D, Polyface3D, Cone, Cylinder, Sphere, Face3D, Plane, Vector3D
        from ladybug_vtk.polydata import PolyData
        def _polyline_from_points3d(points: List[Point3D]) -> PolyData:
            """Create Polydata from a list of Ladybug Point3D objects.

            Args:
                points: A list of Ladybug Point3D objects.

            Returns:
                Polydata containing a polyline created by joining the points.
            """
            pts = vtk.vtkPoints()
            for pt in points:
                pts.InsertNextPoint(tuple(pt))

            polyline = vtk.vtkPolyLine()
            points = list(range(len(points)))
            polyline.initialize(pts, points)
            # polyline.SetPointIds(points)
            # polyline.GetPointIds().SetNumberOfIds(len(points))
            # for i in range(len(points)):
            #     polyline.GetPointIds().SetId(i, i)

            cells = vtk.vtkCellArray()
            cells.InsertNextCell(polyline)

            polydata = PolyData()
            polydata.SetPoints(pts)
            polydata.SetLines(cells)

            return polydata

        ladybug_vtk.from_geometry._polyline_from_points3d = _polyline_from_points3d
        from ladybug.sunpath import Sunpath
        from ladybug.epw import EPW
        from ladybug_vtk._extend_sunpath import sunpath_to_vtkjs

        epw_file = 'weather.epw'
        epw = EPW(epw_file)
        sp = Sunpath.from_location(epw.location)
        sunpath_to_vtkjs(sp)
    except Exception as e:
        import traceback as tb
        tb.print_exception(e)
        print(e)
        raise
import asyncio
asyncio.ensure_future(run())
vtk.py
1
Could not load content