-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import vtk | ||
from trame.app import get_server | ||
from trame.widgets import vuetify, vtk as vtk_widgets | ||
from trame.ui.vuetify import SinglePageLayout | ||
|
||
from vtkmodules.vtkRenderingCore import ( | ||
vtkActor, | ||
vtkPolyDataMapper, | ||
vtkRenderer, | ||
vtkRenderWindow, | ||
vtkRenderWindowInteractor, | ||
) | ||
from vtkmodules.vtkFiltersCore import vtkTubeFilter | ||
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleTrackballCamera | ||
|
||
import vtkmodules.vtkRenderingOpenGL2 # noqa (needed for vtkHardwareSelector) | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Generate dataset | ||
# ----------------------------------------------------------------------------- | ||
|
||
points = vtk.vtkPoints() | ||
points.SetNumberOfPoints(4) | ||
line = vtk.vtkLine() | ||
lines = vtk.vtkCellArray() | ||
|
||
# create first line segment | ||
points.SetPoint(0, 0, 0, 0) | ||
line.GetPointIds().SetId(0, 0) | ||
|
||
points.SetPoint(1, 1, 1, 1) | ||
line.GetPointIds().SetId(1, 1) | ||
|
||
lines.InsertNextCell(line) | ||
|
||
# create second line segment | ||
points.SetPoint(2, 1, 1, 1) | ||
line.GetPointIds().SetId(0, 2) | ||
|
||
points.SetPoint(3, 2, 2, 2) | ||
line.GetPointIds().SetId(1, 3) | ||
|
||
lines.InsertNextCell(line) | ||
|
||
linesPolyData = vtk.vtkPolyData() | ||
linesPolyData.SetPoints(points) | ||
linesPolyData.SetLines(lines) | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Trame initialization | ||
# ----------------------------------------------------------------------------- | ||
|
||
server = get_server() | ||
state, ctrl = server.state, server.controller | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Interactions | ||
# ----------------------------------------------------------------------------- | ||
|
||
|
||
def foo(pickData): | ||
print("hello") | ||
|
||
|
||
# ----------------------------------------------------------------------------- | ||
# VTK pipeline | ||
# ----------------------------------------------------------------------------- | ||
|
||
tubes_filter = vtkTubeFilter() | ||
tubes_filter.SetInputData(linesPolyData) | ||
tubes_filter.SetRadius(2) | ||
tubes_filter.SetNumberOfSides(3) | ||
tubes_filter.Update() | ||
|
||
mapper = vtkPolyDataMapper() | ||
mapper.SetInputConnection(tubes_filter.GetOutputPort()) | ||
actor = vtkActor() | ||
actor.SetMapper(mapper) | ||
|
||
renderer = vtkRenderer() | ||
renderer.SetBackground(1, 1, 1) | ||
renderer.AddActor(actor) | ||
|
||
render_window = vtkRenderWindow() | ||
render_window.AddRenderer(renderer) | ||
|
||
rw_interactor = vtkRenderWindowInteractor() | ||
rw_interactor.SetRenderWindow(render_window) | ||
rw_interactor.GetInteractorStyle().SetCurrentStyleToTrackballCamera() | ||
|
||
renderer.ResetCamera() | ||
|
||
# ----------------------------------------------------------------------------- | ||
# GUI layout | ||
# ----------------------------------------------------------------------------- | ||
|
||
with SinglePageLayout(server) as layout: | ||
with layout.content: | ||
with vuetify.VContainer(fluid=True, classes="fill-height pa-0 ma-0"): | ||
view = vtk_widgets.VtkRemoteView( | ||
render_window, | ||
interactor_events=("events", ["LeftButtonPress"]), | ||
LeftButtonPress=(foo, "[utils.vtk.event($event)]"), | ||
) | ||
view.update | ||
view.reset_camera | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Main | ||
# ----------------------------------------------------------------------------- | ||
|
||
if __name__ == "__main__": | ||
server.start() |