def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkAVIWriter(), 'Writing vtkAVI.', ('vtkAVI',), (), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkAVIWriter(), 'Writing vtkAVI.', ('vtkAVI', ), (), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def SaveFrame(self, iren): # screenshot code: w2if = vtk.vtkWindowToImageFilter() w2if.SetInput(iren.GetRenderWindow()) w2if.Update() writer = vtk.vtkAVIWriter() writer.SetFileName("movie/screenshot%i.png" % self.step) writer.SetInputConnection(w2if.GetOutputPort()) writer.Write() return
def get_video(renWin, fps, filename): _filter = vtkWindowToImageFilter() _filter.SetInput(renWin) _filter.SetInputBufferTypeToRGB() writer = vtkAVIWriter() writer.SetRate(fps) writer.SetQuality(2) writer.SetCompressorFourCC('DIB') writer.SetInputConnection(_filter.GetOutputPort()) writer.SetFileName(filename + '.avi') writer.Start() return _filter, writer
def setInputConnection(self): """ :return: """ if self.windowToImageFilter is not None: self.movieWriter = vtk.vtkAVIWriter() self.movieWriter.SetQuality(2) # self.movieWriter = vtk.vtkOggTheoraWriter() self.movieWriter.SetInputConnection( self.windowToImageFilter.GetOutputPort()) filename = self._name + ".avi" # filename = self._name + ".ogv" self.movieWriter.SetFileName(filename) print "Animation saved to file: %s" % filename
def init_record_video(self, filename, windows_size=(800, 1000), quality=2, rate=25): self.stop = True self.reset_camera() self.render_window = vtk.vtkRenderWindow() self.render_window.AddRenderer(self._renderer) self.render_window.SetSize(windows_size[0], windows_size[1]) self.render_window_interactor = vtk.vtkRenderWindowInteractor() self.render_window_interactor.SetInteractorStyle( vtk.vtkInteractorStyleTrackballCamera()) self.render_window_interactor.SetRenderWindow(self.render_window) self.render_window.Render() self.windowToImageFilter = vtk.vtkWindowToImageFilter() self.windowToImageFilter.SetInput(self.render_window) self.windowToImageFilter.SetInputBufferTypeToRGB() self.windowToImageFilter.ReadFrontBufferOff() self.windowToImageFilter.Update() self.writer = vtk.vtkAVIWriter() self.writer.SetInputConnection( self.windowToImageFilter.GetOutputPort()) self.writer.SetFileName(filename) self.writer.SetRate(rate) self.writer.SetQuality(quality) self.writer.Start() self.lock = Lock() def cb(interactor, event): if not self.stop and self.lock.acquire(False): self.windowToImageFilter.Modified() self.writer.Write() self.lock.release() self.render_window_interactor.AddObserver('TimerEvent', cb) self.render_window_interactor.AddObserver('RenderEvent', cb) self.render_window_interactor.CreateRepeatingTimer(1)
def vtkRotationMovie(renderWindow, filename='c:/test.avi'): global degrees degrees = 0 windowToImageFilter = vtk.vtkWindowToImageFilter() windowToImageFilter.SetInput(renderWindow) windowToImageFilter.SetInputBufferTypeToRGB() windowToImageFilter.ReadFrontBufferOff() windowToImageFilter.Update() #writer = vtk.vtkOggTheoraWriter() writer = vtk.vtkAVIWriter() writer.SetInputConnection(windowToImageFilter.GetOutputPort()) writer.SetRate(10) # Not needed for Ogg try: os.remove(filename) except OSError: pass writer.SetFileName(filename) writer.Start() timerId = renderWindow.GetInteractor().CreateRepeatingTimer(50) def cb(interactor, event): global degrees step = 5 if (degrees > 359): interactor.DestroyTimer(timerId) writer.End() return interactor.GetRenderWindow().Render() cam = interactor.GetRenderWindow().GetRenderers().GetFirstRenderer( ).GetActiveCamera() cam.Azimuth(step) cam.OrthogonalizeViewUp() windowToImageFilter.Modified() writer.Write() degrees = degrees + step renderWindow.GetInteractor().AddObserver('TimerEvent', cb) renderWindow.GetInteractor().Start()
def dump_movie(actors, win, dx, dy, dz, frames, framerate, filename): windowToImageFilter = vtk.vtkWindowToImageFilter() windowToImageFilter.SetInput(win) # windowToImageFilter.SetInputBufferTypeToRGBA() windowToImageFilter.ReadFrontBufferOff() windowToImageFilter.Update() writer = vtk.vtkAVIWriter() writer.SetQuality(2) writer.SetRate(framerate) writer.SetInputConnection(windowToImageFilter.GetOutputPort()) writer.SetFileName(filename) writer.Start() for frame in range(frames): for actor in actors: actor.RotateX(dx) actor.RotateY(dy) actor.RotateZ(dz) win.GetInteractor().GetRenderWindow().Render() windowToImageFilter.Modified() # This is crucial writer.Write() writer.End()
def start_export_animation_to_file(self, path, frame_rate): self.animation_path = path #Setup filter self.renWin = self._renderer.GetRenderWindow() self.imageFilter = vtk.vtkWindowToImageFilter() self.imageFilter.SetInput(self.renWin) self.imageFilter.SetInputBufferTypeToRGB() self.imageFilter.ReadFrontBufferOff() self.imageFilter.Update() #Setup movie writer if ".avi" in path: self.moviewriter = vtk.vtkAVIWriter() else: self.moviewriter = vtk.vtkOggTheoraWriter() self.moviewriter.SetFileName(path) self.moviewriter.SetInputConnection(self.imageFilter.GetOutputPort()) self.moviewriter.SetRate(30) self.moviewriter.SetQuality(2) self.moviewriter.Start() # self.export_animation = True
def dump_movie(filename, neuron_graph, label_nodes=[], labels=[], priorities=[], nodecolor=ng.nodecolor_4cp, background=(0, 0, 0), lines=False, xrot=0.0, yrot=0.0, zrot=0.0, xangle=0, yangle=0, zangle=0, frames_per_degree=10, framerate=25, size=(800, 600)): """Save the 3D display as a movie""" x = [neuron_graph.node[n]['x'] for n in neuron_graph] y = [neuron_graph.node[n]['y'] for n in neuron_graph] z = [neuron_graph.node[n]['z'] for n in neuron_graph] center_x = (min(x) + max(x)) * 0.5 center_y = (min(y) + max(y)) * 0.5 center_z = (min(z) + max(z)) * 0.5 tmatrix = make_tmatrix(-center_x, -center_y, -center_z, xrot, yrot, zrot) rigid_transform_graph(neuron_graph, tmatrix) # Translate origin to center renderer, actor = nrngraph2vtk(neuron_graph, label_nodes=label_nodes, labels=labels, priorities=priorities, nodecolor=nodecolor, background=background, lines=lines) x = [neuron_graph.node[n]['x'] for n in neuron_graph] y = [neuron_graph.node[n]['y'] for n in neuron_graph] z = [neuron_graph.node[n]['z'] for n in neuron_graph] center_x = (min(x) + max(x)) * 0.5 center_y = (min(y) + max(y)) * 0.5 center_z = (min(z) + max(z)) * 0.5 print('Center:', center_x, center_y, center_z) actor.SetOrigin(center_x, center_y, center_z) win = vtk.vtkRenderWindow() win.SetSize(*size) win.AddRenderer(renderer) interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(win) win.Render() interactor.Initialize() xframes = xangle * frames_per_degree dx = 0 if xframes == 0 else 1.0 / frames_per_degree yframes = yangle * frames_per_degree dy = 0 if yframes == 0 else 1.0 / frames_per_degree zframes = zangle * frames_per_degree dz = 0 if zframes == 0 else 1.0 / frames_per_degree frames = int(max((xframes, yframes, zframes))) print('X-rotation', dx, 'Y-rotation', dy, 'Z-rotation', dz, 'Frames', frames) windowToImageFilter = vtk.vtkWindowToImageFilter() windowToImageFilter.SetInput(win) # windowToImageFilter.SetInputBufferTypeToRGBA() windowToImageFilter.ReadFrontBufferOff() windowToImageFilter.Update() writer = vtk.vtkAVIWriter() writer.SetRate(framerate) writer.SetInputConnection(windowToImageFilter.GetOutputPort()) writer.SetFileName(filename) writer.Start() for frame in range(frames): actor.RotateX(dx) actor.RotateY(dy) actor.RotateZ(dz) interactor.GetRenderWindow().Render() windowToImageFilter.Modified() # This is crucial writer.Write() writer.End() interactor.Start()
renderer = vtk.vtkRenderer() renderer.AddActor(axes) renderer.SetBackground(0.5, 0.5, 0.5) renderer.SetActiveCamera(camera) renderWindow.AddRenderer(renderer) # Interactor renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) renderWindowInteractor.SetInteractorStyle( vtk.vtkInteractorStyleTrackballCamera()) renderWindowInteractor.Initialize() #record video writer = vtk.vtkAVIWriter() writer.SetRate(30) writer.SetFileName("test.avi") # Sign up to receive TimerEvent cb = vis.AddToolsTimerCallBack(renderer, videotoolTransforms, videoPtCloud, writer) renderer.AddActor(cb.tool1Actor) renderer.AddActor(cb.tool2Actor) renderWindowInteractor.AddObserver('TimerEvent', cb.execute) timerId = renderWindowInteractor.CreateRepeatingTimer(200) vis.AddToolsTimerCallBack.timerId = timerId #cb.setActors(tool1.vtkActor, tool2.vtkActor) # cb.transform1 = np.identity(4) # cb.transform2 = np.identity(4)