[vtkusers] pinhole camera in vtk

Hal Canary hal at cs.unc.edu
Mon Sep 10 06:52:49 EDT 2012


On 09/10/2012 06:08 AM, Muhammad Zeshan Afzal wrote:
> I want to render a scene interactively. The controls are already
> provided by VTK so that you can position the camera with mouse but
> you never know the exact value of the internals and external
> parameter of the camera.
>
> I want to manipulate the internal camera values as well e.g focal
> length, principle point.
>
> For external parameters I want to set the translation and rotation of
> the camera.
>
> I want to give all the values manually. Could anyone please help to
> point to such a demo or a code snippet to do it. Preferably in
> python.

You should be able to get to the  the camera internals with
GetActiveCamera().
	http://www.vtk.org/doc/nightly/html/classvtkCamera.html

#!/usr/local/bin/vtkpython
import vtk, time
cube = vtk.vtkCubeSource()
mapper = vtk.vtkPolyDataMapper()
cubeActor = vtk.vtkActor()
renderer = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
mapper.SetInputConnection(cube.GetOutputPort())
cubeActor.SetMapper(mapper)
renWin.AddRenderer(renderer)
renderer.AddActor(cubeActor)
renderer.GetActiveCamera().SetPosition(1.0, 3.0, 1.5)
renWin.Render()
time.sleep(2.0)
renderer.GetActiveCamera().SetPosition(1.0, 4.0, 1.5)
renWin.Render()
time.sleep(2.0)
renderer.GetActiveCamera().SetPosition(1.0, 5.0, 1.5)
renWin.Render()
time.sleep(2.0)
renderer.GetActiveCamera().SetPosition(1.0, 6.0, 1.5)
renWin.Render()
exit()



More information about the vtkusers mailing list