[vtkusers] vtkCamera Parameters

David Pont david_pont at hotmail.com
Thu Oct 26 13:02:41 EDT 2000

  Here are code fragments that I use to save camera settings to file and 
load them back again:

        double dA[3], dV;
        int iV;
        vtkCamera *Camera = Renderer->GetActiveCamera();

        Camera->GetPosition( dA );
            fprintf( f, "Position=%lg,%lg,%lg\n", dA[0], dA[1], dA[2] );
        Camera->GetFocalPoint( dA );
            fprintf( f, "FocalPoint=%lg,%lg,%lg\n", dA[0], dA[1], dA[2] );
        Camera->GetViewUp( dA );
            fprintf( f, "ViewUp=%lg,%lg,%lg\n", dA[0], dA[1], dA[2] );
        dV = Camera->GetViewAngle();
            fprintf( f, "ViewAngle=%lg\n", dV );
        Camera->GetViewPlaneNormal( dA );
            fprintf( f, "ViewPlaneNormal=%lg,%lg,%lg\n", dA[0], dA[1], dA[2] 
        iV = Camera->GetParallelProjection();
            fprintf( f, "ParallelProjection=%d\n", iV );
        dV = Camera->GetParallelScale();
            fprintf( f, "ParallelScale=%lg\n", dV );

I use similar code to load the settings back from file into a temporary 
structure, then do the following:

        Camera->SetPosition( C->Position );
        Camera->SetFocalPoint( C->FocalPoint );
        Camera->SetViewUp( C->ViewUp );
        Camera->SetViewAngle( C->ViewAngle );
        Camera->SetViewPlaneNormal( C->ViewPlaneNormal );
        Camera->SetParallelProjection( C->ParallelProjection );
        Camera->SetParallelScale( C->ParallelScale );


        vtkLightCollection* Lights = Renderer->GetLights();
        int i, n = Lights->GetNumberOfItems();
        vtkLight *Light;
        float pos[3], fp[3];

        Camera->GetPosition( pos );
        Camera->GetFocalPoint( fp );
        for( i=0; i<n; i++ ) {
            Light = Lights->GetNextItem();
            Light->SetPosition( pos );
            Light->SetFocalPoint( fp );

I have cobbled this together from some questions/responses I found in the 
mailing list archive, plus a bit of my own fiddling. There may be a few 
redundant or dumb bits, but it works OK for me.

    Dave Pont

>From: Erik Sobel <erik.sobel at alphatech.com>
>To: vtkusers at public.kitware.com
>Subject: [vtkusers] vtkCamera Parameters
>Date: Wed, 25 Oct 2000 11:55:07 -0400
>Does anyone know how to completely specify the camera parameters?
>I am frustrated by the lack of consistency in its methods.  There is a
>Get/SetRoll pair, Get/SetPosition, and Get/SetFocalPoint but no way to Get:
>Zoom, Dolly, Yaw,  Azimuth, Pitch or Elevation.  There is a way to
>GetOrientationWXYZ but no way to Set it.  Calling the renderer's
>ResetCamera method doesn't seem to reset ALL of the camera's parameters.
>What I am looking for is a convenient way to save and restore the complete
>state of the camera after it has been moved by hand.
>This is the private VTK discussion list.
>Please keep messages on-topic. Check the FAQ at: 
>Follow this link to subscribe/unsubscribe:

Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 

More information about the vtkusers mailing list