Example #1
0
    def zoomTo(self, newFocalPoint, newPosition=None):

        self.interp = vtk.vtkCameraInterpolator()
        self.interp.AddCamera(0.0, self.getCameraCopy())

        c = self.getCameraCopy()
        newFocalPoint = np.array(newFocalPoint)
        oldFocalPoint = np.array(c.GetFocalPoint())
        oldPosition = np.array(c.GetPosition())

        if newPosition is None:
            if self.maintainViewDirection:
                newPosition = oldPosition + (newFocalPoint - oldFocalPoint)
            else:
                newPosition = oldPosition
            newPosition += self.positionZoom * (newFocalPoint - newPosition)
            # newPosition = newFocalPoint - self.positionZoom*(newFocalPoint - newPosition)

        c.SetFocalPoint(newFocalPoint)
        c.SetPosition(newPosition)
        c.SetViewUp([0.0, 0.0, 1.0])

        self.interp.AddCamera(1.0, c)
        self.startTime = time.time()
        self.start()
Example #2
0
	def initializeCameraInterpolator(self):
		"""
		Initialize the camera interpolator if there are keyframes
		"""           
		tracks = self.getKeyframes()
		if not tracks:
			self.interpolator = None
			return
		self.interpolator = vtk.vtkCameraInterpolator()
		self.interpolator.SetInterpolationTypeToSpline()
		self.camPositions = []
		for track in tracks:
			items = track.getItems()
			for item in items[:-1]:
				start, end = item.getPosition()
				campos = item.cam.GetPosition()
				self.camPositions.append((start, campos))
				self.interpolator.AddCamera(start, item.cam)
			# The last item is the end of track-item
			if len(items):
				item = items[-1]
				start, end = item.getPosition()
				campos = item.cam.GetPosition()
				self.camPositions.append((start, campos))                
				self.interpolator.AddCamera(start, item.cam)
Example #3
0
    def zoomTo(self, newFocalPoint, newPosition=None):

        self.interp = vtk.vtkCameraInterpolator()
        self.interp.AddCamera(0.0, self.getCameraCopy())

        c = self.getCameraCopy()
        newFocalPoint = np.array(newFocalPoint)
        oldFocalPoint = np.array(c.GetFocalPoint())
        oldViewUp = np.array(c.GetViewUp())
        oldPosition = np.array(c.GetPosition())

        if newPosition is None:
            if self.maintainViewDirection:
                newPosition = oldPosition + (newFocalPoint - oldFocalPoint)
            else:
                newPosition = oldPosition
            newPosition += self.positionZoom * (newFocalPoint - newPosition)
            #newPosition = newFocalPoint - self.positionZoom*(newFocalPoint - newPosition)

        c.SetFocalPoint(newFocalPoint)
        c.SetPosition(newPosition)
        c.SetViewUp(oldViewUp)

        self.interp.AddCamera(1.0, c)
        self.startTime = time.time()
        self.start()
Example #4
0
def make_camera_interpolator(times, cameras, linear=False):
    assert (len(times) == len(cameras))
    camera_interp = vtk.vtkCameraInterpolator()
    for t, cam in zip(times, cameras):
        camera_interp.AddCamera(t, cam)
    if linear:
        camera_interp.SetInterpolationTypeToLinear()
    return camera_interp
Example #5
0
view4 = vtk.vtkCamera()
view4.SetClippingRange(14.0481, 14048.1)
view4.SetFocalPoint(562880, 5.11652e+006, 2733.15)
view4.SetPosition(562974, 5.11462e+006, 6419.98)
view4.SetViewAngle(30)
view4.SetViewUp(0.0047047, 0.888364, 0.459116)

view5 = vtk.vtkCamera()
view5.SetClippingRange(14.411, 14411)
view5.SetFocalPoint(562910, 5.11674e+006, 3027.15)
view5.SetPosition(562414, 5.11568e+006, 3419.87)
view5.SetViewAngle(30)
view5.SetViewUp(-0.0301976, 0.359864, 0.932516)

interpolator = vtk.vtkCameraInterpolator()
interpolator.SetInterpolationTypeToSpline()
interpolator.AddCamera(0, view1)
interpolator.AddCamera(5, view2)
interpolator.AddCamera(7.5, view3)
interpolator.AddCamera(9.0, view4)
interpolator.AddCamera(11.0, view5)

camera = vtk.vtkCamera()
ren1.SetActiveCamera(camera)

def animate():
    numSteps = 500
    min = interpolator.GetMinimumT()
    max = interpolator.GetMaximumT()
    i = 0
