Commit 3810c5a6 authored by Andrew Maclean's avatar Andrew Maclean
Browse files

These Python tests have been refactored.



This has been done by removing the "tcl-isms" and making
 the code more readable. In some cases redundant code
 has been removed (often a result of copy/paste operations).
 The code has also been checked to ensure each line is 80
 characters or less.

The code can now be run using vtkpython or by using the
 appropriate Python environment.

Originally these were TCL scripts that were converted using
  vtkTclTestToPy.py and they they needed to be run through the
  rtImageTest.py driver which defines a few needed
  functions/variables for their operation. To this end
  backdrop.py has been added where it is needed.

Change-Id: I50d6505628c140ea4551f74f7f3e85df907567e1
Signed-off-by: Andrew Maclean's avatarAndrew Maclean <andrew.amaclean@gmail.com>
parent d77d09c5
......@@ -11,88 +11,106 @@ renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
math = vtk.vtkMath()
numberOfInputPoints = 30
aSplineX = vtk.vtkCardinalSpline()
aSplineY = vtk.vtkCardinalSpline()
aSplineZ = vtk.vtkCardinalSpline()
# generate random points
inputPoints = vtk.vtkPoints()
i = 0
while i < numberOfInputPoints:
x = math.Random(0,1)
y = math.Random(0,1)
z = math.Random(0,1)
aSplineX.AddPoint(i,x)
aSplineY.AddPoint(i,y)
aSplineZ.AddPoint(i,z)
inputPoints.InsertPoint(i,x,y,z)
i = i + 1
x = math.Random(0, 1)
y = math.Random(0, 1)
z = math.Random(0, 1)
aSplineX.AddPoint(i, x)
aSplineY.AddPoint(i, y)
aSplineZ.AddPoint(i, z)
inputPoints.InsertPoint(i, x, y, z)
i += 1
inputData = vtk.vtkPolyData()
inputData.SetPoints(inputPoints)
balls = vtk.vtkSphereSource()
balls.SetRadius(.01)
balls.SetPhiResolution(10)
balls.SetThetaResolution(10)
glyphPoints = vtk.vtkGlyph3D()
glyphPoints.SetInputData(inputData)
glyphPoints.SetSourceConnection(balls.GetOutputPort())
glyphMapper = vtk.vtkPolyDataMapper()
glyphMapper.SetInputConnection(glyphPoints.GetOutputPort())
glyph = vtk.vtkActor()
glyph.SetMapper(glyphMapper)
glyph.GetProperty().SetDiffuseColor(1,0.4,0.4)
glyph.GetProperty().SetDiffuseColor(1, 0.4, 0.4)
glyph.GetProperty().SetSpecular(.3)
glyph.GetProperty().SetSpecularPower(30)
ren1.AddActor(glyph)
# create a polyline
points = vtk.vtkPoints()
profileData = vtk.vtkPolyData()
numberOfOutputPoints = 400
offset = 1.0
def fit (__vtk__temp0=0,__vtk__temp1=0):
global numberOfInputPoints, numberOfOutputPoints, offset
def fit ():
points.Reset()
i = 0
while i < numberOfOutputPoints:
t = expr.expr(globals(), locals(),["(","numberOfInputPoints","-","offset",")","/","(","numberOfOutputPoints","-","1",")","*","i"])
points.InsertPoint(i,aSplineX.Evaluate(t),aSplineY.Evaluate(t),aSplineZ.Evaluate(t))
i = i + 1
t = (numberOfInputPoints - offset) / (numberOfOutputPoints - 1) * i
points.InsertPoint(i, aSplineX.Evaluate(t), aSplineY.Evaluate(t), aSplineZ.Evaluate(t))
i += 1
profileData.Modified()
fit()
lines = vtk.vtkCellArray()
lines.InsertNextCell(numberOfOutputPoints)
i = 0
while i < numberOfOutputPoints:
lines.InsertCellPoint(i)
i = i + 1
i += 1
profileData.SetPoints(points)
profileData.SetLines(lines)
profileTubes = vtk.vtkTubeFilter()
profileTubes.SetNumberOfSides(8)
profileTubes.SetInputData(profileData)
profileTubes.SetRadius(.005)
profileMapper = vtk.vtkPolyDataMapper()
profileMapper.SetInputConnection(profileTubes.GetOutputPort())
profile = vtk.vtkActor()
profile.SetMapper(profileMapper)
profile.GetProperty().SetDiffuseColor(1,1,0.6)
profile.GetProperty().SetDiffuseColor(1, 1, 0.6)
profile.GetProperty().SetSpecular(.3)
profile.GetProperty().SetSpecularPower(30)
ren1.AddActor(profile)
ren1.ResetCamera()
ren1.GetActiveCamera().Dolly(1.5)
ren1.ResetCameraClippingRange()
renWin.SetSize(400,400)
renWin.SetSize(400, 400)
# render the image
#
iren.Initialize()
def opened (__vtk__temp0=0,__vtk__temp1=0):
global offset
def opened (aSplineX, aSplineY, aSplineZ):
offset = 1.0
aSplineX.ClosedOff()
aSplineY.ClosedOff()
......@@ -100,7 +118,7 @@ def opened (__vtk__temp0=0,__vtk__temp1=0):
fit()
renWin.Render()
def varyLeft (__vtk__temp0=0,__vtk__temp1=0):
def varyLeft (aSplineX, aSplineY, aSplineZ):
left = -1
while left <= 1:
aSplineX.SetLeftValue(left)
......@@ -108,10 +126,10 @@ def varyLeft (__vtk__temp0=0,__vtk__temp1=0):
aSplineZ.SetLeftValue(left)
fit()
renWin.Render()
left = expr.expr(globals(), locals(),["left","+",".05"])
left += 0.05
def varyRight (__vtk__temp0=0,__vtk__temp1=0):
def varyRight (aSplineX, aSplineY, aSplineZ):
right = -1
while right <= 1:
aSplineX.SetRightValue(right)
......@@ -119,10 +137,10 @@ def varyRight (__vtk__temp0=0,__vtk__temp1=0):
aSplineZ.SetRightValue(right)
fit()
renWin.Render()
right = expr.expr(globals(), locals(),["right","+",".05"])
right += 0.05
def constraint (value,__vtk__temp0=0,__vtk__temp1=0):
def constraint (value, aSplineX, aSplineY, aSplineZ):
aSplineX.SetLeftConstraint(value)
aSplineY.SetLeftConstraint(value)
aSplineZ.SetLeftConstraint(value)
......@@ -130,8 +148,7 @@ def constraint (value,__vtk__temp0=0,__vtk__temp1=0):
aSplineY.SetRightConstraint(value)
aSplineZ.SetRightConstraint(value)
def closed (__vtk__temp0=0,__vtk__temp1=0):
global offset
def closed (aSplineX, aSplineY, aSplineZ):
offset = 0.0
aSplineX.ClosedOn()
aSplineY.ClosedOn()
......@@ -139,5 +156,4 @@ def closed (__vtk__temp0=0,__vtk__temp1=0):
fit()
renWin.Render()
# prevent the tk window from showing up then start the event loop
# --- end of script --
#iren.Start()
......@@ -11,42 +11,53 @@ renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
math = vtk.vtkMath()
numberOfInputPoints = 30
aSplineX = vtk.vtkKochanekSpline()
aSplineY = vtk.vtkKochanekSpline()
aSplineZ = vtk.vtkKochanekSpline()
# generate random points
inputPoints = vtk.vtkPoints()
i = 0
while i < numberOfInputPoints:
x = math.Random(0,1)
y = math.Random(0,1)
z = math.Random(0,1)
aSplineX.AddPoint(i,x)
aSplineY.AddPoint(i,y)
aSplineZ.AddPoint(i,z)
inputPoints.InsertPoint(i,x,y,z)
i = i + 1
x = math.Random(0, 1)
y = math.Random(0, 1)
z = math.Random(0, 1)
aSplineX.AddPoint(i, x)
aSplineY.AddPoint(i, y)
aSplineZ.AddPoint(i, z)
inputPoints.InsertPoint(i, x, y, z)
i += 1
inputData = vtk.vtkPolyData()
inputData.SetPoints(inputPoints)
balls = vtk.vtkSphereSource()
balls.SetRadius(.01)
balls.SetPhiResolution(10)
balls.SetThetaResolution(10)
glyphPoints = vtk.vtkGlyph3D()
glyphPoints.SetInputData(inputData)
glyphPoints.SetSourceConnection(balls.GetOutputPort())
glyphMapper = vtk.vtkPolyDataMapper()
glyphMapper.SetInputConnection(glyphPoints.GetOutputPort())
glyph = vtk.vtkActor()
glyph.SetMapper(glyphMapper)
glyph.GetProperty().SetDiffuseColor(1,0.6,0.6)
glyph.GetProperty().SetDiffuseColor(1, 0.6, 0.6)
glyph.GetProperty().SetSpecular(.3)
glyph.GetProperty().SetSpecularPower(30)
ren1.AddActor(glyph)
points = vtk.vtkPoints()
# create a line
tension = 0
bias = 0
......@@ -60,23 +71,26 @@ aSplineY.SetDefaultContinuity(continuity)
aSplineZ.SetDefaultTension(tension)
aSplineZ.SetDefaultBias(bias)
aSplineZ.SetDefaultContinuity(continuity)
profileData = vtk.vtkPolyData()
numberOfOutputPoints = 300
offset = 1.0
def fit (__vtk__temp0=0,__vtk__temp1=0):
global numberOfInputPoints, numberOfOutputPoints, offset
def fit ():
points.Reset()
i = 0
while i < numberOfOutputPoints:
t = expr.expr(globals(), locals(),["(","numberOfInputPoints","-","offset",")","/","(","numberOfOutputPoints","-","1",")","*","i"])
points.InsertPoint(i,aSplineX.Evaluate(t),aSplineY.Evaluate(t),aSplineZ.Evaluate(t))
t = (numberOfInputPoints - offset) / (numberOfOutputPoints - 1) * i
points.InsertPoint(i, aSplineX.Evaluate(t), aSplineY.Evaluate(t), aSplineZ.Evaluate(t))
i = i + 1
profileData.Modified()
fit()
lines = vtk.vtkCellArray()
lines.InsertNextCell(numberOfOutputPoints)
i = 0
while i < numberOfOutputPoints:
lines.InsertCellPoint(i)
......@@ -84,27 +98,33 @@ while i < numberOfOutputPoints:
profileData.SetPoints(points)
profileData.SetLines(lines)
profileTubes = vtk.vtkTubeFilter()
profileTubes.SetNumberOfSides(8)
profileTubes.SetInputData(profileData)
profileTubes.SetRadius(.005)
profileMapper = vtk.vtkPolyDataMapper()
profileMapper.SetInputConnection(profileTubes.GetOutputPort())
profile = vtk.vtkActor()
profile.SetMapper(profileMapper)
profile.GetProperty().SetDiffuseColor(1,1,0.7)
profile.GetProperty().SetDiffuseColor(1, 1, 0.7)
profile.GetProperty().SetSpecular(.3)
profile.GetProperty().SetSpecularPower(30)
ren1.AddActor(profile)
ren1.GetActiveCamera().Dolly(1.5)
ren1.ResetCamera()
ren1.ResetCameraClippingRange()
renWin.SetSize(400,400)
renWin.SetSize(400, 400)
# render the image
#
iren.Initialize()
# prevent the tk window from showing up then start the event loop
def defaults (__vtk__temp0=0,__vtk__temp1=0):
def defaults (aSplineX, aSplineY, aSplineZ):
aSplineX.SetDefaultBias(0)
aSplineX.SetDefaultTension(0)
aSplineX.SetDefaultContinuity(0)
......@@ -117,8 +137,8 @@ def defaults (__vtk__temp0=0,__vtk__temp1=0):
fit()
renWin.Render()
def varyBias (__vtk__temp0=0,__vtk__temp1=0):
defaults()
def varyBias (aSplineX, aSplineY, aSplineZ):
defaults(aSplineX, aSplineY, aSplineZ)
bias = -1
while bias <= 1:
aSplineX.SetDefaultBias(bias)
......@@ -126,11 +146,11 @@ def varyBias (__vtk__temp0=0,__vtk__temp1=0):
aSplineZ.SetDefaultBias(bias)
fit()
renWin.Render()
bias = expr.expr(globals(), locals(),["bias","+",".05"])
bias += .05
def varyTension (__vtk__temp0=0,__vtk__temp1=0):
defaults()
def varyTension (aSplineX, aSplineY, aSplineZ):
defaults(aSplineX, aSplineY, aSplineZ)
tension = -1
while tension <= 1:
aSplineX.SetDefaultTension(tension)
......@@ -138,11 +158,11 @@ def varyTension (__vtk__temp0=0,__vtk__temp1=0):
aSplineZ.SetDefaultTension(tension)
fit()
renWin.Render()
tension = expr.expr(globals(), locals(),["tension","+",".05"])
tension += 0.05
def varyContinuity (__vtk__temp0=0,__vtk__temp1=0):
defaults()
def varyContinuity (aSplineX, aSplineY, aSplineZ):
defaults(aSplineX, aSplineY, aSplineZ)
Continuity = -1
while Continuity <= 1:
aSplineX.SetDefaultContinuity(Continuity)
......@@ -150,11 +170,10 @@ def varyContinuity (__vtk__temp0=0,__vtk__temp1=0):
aSplineZ.SetDefaultContinuity(Continuity)
fit()
renWin.Render()
Continuity = expr.expr(globals(), locals(),["Continuity","+",".05"])
Continuity += 0.05
def closed (__vtk__temp0=0,__vtk__temp1=0):
global offset
def closed (aSplineX, aSplineY, aSplineZ):
offset = 0.0
aSplineX.ClosedOn()
aSplineY.ClosedOn()
......@@ -162,8 +181,7 @@ def closed (__vtk__temp0=0,__vtk__temp1=0):
fit()
renWin.Render()
def opened (__vtk__temp0=0,__vtk__temp1=0):
global offset
def opened (aSplineX, aSplineY, aSplineZ):
offset = 1.0
aSplineX.ClosedOff()
aSplineY.ClosedOff()
......@@ -171,4 +189,4 @@ def opened (__vtk__temp0=0,__vtk__temp1=0):
fit()
renWin.Render()
# --- end of script --
# iren.Start()
......@@ -4,6 +4,15 @@ from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
def GetRGBColor(colorName):
'''
Return the red, green and blue components for a
color as doubles.
'''
rgb = [0.0, 0.0, 0.0] # black
vtk.vtkNamedColors().GetColorRGB(colorName, rgb)
return rgb
# get the interactor ui
# Now create the RenderWindow, Renderer and Interactor
#
......@@ -12,209 +21,241 @@ renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
math = vtk.vtkMath()
# math = vtk.vtkMath()
numberOfInputPoints = 30
aKSplineX = vtk.vtkKochanekSpline()
aKSplineX.ClosedOn()
aKSplineY = vtk.vtkKochanekSpline()
aKSplineY.ClosedOn()
aKSplineZ = vtk.vtkKochanekSpline()
aKSplineZ.ClosedOn()
aCSplineX = vtk.vtkCardinalSpline()
aCSplineX.ClosedOn()
aCSplineY = vtk.vtkCardinalSpline()
aCSplineY.ClosedOn()
aCSplineZ = vtk.vtkCardinalSpline()
aCSplineZ.ClosedOn()
# add some points
inputPoints = vtk.vtkPoints()
x = -1.0
y = -1.0
z = 0.0
aKSplineX.AddPoint(0,x)
aKSplineY.AddPoint(0,y)
aKSplineZ.AddPoint(0,z)
aCSplineX.AddPoint(0,x)
aCSplineY.AddPoint(0,y)
aCSplineZ.AddPoint(0,z)
inputPoints.InsertPoint(0,x,y,z)
aKSplineX.AddPoint(0, x)
aKSplineY.AddPoint(0, y)
aKSplineZ.AddPoint(0, z)
aCSplineX.AddPoint(0, x)
aCSplineY.AddPoint(0, y)
aCSplineZ.AddPoint(0, z)
inputPoints.InsertPoint(0, x, y, z)
x = 1.0
y = -1.0
z = 0.0
aKSplineX.AddPoint(1,x)
aKSplineY.AddPoint(1,y)
aKSplineZ.AddPoint(1,z)
aCSplineX.AddPoint(1,x)
aCSplineY.AddPoint(1,y)
aCSplineZ.AddPoint(1,z)
inputPoints.InsertPoint(1,x,y,z)
aKSplineX.AddPoint(1, x)
aKSplineY.AddPoint(1, y)
aKSplineZ.AddPoint(1, z)
aCSplineX.AddPoint(1, x)
aCSplineY.AddPoint(1, y)
aCSplineZ.AddPoint(1, z)
inputPoints.InsertPoint(1, x, y, z)
x = 1.0
y = 1.0
z = 0.0
aKSplineX.AddPoint(2,x)
aKSplineY.AddPoint(2,y)
aKSplineZ.AddPoint(2,z)
aCSplineX.AddPoint(2,x)
aCSplineY.AddPoint(2,y)
aCSplineZ.AddPoint(2,z)
inputPoints.InsertPoint(2,x,y,z)
aKSplineX.AddPoint(2, x)
aKSplineY.AddPoint(2, y)
aKSplineZ.AddPoint(2, z)
aCSplineX.AddPoint(2, x)
aCSplineY.AddPoint(2, y)
aCSplineZ.AddPoint(2, z)
inputPoints.InsertPoint(2, x, y, z)
x = -1.0
y = 1.0
z = 0.0
aKSplineX.AddPoint(3,x)
aKSplineY.AddPoint(3,y)
aKSplineZ.AddPoint(3,z)
aCSplineX.AddPoint(3,x)
aCSplineY.AddPoint(3,y)
aCSplineZ.AddPoint(3,z)
inputPoints.InsertPoint(3,x,y,z)
aKSplineX.AddPoint(3, x)
aKSplineY.AddPoint(3, y)
aKSplineZ.AddPoint(3, z)
aCSplineX.AddPoint(3, x)
aCSplineY.AddPoint(3, y)
aCSplineZ.AddPoint(3, z)
inputPoints.InsertPoint(3, x, y, z)
inputData = vtk.vtkPolyData()
inputData.SetPoints(inputPoints)
balls = vtk.vtkSphereSource()
balls.SetRadius(.04)
balls.SetPhiResolution(10)
balls.SetThetaResolution(10)
glyphPoints = vtk.vtkGlyph3D()
glyphPoints.SetInputData(inputData)
glyphPoints.SetSourceConnection(balls.GetOutputPort())
glyphMapper = vtk.vtkPolyDataMapper()
glyphMapper.SetInputConnection(glyphPoints.GetOutputPort())
glyph = vtk.vtkActor()
glyph.SetMapper(glyphMapper)
glyph.GetProperty().SetDiffuseColor(tomato)
glyph.GetProperty().SetDiffuseColor(GetRGBColor('tomato'))
glyph.GetProperty().SetSpecular(.3)
glyph.GetProperty().SetSpecularPower(30)
ren1.AddActor(glyph)
Kpoints = vtk.vtkPoints()
Cpoints = vtk.vtkPoints()
profileKData = vtk.vtkPolyData()
profileCData = vtk.vtkPolyData()
numberOfInputPoints = 5
numberOfOutputPoints = 100
offset = 1.0
def fit (__vtk__temp0=0,__vtk__temp1=0):
global numberOfInputPoints, numberOfOutputPoints, offset
def fit ():
Kpoints.Reset()
Cpoints.Reset()
i = 0
while i < numberOfOutputPoints:
t = expr.expr(globals(), locals(),["(","numberOfInputPoints","-","offset",")","/","(","numberOfOutputPoints","-","1",")","*","i"])
Kpoints.InsertPoint(i,aKSplineX.Evaluate(t),aKSplineY.Evaluate(t),aKSplineZ.Evaluate(t))
Cpoints.InsertPoint(i,aCSplineX.Evaluate(t),aCSplineY.Evaluate(t),aCSplineZ.Evaluate(t))
i = i + 1
t = (numberOfInputPoints - offset) / (numberOfOutputPoints - 1) * i
Kpoints.InsertPoint(i, aKSplineX.Evaluate(t), aKSplineY.Evaluate(t), aKSplineZ.Evaluate(t))
Cpoints.InsertPoint(i, aCSplineX.Evaluate(t), aCSplineY.Evaluate(t), aCSplineZ.Evaluate(t))
i += 1
profileKData.Modified()
profileCData.Modified()
fit()
lines = vtk.vtkCellArray()
lines.InsertNextCell(numberOfOutputPoints)
i = 0
while i < numberOfOutputPoints:
lines.InsertCellPoint(i)
i = i + 1
i += 1
profileKData.SetPoints(Kpoints)
profileKData.SetLines(lines)
profileCData.SetPoints(Cpoints)
profileCData.SetLines(lines)
profileKTubes = vtk.vtkTubeFilter()
profileKTubes.SetNumberOfSides(8)
profileKTubes.SetInputData(profileKData)
profileKTubes.SetRadius(.01)
profileKMapper = vtk.vtkPolyDataMapper()
profileKMapper.SetInputConnection(profileKTubes.GetOutputPort())
profileK = vtk.vtkActor()
profileK.SetMapper(profileKMapper)
profileK.GetProperty().SetDiffuseColor(banana)
profileK.GetProperty().SetDiffuseColor(GetRGBColor('banana'))
profileK.GetProperty().SetSpecular(.3)
profileK.GetProperty().SetSpecularPower(30)
ren1.AddActor(profileK)
profileCTubes = vtk.vtkTubeFilter()
profileCTubes.SetNumberOfSides(8)
profileCTubes.SetInputData(profileCData)
profileCTubes.SetRadius(.01)