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())