Python vtk.vtkRenderWindowInteractor() Examples
The following are 14
code examples of vtk.vtkRenderWindowInteractor().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
vtk
, or try the search function
.
Example #1
Source File: vtkpointcloud.py From deep-prior-pp with GNU General Public License v3.0 | 6 votes |
def viewer(pointclouds): assert all([isinstance(p, VtkPointCloud) for p in pointclouds]) # Renderer renderer = vtk.vtkRenderer() renderer.SetBackground(1.0, 1.0, 1.0) for p in pointclouds: renderer.AddActor(p.vtkActor) renderer.ResetCamera() # Render Window renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer) # Interactor renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # Begin Interaction renderWindow.Render() renderWindow.SetWindowName("XYZ Data Viewer") renderWindowInteractor.Start()
Example #2
Source File: vtkVisualization.py From MOTSFusion with MIT License | 5 votes |
def __init__(self): self.renderer = vtk.vtkRenderer() self.renderer.SetBackground(0.5, 0.5, 0.5) self.renderer.ResetCamera() axes_actor = vtk.vtkAxesActor() axes_actor.AxisLabelsOff() self.renderer.AddActor(axes_actor) self.window = vtk.vtkRenderWindow() self.window.AddRenderer(self.renderer) self.interactor = vtk.vtkRenderWindowInteractor() self.interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera()) self.interactor.SetRenderWindow(self.window) self.camera = vtk.vtkCamera() self.camera.SetViewUp(0.0, -1.0, 0.0) self.camera.SetPosition(0.0, 0.0, -5) self.camera.SetFocalPoint(0.0, 0.0, 0.0) # self.camera.SetClippingRange(0.0, 100000) self.renderer.SetActiveCamera(self.camera)
Example #3
Source File: vtkhelpers.py From pcloudpy with BSD 3-Clause "New" or "Revised" License | 5 votes |
def display_from_actor(actor): renderer = vtkRenderer() renderWindow = vtkRenderWindow() renderWindow.AddRenderer(renderer) renderer.AddActor(actor) # enable user interface interactor iren = vtkRenderWindowInteractor() iren.SetRenderWindow(renderWindow) iren.Initialize() renderWindow.Render() iren.Start()
Example #4
Source File: graphics.py From robopy with MIT License | 5 votes |
def __init__(self, background=(0.15, 0.15, 0.15), total_time_steps=None, timer_rate=60, gif_file=None): self.ren = vtk.vtkRenderer() self.ren.SetBackground(background[0], background[1], background[2]) self.ren_win = vtk.vtkRenderWindow() self.ren_win.AddRenderer(self.ren) self.iren = vtk.vtkRenderWindowInteractor() self.iren.SetRenderWindow(self.ren_win) self.iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera()) self.actor_list = [] self.mapper_list = [] self.source_list = [] self.screenshot_count = 0 self.timer_rate = timer_rate self.gif_data = [] if gif_file is not None: try: assert type(gif_file) is str except AssertionError: gif_file = str(gif_file) self.gif_file = gif_file else: self.gif_file = None if total_time_steps is not None: assert type(total_time_steps) is int self.timer_count = 0 self.total_time_steps = total_time_steps
Example #5
Source File: plotting.py From pyvista with MIT License | 5 votes |
def update(self, stime=1, force_redraw=True): """Update window, redraw, process messages query. Parameters ---------- stime : int, optional Duration of timer that interrupt vtkRenderWindowInteractor in milliseconds. force_redraw : bool, optional Call ``render`` immediately. """ if stime <= 0: stime = 1 curr_time = time.time() if Plotter.last_update_time > curr_time: Plotter.last_update_time = curr_time if not hasattr(self, 'iren'): return update_rate = self.iren.GetDesiredUpdateRate() if (curr_time - Plotter.last_update_time) > (1.0/update_rate): self.right_timer_id = self.iren.CreateRepeatingTimer(stime) self.iren.Start() self.iren.DestroyTimer(self.right_timer_id) self.render() Plotter.last_update_time = curr_time elif force_redraw: self.render()
Example #6
Source File: vis.py From DeepV2D with BSD 3-Clause "New" or "Revised" License | 5 votes |
def visualize_prediction(pointcloud, colors, poses=None, renwin=None): """ render point cloud and cameras """ renderer = vtk.vtkRenderer() renderer.SetBackground(0, 0, 0) pointcloud_actor = create_pointcloud_actor(points=pointcloud, colors=colors) pointcloud_actor.GetProperty().SetPointSize(2) renderer.AddActor(pointcloud_actor) for pose in poses: R, t = pose[:3, :3], pose[:3, 3] cam_actor = create_camera_actor(R,t) cam_actor.GetProperty().SetColor((255, 255, 0)) renderer.AddActor(cam_actor) camera = vtk.vtkCamera() camera.SetPosition((1, -1, -2)); camera.SetViewUp((0, -1, 0)); camera.SetFocalPoint((0, 0, 2)); renderer.SetActiveCamera(camera) renwin = vtk.vtkRenderWindow() renwin.SetWindowName("Point Cloud Viewer") renwin.SetSize(800,600) renwin.AddRenderer(renderer) # An interactor interactor = vtk.vtkRenderWindowInteractor() interstyle = vtk.vtkInteractorStyleTrackballCamera() interactor.SetInteractorStyle(interstyle) interactor.SetRenderWindow(renwin) # Render and interact renwin.Render() interactor.Initialize() interactor.Start()
Example #7
Source File: vis.py From DeepV2D with BSD 3-Clause "New" or "Revised" License | 5 votes |
def run(self): renderer = vtk.vtkRenderer() renderer.SetBackground(0, 0, 0) camera = vtk.vtkCamera() camera.SetPosition((1, -1, -2)); camera.SetViewUp((0, -1, 0)); camera.SetFocalPoint((0, 0, 2)); renderer.SetActiveCamera(camera) renwin = vtk.vtkRenderWindow() renwin.SetWindowName("Point Cloud Viewer") renwin.SetSize(800,600) renwin.AddRenderer(renderer) interactor = vtk.vtkRenderWindowInteractor() interstyle = vtk.vtkInteractorStyleTrackballCamera() interactor.SetInteractorStyle(interstyle) interactor.SetRenderWindow(renwin) interactor.Initialize() cb = vtkTimerCallback(self.cinematic, self.render_path, self.clear_points) cb.queue = self.queue interactor.AddObserver('TimerEvent', cb.execute) timerId = interactor.CreateRepeatingTimer(100); #start the interaction and timer interactor.Start()
Example #8
Source File: tessagon_vtk_demo.py From tessagon with Apache License 2.0 | 5 votes |
def __init__(self): self.ren = vtk.vtkRenderer() self.renWin = vtk.vtkRenderWindow() self.renWin.AddRenderer(self.ren) self.iren = vtk.vtkRenderWindowInteractor() self.iren.SetRenderWindow(self.renWin) self.lut = vtk.vtkLookupTable() self.lut.SetHueRange(0.6, 0.6) self.lut.SetSaturationRange(.5, .5) self.lut.SetValueRange(0.2, 1.0) self.lut.SetNumberOfColors(256) self.lut.Build()
Example #9
Source File: show_vtk.py From pyrealsense with Apache License 2.0 | 5 votes |
def __init__(self, threadLock, actorWrapper, axis=True,): super(VTKVisualisation, self).__init__() self.threadLock = threadLock self.ren = vtk.vtkRenderer() self.ren.AddActor(actorWrapper.actor) self.axesActor = vtk.vtkAxesActor() self.axesActor.AxisLabelsOff() self.axesActor.SetTotalLength(1, 1, 1) self.ren.AddActor(self.axesActor) self.renWin = vtk.vtkRenderWindow() self.renWin.AddRenderer(self.ren) ## IREN self.iren = vtk.vtkRenderWindowInteractor() self.iren.SetRenderWindow(self.renWin) self.iren.Initialize() self.style = vtk.vtkInteractorStyleTrackballCamera() self.iren.SetInteractorStyle(self.style) self.iren.AddObserver("TimerEvent", self.update_visualisation) dt = 30 # ms timer_id = self.iren.CreateRepeatingTimer(dt)
Example #10
Source File: visualizer_3d.py From sanet_relocal_demo with GNU General Public License v3.0 | 5 votes |
def __init__(self, h=800, w=600): self.renderer = vtk.vtkRenderer() self.renderer.SetBackground(0.1, 0.1, 0.1) # Add axes axes = vtk.vtkAxesActor() axes.GetXAxisCaptionActor2D().SetHeight(0.05) axes.GetYAxisCaptionActor2D().SetHeight(0.05) axes.GetZAxisCaptionActor2D().SetHeight(0.05) axes.SetCylinderRadius(0.03) axes.SetShaftTypeToCylinder() self.renderer.AddActor(axes) # Add render window self.renwin = vtk.vtkRenderWindow() self.renwin.SetWindowName("Point Cloud Viewer") self.renwin.SetSize(h, w) self.renwin.AddRenderer(self.renderer) # An interactor self.interactor = vtk.vtkRenderWindowInteractor() interstyle = vtk.vtkInteractorStyleTrackballCamera() self.interactor.SetInteractorStyle(interstyle) self.interactor.SetRenderWindow(self.renwin) self.camera_actors = []
Example #11
Source File: vtk_helpers.py From NURBS-Python with MIT License | 4 votes |
def create_render_window(actors, callbacks, **kwargs): """ Creates VTK render window with an interactor. :param actors: list of VTK actors :type actors: list, tuple :param callbacks: callback functions for registering custom events :type callbacks: dict """ # Get keyword arguments figure_size = kwargs.get('figure_size', (800, 600)) camera_position = kwargs.get('camera_position', (0, 0, 100)) # Find camera focal point center_points = [] for actor in actors: center_points.append(actor.GetCenter()) camera_focal_point = linalg.vector_mean(*center_points) # Create camera camera = vtk.vtkCamera() camera.SetPosition(*camera_position) camera.SetFocalPoint(*camera_focal_point) # Create renderer renderer = vtk.vtkRenderer() renderer.SetActiveCamera(camera) renderer.SetBackground(1.0, 1.0, 1.0) # Add actors to the scene for actor in actors: renderer.AddActor(actor) # Render window render_window = vtk.vtkRenderWindow() render_window.AddRenderer(renderer) render_window.SetSize(*figure_size) # Render window interactor window_interactor = vtk.vtkRenderWindowInteractor() window_interactor.SetRenderWindow(render_window) # Add event observers for cb in callbacks: window_interactor.AddObserver(cb, callbacks[cb][0], callbacks[cb][1]) # cb name, cb function ref, cb priority # Render actors render_window.Render() # Set window name after render() is called render_window.SetWindowName("geomdl") # Use trackball camera interactor_style = vtk.vtkInteractorStyleTrackballCamera() window_interactor.SetInteractorStyle(interactor_style) # Start interactor window_interactor.Start() # Return window interactor instance return window_interactor
Example #12
Source File: pcd_corners_est.py From ILCC with BSD 2-Clause "Simplified" License | 4 votes |
def show_pcd_ndarray(array_data, color_arr=[0, 255, 0]): all_rows = array_data.shape[0] Colors = vtk.vtkUnsignedCharArray() Colors.SetNumberOfComponents(3) Colors.SetName("Colors") Points = vtk.vtkPoints() Vertices = vtk.vtkCellArray() for k in xrange(all_rows): point = array_data[k, :] id = Points.InsertNextPoint(point[0], point[1], point[2]) Vertices.InsertNextCell(1) Vertices.InsertCellPoint(id) if vtk.VTK_MAJOR_VERSION > 6: Colors.InsertNextTuple(color_arr) else: Colors.InsertNextTupleValue(color_arr) dis_tmp = np.sqrt((point ** 2).sum(0)) # Colors.InsertNextTupleValue([0,255-dis_tmp/max_dist*255,0]) # Colors.InsertNextTupleValue([255-abs(point[0]/x_max*255),255-abs(point[1]/y_max*255),255-abs(point[2]/z_max*255)]) # Colors.InsertNextTupleValue([255-abs(point[0]/x_max*255),255,255]) polydata = vtk.vtkPolyData() polydata.SetPoints(Points) polydata.SetVerts(Vertices) polydata.GetPointData().SetScalars(Colors) polydata.Modified() mapper = vtk.vtkPolyDataMapper() if vtk.VTK_MAJOR_VERSION <= 5: mapper.SetInput(polydata) else: mapper.SetInputData(polydata) mapper.SetColorModeToDefault() actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetPointSize(5) # Renderer renderer = vtk.vtkRenderer() renderer.AddActor(actor) renderer.SetBackground(.2, .3, .4) renderer.ResetCamera() # Render Window renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer) # Interactor renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # Begin Interaction renderWindow.Render() renderWindowInteractor.Start() # determine whether a segment is the potential chessboard's point cloud
Example #13
Source File: utility.py From ILCC with BSD 2-Clause "Simplified" License | 4 votes |
def vis_with_renderer(renderer): # Renderer # renderer.SetBackground(.2, .3, .4) renderer.SetBackground(1, 1, 1) renderer.ResetCamera() transform = vtk.vtkTransform() transform.Translate(1.0, 0.0, 0.0) axes = vtk.vtkAxesActor() renderer.AddActor(axes) # Render Window renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer) # Interactor renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) def get_camera_info(obj, ev): if renderWindowInteractor.GetKeyCode() == "s": w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(renderWindow) w2if.Update() writer = vtk.vtkPNGWriter() writer.SetFileName("screenshot.png") if vtk.VTK_MAJOR_VERSION == 5: writer.SetInput(w2if.GetOutput()) else: writer.SetInputData(w2if.GetOutput()) writer.Write() print "screenshot saved" style = vtk.vtkInteractorStyleSwitch() renderWindowInteractor.SetInteractorStyle(style) # style.SetCurrentStyleToTrackballActor() style.SetCurrentStyleToTrackballCamera() # Begin Interaction renderWindowInteractor.AddObserver(vtk.vtkCommand.KeyPressEvent, get_camera_info, 1) renderWindow.Render() renderWindowInteractor.Start()
Example #14
Source File: volumerendering.py From Medical-Image-Analysis-IPython-Tutorials with Apache License 2.0 | 4 votes |
def vtk_basic( actors, embed=False, magnification=1.0 ): """ Create a window, renderer, interactor, add the actors and start the thing Parameters ---------- actors : list of vtkActors Returns ------- nothing """ # create a rendering window and renderer ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) renWin.SetSize(600,600) # ren.SetBackground( 1, 1, 1) # create a renderwindowinteractor iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) for a in actors: move( a, np.dot(Ry(-180),Rx(-180)) ) # assign actor to the renderer ren.AddActor(a ) # render renWin.Render() if embed: renWin.SetSize(300,300) grabber = vtk.vtkWindowToImageFilter() grabber.SetInput( renWin ) grabber.SetMagnification( magnification ) grabber.Update() writer = vtk.vtkPNGWriter() writer.SetInput( grabber.GetOutput() ) writer.SetFileName( "screenshot.png" ) writer.Write() return display.Image("screenshot.png") else: # enable user interface interactor iren.Initialize() iren.Start()