[vtkusers] SetParallelProjection vs. SetPosition
Phlip
pplumlee at omnigon.com
Thu Jun 21 17:17:51 EDT 2001
VTK Users:
Below my signature is Pythonage that should display a box with a bunch of
variously sized marbles floating in it. We're using this for a 3d
scatterplot.
When the line marked "YO" is commented out, the SetPosition call
correctly puts the camera away from the box and looking at it.
When that line, containing SetParallelProjection, is active, the camera is
born inside the box looking out. Disconcerting to say the least.
I have tried any number of dollies and zooms and repositionings, and the
camera refuses to be born in the right position, and refuses to reveal its
position correctly after I use the widget's interaction to draw the camera
back out of the box. (But that last action might instead be drawing the
box off the camera.)
How to turn off perspective projection but still have the camera born
looking at our object?
(If we fix this, please feel free to drop it into your examplesPython
folder.)
--
Phlip phlip_cpp at my-deja.com
============== http://phlip.webjump.com ==============
-- Got in trouble at StarBucks. I tried to order
"A double latte mocha and a body piercing." --
import os, sys
from libVTKCommonPython import *
from libVTKGraphicsPython import *
import Tkinter
from Tkinter import *
from vtkpython import *
from vtkRenderWidget import *
from whrandom import random
from math import sqrt
class OPlotter3d:
def __init__(self) :
return
def makeCamera(self):
camera = vtkCamera()
camera.SetParallelProjection(1) # <-- YO
camera.SetPosition(0,0,100)
return camera
def reveal(self, list):
top = Tk()
top_f1 = Frame(top)
pane = vtkTkRenderWidget(top_f1,width=300,height=300)
ren = vtkRenderer()
renWin = pane.GetRenderWindow()
renWin.AddRenderer(ren)
self.renderShapes(list, ren)
top_btn = Button(top,text="Quit",command=top.tk.quit)
pane.pack(side='left',padx=3,pady=3,fill='both',expand='t')
top_f1.pack(fill='both',expand='t')
top_btn.pack(fill='y')
top.mainloop()
return
def renderShapes(self, list, ren):
# create lights
#
# CameraLights are defined in a local coordinate system where
# the camera is at (0, 0, 1), looking at (0, 0, 0), with up
# being (0, 1, 0)
#
keyLight = vtkLight()
keyLight.SetLightTypeToCameraLight()
keyLight.SetPosition(0.25, 1.0, 0.75)
keyLight.SetColor(1.0, 1.0, 0.9)
ren.AddLight(keyLight)
ptLoad = vtkPointLoad()
ptLoad.SetModelBounds(-10,10,-10,10,-10,10)
#
# Create outline around data
#
outline = vtkOutlineFilter()
outline.SetInput(ptLoad.GetOutput())
outlineMapper = vtkPolyDataMapper()
outlineMapper.SetInput(outline.GetOutput())
outlineActor = vtkActor()
outlineActor.SetMapper(outlineMapper)
outlineActor.GetProperty().SetColor(0.25,0.25,0.25)
#
# Create cone indicating application of load
#
ballSrc = vtkSphereSource()
ballSrc.SetRadius(.5)
# inspectObject(ballSrc)
ballMap = vtkPolyDataMapper()
ballMap.SetInput(ballSrc.GetOutput())
camera = self.makeCamera()
ren.SetActiveCamera(camera)
ren.ResetCameraClippingRange()
camera.Modified()
ren.AddActor(outlineActor)
self.makeBalls(ren, list, ballMap)
ren.SetBackground(0.75,0.75,0.75)
return 1
def addBall(self, ren, data, ballMap):
ball = vtkActor()
ball.SetMapper(ballMap)
ball.SetPosition(data[:3])
prop = ball.GetProperty()
ball.SetScale(data[3])
prop.SetColor(0,1,0)
ren.AddActor(ball)
return
def makeBalls(self, ren, list, ballMap):
sample = list[0]
mins = [sample[0],sample[1],sample[2]]
maxs = [mins[0], mins[1], mins[2]]
first = 1
for q in list:
if not first:
for x in range (0, 3):
if mins[x] > q[x]: mins[x] = q[x]
if maxs[x] < q[x]: maxs[x] = q[x]
first = 0
extent = 0.0
extents = [0] * 3
for x in range (0, 3):
diff = maxs[x] - mins[x]
extents[x] = diff
if extent < abs(diff):
extent = abs(diff)
for q in list:
xyzs = q
for x in range (0, 3):
# scale and translate to a bounding box of -10 to
10 on a side
nu = (xyzs[x] - mins[x]) /extent
nu *= 20.0
nu -= 10.0
assert nu >= -10.0
assert nu <= 10.0
xyzs[x] = nu
# size scaling
xyzs[3] *= 10.
More information about the vtkusers
mailing list