Commit 758a3cc5 authored by Nikhil Shetty's avatar Nikhil Shetty
Browse files

Adding CommonComutationalGeometry python tests

- add_test_python() macro is used.
- New test which were previously autogenerated from Tcl are brought in

Note: Not all tests work. Will need to revisit them.

Change-Id: Ia9130012fc38ccb066def01557320e89ef91c25d
parent 79e94867
if(VTK_PYTHON_EXE)
set(tests)
if(VTK_DATA_ROOT)
# Tests written in Python that require VTKData
# These tests should use vtk.test.Testing.
set(tests
${tests}
TestParametricFunctions
)
else()
# Tests written in Python that do NOT require VTKData
# These tests should use vtk.test.Testing.
set(tests
${tests}
)
endif()
if(tests)
foreach(tfile ${tests})
add_test(NAME ${vtk-module}Python-${tfile}
COMMAND ${VTK_PYTHON_EXE}
${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.py
-D ${VTK_DATA_ROOT}
-B ${VTK_DATA_ROOT}/Baseline/Graphics)
endforeach()
endif()
else()
message(FATAL_ERROR "No Python tests added!")
endif()
add_test_python(CSpline.py Filtering)
add_test_python(KSpline.py Filtering)
add_test_python(TestParametricFunctions.py Graphics)
add_test_python(closedSplines.py Filtering)
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Now create the RenderWindow, Renderer and Interactor
#
ren1 = vtk.vtkRenderer()
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
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().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
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
profileData.Modified()
fit()
lines = vtk.vtkCellArray()
lines.InsertNextCell(numberOfOutputPoints)
i = 0
while i < numberOfOutputPoints:
lines.InsertCellPoint(i)
i = 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().SetSpecular(.3)
profile.GetProperty().SetSpecularPower(30)
ren1.AddActor(profile)
ren1.ResetCamera()
ren1.GetActiveCamera().Dolly(1.5)
ren1.ResetCameraClippingRange()
renWin.SetSize(400,400)
# render the image
#
iren.Initialize()
def opened (__vtk__temp0=0,__vtk__temp1=0):
global offset
offset = 1.0
aSplineX.ClosedOff()
aSplineY.ClosedOff()
aSplineZ.ClosedOff()
fit()
renWin.Render()
def varyLeft (__vtk__temp0=0,__vtk__temp1=0):
left = -1
while left <= 1:
aSplineX.SetLeftValue(left)
aSplineY.SetLeftValue(left)
aSplineZ.SetLeftValue(left)
fit()
renWin.Render()
left = expr.expr(globals(), locals(),["left","+",".05"])
def varyRight (__vtk__temp0=0,__vtk__temp1=0):
right = -1
while right <= 1:
aSplineX.SetRightValue(right)
aSplineY.SetRightValue(right)
aSplineZ.SetRightValue(right)
fit()
renWin.Render()
right = expr.expr(globals(), locals(),["right","+",".05"])
def constraint (value,__vtk__temp0=0,__vtk__temp1=0):
aSplineX.SetLeftConstraint(value)
aSplineY.SetLeftConstraint(value)
aSplineZ.SetLeftConstraint(value)
aSplineX.SetRightConstraint(value)
aSplineY.SetRightConstraint(value)
aSplineZ.SetRightConstraint(value)
def closed (__vtk__temp0=0,__vtk__temp1=0):
global offset
offset = 0.0
aSplineX.ClosedOn()
aSplineY.ClosedOn()
aSplineZ.ClosedOn()
fit()
renWin.Render()
# prevent the tk window from showing up then start the event loop
# --- end of script --
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Now create the RenderWindow, Renderer and Interactor
#
ren1 = vtk.vtkRenderer()
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
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().SetSpecular(.3)
glyph.GetProperty().SetSpecularPower(30)
ren1.AddActor(glyph)
points = vtk.vtkPoints()
# create a line
tension = 0
bias = 0
continuity = 0
aSplineX.SetDefaultTension(tension)
aSplineX.SetDefaultBias(bias)
aSplineX.SetDefaultContinuity(continuity)
aSplineY.SetDefaultTension(tension)
aSplineY.SetDefaultBias(bias)
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
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
profileData.Modified()
fit()
lines = vtk.vtkCellArray()
lines.InsertNextCell(numberOfOutputPoints)
i = 0
while i < numberOfOutputPoints:
lines.InsertCellPoint(i)
i = 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.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)
# 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):
aSplineX.SetDefaultBias(0)
aSplineX.SetDefaultTension(0)
aSplineX.SetDefaultContinuity(0)
aSplineY.SetDefaultBias(0)
aSplineY.SetDefaultTension(0)
aSplineY.SetDefaultContinuity(0)
aSplineZ.SetDefaultBias(0)
aSplineZ.SetDefaultTension(0)
aSplineZ.SetDefaultContinuity(0)
fit()
renWin.Render()
def varyBias (__vtk__temp0=0,__vtk__temp1=0):
defaults()
bias = -1
while bias <= 1:
aSplineX.SetDefaultBias(bias)
aSplineY.SetDefaultBias(bias)
aSplineZ.SetDefaultBias(bias)
fit()
renWin.Render()
bias = expr.expr(globals(), locals(),["bias","+",".05"])
def varyTension (__vtk__temp0=0,__vtk__temp1=0):
defaults()
tension = -1
while tension <= 1:
aSplineX.SetDefaultTension(tension)
aSplineY.SetDefaultTension(tension)
aSplineZ.SetDefaultTension(tension)
fit()
renWin.Render()
tension = expr.expr(globals(), locals(),["tension","+",".05"])
def varyContinuity (__vtk__temp0=0,__vtk__temp1=0):
defaults()
Continuity = -1
while Continuity <= 1:
aSplineX.SetDefaultContinuity(Continuity)
aSplineY.SetDefaultContinuity(Continuity)
aSplineZ.SetDefaultContinuity(Continuity)
fit()
renWin.Render()
Continuity = expr.expr(globals(), locals(),["Continuity","+",".05"])
def closed (__vtk__temp0=0,__vtk__temp1=0):
global offset
offset = 0.0
aSplineX.ClosedOn()
aSplineY.ClosedOn()
aSplineZ.ClosedOn()
fit()
renWin.Render()
def opened (__vtk__temp0=0,__vtk__temp1=0):
global offset
offset = 1.0
aSplineX.ClosedOff()
aSplineY.ClosedOff()
aSplineZ.ClosedOff()
fit()
renWin.Render()
# --- end of script --
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# get the interactor ui
# Now create the RenderWindow, Renderer and Interactor
#
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
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)
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)
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)
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)
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().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
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
profileKData.Modified()
profileCData.Modified()
fit()
lines = vtk.vtkCellArray()
lines.InsertNextCell(numberOfOutputPoints)
i = 0
while i < numberOfOutputPoints:
lines.InsertCellPoint(i)
i = 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().SetSpecular(.3)
profileK.GetProperty().SetSpecularPower(30)
ren1.AddActor(profileK)
profileCTubes = vtk.vtkTubeFilter()
profileCTubes.SetNumberOfSides(8)
profileCTubes.SetInputData(profileCData)
profileCTubes.SetRadius(.01)
profileCMapper = vtk.vtkPolyDataMapper()
profileCMapper.SetInputConnection(profileCTubes.GetOutputPort())
profileC = vtk.vtkActor()
profileC.SetMapper(profileCMapper)
profileC.GetProperty().SetDiffuseColor(peacock)
profileC.GetProperty().SetSpecular(.3)
profileC.GetProperty().SetSpecularPower(30)
ren1.AddActor(profileC)
ren1.ResetCamera()
ren1.GetActiveCamera().Dolly(1.5)
ren1.ResetCameraClippingRange()
renWin.SetSize(300,300)
# 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):
aSplineX.SetDefaultBias(0)
aSplineX.SetDefaultTension(0)
aSplineX.SetDefaultContinuity(0)
aSplineY.SetDefaultBias(0)
aSplineY.SetDefaultTension(0)
aSplineY.SetDefaultContinuity(0)
aSplineZ.SetDefaultBias(0)
aSplineZ.SetDefaultTension(0)
aSplineZ.SetDefaultContinuity(0)
fit()
renWin.Render()
def varyBias (__vtk__temp0=0,__vtk__temp1=0):
defaults()
bias = -1
while bias <= 1:
aSplineX.SetDefaultBias(bias)
aSplineY.SetDefaultBias(bias)
aSplineZ.SetDefaultBias(bias)
fit()
renWin.Render()
bias = expr.expr(globals(), locals(),["bias","+",".05"])
def varyTension (__vtk__temp0=0,__vtk__temp1=0):
defaults()
tension = -1
while tension <= 1:
aSplineX.SetDefaultTension(tension)
aSplineY.SetDefaultTension(tension)
aSplineZ.SetDefaultTension(tension)
fit()
renWin.Render()
tension = expr.expr(globals(), locals(),["tension","+",".05"])
def varyContinuity (__vtk__temp0=0,__vtk__temp1=0):
defaults()
Continuity = -1
while Continuity <= 1:
aSplineX.SetDefaultContinuity(Continuity)
aSplineY.SetDefaultContinuity(Continuity)
aSplineZ.SetDefaultContinuity(Continuity)
fit()
renWin.Render()
Continuity = expr.expr(globals(), locals(),["Continuity","+",".05"])
def closed (__vtk__temp0=0,__vtk__temp1=0):
global offset
offset = 0.0
aSplineX.ClosedOn()
aSplineY.ClosedOn()
aSplineZ.ClosedOn()
fit()
renWin.Render()
def opened (__vtk__temp0=0,__vtk__temp1=0):
global offset
offset = 1.0
aSplineX.ClosedOff()
aSplineY.ClosedOff()
aSplineZ.ClosedOff()
fit()
renWin.Render()
# --- end of script --
......@@ -5,4 +5,6 @@ vtk_module(vtkCommonComputationalGeometry
vtkCommonSystem
vtkCommonMath
vtkCommonDataModel
TEST_DEPENDS
vtkTestingCore
)
add_test_python(TestImagePlaneWidget.py Widgets)