[vtkusers] restoring & saving camera positions

Yamrom, Boris (CRD) yamrom at crd.ge.com
Wed Jun 28 16:13:20 EDT 2000


Here is the script that works for me. vtk/examplesTcl/savecamera.tcl is a little more simple and is
less robust.
#
# save a vtk camera to a file in tcl format
#
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 SetClippingRange [$activeCamera GetClippingRange]"
    puts $filePtr "$camera SetParallelScale [$activeCamera GetParallelScale]"
    puts $filePtr "$camera ComputeViewPlaneNormal"


    puts $filePtr {set camera [ren1 GetActiveCamera]; set lights [ren1 GetLights];
    $lights InitTraversal ;
    set light [$lights GetNextItem] ;
    eval $light SetPosition [$camera GetPosition] ;
    eval $light SetFocalPoint [$camera GetFocalPoint]}
    close $filePtr
}

Boris Yamrom, PhD
Graphics Scientist
Computer Graphics & Systems Program
General Electric Company
Building KW, Room C214, One Research Circle
Niskayuna, NY 12309
518 387-6920, DC: 8*833-6920, Fax: 518 387-6920
-----Original Message-----
From: Bernhard Hombitzer [mailto:Bernhard at Hombitzer.com]
Sent: Monday, June 26, 2000 11:52 AM
To: vtkusers at public.kitware.com
Subject: [vtkusers] restoring & saving camera positions


Hi all,

I tried to wrote some routines to to save and to restore camera properties.
After having some difficulties, I found some code in the archive.
But with this portion of code the same problem still accours.

Now my problem:

If I have a scene in the renderwindow and I call
SetPosition from the Renderers camera, my RenderWindows becomes black.
Nothing happens if I call renderer.render or the windows gets the focus.

The only thing to get the scene renderer again, is to make a short click
with the mouse into the renderwindow.

I have the same problem with the load/savecamera code which is included in the
bottom.
What do I have to do, do get the scene rendered successfully after
repositioning the camera

thanks
   Berni

-------------------------------------------------------------------------
catch {load vtktcl}

vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin
renWin SetSize 500 500
iren SetUserMethod {wm deiconify .vtkInteract}
renWin Render

vtkUnstructuredGridReader ugr
	ugr SetFileName "i:\\kincx\\comp.vtk"

vtkCellDataToPointData ctp
	ctp SetInput [ugr GetOutput]

vtkGeometryFilter gf
	gf SetInput [ctp GetOutput]

vtkPolyDataNormals pdn
	pdn SetInput [gf GetOutput]

vtkPolyDataMapper pdm
	pdm SetInput [pdn GetOutput]

vtkLODActor act
	act SetMapper pdm

ren1 AddActor act

ren1 ResetCamera
ren1 Render

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
}

proc loadCamera { fileName } {
        global renWin
        source $fileName
        puts "file read"
        reset_light
        renWin Render
}

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
        }
}

saveCamera "test"
#now zooming out far away, but I see a small piece of my part
loadCamera "test"
#now the windows becomes black
#make a short click with the mouse into the window
#now the scene is restored


_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
vtkusers mailing list
vtkusers at public.kitware.com
http://public.kitware.com/mailman/listinfo/vtkusers




More information about the vtkusers mailing list