[vtkusers] restoring & saving camera positions

Bernhard Hombitzer Bernhard at Hombitzer.com
Mon Jun 26 11:51:35 EDT 2000


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





More information about the vtkusers mailing list