Example #6
0
def render_movie(actors,
                 directory,
                 times,
                 cameras,
                 start_frame=0,
                 video_width=1280,
                 video_height=720,
                 scale=4,
                 do_save=True,
                 back_color=(1, 1, 1)):
    """
    Function to create a series of png frames based upon a defining 
    a set of cameras at a set of times.
    This will save images as a series of png images in the directory
    specified.
    The movie will start at time 0 and will go to frame np.max(times)
    Reccomend to make times start at 0 and the length of the movie
    you want.  Keep in mind that typical movies are encoded at 15-30
    frames per second and times is units of frames.

    Parameters
    ----------
    actors :  list of vtkActor's
        list of vtkActors to render
    directory : str
        folder to save images into
    times : np.array
        array of K frame times to set the camera to
    cameras : list of vtkCamera's
        array of K vtkCamera objects. movie with have cameras[k]
        at times[k]. 
    start_frame : int
        number to save the first frame number as... (default 0)
        i.e. frames will start_frame = 5, first file would be 005.png
    video_width : int
        size of video in pixels
    video_height : int
        size of the video in pixels
    scale : int
        how much to expand the image
    do_save : bool
        whether to save the images to disk or just play interactively
    Returns
    -------
    vtkRenderer
        the renderer used to render
    endframe
        the last frame written
    Example
    -------
    ::

        from meshparty import trimesh_io, trimesh_vtk
        mm = trimesh_io.MeshMeta(disk_cache_path = 'meshes')
        mesh = mm.mesh(filename='mymesh.obj')
        mesh_actor = trimesh_vtk.mesh_actor(mesh)
        mesh_center = np.mean(mesh.vertices, axis=0)

        camera_start = trimesh_vtk.oriented_camera(mesh_center, backoff = 10000, backoff_vector=(0, 0, 1))
        camera_180 = trimesh_vtk.oriented_camera(mesh_center, backoff = 10000, backoff_vector=(0, 0, -1))
        times = np.array([0, 90, 180])
        cameras = [camera_start, camera_180, camera_start]
        render_movie([mesh_actor],
                'movie',
                times,
                cameras)
    """

    camera_interp = vtk.vtkCameraInterpolator()
    assert (len(times) == len(cameras))
    for t, cam in zip(times, cameras):
        camera_interp.AddCamera(t, cam)

    camera = vtk.vtkCamera()
    # create a rendering window and renderer
    ren, renWin, iren = _setup_renderer(video_width,
                                        video_height,
                                        back_color,
                                        camera=camera)

    for a in actors:
        # assign actor to the renderer
        ren.AddActor(a)

    imageFilter = vtk.vtkWindowToImageFilter()
    imageFilter.SetInput(renWin)
    imageFilter.SetScale(scale)
    imageFilter.SetInputBufferTypeToRGB()
    imageFilter.ReadFrontBufferOff()
    imageFilter.Update()

    # Setup movie writer
    if do_save:
        moviewriter = vtk.vtkPNGWriter()
        moviewriter.SetInputConnection(imageFilter.GetOutputPort())
        renWin.OffScreenRenderingOn()

    for i in np.arange(0, np.max(times) + 1):
        camera_interp.InterpolateCamera(i, camera)
        ren.ResetCameraClippingRange()
        camera.ViewingRaysModified()
        renWin.Render()

        if do_save:
            filename = os.path.join(directory, "%04d.png" % (i + start_frame))
            moviewriter.SetFileName(filename)
            # Export a current frame
            imageFilter.Update()
            imageFilter.Modified()
            moviewriter.Write()

    renWin.Finalize()
    return renWin, i + start_frame
Example #7
0
 def reset(self):
     self.interp = vtk.vtkCameraInterpolator()
Example #8
0
view4 = vtk.vtkCamera()
view4.SetClippingRange(14.0481, 14048.1)
view4.SetFocalPoint(562880, 5.11652e+006, 2733.15)
view4.SetPosition(562974, 5.11462e+006, 6419.98)
view4.SetViewAngle(30)
view4.SetViewUp(0.0047047, 0.888364, 0.459116)

view5 = vtk.vtkCamera()
view5.SetClippingRange(14.411, 14411)
view5.SetFocalPoint(562910, 5.11674e+006, 3027.15)
view5.SetPosition(562414, 5.11568e+006, 3419.87)
view5.SetViewAngle(30)
view5.SetViewUp(-0.0301976, 0.359864, 0.932516)

interpolator = vtk.vtkCameraInterpolator()
interpolator.SetInterpolationTypeToSpline()
interpolator.AddCamera(0, view1)
interpolator.AddCamera(5, view2)
interpolator.AddCamera(7.5, view3)
interpolator.AddCamera(9.0, view4)
interpolator.AddCamera(11.0, view5)

camera = vtk.vtkCamera()
ren1.SetActiveCamera(camera)


def animate():
    numSteps = 500
    min = interpolator.GetMinimumT()
    max = interpolator.GetMaximumT()
def make_camera_interpolator(times, cameras):
    assert (len(times) == len(cameras))
    camera_interp = vtk.vtkCameraInterpolator()
    for t, cam in zip(times, cameras):
        camera_interp.AddCamera(t, cam)
    return camera_interp
Example #10
0
 def reset(self):
     self.interp = vtk.vtkCameraInterpolator()