saving/restoring views..

Rainer Sabelka sabelka at iue.tuwien.ac.at
Wed May 3 04:08:16 EDT 2000


"K.R.Subramanian" wrote:

> Is there a convenient way to save a particular view (camera,
> perspective, etc.) so that
> the application can be brought back at a later time to the same view?
> [...]

I'm using the following tcl functions to save and restore the camera
position:
If you want to use this script with the latest nightly vtk you'll
probably have to change it according to the mail from David Gobbi [New
vtkCamera class] on Mon, 1 May 2000 15:35:38 -0400 (EDT).


proc saveCamera { fileName } {
        set filePtr [open $fileName w]
        set camera "\[ren1 GetActiveCamera\]"
        set activeCamera [ren1 GetActiveCamera]
        puts $filePtr "$camera SetPosition [$activeCamera GetPosition]"
        puts $filePtr "$camera SetFocalPoint [$activeCamera GetFocalPoint]"
        puts $filePtr "$camera SetViewAngle [$activeCamera GetViewAngle]"
        puts $filePtr "$camera SetViewUp [$activeCamera GetViewUp]"
        puts $filePtr "$camera SetViewPlaneNormal [$activeCamera GetViewPlaneNormal]"
        close $filePtr
}

#-----------------------------------------------------------------------------
# load a saved camera position

proc loadCamera { fileName } {
        global renWin

        #load the camera position
        source $fileName
        puts "file read"

        reset_light

        $renWin Render
}


#------------------------------------------------------------------------------# set the position of the light to the position of the active camera

proc reset_light {} {

        set lights [ren1 GetLights]
        puts "got lights $lights"
        set num_lights [$lights GetNumberOfItems]
        if { $num_lights == 1 } {
                puts "has $num_lights lights"
                $lights InitTraversal
                set light [$lights GetNextItem]
                puts "got light $light"
                set activeCamera [ren1 GetActiveCamera]
                set position [$activeCamera GetPosition]
                set pos0 [lindex $position 0]
                set pos1 [lindex $position 1]
                set pos2 [lindex $position 2]
                puts "position=($pos0,$pos1,$pos2)"
                $light SetPosition $pos0 $pos1 $pos2
        }
}

--
 Rainer Sabelka                     | Institute for Microelectronics
 phone:  +43 1 58801-36029          | Technical University Vienna
 fax:    +43 1 58801-36099          | Gusshausstrasse 27-29/E360
 e-mail: sabelka at iue.tuwien.ac.at   | A-1040 Vienna, Austria/Europe


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20000503/52ed1de6/attachment.html>


More information about the vtkusers mailing list