-
|
In my app with I though it has something to do with client getting the Motivated by this project: https://github.com/PaulHax/burnoutweb/blob/threed/app/burn_out/app/world_view.py I modifed the simple cone LocalRendering.py example that reproduces my approach and issue: How to change a polydata (or similar?) then have the client side camera fit the larger/smaller scene? r"""
Version for trame 1.x - https://github.com/Kitware/trame/blob/release-v1/examples/VTK/SimpleCone/LocalRendering.py
Delta v1..v2 - https://github.com/Kitware/trame/commit/674f72774228bbcab5689417c1c5642230b1eab8
Installation requirements:
pip install trame trame-vuetify trame-vtk
"""
from vtkmodules.vtkFiltersSources import vtkConeSource
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleSwitch # noqa
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderer,
vtkRenderWindow,
vtkRenderWindowInteractor,
)
from vtkmodules.vtkCommonDataModel import vtkPolyData, vtkCellArray
from vtkmodules.vtkCommonCore import vtkPoints
from trame.app import get_server, asynchronous
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import vtk as vtk_widgets
from trame.widgets import vuetify
# -----------------------------------------------------------------------------
# Trame initialization
# -----------------------------------------------------------------------------
server = get_server(client_type="vue2")
state, ctrl = server.state, server.controller
state.trame__title = "VTK Remote View - Local Rendering"
# -----------------------------------------------------------------------------
# VTK pipeline
# -----------------------------------------------------------------------------
DEFAULT_RESOLUTION = 6
renderer = vtkRenderer()
renderWindow = vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)
renderWindowInteractor.GetInteractorStyle().SetCurrentStyleToTrackballCamera()
# cone_source = vtkConeSource()
point_data = []
points = vtkPoints()
lines = vtkCellArray()
poly_data = vtkPolyData()
poly_data.SetPoints(points)
poly_data.SetLines(lines)
mapper = vtkPolyDataMapper()
actor = vtkActor()
# mapper.SetInputConnection(cone_source.GetOutputPort())
mapper.SetInputData(poly_data)
actor.SetMapper(mapper)
renderer.AddActor(actor)
renderer.ResetCamera()
renderWindow.Render()
def update_points(points, lines, point_data):
point_ids = []
for point in point_data:
point_id = points.InsertNextPoint(point[0], point[1], point[2])
point_ids.append(point_id)
lines.InsertNextCell(len(point_ids))
for point_id in point_ids:
lines.InsertCellPoint(point_id)
# -----------------------------------------------------------------------------
# Callbacks
# -----------------------------------------------------------------------------
def update_rep(r):
point_data = [(-r, -r, 0), (r, -r, 0), (r, r, 0), (-r, r, 0)]
points = vtkPoints()
lines = vtkCellArray()
update_points(points, lines, point_data)
poly_data.SetPoints(points)
poly_data.SetLines(lines)
poly_data.Modified()
async def async_flush():
with state:
ctrl.view_update()
await server.network_completion
ctrl.view_reset_camera()
@state.change("resolution")
def update_cone(resolution=DEFAULT_RESOLUTION, **kwargs):
# cone_source.SetResolution(resolution)
r = resolution
update_rep(r)
# ctrl.view_update()
# ctrl.view_reset_camera()
# not fitting new scene size either
asynchronous.create_task(async_flush())
def update_reset_resolution():
state.resolution = DEFAULT_RESOLUTION
# -----------------------------------------------------------------------------
# GUI
# -----------------------------------------------------------------------------
with SinglePageLayout(server) as layout:
layout.icon.click = ctrl.view_reset_camera
layout.title.set_text("Cone Application")
with layout.toolbar:
vuetify.VSpacer()
vuetify.VSlider(
v_model=("resolution", DEFAULT_RESOLUTION),
min=3,
max=60,
step=1,
hide_details=True,
dense=True,
style="max-width: 300px",
)
vuetify.VDivider(vertical=True, classes="mx-2")
with vuetify.VBtn(icon=True, click=update_reset_resolution):
vuetify.VIcon("mdi-undo-variant")
with layout.content:
with vuetify.VContainer(
fluid=True,
classes="pa-0 fill-height",
):
view = vtk_widgets.VtkLocalView(renderWindow, ref="view")
ctrl.view_update = view.update
ctrl.view_reset_camera = view.reset_camera
# -----------------------------------------------------------------------------
# Jupyter
# -----------------------------------------------------------------------------
def show(**kwargs):
from trame.app import jupyter
jupyter.show(server, **kwargs)
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
if __name__ == "__main__":
server.start() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
VtkLocalView has a Here is a gist of what you could do def update_data(self):
# ... update pipeline/data
self.html_view.update()
self.schedule_reset_camera = self.state.update_count + 1
@change("update_count")
def _on_update_count(self, update_count, **_):
if update_count == self.schedule_reset_camera:
self.html_view.reset_camera()
def _build_ui(self):
with layout:
# ...
self.html_view = vtk_widgets.VtkLocalView(
renderWindow,
on_ready="update_count++",
)Another approach is to reset the camera on the server side (as you have the proper bounds) and call |
Beta Was this translation helpful? Give feedback.
VtkLocalView has a
on_readyevent that you can listen to to see when reset_camera should be called.Here is a gist of what you could do
Another approach is to reset the camera on the server side (as you have…