Python vtk.vtkCamera() Examples

The following are 12 code examples of vtk.vtkCamera(). 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: renderer.py    From pyvista with MIT License 7 votes vote down vote up
def scale_point(camera, point, invert=False):
    """Scale a point using the camera's transform matrix.

    Parameters
    ----------
    camera : vtk.vtkCamera
        The camera who's matrix to use.

    point : tuple(float)
        Length 3 tuple of the point coordinates.

    invert : bool
        If True, invert the matrix to transform the point out of the
        camera's transformed space. Default is False to transform a
        point from world coordinates to the camera's transformed space.

    """
    if invert:
        mtx = vtk.vtkMatrix4x4()
        mtx.DeepCopy(camera.GetModelTransformMatrix())
        mtx.Invert()
    else:
        mtx = camera.GetModelTransformMatrix()
    scaled = mtx.MultiplyDoublePoint((point[0], point[1], point[2], 0.0))
    return (scaled[0], scaled[1], scaled[2]) 
Example #2
Source File: plotting.py    From pyvista with MIT License 6 votes vote down vote up
def unlink_views(self, views=None):
        """Unlink the views' cameras.

        Parameters
        ----------
        views : None | int | tuple or list
            If ``views`` is None unlink all the views, if ``views``
            is int unlink the selected view's camera or if ``views``
            is a tuple or a list, unlink the given views cameras.

        """
        if views is None:
            for renderer in self.renderers:
                renderer.camera = vtk.vtkCamera()
                renderer.reset_camera()
        elif isinstance(views, int):
            self.renderers[views].camera = vtk.vtkCamera()
            self.renderers[views].reset_camera()
        elif isinstance(views, collections.abc.Iterable):
            for view_index in views:
                self.renderers[view_index].camera = vtk.vtkCamera()
                self.renderers[view_index].reset_camera()
        else:
            raise TypeError('Expected type is None, int, list or tuple:'
                            '{} is given'.format(type(views))) 
Example #3
Source File: camera.py    From BrainRender with MIT License 6 votes vote down vote up
def set_camera(scene, camera):
    """
        Sets the position of the camera of a brainrender scene.

        :param scene: instance of Scene()
        :param camera: either a string with the name of one of the available cameras, or
                        a dictionary of camera parameters. 
        
    """
    if camera is None: return

    if not isinstance(camera, vtk.vtkCamera):
        # Get camera params
        camera = check_camera_param(camera)

        # set params
        set_camera_params(scene.plotter.camera, camera)
    else:
        scene.plotter.camera = camera
    return camera 
Example #4
Source File: vtk.py    From panel with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def unlink_camera(self):
        """
        Create a fresh vtkCamera instance and set it to the renderer
        """
        import vtk
        old_camera = self.vtk_camera
        new_camera = vtk.vtkCamera()
        self.vtk_camera = new_camera
        if self.camera is not None:
            for k, v in self.camera.items():
                if type(v) is list:
                    getattr(new_camera, 'Set' + k[0].capitalize() + k[1:])(*v)
                else:
                    getattr(new_camera, 'Set' + k[0].capitalize() + k[1:])(v)
        else:
            new_camera.DeepCopy(old_camera) 
Example #5
Source File: vtkVisualization.py    From MOTSFusion with MIT License 5 votes vote down vote up
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 #6
Source File: camera.py    From BrainRender with MIT License 5 votes vote down vote up
def buildcam(cm):
    """
        Builds a camera from a dictionary of parameters, from vtkplotter
    """

    cm = cm.copy()
    
    cm_pos = cm.pop("position", None)
    cm_focalPoint = cm.pop("focal", None)
    cm_viewup = cm.pop("viewup", None)
    cm_distance = cm.pop("distance", None)
    cm_clippingRange = cm.pop("clipping", None)
    cm_parallelScale = cm.pop("parallelScale", None)
    cm_thickness = cm.pop("thickness", None)
    cm_viewAngle = cm.pop("viewAngle", None)

    cm = vtk.vtkCamera()

    if cm_pos is not None: cm.SetPosition(cm_pos)
    if cm_focalPoint is not None: cm.SetFocalPoint(cm_focalPoint)
    if cm_viewup is not None: cm.SetViewUp(cm_viewup)
    if cm_distance is not None: cm.SetDistance(cm_distance)
    if cm_clippingRange is not None: cm.SetClippingRange(cm_clippingRange)
    if cm_parallelScale is not None: cm.SetParallelScale(cm_parallelScale)
    if cm_thickness is not None: cm.SetThickness(cm_thickness)
    if cm_viewAngle is not None: cm.SetViewAngle(cm_viewAngle)
    
    return cm 
Example #7
Source File: vis.py    From DeepV2D with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #8
Source File: vis.py    From DeepV2D with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #9
Source File: cameracontrol.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def getViewCameraCopy(self):
        camera = vtk.vtkCamera()
        camera.DeepCopy(self.view.camera())
        return camera 
Example #10
Source File: cameracontrol.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def getCameraCopy(self):
        camera = vtk.vtkCamera()
        camera.DeepCopy(self.view.camera())
        return camera 
Example #11
Source File: cameracontrol.py    From director with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def getCameraCopy(self):
        camera = vtk.vtkCamera()
        camera.DeepCopy(self.view.camera())
        return camera 
Example #12
Source File: vtk_helpers.py    From NURBS-Python with MIT License 4 votes vote down vote up
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