From 3810c5a6441ccf523586469a454f47560638561f Mon Sep 17 00:00:00 2001 From: Andrew Maclean <andrew.amaclean@gmail.com> Date: Sun, 28 Apr 2013 14:46:20 +1000 Subject: [PATCH] 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 <andrew.amaclean@gmail.com> --- .../Testing/Python/CSpline.py | 72 +- .../Testing/Python/KSpline.py | 80 +- .../Testing/Python/closedSplines.py | 259 ++-- .../Python/LineIntersectQuadraticCells.py | 566 ++++---- .../DataModel/Testing/Python/SelectionLoop.py | 38 +- .../Testing/Python/TestConvexPointSet.py | 82 +- .../Testing/Python/TestQuadricClustering.py | 38 +- Common/DataModel/Testing/Python/backdrop.py | 74 + Common/DataModel/Testing/Python/headBone.py | 59 +- Common/Transforms/Testing/Python/spherical.py | 35 +- .../Testing/Python/Delaunay2DTransform.py | 31 +- Filters/Core/Testing/Python/StreamPolyData.py | 52 +- .../Python/TestGridSynchronizedTemplates3D.py | 171 ++- .../Core/Testing/Python/TestTensorGlyph.py | 16 +- Filters/Core/Testing/Python/backdrop.py | 74 + Filters/Core/Testing/Python/capCow.py | 62 +- Filters/Core/Testing/Python/capSphere.py | 45 +- Filters/Core/Testing/Python/clipArt.py | 99 +- .../Testing/Python/constrainedDelaunay.py | 109 +- Filters/Core/Testing/Python/contourCells.py | 972 ++++++++----- .../Testing/Python/contourQuadraticCells.py | 1220 +++++++++-------- Filters/Core/Testing/Python/cutLoop.py | 103 +- Filters/Core/Testing/Python/dispPlot.py | 40 +- .../Core/Testing/Python/fieldToPolyData.py | 60 +- Filters/Core/Testing/Python/fieldToRGrid.py | 115 +- Filters/Core/Testing/Python/fieldToSGrid.py | 97 +- Filters/Core/Testing/Python/fieldToUGrid.py | 83 +- Filters/Core/Testing/Python/hull.py | 42 +- Filters/Core/Testing/Python/multipleIso.py | 77 +- Filters/Core/Testing/Python/reverseNormals.py | 45 +- Filters/Core/Testing/Python/teapotHulls.py | 68 +- .../Testing/Python/extractRectGrid.py | 47 +- Filters/General/Testing/Python/OBBCylinder.py | 28 +- .../General/Testing/Python/TestCellDerivs.py | 692 ++++++---- .../Python/TestDiscreteMarchingCubes.py | 69 +- .../Testing/Python/TestGraphLayoutFilter.py | 74 +- .../Testing/Python/TestMultiBlockStreamer.py | 84 +- .../Python/TestRandomAttributeGenerator.py | 30 +- .../Python/TestRectilinearGridToTetrahedra.py | 113 +- .../General/Testing/Python/WarpScalarImage.py | 29 +- .../General/Testing/Python/WarpVectorImage.py | 36 +- Filters/General/Testing/Python/backdrop.py | 74 + Filters/General/Testing/Python/blankGrid.py | 102 +- Filters/General/Testing/Python/clipComb.py | 50 +- Filters/General/Testing/Python/clipHex.py | 117 +- Filters/General/Testing/Python/clipPyramid.py | 113 +- .../Testing/Python/clipQuadraticCells.py | 1189 ++++++++-------- Filters/General/Testing/Python/clipTet.py | 128 +- Filters/General/Testing/Python/clipWedge.py | 113 +- .../Testing/Python/contoursToSurface.py | 124 +- Filters/General/Testing/Python/cursor2D.py | 44 +- Filters/General/Testing/Python/edgePoints.py | 43 +- Filters/General/Testing/Python/mcubes.py | 46 +- Filters/General/Testing/Python/recursiveDC.py | 42 +- Filters/General/Testing/Python/warplens.py | 30 +- .../Testing/Python/officeStreamPoints.py | 126 +- Filters/Geometry/Testing/Python/rectGrid.py | 60 +- Filters/Hybrid/Testing/Python/3DMorph.py | 69 +- .../Python/TestGreedyTerrainDecimation.py | 49 +- .../Hybrid/Testing/Python/TestProcrustes.py | 88 +- .../Python/TestProcrustesRigidCentroid.py | 98 +- .../Python/TestProjectedTerrainPath.py | 65 +- Filters/Hybrid/Testing/Python/banana.py | 57 +- .../Hybrid/Testing/Python/largeImageOffset.py | 32 +- .../Testing/Python/largeImageParallel.py | 28 +- Filters/Modeling/Testing/Python/Hyper.py | 97 +- .../Testing/Python/TestFillHolesFilter.py | 55 +- .../Testing/Python/TestImageMarchingCubes.py | 45 +- .../Testing/Python/TestSpherePuzzleArrows.py | 68 +- Filters/Modeling/Testing/Python/eleState.py | 79 +- Filters/Modeling/Testing/Python/smoothCyl.py | 50 +- Filters/Modeling/Testing/Python/smoothCyl2.py | 49 +- .../Testing/Python/TestButtonSource.py | 45 +- Filters/Sources/Testing/Python/glyph2D.py | 47 +- .../Testing/Python/triangularTCoords.py | 31 +- .../Testing/Python/EnSightRectGridASCII.py | 83 +- .../Testing/Python/EnSightRectGridBin.py | 82 +- IO/Geometry/Testing/Python/Plot3DScalars.py | 131 +- IO/Geometry/Testing/Python/Plot3DVectors.py | 138 +- IO/Geometry/Testing/Python/TestChacoReader.py | 24 +- .../Testing/Python/TestSimplePointsReader.py | 18 +- IO/Geometry/Testing/Python/motor.py | 97 +- IO/Image/Testing/Python/TestImageWriters.py | 148 +- IO/Image/Testing/Python/TestMetaImage2D.py | 12 +- IO/Image/Testing/Python/TestSetFileNames.py | 15 +- IO/Image/Testing/Python/dem.py | 123 +- IO/MINC/Testing/Python/TestMINCImageReader.py | 7 +- IO/MINC/Testing/Python/TestMINCImageWriter.py | 74 +- IO/MINC/Testing/Python/TestMNIObjects.py | 237 ++-- IO/MINC/Testing/Python/TestMNITagPoints.py | 221 +-- IO/MINC/Testing/Python/TestMNITransforms.py | 264 ++-- IO/PLY/Testing/Python/TestPLYReadWrite.py | 210 +-- .../Core/Testing/Python/TestBlendStencil.py | 39 +- Imaging/Core/Testing/Python/TestExtractVOI.py | 39 +- .../Core/Testing/Python/TestHybridMedian2D.py | 51 +- .../Testing/Python/TestImageWeightedSum.py | 26 +- .../Core/Testing/Python/TestInPlaceFilter.py | 31 +- .../Python/TestMapToWindowLevelColors.py | 15 +- .../Testing/Python/TestSeparableFilter.py | 25 +- Imaging/Core/Testing/Python/voxelModel.py | 49 +- Imaging/Hybrid/Testing/Python/genHead.py | 72 +- Imaging/Hybrid/Testing/Python/iceCream.py | 65 +- Interaction/Style/Testing/Python/TestFlyTo.py | 35 +- .../Core/Testing/Python/TestPolyDataPieces.py | 24 +- .../Testing/Python/TestUnstructuredPieces.py | 33 +- .../Annotation/Testing/Python/cubeAxes.py | 64 +- .../Annotation/Testing/Python/cubeAxes2.py | 109 +- .../Annotation/Testing/Python/cubeAxes3.py | 58 +- .../Python/PolyDataMapperAllPolygons.py | 188 +-- .../Python/PolyDataMapperAllWireframe.py | 192 +-- .../Testing/Python/TestCameraInterpolator.py | 108 +- .../Python/TestGenericVertexAttributesGLSL.py | 26 +- .../Core/Testing/Python/TestLeaderActor2D.py | 32 +- Rendering/Core/Testing/Python/TestOpacity2.py | 54 +- .../Python/TestTransformCoordinateSystems.py | 24 +- .../Python/TestWindowToImageTransparency.py | 37 +- .../Core/Testing/Python/TexturedSphere.py | 30 +- Rendering/Core/Testing/Python/cowHair.py | 45 +- Rendering/Core/Testing/Python/cowHair2.py | 49 +- .../Core/Testing/Python/rendererSource.py | 73 +- .../LOD/Testing/Python/TestQuadricLODActor.py | 31 +- .../Label/Testing/Python/labeledContours.py | 38 +- Rendering/Label/Testing/Python/labeledMesh.py | 94 +- .../Testing/Python/VolumeOutlineSource.py | 130 +- .../Python/VolumeOutlineSourceClipped.py | 92 +- .../Volume/Testing/Python/VolumePickerCrop.py | 188 ++- Rendering/Volume/Testing/Python/gaussian.py | 94 +- .../Volume/Testing/Python/volRCCropRegions.py | 97 +- .../Testing/Python/volTM2DCropRegions.py | 91 +- .../Python/volTM3DCompressedCropRegions.py | 101 +- .../Testing/Python/volTM3DCropRegions.py | 99 +- .../Testing/Python/volTM3DRotateClip.py | 83 +- 132 files changed, 8718 insertions(+), 5436 deletions(-) create mode 100644 Common/DataModel/Testing/Python/backdrop.py create mode 100644 Filters/Core/Testing/Python/backdrop.py create mode 100644 Filters/General/Testing/Python/backdrop.py diff --git a/Common/ComputationalGeometry/Testing/Python/CSpline.py b/Common/ComputationalGeometry/Testing/Python/CSpline.py index e7feea105e9..ae01a3a264a 100755 --- a/Common/ComputationalGeometry/Testing/Python/CSpline.py +++ b/Common/ComputationalGeometry/Testing/Python/CSpline.py @@ -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() diff --git a/Common/ComputationalGeometry/Testing/Python/KSpline.py b/Common/ComputationalGeometry/Testing/Python/KSpline.py index 5c4cc1bfdb2..ecdd666afb9 100755 --- a/Common/ComputationalGeometry/Testing/Python/KSpline.py +++ b/Common/ComputationalGeometry/Testing/Python/KSpline.py @@ -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() diff --git a/Common/ComputationalGeometry/Testing/Python/closedSplines.py b/Common/ComputationalGeometry/Testing/Python/closedSplines.py index a942e621663..0fb1b5964c0 100755 --- a/Common/ComputationalGeometry/Testing/Python/closedSplines.py +++ b/Common/ComputationalGeometry/Testing/Python/closedSplines.py @@ -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) + profileCMapper = vtk.vtkPolyDataMapper() profileCMapper.SetInputConnection(profileCTubes.GetOutputPort()) + profileC = vtk.vtkActor() profileC.SetMapper(profileCMapper) -profileC.GetProperty().SetDiffuseColor(peacock) +profileC.GetProperty().SetDiffuseColor(GetRGBColor('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) + +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 -- + +def defaults (aSplineX, aSplineY, aSplineZ): + 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 (aSplineX, aSplineY, aSplineZ): + defaults(aSplineX, aSplineY, aSplineZ) + bias = -1 + while bias <= 1: + aSplineX.SetDefaultBias(bias) + aSplineY.SetDefaultBias(bias) + aSplineZ.SetDefaultBias(bias) + fit() + renWin.Render() + bias += 0.05 + + +def varyTension (aSplineX, aSplineY, aSplineZ): + defaults(aSplineX, aSplineY, aSplineZ) + tension = -1 + while tension <= 1: + aSplineX.SetDefaultTension(tension) + aSplineY.SetDefaultTension(tension) + aSplineZ.SetDefaultTension(tension) + fit() + renWin.Render() + tension += 0.05 + + +def varyContinuity (aSplineX, aSplineY, aSplineZ): + defaults(aSplineX, aSplineY, aSplineZ) + Continuity = -1 + while Continuity <= 1: + aSplineX.SetDefaultContinuity(Continuity) + aSplineY.SetDefaultContinuity(Continuity) + aSplineZ.SetDefaultContinuity(Continuity) + fit() + renWin.Render() + Continuity += 0.05 + + +def closed (aSplineX, aSplineY, aSplineZ): + global offset + offset = 0.0 + aSplineX.ClosedOn() + aSplineY.ClosedOn() + aSplineZ.ClosedOn() + fit() + renWin.Render() + +def opened (aSplineX, aSplineY, aSplineZ): + global offset + offset = 1.0 + aSplineX.ClosedOff() + aSplineY.ClosedOff() + aSplineZ.ClosedOff() + fit() + renWin.Render() + +# varyBias (aKSplineX, aKSplineY, aKSplineZ) +# varyTension (aKSplineX, aKSplineY, aKSplineZ) +# varyContinuity(aKSplineX, aKSplineY, aKSplineZ) + +#iren.Start() diff --git a/Common/DataModel/Testing/Python/LineIntersectQuadraticCells.py b/Common/DataModel/Testing/Python/LineIntersectQuadraticCells.py index f23cf3011c7..20d9fcb74f5 100755 --- a/Common/DataModel/Testing/Python/LineIntersectQuadraticCells.py +++ b/Common/DataModel/Testing/Python/LineIntersectQuadraticCells.py @@ -1,29 +1,37 @@ #!/usr/bin/env python +import sys import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() +# Prevent .pyc files being created. +# Stops the vtk source being polluted +# by .pyc files. +sys.dont_write_bytecode = True + +import backdrop + # Contour every quadratic cell type # Create a scene with one of each cell type. # QuadraticEdge edgePoints = vtk.vtkPoints() edgePoints.SetNumberOfPoints(3) -edgePoints.InsertPoint(0,0,0,0) -edgePoints.InsertPoint(1,1.0,0,0) -edgePoints.InsertPoint(2,0.5,0.25,0) +edgePoints.InsertPoint(0, 0, 0, 0) +edgePoints.InsertPoint(1, 1.0, 0, 0) +edgePoints.InsertPoint(2, 0.5, 0.25, 0) edgeScalars = vtk.vtkFloatArray() edgeScalars.SetNumberOfTuples(3) -edgeScalars.InsertValue(0,0.0) -edgeScalars.InsertValue(1,0.0) -edgeScalars.InsertValue(2,0.9) +edgeScalars.InsertValue(0, 0.0) +edgeScalars.InsertValue(1, 0.0) +edgeScalars.InsertValue(2, 0.9) aEdge = vtk.vtkQuadraticEdge() -aEdge.GetPointIds().SetId(0,0) -aEdge.GetPointIds().SetId(1,1) -aEdge.GetPointIds().SetId(2,2) +aEdge.GetPointIds().SetId(0, 0) +aEdge.GetPointIds().SetId(1, 1) +aEdge.GetPointIds().SetId(2, 2) aEdgeGrid = vtk.vtkUnstructuredGrid() -aEdgeGrid.Allocate(1,1) -aEdgeGrid.InsertNextCell(aEdge.GetCellType(),aEdge.GetPointIds()) +aEdgeGrid.Allocate(1, 1) +aEdgeGrid.InsertNextCell(aEdge.GetCellType(), aEdge.GetPointIds()) aEdgeGrid.SetPoints(edgePoints) aEdgeGrid.GetPointData().SetScalars(edgeScalars) aEdgeMapper = vtk.vtkDataSetMapper() @@ -33,33 +41,34 @@ aEdgeActor = vtk.vtkActor() aEdgeActor.SetMapper(aEdgeMapper) aEdgeActor.GetProperty().SetRepresentationToWireframe() aEdgeActor.GetProperty().SetAmbient(1.0) + # Quadratic triangle triPoints = vtk.vtkPoints() triPoints.SetNumberOfPoints(6) -triPoints.InsertPoint(0,0.0,0.0,0.0) -triPoints.InsertPoint(1,1.0,0.0,0.0) -triPoints.InsertPoint(2,0.5,0.8,0.0) -triPoints.InsertPoint(3,0.5,0.0,0.0) -triPoints.InsertPoint(4,0.75,0.4,0.0) -triPoints.InsertPoint(5,0.25,0.4,0.0) +triPoints.InsertPoint(0, 0.0, 0.0, 0.0) +triPoints.InsertPoint(1, 1.0, 0.0, 0.0) +triPoints.InsertPoint(2, 0.5, 0.8, 0.0) +triPoints.InsertPoint(3, 0.5, 0.0, 0.0) +triPoints.InsertPoint(4, 0.75, 0.4, 0.0) +triPoints.InsertPoint(5, 0.25, 0.4, 0.0) triScalars = vtk.vtkFloatArray() triScalars.SetNumberOfTuples(6) -triScalars.InsertValue(0,0.0) -triScalars.InsertValue(1,0.0) -triScalars.InsertValue(2,0.0) -triScalars.InsertValue(3,1.0) -triScalars.InsertValue(4,0.0) -triScalars.InsertValue(5,0.0) +triScalars.InsertValue(0, 0.0) +triScalars.InsertValue(1, 0.0) +triScalars.InsertValue(2, 0.0) +triScalars.InsertValue(3, 1.0) +triScalars.InsertValue(4, 0.0) +triScalars.InsertValue(5, 0.0) aTri = vtk.vtkQuadraticTriangle() -aTri.GetPointIds().SetId(0,0) -aTri.GetPointIds().SetId(1,1) -aTri.GetPointIds().SetId(2,2) -aTri.GetPointIds().SetId(3,3) -aTri.GetPointIds().SetId(4,4) -aTri.GetPointIds().SetId(5,5) +aTri.GetPointIds().SetId(0, 0) +aTri.GetPointIds().SetId(1, 1) +aTri.GetPointIds().SetId(2, 2) +aTri.GetPointIds().SetId(3, 3) +aTri.GetPointIds().SetId(4, 4) +aTri.GetPointIds().SetId(5, 5) aTriGrid = vtk.vtkUnstructuredGrid() -aTriGrid.Allocate(1,1) -aTriGrid.InsertNextCell(aTri.GetCellType(),aTri.GetPointIds()) +aTriGrid.Allocate(1, 1) +aTriGrid.InsertNextCell(aTri.GetCellType(), aTri.GetPointIds()) aTriGrid.SetPoints(triPoints) aTriGrid.GetPointData().SetScalars(triScalars) aTriMapper = vtk.vtkDataSetMapper() @@ -69,39 +78,40 @@ aTriActor = vtk.vtkActor() aTriActor.SetMapper(aTriMapper) aTriActor.GetProperty().SetRepresentationToWireframe() aTriActor.GetProperty().SetAmbient(1.0) + # Quadratic quadrilateral quadPoints = vtk.vtkPoints() quadPoints.SetNumberOfPoints(8) -quadPoints.InsertPoint(0,0.0,0.0,0.0) -quadPoints.InsertPoint(1,1.0,0.0,0.0) -quadPoints.InsertPoint(2,1.0,1.0,0.0) -quadPoints.InsertPoint(3,0.0,1.0,0.0) -quadPoints.InsertPoint(4,0.5,0.0,0.0) -quadPoints.InsertPoint(5,1.0,0.5,0.0) -quadPoints.InsertPoint(6,0.5,1.0,0.0) -quadPoints.InsertPoint(7,0.0,0.5,0.0) +quadPoints.InsertPoint(0, 0.0, 0.0, 0.0) +quadPoints.InsertPoint(1, 1.0, 0.0, 0.0) +quadPoints.InsertPoint(2, 1.0, 1.0, 0.0) +quadPoints.InsertPoint(3, 0.0, 1.0, 0.0) +quadPoints.InsertPoint(4, 0.5, 0.0, 0.0) +quadPoints.InsertPoint(5, 1.0, 0.5, 0.0) +quadPoints.InsertPoint(6, 0.5, 1.0, 0.0) +quadPoints.InsertPoint(7, 0.0, 0.5, 0.0) quadScalars = vtk.vtkFloatArray() quadScalars.SetNumberOfTuples(8) -quadScalars.InsertValue(0,0.0) -quadScalars.InsertValue(1,0.0) -quadScalars.InsertValue(2,1.0) -quadScalars.InsertValue(3,1.0) -quadScalars.InsertValue(4,1.0) -quadScalars.InsertValue(5,0.0) -quadScalars.InsertValue(6,0.0) -quadScalars.InsertValue(7,0.0) +quadScalars.InsertValue(0, 0.0) +quadScalars.InsertValue(1, 0.0) +quadScalars.InsertValue(2, 1.0) +quadScalars.InsertValue(3, 1.0) +quadScalars.InsertValue(4, 1.0) +quadScalars.InsertValue(5, 0.0) +quadScalars.InsertValue(6, 0.0) +quadScalars.InsertValue(7, 0.0) aQuad = vtk.vtkQuadraticQuad() -aQuad.GetPointIds().SetId(0,0) -aQuad.GetPointIds().SetId(1,1) -aQuad.GetPointIds().SetId(2,2) -aQuad.GetPointIds().SetId(3,3) -aQuad.GetPointIds().SetId(4,4) -aQuad.GetPointIds().SetId(5,5) -aQuad.GetPointIds().SetId(6,6) -aQuad.GetPointIds().SetId(7,7) +aQuad.GetPointIds().SetId(0, 0) +aQuad.GetPointIds().SetId(1, 1) +aQuad.GetPointIds().SetId(2, 2) +aQuad.GetPointIds().SetId(3, 3) +aQuad.GetPointIds().SetId(4, 4) +aQuad.GetPointIds().SetId(5, 5) +aQuad.GetPointIds().SetId(6, 6) +aQuad.GetPointIds().SetId(7, 7) aQuadGrid = vtk.vtkUnstructuredGrid() -aQuadGrid.Allocate(1,1) -aQuadGrid.InsertNextCell(aQuad.GetCellType(),aQuad.GetPointIds()) +aQuadGrid.Allocate(1, 1) +aQuadGrid.InsertNextCell(aQuad.GetCellType(), aQuad.GetPointIds()) aQuadGrid.SetPoints(quadPoints) aQuadGrid.GetPointData().SetScalars(quadScalars) aQuadMapper = vtk.vtkDataSetMapper() @@ -111,45 +121,46 @@ aQuadActor = vtk.vtkActor() aQuadActor.SetMapper(aQuadMapper) aQuadActor.GetProperty().SetRepresentationToWireframe() aQuadActor.GetProperty().SetAmbient(1.0) + # Quadratic tetrahedron tetPoints = vtk.vtkPoints() tetPoints.SetNumberOfPoints(10) -tetPoints.InsertPoint(0,0.0,0.0,0.0) -tetPoints.InsertPoint(1,1.0,0.0,0.0) -tetPoints.InsertPoint(2,0.5,0.8,0.0) -tetPoints.InsertPoint(3,0.5,0.4,1.0) -tetPoints.InsertPoint(4,0.5,0.0,0.0) -tetPoints.InsertPoint(5,0.75,0.4,0.0) -tetPoints.InsertPoint(6,0.25,0.4,0.0) -tetPoints.InsertPoint(7,0.25,0.2,0.5) -tetPoints.InsertPoint(8,0.75,0.2,0.5) -tetPoints.InsertPoint(9,0.50,0.6,0.5) +tetPoints.InsertPoint(0, 0.0, 0.0, 0.0) +tetPoints.InsertPoint(1, 1.0, 0.0, 0.0) +tetPoints.InsertPoint(2, 0.5, 0.8, 0.0) +tetPoints.InsertPoint(3, 0.5, 0.4, 1.0) +tetPoints.InsertPoint(4, 0.5, 0.0, 0.0) +tetPoints.InsertPoint(5, 0.75, 0.4, 0.0) +tetPoints.InsertPoint(6, 0.25, 0.4, 0.0) +tetPoints.InsertPoint(7, 0.25, 0.2, 0.5) +tetPoints.InsertPoint(8, 0.75, 0.2, 0.5) +tetPoints.InsertPoint(9, 0.50, 0.6, 0.5) tetScalars = vtk.vtkFloatArray() tetScalars.SetNumberOfTuples(10) -tetScalars.InsertValue(0,1.0) -tetScalars.InsertValue(1,1.0) -tetScalars.InsertValue(2,1.0) -tetScalars.InsertValue(3,1.0) -tetScalars.InsertValue(4,0.0) -tetScalars.InsertValue(5,0.0) -tetScalars.InsertValue(6,0.0) -tetScalars.InsertValue(7,0.0) -tetScalars.InsertValue(8,0.0) -tetScalars.InsertValue(9,0.0) +tetScalars.InsertValue(0, 1.0) +tetScalars.InsertValue(1, 1.0) +tetScalars.InsertValue(2, 1.0) +tetScalars.InsertValue(3, 1.0) +tetScalars.InsertValue(4, 0.0) +tetScalars.InsertValue(5, 0.0) +tetScalars.InsertValue(6, 0.0) +tetScalars.InsertValue(7, 0.0) +tetScalars.InsertValue(8, 0.0) +tetScalars.InsertValue(9, 0.0) aTet = vtk.vtkQuadraticTetra() -aTet.GetPointIds().SetId(0,0) -aTet.GetPointIds().SetId(1,1) -aTet.GetPointIds().SetId(2,2) -aTet.GetPointIds().SetId(3,3) -aTet.GetPointIds().SetId(4,4) -aTet.GetPointIds().SetId(5,5) -aTet.GetPointIds().SetId(6,6) -aTet.GetPointIds().SetId(7,7) -aTet.GetPointIds().SetId(8,8) -aTet.GetPointIds().SetId(9,9) +aTet.GetPointIds().SetId(0, 0) +aTet.GetPointIds().SetId(1, 1) +aTet.GetPointIds().SetId(2, 2) +aTet.GetPointIds().SetId(3, 3) +aTet.GetPointIds().SetId(4, 4) +aTet.GetPointIds().SetId(5, 5) +aTet.GetPointIds().SetId(6, 6) +aTet.GetPointIds().SetId(7, 7) +aTet.GetPointIds().SetId(8, 8) +aTet.GetPointIds().SetId(9, 9) aTetGrid = vtk.vtkUnstructuredGrid() -aTetGrid.Allocate(1,1) -aTetGrid.InsertNextCell(aTet.GetCellType(),aTet.GetPointIds()) +aTetGrid.Allocate(1, 1) +aTetGrid.InsertNextCell(aTet.GetCellType(), aTet.GetPointIds()) aTetGrid.SetPoints(tetPoints) aTetGrid.GetPointData().SetScalars(tetScalars) aTetMapper = vtk.vtkDataSetMapper() @@ -159,75 +170,76 @@ aTetActor = vtk.vtkActor() aTetActor.SetMapper(aTetMapper) aTetActor.GetProperty().SetRepresentationToWireframe() aTetActor.GetProperty().SetAmbient(1.0) + # Quadratic hexahedron hexPoints = vtk.vtkPoints() hexPoints.SetNumberOfPoints(20) -hexPoints.InsertPoint(0,0,0,0) -hexPoints.InsertPoint(1,1,0,0) -hexPoints.InsertPoint(2,1,1,0) -hexPoints.InsertPoint(3,0,1,0) -hexPoints.InsertPoint(4,0,0,1) -hexPoints.InsertPoint(5,1,0,1) -hexPoints.InsertPoint(6,1,1,1) -hexPoints.InsertPoint(7,0,1,1) -hexPoints.InsertPoint(8,0.5,0,0) -hexPoints.InsertPoint(9,1,0.5,0) -hexPoints.InsertPoint(10,0.5,1,0) -hexPoints.InsertPoint(11,0,0.5,0) -hexPoints.InsertPoint(12,0.5,0,1) -hexPoints.InsertPoint(13,1,0.5,1) -hexPoints.InsertPoint(14,0.5,1,1) -hexPoints.InsertPoint(15,0,0.5,1) -hexPoints.InsertPoint(16,0,0,0.5) -hexPoints.InsertPoint(17,1,0,0.5) -hexPoints.InsertPoint(18,1,1,0.5) -hexPoints.InsertPoint(19,0,1,0.5) +hexPoints.InsertPoint(0, 0, 0, 0) +hexPoints.InsertPoint(1, 1, 0, 0) +hexPoints.InsertPoint(2, 1, 1, 0) +hexPoints.InsertPoint(3, 0, 1, 0) +hexPoints.InsertPoint(4, 0, 0, 1) +hexPoints.InsertPoint(5, 1, 0, 1) +hexPoints.InsertPoint(6, 1, 1, 1) +hexPoints.InsertPoint(7, 0, 1, 1) +hexPoints.InsertPoint(8, 0.5, 0, 0) +hexPoints.InsertPoint(9, 1, 0.5, 0) +hexPoints.InsertPoint(10, 0.5, 1, 0) +hexPoints.InsertPoint(11, 0, 0.5, 0) +hexPoints.InsertPoint(12, 0.5, 0, 1) +hexPoints.InsertPoint(13, 1, 0.5, 1) +hexPoints.InsertPoint(14, 0.5, 1, 1) +hexPoints.InsertPoint(15, 0, 0.5, 1) +hexPoints.InsertPoint(16, 0, 0, 0.5) +hexPoints.InsertPoint(17, 1, 0, 0.5) +hexPoints.InsertPoint(18, 1, 1, 0.5) +hexPoints.InsertPoint(19, 0, 1, 0.5) hexScalars = vtk.vtkFloatArray() hexScalars.SetNumberOfTuples(20) -hexScalars.InsertValue(0,1.0) -hexScalars.InsertValue(1,1.0) -hexScalars.InsertValue(2,1.0) -hexScalars.InsertValue(3,1.0) -hexScalars.InsertValue(4,1.0) -hexScalars.InsertValue(5,1.0) -hexScalars.InsertValue(6,1.0) -hexScalars.InsertValue(7,1.0) -hexScalars.InsertValue(8,0.0) -hexScalars.InsertValue(9,0.0) -hexScalars.InsertValue(10,0.0) -hexScalars.InsertValue(11,0.0) -hexScalars.InsertValue(12,0.0) -hexScalars.InsertValue(13,0.0) -hexScalars.InsertValue(14,0.0) -hexScalars.InsertValue(15,0.0) -hexScalars.InsertValue(16,0.0) -hexScalars.InsertValue(17,0.0) -hexScalars.InsertValue(18,0.0) -hexScalars.InsertValue(19,0.0) +hexScalars.InsertValue(0, 1.0) +hexScalars.InsertValue(1, 1.0) +hexScalars.InsertValue(2, 1.0) +hexScalars.InsertValue(3, 1.0) +hexScalars.InsertValue(4, 1.0) +hexScalars.InsertValue(5, 1.0) +hexScalars.InsertValue(6, 1.0) +hexScalars.InsertValue(7, 1.0) +hexScalars.InsertValue(8, 0.0) +hexScalars.InsertValue(9, 0.0) +hexScalars.InsertValue(10, 0.0) +hexScalars.InsertValue(11, 0.0) +hexScalars.InsertValue(12, 0.0) +hexScalars.InsertValue(13, 0.0) +hexScalars.InsertValue(14, 0.0) +hexScalars.InsertValue(15, 0.0) +hexScalars.InsertValue(16, 0.0) +hexScalars.InsertValue(17, 0.0) +hexScalars.InsertValue(18, 0.0) +hexScalars.InsertValue(19, 0.0) aHex = vtk.vtkQuadraticHexahedron() -aHex.GetPointIds().SetId(0,0) -aHex.GetPointIds().SetId(1,1) -aHex.GetPointIds().SetId(2,2) -aHex.GetPointIds().SetId(3,3) -aHex.GetPointIds().SetId(4,4) -aHex.GetPointIds().SetId(5,5) -aHex.GetPointIds().SetId(6,6) -aHex.GetPointIds().SetId(7,7) -aHex.GetPointIds().SetId(8,8) -aHex.GetPointIds().SetId(9,9) -aHex.GetPointIds().SetId(10,10) -aHex.GetPointIds().SetId(11,11) -aHex.GetPointIds().SetId(12,12) -aHex.GetPointIds().SetId(13,13) -aHex.GetPointIds().SetId(14,14) -aHex.GetPointIds().SetId(15,15) -aHex.GetPointIds().SetId(16,16) -aHex.GetPointIds().SetId(17,17) -aHex.GetPointIds().SetId(18,18) -aHex.GetPointIds().SetId(19,19) +aHex.GetPointIds().SetId(0, 0) +aHex.GetPointIds().SetId(1, 1) +aHex.GetPointIds().SetId(2, 2) +aHex.GetPointIds().SetId(3, 3) +aHex.GetPointIds().SetId(4, 4) +aHex.GetPointIds().SetId(5, 5) +aHex.GetPointIds().SetId(6, 6) +aHex.GetPointIds().SetId(7, 7) +aHex.GetPointIds().SetId(8, 8) +aHex.GetPointIds().SetId(9, 9) +aHex.GetPointIds().SetId(10, 10) +aHex.GetPointIds().SetId(11, 11) +aHex.GetPointIds().SetId(12, 12) +aHex.GetPointIds().SetId(13, 13) +aHex.GetPointIds().SetId(14, 14) +aHex.GetPointIds().SetId(15, 15) +aHex.GetPointIds().SetId(16, 16) +aHex.GetPointIds().SetId(17, 17) +aHex.GetPointIds().SetId(18, 18) +aHex.GetPointIds().SetId(19, 19) aHexGrid = vtk.vtkUnstructuredGrid() -aHexGrid.Allocate(1,1) -aHexGrid.InsertNextCell(aHex.GetCellType(),aHex.GetPointIds()) +aHexGrid.Allocate(1, 1) +aHexGrid.InsertNextCell(aHex.GetCellType(), aHex.GetPointIds()) aHexGrid.SetPoints(hexPoints) aHexGrid.GetPointData().SetScalars(hexScalars) aHexMapper = vtk.vtkDataSetMapper() @@ -237,60 +249,61 @@ aHexActor = vtk.vtkActor() aHexActor.SetMapper(aHexMapper) aHexActor.GetProperty().SetRepresentationToWireframe() aHexActor.GetProperty().SetAmbient(1.0) + # Quadratic wedge wedgePoints = vtk.vtkPoints() wedgePoints.SetNumberOfPoints(15) -wedgePoints.InsertPoint(0,0,0,0) -wedgePoints.InsertPoint(1,1,0,0) -wedgePoints.InsertPoint(2,0,1,0) -wedgePoints.InsertPoint(3,0,0,1) -wedgePoints.InsertPoint(4,1,0,1) -wedgePoints.InsertPoint(5,0,1,1) -wedgePoints.InsertPoint(6,0.5,0,0) -wedgePoints.InsertPoint(7,0.5,0.5,0) -wedgePoints.InsertPoint(8,0,0.5,0) -wedgePoints.InsertPoint(9,0.5,0,1) -wedgePoints.InsertPoint(10,0.5,0.5,1) -wedgePoints.InsertPoint(11,0,0.5,1) -wedgePoints.InsertPoint(12,0,0,0.5) -wedgePoints.InsertPoint(13,1,0,0.5) -wedgePoints.InsertPoint(14,0,1,0.5) +wedgePoints.InsertPoint(0, 0, 0, 0) +wedgePoints.InsertPoint(1, 1, 0, 0) +wedgePoints.InsertPoint(2, 0, 1, 0) +wedgePoints.InsertPoint(3, 0, 0, 1) +wedgePoints.InsertPoint(4, 1, 0, 1) +wedgePoints.InsertPoint(5, 0, 1, 1) +wedgePoints.InsertPoint(6, 0.5, 0, 0) +wedgePoints.InsertPoint(7, 0.5, 0.5, 0) +wedgePoints.InsertPoint(8, 0, 0.5, 0) +wedgePoints.InsertPoint(9, 0.5, 0, 1) +wedgePoints.InsertPoint(10, 0.5, 0.5, 1) +wedgePoints.InsertPoint(11, 0, 0.5, 1) +wedgePoints.InsertPoint(12, 0, 0, 0.5) +wedgePoints.InsertPoint(13, 1, 0, 0.5) +wedgePoints.InsertPoint(14, 0, 1, 0.5) wedgeScalars = vtk.vtkFloatArray() wedgeScalars.SetNumberOfTuples(15) -wedgeScalars.InsertValue(0,1.0) -wedgeScalars.InsertValue(1,1.0) -wedgeScalars.InsertValue(2,1.0) -wedgeScalars.InsertValue(3,1.0) -wedgeScalars.InsertValue(4,1.0) -wedgeScalars.InsertValue(5,1.0) -wedgeScalars.InsertValue(6,1.0) -wedgeScalars.InsertValue(7,1.0) -wedgeScalars.InsertValue(8,0.0) -wedgeScalars.InsertValue(9,0.0) -wedgeScalars.InsertValue(10,0.0) -wedgeScalars.InsertValue(11,0.0) -wedgeScalars.InsertValue(12,0.0) -wedgeScalars.InsertValue(13,0.0) -wedgeScalars.InsertValue(14,0.0) +wedgeScalars.InsertValue(0, 1.0) +wedgeScalars.InsertValue(1, 1.0) +wedgeScalars.InsertValue(2, 1.0) +wedgeScalars.InsertValue(3, 1.0) +wedgeScalars.InsertValue(4, 1.0) +wedgeScalars.InsertValue(5, 1.0) +wedgeScalars.InsertValue(6, 1.0) +wedgeScalars.InsertValue(7, 1.0) +wedgeScalars.InsertValue(8, 0.0) +wedgeScalars.InsertValue(9, 0.0) +wedgeScalars.InsertValue(10, 0.0) +wedgeScalars.InsertValue(11, 0.0) +wedgeScalars.InsertValue(12, 0.0) +wedgeScalars.InsertValue(13, 0.0) +wedgeScalars.InsertValue(14, 0.0) aWedge = vtk.vtkQuadraticWedge() -aWedge.GetPointIds().SetId(0,0) -aWedge.GetPointIds().SetId(1,1) -aWedge.GetPointIds().SetId(2,2) -aWedge.GetPointIds().SetId(3,3) -aWedge.GetPointIds().SetId(4,4) -aWedge.GetPointIds().SetId(5,5) -aWedge.GetPointIds().SetId(6,6) -aWedge.GetPointIds().SetId(7,7) -aWedge.GetPointIds().SetId(8,8) -aWedge.GetPointIds().SetId(9,9) -aWedge.GetPointIds().SetId(10,10) -aWedge.GetPointIds().SetId(11,11) -aWedge.GetPointIds().SetId(12,12) -aWedge.GetPointIds().SetId(13,13) -aWedge.GetPointIds().SetId(14,14) +aWedge.GetPointIds().SetId(0, 0) +aWedge.GetPointIds().SetId(1, 1) +aWedge.GetPointIds().SetId(2, 2) +aWedge.GetPointIds().SetId(3, 3) +aWedge.GetPointIds().SetId(4, 4) +aWedge.GetPointIds().SetId(5, 5) +aWedge.GetPointIds().SetId(6, 6) +aWedge.GetPointIds().SetId(7, 7) +aWedge.GetPointIds().SetId(8, 8) +aWedge.GetPointIds().SetId(9, 9) +aWedge.GetPointIds().SetId(10, 10) +aWedge.GetPointIds().SetId(11, 11) +aWedge.GetPointIds().SetId(12, 12) +aWedge.GetPointIds().SetId(13, 13) +aWedge.GetPointIds().SetId(14, 14) aWedgeGrid = vtk.vtkUnstructuredGrid() -aWedgeGrid.Allocate(1,1) -aWedgeGrid.InsertNextCell(aWedge.GetCellType(),aWedge.GetPointIds()) +aWedgeGrid.Allocate(1, 1) +aWedgeGrid.InsertNextCell(aWedge.GetCellType(), aWedge.GetPointIds()) aWedgeGrid.SetPoints(wedgePoints) aWedgeGrid.GetPointData().SetScalars(wedgeScalars) wedgeContours = vtk.vtkClipDataSet() @@ -309,54 +322,55 @@ aWedgeActor.GetProperty().SetAmbient(1.0) aWedgeContourActor = vtk.vtkActor() aWedgeContourActor.SetMapper(aWedgeContourMapper) aWedgeContourActor.GetProperty().SetAmbient(1.0) + # Quadratic pyramid pyraPoints = vtk.vtkPoints() pyraPoints.SetNumberOfPoints(13) -pyraPoints.InsertPoint(0,0,0,0) -pyraPoints.InsertPoint(1,1,0,0) -pyraPoints.InsertPoint(2,1,1,0) -pyraPoints.InsertPoint(3,0,1,0) -pyraPoints.InsertPoint(4,0,0,1) -pyraPoints.InsertPoint(5,0.5,0,0) -pyraPoints.InsertPoint(6,1,0.5,0) -pyraPoints.InsertPoint(7,0.5,1,0) -pyraPoints.InsertPoint(8,0,0.5,0) -pyraPoints.InsertPoint(9,0,0,0.5) -pyraPoints.InsertPoint(10,0.5,0,0.5) -pyraPoints.InsertPoint(11,0.5,0.5,0.5) -pyraPoints.InsertPoint(12,0,0.5,0.5) +pyraPoints.InsertPoint(0, 0, 0, 0) +pyraPoints.InsertPoint(1, 1, 0, 0) +pyraPoints.InsertPoint(2, 1, 1, 0) +pyraPoints.InsertPoint(3, 0, 1, 0) +pyraPoints.InsertPoint(4, 0, 0, 1) +pyraPoints.InsertPoint(5, 0.5, 0, 0) +pyraPoints.InsertPoint(6, 1, 0.5, 0) +pyraPoints.InsertPoint(7, 0.5, 1, 0) +pyraPoints.InsertPoint(8, 0, 0.5, 0) +pyraPoints.InsertPoint(9, 0, 0, 0.5) +pyraPoints.InsertPoint(10, 0.5, 0, 0.5) +pyraPoints.InsertPoint(11, 0.5, 0.5, 0.5) +pyraPoints.InsertPoint(12, 0, 0.5, 0.5) pyraScalars = vtk.vtkFloatArray() pyraScalars.SetNumberOfTuples(13) -pyraScalars.InsertValue(0,1.0) -pyraScalars.InsertValue(1,1.0) -pyraScalars.InsertValue(2,1.0) -pyraScalars.InsertValue(3,1.0) -pyraScalars.InsertValue(4,1.0) -pyraScalars.InsertValue(5,1.0) -pyraScalars.InsertValue(6,1.0) -pyraScalars.InsertValue(7,1.0) -pyraScalars.InsertValue(8,0.0) -pyraScalars.InsertValue(9,0.0) -pyraScalars.InsertValue(10,0.0) -pyraScalars.InsertValue(11,0.0) -pyraScalars.InsertValue(12,0.0) +pyraScalars.InsertValue(0, 1.0) +pyraScalars.InsertValue(1, 1.0) +pyraScalars.InsertValue(2, 1.0) +pyraScalars.InsertValue(3, 1.0) +pyraScalars.InsertValue(4, 1.0) +pyraScalars.InsertValue(5, 1.0) +pyraScalars.InsertValue(6, 1.0) +pyraScalars.InsertValue(7, 1.0) +pyraScalars.InsertValue(8, 0.0) +pyraScalars.InsertValue(9, 0.0) +pyraScalars.InsertValue(10, 0.0) +pyraScalars.InsertValue(11, 0.0) +pyraScalars.InsertValue(12, 0.0) aPyramid = vtk.vtkQuadraticPyramid() -aPyramid.GetPointIds().SetId(0,0) -aPyramid.GetPointIds().SetId(1,1) -aPyramid.GetPointIds().SetId(2,2) -aPyramid.GetPointIds().SetId(3,3) -aPyramid.GetPointIds().SetId(4,4) -aPyramid.GetPointIds().SetId(5,5) -aPyramid.GetPointIds().SetId(6,6) -aPyramid.GetPointIds().SetId(7,7) -aPyramid.GetPointIds().SetId(8,8) -aPyramid.GetPointIds().SetId(9,9) -aPyramid.GetPointIds().SetId(10,10) -aPyramid.GetPointIds().SetId(11,11) -aPyramid.GetPointIds().SetId(12,12) +aPyramid.GetPointIds().SetId(0, 0) +aPyramid.GetPointIds().SetId(1, 1) +aPyramid.GetPointIds().SetId(2, 2) +aPyramid.GetPointIds().SetId(3, 3) +aPyramid.GetPointIds().SetId(4, 4) +aPyramid.GetPointIds().SetId(5, 5) +aPyramid.GetPointIds().SetId(6, 6) +aPyramid.GetPointIds().SetId(7, 7) +aPyramid.GetPointIds().SetId(8, 8) +aPyramid.GetPointIds().SetId(9, 9) +aPyramid.GetPointIds().SetId(10, 10) +aPyramid.GetPointIds().SetId(11, 11) +aPyramid.GetPointIds().SetId(12, 12) aPyramidGrid = vtk.vtkUnstructuredGrid() -aPyramidGrid.Allocate(1,1) -aPyramidGrid.InsertNextCell(aPyramid.GetCellType(),aPyramid.GetPointIds()) +aPyramidGrid.Allocate(1, 1) +aPyramidGrid.InsertNextCell(aPyramid.GetCellType(), aPyramid.GetPointIds()) aPyramidGrid.SetPoints(pyraPoints) aPyramidGrid.GetPointData().SetScalars(pyraScalars) pyraContours = vtk.vtkClipDataSet() @@ -375,6 +389,7 @@ aPyramidActor.GetProperty().SetAmbient(1.0) aPyramidContourActor = vtk.vtkActor() aPyramidContourActor.SetMapper(aPyramidContourMapper) aPyramidContourActor.GetProperty().SetAmbient(1.0) + # Create the rendering related stuff. # Since some of our actors are a single vertex, we need to remove all # cullers so the single vertex actors will render @@ -384,8 +399,10 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) -ren1.SetBackground(.1,.2,.3) -renWin.SetSize(400,200) +ren1.SetBackground(.1, .2, .3) + +renWin.SetSize(400, 200) + # specify properties ren1.AddActor(aEdgeActor) ren1.AddActor(aTriActor) @@ -394,24 +411,26 @@ ren1.AddActor(aTetActor) ren1.AddActor(aHexActor) ren1.AddActor(aWedgeActor) ren1.AddActor(aPyramidActor) + # places everyone!! -aTriActor.AddPosition(2,0,0) -aQuadActor.AddPosition(4,0,0) -aTetActor.AddPosition(6,0,0) -aHexActor.AddPosition(8,0,0) -aWedgeActor.AddPosition(10,0,0) -aPyramidActor.AddPosition(12,0,0) -[base, back, left] = BuildBackdrop(-1, 15, -1, 4, -1, 2, .1) +aTriActor.AddPosition(2, 0, 0) +aQuadActor.AddPosition(4, 0, 0) +aTetActor.AddPosition(6, 0, 0) +aHexActor.AddPosition(8, 0, 0) +aWedgeActor.AddPosition(10, 0, 0) +aPyramidActor.AddPosition(12, 0, 0) +[base, back, left] = backdrop.BuildBackdrop(-1, 15, -1, 4, -1, 2, .1) ren1.AddActor(base) -base.GetProperty().SetDiffuseColor(.2,.2,.2) +base.GetProperty().SetDiffuseColor(.2, .2, .2) ren1.AddActor(left) -left.GetProperty().SetDiffuseColor(.2,.2,.2) +left.GetProperty().SetDiffuseColor(.2, .2, .2) ren1.AddActor(back) -back.GetProperty().SetDiffuseColor(.2,.2,.2) +back.GetProperty().SetDiffuseColor(.2, .2, .2) ren1.ResetCamera() ren1.GetActiveCamera().Dolly(2.5) ren1.ResetCameraClippingRange() renWin.Render() + # create a little scorecard above each of the cells. These are displayed # if a ray cast hits the cell, otherwise they are not shown. pm = vtk.vtkPlaneSource() @@ -419,58 +438,59 @@ pm.SetXResolution(1) pm.SetYResolution(1) pmapper = vtk.vtkPolyDataMapper() pmapper.SetInputConnection(pm.GetOutputPort()) + # now try intersecting rays with the cell cellPicker = vtk.vtkCellPicker() edgeCheck = vtk.vtkActor() edgeCheck.SetMapper(pmapper) -edgeCheck.AddPosition(0.5,2.5,0) -cellPicker.Pick(87,71,0,ren1) +edgeCheck.AddPosition(0.5, 2.5, 0) +cellPicker.Pick(87, 71, 0, ren1) if (cellPicker.GetCellId() != "-1"): ren1.AddActor(edgeCheck) - pass + triCheck = vtk.vtkActor() triCheck.SetMapper(pmapper) -triCheck.AddPosition(2.5,2.5,0) -cellPicker.Pick(139,72,0,ren1) +triCheck.AddPosition(2.5, 2.5, 0) +cellPicker.Pick(139, 72, 0, ren1) if (cellPicker.GetCellId() != "-1"): ren1.AddActor(triCheck) - pass + quadCheck = vtk.vtkActor() quadCheck.SetMapper(pmapper) -quadCheck.AddPosition(4.5,2.5,0) -cellPicker.Pick(192,78,0,ren1) +quadCheck.AddPosition(4.5, 2.5, 0) +cellPicker.Pick(192, 78, 0, ren1) if (cellPicker.GetCellId() != "-1"): ren1.AddActor(quadCheck) - pass + tetCheck = vtk.vtkActor() tetCheck.SetMapper(pmapper) -tetCheck.AddPosition(6.5,2.5,0) -cellPicker.Pick(233,70,0,ren1) +tetCheck.AddPosition(6.5, 2.5, 0) +cellPicker.Pick(233, 70, 0, ren1) if (cellPicker.GetCellId() != "-1"): ren1.AddActor(tetCheck) - pass + hexCheck = vtk.vtkActor() hexCheck.SetMapper(pmapper) -hexCheck.AddPosition(8.5,2.5,0) -cellPicker.Pick(287,80,0,ren1) +hexCheck.AddPosition(8.5, 2.5, 0) +cellPicker.Pick(287, 80, 0, ren1) if (cellPicker.GetCellId() != "-1"): ren1.AddActor(hexCheck) - pass + wedgeCheck = vtk.vtkActor() wedgeCheck.SetMapper(pmapper) -wedgeCheck.AddPosition(10.5,2.5,0) -cellPicker.Pick(287,80,0,ren1) +wedgeCheck.AddPosition(10.5, 2.5, 0) +cellPicker.Pick(287, 80, 0, ren1) if (cellPicker.GetCellId() != "-1"): ren1.AddActor(wedgeCheck) - pass + pyraCheck = vtk.vtkActor() pyraCheck.SetMapper(pmapper) -pyraCheck.AddPosition(12.5,2.5,0) -cellPicker.Pick(287,80,0,ren1) +pyraCheck.AddPosition(12.5, 2.5, 0) +cellPicker.Pick(287, 80, 0, ren1) if (cellPicker.GetCellId() != "-1"): ren1.AddActor(pyraCheck) - pass + # render the image # iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Common/DataModel/Testing/Python/SelectionLoop.py b/Common/DataModel/Testing/Python/SelectionLoop.py index 14f2d502624..f3ff1d211b4 100755 --- a/Common/DataModel/Testing/Python/SelectionLoop.py +++ b/Common/DataModel/Testing/Python/SelectionLoop.py @@ -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 + # # Demonstrate the use of implicit selection loop as well as closest point # connectivity @@ -15,12 +24,12 @@ sphere.SetRadius(1) sphere.SetPhiResolution(100) sphere.SetThetaResolution(100) selectionPoints = vtk.vtkPoints() -selectionPoints.InsertPoint(0,0.07325,0.8417,0.5612) -selectionPoints.InsertPoint(1,0.07244,0.6568,0.7450) -selectionPoints.InsertPoint(2,0.1727,0.4597,0.8850) -selectionPoints.InsertPoint(3,0.3265,0.6054,0.7309) -selectionPoints.InsertPoint(4,0.5722,0.5848,0.5927) -selectionPoints.InsertPoint(5,0.4305,0.8138,0.4189) +selectionPoints.InsertPoint(0, 0.07325, 0.8417, 0.5612) +selectionPoints.InsertPoint(1, 0.07244, 0.6568, 0.7450) +selectionPoints.InsertPoint(2, 0.1727, 0.4597, 0.8850) +selectionPoints.InsertPoint(3, 0.3265, 0.6054, 0.7309) +selectionPoints.InsertPoint(4, 0.5722, 0.5848, 0.5927) +selectionPoints.InsertPoint(5, 0.4305, 0.8138, 0.4189) loop = vtk.vtkImplicitSelectionLoop() loop.SetLoop(selectionPoints) extract = vtk.vtkExtractGeometry() @@ -33,11 +42,12 @@ connect.SetClosestPoint(selectionPoints.GetPoint(0)) clipMapper = vtk.vtkDataSetMapper() clipMapper.SetInputConnection(connect.GetOutputPort()) backProp = vtk.vtkProperty() -backProp.SetDiffuseColor(tomato) +backProp.SetDiffuseColor(GetRGBColor('tomato')) clipActor = vtk.vtkActor() clipActor.SetMapper(clipMapper) -clipActor.GetProperty().SetColor(peacock) +clipActor.GetProperty().SetColor(GetRGBColor('peacock')) clipActor.SetBackfaceProperty(backProp) + # Create graphics stuff # ren1 = vtk.vtkRenderer() @@ -45,18 +55,22 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(clipActor) -ren1.SetBackground(1,1,1) +ren1.SetBackground(1, 1, 1) ren1.ResetCamera() ren1.GetActiveCamera().Azimuth(30) ren1.GetActiveCamera().Elevation(30) ren1.GetActiveCamera().Dolly(1.2) ren1.ResetCameraClippingRange() -renWin.SetSize(400,400) + +renWin.SetSize(400, 400) + renWin.Render() + # render the image # -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Common/DataModel/Testing/Python/TestConvexPointSet.py b/Common/DataModel/Testing/Python/TestConvexPointSet.py index c4f97038eb0..209ec2205bc 100755 --- a/Common/DataModel/Testing/Python/TestConvexPointSet.py +++ b/Common/DataModel/Testing/Python/TestConvexPointSet.py @@ -1,43 +1,48 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing # create points in the configuration of an octant with one 2:1 face # points = vtk.vtkPoints() aConvex = vtk.vtkConvexPointSet() -points.InsertPoint(0,0,0,0) -points.InsertPoint(1,1,0,0) -points.InsertPoint(2,1,1,0) -points.InsertPoint(3,0,1,0) -points.InsertPoint(4,0,0,1) -points.InsertPoint(5,1,0,1) -points.InsertPoint(6,1,1,1) -points.InsertPoint(7,0,1,1) -points.InsertPoint(8,0.5,0,0) -points.InsertPoint(9,1,0.5,0) -points.InsertPoint(10,0.5,1,0) -points.InsertPoint(11,0,0.5,0) -points.InsertPoint(12,0.5,0.5,0) +points.InsertPoint(0, 0, 0, 0) +points.InsertPoint(1, 1, 0, 0) +points.InsertPoint(2, 1, 1, 0) +points.InsertPoint(3, 0, 1, 0) +points.InsertPoint(4, 0, 0, 1) +points.InsertPoint(5, 1, 0, 1) +points.InsertPoint(6, 1, 1, 1) +points.InsertPoint(7, 0, 1, 1) +points.InsertPoint(8, 0.5, 0, 0) +points.InsertPoint(9, 1, 0.5, 0) +points.InsertPoint(10, 0.5, 1, 0) +points.InsertPoint(11, 0, 0.5, 0) +points.InsertPoint(12, 0.5, 0.5, 0) i = 0 while i < 13: - aConvex.GetPointIds().InsertId(i,i) - i = i + 1 + aConvex.GetPointIds().InsertId(i, i) + i += 1 aConvexGrid = vtk.vtkUnstructuredGrid() -aConvexGrid.Allocate(1,1) -aConvexGrid.InsertNextCell(aConvex.GetCellType(),aConvex.GetPointIds()) +aConvexGrid.Allocate(1, 1) +aConvexGrid.InsertNextCell(aConvex.GetCellType(), aConvex.GetPointIds()) aConvexGrid.SetPoints(points) + # Display the cell dsm = vtk.vtkDataSetMapper() dsm.SetInputData(aConvexGrid) a = vtk.vtkActor() a.SetMapper(dsm) -a.GetProperty().SetColor(0,1,0) +a.GetProperty().SetColor(0, 1, 0) + # Contour and clip the cell with elevation scalars ele = vtk.vtkElevationFilter() ele.SetInputData(aConvexGrid) -ele.SetLowPoint(-1,-1,-1) -ele.SetHighPoint(1,1,1) -ele.SetScalarRange(-1,1) +ele.SetLowPoint(-1, -1, -1) +ele.SetHighPoint(1, 1, 1) +ele.SetScalarRange(-1, 1) + # Clip # clip = vtk.vtkClipDataSet() @@ -50,13 +55,14 @@ map.SetInputConnection(g.GetOutputPort()) map.ScalarVisibilityOff() clipActor = vtk.vtkActor() clipActor.SetMapper(map) -clipActor.GetProperty().SetColor(1,0,0) -clipActor.AddPosition(2,0,0) +clipActor.GetProperty().SetColor(1, 0, 0) +clipActor.AddPosition(2, 0, 0) + # Contour # contour = vtk.vtkContourFilter() contour.SetInputConnection(ele.GetOutputPort()) -contour.SetValue(0,0.5) +contour.SetValue(0, 0.5) g2 = vtk.vtkDataSetSurfaceFilter() g2.SetInputConnection(contour.GetOutputPort()) map2 = vtk.vtkPolyDataMapper() @@ -64,8 +70,9 @@ map2.SetInputConnection(g2.GetOutputPort()) map2.ScalarVisibilityOff() contourActor = vtk.vtkActor() contourActor.SetMapper(map2) -contourActor.GetProperty().SetColor(1,0,0) -contourActor.AddPosition(1,2,0) +contourActor.GetProperty().SetColor(1, 0, 0) +contourActor.AddPosition(1, 2, 0) + # Create graphics stuff # ren1 = vtk.vtkRenderer() @@ -73,24 +80,31 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(a) ren1.AddActor(clipActor) ren1.AddActor(contourActor) -ren1.SetBackground(1,1,1) -renWin.SetSize(250,150) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(250, 150) + aCam = vtk.vtkCamera() -aCam.SetFocalPoint(1.38705,1.37031,0.639901) -aCam.SetPosition(1.89458,-5.07106,-4.17439) -aCam.SetViewUp(0.00355726,0.598843,-0.800858) -aCam.SetClippingRange(4.82121,12.1805) +aCam.SetFocalPoint(1.38705, 1.37031, 0.639901) +aCam.SetPosition(1.89458, -5.07106, -4.17439) +aCam.SetViewUp(0.00355726, 0.598843, -0.800858) +aCam.SetClippingRange(4.82121, 12.1805) + ren1.SetActiveCamera(aCam) + renWin.Render() + cam1 = ren1.GetActiveCamera() cam1.Zoom(1.5) + # render the image # renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Common/DataModel/Testing/Python/TestQuadricClustering.py b/Common/DataModel/Testing/Python/TestQuadricClustering.py index a98512daf85..8af49de77c6 100755 --- a/Common/DataModel/Testing/Python/TestQuadricClustering.py +++ b/Common/DataModel/Testing/Python/TestQuadricClustering.py @@ -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 + # Generate implicit model of a sphere # ren1 = vtk.vtkRenderer() @@ -11,16 +20,19 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # pipeline stuff # sphere = vtk.vtkSphereSource() sphere.SetPhiResolution(150) sphere.SetThetaResolution(150) + pts = vtk.vtkPoints() -pts.InsertNextPoint(0,0,0) -pts.InsertNextPoint(1,0,0) -pts.InsertNextPoint(0,1,0) -pts.InsertNextPoint(0,0,1) +pts.InsertNextPoint(0, 0, 0) +pts.InsertNextPoint(1, 0, 0) +pts.InsertNextPoint(0, 1, 0) +pts.InsertNextPoint(0, 0, 1) + tris = vtk.vtkCellArray() tris.InsertNextCell(3) tris.InsertCellPoint(0) @@ -38,29 +50,33 @@ tris.InsertNextCell(3) tris.InsertCellPoint(1) tris.InsertCellPoint(2) tris.InsertCellPoint(3) + polys = vtk.vtkPolyData() polys.SetPoints(pts) polys.SetPolys(tris) + mesh = vtk.vtkQuadricClustering() mesh.SetInputConnection(sphere.GetOutputPort()) mesh.SetNumberOfXDivisions(10) mesh.SetNumberOfYDivisions(10) mesh.SetNumberOfZDivisions(10) + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(mesh.GetOutputPort()) + actor = vtk.vtkActor() actor.SetMapper(mapper) -actor.GetProperty().SetDiffuseColor(tomato) +actor.GetProperty().SetDiffuseColor(GetRGBColor('tomato')) actor.GetProperty().SetDiffuse(.8) actor.GetProperty().SetSpecular(.4) actor.GetProperty().SetSpecularPower(30) + # Add the actors to the renderer, set the background and size # ren1.AddActor(actor) -ren1.SetBackground(1,1,1) -renWin.SetSize(300,300) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(300, 300) + iren.Initialize() -# render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Common/DataModel/Testing/Python/backdrop.py b/Common/DataModel/Testing/Python/backdrop.py new file mode 100644 index 00000000000..77436c43191 --- /dev/null +++ b/Common/DataModel/Testing/Python/backdrop.py @@ -0,0 +1,74 @@ +"""this is python equivalent of ./Wrapping/Tcl/vtktesting/backdrop.tcl +This script is used while running python tests translated from Tcl.""" + +import vtk + +basePlane = None +baseMapper = None +base = None + +backPlane = None +backMapper = None +back = None + +leftPlane = None +leftMapper = None +left = None + +def BuildBackdrop (minX, maxX, minY, maxY, minZ, maxZ, thickness): + global basePlane + global baseMapper + global base + global backPlane + global backMapper + global back + global left + global leftPlane + global leftMapper + + if not basePlane: + basePlane = vtk.vtkCubeSource() + basePlane.SetCenter( (maxX + minX)/2.0, minY, (maxZ + minZ)/2.0) + basePlane.SetXLength(maxX-minX) + basePlane.SetYLength(thickness) + basePlane.SetZLength(maxZ - minZ) + + if not baseMapper: + baseMapper = vtk.vtkPolyDataMapper() + baseMapper.SetInputConnection(basePlane.GetOutputPort()) + + if not base: + base = vtk.vtkActor() + base.SetMapper(baseMapper) + + if not backPlane: + backPlane = vtk.vtkCubeSource() + backPlane.SetCenter( (maxX + minX)/2.0, (maxY + minY)/2.0, minZ) + backPlane.SetXLength(maxX-minX) + backPlane.SetYLength(maxY - minY) + backPlane.SetZLength(thickness) + + if not backMapper: + backMapper = vtk.vtkPolyDataMapper() + backMapper.SetInputConnection(backPlane.GetOutputPort()) + + if not back: + back = vtk.vtkActor() + back.SetMapper(backMapper) + + if not leftPlane: + leftPlane = vtk.vtkCubeSource() + leftPlane.SetCenter( minX, (maxY+minY)/2.0, (maxZ+minZ)/2.0) + leftPlane.SetXLength(thickness) + leftPlane.SetYLength(maxY-minY) + leftPlane.SetZLength(maxZ-minZ) + + if not leftMapper: + leftMapper = vtk.vtkPolyDataMapper() + leftMapper.SetInputConnection(leftPlane.GetOutputPort()) + + if not left: + left = vtk.vtkActor() + left.SetMapper(leftMapper) + + return [base, back, left] diff --git a/Common/DataModel/Testing/Python/headBone.py b/Common/DataModel/Testing/Python/headBone.py index 81fdb0d0654..3ba3ef134c1 100755 --- a/Common/DataModel/Testing/Python/headBone.py +++ b/Common/DataModel/Testing/Python/headBone.py @@ -4,6 +4,16 @@ 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 + + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -15,59 +25,76 @@ lgt = vtk.vtkLight() # create pipeline # locator = vtk.vtkMergePoints() -locator.SetDivisions(32,32,46) +locator.SetDivisions(32, 32, 46) locator.SetNumberOfPointsPerBucket(2) locator.AutomaticOff() + v16 = vtk.vtkVolume16Reader() -v16.SetDataDimensions(64,64) -v16.GetOutput().SetOrigin(0.0,0.0,0.0) +v16.SetDataDimensions(64, 64) +v16.GetOutput().SetOrigin(0.0, 0.0, 0.0) v16.SetDataByteOrderToLittleEndian() -v16.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter") -v16.SetImageRange(1,93) -v16.SetDataSpacing(3.2,3.2,1.5) +v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") +v16.SetImageRange(1, 93) +v16.SetDataSpacing(3.2, 3.2, 1.5) + iso = vtk.vtkMarchingCubes() iso.SetInputConnection(v16.GetOutputPort()) -iso.SetValue(0,1150) +iso.SetValue(0, 1150) iso.ComputeGradientsOn() iso.ComputeScalarsOff() iso.SetLocator(locator) + gradient = vtk.vtkVectorNorm() gradient.SetInputConnection(iso.GetOutputPort()) + isoMapper = vtk.vtkDataSetMapper() isoMapper.SetInputConnection(gradient.GetOutputPort()) isoMapper.ScalarVisibilityOn() -isoMapper.SetScalarRange(0,1200) +isoMapper.SetScalarRange(0, 1200) isoMapper.ImmediateModeRenderingOn() + isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) + isoProp = isoActor.GetProperty() -isoProp.SetColor(antique_white) +isoProp.SetColor(GetRGBColor('antique_white')) + outline = vtk.vtkOutlineFilter() outline.SetInputConnection(v16.GetOutputPort()) + outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) + outlineProp = outlineActor.GetProperty() -#eval $outlineProp SetColor 0 0 0 +# outlineProp.SetColor(0, 0, 0) + # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) ren1.AddActor(isoActor) -ren1.SetBackground(1,1,1) +ren1.SetBackground(1, 1, 1) ren1.AddLight(lgt) -renWin.SetSize(250,250) -ren1.SetBackground(0.1,0.2,0.4) + +renWin.SetSize(250, 250) + +ren1.SetBackground(0.1, 0.2, 0.4) ren1.ResetCamera() + cam1 = ren1.GetActiveCamera() cam1.Elevation(90) -cam1.SetViewUp(0,0,-1) +cam1.SetViewUp(0, 0, -1) cam1.Zoom(1.5) + lgt.SetPosition(cam1.GetPosition()) lgt.SetFocalPoint(cam1.GetFocalPoint()) + ren1.ResetCameraClippingRange() + # render the image # renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Common/Transforms/Testing/Python/spherical.py b/Common/Transforms/Testing/Python/spherical.py index 2c4cad7d40f..b3a8cf85283 100755 --- a/Common/Transforms/Testing/Python/spherical.py +++ b/Common/Transforms/Testing/Python/spherical.py @@ -11,48 +11,61 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # avoid the singularity at the Z axis using 0.0001 radian offset plane = vtk.vtkPlaneSource() -plane.SetOrigin(1.0,expr.expr(globals(), locals(),["3.14159265359","-","0.0001"]),0.0) -plane.SetPoint1(1.0,expr.expr(globals(), locals(),["3.14159265359","-","0.0001"]),6.28318530719) -plane.SetPoint2(1.0,0.0001,0.0) +plane.SetOrigin(1.0, 3.14159265359 - 0.0001, 0.0) +plane.SetPoint1(1.0, 3.14159265359 - 0.0001, 6.28318530719) +plane.SetPoint2(1.0, 0.0001, 0.0) plane.SetXResolution(19) plane.SetYResolution(9) + transform = vtk.vtkSphericalTransform() + tpoly = vtk.vtkTransformPolyDataFilter() tpoly.SetInputConnection(plane.GetOutputPort()) tpoly.SetTransform(transform) + # also cover the inverse transformation by going back and forth tpoly2 = vtk.vtkTransformPolyDataFilter() tpoly2.SetInputConnection(tpoly.GetOutputPort()) tpoly2.SetTransform(transform.GetInverse()) + tpoly3 = vtk.vtkTransformPolyDataFilter() tpoly3.SetInputConnection(tpoly2.GetOutputPort()) tpoly3.SetTransform(transform) + mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(tpoly3.GetOutputPort()) + earth = vtk.vtkPNMReader() -earth.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/earth.ppm") +earth.SetFileName(VTK_DATA_ROOT + "/Data/earth.ppm") + texture = vtk.vtkTexture() texture.SetInputConnection(earth.GetOutputPort()) texture.InterpolateOn() + world = vtk.vtkActor() world.SetMapper(mapper) world.SetTexture(texture) + # Add the actors to the renderer, set the background and size # ren1.AddActor(world) -ren1.SetBackground(0.1,0.2,0.4) -renWin.SetSize(300,300) -ren1.GetActiveCamera().SetPosition(8,-10,6) -ren1.GetActiveCamera().SetFocalPoint(0,0,0) +ren1.SetBackground(0.1, 0.2, 0.4) + +renWin.SetSize(300, 300) + +ren1.GetActiveCamera().SetPosition(8, -10, 6) +ren1.GetActiveCamera().SetFocalPoint(0, 0, 0) ren1.GetActiveCamera().SetViewAngle(15) -ren1.GetActiveCamera().SetViewUp(0.0,0.0,1.0) +ren1.GetActiveCamera().SetViewUp(0.0, 0.0, 1.0) + # render the image # cam1 = ren1.GetActiveCamera() cam1.Zoom(1.4) ren1.ResetCameraClippingRange() + iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Core/Testing/Python/Delaunay2DTransform.py b/Filters/Core/Testing/Python/Delaunay2DTransform.py index 88e25622448..10ad9bfeffe 100755 --- a/Filters/Core/Testing/Python/Delaunay2DTransform.py +++ b/Filters/Core/Testing/Python/Delaunay2DTransform.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import math import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot @@ -11,6 +12,7 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create some points on a sphere such that the data is not in the form # of z = f(x,y) # @@ -20,19 +22,23 @@ vectors = vtk.vtkFloatArray() vectors.SetNumberOfComponents(3) i = 0 while i < 100: - theta = math1.Random(0.31415,2.8) - phi = math1.Random(0.31415,2.8) - points.InsertPoint(i,expr.expr(globals(), locals(),["cos","(","theta",")*","sin","(","phi",")"]),expr.expr(globals(), locals(),["sin","(","theta",")*","sin","(","phi",")"]),expr.expr(globals(), locals(),["cos","(","phi",")"])) - vectors.InsertTuple3(i,expr.expr(globals(), locals(),["cos","(","theta",")*","sin","(","phi",")"]),expr.expr(globals(), locals(),["sin","(","theta",")*","sin","(","phi",")"]),expr.expr(globals(), locals(),["cos","(","phi",")"])) + theta = math1.Random(0.31415, 2.8) + phi = math1.Random(0.31415, 2.8) + points.InsertPoint(i, math.cos(theta) * math.sin(phi), + math.sin(theta) * math.sin(phi), math.cos(phi)) + vectors.InsertTuple3(i, math.cos(theta) * math.sin(phi), + math.sin(theta) * math.sin(phi), math.cos(phi)) i = i + 1 profile = vtk.vtkPolyData() profile.SetPoints(points) profile.GetPointData().SetVectors(vectors) + # build a transform that rotates this data into z = f(x,y) # transform = vtk.vtkTransform() transform.RotateX(90) + # triangulate the data using the specified transform # del1 = vtk.vtkDelaunay2D() @@ -41,27 +47,34 @@ del1.SetTransform(transform) del1.BoundingTriangulationOff() del1.SetTolerance(0.001) del1.SetAlpha(0.0) + shrink = vtk.vtkShrinkPolyData() shrink.SetInputConnection(del1.GetOutputPort()) + map = vtk.vtkPolyDataMapper() map.SetInputConnection(shrink.GetOutputPort()) + triangulation = vtk.vtkActor() triangulation.SetMapper(map) -triangulation.GetProperty().SetColor(1,0,0) +triangulation.GetProperty().SetColor(1, 0, 0) triangulation.GetProperty().BackfaceCullingOn() + # Add the actors to the renderer, set the background and size # ren1.AddActor(triangulation) -ren1.SetBackground(1,1,1) -renWin.SetSize(300,300) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(300, 300) renWin.Render() + cam1 = ren1.GetActiveCamera() cam1.Zoom(1.5) cam1.Azimuth(90) cam1.Elevation(30) cam1.Azimuth(-60) + # render the image # renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Filters/Core/Testing/Python/StreamPolyData.py b/Filters/Core/Testing/Python/StreamPolyData.py index a83762b8ca1..9883a3f03fe 100755 --- a/Filters/Core/Testing/Python/StreamPolyData.py +++ b/Filters/Core/Testing/Python/StreamPolyData.py @@ -4,9 +4,20 @@ 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 + NUMBER_OF_PIECES = 5 + # Generate implicit model of a sphere # + # Create renderer stuff # ren1 = vtk.vtkRenderer() @@ -14,21 +25,25 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create pipeline that handles ghost cells sphere = vtk.vtkSphereSource() sphere.SetRadius(3) sphere.SetPhiResolution(100) sphere.SetThetaResolution(150) -# sphere AddObserver StartEvent {tk_messageBox -message "Executing with piece [[sphere GetOutput] GetUpdatePiece]"} + # Just playing with an alternative that is not currently used. -def NotUsed (__vtk__temp0=0,__vtk__temp1=0): - # This filter actually spoils the example because it asks for the whole input. - # The only reason it is here is because sphere complains it cannot generate ghost cells. +def NotUsed (): + # This filter actually spoils the example because it asks + # for the whole input. + # The only reason it is here is because sphere complains + # it cannot generate ghost cells. vtkExtractPolyDataPiece.piece() piece.SetInputConnection(sphere.GetOutputPort()) # purposely put seams in here. piece.CreateGhostCellsOff() # purposely put seams in here. + pdn = vtk.vtkPolyDataNormals() pdn.SetInputConnection(piece.GetOutputPort()) @@ -37,38 +52,43 @@ deci = vtk.vtkDecimatePro() deci.SetInputConnection(sphere.GetOutputPort()) # this did not remove seams as I thought it would deci.BoundaryVertexDeletionOff() -#deci PreserveTopologyOn +# deci.PreserveTopologyOn() + # Since quadric Clustering does not handle borders properly yet, -# the pieces will have dramatic "eams" +# the pieces will have dramatic "seams" q = vtk.vtkQuadricClustering() q.SetInputConnection(sphere.GetOutputPort()) q.SetNumberOfXDivisions(5) q.SetNumberOfYDivisions(5) q.SetNumberOfZDivisions(10) q.UseInputPointsOn() + streamer = vtk.vtkPolyDataStreamer() -#streamer SetInputConnection [deci GetOutputPort] +# streamer.SetInputConnection(deci.GetOutputPort()) streamer.SetInputConnection(q.GetOutputPort()) -#streamer SetInputConnection [pdn GetOutputPort] +# streamer.SetInputConnection(pdn.GetOutputPort()) streamer.SetNumberOfStreamDivisions(NUMBER_OF_PIECES) + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(streamer.GetOutputPort()) mapper.ScalarVisibilityOff() mapper.SetPiece(0) mapper.SetNumberOfPieces(2) mapper.ImmediateModeRenderingOn() + actor = vtk.vtkActor() actor.SetMapper(mapper) -actor.GetProperty().SetColor(english_red) +actor.GetProperty().SetColor(GetRGBColor('english_red')) + # Add the actors to the renderer, set the background and size # -ren1.GetActiveCamera().SetPosition(5,5,10) -ren1.GetActiveCamera().SetFocalPoint(0,0,0) +ren1.GetActiveCamera().SetPosition(5, 5, 10) +ren1.GetActiveCamera().SetFocalPoint(0, 0, 0) ren1.AddActor(actor) -ren1.SetBackground(1,1,1) -renWin.SetSize(300,300) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(300, 300) + iren.Initialize() # render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Core/Testing/Python/TestGridSynchronizedTemplates3D.py b/Filters/Core/Testing/Python/TestGridSynchronizedTemplates3D.py index 87d58042a6b..51f53b8a5d1 100755 --- a/Filters/Core/Testing/Python/TestGridSynchronizedTemplates3D.py +++ b/Filters/Core/Testing/Python/TestGridSynchronizedTemplates3D.py @@ -5,80 +5,101 @@ from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() class TestGridSynchronizedTemplates3D(Testing.vtkTest): - def testAll(self): - # cut data - pl3d = vtk.vtkMultiBlockPLOT3DReader() - pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") - pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") - pl3d.SetScalarFunctionNumber(100) - pl3d.SetVectorFunctionNumber(202) - pl3d.Update() - pl3d_output = pl3d.GetOutput().GetBlock(0) - range = pl3d_output.GetPointData().GetScalars().GetRange() - min = lindex(range,0) - max = lindex(range,1) - value = expr.expr(globals(), locals(),["(","min","+","max",")","/","2.0"]) - #vtkGridSynchronizedTemplates3D cf - cf = vtk.vtkContourFilter() - cf.SetInputData(pl3d_output) - cf.SetValue(0,value) - cf.GenerateTrianglesOff() - cf.Update() - self.failUnlessEqual(cf.GetOutputDataObject(0).GetNumberOfPoints(),4674) - self.failUnlessEqual(cf.GetOutputDataObject(0).GetNumberOfCells(),4011) - - cf.GenerateTrianglesOn() - cf.Update() - self.failUnlessEqual(cf.GetOutputDataObject(0).GetNumberOfPoints(),4674) - self.failUnlessEqual(cf.GetOutputDataObject(0).GetNumberOfCells(),8076) - - #cf ComputeNormalsOff - cfMapper = vtk.vtkPolyDataMapper() - cfMapper.ImmediateModeRenderingOn() - cfMapper.SetInputConnection(cf.GetOutputPort()) - cfMapper.SetScalarRange(pl3d_output.GetPointData().GetScalars().GetRange()) - cfActor = vtk.vtkActor() - cfActor.SetMapper(cfMapper) -#outline - outline = vtk.vtkStructuredGridOutlineFilter() - outline.SetInputData(pl3d_output) - outlineMapper = vtk.vtkPolyDataMapper() - outlineMapper.SetInputConnection(outline.GetOutputPort()) - outlineActor = vtk.vtkActor() - outlineActor.SetMapper(outlineMapper) - outlineActor.GetProperty().SetColor(0,0,0) - ## Graphics stuff - # Create the RenderWindow, Renderer and both Actors - # - ren1 = vtk.vtkRenderer() - renWin = vtk.vtkRenderWindow() - renWin.SetMultiSamples(0) - renWin.AddRenderer(ren1) - iren = vtk.vtkRenderWindowInteractor() - iren.SetRenderWindow(renWin) - # Add the actors to the renderer, set the background and size - # - ren1.AddActor(outlineActor) - ren1.AddActor(cfActor) - ren1.SetBackground(1,1,1) - renWin.SetSize(400,400) - cam1 = ren1.GetActiveCamera() - cam1.SetClippingRange(3.95297,50) - cam1.SetFocalPoint(9.71821,0.458166,29.3999) - cam1.SetPosition(2.7439,-37.3196,38.7167) - cam1.SetViewUp(-0.16123,0.264271,0.950876) - iren.Initialize() - # render the image - # - # loop over surfaces - i = 0 - while i < 17: - cf.SetValue(0,expr.expr(globals(), locals(),["min","+","(","i","/","16.0",")*(","max","-","min",")"])) - renWin.Render() - i = i + 1 - - cf.SetValue(0,expr.expr(globals(), locals(),["min","+","(","0.2",")*(","max","-","min",")"])) - renWin.Render() + def testAll(self): + # cut data + pl3d = vtk.vtkMultiBlockPLOT3DReader() + pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") + pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") + pl3d.SetScalarFunctionNumber(100) + pl3d.SetVectorFunctionNumber(202) + pl3d.Update() + pl3d_output = pl3d.GetOutput().GetBlock(0) + + range = pl3d_output.GetPointData().GetScalars().GetRange() + min = range[0] + max = range[1] + value = (min + max) / 2.0 + + # cf = vtk.vtkGridSynchronizedTemplates3D() + cf = vtk.vtkContourFilter() + cf.SetInputData(pl3d_output) + cf.SetValue(0, value) + cf.GenerateTrianglesOff() + cf.Update() + self.failUnlessEqual( + cf.GetOutputDataObject(0).GetNumberOfPoints(), 4674) + self.failUnlessEqual( + cf.GetOutputDataObject(0).GetNumberOfCells(), 4011) + + cf.GenerateTrianglesOn() + cf.Update() + self.failUnlessEqual( + cf.GetOutputDataObject(0).GetNumberOfPoints(), 4674) + self.failUnlessEqual( + cf.GetOutputDataObject(0).GetNumberOfCells(), 8076) + + # cf ComputeNormalsOff + cfMapper = vtk.vtkPolyDataMapper() + cfMapper.ImmediateModeRenderingOn() + cfMapper.SetInputConnection(cf.GetOutputPort()) + cfMapper.SetScalarRange( + pl3d_output.GetPointData().GetScalars().GetRange()) + + cfActor = vtk.vtkActor() + cfActor.SetMapper(cfMapper) + + # outline + outline = vtk.vtkStructuredGridOutlineFilter() + outline.SetInputData(pl3d_output) + + outlineMapper = vtk.vtkPolyDataMapper() + outlineMapper.SetInputConnection(outline.GetOutputPort()) + + outlineActor = vtk.vtkActor() + outlineActor.SetMapper(outlineMapper) + outlineActor.GetProperty().SetColor(0, 0, 0) + + # # Graphics stuff + # Create the RenderWindow, Renderer and both Actors + # + ren1 = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() + renWin.SetMultiSamples(0) + renWin.AddRenderer(ren1) + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) + + # Add the actors to the renderer, set the background and size + # + ren1.AddActor(outlineActor) + ren1.AddActor(cfActor) + ren1.SetBackground(1, 1, 1) + + renWin.SetSize(400, 400) + + cam1 = ren1.GetActiveCamera() + cam1.SetClippingRange(3.95297, 50) + cam1.SetFocalPoint(9.71821, 0.458166, 29.3999) + cam1.SetPosition(2.7439, -37.3196, 38.7167) + cam1.SetViewUp(-0.16123, 0.264271, 0.950876) + iren.Initialize() + + # render the image + # + # loop over surfaces + i = 0 + while i < 17: + cf.SetValue(0, min + (i / 16.0) * (max - min)) + + renWin.Render() + + cf.SetValue(0, min + (0.2) * (max - min)) + + renWin.Render() + + i += 1 + +# iren.Start() if __name__ == "__main__": - Testing.main([(TestGridSynchronizedTemplates3D, 'test')]) + Testing.main([(TestGridSynchronizedTemplates3D, 'test')]) diff --git a/Filters/Core/Testing/Python/TestTensorGlyph.py b/Filters/Core/Testing/Python/TestTensorGlyph.py index e22d7d50598..1a114bad390 100755 --- a/Filters/Core/Testing/Python/TestTensorGlyph.py +++ b/Filters/Core/Testing/Python/TestTensorGlyph.py @@ -12,9 +12,11 @@ class SimpleGlyph: """A simple class used to test vtkTensorGlyph.""" def __init__(self, reader): self.reader = reader + sg = self.src_glyph = vtk.vtkSphereSource() sg.SetRadius(0.5) sg.SetCenter(0.5, 0.0, 0.0) + g = self.glyph = vtk.vtkTensorGlyph() g.SetInputConnection(self.reader.GetOutputPort()) g.SetSourceConnection(self.src_glyph.GetOutputPort()) @@ -24,16 +26,20 @@ class SimpleGlyph: # not used some of the glyphs are black. self.normals = vtk.vtkPolyDataNormals() self.normals.SetInputConnection(g.GetOutputPort()) + self.map = vtk.vtkPolyDataMapper() self.map.SetInputConnection(self.normals.GetOutputPort()) + self.act = vtk.vtkActor() self.act.SetMapper(self.map) # An outline. self.of = vtk.vtkOutlineFilter() self.of.SetInputConnection(self.reader.GetOutputPort()) + self.out_map = vtk.vtkPolyDataMapper() self.out_map.SetInputConnection(self.of.GetOutputPort()) + self.out_act = vtk.vtkActor() self.out_act.SetMapper(self.out_map) @@ -42,6 +48,7 @@ class SimpleGlyph: def Update(self): self.glyph.Update() + s = self.glyph.GetOutput().GetPointData().GetScalars() if s: self.map.SetScalarRange(s.GetRange()) @@ -53,10 +60,11 @@ class SimpleGlyph: class TestTensorGlyph(Testing.vtkTest): def testGlyphs(self): - "Test if the glyphs are created nicely." + '''Test if the glyphs are created nicely.''' reader = vtk.vtkDataSetReader() - data_file = os.path.join(Testing.VTK_DATA_ROOT, "Data", - "tensors.vtk") + + data_file = os.path.join(Testing.VTK_DATA_ROOT, "Data", "tensors.vtk") + reader.SetFileName(data_file) g1 = SimpleGlyph(reader) @@ -87,12 +95,14 @@ class TestTensorGlyph(Testing.vtkTest): ren.AddActor(j) ren.ResetCamera(); + cam = ren.GetActiveCamera() cam.Azimuth(-20) cam.Elevation(20) cam.Zoom(1.5) ren.SetBackground(0.5, 0.5, 0.5) + renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) renWin.Render() diff --git a/Filters/Core/Testing/Python/backdrop.py b/Filters/Core/Testing/Python/backdrop.py new file mode 100644 index 00000000000..77436c43191 --- /dev/null +++ b/Filters/Core/Testing/Python/backdrop.py @@ -0,0 +1,74 @@ +"""this is python equivalent of ./Wrapping/Tcl/vtktesting/backdrop.tcl +This script is used while running python tests translated from Tcl.""" + +import vtk + +basePlane = None +baseMapper = None +base = None + +backPlane = None +backMapper = None +back = None + +leftPlane = None +leftMapper = None +left = None + +def BuildBackdrop (minX, maxX, minY, maxY, minZ, maxZ, thickness): + global basePlane + global baseMapper + global base + global backPlane + global backMapper + global back + global left + global leftPlane + global leftMapper + + if not basePlane: + basePlane = vtk.vtkCubeSource() + basePlane.SetCenter( (maxX + minX)/2.0, minY, (maxZ + minZ)/2.0) + basePlane.SetXLength(maxX-minX) + basePlane.SetYLength(thickness) + basePlane.SetZLength(maxZ - minZ) + + if not baseMapper: + baseMapper = vtk.vtkPolyDataMapper() + baseMapper.SetInputConnection(basePlane.GetOutputPort()) + + if not base: + base = vtk.vtkActor() + base.SetMapper(baseMapper) + + if not backPlane: + backPlane = vtk.vtkCubeSource() + backPlane.SetCenter( (maxX + minX)/2.0, (maxY + minY)/2.0, minZ) + backPlane.SetXLength(maxX-minX) + backPlane.SetYLength(maxY - minY) + backPlane.SetZLength(thickness) + + if not backMapper: + backMapper = vtk.vtkPolyDataMapper() + backMapper.SetInputConnection(backPlane.GetOutputPort()) + + if not back: + back = vtk.vtkActor() + back.SetMapper(backMapper) + + if not leftPlane: + leftPlane = vtk.vtkCubeSource() + leftPlane.SetCenter( minX, (maxY+minY)/2.0, (maxZ+minZ)/2.0) + leftPlane.SetXLength(thickness) + leftPlane.SetYLength(maxY-minY) + leftPlane.SetZLength(maxZ-minZ) + + if not leftMapper: + leftMapper = vtk.vtkPolyDataMapper() + leftMapper.SetInputConnection(leftPlane.GetOutputPort()) + + if not left: + left = vtk.vtkActor() + left.SetMapper(leftMapper) + + return [base, back, left] diff --git a/Filters/Core/Testing/Python/capCow.py b/Filters/Core/Testing/Python/capCow.py index 74cf1d108fe..e04fe01f8c4 100755 --- a/Filters/Core/Testing/Python/capCow.py +++ b/Filters/Core/Testing/Python/capCow.py @@ -4,67 +4,90 @@ 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 + # # Demonstrate the use of clipping and capping on polyhedral data. Also shows how to # use triangle filter to triangulate loops. # + # create pipeline # # Read the polygonal data and generate vertex normals cow = vtk.vtkBYUReader() -cow.SetGeometryFileName("" + str(VTK_DATA_ROOT) + "/Data/Viewpoint/cow.g") +cow.SetGeometryFileName(VTK_DATA_ROOT + "/Data/Viewpoint/cow.g") cowNormals = vtk.vtkPolyDataNormals() cowNormals.SetInputConnection(cow.GetOutputPort()) + # Define a clip plane to clip the cow in half plane = vtk.vtkPlane() -plane.SetOrigin(0.25,0,0) -plane.SetNormal(-1,-1,0) +plane.SetOrigin(0.25, 0, 0) +plane.SetNormal(-1, -1, 0) + clipper = vtk.vtkClipPolyData() clipper.SetInputConnection(cowNormals.GetOutputPort()) clipper.SetClipFunction(plane) clipper.GenerateClipScalarsOn() clipper.GenerateClippedOutputOn() clipper.SetValue(0.5) + clipMapper = vtk.vtkPolyDataMapper() clipMapper.SetInputConnection(clipper.GetOutputPort()) clipMapper.ScalarVisibilityOff() + backProp = vtk.vtkProperty() -backProp.SetDiffuseColor(tomato) +backProp.SetDiffuseColor(GetRGBColor('tomato')) + clipActor = vtk.vtkActor() clipActor.SetMapper(clipMapper) -clipActor.GetProperty().SetColor(peacock) +clipActor.GetProperty().SetColor(GetRGBColor('peacock')) clipActor.SetBackfaceProperty(backProp) + # Create polygons outlining clipped areas and triangulate them to generate cut surface cutEdges = vtk.vtkCutter() -#Generate cut lines +# Generate cut lines cutEdges.SetInputConnection(cowNormals.GetOutputPort()) cutEdges.SetCutFunction(plane) cutEdges.GenerateCutScalarsOn() -cutEdges.SetValue(0,0.5) +cutEdges.SetValue(0, 0.5) cutStrips = vtk.vtkStripper() -#Forms loops (closed polylines) from cutter + +# Forms loops (closed polylines) from cutter cutStrips.SetInputConnection(cutEdges.GetOutputPort()) cutStrips.Update() + cutPoly = vtk.vtkPolyData() -#This trick defines polygons as polyline loop +# This trick defines polygons as polyline loop cutPoly.SetPoints(cutStrips.GetOutput().GetPoints()) cutPoly.SetPolys(cutStrips.GetOutput().GetLines()) + cutTriangles = vtk.vtkTriangleFilter() -#Triangulates the polygons to create cut surface +# Triangulates the polygons to create cut surface cutTriangles.SetInputData(cutPoly) cutMapper = vtk.vtkPolyDataMapper() cutMapper.SetInputData(cutPoly) cutMapper.SetInputConnection(cutTriangles.GetOutputPort()) + cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) -cutActor.GetProperty().SetColor(peacock) +cutActor.GetProperty().SetColor(GetRGBColor('peacock')) + # Create the rest of the cow in wireframe restMapper = vtk.vtkPolyDataMapper() restMapper.SetInputData(clipper.GetClippedOutput()) restMapper.ScalarVisibilityOff() + restActor = vtk.vtkActor() restActor.SetMapper(restMapper) restActor.GetProperty().SetRepresentationToWireframe() + # Create graphics stuff # ren1 = vtk.vtkRenderer() @@ -72,29 +95,32 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size ren1.AddActor(clipActor) ren1.AddActor(cutActor) ren1.AddActor(restActor) -ren1.SetBackground(1,1,1) +ren1.SetBackground(1, 1, 1) ren1.ResetCamera() ren1.GetActiveCamera().Azimuth(30) ren1.GetActiveCamera().Elevation(30) ren1.GetActiveCamera().Dolly(1.5) ren1.ResetCameraClippingRange() -renWin.SetSize(300,300) + +renWin.SetSize(300, 300) + iren.Initialize() + # render the image -# -# prevent the tk window from showing up then start the event loop + # Lets you move the cut plane back and forth -def Cut (v,__vtk__temp0=0,__vtk__temp1=0): +def Cut (v): clipper.SetValue(v) - cutEdges.SetValue(0,v) + cutEdges.SetValue(0, v) cutStrips.Update() cutPoly.SetPoints(cutStrips.GetOutput().GetPoints()) cutPoly.SetPolys(cutStrips.GetOutput().GetLines()) cutMapper.Update() renWin.Render() -# --- end of script -- +# iren.Start() diff --git a/Filters/Core/Testing/Python/capSphere.py b/Filters/Core/Testing/Python/capSphere.py index 312a0338a3a..51ccbb6685d 100755 --- a/Filters/Core/Testing/Python/capSphere.py +++ b/Filters/Core/Testing/Python/capSphere.py @@ -4,54 +4,77 @@ 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 + # # Demonstrate the use of clipping and capping on polyhedral data # + # create a sphere and clip it # sphere = vtk.vtkSphereSource() sphere.SetRadius(1) sphere.SetPhiResolution(10) sphere.SetThetaResolution(10) + plane = vtk.vtkPlane() -plane.SetOrigin(0,0,0) -plane.SetNormal(-1,-1,0) +plane.SetOrigin(0, 0, 0) +plane.SetNormal(-1, -1, 0) + clipper = vtk.vtkClipPolyData() clipper.SetInputConnection(sphere.GetOutputPort()) clipper.SetClipFunction(plane) clipper.GenerateClipScalarsOn() clipper.GenerateClippedOutputOn() clipper.SetValue(0) + clipMapper = vtk.vtkPolyDataMapper() clipMapper.SetInputConnection(clipper.GetOutputPort()) clipMapper.ScalarVisibilityOff() + backProp = vtk.vtkProperty() -backProp.SetDiffuseColor(tomato) +backProp.SetDiffuseColor(GetRGBColor('tomato')) + clipActor = vtk.vtkActor() clipActor.SetMapper(clipMapper) -clipActor.GetProperty().SetColor(peacock) +clipActor.GetProperty().SetColor(GetRGBColor('peacock')) clipActor.SetBackfaceProperty(backProp) + # now extract feature edges boundaryEdges = vtk.vtkFeatureEdges() boundaryEdges.SetInputConnection(clipper.GetOutputPort()) boundaryEdges.BoundaryEdgesOn() boundaryEdges.FeatureEdgesOff() boundaryEdges.NonManifoldEdgesOff() + boundaryClean = vtk.vtkCleanPolyData() boundaryClean.SetInputConnection(boundaryEdges.GetOutputPort()) + boundaryStrips = vtk.vtkStripper() boundaryStrips.SetInputConnection(boundaryClean.GetOutputPort()) boundaryStrips.Update() + boundaryPoly = vtk.vtkPolyData() boundaryPoly.SetPoints(boundaryStrips.GetOutput().GetPoints()) boundaryPoly.SetPolys(boundaryStrips.GetOutput().GetLines()) + boundaryTriangles = vtk.vtkTriangleFilter() boundaryTriangles.SetInputData(boundaryPoly) + boundaryMapper = vtk.vtkPolyDataMapper() boundaryMapper.SetInputConnection(boundaryTriangles.GetOutputPort()) + boundaryActor = vtk.vtkActor() boundaryActor.SetMapper(boundaryMapper) -boundaryActor.GetProperty().SetColor(banana) +boundaryActor.GetProperty().SetColor(GetRGBColor('banana')) + # Create graphics stuff # ren1 = vtk.vtkRenderer() @@ -59,19 +82,19 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(clipActor) ren1.AddActor(boundaryActor) -ren1.SetBackground(1,1,1) +ren1.SetBackground(1, 1, 1) ren1.ResetCamera() ren1.GetActiveCamera().Azimuth(30) ren1.GetActiveCamera().Elevation(30) ren1.GetActiveCamera().Dolly(1.2) ren1.ResetCameraClippingRange() -renWin.SetSize(300,300) + +renWin.SetSize(300, 300) + iren.Initialize() -# render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Core/Testing/Python/clipArt.py b/Filters/Core/Testing/Python/clipArt.py index 711eb92aca4..4defacee48f 100755 --- a/Filters/Core/Testing/Python/clipArt.py +++ b/Filters/Core/Testing/Python/clipArt.py @@ -11,8 +11,9 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + imageIn = vtk.vtkTIFFReader() -imageIn.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/beach.tif") +imageIn.SetFileName(VTK_DATA_ROOT + "/Data/beach.tif") # "beach.tif" image contains ORIENTATION tag which is # ORIENTATION_TOPLEFT (row 0 top, col 0 lhs) type. The TIFF # reader parses this tag and sets the internal TIFF image @@ -20,68 +21,86 @@ imageIn.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/beach.tif") # convention of ORIENTATION_BOTLEFT (row 0 bottom, col 0 lhs ), invoke # SetOrientationType method with parameter value of 4. imageIn.SetOrientationType(4) -imageIn.GetExecutive().SetReleaseDataFlag(0,0) +imageIn.GetExecutive().SetReleaseDataFlag(0, 0) imageIn.Update() -def PowerOfTwo (amt,__vtk__temp0=0,__vtk__temp1=0): + +def PowerOfTwo (amt): + ''' Finds the first power of two >= amt. ''' pow = 0 - amt = amt + -1 - while 1: - amt = expr.expr(globals(), locals(),["amt",">>","1"]) - pow = pow + 1 + amt -= 1 + while True: + amt = amt >> 1 + pow += 1 if (amt <= 0): - return expr.expr(globals(), locals(),["1","<<","pow"]) - pass - - pass + return 1 << pow -orgX = expr.expr(globals(), locals(),["lindex(imageIn.GetExecutive().GetWholeExtent(imageIn.GetOutputInformation(0)),1)","-","lindex(imageIn.GetExecutive().GetWholeExtent(imageIn.GetOutputInformation(0)),0)","+","1"]) -orgY = expr.expr(globals(), locals(),["lindex(imageIn.GetExecutive().GetWholeExtent(imageIn.GetOutputInformation(0)),3)","-","lindex(imageIn.GetExecutive().GetWholeExtent(imageIn.GetOutputInformation(0)),2)","+","1"]) +orgX = imageIn.GetExecutive().GetWholeExtent( + imageIn.GetOutputInformation(0))[1]\ + - imageIn.GetExecutive().GetWholeExtent( + imageIn.GetOutputInformation(0))[0] + 1 +orgY = imageIn.GetExecutive().GetWholeExtent( + imageIn.GetOutputInformation(0))[3]\ + - imageIn.GetExecutive().GetWholeExtent( + imageIn.GetOutputInformation(0))[2] + 1 padX = PowerOfTwo(orgX) padY = PowerOfTwo(orgY) + imagePowerOf2 = vtk.vtkImageConstantPad() imagePowerOf2.SetInputConnection(imageIn.GetOutputPort()) -imagePowerOf2.SetOutputWholeExtent(0,expr.expr(globals(), locals(),["padX","-","1"]),0,expr.expr(globals(), locals(),["padY","-","1"]),0,0) +imagePowerOf2.SetOutputWholeExtent(0, padX - 1, 0, padY - 1, 0, 0) + toHSV = vtk.vtkImageRGBToHSV() toHSV.SetInputConnection(imageIn.GetOutputPort()) -toHSV.GetExecutive().SetReleaseDataFlag(0,0) +toHSV.GetExecutive().SetReleaseDataFlag(0, 0) + extractImage = vtk.vtkImageExtractComponents() extractImage.SetInputConnection(toHSV.GetOutputPort()) extractImage.SetComponents(2) -extractImage.GetExecutive().SetReleaseDataFlag(0,0) +extractImage.GetExecutive().SetReleaseDataFlag(0, 0) + threshold1 = vtk.vtkImageThreshold() threshold1.SetInputConnection(extractImage.GetOutputPort()) threshold1.ThresholdByUpper(230) threshold1.SetInValue(255) threshold1.SetOutValue(0) threshold1.Update() -extent = threshold1.GetExecutive().GetWholeExtent(threshold1.GetOutputInformation(0)) + +extent = threshold1.GetExecutive().GetWholeExtent( + threshold1.GetOutputInformation(0)) + connect = vtk.vtkImageSeedConnectivity() connect.SetInputConnection(threshold1.GetOutputPort()) connect.SetInputConnectValue(255) connect.SetOutputConnectedValue(255) connect.SetOutputUnconnectedValue(0) -connect.AddSeed(lindex(extent,0),lindex(extent,2)) -connect.AddSeed(lindex(extent,1),lindex(extent,2)) -connect.AddSeed(lindex(extent,1),lindex(extent,3)) -connect.AddSeed(lindex(extent,0),lindex(extent,3)) +connect.AddSeed(extent[0], extent[2]) +connect.AddSeed(extent[1], extent[2]) +connect.AddSeed(extent[1], extent[3]) +connect.AddSeed(extent[0], extent[3]) + smooth = vtk.vtkImageGaussianSmooth() smooth.SetDimensionality(2) -smooth.SetStandardDeviation(1,1) +smooth.SetStandardDeviation(1, 1) smooth.SetInputConnection(connect.GetOutputPort()) + shrink = vtk.vtkImageShrink3D() shrink.SetInputConnection(smooth.GetOutputPort()) -shrink.SetShrinkFactors(2,2,1) +shrink.SetShrinkFactors(2, 2, 1) shrink.AveragingOn() + geometry = vtk.vtkImageDataGeometryFilter() geometry.SetInputConnection(shrink.GetOutputPort()) + geometryTexture = vtk.vtkTextureMapToPlane() geometryTexture.SetInputConnection(geometry.GetOutputPort()) -geometryTexture.SetOrigin(0,0,0) -geometryTexture.SetPoint1(expr.expr(globals(), locals(),["padX","-","1"]),0,0) -geometryTexture.SetPoint2(0,expr.expr(globals(), locals(),["padY","-","1"]),0) +geometryTexture.SetOrigin(0, 0, 0) +geometryTexture.SetPoint1(padX - 1, 0, 0) +geometryTexture.SetPoint2(0, padY - 1, 0) + geometryPD = vtk.vtkCastToConcrete() geometryPD.SetInputConnection(geometryTexture.GetOutputPort()) geometryPD.Update() + clip = vtk.vtkClipPolyData() clip.SetInputData(geometryPD.GetPolyDataOutput()) clip.SetValue(5.5) @@ -90,48 +109,62 @@ clip.InsideOutOff() clip.InsideOutOn() clip.GetOutput().GetPointData().CopyScalarsOff() clip.Update() + triangles = vtk.vtkTriangleFilter() triangles.SetInputConnection(clip.GetOutputPort()) + decimate = vtk.vtkDecimatePro() decimate.SetInputConnection(triangles.GetOutputPort()) decimate.BoundaryVertexDeletionOn() decimate.SetDegree(25) decimate.PreserveTopologyOn() + extrude = vtk.vtkLinearExtrusionFilter() extrude.SetInputConnection(decimate.GetOutputPort()) extrude.SetExtrusionType(2) extrude.SetScaleFactor(-20) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(extrude.GetOutputPort()) normals.SetFeatureAngle(80) + strip = vtk.vtkStripper() strip.SetInputConnection(extrude.GetOutputPort()) + map = vtk.vtkPolyDataMapper() map.SetInputConnection(strip.GetOutputPort()) map.SetInputConnection(normals.GetOutputPort()) map.ScalarVisibilityOff() + imageTexture = vtk.vtkTexture() imageTexture.InterpolateOn() imageTexture.SetInputConnection(imagePowerOf2.GetOutputPort()) + clipart = vtk.vtkActor() clipart.SetMapper(map) clipart.SetTexture(imageTexture) + ren1.AddActor(clipart) -clipart.GetProperty().SetDiffuseColor(1,1,1) + +clipart.GetProperty().SetDiffuseColor(1, 1, 1) clipart.GetProperty().SetSpecular(.5) clipart.GetProperty().SetSpecularPower(30) clipart.GetProperty().SetDiffuse(.9) + ren1.ResetCamera() + camera = ren1.GetActiveCamera() camera.Azimuth(30) camera.Elevation(-30) camera.Dolly(1.5) + ren1.ResetCameraClippingRange() -ren1.SetBackground(0.2,0.3,0.4) -renWin.SetSize(320,256) +ren1.SetBackground(0.2, 0.3, 0.4) + +renWin.SetSize(320, 256) + iren.Initialize() + renWin.Render() -# render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Filters/Core/Testing/Python/constrainedDelaunay.py b/Filters/Core/Testing/Python/constrainedDelaunay.py index c58b352ee55..a6f5b9cf3b7 100755 --- a/Filters/Core/Testing/Python/constrainedDelaunay.py +++ b/Filters/Core/Testing/Python/constrainedDelaunay.py @@ -4,50 +4,60 @@ 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 + # Create a constrained Delaunay triangulation (i.e., edges and polygons defined) # Generate the input points and constrained edges/polygons # points = vtk.vtkPoints() -points.InsertPoint(0,1,4,0) -points.InsertPoint(1,3,4,0) -points.InsertPoint(2,7,4,0) -points.InsertPoint(3,11,4,0) -points.InsertPoint(4,13,4,0) -points.InsertPoint(5,13,8,0) -points.InsertPoint(6,13,12,0) -points.InsertPoint(7,10,12,0) -points.InsertPoint(8,7,12,0) -points.InsertPoint(9,4,12,0) -points.InsertPoint(10,1,12,0) -points.InsertPoint(11,1,8,0) -points.InsertPoint(12,3.5,5,0) -points.InsertPoint(13,4.5,5,0) -points.InsertPoint(14,5.5,8,0) -points.InsertPoint(15,6.5,8,0) -points.InsertPoint(16,6.5,5,0) -points.InsertPoint(17,7.5,5,0) -points.InsertPoint(18,7.5,8,0) -points.InsertPoint(19,9,8,0) -points.InsertPoint(20,9,5,0) -points.InsertPoint(21,10,5,0) -points.InsertPoint(22,10,7,0) -points.InsertPoint(23,11,5,0) -points.InsertPoint(24,12,5,0) -points.InsertPoint(25,10.5,8,0) -points.InsertPoint(26,12,11,0) -points.InsertPoint(27,11,11,0) -points.InsertPoint(28,10,9,0) -points.InsertPoint(29,10,11,0) -points.InsertPoint(30,9,11,0) -points.InsertPoint(31,9,9,0) -points.InsertPoint(32,7.5,9,0) -points.InsertPoint(33,7.5,11,0) -points.InsertPoint(34,6.5,11,0) -points.InsertPoint(35,6.5,9,0) -points.InsertPoint(36,5,9,0) -points.InsertPoint(37,4,6,0) -points.InsertPoint(38,3,9,0) -points.InsertPoint(39,2,9,0) +points.InsertPoint(0, 1, 4, 0) +points.InsertPoint(1, 3, 4, 0) +points.InsertPoint(2, 7, 4, 0) +points.InsertPoint(3, 11, 4, 0) +points.InsertPoint(4, 13, 4, 0) +points.InsertPoint(5, 13, 8, 0) +points.InsertPoint(6, 13, 12, 0) +points.InsertPoint(7, 10, 12, 0) +points.InsertPoint(8, 7, 12, 0) +points.InsertPoint(9, 4, 12, 0) +points.InsertPoint(10, 1, 12, 0) +points.InsertPoint(11, 1, 8, 0) +points.InsertPoint(12, 3.5, 5, 0) +points.InsertPoint(13, 4.5, 5, 0) +points.InsertPoint(14, 5.5, 8, 0) +points.InsertPoint(15, 6.5, 8, 0) +points.InsertPoint(16, 6.5, 5, 0) +points.InsertPoint(17, 7.5, 5, 0) +points.InsertPoint(18, 7.5, 8, 0) +points.InsertPoint(19, 9, 8, 0) +points.InsertPoint(20, 9, 5, 0) +points.InsertPoint(21, 10, 5, 0) +points.InsertPoint(22, 10, 7, 0) +points.InsertPoint(23, 11, 5, 0) +points.InsertPoint(24, 12, 5, 0) +points.InsertPoint(25, 10.5, 8, 0) +points.InsertPoint(26, 12, 11, 0) +points.InsertPoint(27, 11, 11, 0) +points.InsertPoint(28, 10, 9, 0) +points.InsertPoint(29, 10, 11, 0) +points.InsertPoint(30, 9, 11, 0) +points.InsertPoint(31, 9, 9, 0) +points.InsertPoint(32, 7.5, 9, 0) +points.InsertPoint(33, 7.5, 11, 0) +points.InsertPoint(34, 6.5, 11, 0) +points.InsertPoint(35, 6.5, 9, 0) +points.InsertPoint(36, 5, 9, 0) +points.InsertPoint(37, 4, 6, 0) +points.InsertPoint(38, 3, 9, 0) +points.InsertPoint(39, 2, 9, 0) + polys = vtk.vtkCellArray() polys.InsertNextCell(12) polys.InsertCellPoint(0) @@ -91,9 +101,11 @@ polys.InsertCellPoint(15) polys.InsertCellPoint(14) polys.InsertCellPoint(13) polys.InsertCellPoint(12) + polyData = vtk.vtkPolyData() polyData.SetPoints(points) polyData.SetPolys(polys) + # triangulate them # del1 = vtk.vtkDelaunay2D() @@ -103,6 +115,7 @@ mapMesh = vtk.vtkPolyDataMapper() mapMesh.SetInputConnection(del1.GetOutputPort()) meshActor = vtk.vtkActor() meshActor.SetMapper(mapMesh) + # tubes around mesh extract = vtk.vtkExtractEdges() extract.SetInputConnection(del1.GetOutputPort()) @@ -114,12 +127,13 @@ mapEdges = vtk.vtkPolyDataMapper() mapEdges.SetInputConnection(tubes.GetOutputPort()) edgeActor = vtk.vtkActor() edgeActor.SetMapper(mapEdges) -edgeActor.GetProperty().SetColor(peacock) -edgeActor.GetProperty().SetSpecularColor(1,1,1) +edgeActor.GetProperty().SetColor(GetRGBColor('peacock')) +edgeActor.GetProperty().SetSpecularColor(1, 1, 1) edgeActor.GetProperty().SetSpecular(0.3) edgeActor.GetProperty().SetSpecularPower(20) edgeActor.GetProperty().SetAmbient(0.2) edgeActor.GetProperty().SetDiffuse(0.8) + # Create graphics objects # Create the rendering window, renderer, and interactive renderer ren1 = vtk.vtkRenderer() @@ -127,15 +141,18 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size ren1.AddActor(meshActor) ren1.AddActor(edgeActor) ren1.ResetCamera() -ren1.SetBackground(0,0,0) -renWin.SetSize(450,300) +ren1.SetBackground(0, 0, 0) + +renWin.SetSize(450, 300) + # render the image # ren1.GetActiveCamera().Zoom(2) + iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Core/Testing/Python/contourCells.py b/Filters/Core/Testing/Python/contourCells.py index 0194457c192..e9b22ad1a2f 100755 --- a/Filters/Core/Testing/Python/contourCells.py +++ b/Filters/Core/Testing/Python/contourCells.py @@ -1,810 +1,1022 @@ #!/usr/bin/env python +import sys import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() +# Prevent .pyc files being created. +# Stops the vtk source being polluted +# by .pyc files. +sys.dont_write_bytecode = True + +import backdrop + # Contour every cell type + # Since some of our actors are a single vertex, we need to remove all # cullers so the single vertex actors will render ren1 = vtk.vtkRenderer() ren1.GetCullers().RemoveAllItems() + renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create a scene with one of each cell type # Voxel voxelPoints = vtk.vtkPoints() voxelPoints.SetNumberOfPoints(8) -voxelPoints.InsertPoint(0,0,0,0) -voxelPoints.InsertPoint(1,1,0,0) -voxelPoints.InsertPoint(2,0,1,0) -voxelPoints.InsertPoint(3,1,1,0) -voxelPoints.InsertPoint(4,0,0,1) -voxelPoints.InsertPoint(5,1,0,1) -voxelPoints.InsertPoint(6,0,1,1) -voxelPoints.InsertPoint(7,1,1,1) +voxelPoints.InsertPoint(0, 0, 0, 0) +voxelPoints.InsertPoint(1, 1, 0, 0) +voxelPoints.InsertPoint(2, 0, 1, 0) +voxelPoints.InsertPoint(3, 1, 1, 0) +voxelPoints.InsertPoint(4, 0, 0, 1) +voxelPoints.InsertPoint(5, 1, 0, 1) +voxelPoints.InsertPoint(6, 0, 1, 1) +voxelPoints.InsertPoint(7, 1, 1, 1) + voxelScalars = vtk.vtkFloatArray() voxelScalars.SetNumberOfTuples(8) -voxelScalars.InsertValue(0,0) -voxelScalars.InsertValue(1,1) -voxelScalars.InsertValue(2,0) -voxelScalars.InsertValue(3,0) -voxelScalars.InsertValue(4,0) -voxelScalars.InsertValue(5,0) -voxelScalars.InsertValue(6,0) -voxelScalars.InsertValue(7,0) +voxelScalars.InsertValue(0, 0) +voxelScalars.InsertValue(1, 1) +voxelScalars.InsertValue(2, 0) +voxelScalars.InsertValue(3, 0) +voxelScalars.InsertValue(4, 0) +voxelScalars.InsertValue(5, 0) +voxelScalars.InsertValue(6, 0) +voxelScalars.InsertValue(7, 0) + aVoxel = vtk.vtkVoxel() -aVoxel.GetPointIds().SetId(0,0) -aVoxel.GetPointIds().SetId(1,1) -aVoxel.GetPointIds().SetId(2,2) -aVoxel.GetPointIds().SetId(3,3) -aVoxel.GetPointIds().SetId(4,4) -aVoxel.GetPointIds().SetId(5,5) -aVoxel.GetPointIds().SetId(6,6) -aVoxel.GetPointIds().SetId(7,7) +aVoxel.GetPointIds().SetId(0, 0) +aVoxel.GetPointIds().SetId(1, 1) +aVoxel.GetPointIds().SetId(2, 2) +aVoxel.GetPointIds().SetId(3, 3) +aVoxel.GetPointIds().SetId(4, 4) +aVoxel.GetPointIds().SetId(5, 5) +aVoxel.GetPointIds().SetId(6, 6) +aVoxel.GetPointIds().SetId(7, 7) + aVoxelGrid = vtk.vtkUnstructuredGrid() -aVoxelGrid.Allocate(1,1) -aVoxelGrid.InsertNextCell(aVoxel.GetCellType(),aVoxel.GetPointIds()) +aVoxelGrid.Allocate(1, 1) +aVoxelGrid.InsertNextCell(aVoxel.GetCellType(), aVoxel.GetPointIds()) aVoxelGrid.SetPoints(voxelPoints) aVoxelGrid.GetPointData().SetScalars(voxelScalars) + voxelContours = vtk.vtkContourFilter() voxelContours.SetInputData(aVoxelGrid) -voxelContours.SetValue(0,.5) +voxelContours.SetValue(0, .5) + aVoxelContourMapper = vtk.vtkDataSetMapper() aVoxelContourMapper.SetInputConnection(voxelContours.GetOutputPort()) aVoxelContourMapper.ScalarVisibilityOff() + aVoxelMapper = vtk.vtkDataSetMapper() aVoxelMapper.SetInputData(aVoxelGrid) aVoxelMapper.ScalarVisibilityOff() + aVoxelActor = vtk.vtkActor() aVoxelActor.SetMapper(aVoxelMapper) aVoxelActor.GetProperty().SetRepresentationToWireframe() + aVoxelContourActor = vtk.vtkActor() aVoxelContourActor.SetMapper(aVoxelContourMapper) aVoxelContourActor.GetProperty().BackfaceCullingOn() + # Hexahedron + hexahedronPoints = vtk.vtkPoints() hexahedronPoints.SetNumberOfPoints(8) -hexahedronPoints.InsertPoint(0,0,0,0) -hexahedronPoints.InsertPoint(1,1,0,0) -hexahedronPoints.InsertPoint(2,1,1,0) -hexahedronPoints.InsertPoint(3,0,1,0) -hexahedronPoints.InsertPoint(4,0,0,1) -hexahedronPoints.InsertPoint(5,1,0,1) -hexahedronPoints.InsertPoint(6,1,1,1) -hexahedronPoints.InsertPoint(7,0,1,1) +hexahedronPoints.InsertPoint(0, 0, 0, 0) +hexahedronPoints.InsertPoint(1, 1, 0, 0) +hexahedronPoints.InsertPoint(2, 1, 1, 0) +hexahedronPoints.InsertPoint(3, 0, 1, 0) +hexahedronPoints.InsertPoint(4, 0, 0, 1) +hexahedronPoints.InsertPoint(5, 1, 0, 1) +hexahedronPoints.InsertPoint(6, 1, 1, 1) +hexahedronPoints.InsertPoint(7, 0, 1, 1) + hexahedronScalars = vtk.vtkFloatArray() hexahedronScalars.SetNumberOfTuples(8) -hexahedronScalars.InsertValue(0,0) -hexahedronScalars.InsertValue(1,1) -hexahedronScalars.InsertValue(2,0) -hexahedronScalars.InsertValue(3,0) -hexahedronScalars.InsertValue(4,0) -hexahedronScalars.InsertValue(5,0) -hexahedronScalars.InsertValue(6,0) -hexahedronScalars.InsertValue(7,0) +hexahedronScalars.InsertValue(0, 0) +hexahedronScalars.InsertValue(1, 1) +hexahedronScalars.InsertValue(2, 0) +hexahedronScalars.InsertValue(3, 0) +hexahedronScalars.InsertValue(4, 0) +hexahedronScalars.InsertValue(5, 0) +hexahedronScalars.InsertValue(6, 0) +hexahedronScalars.InsertValue(7, 0) + aHexahedron = vtk.vtkHexahedron() -aHexahedron.GetPointIds().SetId(0,0) -aHexahedron.GetPointIds().SetId(1,1) -aHexahedron.GetPointIds().SetId(2,2) -aHexahedron.GetPointIds().SetId(3,3) -aHexahedron.GetPointIds().SetId(4,4) -aHexahedron.GetPointIds().SetId(5,5) -aHexahedron.GetPointIds().SetId(6,6) -aHexahedron.GetPointIds().SetId(7,7) +aHexahedron.GetPointIds().SetId(0, 0) +aHexahedron.GetPointIds().SetId(1, 1) +aHexahedron.GetPointIds().SetId(2, 2) +aHexahedron.GetPointIds().SetId(3, 3) +aHexahedron.GetPointIds().SetId(4, 4) +aHexahedron.GetPointIds().SetId(5, 5) +aHexahedron.GetPointIds().SetId(6, 6) +aHexahedron.GetPointIds().SetId(7, 7) + aHexahedronGrid = vtk.vtkUnstructuredGrid() -aHexahedronGrid.Allocate(1,1) -aHexahedronGrid.InsertNextCell(aHexahedron.GetCellType(),aHexahedron.GetPointIds()) +aHexahedronGrid.Allocate(1, 1) +aHexahedronGrid.InsertNextCell(aHexahedron.GetCellType(), aHexahedron.GetPointIds()) aHexahedronGrid.SetPoints(hexahedronPoints) aHexahedronGrid.GetPointData().SetScalars(hexahedronScalars) + hexahedronContours = vtk.vtkContourFilter() hexahedronContours.SetInputData(aHexahedronGrid) -hexahedronContours.SetValue(0,.5) +hexahedronContours.SetValue(0, .5) + aHexahedronContourMapper = vtk.vtkDataSetMapper() aHexahedronContourMapper.SetInputConnection(hexahedronContours.GetOutputPort()) aHexahedronContourMapper.ScalarVisibilityOff() + aHexahedronMapper = vtk.vtkDataSetMapper() aHexahedronMapper.SetInputData(aHexahedronGrid) aHexahedronMapper.ScalarVisibilityOff() + aHexahedronActor = vtk.vtkActor() aHexahedronActor.SetMapper(aHexahedronMapper) aHexahedronActor.GetProperty().BackfaceCullingOn() aHexahedronActor.GetProperty().SetRepresentationToWireframe() + aHexahedronContourActor = vtk.vtkActor() aHexahedronContourActor.SetMapper(aHexahedronContourMapper) aHexahedronContourActor.GetProperty().BackfaceCullingOn() + # Tetra + tetraPoints = vtk.vtkPoints() tetraPoints.SetNumberOfPoints(4) -tetraPoints.InsertPoint(0,0,0,0) -tetraPoints.InsertPoint(1,1,0,0) -tetraPoints.InsertPoint(2,.5,1,0) -tetraPoints.InsertPoint(3,.5,.5,1) +tetraPoints.InsertPoint(0, 0, 0, 0) +tetraPoints.InsertPoint(1, 1, 0, 0) +tetraPoints.InsertPoint(2, .5, 1, 0) +tetraPoints.InsertPoint(3, .5, .5, 1) + tetraScalars = vtk.vtkFloatArray() tetraScalars.SetNumberOfTuples(4) -tetraScalars.InsertValue(0,1) -tetraScalars.InsertValue(1,0) -tetraScalars.InsertValue(2,0) -tetraScalars.InsertValue(3,0) +tetraScalars.InsertValue(0, 1) +tetraScalars.InsertValue(1, 0) +tetraScalars.InsertValue(2, 0) +tetraScalars.InsertValue(3, 0) + aTetra = vtk.vtkTetra() -aTetra.GetPointIds().SetId(0,0) -aTetra.GetPointIds().SetId(1,1) -aTetra.GetPointIds().SetId(2,2) -aTetra.GetPointIds().SetId(3,3) +aTetra.GetPointIds().SetId(0, 0) +aTetra.GetPointIds().SetId(1, 1) +aTetra.GetPointIds().SetId(2, 2) +aTetra.GetPointIds().SetId(3, 3) + aTetraGrid = vtk.vtkUnstructuredGrid() -aTetraGrid.Allocate(1,1) -aTetraGrid.InsertNextCell(aTetra.GetCellType(),aTetra.GetPointIds()) +aTetraGrid.Allocate(1, 1) +aTetraGrid.InsertNextCell(aTetra.GetCellType(), aTetra.GetPointIds()) aTetraGrid.SetPoints(tetraPoints) aTetraGrid.GetPointData().SetScalars(tetraScalars) + tetraContours = vtk.vtkContourFilter() tetraContours.SetInputData(aTetraGrid) -tetraContours.SetValue(0,.5) +tetraContours.SetValue(0, .5) + aTetraContourMapper = vtk.vtkDataSetMapper() aTetraContourMapper.SetInputConnection(tetraContours.GetOutputPort()) aTetraContourMapper.ScalarVisibilityOff() + aTetraMapper = vtk.vtkDataSetMapper() aTetraMapper.SetInputData(aTetraGrid) aTetraMapper.ScalarVisibilityOff() + aTetraContourActor = vtk.vtkActor() aTetraContourActor.SetMapper(aTetraContourMapper) + aTetraActor = vtk.vtkActor() aTetraActor.SetMapper(aTetraMapper) aTetraActor.GetProperty().SetRepresentationToWireframe() + # Wedge + wedgePoints = vtk.vtkPoints() wedgePoints.SetNumberOfPoints(6) -wedgePoints.InsertPoint(0,0,1,0) -wedgePoints.InsertPoint(1,0,0,0) -wedgePoints.InsertPoint(2,0,.5,.5) -wedgePoints.InsertPoint(3,1,1,0) -wedgePoints.InsertPoint(4,1,0,0) -wedgePoints.InsertPoint(5,1,.5,.5) +wedgePoints.InsertPoint(0, 0, 1, 0) +wedgePoints.InsertPoint(1, 0, 0, 0) +wedgePoints.InsertPoint(2, 0, .5, .5) +wedgePoints.InsertPoint(3, 1, 1, 0) +wedgePoints.InsertPoint(4, 1, 0, 0) +wedgePoints.InsertPoint(5, 1, .5, .5) + wedgeScalars = vtk.vtkFloatArray() wedgeScalars.SetNumberOfTuples(6) -wedgeScalars.InsertValue(0,1) -wedgeScalars.InsertValue(1,1) -wedgeScalars.InsertValue(2,0) -wedgeScalars.InsertValue(3,1) -wedgeScalars.InsertValue(4,1) -wedgeScalars.InsertValue(5,0) +wedgeScalars.InsertValue(0, 1) +wedgeScalars.InsertValue(1, 1) +wedgeScalars.InsertValue(2, 0) +wedgeScalars.InsertValue(3, 1) +wedgeScalars.InsertValue(4, 1) +wedgeScalars.InsertValue(5, 0) + aWedge = vtk.vtkWedge() -aWedge.GetPointIds().SetId(0,0) -aWedge.GetPointIds().SetId(1,1) -aWedge.GetPointIds().SetId(2,2) -aWedge.GetPointIds().SetId(3,3) -aWedge.GetPointIds().SetId(4,4) -aWedge.GetPointIds().SetId(5,5) +aWedge.GetPointIds().SetId(0, 0) +aWedge.GetPointIds().SetId(1, 1) +aWedge.GetPointIds().SetId(2, 2) +aWedge.GetPointIds().SetId(3, 3) +aWedge.GetPointIds().SetId(4, 4) +aWedge.GetPointIds().SetId(5, 5) + aWedgeGrid = vtk.vtkUnstructuredGrid() -aWedgeGrid.Allocate(1,1) -aWedgeGrid.InsertNextCell(aWedge.GetCellType(),aWedge.GetPointIds()) +aWedgeGrid.Allocate(1, 1) +aWedgeGrid.InsertNextCell(aWedge.GetCellType(), aWedge.GetPointIds()) aWedgeGrid.SetPoints(wedgePoints) aWedgeGrid.GetPointData().SetScalars(wedgeScalars) + wedgeContours = vtk.vtkContourFilter() wedgeContours.SetInputData(aWedgeGrid) -wedgeContours.SetValue(0,.5) +wedgeContours.SetValue(0, .5) + aWedgeContourMapper = vtk.vtkDataSetMapper() aWedgeContourMapper.SetInputConnection(wedgeContours.GetOutputPort()) aWedgeContourMapper.ScalarVisibilityOff() + aWedgeMapper = vtk.vtkDataSetMapper() aWedgeMapper.SetInputData(aWedgeGrid) aWedgeMapper.ScalarVisibilityOff() + aWedgeContourActor = vtk.vtkActor() aWedgeContourActor.SetMapper(aWedgeContourMapper) + aWedgeActor = vtk.vtkActor() aWedgeActor.SetMapper(aWedgeMapper) aWedgeActor.GetProperty().SetRepresentationToWireframe() + # Pyramid + pyramidPoints = vtk.vtkPoints() pyramidPoints.SetNumberOfPoints(5) -pyramidPoints.InsertPoint(0,0,0,0) -pyramidPoints.InsertPoint(1,1,0,0) -pyramidPoints.InsertPoint(2,1,1,0) -pyramidPoints.InsertPoint(3,0,1,0) -pyramidPoints.InsertPoint(4,.5,.5,1) +pyramidPoints.InsertPoint(0, 0, 0, 0) +pyramidPoints.InsertPoint(1, 1, 0, 0) +pyramidPoints.InsertPoint(2, 1, 1, 0) +pyramidPoints.InsertPoint(3, 0, 1, 0) +pyramidPoints.InsertPoint(4, .5, .5, 1) + pyramidScalars = vtk.vtkFloatArray() pyramidScalars.SetNumberOfTuples(5) -pyramidScalars.InsertValue(0,1) -pyramidScalars.InsertValue(1,1) -pyramidScalars.InsertValue(2,1) -pyramidScalars.InsertValue(3,1) -pyramidScalars.InsertValue(4,0) +pyramidScalars.InsertValue(0, 1) +pyramidScalars.InsertValue(1, 1) +pyramidScalars.InsertValue(2, 1) +pyramidScalars.InsertValue(3, 1) +pyramidScalars.InsertValue(4, 0) + aPyramid = vtk.vtkPyramid() -aPyramid.GetPointIds().SetId(0,0) -aPyramid.GetPointIds().SetId(1,1) -aPyramid.GetPointIds().SetId(2,2) -aPyramid.GetPointIds().SetId(3,3) -aPyramid.GetPointIds().SetId(4,4) +aPyramid.GetPointIds().SetId(0, 0) +aPyramid.GetPointIds().SetId(1, 1) +aPyramid.GetPointIds().SetId(2, 2) +aPyramid.GetPointIds().SetId(3, 3) +aPyramid.GetPointIds().SetId(4, 4) + aPyramidGrid = vtk.vtkUnstructuredGrid() -aPyramidGrid.Allocate(1,1) -aPyramidGrid.InsertNextCell(aPyramid.GetCellType(),aPyramid.GetPointIds()) +aPyramidGrid.Allocate(1, 1) +aPyramidGrid.InsertNextCell(aPyramid.GetCellType(), aPyramid.GetPointIds()) aPyramidGrid.SetPoints(pyramidPoints) aPyramidGrid.GetPointData().SetScalars(pyramidScalars) + pyramidContours = vtk.vtkContourFilter() pyramidContours.SetInputData(aPyramidGrid) -pyramidContours.SetValue(0,.5) +pyramidContours.SetValue(0, .5) + aPyramidContourMapper = vtk.vtkDataSetMapper() aPyramidContourMapper.SetInputConnection(pyramidContours.GetOutputPort()) aPyramidContourMapper.ScalarVisibilityOff() + aPyramidMapper = vtk.vtkDataSetMapper() aPyramidMapper.SetInputData(aPyramidGrid) aPyramidMapper.ScalarVisibilityOff() + aPyramidContourActor = vtk.vtkActor() aPyramidContourActor.SetMapper(aPyramidContourMapper) + aPyramidActor = vtk.vtkActor() aPyramidActor.SetMapper(aPyramidMapper) aPyramidActor.GetProperty().SetRepresentationToWireframe() + # Pixel + pixelPoints = vtk.vtkPoints() pixelPoints.SetNumberOfPoints(4) -pixelPoints.InsertPoint(0,0,0,0) -pixelPoints.InsertPoint(1,1,0,0) -pixelPoints.InsertPoint(2,0,1,0) -pixelPoints.InsertPoint(3,1,1,0) +pixelPoints.InsertPoint(0, 0, 0, 0) +pixelPoints.InsertPoint(1, 1, 0, 0) +pixelPoints.InsertPoint(2, 0, 1, 0) +pixelPoints.InsertPoint(3, 1, 1, 0) + pixelScalars = vtk.vtkFloatArray() pixelScalars.SetNumberOfTuples(4) -pixelScalars.InsertValue(0,1) -pixelScalars.InsertValue(1,0) -pixelScalars.InsertValue(2,0) -pixelScalars.InsertValue(3,0) +pixelScalars.InsertValue(0, 1) +pixelScalars.InsertValue(1, 0) +pixelScalars.InsertValue(2, 0) +pixelScalars.InsertValue(3, 0) + aPixel = vtk.vtkPixel() -aPixel.GetPointIds().SetId(0,0) -aPixel.GetPointIds().SetId(1,1) -aPixel.GetPointIds().SetId(2,2) -aPixel.GetPointIds().SetId(3,3) +aPixel.GetPointIds().SetId(0, 0) +aPixel.GetPointIds().SetId(1, 1) +aPixel.GetPointIds().SetId(2, 2) +aPixel.GetPointIds().SetId(3, 3) + aPixelGrid = vtk.vtkUnstructuredGrid() -aPixelGrid.Allocate(1,1) -aPixelGrid.InsertNextCell(aPixel.GetCellType(),aPixel.GetPointIds()) +aPixelGrid.Allocate(1, 1) +aPixelGrid.InsertNextCell(aPixel.GetCellType(), aPixel.GetPointIds()) aPixelGrid.SetPoints(pixelPoints) aPixelGrid.GetPointData().SetScalars(pixelScalars) + pixelContours = vtk.vtkContourFilter() pixelContours.SetInputData(aPixelGrid) -pixelContours.SetValue(0,.5) +pixelContours.SetValue(0, .5) + aPixelContourMapper = vtk.vtkDataSetMapper() aPixelContourMapper.SetInputConnection(pixelContours.GetOutputPort()) aPixelContourMapper.ScalarVisibilityOff() + aPixelMapper = vtk.vtkDataSetMapper() aPixelMapper.SetInputData(aPixelGrid) aPixelMapper.ScalarVisibilityOff() + aPixelContourActor = vtk.vtkActor() aPixelContourActor.SetMapper(aPixelContourMapper) + aPixelActor = vtk.vtkActor() aPixelActor.SetMapper(aPixelMapper) aPixelActor.GetProperty().BackfaceCullingOn() aPixelActor.GetProperty().SetRepresentationToWireframe() + # Quad + quadPoints = vtk.vtkPoints() quadPoints.SetNumberOfPoints(4) -quadPoints.InsertPoint(0,0,0,0) -quadPoints.InsertPoint(1,1,0,0) -quadPoints.InsertPoint(2,1,1,0) -quadPoints.InsertPoint(3,0,1,0) +quadPoints.InsertPoint(0, 0, 0, 0) +quadPoints.InsertPoint(1, 1, 0, 0) +quadPoints.InsertPoint(2, 1, 1, 0) +quadPoints.InsertPoint(3, 0, 1, 0) + quadScalars = vtk.vtkFloatArray() quadScalars.SetNumberOfTuples(4) -quadScalars.InsertValue(0,1) -quadScalars.InsertValue(1,0) -quadScalars.InsertValue(2,0) -quadScalars.InsertValue(3,0) +quadScalars.InsertValue(0, 1) +quadScalars.InsertValue(1, 0) +quadScalars.InsertValue(2, 0) +quadScalars.InsertValue(3, 0) + aQuad = vtk.vtkQuad() -aQuad.GetPointIds().SetId(0,0) -aQuad.GetPointIds().SetId(1,1) -aQuad.GetPointIds().SetId(2,2) -aQuad.GetPointIds().SetId(3,3) +aQuad.GetPointIds().SetId(0, 0) +aQuad.GetPointIds().SetId(1, 1) +aQuad.GetPointIds().SetId(2, 2) +aQuad.GetPointIds().SetId(3, 3) + aQuadGrid = vtk.vtkUnstructuredGrid() -aQuadGrid.Allocate(1,1) -aQuadGrid.InsertNextCell(aQuad.GetCellType(),aQuad.GetPointIds()) +aQuadGrid.Allocate(1, 1) +aQuadGrid.InsertNextCell(aQuad.GetCellType(), aQuad.GetPointIds()) aQuadGrid.SetPoints(quadPoints) aQuadGrid.GetPointData().SetScalars(quadScalars) + quadContours = vtk.vtkContourFilter() quadContours.SetInputData(aQuadGrid) -quadContours.SetValue(0,.5) +quadContours.SetValue(0, .5) + aQuadContourMapper = vtk.vtkDataSetMapper() aQuadContourMapper.SetInputConnection(quadContours.GetOutputPort()) aQuadContourMapper.ScalarVisibilityOff() + aQuadMapper = vtk.vtkDataSetMapper() aQuadMapper.SetInputData(aQuadGrid) aQuadMapper.ScalarVisibilityOff() + aQuadContourActor = vtk.vtkActor() aQuadContourActor.SetMapper(aQuadContourMapper) + aQuadActor = vtk.vtkActor() aQuadActor.SetMapper(aQuadMapper) aQuadActor.GetProperty().BackfaceCullingOn() aQuadActor.GetProperty().SetRepresentationToWireframe() + # Triangle + trianglePoints = vtk.vtkPoints() trianglePoints.SetNumberOfPoints(3) -trianglePoints.InsertPoint(0,0,0,0) -trianglePoints.InsertPoint(1,1,0,0) -trianglePoints.InsertPoint(2,.5,.5,0) +trianglePoints.InsertPoint(0, 0, 0, 0) +trianglePoints.InsertPoint(1, 1, 0, 0) +trianglePoints.InsertPoint(2, .5, .5, 0) + triangleScalars = vtk.vtkFloatArray() triangleScalars.SetNumberOfTuples(3) -triangleScalars.InsertValue(0,1) -triangleScalars.InsertValue(1,0) -triangleScalars.InsertValue(2,0) +triangleScalars.InsertValue(0, 1) +triangleScalars.InsertValue(1, 0) +triangleScalars.InsertValue(2, 0) + aTriangle = vtk.vtkTriangle() -aTriangle.GetPointIds().SetId(0,0) -aTriangle.GetPointIds().SetId(1,1) -aTriangle.GetPointIds().SetId(2,2) +aTriangle.GetPointIds().SetId(0, 0) +aTriangle.GetPointIds().SetId(1, 1) +aTriangle.GetPointIds().SetId(2, 2) + aTriangleGrid = vtk.vtkUnstructuredGrid() -aTriangleGrid.Allocate(1,1) -aTriangleGrid.InsertNextCell(aTriangle.GetCellType(),aTriangle.GetPointIds()) +aTriangleGrid.Allocate(1, 1) +aTriangleGrid.InsertNextCell(aTriangle.GetCellType(), aTriangle.GetPointIds()) aTriangleGrid.SetPoints(trianglePoints) aTriangleGrid.GetPointData().SetScalars(triangleScalars) + triangleContours = vtk.vtkContourFilter() triangleContours.SetInputData(aTriangleGrid) -triangleContours.SetValue(0,.5) +triangleContours.SetValue(0, .5) + aTriangleContourMapper = vtk.vtkDataSetMapper() aTriangleContourMapper.SetInputConnection(triangleContours.GetOutputPort()) aTriangleContourMapper.ScalarVisibilityOff() + aTriangleContourActor = vtk.vtkActor() aTriangleContourActor.SetMapper(aTriangleContourMapper) + aTriangleMapper = vtk.vtkDataSetMapper() aTriangleMapper.SetInputData(aTriangleGrid) aTriangleMapper.ScalarVisibilityOff() + aTriangleActor = vtk.vtkActor() aTriangleActor.SetMapper(aTriangleMapper) aTriangleActor.GetProperty().BackfaceCullingOn() aTriangleActor.GetProperty().SetRepresentationToWireframe() + # Polygon + polygonPoints = vtk.vtkPoints() polygonPoints.SetNumberOfPoints(4) -polygonPoints.InsertPoint(0,0,0,0) -polygonPoints.InsertPoint(1,1,0,0) -polygonPoints.InsertPoint(2,1,1,0) -polygonPoints.InsertPoint(3,0,1,0) +polygonPoints.InsertPoint(0, 0, 0, 0) +polygonPoints.InsertPoint(1, 1, 0, 0) +polygonPoints.InsertPoint(2, 1, 1, 0) +polygonPoints.InsertPoint(3, 0, 1, 0) + polygonScalars = vtk.vtkFloatArray() polygonScalars.SetNumberOfTuples(4) -polygonScalars.InsertValue(0,1) -polygonScalars.InsertValue(1,0) -polygonScalars.InsertValue(2,0) -polygonScalars.InsertValue(3,0) +polygonScalars.InsertValue(0, 1) +polygonScalars.InsertValue(1, 0) +polygonScalars.InsertValue(2, 0) +polygonScalars.InsertValue(3, 0) + aPolygon = vtk.vtkPolygon() aPolygon.GetPointIds().SetNumberOfIds(4) -aPolygon.GetPointIds().SetId(0,0) -aPolygon.GetPointIds().SetId(1,1) -aPolygon.GetPointIds().SetId(2,2) -aPolygon.GetPointIds().SetId(3,3) +aPolygon.GetPointIds().SetId(0, 0) +aPolygon.GetPointIds().SetId(1, 1) +aPolygon.GetPointIds().SetId(2, 2) +aPolygon.GetPointIds().SetId(3, 3) + aPolygonGrid = vtk.vtkUnstructuredGrid() -aPolygonGrid.Allocate(1,1) -aPolygonGrid.InsertNextCell(aPolygon.GetCellType(),aPolygon.GetPointIds()) +aPolygonGrid.Allocate(1, 1) +aPolygonGrid.InsertNextCell(aPolygon.GetCellType(), aPolygon.GetPointIds()) aPolygonGrid.SetPoints(polygonPoints) aPolygonGrid.GetPointData().SetScalars(polygonScalars) + polygonContours = vtk.vtkContourFilter() polygonContours.SetInputData(aPolygonGrid) -polygonContours.SetValue(0,.5) +polygonContours.SetValue(0, .5) + aPolygonContourMapper = vtk.vtkDataSetMapper() aPolygonContourMapper.SetInputConnection(polygonContours.GetOutputPort()) aPolygonContourMapper.ScalarVisibilityOff() + aPolygonMapper = vtk.vtkDataSetMapper() aPolygonMapper.SetInputData(aPolygonGrid) aPolygonMapper.ScalarVisibilityOff() + aPolygonContourActor = vtk.vtkActor() aPolygonContourActor.SetMapper(aPolygonContourMapper) + aPolygonActor = vtk.vtkActor() aPolygonActor.SetMapper(aPolygonMapper) aPolygonActor.GetProperty().BackfaceCullingOn() aPolygonActor.GetProperty().SetRepresentationToWireframe() + # Triangle strip + triangleStripPoints = vtk.vtkPoints() triangleStripPoints.SetNumberOfPoints(5) -triangleStripPoints.InsertPoint(0,0,1,0) -triangleStripPoints.InsertPoint(1,0,0,0) -triangleStripPoints.InsertPoint(2,1,1,0) -triangleStripPoints.InsertPoint(3,1,0,0) -triangleStripPoints.InsertPoint(4,2,1,0) +triangleStripPoints.InsertPoint(0, 0, 1, 0) +triangleStripPoints.InsertPoint(1, 0, 0, 0) +triangleStripPoints.InsertPoint(2, 1, 1, 0) +triangleStripPoints.InsertPoint(3, 1, 0, 0) +triangleStripPoints.InsertPoint(4, 2, 1, 0) + triangleStripScalars = vtk.vtkFloatArray() triangleStripScalars.SetNumberOfTuples(5) -triangleStripScalars.InsertValue(0,1) -triangleStripScalars.InsertValue(1,0) -triangleStripScalars.InsertValue(2,0) -triangleStripScalars.InsertValue(3,0) -triangleStripScalars.InsertValue(4,0) +triangleStripScalars.InsertValue(0, 1) +triangleStripScalars.InsertValue(1, 0) +triangleStripScalars.InsertValue(2, 0) +triangleStripScalars.InsertValue(3, 0) +triangleStripScalars.InsertValue(4, 0) + aTriangleStrip = vtk.vtkTriangleStrip() aTriangleStrip.GetPointIds().SetNumberOfIds(5) -aTriangleStrip.GetPointIds().SetId(0,0) -aTriangleStrip.GetPointIds().SetId(1,1) -aTriangleStrip.GetPointIds().SetId(2,2) -aTriangleStrip.GetPointIds().SetId(3,3) -aTriangleStrip.GetPointIds().SetId(4,4) +aTriangleStrip.GetPointIds().SetId(0, 0) +aTriangleStrip.GetPointIds().SetId(1, 1) +aTriangleStrip.GetPointIds().SetId(2, 2) +aTriangleStrip.GetPointIds().SetId(3, 3) +aTriangleStrip.GetPointIds().SetId(4, 4) + aTriangleStripGrid = vtk.vtkUnstructuredGrid() -aTriangleStripGrid.Allocate(1,1) -aTriangleStripGrid.InsertNextCell(aTriangleStrip.GetCellType(),aTriangleStrip.GetPointIds()) +aTriangleStripGrid.Allocate(1, 1) +aTriangleStripGrid.InsertNextCell(aTriangleStrip.GetCellType(), aTriangleStrip.GetPointIds()) aTriangleStripGrid.SetPoints(triangleStripPoints) aTriangleStripGrid.GetPointData().SetScalars(triangleStripScalars) + aTriangleStripMapper = vtk.vtkDataSetMapper() aTriangleStripMapper.SetInputData(aTriangleStripGrid) aTriangleStripMapper.ScalarVisibilityOff() + triangleStripContours = vtk.vtkContourFilter() triangleStripContours.SetInputData(aTriangleStripGrid) -triangleStripContours.SetValue(0,.5) +triangleStripContours.SetValue(0, .5) + aTriangleStripContourMapper = vtk.vtkDataSetMapper() aTriangleStripContourMapper.SetInputConnection(triangleStripContours.GetOutputPort()) aTriangleStripContourMapper.ScalarVisibilityOff() + aTriangleStripContourActor = vtk.vtkActor() aTriangleStripContourActor.SetMapper(aTriangleStripContourMapper) + aTriangleStripActor = vtk.vtkActor() aTriangleStripActor.SetMapper(aTriangleStripMapper) aTriangleStripActor.GetProperty().BackfaceCullingOn() aTriangleStripActor.GetProperty().SetRepresentationToWireframe() + # Line + linePoints = vtk.vtkPoints() linePoints.SetNumberOfPoints(2) -linePoints.InsertPoint(0,0,0,0) -linePoints.InsertPoint(1,1,1,0) +linePoints.InsertPoint(0, 0, 0, 0) +linePoints.InsertPoint(1, 1, 1, 0) lineScalars = vtk.vtkFloatArray() lineScalars.SetNumberOfTuples(2) -lineScalars.InsertValue(0,1) -lineScalars.InsertValue(1,0) +lineScalars.InsertValue(0, 1) +lineScalars.InsertValue(1, 0) + aLine = vtk.vtkLine() -aLine.GetPointIds().SetId(0,0) -aLine.GetPointIds().SetId(1,1) +aLine.GetPointIds().SetId(0, 0) +aLine.GetPointIds().SetId(1, 1) aLineGrid = vtk.vtkUnstructuredGrid() -aLineGrid.Allocate(1,1) -aLineGrid.InsertNextCell(aLine.GetCellType(),aLine.GetPointIds()) + +aLineGrid.Allocate(1, 1) +aLineGrid.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds()) aLineGrid.SetPoints(linePoints) aLineGrid.GetPointData().SetScalars(lineScalars) + lineContours = vtk.vtkContourFilter() lineContours.SetInputData(aLineGrid) -lineContours.SetValue(0,.5) +lineContours.SetValue(0, .5) + aLineContourMapper = vtk.vtkDataSetMapper() aLineContourMapper.SetInputConnection(lineContours.GetOutputPort()) aLineContourMapper.ScalarVisibilityOff() + aLineContourActor = vtk.vtkActor() aLineContourActor.SetMapper(aLineContourMapper) + aLineMapper = vtk.vtkDataSetMapper() aLineMapper.SetInputData(aLineGrid) aLineMapper.ScalarVisibilityOff() + aLineActor = vtk.vtkActor() aLineActor.SetMapper(aLineMapper) aLineActor.GetProperty().BackfaceCullingOn() aLineActor.GetProperty().SetRepresentationToWireframe() + # Polyline + polyLinePoints = vtk.vtkPoints() polyLinePoints.SetNumberOfPoints(3) -polyLinePoints.InsertPoint(0,0,0,0) -polyLinePoints.InsertPoint(1,1,1,0) -polyLinePoints.InsertPoint(2,1,0,0) +polyLinePoints.InsertPoint(0, 0, 0, 0) +polyLinePoints.InsertPoint(1, 1, 1, 0) +polyLinePoints.InsertPoint(2, 1, 0, 0) + polyLineScalars = vtk.vtkFloatArray() polyLineScalars.SetNumberOfTuples(3) -polyLineScalars.InsertValue(0,1) -polyLineScalars.InsertValue(1,0) -polyLineScalars.InsertValue(2,0) +polyLineScalars.InsertValue(0, 1) +polyLineScalars.InsertValue(1, 0) +polyLineScalars.InsertValue(2, 0) + aPolyLine = vtk.vtkPolyLine() aPolyLine.GetPointIds().SetNumberOfIds(3) -aPolyLine.GetPointIds().SetId(0,0) -aPolyLine.GetPointIds().SetId(1,1) -aPolyLine.GetPointIds().SetId(2,2) +aPolyLine.GetPointIds().SetId(0, 0) +aPolyLine.GetPointIds().SetId(1, 1) +aPolyLine.GetPointIds().SetId(2, 2) + aPolyLineGrid = vtk.vtkUnstructuredGrid() -aPolyLineGrid.Allocate(1,1) -aPolyLineGrid.InsertNextCell(aPolyLine.GetCellType(),aPolyLine.GetPointIds()) +aPolyLineGrid.Allocate(1, 1) +aPolyLineGrid.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds()) aPolyLineGrid.SetPoints(polyLinePoints) aPolyLineGrid.GetPointData().SetScalars(polyLineScalars) + polyLineContours = vtk.vtkContourFilter() polyLineContours.SetInputData(aPolyLineGrid) -polyLineContours.SetValue(0,.5) +polyLineContours.SetValue(0, .5) + aPolyLineContourMapper = vtk.vtkDataSetMapper() aPolyLineContourMapper.SetInputConnection(polyLineContours.GetOutputPort()) aPolyLineContourMapper.ScalarVisibilityOff() + aPolyLineContourActor = vtk.vtkActor() aPolyLineContourActor.SetMapper(aPolyLineContourMapper) + aPolyLineMapper = vtk.vtkDataSetMapper() aPolyLineMapper.SetInputData(aPolyLineGrid) aPolyLineMapper.ScalarVisibilityOff() + aPolyLineActor = vtk.vtkActor() aPolyLineActor.SetMapper(aPolyLineMapper) aPolyLineActor.GetProperty().BackfaceCullingOn() aPolyLineActor.GetProperty().SetRepresentationToWireframe() + # Vertex + vertexPoints = vtk.vtkPoints() vertexPoints.SetNumberOfPoints(1) -vertexPoints.InsertPoint(0,0,0,0) +vertexPoints.InsertPoint(0, 0, 0, 0) + vertexScalars = vtk.vtkFloatArray() vertexScalars.SetNumberOfTuples(1) -vertexScalars.InsertValue(0,1) +vertexScalars.InsertValue(0, 1) + aVertex = vtk.vtkVertex() -aVertex.GetPointIds().SetId(0,0) +aVertex.GetPointIds().SetId(0, 0) + aVertexGrid = vtk.vtkUnstructuredGrid() -aVertexGrid.Allocate(1,1) -aVertexGrid.InsertNextCell(aVertex.GetCellType(),aVertex.GetPointIds()) +aVertexGrid.Allocate(1, 1) +aVertexGrid.InsertNextCell(aVertex.GetCellType(), aVertex.GetPointIds()) aVertexGrid.SetPoints(vertexPoints) aVertexGrid.GetPointData().SetScalars(vertexScalars) + vertexContours = vtk.vtkContourFilter() vertexContours.SetInputData(aVertexGrid) -vertexContours.SetValue(0,1) +vertexContours.SetValue(0, 1) + aVertexContourMapper = vtk.vtkDataSetMapper() aVertexContourMapper.SetInputConnection(vertexContours.GetOutputPort()) aVertexContourMapper.ScalarVisibilityOff() + aVertexContourActor = vtk.vtkActor() aVertexContourActor.SetMapper(aVertexContourMapper) aVertexContourActor.GetProperty().SetRepresentationToWireframe() + aVertexMapper = vtk.vtkDataSetMapper() aVertexMapper.SetInputData(aVertexGrid) aVertexMapper.ScalarVisibilityOff() + aVertexActor = vtk.vtkActor() aVertexActor.SetMapper(aVertexMapper) aVertexActor.GetProperty().BackfaceCullingOn() + # Poly Vertex + polyVertexPoints = vtk.vtkPoints() polyVertexPoints.SetNumberOfPoints(3) -polyVertexPoints.InsertPoint(0,0,0,0) -polyVertexPoints.InsertPoint(1,1,0,0) -polyVertexPoints.InsertPoint(2,1,1,0) +polyVertexPoints.InsertPoint(0, 0, 0, 0) +polyVertexPoints.InsertPoint(1, 1, 0, 0) +polyVertexPoints.InsertPoint(2, 1, 1, 0) + polyVertexScalars = vtk.vtkFloatArray() polyVertexScalars.SetNumberOfTuples(3) -polyVertexScalars.InsertValue(0,1) -polyVertexScalars.InsertValue(1,0) -polyVertexScalars.InsertValue(2,0) +polyVertexScalars.InsertValue(0, 1) +polyVertexScalars.InsertValue(1, 0) +polyVertexScalars.InsertValue(2, 0) + aPolyVertex = vtk.vtkPolyVertex() aPolyVertex.GetPointIds().SetNumberOfIds(3) -aPolyVertex.GetPointIds().SetId(0,0) -aPolyVertex.GetPointIds().SetId(1,1) -aPolyVertex.GetPointIds().SetId(2,2) +aPolyVertex.GetPointIds().SetId(0, 0) +aPolyVertex.GetPointIds().SetId(1, 1) +aPolyVertex.GetPointIds().SetId(2, 2) + aPolyVertexGrid = vtk.vtkUnstructuredGrid() -aPolyVertexGrid.Allocate(1,1) -aPolyVertexGrid.InsertNextCell(aPolyVertex.GetCellType(),aPolyVertex.GetPointIds()) +aPolyVertexGrid.Allocate(1, 1) +aPolyVertexGrid.InsertNextCell(aPolyVertex.GetCellType(), aPolyVertex.GetPointIds()) aPolyVertexGrid.SetPoints(polyVertexPoints) aPolyVertexGrid.GetPointData().SetScalars(polyVertexScalars) + polyVertexContours = vtk.vtkContourFilter() polyVertexContours.SetInputData(aPolyVertexGrid) -polyVertexContours.SetValue(0,0) +polyVertexContours.SetValue(0, 0) + aPolyVertexContourMapper = vtk.vtkDataSetMapper() aPolyVertexContourMapper.SetInputConnection(polyVertexContours.GetOutputPort()) aPolyVertexContourMapper.ScalarVisibilityOff() + aPolyVertexContourActor = vtk.vtkActor() aPolyVertexContourActor.SetMapper(aPolyVertexContourMapper) aPolyVertexContourActor.GetProperty().SetRepresentationToWireframe() + aPolyVertexMapper = vtk.vtkDataSetMapper() aPolyVertexMapper.SetInputData(aPolyVertexGrid) aPolyVertexMapper.ScalarVisibilityOff() + aPolyVertexActor = vtk.vtkActor() aPolyVertexActor.SetMapper(aPolyVertexMapper) + # Pentagonal prism + pentaPoints = vtk.vtkPoints() pentaPoints.SetNumberOfPoints(10) -pentaPoints.InsertPoint(0,0.25,0.0,0.0) -pentaPoints.InsertPoint(1,0.75,0.0,0.0) -pentaPoints.InsertPoint(2,1.0,0.5,0.0) -pentaPoints.InsertPoint(3,0.5,1.0,0.0) -pentaPoints.InsertPoint(4,0.0,0.5,0.0) -pentaPoints.InsertPoint(5,0.25,0.0,1.0) -pentaPoints.InsertPoint(6,0.75,0.0,1.0) -pentaPoints.InsertPoint(7,1.0,0.5,1.0) -pentaPoints.InsertPoint(8,0.5,1.0,1.0) -pentaPoints.InsertPoint(9,0.0,0.5,1.0) +pentaPoints.InsertPoint(0, 0.25, 0.0, 0.0) +pentaPoints.InsertPoint(1, 0.75, 0.0, 0.0) +pentaPoints.InsertPoint(2, 1.0, 0.5, 0.0) +pentaPoints.InsertPoint(3, 0.5, 1.0, 0.0) +pentaPoints.InsertPoint(4, 0.0, 0.5, 0.0) +pentaPoints.InsertPoint(5, 0.25, 0.0, 1.0) +pentaPoints.InsertPoint(6, 0.75, 0.0, 1.0) +pentaPoints.InsertPoint(7, 1.0, 0.5, 1.0) +pentaPoints.InsertPoint(8, 0.5, 1.0, 1.0) +pentaPoints.InsertPoint(9, 0.0, 0.5, 1.0) + pentaScalars = vtk.vtkFloatArray() pentaScalars.SetNumberOfTuples(10) -pentaScalars.InsertValue(0,1) -pentaScalars.InsertValue(1,1) -pentaScalars.InsertValue(2,1) -pentaScalars.InsertValue(3,1) -pentaScalars.InsertValue(4,1) -pentaScalars.InsertValue(5,0) -pentaScalars.InsertValue(6,0) -pentaScalars.InsertValue(7,0) -pentaScalars.InsertValue(8,0) -pentaScalars.InsertValue(9,0) +pentaScalars.InsertValue(0, 1) +pentaScalars.InsertValue(1, 1) +pentaScalars.InsertValue(2, 1) +pentaScalars.InsertValue(3, 1) +pentaScalars.InsertValue(4, 1) +pentaScalars.InsertValue(5, 0) +pentaScalars.InsertValue(6, 0) +pentaScalars.InsertValue(7, 0) +pentaScalars.InsertValue(8, 0) +pentaScalars.InsertValue(9, 0) + aPenta = vtk.vtkPentagonalPrism() -aPenta.GetPointIds().SetId(0,0) -aPenta.GetPointIds().SetId(1,1) -aPenta.GetPointIds().SetId(2,2) -aPenta.GetPointIds().SetId(3,3) -aPenta.GetPointIds().SetId(4,4) -aPenta.GetPointIds().SetId(5,5) -aPenta.GetPointIds().SetId(6,6) -aPenta.GetPointIds().SetId(7,7) -aPenta.GetPointIds().SetId(8,8) -aPenta.GetPointIds().SetId(9,9) +aPenta.GetPointIds().SetId(0, 0) +aPenta.GetPointIds().SetId(1, 1) +aPenta.GetPointIds().SetId(2, 2) +aPenta.GetPointIds().SetId(3, 3) +aPenta.GetPointIds().SetId(4, 4) +aPenta.GetPointIds().SetId(5, 5) +aPenta.GetPointIds().SetId(6, 6) +aPenta.GetPointIds().SetId(7, 7) +aPenta.GetPointIds().SetId(8, 8) +aPenta.GetPointIds().SetId(9, 9) + aPentaGrid = vtk.vtkUnstructuredGrid() -aPentaGrid.Allocate(1,1) -aPentaGrid.InsertNextCell(aPenta.GetCellType(),aPenta.GetPointIds()) +aPentaGrid.Allocate(1, 1) +aPentaGrid.InsertNextCell(aPenta.GetCellType(), aPenta.GetPointIds()) aPentaGrid.SetPoints(pentaPoints) aPentaGrid.GetPointData().SetScalars(pentaScalars) + pentaContours = vtk.vtkContourFilter() pentaContours.SetInputData(aPentaGrid) -pentaContours.SetValue(0,.5) +pentaContours.SetValue(0, .5) + aPentaContourMapper = vtk.vtkDataSetMapper() aPentaContourMapper.SetInputConnection(pentaContours.GetOutputPort()) aPentaContourMapper.ScalarVisibilityOff() + aPentaMapper = vtk.vtkDataSetMapper() aPentaMapper.SetInputData(aPentaGrid) aPentaMapper.ScalarVisibilityOff() + aPentaActor = vtk.vtkActor() aPentaActor.SetMapper(aPentaMapper) aPentaActor.GetProperty().BackfaceCullingOn() aPentaActor.GetProperty().SetRepresentationToWireframe() + aPentaContourActor = vtk.vtkActor() aPentaContourActor.SetMapper(aPentaContourMapper) aPentaContourActor.GetProperty().BackfaceCullingOn() + # Hexagonal prism + hexaPoints = vtk.vtkPoints() hexaPoints.SetNumberOfPoints(12) -hexaPoints.InsertPoint(0,0.0,0.0,0.0) -hexaPoints.InsertPoint(1,0.5,0.0,0.0) -hexaPoints.InsertPoint(2,1.0,0.5,0.0) -hexaPoints.InsertPoint(3,1.0,1.0,0.0) -hexaPoints.InsertPoint(4,0.5,1.0,0.0) -hexaPoints.InsertPoint(5,0.0,0.5,0.0) -hexaPoints.InsertPoint(6,0.0,0.0,1.0) -hexaPoints.InsertPoint(7,0.5,0.0,1.0) -hexaPoints.InsertPoint(8,1.0,0.5,1.0) -hexaPoints.InsertPoint(9,1.0,1.0,1.0) -hexaPoints.InsertPoint(10,0.5,1.0,1.0) -hexaPoints.InsertPoint(11,0.0,0.5,1.0) +hexaPoints.InsertPoint(0, 0.0, 0.0, 0.0) +hexaPoints.InsertPoint(1, 0.5, 0.0, 0.0) +hexaPoints.InsertPoint(2, 1.0, 0.5, 0.0) +hexaPoints.InsertPoint(3, 1.0, 1.0, 0.0) +hexaPoints.InsertPoint(4, 0.5, 1.0, 0.0) +hexaPoints.InsertPoint(5, 0.0, 0.5, 0.0) +hexaPoints.InsertPoint(6, 0.0, 0.0, 1.0) +hexaPoints.InsertPoint(7, 0.5, 0.0, 1.0) +hexaPoints.InsertPoint(8, 1.0, 0.5, 1.0) +hexaPoints.InsertPoint(9, 1.0, 1.0, 1.0) +hexaPoints.InsertPoint(10, 0.5, 1.0, 1.0) +hexaPoints.InsertPoint(11, 0.0, 0.5, 1.0) + hexaScalars = vtk.vtkFloatArray() hexaScalars.SetNumberOfTuples(12) -hexaScalars.InsertValue(0,1) -hexaScalars.InsertValue(1,1) -hexaScalars.InsertValue(2,1) -hexaScalars.InsertValue(3,1) -hexaScalars.InsertValue(4,1) -hexaScalars.InsertValue(5,1) -hexaScalars.InsertValue(6,0) -hexaScalars.InsertValue(7,0) -hexaScalars.InsertValue(8,0) -hexaScalars.InsertValue(9,0) -hexaScalars.InsertValue(10,0) -hexaScalars.InsertValue(11,0) +hexaScalars.InsertValue(0, 1) +hexaScalars.InsertValue(1, 1) +hexaScalars.InsertValue(2, 1) +hexaScalars.InsertValue(3, 1) +hexaScalars.InsertValue(4, 1) +hexaScalars.InsertValue(5, 1) +hexaScalars.InsertValue(6, 0) +hexaScalars.InsertValue(7, 0) +hexaScalars.InsertValue(8, 0) +hexaScalars.InsertValue(9, 0) +hexaScalars.InsertValue(10, 0) +hexaScalars.InsertValue(11, 0) + aHexa = vtk.vtkHexagonalPrism() -aHexa.GetPointIds().SetId(0,0) -aHexa.GetPointIds().SetId(1,1) -aHexa.GetPointIds().SetId(2,2) -aHexa.GetPointIds().SetId(3,3) -aHexa.GetPointIds().SetId(4,4) -aHexa.GetPointIds().SetId(5,5) -aHexa.GetPointIds().SetId(6,6) -aHexa.GetPointIds().SetId(7,7) -aHexa.GetPointIds().SetId(8,8) -aHexa.GetPointIds().SetId(9,9) -aHexa.GetPointIds().SetId(10,10) -aHexa.GetPointIds().SetId(11,11) +aHexa.GetPointIds().SetId(0, 0) +aHexa.GetPointIds().SetId(1, 1) +aHexa.GetPointIds().SetId(2, 2) +aHexa.GetPointIds().SetId(3, 3) +aHexa.GetPointIds().SetId(4, 4) +aHexa.GetPointIds().SetId(5, 5) +aHexa.GetPointIds().SetId(6, 6) +aHexa.GetPointIds().SetId(7, 7) +aHexa.GetPointIds().SetId(8, 8) +aHexa.GetPointIds().SetId(9, 9) +aHexa.GetPointIds().SetId(10, 10) +aHexa.GetPointIds().SetId(11, 11) + aHexaGrid = vtk.vtkUnstructuredGrid() -aHexaGrid.Allocate(1,1) -aHexaGrid.InsertNextCell(aHexa.GetCellType(),aHexa.GetPointIds()) +aHexaGrid.Allocate(1, 1) +aHexaGrid.InsertNextCell(aHexa.GetCellType(), aHexa.GetPointIds()) aHexaGrid.SetPoints(hexaPoints) aHexaGrid.GetPointData().SetScalars(hexaScalars) + hexaContours = vtk.vtkContourFilter() hexaContours.SetInputData(aHexaGrid) -hexaContours.SetValue(0,.5) +hexaContours.SetValue(0, .5) + aHexaContourMapper = vtk.vtkDataSetMapper() aHexaContourMapper.SetInputConnection(hexaContours.GetOutputPort()) aHexaContourMapper.ScalarVisibilityOff() + aHexaMapper = vtk.vtkDataSetMapper() aHexaMapper.SetInputData(aHexaGrid) aHexaMapper.ScalarVisibilityOff() + aHexaActor = vtk.vtkActor() aHexaActor.SetMapper(aHexaMapper) aHexaActor.GetProperty().BackfaceCullingOn() aHexaActor.GetProperty().SetRepresentationToWireframe() + aHexaContourActor = vtk.vtkActor() aHexaContourActor.SetMapper(aHexaContourMapper) aHexaContourActor.GetProperty().BackfaceCullingOn() -ren1.SetBackground(.1,.2,.3) -renWin.SetSize(400,400) + +ren1.SetBackground(.1, .2, .3) +renWin.SetSize(400, 400) + ren1.AddActor(aVoxelActor) -aVoxelActor.GetProperty().SetDiffuseColor(1,0,0) +aVoxelActor.GetProperty().SetDiffuseColor(1, 0, 0) + ren1.AddActor(aVoxelContourActor) -aVoxelContourActor.GetProperty().SetDiffuseColor(1,0,0) +aVoxelContourActor.GetProperty().SetDiffuseColor(1, 0, 0) + ren1.AddActor(aHexahedronActor) -aHexahedronActor.GetProperty().SetDiffuseColor(1,1,0) +aHexahedronActor.GetProperty().SetDiffuseColor(1, 1, 0) + ren1.AddActor(aHexahedronContourActor) -aHexahedronContourActor.GetProperty().SetDiffuseColor(1,1,0) +aHexahedronContourActor.GetProperty().SetDiffuseColor(1, 1, 0) + ren1.AddActor(aTetraActor) -aTetraActor.GetProperty().SetDiffuseColor(0,1,0) +aTetraActor.GetProperty().SetDiffuseColor(0, 1, 0) + ren1.AddActor(aTetraContourActor) -aTetraContourActor.GetProperty().SetDiffuseColor(0,1,0) +aTetraContourActor.GetProperty().SetDiffuseColor(0, 1, 0) + ren1.AddActor(aWedgeActor) -aWedgeActor.GetProperty().SetDiffuseColor(0,1,1) +aWedgeActor.GetProperty().SetDiffuseColor(0, 1, 1) + ren1.AddActor(aWedgeContourActor) -aWedgeContourActor.GetProperty().SetDiffuseColor(0,1,1) +aWedgeContourActor.GetProperty().SetDiffuseColor(0, 1, 1) + ren1.AddActor(aPyramidActor) -aPyramidActor.GetProperty().SetDiffuseColor(1,0,1) +aPyramidActor.GetProperty().SetDiffuseColor(1, 0, 1) + ren1.AddActor(aPyramidContourActor) -aPyramidContourActor.GetProperty().SetDiffuseColor(1,0,1) +aPyramidContourActor.GetProperty().SetDiffuseColor(1, 0, 1) + ren1.AddActor(aPixelActor) -aPixelActor.GetProperty().SetDiffuseColor(0,1,1) +aPixelActor.GetProperty().SetDiffuseColor(0, 1, 1) + ren1.AddActor(aPixelContourActor) -aPixelContourActor.GetProperty().SetDiffuseColor(0,1,1) +aPixelContourActor.GetProperty().SetDiffuseColor(0, 1, 1) + ren1.AddActor(aQuadActor) -aQuadActor.GetProperty().SetDiffuseColor(1,0,1) +aQuadActor.GetProperty().SetDiffuseColor(1, 0, 1) + ren1.AddActor(aQuadContourActor) -aQuadContourActor.GetProperty().SetDiffuseColor(1,0,1) +aQuadContourActor.GetProperty().SetDiffuseColor(1, 0, 1) + ren1.AddActor(aTriangleActor) -aTriangleActor.GetProperty().SetDiffuseColor(.3,1,.5) +aTriangleActor.GetProperty().SetDiffuseColor(.3, 1, .5) + ren1.AddActor(aTriangleContourActor) -aTriangleContourActor.GetProperty().SetDiffuseColor(.3,1,.5) +aTriangleContourActor.GetProperty().SetDiffuseColor(.3, 1, .5) + ren1.AddActor(aPolygonActor) -aPolygonActor.GetProperty().SetDiffuseColor(1,.4,.5) +aPolygonActor.GetProperty().SetDiffuseColor(1, .4, .5) + ren1.AddActor(aPolygonContourActor) -aPolygonContourActor.GetProperty().SetDiffuseColor(1,.4,.5) +aPolygonContourActor.GetProperty().SetDiffuseColor(1, .4, .5) + ren1.AddActor(aTriangleStripActor) -aTriangleStripActor.GetProperty().SetDiffuseColor(.3,.7,1) +aTriangleStripActor.GetProperty().SetDiffuseColor(.3, .7, 1) + ren1.AddActor(aTriangleStripContourActor) -aTriangleStripContourActor.GetProperty().SetDiffuseColor(.3,.7,1) +aTriangleStripContourActor.GetProperty().SetDiffuseColor(.3, .7, 1) + ren1.AddActor(aLineActor) -aLineActor.GetProperty().SetDiffuseColor(.2,1,1) +aLineActor.GetProperty().SetDiffuseColor(.2, 1, 1) + ren1.AddActor(aLineContourActor) -aLineContourActor.GetProperty().SetDiffuseColor(.2,1,1) +aLineContourActor.GetProperty().SetDiffuseColor(.2, 1, 1) + ren1.AddActor(aPolyLineActor) -aPolyLineActor.GetProperty().SetDiffuseColor(1,1,1) +aPolyLineActor.GetProperty().SetDiffuseColor(1, 1, 1) + ren1.AddActor(aPolyLineContourActor) -aPolyLineContourActor.GetProperty().SetDiffuseColor(1,1,1) +aPolyLineContourActor.GetProperty().SetDiffuseColor(1, 1, 1) + ren1.AddActor(aVertexActor) -aVertexActor.GetProperty().SetDiffuseColor(1,1,1) +aVertexActor.GetProperty().SetDiffuseColor(1, 1, 1) + ren1.AddActor(aVertexContourActor) -aVertexContourActor.GetProperty().SetDiffuseColor(1,1,1) +aVertexContourActor.GetProperty().SetDiffuseColor(1, 1, 1) + ren1.AddActor(aPolyVertexActor) -aPolyVertexActor.GetProperty().SetDiffuseColor(1,1,1) +aPolyVertexActor.GetProperty().SetDiffuseColor(1, 1, 1) + ren1.AddActor(aPolyVertexContourActor) -aPolyVertexContourActor.GetProperty().SetDiffuseColor(1,1,1) +aPolyVertexContourActor.GetProperty().SetDiffuseColor(1, 1, 1) + ren1.AddActor(aPentaActor) -aPentaActor.GetProperty().SetDiffuseColor(.2,.4,.7) +aPentaActor.GetProperty().SetDiffuseColor(.2, .4, .7) + ren1.AddActor(aPentaContourActor) -aPentaContourActor.GetProperty().SetDiffuseColor(.2,.4,.7) +aPentaContourActor.GetProperty().SetDiffuseColor(.2, .4, .7) + ren1.AddActor(aHexaActor) -aHexaActor.GetProperty().SetDiffuseColor(.7,.5,1) +aHexaActor.GetProperty().SetDiffuseColor(.7, .5, 1) + ren1.AddActor(aHexaContourActor) -aHexaContourActor.GetProperty().SetDiffuseColor(.7,.5,1) +aHexaContourActor.GetProperty().SetDiffuseColor(.7, .5, 1) + # places everyone!! -aVoxelContourActor.AddPosition(0,0,0) -aVoxelContourActor.AddPosition(0,2,0) -aHexahedronContourActor.AddPosition(2,0,0) -aHexahedronContourActor.AddPosition(0,2,0) -aHexahedronActor.AddPosition(2,0,0) -aTetraContourActor.AddPosition(4,0,0) -aTetraContourActor.AddPosition(0,2,0) -aTetraActor.AddPosition(4,0,0) -aWedgeContourActor.AddPosition(6,0,0) -aWedgeContourActor.AddPosition(0,2,0) -aWedgeActor.AddPosition(6,0,0) -aPyramidContourActor.AddPosition(8,0,0) -aPyramidContourActor.AddPosition(0,2,0) -aPyramidActor.AddPosition(8,0,0) -aPixelContourActor.AddPosition(0,4,0) -aPixelContourActor.AddPosition(0,2,0) -aPixelActor.AddPosition(0,4,0) -aQuadContourActor.AddPosition(2,4,0) -aQuadContourActor.AddPosition(0,2,0) -aQuadActor.AddPosition(2,4,0) -aTriangleContourActor.AddPosition(4,4,0) -aTriangleContourActor.AddPosition(0,2,0) -aTriangleActor.AddPosition(4,4,0) -aPolygonContourActor.AddPosition(6,4,0) -aPolygonContourActor.AddPosition(0,2,0) -aPolygonActor.AddPosition(6,4,0) -aTriangleStripContourActor.AddPosition(8,4,0) -aTriangleStripContourActor.AddPosition(0,2,0) -aTriangleStripActor.AddPosition(8,4,0) -aLineContourActor.AddPosition(0,8,0) -aLineContourActor.AddPosition(0,2,0) -aLineActor.AddPosition(0,8,0) -aPolyLineContourActor.AddPosition(2,8,0) -aPolyLineContourActor.AddPosition(0,2,0) -aPolyLineActor.AddPosition(2,8,0) -aVertexContourActor.AddPosition(0,12,0) -aVertexContourActor.AddPosition(0,2,0) -aVertexActor.AddPosition(0,12,0) -aPolyVertexContourActor.AddPosition(2,12,0) -aPolyVertexContourActor.AddPosition(0,2,0) -aPolyVertexActor.AddPosition(2,12,0) -aPentaContourActor.AddPosition(4,8,0) -aPentaContourActor.AddPosition(0,2,0) -aPentaActor.AddPosition(4,8,0) -aHexaContourActor.AddPosition(6,8,0) -aHexaContourActor.AddPosition(0,2,0) -aHexaActor.AddPosition(6,8,0) -[base, back, left] = BuildBackdrop(-1, 11, -1, 16, -1, 2, .1) + +aVoxelContourActor.AddPosition(0, 0, 0) +aVoxelContourActor.AddPosition(0, 2, 0) +aHexahedronContourActor.AddPosition(2, 0, 0) +aHexahedronContourActor.AddPosition(0, 2, 0) +aHexahedronActor.AddPosition(2, 0, 0) +aTetraContourActor.AddPosition(4, 0, 0) +aTetraContourActor.AddPosition(0, 2, 0) +aTetraActor.AddPosition(4, 0, 0) +aWedgeContourActor.AddPosition(6, 0, 0) +aWedgeContourActor.AddPosition(0, 2, 0) +aWedgeActor.AddPosition(6, 0, 0) +aPyramidContourActor.AddPosition(8, 0, 0) +aPyramidContourActor.AddPosition(0, 2, 0) +aPyramidActor.AddPosition(8, 0, 0) + +aPixelContourActor.AddPosition(0, 4, 0) +aPixelContourActor.AddPosition(0, 2, 0) +aPixelActor.AddPosition(0, 4, 0) +aQuadContourActor.AddPosition(2, 4, 0) +aQuadContourActor.AddPosition(0, 2, 0) +aQuadActor.AddPosition(2, 4, 0) +aTriangleContourActor.AddPosition(4, 4, 0) +aTriangleContourActor.AddPosition(0, 2, 0) +aTriangleActor.AddPosition(4, 4, 0) +aPolygonContourActor.AddPosition(6, 4, 0) +aPolygonContourActor.AddPosition(0, 2, 0) +aPolygonActor.AddPosition(6, 4, 0) +aTriangleStripContourActor.AddPosition(8, 4, 0) +aTriangleStripContourActor.AddPosition(0, 2, 0) +aTriangleStripActor.AddPosition(8, 4, 0) + +aLineContourActor.AddPosition(0, 8, 0) +aLineContourActor.AddPosition(0, 2, 0) +aLineActor.AddPosition(0, 8, 0) +aPolyLineContourActor.AddPosition(2, 8, 0) +aPolyLineContourActor.AddPosition(0, 2, 0) +aPolyLineActor.AddPosition(2, 8, 0) + +aVertexContourActor.AddPosition(0, 12, 0) +aVertexContourActor.AddPosition(0, 2, 0) +aVertexActor.AddPosition(0, 12, 0) +aPolyVertexContourActor.AddPosition(2, 12, 0) +aPolyVertexContourActor.AddPosition(0, 2, 0) +aPolyVertexActor.AddPosition(2, 12, 0) + +aPentaContourActor.AddPosition(4, 8, 0) +aPentaContourActor.AddPosition(0, 2, 0) +aPentaActor.AddPosition(4, 8, 0) +aHexaContourActor.AddPosition(6, 8, 0) +aHexaContourActor.AddPosition(0, 2, 0) +aHexaActor.AddPosition(6, 8, 0) + +[base, back, left] = backdrop.BuildBackdrop(-1, 11, -1, 16, -1, 2, .1) + ren1.AddActor(base) -base.GetProperty().SetDiffuseColor(.2,.2,.2) +base.GetProperty().SetDiffuseColor(.2, .2, .2) ren1.AddActor(left) -left.GetProperty().SetDiffuseColor(.2,.2,.2) +left.GetProperty().SetDiffuseColor(.2, .2, .2) ren1.AddActor(back) -back.GetProperty().SetDiffuseColor(.2,.2,.2) +back.GetProperty().SetDiffuseColor(.2, .2, .2) + ren1.ResetCamera() ren1.GetActiveCamera().Dolly(1.5) ren1.ResetCameraClippingRange() + renWin.Render() + # render the image # iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Filters/Core/Testing/Python/contourQuadraticCells.py b/Filters/Core/Testing/Python/contourQuadraticCells.py index 01e76f548e7..6e207300cac 100755 --- a/Filters/Core/Testing/Python/contourQuadraticCells.py +++ b/Filters/Core/Testing/Python/contourQuadraticCells.py @@ -1,34 +1,43 @@ #!/usr/bin/env python +import sys import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() +# Prevent .pyc files being created. +# Stops the vtk source being polluted +# by .pyc files. +sys.dont_write_bytecode = True + +import backdrop + # Contour every quadratic cell type # Create a scene with one of each cell type. + # QuadraticEdge edgePoints = vtk.vtkPoints() edgePoints.SetNumberOfPoints(3) -edgePoints.InsertPoint(0,0,0,0) -edgePoints.InsertPoint(1,1.0,0,0) -edgePoints.InsertPoint(2,0.5,0.25,0) +edgePoints.InsertPoint(0, 0, 0, 0) +edgePoints.InsertPoint(1, 1.0, 0, 0) +edgePoints.InsertPoint(2, 0.5, 0.25, 0) edgeScalars = vtk.vtkFloatArray() edgeScalars.SetNumberOfTuples(3) -edgeScalars.InsertValue(0,0.0) -edgeScalars.InsertValue(1,0.0) -edgeScalars.InsertValue(2,0.9) +edgeScalars.InsertValue(0, 0.0) +edgeScalars.InsertValue(1, 0.0) +edgeScalars.InsertValue(2, 0.9) aEdge = vtk.vtkQuadraticEdge() -aEdge.GetPointIds().SetId(0,0) -aEdge.GetPointIds().SetId(1,1) -aEdge.GetPointIds().SetId(2,2) +aEdge.GetPointIds().SetId(0, 0) +aEdge.GetPointIds().SetId(1, 1) +aEdge.GetPointIds().SetId(2, 2) aEdgeGrid = vtk.vtkUnstructuredGrid() -aEdgeGrid.Allocate(1,1) -aEdgeGrid.InsertNextCell(aEdge.GetCellType(),aEdge.GetPointIds()) +aEdgeGrid.Allocate(1, 1) +aEdgeGrid.InsertNextCell(aEdge.GetCellType(), aEdge.GetPointIds()) aEdgeGrid.SetPoints(edgePoints) aEdgeGrid.GetPointData().SetScalars(edgeScalars) edgeContours = vtk.vtkContourFilter() edgeContours.SetInputData(aEdgeGrid) -edgeContours.SetValue(0,0.5) +edgeContours.SetValue(0, 0.5) aEdgeContourMapper = vtk.vtkDataSetMapper() aEdgeContourMapper.SetInputConnection(edgeContours.GetOutputPort()) aEdgeContourMapper.ScalarVisibilityOff() @@ -43,38 +52,39 @@ aEdgeContourActor = vtk.vtkActor() aEdgeContourActor.SetMapper(aEdgeContourMapper) aEdgeContourActor.GetProperty().BackfaceCullingOn() aEdgeContourActor.GetProperty().SetAmbient(1.0) + # Quadratic triangle triPoints = vtk.vtkPoints() triPoints.SetNumberOfPoints(6) -triPoints.InsertPoint(0,0.0,0.0,0.0) -triPoints.InsertPoint(1,1.0,0.0,0.0) -triPoints.InsertPoint(2,0.5,0.8,0.0) -triPoints.InsertPoint(3,0.5,0.0,0.0) -triPoints.InsertPoint(4,0.75,0.4,0.0) -triPoints.InsertPoint(5,0.25,0.4,0.0) +triPoints.InsertPoint(0, 0.0, 0.0, 0.0) +triPoints.InsertPoint(1, 1.0, 0.0, 0.0) +triPoints.InsertPoint(2, 0.5, 0.8, 0.0) +triPoints.InsertPoint(3, 0.5, 0.0, 0.0) +triPoints.InsertPoint(4, 0.75, 0.4, 0.0) +triPoints.InsertPoint(5, 0.25, 0.4, 0.0) triScalars = vtk.vtkFloatArray() triScalars.SetNumberOfTuples(6) -triScalars.InsertValue(0,0.0) -triScalars.InsertValue(1,0.0) -triScalars.InsertValue(2,0.0) -triScalars.InsertValue(3,1.0) -triScalars.InsertValue(4,0.0) -triScalars.InsertValue(5,0.0) +triScalars.InsertValue(0, 0.0) +triScalars.InsertValue(1, 0.0) +triScalars.InsertValue(2, 0.0) +triScalars.InsertValue(3, 1.0) +triScalars.InsertValue(4, 0.0) +triScalars.InsertValue(5, 0.0) aTri = vtk.vtkQuadraticTriangle() -aTri.GetPointIds().SetId(0,0) -aTri.GetPointIds().SetId(1,1) -aTri.GetPointIds().SetId(2,2) -aTri.GetPointIds().SetId(3,3) -aTri.GetPointIds().SetId(4,4) -aTri.GetPointIds().SetId(5,5) +aTri.GetPointIds().SetId(0, 0) +aTri.GetPointIds().SetId(1, 1) +aTri.GetPointIds().SetId(2, 2) +aTri.GetPointIds().SetId(3, 3) +aTri.GetPointIds().SetId(4, 4) +aTri.GetPointIds().SetId(5, 5) aTriGrid = vtk.vtkUnstructuredGrid() -aTriGrid.Allocate(1,1) -aTriGrid.InsertNextCell(aTri.GetCellType(),aTri.GetPointIds()) +aTriGrid.Allocate(1, 1) +aTriGrid.InsertNextCell(aTri.GetCellType(), aTri.GetPointIds()) aTriGrid.SetPoints(triPoints) aTriGrid.GetPointData().SetScalars(triScalars) triContours = vtk.vtkContourFilter() triContours.SetInputData(aTriGrid) -triContours.SetValue(0,0.5) +triContours.SetValue(0, 0.5) aTriContourMapper = vtk.vtkDataSetMapper() aTriContourMapper.SetInputConnection(triContours.GetOutputPort()) aTriContourMapper.ScalarVisibilityOff() @@ -89,44 +99,45 @@ aTriContourActor = vtk.vtkActor() aTriContourActor.SetMapper(aTriContourMapper) aTriContourActor.GetProperty().BackfaceCullingOn() aTriContourActor.GetProperty().SetAmbient(1.0) + # Quadratic quadrilateral quadPoints = vtk.vtkPoints() quadPoints.SetNumberOfPoints(8) -quadPoints.InsertPoint(0,0.0,0.0,0.0) -quadPoints.InsertPoint(1,1.0,0.0,0.0) -quadPoints.InsertPoint(2,1.0,1.0,0.0) -quadPoints.InsertPoint(3,0.0,1.0,0.0) -quadPoints.InsertPoint(4,0.5,0.0,0.0) -quadPoints.InsertPoint(5,1.0,0.5,0.0) -quadPoints.InsertPoint(6,0.5,1.0,0.0) -quadPoints.InsertPoint(7,0.0,0.5,0.0) +quadPoints.InsertPoint(0, 0.0, 0.0, 0.0) +quadPoints.InsertPoint(1, 1.0, 0.0, 0.0) +quadPoints.InsertPoint(2, 1.0, 1.0, 0.0) +quadPoints.InsertPoint(3, 0.0, 1.0, 0.0) +quadPoints.InsertPoint(4, 0.5, 0.0, 0.0) +quadPoints.InsertPoint(5, 1.0, 0.5, 0.0) +quadPoints.InsertPoint(6, 0.5, 1.0, 0.0) +quadPoints.InsertPoint(7, 0.0, 0.5, 0.0) quadScalars = vtk.vtkFloatArray() quadScalars.SetNumberOfTuples(8) -quadScalars.InsertValue(0,0.0) -quadScalars.InsertValue(1,0.0) -quadScalars.InsertValue(2,1.0) -quadScalars.InsertValue(3,1.0) -quadScalars.InsertValue(4,1.0) -quadScalars.InsertValue(5,0.0) -quadScalars.InsertValue(6,0.0) -quadScalars.InsertValue(7,0.0) +quadScalars.InsertValue(0, 0.0) +quadScalars.InsertValue(1, 0.0) +quadScalars.InsertValue(2, 1.0) +quadScalars.InsertValue(3, 1.0) +quadScalars.InsertValue(4, 1.0) +quadScalars.InsertValue(5, 0.0) +quadScalars.InsertValue(6, 0.0) +quadScalars.InsertValue(7, 0.0) aQuad = vtk.vtkQuadraticQuad() -aQuad.GetPointIds().SetId(0,0) -aQuad.GetPointIds().SetId(1,1) -aQuad.GetPointIds().SetId(2,2) -aQuad.GetPointIds().SetId(3,3) -aQuad.GetPointIds().SetId(4,4) -aQuad.GetPointIds().SetId(5,5) -aQuad.GetPointIds().SetId(6,6) -aQuad.GetPointIds().SetId(7,7) +aQuad.GetPointIds().SetId(0, 0) +aQuad.GetPointIds().SetId(1, 1) +aQuad.GetPointIds().SetId(2, 2) +aQuad.GetPointIds().SetId(3, 3) +aQuad.GetPointIds().SetId(4, 4) +aQuad.GetPointIds().SetId(5, 5) +aQuad.GetPointIds().SetId(6, 6) +aQuad.GetPointIds().SetId(7, 7) aQuadGrid = vtk.vtkUnstructuredGrid() -aQuadGrid.Allocate(1,1) -aQuadGrid.InsertNextCell(aQuad.GetCellType(),aQuad.GetPointIds()) +aQuadGrid.Allocate(1, 1) +aQuadGrid.InsertNextCell(aQuad.GetCellType(), aQuad.GetPointIds()) aQuadGrid.SetPoints(quadPoints) aQuadGrid.GetPointData().SetScalars(quadScalars) quadContours = vtk.vtkContourFilter() quadContours.SetInputData(aQuadGrid) -quadContours.SetValue(0,0.5) +quadContours.SetValue(0, 0.5) aQuadContourMapper = vtk.vtkDataSetMapper() aQuadContourMapper.SetInputConnection(quadContours.GetOutputPort()) aQuadContourMapper.ScalarVisibilityOff() @@ -141,47 +152,48 @@ aQuadContourActor = vtk.vtkActor() aQuadContourActor.SetMapper(aQuadContourMapper) aQuadContourActor.GetProperty().BackfaceCullingOn() aQuadContourActor.GetProperty().SetAmbient(1.0) + # BiQuadratic quadrilateral BquadPoints = vtk.vtkPoints() BquadPoints.SetNumberOfPoints(9) -BquadPoints.InsertPoint(0,0.0,0.0,0.0) -BquadPoints.InsertPoint(1,1.0,0.0,0.0) -BquadPoints.InsertPoint(2,1.0,1.0,0.0) -BquadPoints.InsertPoint(3,0.0,1.0,0.0) -BquadPoints.InsertPoint(4,0.5,0.0,0.0) -BquadPoints.InsertPoint(5,1.0,0.5,0.0) -BquadPoints.InsertPoint(6,0.5,1.0,0.0) -BquadPoints.InsertPoint(7,0.0,0.5,0.0) -BquadPoints.InsertPoint(8,0.5,0.5,0.0) +BquadPoints.InsertPoint(0, 0.0, 0.0, 0.0) +BquadPoints.InsertPoint(1, 1.0, 0.0, 0.0) +BquadPoints.InsertPoint(2, 1.0, 1.0, 0.0) +BquadPoints.InsertPoint(3, 0.0, 1.0, 0.0) +BquadPoints.InsertPoint(4, 0.5, 0.0, 0.0) +BquadPoints.InsertPoint(5, 1.0, 0.5, 0.0) +BquadPoints.InsertPoint(6, 0.5, 1.0, 0.0) +BquadPoints.InsertPoint(7, 0.0, 0.5, 0.0) +BquadPoints.InsertPoint(8, 0.5, 0.5, 0.0) BquadScalars = vtk.vtkFloatArray() BquadScalars.SetNumberOfTuples(9) -BquadScalars.InsertValue(0,1.0) -BquadScalars.InsertValue(1,1.0) -BquadScalars.InsertValue(2,1.0) -BquadScalars.InsertValue(3,1.0) -BquadScalars.InsertValue(4,0.0) -BquadScalars.InsertValue(5,0.0) -BquadScalars.InsertValue(6,0.0) -BquadScalars.InsertValue(7,0.0) -BquadScalars.InsertValue(8,1.0) +BquadScalars.InsertValue(0, 1.0) +BquadScalars.InsertValue(1, 1.0) +BquadScalars.InsertValue(2, 1.0) +BquadScalars.InsertValue(3, 1.0) +BquadScalars.InsertValue(4, 0.0) +BquadScalars.InsertValue(5, 0.0) +BquadScalars.InsertValue(6, 0.0) +BquadScalars.InsertValue(7, 0.0) +BquadScalars.InsertValue(8, 1.0) BQuad = vtk.vtkBiQuadraticQuad() -BQuad.GetPointIds().SetId(0,0) -BQuad.GetPointIds().SetId(1,1) -BQuad.GetPointIds().SetId(2,2) -BQuad.GetPointIds().SetId(3,3) -BQuad.GetPointIds().SetId(4,4) -BQuad.GetPointIds().SetId(5,5) -BQuad.GetPointIds().SetId(6,6) -BQuad.GetPointIds().SetId(7,7) -BQuad.GetPointIds().SetId(8,8) +BQuad.GetPointIds().SetId(0, 0) +BQuad.GetPointIds().SetId(1, 1) +BQuad.GetPointIds().SetId(2, 2) +BQuad.GetPointIds().SetId(3, 3) +BQuad.GetPointIds().SetId(4, 4) +BQuad.GetPointIds().SetId(5, 5) +BQuad.GetPointIds().SetId(6, 6) +BQuad.GetPointIds().SetId(7, 7) +BQuad.GetPointIds().SetId(8, 8) BQuadGrid = vtk.vtkUnstructuredGrid() -BQuadGrid.Allocate(1,1) -BQuadGrid.InsertNextCell(BQuad.GetCellType(),BQuad.GetPointIds()) +BQuadGrid.Allocate(1, 1) +BQuadGrid.InsertNextCell(BQuad.GetCellType(), BQuad.GetPointIds()) BQuadGrid.SetPoints(BquadPoints) BQuadGrid.GetPointData().SetScalars(BquadScalars) BquadContours = vtk.vtkContourFilter() BquadContours.SetInputData(BQuadGrid) -BquadContours.SetValue(0,0.5) +BquadContours.SetValue(0, 0.5) BQuadContourMapper = vtk.vtkDataSetMapper() BQuadContourMapper.SetInputConnection(BquadContours.GetOutputPort()) BQuadContourMapper.ScalarVisibilityOff() @@ -196,38 +208,39 @@ BQuadContourActor = vtk.vtkActor() BQuadContourActor.SetMapper(BQuadContourMapper) BQuadContourActor.GetProperty().BackfaceCullingOn() BQuadContourActor.GetProperty().SetAmbient(1.0) + # Quadratic linear quadrilateral QLquadPoints = vtk.vtkPoints() QLquadPoints.SetNumberOfPoints(6) -QLquadPoints.InsertPoint(0,0.0,0.0,0.0) -QLquadPoints.InsertPoint(1,1.0,0.0,0.0) -QLquadPoints.InsertPoint(2,1.0,1.0,0.0) -QLquadPoints.InsertPoint(3,0.0,1.0,0.0) -QLquadPoints.InsertPoint(4,0.5,0.0,0.0) -QLquadPoints.InsertPoint(5,0.5,1.0,0.0) +QLquadPoints.InsertPoint(0, 0.0, 0.0, 0.0) +QLquadPoints.InsertPoint(1, 1.0, 0.0, 0.0) +QLquadPoints.InsertPoint(2, 1.0, 1.0, 0.0) +QLquadPoints.InsertPoint(3, 0.0, 1.0, 0.0) +QLquadPoints.InsertPoint(4, 0.5, 0.0, 0.0) +QLquadPoints.InsertPoint(5, 0.5, 1.0, 0.0) QLquadScalars = vtk.vtkFloatArray() QLquadScalars.SetNumberOfTuples(6) -QLquadScalars.InsertValue(0,1.0) -QLquadScalars.InsertValue(1,1.0) -QLquadScalars.InsertValue(2,0.0) -QLquadScalars.InsertValue(3,0.0) -QLquadScalars.InsertValue(4,0.0) -QLquadScalars.InsertValue(5,1.0) +QLquadScalars.InsertValue(0, 1.0) +QLquadScalars.InsertValue(1, 1.0) +QLquadScalars.InsertValue(2, 0.0) +QLquadScalars.InsertValue(3, 0.0) +QLquadScalars.InsertValue(4, 0.0) +QLquadScalars.InsertValue(5, 1.0) QLQuad = vtk.vtkQuadraticLinearQuad() -QLQuad.GetPointIds().SetId(0,0) -QLQuad.GetPointIds().SetId(1,1) -QLQuad.GetPointIds().SetId(2,2) -QLQuad.GetPointIds().SetId(3,3) -QLQuad.GetPointIds().SetId(4,4) -QLQuad.GetPointIds().SetId(5,5) +QLQuad.GetPointIds().SetId(0, 0) +QLQuad.GetPointIds().SetId(1, 1) +QLQuad.GetPointIds().SetId(2, 2) +QLQuad.GetPointIds().SetId(3, 3) +QLQuad.GetPointIds().SetId(4, 4) +QLQuad.GetPointIds().SetId(5, 5) QLQuadGrid = vtk.vtkUnstructuredGrid() -QLQuadGrid.Allocate(1,1) -QLQuadGrid.InsertNextCell(QLQuad.GetCellType(),QLQuad.GetPointIds()) +QLQuadGrid.Allocate(1, 1) +QLQuadGrid.InsertNextCell(QLQuad.GetCellType(), QLQuad.GetPointIds()) QLQuadGrid.SetPoints(QLquadPoints) QLQuadGrid.GetPointData().SetScalars(QLquadScalars) QLquadContours = vtk.vtkContourFilter() QLquadContours.SetInputData(QLQuadGrid) -QLquadContours.SetValue(0,0.5) +QLquadContours.SetValue(0, 0.5) QLQuadContourMapper = vtk.vtkDataSetMapper() QLQuadContourMapper.SetInputConnection(QLquadContours.GetOutputPort()) QLQuadContourMapper.ScalarVisibilityOff() @@ -242,50 +255,51 @@ QLQuadContourActor = vtk.vtkActor() QLQuadContourActor.SetMapper(QLQuadContourMapper) QLQuadContourActor.GetProperty().BackfaceCullingOn() QLQuadContourActor.GetProperty().SetAmbient(1.0) + # Quadratic tetrahedron tetPoints = vtk.vtkPoints() tetPoints.SetNumberOfPoints(10) -tetPoints.InsertPoint(0,0.0,0.0,0.0) -tetPoints.InsertPoint(1,1.0,0.0,0.0) -tetPoints.InsertPoint(2,0.5,0.8,0.0) -tetPoints.InsertPoint(3,0.5,0.4,1.0) -tetPoints.InsertPoint(4,0.5,0.0,0.0) -tetPoints.InsertPoint(5,0.75,0.4,0.0) -tetPoints.InsertPoint(6,0.25,0.4,0.0) -tetPoints.InsertPoint(7,0.25,0.2,0.5) -tetPoints.InsertPoint(8,0.75,0.2,0.5) -tetPoints.InsertPoint(9,0.50,0.6,0.5) +tetPoints.InsertPoint(0, 0.0, 0.0, 0.0) +tetPoints.InsertPoint(1, 1.0, 0.0, 0.0) +tetPoints.InsertPoint(2, 0.5, 0.8, 0.0) +tetPoints.InsertPoint(3, 0.5, 0.4, 1.0) +tetPoints.InsertPoint(4, 0.5, 0.0, 0.0) +tetPoints.InsertPoint(5, 0.75, 0.4, 0.0) +tetPoints.InsertPoint(6, 0.25, 0.4, 0.0) +tetPoints.InsertPoint(7, 0.25, 0.2, 0.5) +tetPoints.InsertPoint(8, 0.75, 0.2, 0.5) +tetPoints.InsertPoint(9, 0.50, 0.6, 0.5) tetScalars = vtk.vtkFloatArray() tetScalars.SetNumberOfTuples(10) -tetScalars.InsertValue(0,1.0) -tetScalars.InsertValue(1,1.0) -tetScalars.InsertValue(2,1.0) -tetScalars.InsertValue(3,1.0) -tetScalars.InsertValue(4,0.0) -tetScalars.InsertValue(5,0.0) -tetScalars.InsertValue(6,0.0) -tetScalars.InsertValue(7,0.0) -tetScalars.InsertValue(8,0.0) -tetScalars.InsertValue(9,0.0) +tetScalars.InsertValue(0, 1.0) +tetScalars.InsertValue(1, 1.0) +tetScalars.InsertValue(2, 1.0) +tetScalars.InsertValue(3, 1.0) +tetScalars.InsertValue(4, 0.0) +tetScalars.InsertValue(5, 0.0) +tetScalars.InsertValue(6, 0.0) +tetScalars.InsertValue(7, 0.0) +tetScalars.InsertValue(8, 0.0) +tetScalars.InsertValue(9, 0.0) aTet = vtk.vtkQuadraticTetra() -aTet.GetPointIds().SetId(0,0) -aTet.GetPointIds().SetId(1,1) -aTet.GetPointIds().SetId(2,2) -aTet.GetPointIds().SetId(3,3) -aTet.GetPointIds().SetId(4,4) -aTet.GetPointIds().SetId(5,5) -aTet.GetPointIds().SetId(6,6) -aTet.GetPointIds().SetId(7,7) -aTet.GetPointIds().SetId(8,8) -aTet.GetPointIds().SetId(9,9) +aTet.GetPointIds().SetId(0, 0) +aTet.GetPointIds().SetId(1, 1) +aTet.GetPointIds().SetId(2, 2) +aTet.GetPointIds().SetId(3, 3) +aTet.GetPointIds().SetId(4, 4) +aTet.GetPointIds().SetId(5, 5) +aTet.GetPointIds().SetId(6, 6) +aTet.GetPointIds().SetId(7, 7) +aTet.GetPointIds().SetId(8, 8) +aTet.GetPointIds().SetId(9, 9) aTetGrid = vtk.vtkUnstructuredGrid() -aTetGrid.Allocate(1,1) -aTetGrid.InsertNextCell(aTet.GetCellType(),aTet.GetPointIds()) +aTetGrid.Allocate(1, 1) +aTetGrid.InsertNextCell(aTet.GetCellType(), aTet.GetPointIds()) aTetGrid.SetPoints(tetPoints) aTetGrid.GetPointData().SetScalars(tetScalars) tetContours = vtk.vtkContourFilter() tetContours.SetInputData(aTetGrid) -tetContours.SetValue(0,0.5) +tetContours.SetValue(0, 0.5) aTetContourMapper = vtk.vtkDataSetMapper() aTetContourMapper.SetInputConnection(tetContours.GetOutputPort()) aTetContourMapper.ScalarVisibilityOff() @@ -299,80 +313,81 @@ aTetActor.GetProperty().SetAmbient(1.0) aTetContourActor = vtk.vtkActor() aTetContourActor.SetMapper(aTetContourMapper) aTetContourActor.GetProperty().SetAmbient(1.0) + # Quadratic hexahedron hexPoints = vtk.vtkPoints() hexPoints.SetNumberOfPoints(20) -hexPoints.InsertPoint(0,0,0,0) -hexPoints.InsertPoint(1,1,0,0) -hexPoints.InsertPoint(2,1,1,0) -hexPoints.InsertPoint(3,0,1,0) -hexPoints.InsertPoint(4,0,0,1) -hexPoints.InsertPoint(5,1,0,1) -hexPoints.InsertPoint(6,1,1,1) -hexPoints.InsertPoint(7,0,1,1) -hexPoints.InsertPoint(8,0.5,0,0) -hexPoints.InsertPoint(9,1,0.5,0) -hexPoints.InsertPoint(10,0.5,1,0) -hexPoints.InsertPoint(11,0,0.5,0) -hexPoints.InsertPoint(12,0.5,0,1) -hexPoints.InsertPoint(13,1,0.5,1) -hexPoints.InsertPoint(14,0.5,1,1) -hexPoints.InsertPoint(15,0,0.5,1) -hexPoints.InsertPoint(16,0,0,0.5) -hexPoints.InsertPoint(17,1,0,0.5) -hexPoints.InsertPoint(18,1,1,0.5) -hexPoints.InsertPoint(19,0,1,0.5) +hexPoints.InsertPoint(0, 0, 0, 0) +hexPoints.InsertPoint(1, 1, 0, 0) +hexPoints.InsertPoint(2, 1, 1, 0) +hexPoints.InsertPoint(3, 0, 1, 0) +hexPoints.InsertPoint(4, 0, 0, 1) +hexPoints.InsertPoint(5, 1, 0, 1) +hexPoints.InsertPoint(6, 1, 1, 1) +hexPoints.InsertPoint(7, 0, 1, 1) +hexPoints.InsertPoint(8, 0.5, 0, 0) +hexPoints.InsertPoint(9, 1, 0.5, 0) +hexPoints.InsertPoint(10, 0.5, 1, 0) +hexPoints.InsertPoint(11, 0, 0.5, 0) +hexPoints.InsertPoint(12, 0.5, 0, 1) +hexPoints.InsertPoint(13, 1, 0.5, 1) +hexPoints.InsertPoint(14, 0.5, 1, 1) +hexPoints.InsertPoint(15, 0, 0.5, 1) +hexPoints.InsertPoint(16, 0, 0, 0.5) +hexPoints.InsertPoint(17, 1, 0, 0.5) +hexPoints.InsertPoint(18, 1, 1, 0.5) +hexPoints.InsertPoint(19, 0, 1, 0.5) hexScalars = vtk.vtkFloatArray() hexScalars.SetNumberOfTuples(20) -hexScalars.InsertValue(0,1.0) -hexScalars.InsertValue(1,1.0) -hexScalars.InsertValue(2,1.0) -hexScalars.InsertValue(3,1.0) -hexScalars.InsertValue(4,1.0) -hexScalars.InsertValue(5,1.0) -hexScalars.InsertValue(6,1.0) -hexScalars.InsertValue(7,1.0) -hexScalars.InsertValue(8,0.0) -hexScalars.InsertValue(9,0.0) -hexScalars.InsertValue(10,0.0) -hexScalars.InsertValue(11,0.0) -hexScalars.InsertValue(12,0.0) -hexScalars.InsertValue(13,0.0) -hexScalars.InsertValue(14,0.0) -hexScalars.InsertValue(15,0.0) -hexScalars.InsertValue(16,0.0) -hexScalars.InsertValue(17,0.0) -hexScalars.InsertValue(18,0.0) -hexScalars.InsertValue(19,0.0) +hexScalars.InsertValue(0, 1.0) +hexScalars.InsertValue(1, 1.0) +hexScalars.InsertValue(2, 1.0) +hexScalars.InsertValue(3, 1.0) +hexScalars.InsertValue(4, 1.0) +hexScalars.InsertValue(5, 1.0) +hexScalars.InsertValue(6, 1.0) +hexScalars.InsertValue(7, 1.0) +hexScalars.InsertValue(8, 0.0) +hexScalars.InsertValue(9, 0.0) +hexScalars.InsertValue(10, 0.0) +hexScalars.InsertValue(11, 0.0) +hexScalars.InsertValue(12, 0.0) +hexScalars.InsertValue(13, 0.0) +hexScalars.InsertValue(14, 0.0) +hexScalars.InsertValue(15, 0.0) +hexScalars.InsertValue(16, 0.0) +hexScalars.InsertValue(17, 0.0) +hexScalars.InsertValue(18, 0.0) +hexScalars.InsertValue(19, 0.0) aHex = vtk.vtkQuadraticHexahedron() -aHex.GetPointIds().SetId(0,0) -aHex.GetPointIds().SetId(1,1) -aHex.GetPointIds().SetId(2,2) -aHex.GetPointIds().SetId(3,3) -aHex.GetPointIds().SetId(4,4) -aHex.GetPointIds().SetId(5,5) -aHex.GetPointIds().SetId(6,6) -aHex.GetPointIds().SetId(7,7) -aHex.GetPointIds().SetId(8,8) -aHex.GetPointIds().SetId(9,9) -aHex.GetPointIds().SetId(10,10) -aHex.GetPointIds().SetId(11,11) -aHex.GetPointIds().SetId(12,12) -aHex.GetPointIds().SetId(13,13) -aHex.GetPointIds().SetId(14,14) -aHex.GetPointIds().SetId(15,15) -aHex.GetPointIds().SetId(16,16) -aHex.GetPointIds().SetId(17,17) -aHex.GetPointIds().SetId(18,18) -aHex.GetPointIds().SetId(19,19) +aHex.GetPointIds().SetId(0, 0) +aHex.GetPointIds().SetId(1, 1) +aHex.GetPointIds().SetId(2, 2) +aHex.GetPointIds().SetId(3, 3) +aHex.GetPointIds().SetId(4, 4) +aHex.GetPointIds().SetId(5, 5) +aHex.GetPointIds().SetId(6, 6) +aHex.GetPointIds().SetId(7, 7) +aHex.GetPointIds().SetId(8, 8) +aHex.GetPointIds().SetId(9, 9) +aHex.GetPointIds().SetId(10, 10) +aHex.GetPointIds().SetId(11, 11) +aHex.GetPointIds().SetId(12, 12) +aHex.GetPointIds().SetId(13, 13) +aHex.GetPointIds().SetId(14, 14) +aHex.GetPointIds().SetId(15, 15) +aHex.GetPointIds().SetId(16, 16) +aHex.GetPointIds().SetId(17, 17) +aHex.GetPointIds().SetId(18, 18) +aHex.GetPointIds().SetId(19, 19) aHexGrid = vtk.vtkUnstructuredGrid() -aHexGrid.Allocate(1,1) -aHexGrid.InsertNextCell(aHex.GetCellType(),aHex.GetPointIds()) +aHexGrid.Allocate(1, 1) +aHexGrid.InsertNextCell(aHex.GetCellType(), aHex.GetPointIds()) aHexGrid.SetPoints(hexPoints) aHexGrid.GetPointData().SetScalars(hexScalars) hexContours = vtk.vtkContourFilter() hexContours.SetInputData(aHexGrid) -hexContours.SetValue(0,0.5) +hexContours.SetValue(0, 0.5) aHexContourMapper = vtk.vtkDataSetMapper() aHexContourMapper.SetInputConnection(hexContours.GetOutputPort()) aHexContourMapper.ScalarVisibilityOff() @@ -386,101 +401,102 @@ aHexActor.GetProperty().SetAmbient(1.0) aHexContourActor = vtk.vtkActor() aHexContourActor.SetMapper(aHexContourMapper) aHexContourActor.GetProperty().SetAmbient(1.0) + # TriQuadratic hexahedron TQhexPoints = vtk.vtkPoints() TQhexPoints.SetNumberOfPoints(27) -TQhexPoints.InsertPoint(0,0,0,0) -TQhexPoints.InsertPoint(1,1,0,0) -TQhexPoints.InsertPoint(2,1,1,0) -TQhexPoints.InsertPoint(3,0,1,0) -TQhexPoints.InsertPoint(4,0,0,1) -TQhexPoints.InsertPoint(5,1,0,1) -TQhexPoints.InsertPoint(6,1,1,1) -TQhexPoints.InsertPoint(7,0,1,1) -TQhexPoints.InsertPoint(8,0.5,0,0) -TQhexPoints.InsertPoint(9,1,0.5,0) -TQhexPoints.InsertPoint(10,0.5,1,0) -TQhexPoints.InsertPoint(11,0,0.5,0) -TQhexPoints.InsertPoint(12,0.5,0,1) -TQhexPoints.InsertPoint(13,1,0.5,1) -TQhexPoints.InsertPoint(14,0.5,1,1) -TQhexPoints.InsertPoint(15,0,0.5,1) -TQhexPoints.InsertPoint(16,0,0,0.5) -TQhexPoints.InsertPoint(17,1,0,0.5) -TQhexPoints.InsertPoint(18,1,1,0.5) -TQhexPoints.InsertPoint(19,0,1,0.5) -TQhexPoints.InsertPoint(22,0.5,0,0.5) -TQhexPoints.InsertPoint(21,1,0.5,0.5) -TQhexPoints.InsertPoint(23,0.5,1,0.5) -TQhexPoints.InsertPoint(20,0,0.5,0.5) -TQhexPoints.InsertPoint(24,0.5,0.5,0.0) -TQhexPoints.InsertPoint(25,0.5,0.5,1) -TQhexPoints.InsertPoint(26,0.5,0.5,0.5) +TQhexPoints.InsertPoint(0, 0, 0, 0) +TQhexPoints.InsertPoint(1, 1, 0, 0) +TQhexPoints.InsertPoint(2, 1, 1, 0) +TQhexPoints.InsertPoint(3, 0, 1, 0) +TQhexPoints.InsertPoint(4, 0, 0, 1) +TQhexPoints.InsertPoint(5, 1, 0, 1) +TQhexPoints.InsertPoint(6, 1, 1, 1) +TQhexPoints.InsertPoint(7, 0, 1, 1) +TQhexPoints.InsertPoint(8, 0.5, 0, 0) +TQhexPoints.InsertPoint(9, 1, 0.5, 0) +TQhexPoints.InsertPoint(10, 0.5, 1, 0) +TQhexPoints.InsertPoint(11, 0, 0.5, 0) +TQhexPoints.InsertPoint(12, 0.5, 0, 1) +TQhexPoints.InsertPoint(13, 1, 0.5, 1) +TQhexPoints.InsertPoint(14, 0.5, 1, 1) +TQhexPoints.InsertPoint(15, 0, 0.5, 1) +TQhexPoints.InsertPoint(16, 0, 0, 0.5) +TQhexPoints.InsertPoint(17, 1, 0, 0.5) +TQhexPoints.InsertPoint(18, 1, 1, 0.5) +TQhexPoints.InsertPoint(19, 0, 1, 0.5) +TQhexPoints.InsertPoint(22, 0.5, 0, 0.5) +TQhexPoints.InsertPoint(21, 1, 0.5, 0.5) +TQhexPoints.InsertPoint(23, 0.5, 1, 0.5) +TQhexPoints.InsertPoint(20, 0, 0.5, 0.5) +TQhexPoints.InsertPoint(24, 0.5, 0.5, 0.0) +TQhexPoints.InsertPoint(25, 0.5, 0.5, 1) +TQhexPoints.InsertPoint(26, 0.5, 0.5, 0.5) TQhexScalars = vtk.vtkFloatArray() TQhexScalars.SetNumberOfTuples(27) -TQhexScalars.InsertValue(0,1.0) -TQhexScalars.InsertValue(1,1.0) -TQhexScalars.InsertValue(2,1.0) -TQhexScalars.InsertValue(3,1.0) -TQhexScalars.InsertValue(4,1.0) -TQhexScalars.InsertValue(5,1.0) -TQhexScalars.InsertValue(6,1.0) -TQhexScalars.InsertValue(7,1.0) -TQhexScalars.InsertValue(8,0.0) -TQhexScalars.InsertValue(9,0.0) -TQhexScalars.InsertValue(10,0.0) -TQhexScalars.InsertValue(11,0.0) -TQhexScalars.InsertValue(12,0.0) -TQhexScalars.InsertValue(13,0.0) -TQhexScalars.InsertValue(14,0.0) -TQhexScalars.InsertValue(15,0.0) -TQhexScalars.InsertValue(16,0.0) -TQhexScalars.InsertValue(17,0.0) -TQhexScalars.InsertValue(18,0.0) -TQhexScalars.InsertValue(19,0.0) -TQhexScalars.InsertValue(20,0.0) -TQhexScalars.InsertValue(21,0.0) -TQhexScalars.InsertValue(22,0.0) -TQhexScalars.InsertValue(23,0.0) -TQhexScalars.InsertValue(24,0.0) -TQhexScalars.InsertValue(25,0.0) -TQhexScalars.InsertValue(26,1.0) +TQhexScalars.InsertValue(0, 1.0) +TQhexScalars.InsertValue(1, 1.0) +TQhexScalars.InsertValue(2, 1.0) +TQhexScalars.InsertValue(3, 1.0) +TQhexScalars.InsertValue(4, 1.0) +TQhexScalars.InsertValue(5, 1.0) +TQhexScalars.InsertValue(6, 1.0) +TQhexScalars.InsertValue(7, 1.0) +TQhexScalars.InsertValue(8, 0.0) +TQhexScalars.InsertValue(9, 0.0) +TQhexScalars.InsertValue(10, 0.0) +TQhexScalars.InsertValue(11, 0.0) +TQhexScalars.InsertValue(12, 0.0) +TQhexScalars.InsertValue(13, 0.0) +TQhexScalars.InsertValue(14, 0.0) +TQhexScalars.InsertValue(15, 0.0) +TQhexScalars.InsertValue(16, 0.0) +TQhexScalars.InsertValue(17, 0.0) +TQhexScalars.InsertValue(18, 0.0) +TQhexScalars.InsertValue(19, 0.0) +TQhexScalars.InsertValue(20, 0.0) +TQhexScalars.InsertValue(21, 0.0) +TQhexScalars.InsertValue(22, 0.0) +TQhexScalars.InsertValue(23, 0.0) +TQhexScalars.InsertValue(24, 0.0) +TQhexScalars.InsertValue(25, 0.0) +TQhexScalars.InsertValue(26, 1.0) TQHex = vtk.vtkTriQuadraticHexahedron() -TQHex.GetPointIds().SetId(0,0) -TQHex.GetPointIds().SetId(1,1) -TQHex.GetPointIds().SetId(2,2) -TQHex.GetPointIds().SetId(3,3) -TQHex.GetPointIds().SetId(4,4) -TQHex.GetPointIds().SetId(5,5) -TQHex.GetPointIds().SetId(6,6) -TQHex.GetPointIds().SetId(7,7) -TQHex.GetPointIds().SetId(8,8) -TQHex.GetPointIds().SetId(9,9) -TQHex.GetPointIds().SetId(10,10) -TQHex.GetPointIds().SetId(11,11) -TQHex.GetPointIds().SetId(12,12) -TQHex.GetPointIds().SetId(13,13) -TQHex.GetPointIds().SetId(14,14) -TQHex.GetPointIds().SetId(15,15) -TQHex.GetPointIds().SetId(16,16) -TQHex.GetPointIds().SetId(17,17) -TQHex.GetPointIds().SetId(18,18) -TQHex.GetPointIds().SetId(19,19) -TQHex.GetPointIds().SetId(20,20) -TQHex.GetPointIds().SetId(21,21) -TQHex.GetPointIds().SetId(22,22) -TQHex.GetPointIds().SetId(23,23) -TQHex.GetPointIds().SetId(24,24) -TQHex.GetPointIds().SetId(25,25) -TQHex.GetPointIds().SetId(26,26) +TQHex.GetPointIds().SetId(0, 0) +TQHex.GetPointIds().SetId(1, 1) +TQHex.GetPointIds().SetId(2, 2) +TQHex.GetPointIds().SetId(3, 3) +TQHex.GetPointIds().SetId(4, 4) +TQHex.GetPointIds().SetId(5, 5) +TQHex.GetPointIds().SetId(6, 6) +TQHex.GetPointIds().SetId(7, 7) +TQHex.GetPointIds().SetId(8, 8) +TQHex.GetPointIds().SetId(9, 9) +TQHex.GetPointIds().SetId(10, 10) +TQHex.GetPointIds().SetId(11, 11) +TQHex.GetPointIds().SetId(12, 12) +TQHex.GetPointIds().SetId(13, 13) +TQHex.GetPointIds().SetId(14, 14) +TQHex.GetPointIds().SetId(15, 15) +TQHex.GetPointIds().SetId(16, 16) +TQHex.GetPointIds().SetId(17, 17) +TQHex.GetPointIds().SetId(18, 18) +TQHex.GetPointIds().SetId(19, 19) +TQHex.GetPointIds().SetId(20, 20) +TQHex.GetPointIds().SetId(21, 21) +TQHex.GetPointIds().SetId(22, 22) +TQHex.GetPointIds().SetId(23, 23) +TQHex.GetPointIds().SetId(24, 24) +TQHex.GetPointIds().SetId(25, 25) +TQHex.GetPointIds().SetId(26, 26) TQHexGrid = vtk.vtkUnstructuredGrid() -TQHexGrid.Allocate(1,1) -TQHexGrid.InsertNextCell(TQHex.GetCellType(),TQHex.GetPointIds()) +TQHexGrid.Allocate(1, 1) +TQHexGrid.InsertNextCell(TQHex.GetCellType(), TQHex.GetPointIds()) TQHexGrid.SetPoints(TQhexPoints) TQHexGrid.GetPointData().SetScalars(TQhexScalars) TQhexContours = vtk.vtkContourFilter() TQhexContours.SetInputData(TQHexGrid) -TQhexContours.SetValue(0,0.5) +TQhexContours.SetValue(0, 0.5) TQHexContourMapper = vtk.vtkDataSetMapper() TQHexContourMapper.SetInputConnection(TQhexContours.GetOutputPort()) TQHexContourMapper.ScalarVisibilityOff() @@ -494,92 +510,93 @@ TQHexActor.GetProperty().SetAmbient(1.0) TQHexContourActor = vtk.vtkActor() TQHexContourActor.SetMapper(TQHexContourMapper) TQHexContourActor.GetProperty().SetAmbient(1.0) + # BiQuadratic Quadratic hexahedron BQhexPoints = vtk.vtkPoints() BQhexPoints.SetNumberOfPoints(24) -BQhexPoints.InsertPoint(0,0,0,0) -BQhexPoints.InsertPoint(1,1,0,0) -BQhexPoints.InsertPoint(2,1,1,0) -BQhexPoints.InsertPoint(3,0,1,0) -BQhexPoints.InsertPoint(4,0,0,1) -BQhexPoints.InsertPoint(5,1,0,1) -BQhexPoints.InsertPoint(6,1,1,1) -BQhexPoints.InsertPoint(7,0,1,1) -BQhexPoints.InsertPoint(8,0.5,0,0) -BQhexPoints.InsertPoint(9,1,0.5,0) -BQhexPoints.InsertPoint(10,0.5,1,0) -BQhexPoints.InsertPoint(11,0,0.5,0) -BQhexPoints.InsertPoint(12,0.5,0,1) -BQhexPoints.InsertPoint(13,1,0.5,1) -BQhexPoints.InsertPoint(14,0.5,1,1) -BQhexPoints.InsertPoint(15,0,0.5,1) -BQhexPoints.InsertPoint(16,0,0,0.5) -BQhexPoints.InsertPoint(17,1,0,0.5) -BQhexPoints.InsertPoint(18,1,1,0.5) -BQhexPoints.InsertPoint(19,0,1,0.5) -BQhexPoints.InsertPoint(22,0.5,0,0.5) -BQhexPoints.InsertPoint(21,1,0.5,0.5) -BQhexPoints.InsertPoint(23,0.5,1,0.5) -BQhexPoints.InsertPoint(20,0,0.5,0.5) +BQhexPoints.InsertPoint(0, 0, 0, 0) +BQhexPoints.InsertPoint(1, 1, 0, 0) +BQhexPoints.InsertPoint(2, 1, 1, 0) +BQhexPoints.InsertPoint(3, 0, 1, 0) +BQhexPoints.InsertPoint(4, 0, 0, 1) +BQhexPoints.InsertPoint(5, 1, 0, 1) +BQhexPoints.InsertPoint(6, 1, 1, 1) +BQhexPoints.InsertPoint(7, 0, 1, 1) +BQhexPoints.InsertPoint(8, 0.5, 0, 0) +BQhexPoints.InsertPoint(9, 1, 0.5, 0) +BQhexPoints.InsertPoint(10, 0.5, 1, 0) +BQhexPoints.InsertPoint(11, 0, 0.5, 0) +BQhexPoints.InsertPoint(12, 0.5, 0, 1) +BQhexPoints.InsertPoint(13, 1, 0.5, 1) +BQhexPoints.InsertPoint(14, 0.5, 1, 1) +BQhexPoints.InsertPoint(15, 0, 0.5, 1) +BQhexPoints.InsertPoint(16, 0, 0, 0.5) +BQhexPoints.InsertPoint(17, 1, 0, 0.5) +BQhexPoints.InsertPoint(18, 1, 1, 0.5) +BQhexPoints.InsertPoint(19, 0, 1, 0.5) +BQhexPoints.InsertPoint(22, 0.5, 0, 0.5) +BQhexPoints.InsertPoint(21, 1, 0.5, 0.5) +BQhexPoints.InsertPoint(23, 0.5, 1, 0.5) +BQhexPoints.InsertPoint(20, 0, 0.5, 0.5) BQhexScalars = vtk.vtkFloatArray() BQhexScalars.SetNumberOfTuples(24) -BQhexScalars.InsertValue(0,1.0) -BQhexScalars.InsertValue(1,1.0) -BQhexScalars.InsertValue(2,1.0) -BQhexScalars.InsertValue(3,1.0) -BQhexScalars.InsertValue(4,1.0) -BQhexScalars.InsertValue(5,1.0) -BQhexScalars.InsertValue(6,1.0) -BQhexScalars.InsertValue(7,1.0) -BQhexScalars.InsertValue(8,0.0) -BQhexScalars.InsertValue(9,0.0) -BQhexScalars.InsertValue(10,0.0) -BQhexScalars.InsertValue(11,0.0) -BQhexScalars.InsertValue(12,0.0) -BQhexScalars.InsertValue(13,0.0) -BQhexScalars.InsertValue(14,0.0) -BQhexScalars.InsertValue(15,0.0) -BQhexScalars.InsertValue(16,0.0) -BQhexScalars.InsertValue(17,0.0) -BQhexScalars.InsertValue(18,0.0) -BQhexScalars.InsertValue(19,0.0) -BQhexScalars.InsertValue(20,0.0) -BQhexScalars.InsertValue(21,0.0) -BQhexScalars.InsertValue(22,0.0) -BQhexScalars.InsertValue(23,0.0) +BQhexScalars.InsertValue(0, 1.0) +BQhexScalars.InsertValue(1, 1.0) +BQhexScalars.InsertValue(2, 1.0) +BQhexScalars.InsertValue(3, 1.0) +BQhexScalars.InsertValue(4, 1.0) +BQhexScalars.InsertValue(5, 1.0) +BQhexScalars.InsertValue(6, 1.0) +BQhexScalars.InsertValue(7, 1.0) +BQhexScalars.InsertValue(8, 0.0) +BQhexScalars.InsertValue(9, 0.0) +BQhexScalars.InsertValue(10, 0.0) +BQhexScalars.InsertValue(11, 0.0) +BQhexScalars.InsertValue(12, 0.0) +BQhexScalars.InsertValue(13, 0.0) +BQhexScalars.InsertValue(14, 0.0) +BQhexScalars.InsertValue(15, 0.0) +BQhexScalars.InsertValue(16, 0.0) +BQhexScalars.InsertValue(17, 0.0) +BQhexScalars.InsertValue(18, 0.0) +BQhexScalars.InsertValue(19, 0.0) +BQhexScalars.InsertValue(20, 0.0) +BQhexScalars.InsertValue(21, 0.0) +BQhexScalars.InsertValue(22, 0.0) +BQhexScalars.InsertValue(23, 0.0) BQHex = vtk.vtkBiQuadraticQuadraticHexahedron() -BQHex.GetPointIds().SetId(0,0) -BQHex.GetPointIds().SetId(1,1) -BQHex.GetPointIds().SetId(2,2) -BQHex.GetPointIds().SetId(3,3) -BQHex.GetPointIds().SetId(4,4) -BQHex.GetPointIds().SetId(5,5) -BQHex.GetPointIds().SetId(6,6) -BQHex.GetPointIds().SetId(7,7) -BQHex.GetPointIds().SetId(8,8) -BQHex.GetPointIds().SetId(9,9) -BQHex.GetPointIds().SetId(10,10) -BQHex.GetPointIds().SetId(11,11) -BQHex.GetPointIds().SetId(12,12) -BQHex.GetPointIds().SetId(13,13) -BQHex.GetPointIds().SetId(14,14) -BQHex.GetPointIds().SetId(15,15) -BQHex.GetPointIds().SetId(16,16) -BQHex.GetPointIds().SetId(17,17) -BQHex.GetPointIds().SetId(18,18) -BQHex.GetPointIds().SetId(19,19) -BQHex.GetPointIds().SetId(20,20) -BQHex.GetPointIds().SetId(21,21) -BQHex.GetPointIds().SetId(22,22) -BQHex.GetPointIds().SetId(23,23) +BQHex.GetPointIds().SetId(0, 0) +BQHex.GetPointIds().SetId(1, 1) +BQHex.GetPointIds().SetId(2, 2) +BQHex.GetPointIds().SetId(3, 3) +BQHex.GetPointIds().SetId(4, 4) +BQHex.GetPointIds().SetId(5, 5) +BQHex.GetPointIds().SetId(6, 6) +BQHex.GetPointIds().SetId(7, 7) +BQHex.GetPointIds().SetId(8, 8) +BQHex.GetPointIds().SetId(9, 9) +BQHex.GetPointIds().SetId(10, 10) +BQHex.GetPointIds().SetId(11, 11) +BQHex.GetPointIds().SetId(12, 12) +BQHex.GetPointIds().SetId(13, 13) +BQHex.GetPointIds().SetId(14, 14) +BQHex.GetPointIds().SetId(15, 15) +BQHex.GetPointIds().SetId(16, 16) +BQHex.GetPointIds().SetId(17, 17) +BQHex.GetPointIds().SetId(18, 18) +BQHex.GetPointIds().SetId(19, 19) +BQHex.GetPointIds().SetId(20, 20) +BQHex.GetPointIds().SetId(21, 21) +BQHex.GetPointIds().SetId(22, 22) +BQHex.GetPointIds().SetId(23, 23) BQHexGrid = vtk.vtkUnstructuredGrid() -BQHexGrid.Allocate(1,1) -BQHexGrid.InsertNextCell(BQHex.GetCellType(),BQHex.GetPointIds()) +BQHexGrid.Allocate(1, 1) +BQHexGrid.InsertNextCell(BQHex.GetCellType(), BQHex.GetPointIds()) BQHexGrid.SetPoints(BQhexPoints) BQHexGrid.GetPointData().SetScalars(BQhexScalars) BQhexContours = vtk.vtkContourFilter() BQhexContours.SetInputData(BQHexGrid) -BQhexContours.SetValue(0,0.5) +BQhexContours.SetValue(0, 0.5) BQHexContourMapper = vtk.vtkDataSetMapper() BQHexContourMapper.SetInputConnection(BQhexContours.GetOutputPort()) BQHexContourMapper.ScalarVisibilityOff() @@ -593,65 +610,66 @@ BQHexActor.GetProperty().SetAmbient(1.0) BQHexContourActor = vtk.vtkActor() BQHexContourActor.SetMapper(BQHexContourMapper) BQHexContourActor.GetProperty().SetAmbient(1.0) + # Quadratic wedge wedgePoints = vtk.vtkPoints() wedgePoints.SetNumberOfPoints(15) -wedgePoints.InsertPoint(0,0,0,0) -wedgePoints.InsertPoint(1,1,0,0) -wedgePoints.InsertPoint(2,0,1,0) -wedgePoints.InsertPoint(3,0,0,1) -wedgePoints.InsertPoint(4,1,0,1) -wedgePoints.InsertPoint(5,0,1,1) -wedgePoints.InsertPoint(6,0.5,0,0) -wedgePoints.InsertPoint(7,0.5,0.5,0) -wedgePoints.InsertPoint(8,0,0.5,0) -wedgePoints.InsertPoint(9,0.5,0,1) -wedgePoints.InsertPoint(10,0.5,0.5,1) -wedgePoints.InsertPoint(11,0,0.5,1) -wedgePoints.InsertPoint(12,0,0,0.5) -wedgePoints.InsertPoint(13,1,0,0.5) -wedgePoints.InsertPoint(14,0,1,0.5) +wedgePoints.InsertPoint(0, 0, 0, 0) +wedgePoints.InsertPoint(1, 1, 0, 0) +wedgePoints.InsertPoint(2, 0, 1, 0) +wedgePoints.InsertPoint(3, 0, 0, 1) +wedgePoints.InsertPoint(4, 1, 0, 1) +wedgePoints.InsertPoint(5, 0, 1, 1) +wedgePoints.InsertPoint(6, 0.5, 0, 0) +wedgePoints.InsertPoint(7, 0.5, 0.5, 0) +wedgePoints.InsertPoint(8, 0, 0.5, 0) +wedgePoints.InsertPoint(9, 0.5, 0, 1) +wedgePoints.InsertPoint(10, 0.5, 0.5, 1) +wedgePoints.InsertPoint(11, 0, 0.5, 1) +wedgePoints.InsertPoint(12, 0, 0, 0.5) +wedgePoints.InsertPoint(13, 1, 0, 0.5) +wedgePoints.InsertPoint(14, 0, 1, 0.5) wedgeScalars = vtk.vtkFloatArray() wedgeScalars.SetNumberOfTuples(15) -wedgeScalars.InsertValue(0,1.0) -wedgeScalars.InsertValue(1,1.0) -wedgeScalars.InsertValue(2,1.0) -wedgeScalars.InsertValue(3,1.0) -wedgeScalars.InsertValue(4,1.0) -wedgeScalars.InsertValue(5,1.0) -wedgeScalars.InsertValue(6,0.0) -wedgeScalars.InsertValue(7,0.0) -wedgeScalars.InsertValue(8,0.0) -wedgeScalars.InsertValue(9,0.0) -wedgeScalars.InsertValue(10,0.0) -wedgeScalars.InsertValue(11,0.0) -wedgeScalars.InsertValue(12,0.0) -wedgeScalars.InsertValue(13,0.0) -wedgeScalars.InsertValue(14,0.0) +wedgeScalars.InsertValue(0, 1.0) +wedgeScalars.InsertValue(1, 1.0) +wedgeScalars.InsertValue(2, 1.0) +wedgeScalars.InsertValue(3, 1.0) +wedgeScalars.InsertValue(4, 1.0) +wedgeScalars.InsertValue(5, 1.0) +wedgeScalars.InsertValue(6, 0.0) +wedgeScalars.InsertValue(7, 0.0) +wedgeScalars.InsertValue(8, 0.0) +wedgeScalars.InsertValue(9, 0.0) +wedgeScalars.InsertValue(10, 0.0) +wedgeScalars.InsertValue(11, 0.0) +wedgeScalars.InsertValue(12, 0.0) +wedgeScalars.InsertValue(13, 0.0) +wedgeScalars.InsertValue(14, 0.0) aWedge = vtk.vtkQuadraticWedge() -aWedge.GetPointIds().SetId(0,0) -aWedge.GetPointIds().SetId(1,1) -aWedge.GetPointIds().SetId(2,2) -aWedge.GetPointIds().SetId(3,3) -aWedge.GetPointIds().SetId(4,4) -aWedge.GetPointIds().SetId(5,5) -aWedge.GetPointIds().SetId(6,6) -aWedge.GetPointIds().SetId(7,7) -aWedge.GetPointIds().SetId(8,8) -aWedge.GetPointIds().SetId(9,9) -aWedge.GetPointIds().SetId(10,10) -aWedge.GetPointIds().SetId(11,11) -aWedge.GetPointIds().SetId(12,12) -aWedge.GetPointIds().SetId(13,13) -aWedge.GetPointIds().SetId(14,14) +aWedge.GetPointIds().SetId(0, 0) +aWedge.GetPointIds().SetId(1, 1) +aWedge.GetPointIds().SetId(2, 2) +aWedge.GetPointIds().SetId(3, 3) +aWedge.GetPointIds().SetId(4, 4) +aWedge.GetPointIds().SetId(5, 5) +aWedge.GetPointIds().SetId(6, 6) +aWedge.GetPointIds().SetId(7, 7) +aWedge.GetPointIds().SetId(8, 8) +aWedge.GetPointIds().SetId(9, 9) +aWedge.GetPointIds().SetId(10, 10) +aWedge.GetPointIds().SetId(11, 11) +aWedge.GetPointIds().SetId(12, 12) +aWedge.GetPointIds().SetId(13, 13) +aWedge.GetPointIds().SetId(14, 14) aWedgeGrid = vtk.vtkUnstructuredGrid() -aWedgeGrid.Allocate(1,1) -aWedgeGrid.InsertNextCell(aWedge.GetCellType(),aWedge.GetPointIds()) +aWedgeGrid.Allocate(1, 1) +aWedgeGrid.InsertNextCell(aWedge.GetCellType(), aWedge.GetPointIds()) aWedgeGrid.SetPoints(wedgePoints) aWedgeGrid.GetPointData().SetScalars(wedgeScalars) wedgeContours = vtk.vtkContourFilter() wedgeContours.SetInputData(aWedgeGrid) -wedgeContours.SetValue(0,0.5) +wedgeContours.SetValue(0, 0.5) aWedgeContourMapper = vtk.vtkDataSetMapper() aWedgeContourMapper.SetInputConnection(wedgeContours.GetOutputPort()) aWedgeContourMapper.ScalarVisibilityOff() @@ -665,57 +683,58 @@ aWedgeActor.GetProperty().SetAmbient(1.0) aWedgeContourActor = vtk.vtkActor() aWedgeContourActor.SetMapper(aWedgeContourMapper) aWedgeContourActor.GetProperty().SetAmbient(1.0) + # Quadratic linear wedge QLwedgePoints = vtk.vtkPoints() QLwedgePoints.SetNumberOfPoints(12) -QLwedgePoints.InsertPoint(0,0,0,0) -QLwedgePoints.InsertPoint(1,1,0,0) -QLwedgePoints.InsertPoint(2,0,1,0) -QLwedgePoints.InsertPoint(3,0,0,1) -QLwedgePoints.InsertPoint(4,1,0,1) -QLwedgePoints.InsertPoint(5,0,1,1) -QLwedgePoints.InsertPoint(6,0.5,0,0) -QLwedgePoints.InsertPoint(7,0.5,0.5,0) -QLwedgePoints.InsertPoint(8,0,0.5,0) -QLwedgePoints.InsertPoint(9,0.5,0,1) -QLwedgePoints.InsertPoint(10,0.5,0.5,1) -QLwedgePoints.InsertPoint(11,0,0.5,1) +QLwedgePoints.InsertPoint(0, 0, 0, 0) +QLwedgePoints.InsertPoint(1, 1, 0, 0) +QLwedgePoints.InsertPoint(2, 0, 1, 0) +QLwedgePoints.InsertPoint(3, 0, 0, 1) +QLwedgePoints.InsertPoint(4, 1, 0, 1) +QLwedgePoints.InsertPoint(5, 0, 1, 1) +QLwedgePoints.InsertPoint(6, 0.5, 0, 0) +QLwedgePoints.InsertPoint(7, 0.5, 0.5, 0) +QLwedgePoints.InsertPoint(8, 0, 0.5, 0) +QLwedgePoints.InsertPoint(9, 0.5, 0, 1) +QLwedgePoints.InsertPoint(10, 0.5, 0.5, 1) +QLwedgePoints.InsertPoint(11, 0, 0.5, 1) QLwedgeScalars = vtk.vtkFloatArray() QLwedgeScalars.SetNumberOfTuples(12) -QLwedgeScalars.InsertValue(0,1.0) -QLwedgeScalars.InsertValue(1,1.0) -QLwedgeScalars.InsertValue(2,1.0) -QLwedgeScalars.InsertValue(3,1.0) -QLwedgeScalars.InsertValue(4,1.0) -QLwedgeScalars.InsertValue(5,1.0) -QLwedgeScalars.InsertValue(6,0.0) -QLwedgeScalars.InsertValue(7,0.0) -QLwedgeScalars.InsertValue(8,0.0) -QLwedgeScalars.InsertValue(9,0.0) -QLwedgeScalars.InsertValue(10,0.0) -QLwedgeScalars.InsertValue(11,0.0) +QLwedgeScalars.InsertValue(0, 1.0) +QLwedgeScalars.InsertValue(1, 1.0) +QLwedgeScalars.InsertValue(2, 1.0) +QLwedgeScalars.InsertValue(3, 1.0) +QLwedgeScalars.InsertValue(4, 1.0) +QLwedgeScalars.InsertValue(5, 1.0) +QLwedgeScalars.InsertValue(6, 0.0) +QLwedgeScalars.InsertValue(7, 0.0) +QLwedgeScalars.InsertValue(8, 0.0) +QLwedgeScalars.InsertValue(9, 0.0) +QLwedgeScalars.InsertValue(10, 0.0) +QLwedgeScalars.InsertValue(11, 0.0) QLWedge = vtk.vtkQuadraticLinearWedge() -QLWedge.GetPointIds().SetId(0,0) -QLWedge.GetPointIds().SetId(1,1) -QLWedge.GetPointIds().SetId(2,2) -QLWedge.GetPointIds().SetId(3,3) -QLWedge.GetPointIds().SetId(4,4) -QLWedge.GetPointIds().SetId(5,5) -QLWedge.GetPointIds().SetId(6,6) -QLWedge.GetPointIds().SetId(7,7) -QLWedge.GetPointIds().SetId(8,8) -QLWedge.GetPointIds().SetId(9,9) -QLWedge.GetPointIds().SetId(10,10) -QLWedge.GetPointIds().SetId(11,11) -#QLaWedge DebugOn +QLWedge.GetPointIds().SetId(0, 0) +QLWedge.GetPointIds().SetId(1, 1) +QLWedge.GetPointIds().SetId(2, 2) +QLWedge.GetPointIds().SetId(3, 3) +QLWedge.GetPointIds().SetId(4, 4) +QLWedge.GetPointIds().SetId(5, 5) +QLWedge.GetPointIds().SetId(6, 6) +QLWedge.GetPointIds().SetId(7, 7) +QLWedge.GetPointIds().SetId(8, 8) +QLWedge.GetPointIds().SetId(9, 9) +QLWedge.GetPointIds().SetId(10, 10) +QLWedge.GetPointIds().SetId(11, 11) +# QLWedge.DebugOn() QLWedgeGrid = vtk.vtkUnstructuredGrid() -QLWedgeGrid.Allocate(1,1) -QLWedgeGrid.InsertNextCell(QLWedge.GetCellType(),QLWedge.GetPointIds()) +QLWedgeGrid.Allocate(1, 1) +QLWedgeGrid.InsertNextCell(QLWedge.GetCellType(), QLWedge.GetPointIds()) QLWedgeGrid.SetPoints(QLwedgePoints) QLWedgeGrid.GetPointData().SetScalars(QLwedgeScalars) QLwedgeContours = vtk.vtkContourFilter() QLwedgeContours.SetInputData(QLWedgeGrid) -QLwedgeContours.SetValue(0,0.5) +QLwedgeContours.SetValue(0, 0.5) QLWedgeContourMapper = vtk.vtkDataSetMapper() QLWedgeContourMapper.SetInputConnection(QLwedgeContours.GetOutputPort()) QLWedgeContourMapper.ScalarVisibilityOff() @@ -729,81 +748,82 @@ QLWedgeActor.GetProperty().SetAmbient(1.0) QLWedgeContourActor = vtk.vtkActor() QLWedgeContourActor.SetMapper(QLWedgeContourMapper) QLWedgeContourActor.GetProperty().SetAmbient(1.0) + # BiQuadratic wedge BQwedgePoints = vtk.vtkPoints() BQwedgePoints.SetNumberOfPoints(18) -BQwedgePoints.InsertPoint(0,0,0,0) -BQwedgePoints.InsertPoint(1,1,0,0) -BQwedgePoints.InsertPoint(2,0,1,0) -BQwedgePoints.InsertPoint(3,0,0,1) -BQwedgePoints.InsertPoint(4,1,0,1) -BQwedgePoints.InsertPoint(5,0,1,1) -BQwedgePoints.InsertPoint(6,0.5,0,0) -BQwedgePoints.InsertPoint(7,0.5,0.5,0) -BQwedgePoints.InsertPoint(8,0,0.5,0) -BQwedgePoints.InsertPoint(9,0.5,0,1) -BQwedgePoints.InsertPoint(10,0.5,0.5,1) -BQwedgePoints.InsertPoint(11,0,0.5,1) -BQwedgePoints.InsertPoint(12,0,0,0.5) -BQwedgePoints.InsertPoint(13,1,0,0.5) -BQwedgePoints.InsertPoint(14,0,1,0.5) -BQwedgePoints.InsertPoint(15,0.5,0,0.5) -BQwedgePoints.InsertPoint(16,0.5,0.5,0.5) -BQwedgePoints.InsertPoint(17,0,0.5,0.5) +BQwedgePoints.InsertPoint(0, 0, 0, 0) +BQwedgePoints.InsertPoint(1, 1, 0, 0) +BQwedgePoints.InsertPoint(2, 0, 1, 0) +BQwedgePoints.InsertPoint(3, 0, 0, 1) +BQwedgePoints.InsertPoint(4, 1, 0, 1) +BQwedgePoints.InsertPoint(5, 0, 1, 1) +BQwedgePoints.InsertPoint(6, 0.5, 0, 0) +BQwedgePoints.InsertPoint(7, 0.5, 0.5, 0) +BQwedgePoints.InsertPoint(8, 0, 0.5, 0) +BQwedgePoints.InsertPoint(9, 0.5, 0, 1) +BQwedgePoints.InsertPoint(10, 0.5, 0.5, 1) +BQwedgePoints.InsertPoint(11, 0, 0.5, 1) +BQwedgePoints.InsertPoint(12, 0, 0, 0.5) +BQwedgePoints.InsertPoint(13, 1, 0, 0.5) +BQwedgePoints.InsertPoint(14, 0, 1, 0.5) +BQwedgePoints.InsertPoint(15, 0.5, 0, 0.5) +BQwedgePoints.InsertPoint(16, 0.5, 0.5, 0.5) +BQwedgePoints.InsertPoint(17, 0, 0.5, 0.5) BQwedgeScalars = vtk.vtkFloatArray() BQwedgeScalars.SetNumberOfTuples(18) -BQwedgeScalars.InsertValue(0,1.0) -BQwedgeScalars.InsertValue(1,1.0) -BQwedgeScalars.InsertValue(2,1.0) -BQwedgeScalars.InsertValue(3,1.0) -BQwedgeScalars.InsertValue(4,1.0) -BQwedgeScalars.InsertValue(5,1.0) -BQwedgeScalars.InsertValue(6,0.0) -BQwedgeScalars.InsertValue(7,0.0) -BQwedgeScalars.InsertValue(8,0.0) -BQwedgeScalars.InsertValue(9,0.0) -BQwedgeScalars.InsertValue(10,0.0) -BQwedgeScalars.InsertValue(11,0.0) -BQwedgeScalars.InsertValue(12,0.0) -BQwedgeScalars.InsertValue(13,0.0) -BQwedgeScalars.InsertValue(14,0.0) -BQwedgeScalars.InsertValue(15,0.0) -BQwedgeScalars.InsertValue(16,0.0) -BQwedgeScalars.InsertValue(17,0.0) +BQwedgeScalars.InsertValue(0, 1.0) +BQwedgeScalars.InsertValue(1, 1.0) +BQwedgeScalars.InsertValue(2, 1.0) +BQwedgeScalars.InsertValue(3, 1.0) +BQwedgeScalars.InsertValue(4, 1.0) +BQwedgeScalars.InsertValue(5, 1.0) +BQwedgeScalars.InsertValue(6, 0.0) +BQwedgeScalars.InsertValue(7, 0.0) +BQwedgeScalars.InsertValue(8, 0.0) +BQwedgeScalars.InsertValue(9, 0.0) +BQwedgeScalars.InsertValue(10, 0.0) +BQwedgeScalars.InsertValue(11, 0.0) +BQwedgeScalars.InsertValue(12, 0.0) +BQwedgeScalars.InsertValue(13, 0.0) +BQwedgeScalars.InsertValue(14, 0.0) +BQwedgeScalars.InsertValue(15, 0.0) +BQwedgeScalars.InsertValue(16, 0.0) +BQwedgeScalars.InsertValue(17, 0.0) BQWedge = vtk.vtkBiQuadraticQuadraticWedge() -BQWedge.GetPointIds().SetId(0,0) -BQWedge.GetPointIds().SetId(1,1) -BQWedge.GetPointIds().SetId(2,2) -BQWedge.GetPointIds().SetId(3,3) -BQWedge.GetPointIds().SetId(4,4) -BQWedge.GetPointIds().SetId(5,5) -BQWedge.GetPointIds().SetId(6,6) -BQWedge.GetPointIds().SetId(7,7) -BQWedge.GetPointIds().SetId(8,8) -BQWedge.GetPointIds().SetId(9,9) -BQWedge.GetPointIds().SetId(10,10) -BQWedge.GetPointIds().SetId(11,11) -BQWedge.GetPointIds().SetId(12,12) -BQWedge.GetPointIds().SetId(13,13) -BQWedge.GetPointIds().SetId(14,14) -BQWedge.GetPointIds().SetId(15,15) -BQWedge.GetPointIds().SetId(16,16) -BQWedge.GetPointIds().SetId(17,17) -#BQWedge DebugOn +BQWedge.GetPointIds().SetId(0, 0) +BQWedge.GetPointIds().SetId(1, 1) +BQWedge.GetPointIds().SetId(2, 2) +BQWedge.GetPointIds().SetId(3, 3) +BQWedge.GetPointIds().SetId(4, 4) +BQWedge.GetPointIds().SetId(5, 5) +BQWedge.GetPointIds().SetId(6, 6) +BQWedge.GetPointIds().SetId(7, 7) +BQWedge.GetPointIds().SetId(8, 8) +BQWedge.GetPointIds().SetId(9, 9) +BQWedge.GetPointIds().SetId(10, 10) +BQWedge.GetPointIds().SetId(11, 11) +BQWedge.GetPointIds().SetId(12, 12) +BQWedge.GetPointIds().SetId(13, 13) +BQWedge.GetPointIds().SetId(14, 14) +BQWedge.GetPointIds().SetId(15, 15) +BQWedge.GetPointIds().SetId(16, 16) +BQWedge.GetPointIds().SetId(17, 17) +# BQWedge.DebugOn() BQWedgeGrid = vtk.vtkUnstructuredGrid() -BQWedgeGrid.Allocate(1,1) -BQWedgeGrid.InsertNextCell(BQWedge.GetCellType(),BQWedge.GetPointIds()) +BQWedgeGrid.Allocate(1, 1) +BQWedgeGrid.InsertNextCell(BQWedge.GetCellType(), BQWedge.GetPointIds()) BQWedgeGrid.SetPoints(BQwedgePoints) BQWedgeGrid.GetPointData().SetScalars(BQwedgeScalars) BQwedgeContours = vtk.vtkContourFilter() BQwedgeContours.SetInputData(BQWedgeGrid) -BQwedgeContours.SetValue(0,0.5) +BQwedgeContours.SetValue(0, 0.5) BQWedgeContourMapper = vtk.vtkDataSetMapper() BQWedgeContourMapper.SetInputConnection(BQwedgeContours.GetOutputPort()) -#BQWedgeContourMapper ScalarVisibilityOff +# BQWedgeContourMapper.ScalarVisibilityOff() BQWedgeMapper = vtk.vtkDataSetMapper() BQWedgeMapper.SetInputData(BQWedgeGrid) -#BQWedgeMapper ScalarVisibilityOff +# BQWedgeMapper.ScalarVisibilityOff() BQWedgeActor = vtk.vtkActor() BQWedgeActor.SetMapper(BQWedgeMapper) BQWedgeActor.GetProperty().SetRepresentationToWireframe() @@ -811,59 +831,60 @@ BQWedgeActor.GetProperty().SetAmbient(1.0) BQWedgeContourActor = vtk.vtkActor() BQWedgeContourActor.SetMapper(BQWedgeContourMapper) BQWedgeContourActor.GetProperty().SetAmbient(1.0) + # Quadratic pyramid pyraPoints = vtk.vtkPoints() pyraPoints.SetNumberOfPoints(13) -pyraPoints.InsertPoint(0,0,0,0) -pyraPoints.InsertPoint(1,1,0,0) -pyraPoints.InsertPoint(2,1,1,0) -pyraPoints.InsertPoint(3,0,1,0) -pyraPoints.InsertPoint(4,0,0,1) -pyraPoints.InsertPoint(5,0.5,0,0) -pyraPoints.InsertPoint(6,1,0.5,0) -pyraPoints.InsertPoint(7,0.5,1,0) -pyraPoints.InsertPoint(8,0,0.5,0) -pyraPoints.InsertPoint(9,0,0,0.5) -pyraPoints.InsertPoint(10,0.5,0,0.5) -pyraPoints.InsertPoint(11,0.5,0.5,0.5) -pyraPoints.InsertPoint(12,0,0.5,0.5) +pyraPoints.InsertPoint(0, 0, 0, 0) +pyraPoints.InsertPoint(1, 1, 0, 0) +pyraPoints.InsertPoint(2, 1, 1, 0) +pyraPoints.InsertPoint(3, 0, 1, 0) +pyraPoints.InsertPoint(4, 0, 0, 1) +pyraPoints.InsertPoint(5, 0.5, 0, 0) +pyraPoints.InsertPoint(6, 1, 0.5, 0) +pyraPoints.InsertPoint(7, 0.5, 1, 0) +pyraPoints.InsertPoint(8, 0, 0.5, 0) +pyraPoints.InsertPoint(9, 0, 0, 0.5) +pyraPoints.InsertPoint(10, 0.5, 0, 0.5) +pyraPoints.InsertPoint(11, 0.5, 0.5, 0.5) +pyraPoints.InsertPoint(12, 0, 0.5, 0.5) pyraScalars = vtk.vtkFloatArray() pyraScalars.SetNumberOfTuples(13) -pyraScalars.InsertValue(0,1.0) -pyraScalars.InsertValue(1,1.0) -pyraScalars.InsertValue(2,1.0) -pyraScalars.InsertValue(3,1.0) -pyraScalars.InsertValue(4,1.0) -pyraScalars.InsertValue(5,0.0) -pyraScalars.InsertValue(6,0.0) -pyraScalars.InsertValue(7,0.0) -pyraScalars.InsertValue(8,0.0) -pyraScalars.InsertValue(9,0.0) -pyraScalars.InsertValue(10,0.0) -pyraScalars.InsertValue(11,0.0) -pyraScalars.InsertValue(12,0.0) +pyraScalars.InsertValue(0, 1.0) +pyraScalars.InsertValue(1, 1.0) +pyraScalars.InsertValue(2, 1.0) +pyraScalars.InsertValue(3, 1.0) +pyraScalars.InsertValue(4, 1.0) +pyraScalars.InsertValue(5, 0.0) +pyraScalars.InsertValue(6, 0.0) +pyraScalars.InsertValue(7, 0.0) +pyraScalars.InsertValue(8, 0.0) +pyraScalars.InsertValue(9, 0.0) +pyraScalars.InsertValue(10, 0.0) +pyraScalars.InsertValue(11, 0.0) +pyraScalars.InsertValue(12, 0.0) aPyramid = vtk.vtkQuadraticPyramid() -aPyramid.GetPointIds().SetId(0,0) -aPyramid.GetPointIds().SetId(1,1) -aPyramid.GetPointIds().SetId(2,2) -aPyramid.GetPointIds().SetId(3,3) -aPyramid.GetPointIds().SetId(4,4) -aPyramid.GetPointIds().SetId(5,5) -aPyramid.GetPointIds().SetId(6,6) -aPyramid.GetPointIds().SetId(7,7) -aPyramid.GetPointIds().SetId(8,8) -aPyramid.GetPointIds().SetId(9,9) -aPyramid.GetPointIds().SetId(10,10) -aPyramid.GetPointIds().SetId(11,11) -aPyramid.GetPointIds().SetId(12,12) +aPyramid.GetPointIds().SetId(0, 0) +aPyramid.GetPointIds().SetId(1, 1) +aPyramid.GetPointIds().SetId(2, 2) +aPyramid.GetPointIds().SetId(3, 3) +aPyramid.GetPointIds().SetId(4, 4) +aPyramid.GetPointIds().SetId(5, 5) +aPyramid.GetPointIds().SetId(6, 6) +aPyramid.GetPointIds().SetId(7, 7) +aPyramid.GetPointIds().SetId(8, 8) +aPyramid.GetPointIds().SetId(9, 9) +aPyramid.GetPointIds().SetId(10, 10) +aPyramid.GetPointIds().SetId(11, 11) +aPyramid.GetPointIds().SetId(12, 12) aPyramidGrid = vtk.vtkUnstructuredGrid() -aPyramidGrid.Allocate(1,1) -aPyramidGrid.InsertNextCell(aPyramid.GetCellType(),aPyramid.GetPointIds()) +aPyramidGrid.Allocate(1, 1) +aPyramidGrid.InsertNextCell(aPyramid.GetCellType(), aPyramid.GetPointIds()) aPyramidGrid.SetPoints(pyraPoints) aPyramidGrid.GetPointData().SetScalars(pyraScalars) pyraContours = vtk.vtkContourFilter() pyraContours.SetInputData(aPyramidGrid) -pyraContours.SetValue(0,0.5) +pyraContours.SetValue(0, 0.5) aPyramidContourMapper = vtk.vtkDataSetMapper() aPyramidContourMapper.SetInputConnection(pyraContours.GetOutputPort()) aPyramidContourMapper.ScalarVisibilityOff() @@ -877,6 +898,7 @@ aPyramidActor.GetProperty().SetAmbient(1.0) aPyramidContourActor = vtk.vtkActor() aPyramidContourActor.SetMapper(aPyramidContourMapper) aPyramidContourActor.GetProperty().SetAmbient(1.0) + # Create the rendering related stuff. # Since some of our actors are a single vertex, we need to remove all # cullers so the single vertex actors will render @@ -886,73 +908,95 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) -ren1.SetBackground(.1,.2,.3) -renWin.SetSize(400,200) + +ren1.SetBackground(.1, .2, .3) + +renWin.SetSize(400, 200) + # specify properties ren1.AddActor(aEdgeActor) ren1.AddActor(aEdgeContourActor) + ren1.AddActor(aTriActor) ren1.AddActor(aTriContourActor) + ren1.AddActor(aQuadActor) ren1.AddActor(aQuadContourActor) + ren1.AddActor(BQuadActor) ren1.AddActor(BQuadContourActor) + ren1.AddActor(QLQuadActor) ren1.AddActor(QLQuadContourActor) + ren1.AddActor(aTetActor) ren1.AddActor(aTetContourActor) + ren1.AddActor(aHexActor) ren1.AddActor(aHexContourActor) + ren1.AddActor(TQHexActor) ren1.AddActor(TQHexContourActor) + ren1.AddActor(BQHexActor) ren1.AddActor(BQHexContourActor) + ren1.AddActor(aWedgeActor) ren1.AddActor(aWedgeContourActor) + ren1.AddActor(BQWedgeActor) ren1.AddActor(BQWedgeContourActor) + ren1.AddActor(QLWedgeActor) ren1.AddActor(QLWedgeContourActor) + ren1.AddActor(aPyramidActor) ren1.AddActor(aPyramidContourActor) + # places everyone!! -aEdgeContourActor.AddPosition(0,2,0) -aTriActor.AddPosition(2,0,0) -aTriContourActor.AddPosition(2,2,0) -aQuadActor.AddPosition(4,0,0) -BQuadActor.AddPosition(4,0,2) -QLQuadActor.AddPosition(4,0,4) -aQuadContourActor.AddPosition(4,2,0) -BQuadContourActor.AddPosition(4,2,2) -QLQuadContourActor.AddPosition(4,2,4) -aTetActor.AddPosition(6,0,0) -aTetContourActor.AddPosition(6,2,0) -aHexActor.AddPosition(8,0,0) -TQHexActor.AddPosition(8,0,2) -BQHexActor.AddPosition(8,0,4) -aHexContourActor.AddPosition(8,2,0) -TQHexContourActor.AddPosition(8,2,2) -BQHexContourActor.AddPosition(8,2,4) -aWedgeActor.AddPosition(10,0,0) -QLWedgeActor.AddPosition(10,0,2) -BQWedgeActor.AddPosition(10,0,4) -aWedgeContourActor.AddPosition(10,2,0) -QLWedgeContourActor.AddPosition(10,2,2) -BQWedgeContourActor.AddPosition(10,2,4) -aPyramidActor.AddPosition(12,0,0) -aPyramidContourActor.AddPosition(12,2,0) -[base, back, left] = BuildBackdrop(-1, 15, -1, 4, -1, 6, .1) +aEdgeContourActor.AddPosition(0, 2, 0) +aTriActor.AddPosition(2, 0, 0) +aTriContourActor.AddPosition(2, 2, 0) +aQuadActor.AddPosition(4, 0, 0) +BQuadActor.AddPosition(4, 0, 2) +QLQuadActor.AddPosition(4, 0, 4) +aQuadContourActor.AddPosition(4, 2, 0) +BQuadContourActor.AddPosition(4, 2, 2) +QLQuadContourActor.AddPosition(4, 2, 4) +aTetActor.AddPosition(6, 0, 0) +aTetContourActor.AddPosition(6, 2, 0) +aHexActor.AddPosition(8, 0, 0) +TQHexActor.AddPosition(8, 0, 2) +BQHexActor.AddPosition(8, 0, 4) +aHexContourActor.AddPosition(8, 2, 0) +TQHexContourActor.AddPosition(8, 2, 2) +BQHexContourActor.AddPosition(8, 2, 4) +aWedgeActor.AddPosition(10, 0, 0) +QLWedgeActor.AddPosition(10, 0, 2) +BQWedgeActor.AddPosition(10, 0, 4) +aWedgeContourActor.AddPosition(10, 2, 0) +QLWedgeContourActor.AddPosition(10, 2, 2) +BQWedgeContourActor.AddPosition(10, 2, 4) +aPyramidActor.AddPosition(12, 0, 0) +aPyramidContourActor.AddPosition(12, 2, 0) + +[base, back, left] = backdrop.BuildBackdrop(-1, 15, -1, 4, -1, 6, .1) + ren1.AddActor(base) -base.GetProperty().SetDiffuseColor(.2,.2,.2) +base.GetProperty().SetDiffuseColor(.2, .2, .2) ren1.AddActor(left) -left.GetProperty().SetDiffuseColor(.2,.2,.2) +left.GetProperty().SetDiffuseColor(.2, .2, .2) ren1.AddActor(back) -back.GetProperty().SetDiffuseColor(.2,.2,.2) +back.GetProperty().SetDiffuseColor(.2, .2, .2) + ren1.ResetCamera() ren1.GetActiveCamera().Dolly(2.5) ren1.ResetCameraClippingRange() + renWin.Render() + # render the image # + iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Filters/Core/Testing/Python/cutLoop.py b/Filters/Core/Testing/Python/cutLoop.py index 1fe780a7097..f7393aaa039 100755 --- a/Filters/Core/Testing/Python/cutLoop.py +++ b/Filters/Core/Testing/Python/cutLoop.py @@ -4,65 +4,83 @@ 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 + # Define loop to clip with # selectionPoints = vtk.vtkPoints() -selectionPoints.InsertPoint(0,-0.16553,0.135971,0.451972) -selectionPoints.InsertPoint(1,-0.0880123,-0.134952,0.4747) -selectionPoints.InsertPoint(2,0.00292618,-0.134604,0.482459) -selectionPoints.InsertPoint(3,0.0641941,0.067112,0.490947) -selectionPoints.InsertPoint(4,0.15577,0.0734765,0.469245) -selectionPoints.InsertPoint(5,0.166667,-0.129217,0.454622) -selectionPoints.InsertPoint(6,0.241259,-0.123363,0.420581) -selectionPoints.InsertPoint(7,0.240334,0.0727106,0.432555) -selectionPoints.InsertPoint(8,0.308529,0.0844311,0.384357) -selectionPoints.InsertPoint(9,0.32672,-0.121674,0.359187) -selectionPoints.InsertPoint(10,0.380721,-0.117342,0.302527) -selectionPoints.InsertPoint(11,0.387804,0.0455074,0.312375) -selectionPoints.InsertPoint(12,0.43943,-0.111673,0.211707) -selectionPoints.InsertPoint(13,0.470984,-0.0801913,0.147919) -selectionPoints.InsertPoint(14,0.436777,0.0688872,0.233021) -selectionPoints.InsertPoint(15,0.44874,0.188852,0.109882) -selectionPoints.InsertPoint(16,0.391352,0.254285,0.176943) -selectionPoints.InsertPoint(17,0.373274,0.154162,0.294296) -selectionPoints.InsertPoint(18,0.274659,0.311654,0.276609) -selectionPoints.InsertPoint(19,0.206068,0.31396,0.329702) -selectionPoints.InsertPoint(20,0.263789,0.174982,0.387308) -selectionPoints.InsertPoint(21,0.213034,0.175485,0.417142) -selectionPoints.InsertPoint(22,0.169113,0.261974,0.390286) -selectionPoints.InsertPoint(23,0.102552,0.25997,0.414814) -selectionPoints.InsertPoint(24,0.131512,0.161254,0.454705) -selectionPoints.InsertPoint(25,0.000192443,0.156264,0.475307) -selectionPoints.InsertPoint(26,-0.0392091,0.000251724,0.499943) -selectionPoints.InsertPoint(27,-0.096161,0.159646,0.46438) +selectionPoints.InsertPoint(0, -0.16553, 0.135971, 0.451972) +selectionPoints.InsertPoint(1, -0.0880123, -0.134952, 0.4747) +selectionPoints.InsertPoint(2, 0.00292618, -0.134604, 0.482459) +selectionPoints.InsertPoint(3, 0.0641941, 0.067112, 0.490947) +selectionPoints.InsertPoint(4, 0.15577, 0.0734765, 0.469245) +selectionPoints.InsertPoint(5, 0.166667, -0.129217, 0.454622) +selectionPoints.InsertPoint(6, 0.241259, -0.123363, 0.420581) +selectionPoints.InsertPoint(7, 0.240334, 0.0727106, 0.432555) +selectionPoints.InsertPoint(8, 0.308529, 0.0844311, 0.384357) +selectionPoints.InsertPoint(9, 0.32672, -0.121674, 0.359187) +selectionPoints.InsertPoint(10, 0.380721, -0.117342, 0.302527) +selectionPoints.InsertPoint(11, 0.387804, 0.0455074, 0.312375) +selectionPoints.InsertPoint(12, 0.43943, -0.111673, 0.211707) +selectionPoints.InsertPoint(13, 0.470984, -0.0801913, 0.147919) +selectionPoints.InsertPoint(14, 0.436777, 0.0688872, 0.233021) +selectionPoints.InsertPoint(15, 0.44874, 0.188852, 0.109882) +selectionPoints.InsertPoint(16, 0.391352, 0.254285, 0.176943) +selectionPoints.InsertPoint(17, 0.373274, 0.154162, 0.294296) +selectionPoints.InsertPoint(18, 0.274659, 0.311654, 0.276609) +selectionPoints.InsertPoint(19, 0.206068, 0.31396, 0.329702) +selectionPoints.InsertPoint(20, 0.263789, 0.174982, 0.387308) +selectionPoints.InsertPoint(21, 0.213034, 0.175485, 0.417142) +selectionPoints.InsertPoint(22, 0.169113, 0.261974, 0.390286) +selectionPoints.InsertPoint(23, 0.102552, 0.25997, 0.414814) +selectionPoints.InsertPoint(24, 0.131512, 0.161254, 0.454705) +selectionPoints.InsertPoint(25, 0.000192443, 0.156264, 0.475307) +selectionPoints.InsertPoint(26, -0.0392091, 0.000251724, 0.499943) +selectionPoints.InsertPoint(27, -0.096161, 0.159646, 0.46438) + sphere = vtk.vtkSphereSource() sphere.SetPhiResolution(50) sphere.SetThetaResolution(100) sphere.SetStartPhi(0) sphere.SetEndPhi(90) + loop = vtk.vtkSelectPolyData() loop.SetInputConnection(sphere.GetOutputPort()) loop.SetLoop(selectionPoints) loop.GenerateSelectionScalarsOn() +# negative scalars inside loop.SetSelectionModeToSmallestRegion() -#negative scalars inside + +# clips out positive region clip = vtk.vtkClipPolyData() -#clips out positive region clip.SetInputConnection(loop.GetOutputPort()) + clipMapper = vtk.vtkPolyDataMapper() clipMapper.SetInputConnection(clip.GetOutputPort()) + clipActor = vtk.vtkLODActor() clipActor.SetMapper(clipMapper) + loop2 = vtk.vtkSelectPolyData() loop2.SetInputConnection(sphere.GetOutputPort()) loop2.SetLoop(selectionPoints) loop2.SetSelectionModeToSmallestRegion() + selectMapper = vtk.vtkPolyDataMapper() selectMapper.SetInputConnection(loop2.GetOutputPort()) + selectActor = vtk.vtkLODActor() selectActor.SetMapper(selectMapper) -selectActor.AddPosition(1,0,0) -selectActor.GetProperty().SetColor(peacock) +selectActor.AddPosition(1, 0, 0) +selectActor.GetProperty().SetColor(GetRGBColor('peacock')) + # Create graphics stuff # ren1 = vtk.vtkRenderer() @@ -70,19 +88,22 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(clipActor) ren1.AddActor(selectActor) -ren1.SetBackground(.1,.2,.4) -renWin.SetSize(500,250) +ren1.SetBackground(.1, .2, .4) + +renWin.SetSize(500, 250) + cam1 = ren1.GetActiveCamera() -cam1.SetClippingRange(0.236644,11.8322) -cam1.SetFocalPoint(0.542809,-0.0166201,0.183931) -cam1.SetPosition(1.65945,0.364443,2.29141) -cam1.SetViewUp(-0.0746604,0.986933,-0.14279) +cam1.SetClippingRange(0.236644, 11.8322) +cam1.SetFocalPoint(0.542809, -0.0166201, 0.183931) +cam1.SetPosition(1.65945, 0.364443, 2.29141) +cam1.SetViewUp(-0.0746604, 0.986933, -0.14279) + iren.Initialize() + # render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Core/Testing/Python/dispPlot.py b/Filters/Core/Testing/Python/dispPlot.py index 41130b5dfe6..03a1b3e22c1 100755 --- a/Filters/Core/Testing/Python/dispPlot.py +++ b/Filters/Core/Testing/Python/dispPlot.py @@ -10,49 +10,61 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # read a vtk file # plate = vtk.vtkPolyDataReader() -plate.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/plate.vtk") +plate.SetFileName(VTK_DATA_ROOT + "/Data/plate.vtk") plate.SetVectorsName("mode8") + warp = vtk.vtkWarpVector() warp.SetInputConnection(plate.GetOutputPort()) warp.SetScaleFactor(0.5) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(warp.GetOutputPort()) + color = vtk.vtkVectorDot() color.SetInputConnection(normals.GetOutputPort()) + lut = vtk.vtkLookupTable() lut.SetNumberOfColors(256) lut.Build() + i = 0 while i < 128: - lut.SetTableValue(i,expr.expr(globals(), locals(),["(","128.0","-i",")/","128.0"]),expr.expr(globals(), locals(),["(","128.0","-i",")/","128.0"]),expr.expr(globals(), locals(),["(","128.0","-i",")/","128.0"]),1) - i = i + 1 + lut.SetTableValue(i, (128.0 - i) / 128.0, (128.0 - i) / 128.0, + (128.0 - i) / 128.0, 1) + i += 1 i = 128 while i < 256: - lut.SetTableValue(i,expr.expr(globals(), locals(),["(","i","-128.0",")/","128.0"]),expr.expr(globals(), locals(),["(","i","-128.0",")/","128.0"]),expr.expr(globals(), locals(),["(","i","-128.0",")/","128.0"]),1) - i = i + 1 + lut.SetTableValue(i, (i - 128.0) / 128.0, (i - 128.0) / 128.0, + (i - 128.0) / 128.0, 1) + i += 1 plateMapper = vtk.vtkDataSetMapper() plateMapper.SetInputConnection(color.GetOutputPort()) plateMapper.SetLookupTable(lut) -plateMapper.SetScalarRange(-1,1) +plateMapper.SetScalarRange(-1, 1) + plateActor = vtk.vtkActor() plateActor.SetMapper(plateMapper) + # Add the actors to the renderer, set the background and size # ren1.AddActor(plateActor) -ren1.SetBackground(1,1,1) -renWin.SetSize(250,250) -ren1.GetActiveCamera().SetPosition(13.3991,14.0764,9.97787) -ren1.GetActiveCamera().SetFocalPoint(1.50437,0.481517,4.52992) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(250, 250) + +ren1.GetActiveCamera().SetPosition(13.3991, 14.0764, 9.97787) +ren1.GetActiveCamera().SetFocalPoint(1.50437, 0.481517, 4.52992) ren1.GetActiveCamera().SetViewAngle(30) -ren1.GetActiveCamera().SetViewUp(-0.120861,0.458556,-0.880408) -ren1.GetActiveCamera().SetClippingRange(12.5724,26.8374) +ren1.GetActiveCamera().SetViewUp(-0.120861, 0.458556, -0.880408) +ren1.GetActiveCamera().SetClippingRange(12.5724, 26.8374) + # render the image # iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Core/Testing/Python/fieldToPolyData.py b/Filters/Core/Testing/Python/fieldToPolyData.py index 4162d9e1f94..d05110eb079 100755 --- a/Filters/Core/Testing/Python/fieldToPolyData.py +++ b/Filters/Core/Testing/Python/fieldToPolyData.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot @@ -6,60 +7,83 @@ VTK_DATA_ROOT = vtkGetDataRoot() # This example demonstrates the reading of a field and conversion to PolyData # The output should be the same as polyEx.tcl. -# get the interactor ui + # Create a reader and write out the field reader = vtk.vtkPolyDataReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/polyEx.vtk") +reader.SetFileName(VTK_DATA_ROOT + "/Data/polyEx.vtk") + ds2do = vtk.vtkDataSetToDataObjectFilter() ds2do.SetInputConnection(reader.GetOutputPort()) -if (catch.catch(globals(),"""channel = open("PolyField.vtk", "w")""") == 0): + +# NOTE: This test only works if the current directory is writable +# +try: + channel = open("PolyField.vtk", "wb") channel.close() + writer = vtk.vtkDataObjectWriter() writer.SetInputConnection(ds2do.GetOutputPort()) writer.SetFileName("PolyField.vtk") writer.Write() + # create pipeline # dor = vtk.vtkDataObjectReader() dor.SetFileName("PolyField.vtk") + do2ds = vtk.vtkDataObjectToDataSetFilter() do2ds.SetInputConnection(dor.GetOutputPort()) do2ds.SetDataSetTypeToPolyData() - do2ds.SetPointComponent(0,"Points",0) - do2ds.SetPointComponent(1,"Points",1) - do2ds.SetPointComponent(2,"Points",2) - do2ds.SetPolysComponent("Polys",0) + do2ds.SetPointComponent(0, "Points", 0) + do2ds.SetPointComponent(1, "Points", 1) + do2ds.SetPointComponent(2, "Points", 2) + do2ds.SetPolysComponent("Polys", 0) + fd2ad = vtk.vtkFieldDataToAttributeDataFilter() fd2ad.SetInputConnection(do2ds.GetOutputPort()) fd2ad.SetInputFieldToDataObjectField() fd2ad.SetOutputAttributeDataToPointData() - fd2ad.SetScalarComponent(0,"my_scalars",0) + fd2ad.SetScalarComponent(0, "my_scalars", 0) + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(fd2ad.GetOutputPort()) mapper.SetScalarRange(fd2ad.GetOutput().GetScalarRange()) + actor = vtk.vtkActor() actor.SetMapper(mapper) + # Create the RenderWindow, Renderer and both Actors ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + ren1.AddActor(actor) - ren1.SetBackground(1,1,1) - renWin.SetSize(300,300) + ren1.SetBackground(1, 1, 1) + + renWin.SetSize(300, 300) + ren1.ResetCamera() cam1 = ren1.GetActiveCamera() - cam1.SetClippingRange(.348,17.43) - cam1.SetPosition(2.92,2.62,-0.836) - cam1.SetViewUp(-0.436,-0.067,-0.897) + cam1.SetClippingRange(.348, 17.43) + cam1.SetPosition(2.92, 2.62, -0.836) + cam1.SetViewUp(-0.436, -0.067, -0.897) cam1.Azimuth(90) + # render the image # renWin.Render() - if (info.commands(globals(), locals(), "rtExMath") != ""): - file.delete("-force", "PolyField.vtk") + + # cleanup + # + try: + os.remove("PolyField.vtk") + except OSError: pass - pass -# prevent the tk window from showing up then start the event loop -# --- end of script -- + + +# iren.Start() + +except IOError: + print "Couldn't open PolyField.vtk for writing." diff --git a/Filters/Core/Testing/Python/fieldToRGrid.py b/Filters/Core/Testing/Python/fieldToRGrid.py index 1c38ad24d5e..207a8e604ba 100755 --- a/Filters/Core/Testing/Python/fieldToRGrid.py +++ b/Filters/Core/Testing/Python/fieldToRGrid.py @@ -1,106 +1,145 @@ #!/usr/bin/env python +import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() -## Generate a rectilinear grid from a field. -## -# get the interactor ui +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 + +# Generate a rectilinear grid from a field. +# + # Create a reader and write out the field reader = vtk.vtkDataSetReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/RectGrid2.vtk") +reader.SetFileName(VTK_DATA_ROOT + "/Data/RectGrid2.vtk") + ds2do = vtk.vtkDataSetToDataObjectFilter() ds2do.SetInputConnection(reader.GetOutputPort()) -if (catch.catch(globals(),"""channel = open("RGridField.vtk", "w")""") == 0): + +# NOTE: This test only works if the current directory is writable +# +try: + channel = open("RGridField.vtk", "wb") channel.close() + writer = vtk.vtkDataObjectWriter() writer.SetInputConnection(ds2do.GetOutputPort()) writer.SetFileName("RGridField.vtk") writer.Write() + # Read the field # dor = vtk.vtkDataObjectReader() dor.SetFileName("RGridField.vtk") + do2ds = vtk.vtkDataObjectToDataSetFilter() do2ds.SetInputConnection(dor.GetOutputPort()) do2ds.SetDataSetTypeToRectilinearGrid() - do2ds.SetDimensionsComponent("Dimensions",0) - do2ds.SetPointComponent(0,"XCoordinates",0) - do2ds.SetPointComponent(1,"YCoordinates",0) - do2ds.SetPointComponent(2,"ZCoordinates",0) + do2ds.SetDimensionsComponent("Dimensions", 0) + do2ds.SetPointComponent(0, "XCoordinates", 0) + do2ds.SetPointComponent(1, "YCoordinates", 0) + do2ds.SetPointComponent(2, "ZCoordinates", 0) do2ds.Update() + fd2ad = vtk.vtkFieldDataToAttributeDataFilter() fd2ad.SetInputData(do2ds.GetRectilinearGridOutput()) fd2ad.SetInputFieldToDataObjectField() fd2ad.SetOutputAttributeDataToPointData() - fd2ad.SetVectorComponent(0,"vectors",0) - fd2ad.SetVectorComponent(1,"vectors",1) - fd2ad.SetVectorComponent(2,"vectors",2) - fd2ad.SetScalarComponent(0,"scalars",0) + fd2ad.SetVectorComponent(0, "vectors", 0) + fd2ad.SetVectorComponent(1, "vectors", 1) + fd2ad.SetVectorComponent(2, "vectors", 2) + fd2ad.SetScalarComponent(0, "scalars", 0) fd2ad.Update() + # create pipeline # plane = vtk.vtkRectilinearGridGeometryFilter() plane.SetInputData(fd2ad.GetRectilinearGridOutput()) - plane.SetExtent(0,100,0,100,15,15) + plane.SetExtent(0, 100, 0, 100, 15, 15) + warper = vtk.vtkWarpVector() warper.SetInputConnection(plane.GetOutputPort()) warper.SetScaleFactor(0.05) + planeMapper = vtk.vtkDataSetMapper() planeMapper.SetInputConnection(warper.GetOutputPort()) - planeMapper.SetScalarRange(0.197813,0.710419) + planeMapper.SetScalarRange(0.197813, 0.710419) + planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) + cutPlane = vtk.vtkPlane() cutPlane.SetOrigin(fd2ad.GetOutput().GetCenter()) - cutPlane.SetNormal(1,0,0) + cutPlane.SetNormal(1, 0, 0) + planeCut = vtk.vtkCutter() planeCut.SetInputData(fd2ad.GetRectilinearGridOutput()) planeCut.SetCutFunction(cutPlane) + cutMapper = vtk.vtkDataSetMapper() cutMapper.SetInputConnection(planeCut.GetOutputPort()) cutMapper.SetScalarRange(fd2ad.GetOutput().GetPointData().GetScalars().GetRange()) + cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) + iso = vtk.vtkContourFilter() iso.SetInputData(fd2ad.GetRectilinearGridOutput()) - iso.SetValue(0,0.7) + iso.SetValue(0, 0.7) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(iso.GetOutputPort()) normals.SetFeatureAngle(45) + isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(normals.GetOutputPort()) isoMapper.ScalarVisibilityOff() + isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) - isoActor.GetProperty().SetColor(bisque) + isoActor.GetProperty().SetColor(GetRGBColor('bisque')) isoActor.GetProperty().SetRepresentationToWireframe() + streamer = vtk.vtkStreamLine() streamer.SetInputConnection(fd2ad.GetOutputPort()) - streamer.SetStartPosition(-1.2,-0.1,1.3) + streamer.SetStartPosition(-1.2, -0.1, 1.3) streamer.SetMaximumPropagationTime(500) streamer.SetStepLength(0.05) streamer.SetIntegrationStepLength(0.05) streamer.SetIntegrationDirectionToIntegrateBothDirections() + streamTube = vtk.vtkTubeFilter() streamTube.SetInputConnection(streamer.GetOutputPort()) streamTube.SetRadius(0.025) streamTube.SetNumberOfSides(6) streamTube.SetVaryRadiusToVaryRadiusByVector() + mapStreamTube = vtk.vtkPolyDataMapper() mapStreamTube.SetInputConnection(streamTube.GetOutputPort()) mapStreamTube.SetScalarRange(fd2ad.GetOutput().GetPointData().GetScalars().GetRange()) + streamTubeActor = vtk.vtkActor() streamTubeActor.SetMapper(mapStreamTube) streamTubeActor.GetProperty().BackfaceCullingOn() + outline = vtk.vtkOutlineFilter() outline.SetInputData(fd2ad.GetRectilinearGridOutput()) + outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) - outlineActor.GetProperty().SetColor(black) + outlineActor.GetProperty().SetColor(GetRGBColor('black')) + # Graphics stuff # Create the RenderWindow, Renderer and both Actors # @@ -110,6 +149,7 @@ if (catch.catch(globals(),"""channel = open("RGridField.vtk", "w")""") == 0): renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) @@ -117,19 +157,32 @@ if (catch.catch(globals(),"""channel = open("RGridField.vtk", "w")""") == 0): ren1.AddActor(cutActor) ren1.AddActor(isoActor) ren1.AddActor(streamTubeActor) - ren1.SetBackground(1,1,1) - renWin.SetSize(300,300) - ren1.GetActiveCamera().SetPosition(0.0390893,0.184813,-3.94026) - ren1.GetActiveCamera().SetFocalPoint(-0.00578326,0,0.701967) + + ren1.SetBackground(1, 1, 1) + + renWin.SetSize(300, 300) + + ren1.GetActiveCamera().SetPosition(0.0390893, 0.184813, -3.94026) + ren1.GetActiveCamera().SetFocalPoint(-0.00578326, 0, 0.701967) ren1.GetActiveCamera().SetViewAngle(30) - ren1.GetActiveCamera().SetViewUp(0.00850257,0.999169,0.0398605) - ren1.GetActiveCamera().SetClippingRange(3.08127,6.62716) + ren1.GetActiveCamera().SetViewUp(0.00850257, 0.999169, 0.0398605) + ren1.GetActiveCamera().SetClippingRange(3.08127, 6.62716) + iren.Initialize() + # render the image # - if (info.commands(globals(), locals(), "rtExMath") != ""): - file.delete("-force", "RGridField.vtk") + renWin.Render() + + # cleanup + # + try: + os.remove("RGridField.vtk") + except OSError: pass - pass -# prevent the tk window from showing up then start the event loop -# --- end of script -- + + +# iren.Start() + +except IOError: + print "Couldn't open RGridField.vtk for writing." diff --git a/Filters/Core/Testing/Python/fieldToSGrid.py b/Filters/Core/Testing/Python/fieldToSGrid.py index e16ba7dba14..c156527e6fc 100755 --- a/Filters/Core/Testing/Python/fieldToSGrid.py +++ b/Filters/Core/Testing/Python/fieldToSGrid.py @@ -1,78 +1,105 @@ #!/usr/bin/env python +import os import vtk 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 + # Demonstrate the generation of a structured grid from field data. The output # should be similar to combIso.tcl. # # NOTE: This test only works if the current directory is writable # -if (catch.catch(globals(),"""channel = open("test.tmp", "w")""") == 0): +try: + channel = open("combsg.vtk", "wb") + channel.close() + channel = open("SGridField.vtk", "wb") channel.close() - file.delete("-force", "test.tmp") - # get the interactor ui + # Create a reader and write out the field comb = vtk.vtkMultiBlockPLOT3DReader() - comb.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") - comb.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") + comb.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") + comb.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") comb.SetScalarFunctionNumber(100) comb.Update() + output = comb.GetOutput().GetBlock(0) + wsg = vtk.vtkStructuredGridWriter() wsg.SetInputData(output) wsg.SetFileTypeToBinary() wsg.SetFileName("combsg.vtk") wsg.Write() + pl3d = vtk.vtkStructuredGridReader() pl3d.SetFileName("combsg.vtk") + ds2do = vtk.vtkDataSetToDataObjectFilter() ds2do.SetInputConnection(pl3d.GetOutputPort()) + writer = vtk.vtkDataObjectWriter() writer.SetInputConnection(ds2do.GetOutputPort()) writer.SetFileName("SGridField.vtk") writer.Write() + # read the field dor = vtk.vtkDataObjectReader() dor.SetFileName("SGridField.vtk") + do2ds = vtk.vtkDataObjectToDataSetFilter() do2ds.SetInputConnection(dor.GetOutputPort()) do2ds.SetDataSetTypeToStructuredGrid() - do2ds.SetDimensionsComponent("Dimensions",0) - do2ds.SetPointComponent(0,"Points",0) - do2ds.SetPointComponent(1,"Points",1) - do2ds.SetPointComponent(2,"Points",2) + do2ds.SetDimensionsComponent("Dimensions", 0) + do2ds.SetPointComponent(0, "Points", 0) + do2ds.SetPointComponent(1, "Points", 1) + do2ds.SetPointComponent(2, "Points", 2) do2ds.Update() + fd2ad = vtk.vtkFieldDataToAttributeDataFilter() fd2ad.SetInputData(do2ds.GetStructuredGridOutput()) fd2ad.SetInputFieldToDataObjectField() fd2ad.SetOutputAttributeDataToPointData() - fd2ad.SetVectorComponent(0,"Momentum",0) - fd2ad.SetVectorComponent(1,"Momentum",1) - fd2ad.SetVectorComponent(2,"Momentum",2) - fd2ad.SetScalarComponent(0,"Density",0) + fd2ad.SetVectorComponent(0, "Momentum", 0) + fd2ad.SetVectorComponent(1, "Momentum", 1) + fd2ad.SetVectorComponent(2, "Momentum", 2) + fd2ad.SetScalarComponent(0, "Density", 0) fd2ad.Update() + # create pipeline # iso = vtk.vtkContourFilter() iso.SetInputConnection(fd2ad.GetOutputPort()) - iso.SetValue(0,.38) + iso.SetValue(0, .38) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(iso.GetOutputPort()) normals.SetFeatureAngle(45) + isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(normals.GetOutputPort()) isoMapper.ScalarVisibilityOff() isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) - isoActor.GetProperty().SetColor(bisque) + isoActor.GetProperty().SetColor(GetRGBColor('bisque')) + outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(fd2ad.GetStructuredGridOutput()) + outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -80,25 +107,39 @@ if (catch.catch(globals(),"""channel = open("test.tmp", "w")""") == 0): renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) ren1.AddActor(isoActor) - ren1.SetBackground(1,1,1) - renWin.SetSize(250,250) - ren1.SetBackground(0.1,0.2,0.4) + ren1.SetBackground(1, 1, 1) + + renWin.SetSize(250, 250) + + ren1.SetBackground(0.1, 0.2, 0.4) + cam1 = ren1.GetActiveCamera() - cam1.SetClippingRange(3.95297,50) - cam1.SetFocalPoint(9.71821,0.458166,29.3999) - cam1.SetPosition(2.7439,-37.3196,38.7167) - cam1.SetViewUp(-0.16123,0.264271,0.950876) + cam1.SetClippingRange(3.95297, 50) + cam1.SetFocalPoint(9.71821, 0.458166, 29.3999) + cam1.SetPosition(2.7439, -37.3196, 38.7167) + cam1.SetViewUp(-0.16123, 0.264271, 0.950876) + # render the image # renWin.Render() - # + # cleanup - file.delete("-force", "combsg.vtk") - file.delete("-force", "SGridField.vtk") - # prevent the tk window from showing up then start the event loop - pass -# --- end of script -- + # + try: + os.remove("combsg.vtk") + except OSError: + pass + try: + os.remove("SGridField.vtk") + except OSError: + pass + +# iren.Start() + +except IOError: + print "Couldn't open combsg.vtk or SGridField.vtk for writing." diff --git a/Filters/Core/Testing/Python/fieldToUGrid.py b/Filters/Core/Testing/Python/fieldToUGrid.py index 0d00f80c1a6..f7856a026e1 100755 --- a/Filters/Core/Testing/Python/fieldToUGrid.py +++ b/Filters/Core/Testing/Python/fieldToUGrid.py @@ -1,107 +1,144 @@ #!/usr/bin/env python +import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() # Read a field representing unstructured grid and display it (similar to blow.tcl) -# create a reader and write out field daya + +# create a reader and write out field data reader = vtk.vtkUnstructuredGridReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/blow.vtk") +reader.SetFileName(VTK_DATA_ROOT + "/Data/blow.vtk") reader.SetScalarsName("thickness9") reader.SetVectorsName("displacement9") + ds2do = vtk.vtkDataSetToDataObjectFilter() ds2do.SetInputConnection(reader.GetOutputPort()) + # we must be able to write here -if (catch.catch(globals(),"""channel = open("UGridField.vtk", "w")""") == 0): +try: + channel = open("UGridField.vtk", "wb") channel.close() + write = vtk.vtkDataObjectWriter() write.SetInputConnection(ds2do.GetOutputPort()) write.SetFileName("UGridField.vtk") write.Write() + # Read the field and convert to unstructured grid. dor = vtk.vtkDataObjectReader() dor.SetFileName("UGridField.vtk") + do2ds = vtk.vtkDataObjectToDataSetFilter() do2ds.SetInputConnection(dor.GetOutputPort()) do2ds.SetDataSetTypeToUnstructuredGrid() - do2ds.SetPointComponent(0,"Points",0) - do2ds.SetPointComponent(1,"Points",1) - do2ds.SetPointComponent(2,"Points",2) - do2ds.SetCellTypeComponent("CellTypes",0) - do2ds.SetCellConnectivityComponent("Cells",0) + do2ds.SetPointComponent(0, "Points", 0) + do2ds.SetPointComponent(1, "Points", 1) + do2ds.SetPointComponent(2, "Points", 2) + do2ds.SetCellTypeComponent("CellTypes", 0) + do2ds.SetCellConnectivityComponent("Cells", 0) do2ds.Update() + fd2ad = vtk.vtkFieldDataToAttributeDataFilter() fd2ad.SetInputData(do2ds.GetUnstructuredGridOutput()) fd2ad.SetInputFieldToDataObjectField() fd2ad.SetOutputAttributeDataToPointData() - fd2ad.SetVectorComponent(0,"displacement9",0) - fd2ad.SetVectorComponent(1,"displacement9",1) - fd2ad.SetVectorComponent(2,"displacement9",2) - fd2ad.SetScalarComponent(0,"thickness9",0) + fd2ad.SetVectorComponent(0, "displacement9", 0) + fd2ad.SetVectorComponent(1, "displacement9", 1) + fd2ad.SetVectorComponent(2, "displacement9", 2) + fd2ad.SetScalarComponent(0, "thickness9", 0) fd2ad.Update() + # Now start visualizing warp = vtk.vtkWarpVector() warp.SetInputData(fd2ad.GetUnstructuredGridOutput()) + # extract mold from mesh using connectivity connect = vtk.vtkConnectivityFilter() connect.SetInputConnection(warp.GetOutputPort()) connect.SetExtractionModeToSpecifiedRegions() connect.AddSpecifiedRegion(0) connect.AddSpecifiedRegion(1) + moldMapper = vtk.vtkDataSetMapper() moldMapper.SetInputConnection(connect.GetOutputPort()) moldMapper.ScalarVisibilityOff() + moldActor = vtk.vtkActor() moldActor.SetMapper(moldMapper) - moldActor.GetProperty().SetColor(.2,.2,.2) + moldActor.GetProperty().SetColor(.2, .2, .2) moldActor.GetProperty().SetRepresentationToWireframe() + # extract parison from mesh using connectivity connect2 = vtk.vtkConnectivityFilter() connect2.SetInputConnection(warp.GetOutputPort()) connect2.SetExtractionModeToSpecifiedRegions() connect2.AddSpecifiedRegion(2) + parison = vtk.vtkGeometryFilter() parison.SetInputConnection(connect2.GetOutputPort()) + normals2 = vtk.vtkPolyDataNormals() normals2.SetInputConnection(parison.GetOutputPort()) normals2.SetFeatureAngle(60) + lut = vtk.vtkLookupTable() - lut.SetHueRange(0.0,0.66667) + lut.SetHueRange(0.0, 0.66667) + parisonMapper = vtk.vtkPolyDataMapper() parisonMapper.SetInputConnection(normals2.GetOutputPort()) parisonMapper.SetLookupTable(lut) - parisonMapper.SetScalarRange(0.12,1.0) + parisonMapper.SetScalarRange(0.12, 1.0) + parisonActor = vtk.vtkActor() parisonActor.SetMapper(parisonMapper) + cf = vtk.vtkContourFilter() cf.SetInputConnection(connect2.GetOutputPort()) - cf.SetValue(0,.5) + cf.SetValue(0, .5) + contourMapper = vtk.vtkPolyDataMapper() contourMapper.SetInputConnection(cf.GetOutputPort()) + contours = vtk.vtkActor() contours.SetMapper(contourMapper) + # Create graphics stuff ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size ren1.AddActor(moldActor) ren1.AddActor(parisonActor) ren1.AddActor(contours) + ren1.ResetCamera() ren1.GetActiveCamera().Azimuth(60) ren1.GetActiveCamera().Roll(-90) ren1.GetActiveCamera().Dolly(2) ren1.ResetCameraClippingRange() - ren1.SetBackground(1,1,1) - renWin.SetSize(375,200) + ren1.SetBackground(1, 1, 1) + + renWin.SetSize(375, 200) + iren.Initialize() - if (info.commands(globals(), locals(), "rtExMath") != ""): - file.delete("-force", "UGridField.vtk") + + # render the image + # + renWin.Render() + + # cleanup + # + try: + os.remove("UGridField.vtk") + except OSError: pass - pass -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +# iren.Start() + +except IOError: + print "Couldn't open UGridField.vtk for writing." diff --git a/Filters/Core/Testing/Python/hull.py b/Filters/Core/Testing/Python/hull.py index 57e52ae83ea..4428b679fff 100755 --- a/Filters/Core/Testing/Python/hull.py +++ b/Filters/Core/Testing/Python/hull.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import math import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot @@ -6,40 +7,47 @@ VTK_DATA_ROOT = vtkGetDataRoot() # Generate random planes to form a convex polyhedron. # Create a polyhedral representation of the planes. -# get the interactor ui -# create some points laying between 1<=r<5 (r is radius) + +# create some points lying between 1<=r<5 (r is radius) # the points also have normals pointing away from the origin. # mathObj = vtk.vtkMath() + points = vtk.vtkPoints() normals = vtk.vtkFloatArray() normals.SetNumberOfComponents(3) i = 0 while i < 100: radius = 1.0 - theta = mathObj.Random(0,360) - phi = mathObj.Random(0,180) - x = expr.expr(globals(), locals(),["radius","*","sin","(","phi",")*","cos","(","theta",")"]) - y = expr.expr(globals(), locals(),["radius","*","sin","(","phi",")*","sin","(","theta",")"]) - z = expr.expr(globals(), locals(),["radius","*","cos","(","phi",")"]) - points.InsertPoint(i,x,y,z) - normals.InsertTuple3(i,x,y,z) - i = i + 1 + theta = mathObj.Random(0, 360) + phi = mathObj.Random(0, 180) + x = radius * math.sin(phi) * math.cos(theta) + y = radius * math.sin(phi) * math.sin(theta) + z = radius * math.cos(phi) + points.InsertPoint(i, x, y, z) + normals.InsertTuple3(i, x, y, z) + i += 1 planes = vtk.vtkPlanes() planes.SetPoints(points) planes.SetNormals(normals) -ss = vtk.vtkSphereSource() + +# ss = vtk.vtkSphereSource() + hull = vtk.vtkHull() hull.SetPlanes(planes) + pd = vtk.vtkPolyData() -hull.GenerateHull(pd,-20,20,-20,20,-20,20) +hull.GenerateHull(pd, -20, 20, -20, 20, -20, 20) + # triangulate them # mapHull = vtk.vtkPolyDataMapper() mapHull.SetInputData(pd) + hullActor = vtk.vtkActor() hullActor.SetMapper(mapHull) + # Create graphics objects # Create the rendering window, renderer, and interactive renderer ren1 = vtk.vtkRenderer() @@ -47,13 +55,17 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size ren1.AddActor(hullActor) -renWin.SetSize(250,250) + +renWin.SetSize(250, 250) + # render the image # ren1.ResetCamera() + ren1.GetActiveCamera().Zoom(1.5) + iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Core/Testing/Python/multipleIso.py b/Filters/Core/Testing/Python/multipleIso.py index 73688a3af3c..531a70a38de 100755 --- a/Filters/Core/Testing/Python/multipleIso.py +++ b/Filters/Core/Testing/Python/multipleIso.py @@ -1,11 +1,11 @@ #!/usr/bin/env python +import math import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() -# get the interactor ui -## Graphics stuff +# Graphics stuff # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -13,53 +13,64 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + pl3d = vtk.vtkMultiBlockPLOT3DReader() -pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") -pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") +pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") +pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() + output = pl3d.GetOutput().GetBlock(0) + range = output.GetPointData().GetScalars().GetRange() -min = lindex(range,0) -max = lindex(range,1) -value = expr.expr(globals(), locals(),["(","min","+","max",")","/","2.0"]) +min = range[0] +max = range[1] +value = (min + max) / 2.0 + cf = vtk.vtkContourFilter() cf.SetInputData(output) -cf.SetValue(0,value) +cf.SetValue(0, value) cf.UseScalarTreeOn() + numberOfContours = 5 -epsilon = expr.expr(globals(), locals(),["double","(","max","-","min",")","/","double","(","numberOfContours","*","10",")"]) -min = expr.expr(globals(), locals(),["min","+","epsilon"]) -max = expr.expr(globals(), locals(),["max","-","epsilon"]) +epsilon = float(max - min) / float(numberOfContours * 10) +min = min + epsilon +max = max - epsilon i = 1 while i <= numberOfContours: - cf.SetValue(0,expr.expr(globals(), locals(),["min","+","((","i","-","1",")","/","double","(","numberOfContours","-","1",")",")*(","max","-","min",")"])) + cf.SetValue(0, min + ((i - 1) / float(numberOfContours - 1)) * (max - min)) cf.Update() - locals()[get_variable_name("pd", i, "")] = vtk.vtkPolyData() - locals()[get_variable_name("pd", i, "")].CopyStructure(cf.GetOutput()) - locals()[get_variable_name("pd", i, "")].GetPointData().DeepCopy(cf.GetOutput().GetPointData()) - locals()[get_variable_name("mapper", i, "")] = vtk.vtkPolyDataMapper() - locals()[get_variable_name("mapper", i, "")].SetInputData(locals()[get_variable_name("pd", i, "")]) - locals()[get_variable_name("mapper", i, "")].SetScalarRange(output.GetPointData().GetScalars().GetRange()) - locals()[get_variable_name("actor", i, "")] = vtk.vtkActor() - locals()[get_variable_name("actor", i, "")].AddPosition(0,expr.expr(globals(), locals(),["i","*","12"]),0) - locals()[get_variable_name("actor", i, "")].SetMapper(locals()[get_variable_name("mapper", i, "")]) - ren1.AddActor(locals()[get_variable_name("actor", i, "")]) - i = i + 1 + idx = str(i) + exec("pd" + idx + " = vtk.vtkPolyData()") + eval("pd" + idx).CopyStructure(cf.GetOutput()) + eval("pd" + idx).GetPointData().DeepCopy(cf.GetOutput().GetPointData()) + + exec("mapper" + idx + " = vtk.vtkPolyDataMapper()") + eval("mapper" + idx).SetInputData(eval("pd" + idx)) + eval("mapper" + idx).SetScalarRange( + output.GetPointData().GetScalars().GetRange()) + + exec("actor" + idx + " = vtk.vtkActor()") + eval("actor" + idx).AddPosition(0, i * 12, 0) + eval("actor" + idx).SetMapper(eval("mapper" + idx)) + + ren1.AddActor(eval("actor" + idx)) + + i += 1 # Add the actors to the renderer, set the background and size # -ren1.SetBackground(.3,.3,.3) -renWin.SetSize(450,150) -cam1 = ren1.GetActiveCamera() -ren1.GetActiveCamera().SetPosition(-36.3762,32.3855,51.3652) -ren1.GetActiveCamera().SetFocalPoint(8.255,33.3861,29.7687) +ren1.SetBackground(.3, .3, .3) + +renWin.SetSize(450, 150) + +# cam1 = ren1.GetActiveCamera() +ren1.GetActiveCamera().SetPosition(-36.3762, 32.3855, 51.3652) +ren1.GetActiveCamera().SetFocalPoint(8.255, 33.3861, 29.7687) ren1.GetActiveCamera().SetViewAngle(30) -ren1.GetActiveCamera().SetViewUp(0,0,1) +ren1.GetActiveCamera().SetViewUp(0, 0, 1) ren1.ResetCameraClippingRange() + iren.Initialize() -# render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Core/Testing/Python/reverseNormals.py b/Filters/Core/Testing/Python/reverseNormals.py index 2d99d19073c..c6be2b0b00e 100755 --- a/Filters/Core/Testing/Python/reverseNormals.py +++ b/Filters/Core/Testing/Python/reverseNormals.py @@ -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 + # Now create the RenderWindow, Renderer and Interactor # ren1 = vtk.vtkRenderer() @@ -11,50 +20,66 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + cowReader = vtk.vtkOBJReader() -cowReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/Viewpoint/cow.obj") +cowReader.SetFileName(VTK_DATA_ROOT + "/Data/Viewpoint/cow.obj") + plane = vtk.vtkPlane() -plane.SetNormal(1,0,0) +plane.SetNormal(1, 0, 0) + cowClipper = vtk.vtkClipPolyData() cowClipper.SetInputConnection(cowReader.GetOutputPort()) cowClipper.SetClipFunction(plane) + cellNormals = vtk.vtkPolyDataNormals() cellNormals.SetInputConnection(cowClipper.GetOutputPort()) cellNormals.ComputePointNormalsOn() cellNormals.ComputeCellNormalsOn() + reflect = vtk.vtkTransform() -reflect.Scale(-1,1,1) +reflect.Scale(-1, 1, 1) + cowReflect = vtk.vtkTransformPolyDataFilter() cowReflect.SetTransform(reflect) cowReflect.SetInputConnection(cellNormals.GetOutputPort()) + cowReverse = vtk.vtkReverseSense() cowReverse.SetInputConnection(cowReflect.GetOutputPort()) cowReverse.ReverseNormalsOn() cowReverse.ReverseCellsOff() + reflectedMapper = vtk.vtkPolyDataMapper() reflectedMapper.SetInputConnection(cowReverse.GetOutputPort()) + reflected = vtk.vtkActor() reflected.SetMapper(reflectedMapper) -reflected.GetProperty().SetDiffuseColor(flesh) +reflected.GetProperty().SetDiffuseColor(GetRGBColor('flesh')) reflected.GetProperty().SetDiffuse(.8) reflected.GetProperty().SetSpecular(.5) reflected.GetProperty().SetSpecularPower(30) reflected.GetProperty().FrontfaceCullingOn() + ren1.AddActor(reflected) + cowMapper = vtk.vtkPolyDataMapper() cowMapper.SetInputConnection(cowClipper.GetOutputPort()) + cow = vtk.vtkActor() cow.SetMapper(cowMapper) + ren1.AddActor(cow) -ren1.SetBackground(.1,.2,.4) -renWin.SetSize(320,240) + +ren1.SetBackground(.1, .2, .4) + +renWin.SetSize(320, 240) + ren1.ResetCamera() -ren1.GetActiveCamera().SetViewUp(0,1,0) +ren1.GetActiveCamera().SetViewUp(0, 1, 0) ren1.GetActiveCamera().Azimuth(180) ren1.GetActiveCamera().Dolly(1.75) ren1.ResetCameraClippingRange() + iren.Initialize() + # render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Core/Testing/Python/teapotHulls.py b/Filters/Core/Testing/Python/teapotHulls.py index a355dbdcf04..4884d349d85 100755 --- a/Filters/Core/Testing/Python/teapotHulls.py +++ b/Filters/Core/Testing/Python/teapotHulls.py @@ -12,41 +12,54 @@ renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + byuReader = vtk.vtkBYUReader() -byuReader.SetGeometryFileName("" + str(VTK_DATA_ROOT) + "/Data/teapot.g") +byuReader.SetGeometryFileName(VTK_DATA_ROOT + "/Data/teapot.g") + byuMapper = vtk.vtkPolyDataMapper() byuMapper.SetInputConnection(byuReader.GetOutputPort()) + i = 0 while i < 9: - locals()[get_variable_name("byuActor", i, "")] = vtk.vtkActor() - locals()[get_variable_name("byuActor", i, "")].SetMapper(byuMapper) - ren1.AddActor(locals()[get_variable_name("byuActor", i, "")]) - locals()[get_variable_name("hull", i, "")] = vtk.vtkHull() - locals()[get_variable_name("hull", i, "")].SetInputConnection(byuReader.GetOutputPort()) - locals()[get_variable_name("hullMapper", i, "")] = vtk.vtkPolyDataMapper() - locals()[get_variable_name("hullMapper", i, "")].SetInputConnection(locals()[get_variable_name("hull", i, "")].GetOutputPort()) - locals()[get_variable_name("hullActor", i, "")] = vtk.vtkActor() - locals()[get_variable_name("hullActor", i, "")].SetMapper(locals()[get_variable_name("hullMapper", i, "")]) - locals()[get_variable_name("hullActor", i, "")].GetProperty().SetColor(1,0,0) - locals()[get_variable_name("hullActor", i, "")].GetProperty().SetAmbient(0.2) - locals()[get_variable_name("hullActor", i, "")].GetProperty().SetDiffuse(0.8) - locals()[get_variable_name("hullActor", i, "")].GetProperty().SetRepresentationToWireframe() - ren1.AddActor(locals()[get_variable_name("hullActor", i, "")]) - i = i + 1 + idx = str(i) + exec("byuActor" + idx + " = vtk.vtkActor()") + eval("byuActor" + idx).SetMapper(byuMapper) + + ren1.AddActor(eval("byuActor" + idx)) + + exec("hull" + idx + " = vtk.vtkHull()") + eval("hull" + idx).SetInputConnection(byuReader.GetOutputPort()) + + exec("hullMapper" + idx + " = vtk.vtkPolyDataMapper()") + eval("hullMapper" + idx).SetInputConnection( + eval("hull" + idx).GetOutputPort()) + + exec("hullActor" + idx + " = vtk.vtkActor()") + eval("hullActor" + idx).SetMapper(eval("hullMapper" + idx)) + eval("hullActor" + idx).GetProperty().SetColor(1, 0, 0) + eval("hullActor" + idx).GetProperty().SetAmbient(0.2) + eval("hullActor" + idx).GetProperty().SetDiffuse(0.8) + eval("hullActor" + idx).GetProperty().SetRepresentationToWireframe() + + ren1.AddActor(eval("hullActor" + idx)) + + i += 1 byuReader.Update() + diagonal = byuActor0.GetLength() i = 0 j = -1 while j < 2: k = -1 while k < 2: - locals()[get_variable_name("byuActor", i, "")].AddPosition(expr.expr(globals(), locals(),["k","*","diagonal"]),expr.expr(globals(), locals(),["j","*","diagonal"]),0) - locals()[get_variable_name("hullActor", i, "")].AddPosition(expr.expr(globals(), locals(),["k","*","diagonal"]),expr.expr(globals(), locals(),["j","*","diagonal"]),0) - i = i + 1 - k = k + 1 + idx = str(i) + eval("byuActor" + idx).AddPosition(k * diagonal, j * diagonal, 0) + eval("hullActor" + idx).AddPosition(k * diagonal, j * diagonal, 0) + i += 1 + k += 1 - j = j + 1 + j += 1 hull0.AddCubeFacePlanes() hull1.AddCubeEdgePlanes() @@ -59,14 +72,17 @@ hull5.AddRecursiveSpherePlanes(1) hull6.AddRecursiveSpherePlanes(2) hull7.AddRecursiveSpherePlanes(3) hull8.AddRecursiveSpherePlanes(4) + # Add the actors to the renderer, set the background and size # -ren1.SetBackground(0.1,0.2,0.4) -renWin.SetSize(500,500) +ren1.SetBackground(0.1, 0.2, 0.4) + +renWin.SetSize(500, 500) + iren.Initialize() renWin.Render() -renWin.Render() -# prevent the tk window from showing up then start the event loop + # for testing threshold = 15 -# --- end of script -- + +#iren.Start() diff --git a/Filters/Extraction/Testing/Python/extractRectGrid.py b/Filters/Extraction/Testing/Python/extractRectGrid.py index c389ecb3b82..3eba850a8d9 100755 --- a/Filters/Extraction/Testing/Python/extractRectGrid.py +++ b/Filters/Extraction/Testing/Python/extractRectGrid.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot @@ -7,47 +8,40 @@ VTK_DATA_ROOT = vtkGetDataRoot() # create pipeline - rectilinear grid # rgridReader = vtk.vtkRectilinearGridReader() -rgridReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/RectGrid2.vtk") +rgridReader.SetFileName(VTK_DATA_ROOT + "/Data/RectGrid2.vtk") + outline = vtk.vtkOutlineFilter() outline.SetInputConnection(rgridReader.GetOutputPort()) + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(outline.GetOutputPort()) + actor = vtk.vtkActor() actor.SetMapper(mapper) + rgridReader.Update() + extract1 = vtk.vtkExtractRectilinearGrid() extract1.SetInputConnection(rgridReader.GetOutputPort()) -#extract1 SetVOI 0 46 0 32 0 10 -extract1.SetVOI(23,40,16,30,9,9) -extract1.SetSampleRate(2,2,1) +# extract1.SetVOI(0, 46, 0, 32, 0, 10) +extract1.SetVOI(23, 40, 16, 30, 9, 9) +extract1.SetSampleRate(2, 2, 1) extract1.IncludeBoundaryOn() extract1.Update() + surf1 = vtk.vtkDataSetSurfaceFilter() surf1.SetInputConnection(extract1.GetOutputPort()) + tris = vtk.vtkTriangleFilter() tris.SetInputConnection(surf1.GetOutputPort()) + mapper1 = vtk.vtkPolyDataMapper() mapper1.SetInputConnection(tris.GetOutputPort()) mapper1.SetScalarRange(extract1.GetOutput().GetScalarRange()) + actor1 = vtk.vtkActor() actor1.SetMapper(mapper1) -# write out a rect grid -# write to the temp directory if possible, otherwise use . -dir = "." -if (info.commands(globals(), locals(), "rtTester") == "rtTester"): - dir = rtTester.GetTempDirectory() - pass -# make sure the directory is writeable first -if (catch.catch(globals(),"""channel = open("" + str(dir) + "/test.tmp", "w")""") == 0): - channel.close() - file.delete("-force", "" + str(dir) + "/test.tmp") - rectWriter = vtk.vtkRectilinearGridWriter() - rectWriter.SetInputConnection(extract1.GetOutputPort()) - rectWriter.SetFileName("" + str(dir) + "/rect.tmp") - rectWriter.Write() - # delete the file - file.delete("-force", "" + str(dir) + "/rect.tmp") - pass + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -55,11 +49,12 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) -#ren1 AddActor actor + +# ren1.AddActor(actor) ren1.AddActor(actor1) -renWin.SetSize(340,400) +renWin.SetSize(340, 400) + iren.Initialize() + # render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/General/Testing/Python/OBBCylinder.py b/Filters/General/Testing/Python/OBBCylinder.py index 9a7e89c47e9..031dd6d80fd 100755 --- a/Filters/General/Testing/Python/OBBCylinder.py +++ b/Filters/General/Testing/Python/OBBCylinder.py @@ -9,54 +9,68 @@ cylinder.SetHeight(1) cylinder.SetRadius(4) cylinder.SetResolution(100) cylinder.CappingOff() + foo = vtk.vtkTransform() foo.RotateX(20) foo.RotateY(10) foo.RotateZ(27) -foo.Scale(1,.7,.3) +foo.Scale(1, .7, .3) + transPD = vtk.vtkTransformPolyDataFilter() transPD.SetInputConnection(cylinder.GetOutputPort()) transPD.SetTransform(foo) + dataMapper = vtk.vtkPolyDataMapper() dataMapper.SetInputConnection(transPD.GetOutputPort()) + model = vtk.vtkActor() model.SetMapper(dataMapper) -model.GetProperty().SetColor(1,0,0) +model.GetProperty().SetColor(1, 0, 0) + obb = vtk.vtkOBBTree() obb.SetMaxLevel(10) obb.SetNumberOfCellsPerNode(5) obb.AutomaticOff() + boxes = vtk.vtkSpatialRepresentationFilter() boxes.SetInputConnection(transPD.GetOutputPort()) boxes.SetSpatialRepresentation(obb) boxes.SetGenerateLeaves(1) boxes.Update() -output = boxes.GetOutput().GetBlock(expr.expr(globals(), locals(),["boxes.GetMaximumLevel()","+","1"])) + +output = boxes.GetOutput().GetBlock(boxes.GetMaximumLevel() + 1) boxEdges = vtk.vtkExtractEdges() boxEdges.SetInputData(output) + boxMapper = vtk.vtkPolyDataMapper() boxMapper.SetInputConnection(boxEdges.GetOutputPort()) boxMapper.SetResolveCoincidentTopology(1) + boxActor = vtk.vtkActor() boxActor.SetMapper(boxMapper) boxActor.GetProperty().SetAmbient(1) boxActor.GetProperty().SetDiffuse(0) boxActor.GetProperty().SetRepresentationToWireframe() + ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(model) ren1.AddActor(boxActor) -ren1.SetBackground(0.1,0.2,0.4) -renWin.SetSize(300,300) +ren1.SetBackground(0.1, 0.2, 0.4) + +renWin.SetSize(300, 300) + ren1.ResetCamera() ren1.GetActiveCamera().Zoom(1.5) + # render the image # iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Filters/General/Testing/Python/TestCellDerivs.py b/Filters/General/Testing/Python/TestCellDerivs.py index 0d05c5e93a9..e2c664b532e 100755 --- a/Filters/General/Testing/Python/TestCellDerivs.py +++ b/Filters/General/Testing/Python/TestCellDerivs.py @@ -6,528 +6,626 @@ VTK_DATA_ROOT = vtkGetDataRoot() # Demonstrates vtkCellDerivatives for all cell types # -# get the interactor ui ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create a scene with one of each cell type # Voxel voxelPoints = vtk.vtkPoints() voxelPoints.SetNumberOfPoints(8) -voxelPoints.InsertPoint(0,0,0,0) -voxelPoints.InsertPoint(1,1,0,0) -voxelPoints.InsertPoint(2,0,1,0) -voxelPoints.InsertPoint(3,1,1,0) -voxelPoints.InsertPoint(4,0,0,1) -voxelPoints.InsertPoint(5,1,0,1) -voxelPoints.InsertPoint(6,0,1,1) -voxelPoints.InsertPoint(7,1,1,1) +voxelPoints.InsertPoint(0, 0, 0, 0) +voxelPoints.InsertPoint(1, 1, 0, 0) +voxelPoints.InsertPoint(2, 0, 1, 0) +voxelPoints.InsertPoint(3, 1, 1, 0) +voxelPoints.InsertPoint(4, 0, 0, 1) +voxelPoints.InsertPoint(5, 1, 0, 1) +voxelPoints.InsertPoint(6, 0, 1, 1) +voxelPoints.InsertPoint(7, 1, 1, 1) + aVoxel = vtk.vtkVoxel() -aVoxel.GetPointIds().SetId(0,0) -aVoxel.GetPointIds().SetId(1,1) -aVoxel.GetPointIds().SetId(2,2) -aVoxel.GetPointIds().SetId(3,3) -aVoxel.GetPointIds().SetId(4,4) -aVoxel.GetPointIds().SetId(5,5) -aVoxel.GetPointIds().SetId(6,6) -aVoxel.GetPointIds().SetId(7,7) +aVoxel.GetPointIds().SetId(0, 0) +aVoxel.GetPointIds().SetId(1, 1) +aVoxel.GetPointIds().SetId(2, 2) +aVoxel.GetPointIds().SetId(3, 3) +aVoxel.GetPointIds().SetId(4, 4) +aVoxel.GetPointIds().SetId(5, 5) +aVoxel.GetPointIds().SetId(6, 6) +aVoxel.GetPointIds().SetId(7, 7) + aVoxelGrid = vtk.vtkUnstructuredGrid() -aVoxelGrid.Allocate(1,1) -aVoxelGrid.InsertNextCell(aVoxel.GetCellType(),aVoxel.GetPointIds()) +aVoxelGrid.Allocate(1, 1) +aVoxelGrid.InsertNextCell(aVoxel.GetCellType(), aVoxel.GetPointIds()) aVoxelGrid.SetPoints(voxelPoints) + aVoxelMapper = vtk.vtkDataSetMapper() aVoxelMapper.SetInputData(aVoxelGrid) + aVoxelActor = vtk.vtkActor() aVoxelActor.SetMapper(aVoxelMapper) aVoxelActor.GetProperty().BackfaceCullingOn() + # Hexahedron hexahedronPoints = vtk.vtkPoints() hexahedronPoints.SetNumberOfPoints(8) -hexahedronPoints.InsertPoint(0,0,0,0) -hexahedronPoints.InsertPoint(1,1,0,0) -hexahedronPoints.InsertPoint(2,1,1,0) -hexahedronPoints.InsertPoint(3,0,1,0) -hexahedronPoints.InsertPoint(4,0,0,1) -hexahedronPoints.InsertPoint(5,1,0,1) -hexahedronPoints.InsertPoint(6,1,1,1) -hexahedronPoints.InsertPoint(7,0,1,1) +hexahedronPoints.InsertPoint(0, 0, 0, 0) +hexahedronPoints.InsertPoint(1, 1, 0, 0) +hexahedronPoints.InsertPoint(2, 1, 1, 0) +hexahedronPoints.InsertPoint(3, 0, 1, 0) +hexahedronPoints.InsertPoint(4, 0, 0, 1) +hexahedronPoints.InsertPoint(5, 1, 0, 1) +hexahedronPoints.InsertPoint(6, 1, 1, 1) +hexahedronPoints.InsertPoint(7, 0, 1, 1) + aHexahedron = vtk.vtkHexahedron() -aHexahedron.GetPointIds().SetId(0,0) -aHexahedron.GetPointIds().SetId(1,1) -aHexahedron.GetPointIds().SetId(2,2) -aHexahedron.GetPointIds().SetId(3,3) -aHexahedron.GetPointIds().SetId(4,4) -aHexahedron.GetPointIds().SetId(5,5) -aHexahedron.GetPointIds().SetId(6,6) -aHexahedron.GetPointIds().SetId(7,7) +aHexahedron.GetPointIds().SetId(0, 0) +aHexahedron.GetPointIds().SetId(1, 1) +aHexahedron.GetPointIds().SetId(2, 2) +aHexahedron.GetPointIds().SetId(3, 3) +aHexahedron.GetPointIds().SetId(4, 4) +aHexahedron.GetPointIds().SetId(5, 5) +aHexahedron.GetPointIds().SetId(6, 6) +aHexahedron.GetPointIds().SetId(7, 7) + aHexahedronGrid = vtk.vtkUnstructuredGrid() -aHexahedronGrid.Allocate(1,1) -aHexahedronGrid.InsertNextCell(aHexahedron.GetCellType(),aHexahedron.GetPointIds()) +aHexahedronGrid.Allocate(1, 1) +aHexahedronGrid.InsertNextCell(aHexahedron.GetCellType(), aHexahedron.GetPointIds()) aHexahedronGrid.SetPoints(hexahedronPoints) + aHexahedronMapper = vtk.vtkDataSetMapper() aHexahedronMapper.SetInputData(aHexahedronGrid) + aHexahedronActor = vtk.vtkActor() aHexahedronActor.SetMapper(aHexahedronMapper) -aHexahedronActor.AddPosition(2,0,0) +aHexahedronActor.AddPosition(2, 0, 0) aHexahedronActor.GetProperty().BackfaceCullingOn() + # Tetra tetraPoints = vtk.vtkPoints() tetraPoints.SetNumberOfPoints(4) -tetraPoints.InsertPoint(0,0,0,0) -tetraPoints.InsertPoint(1,1,0,0) -tetraPoints.InsertPoint(2,0,1,0) -tetraPoints.InsertPoint(3,1,1,1) +tetraPoints.InsertPoint(0, 0, 0, 0) +tetraPoints.InsertPoint(1, 1, 0, 0) +tetraPoints.InsertPoint(2, 0, 1, 0) +tetraPoints.InsertPoint(3, 1, 1, 1) + aTetra = vtk.vtkTetra() -aTetra.GetPointIds().SetId(0,0) -aTetra.GetPointIds().SetId(1,1) -aTetra.GetPointIds().SetId(2,2) -aTetra.GetPointIds().SetId(3,3) +aTetra.GetPointIds().SetId(0, 0) +aTetra.GetPointIds().SetId(1, 1) +aTetra.GetPointIds().SetId(2, 2) +aTetra.GetPointIds().SetId(3, 3) + aTetraGrid = vtk.vtkUnstructuredGrid() -aTetraGrid.Allocate(1,1) -aTetraGrid.InsertNextCell(aTetra.GetCellType(),aTetra.GetPointIds()) +aTetraGrid.Allocate(1, 1) +aTetraGrid.InsertNextCell(aTetra.GetCellType(), aTetra.GetPointIds()) aTetraGrid.SetPoints(tetraPoints) + aTetraMapper = vtk.vtkDataSetMapper() aTetraMapper.SetInputData(aTetraGrid) + aTetraActor = vtk.vtkActor() aTetraActor.SetMapper(aTetraMapper) -aTetraActor.AddPosition(4,0,0) +aTetraActor.AddPosition(4, 0, 0) aTetraActor.GetProperty().BackfaceCullingOn() + # Wedge wedgePoints = vtk.vtkPoints() wedgePoints.SetNumberOfPoints(6) -wedgePoints.InsertPoint(0,0,1,0) -wedgePoints.InsertPoint(1,0,0,0) -wedgePoints.InsertPoint(2,0,.5,.5) -wedgePoints.InsertPoint(3,1,1,0) -wedgePoints.InsertPoint(4,1,0,0) -wedgePoints.InsertPoint(5,1,.5,.5) +wedgePoints.InsertPoint(0, 0, 1, 0) +wedgePoints.InsertPoint(1, 0, 0, 0) +wedgePoints.InsertPoint(2, 0, .5, .5) +wedgePoints.InsertPoint(3, 1, 1, 0) +wedgePoints.InsertPoint(4, 1, 0, 0) +wedgePoints.InsertPoint(5, 1, .5, .5) + aWedge = vtk.vtkWedge() -aWedge.GetPointIds().SetId(0,0) -aWedge.GetPointIds().SetId(1,1) -aWedge.GetPointIds().SetId(2,2) -aWedge.GetPointIds().SetId(3,3) -aWedge.GetPointIds().SetId(4,4) -aWedge.GetPointIds().SetId(5,5) +aWedge.GetPointIds().SetId(0, 0) +aWedge.GetPointIds().SetId(1, 1) +aWedge.GetPointIds().SetId(2, 2) +aWedge.GetPointIds().SetId(3, 3) +aWedge.GetPointIds().SetId(4, 4) +aWedge.GetPointIds().SetId(5, 5) + aWedgeGrid = vtk.vtkUnstructuredGrid() -aWedgeGrid.Allocate(1,1) -aWedgeGrid.InsertNextCell(aWedge.GetCellType(),aWedge.GetPointIds()) +aWedgeGrid.Allocate(1, 1) +aWedgeGrid.InsertNextCell(aWedge.GetCellType(), aWedge.GetPointIds()) aWedgeGrid.SetPoints(wedgePoints) + aWedgeMapper = vtk.vtkDataSetMapper() aWedgeMapper.SetInputData(aWedgeGrid) + aWedgeActor = vtk.vtkActor() aWedgeActor.SetMapper(aWedgeMapper) -aWedgeActor.AddPosition(6,0,0) +aWedgeActor.AddPosition(6, 0, 0) aWedgeActor.GetProperty().BackfaceCullingOn() + # Pyramid pyramidPoints = vtk.vtkPoints() pyramidPoints.SetNumberOfPoints(5) -pyramidPoints.InsertPoint(0,0,0,0) -pyramidPoints.InsertPoint(1,1,0,0) -pyramidPoints.InsertPoint(2,1,1,0) -pyramidPoints.InsertPoint(3,0,1,0) -pyramidPoints.InsertPoint(4,.5,.5,1) +pyramidPoints.InsertPoint(0, 0, 0, 0) +pyramidPoints.InsertPoint(1, 1, 0, 0) +pyramidPoints.InsertPoint(2, 1, 1, 0) +pyramidPoints.InsertPoint(3, 0, 1, 0) +pyramidPoints.InsertPoint(4, .5, .5, 1) + aPyramid = vtk.vtkPyramid() -aPyramid.GetPointIds().SetId(0,0) -aPyramid.GetPointIds().SetId(1,1) -aPyramid.GetPointIds().SetId(2,2) -aPyramid.GetPointIds().SetId(3,3) -aPyramid.GetPointIds().SetId(4,4) +aPyramid.GetPointIds().SetId(0, 0) +aPyramid.GetPointIds().SetId(1, 1) +aPyramid.GetPointIds().SetId(2, 2) +aPyramid.GetPointIds().SetId(3, 3) +aPyramid.GetPointIds().SetId(4, 4) + aPyramidGrid = vtk.vtkUnstructuredGrid() -aPyramidGrid.Allocate(1,1) -aPyramidGrid.InsertNextCell(aPyramid.GetCellType(),aPyramid.GetPointIds()) +aPyramidGrid.Allocate(1, 1) +aPyramidGrid.InsertNextCell(aPyramid.GetCellType(), aPyramid.GetPointIds()) aPyramidGrid.SetPoints(pyramidPoints) + aPyramidMapper = vtk.vtkDataSetMapper() aPyramidMapper.SetInputData(aPyramidGrid) + aPyramidActor = vtk.vtkActor() aPyramidActor.SetMapper(aPyramidMapper) -aPyramidActor.AddPosition(8,0,0) +aPyramidActor.AddPosition(8, 0, 0) aPyramidActor.GetProperty().BackfaceCullingOn() + # Pixel pixelPoints = vtk.vtkPoints() pixelPoints.SetNumberOfPoints(4) -pixelPoints.InsertPoint(0,0,0,0) -pixelPoints.InsertPoint(1,1,0,0) -pixelPoints.InsertPoint(2,0,1,0) -pixelPoints.InsertPoint(3,1,1,0) +pixelPoints.InsertPoint(0, 0, 0, 0) +pixelPoints.InsertPoint(1, 1, 0, 0) +pixelPoints.InsertPoint(2, 0, 1, 0) +pixelPoints.InsertPoint(3, 1, 1, 0) + aPixel = vtk.vtkPixel() -aPixel.GetPointIds().SetId(0,0) -aPixel.GetPointIds().SetId(1,1) -aPixel.GetPointIds().SetId(2,2) -aPixel.GetPointIds().SetId(3,3) +aPixel.GetPointIds().SetId(0, 0) +aPixel.GetPointIds().SetId(1, 1) +aPixel.GetPointIds().SetId(2, 2) +aPixel.GetPointIds().SetId(3, 3) + aPixelGrid = vtk.vtkUnstructuredGrid() -aPixelGrid.Allocate(1,1) -aPixelGrid.InsertNextCell(aPixel.GetCellType(),aPixel.GetPointIds()) +aPixelGrid.Allocate(1, 1) +aPixelGrid.InsertNextCell(aPixel.GetCellType(), aPixel.GetPointIds()) aPixelGrid.SetPoints(pixelPoints) + aPixelMapper = vtk.vtkDataSetMapper() aPixelMapper.SetInputData(aPixelGrid) + aPixelActor = vtk.vtkActor() aPixelActor.SetMapper(aPixelMapper) -aPixelActor.AddPosition(0,0,2) +aPixelActor.AddPosition(0, 0, 2) aPixelActor.GetProperty().BackfaceCullingOn() + # Quad quadPoints = vtk.vtkPoints() quadPoints.SetNumberOfPoints(4) -quadPoints.InsertPoint(0,0,0,0) -quadPoints.InsertPoint(1,1,0,0) -quadPoints.InsertPoint(2,1,1,0) -quadPoints.InsertPoint(3,0,1,0) +quadPoints.InsertPoint(0, 0, 0, 0) +quadPoints.InsertPoint(1, 1, 0, 0) +quadPoints.InsertPoint(2, 1, 1, 0) +quadPoints.InsertPoint(3, 0, 1, 0) + aQuad = vtk.vtkQuad() -aQuad.GetPointIds().SetId(0,0) -aQuad.GetPointIds().SetId(1,1) -aQuad.GetPointIds().SetId(2,2) -aQuad.GetPointIds().SetId(3,3) +aQuad.GetPointIds().SetId(0, 0) +aQuad.GetPointIds().SetId(1, 1) +aQuad.GetPointIds().SetId(2, 2) +aQuad.GetPointIds().SetId(3, 3) + aQuadGrid = vtk.vtkUnstructuredGrid() -aQuadGrid.Allocate(1,1) -aQuadGrid.InsertNextCell(aQuad.GetCellType(),aQuad.GetPointIds()) +aQuadGrid.Allocate(1, 1) +aQuadGrid.InsertNextCell(aQuad.GetCellType(), aQuad.GetPointIds()) aQuadGrid.SetPoints(quadPoints) + aQuadMapper = vtk.vtkDataSetMapper() aQuadMapper.SetInputData(aQuadGrid) + aQuadActor = vtk.vtkActor() aQuadActor.SetMapper(aQuadMapper) -aQuadActor.AddPosition(2,0,2) +aQuadActor.AddPosition(2, 0, 2) aQuadActor.GetProperty().BackfaceCullingOn() + # Triangle trianglePoints = vtk.vtkPoints() trianglePoints.SetNumberOfPoints(3) -trianglePoints.InsertPoint(0,0,0,0) -trianglePoints.InsertPoint(1,1,0,0) -trianglePoints.InsertPoint(2,.5,.5,0) +trianglePoints.InsertPoint(0, 0, 0, 0) +trianglePoints.InsertPoint(1, 1, 0, 0) +trianglePoints.InsertPoint(2, .5, .5, 0) + triangleTCoords = vtk.vtkFloatArray() triangleTCoords.SetNumberOfComponents(2) triangleTCoords.SetNumberOfTuples(3) -triangleTCoords.InsertTuple2(0,1,1) -triangleTCoords.InsertTuple2(1,2,2) -triangleTCoords.InsertTuple2(2,3,3) +triangleTCoords.InsertTuple2(0, 1, 1) +triangleTCoords.InsertTuple2(1, 2, 2) +triangleTCoords.InsertTuple2(2, 3, 3) + aTriangle = vtk.vtkTriangle() -aTriangle.GetPointIds().SetId(0,0) -aTriangle.GetPointIds().SetId(1,1) -aTriangle.GetPointIds().SetId(2,2) +aTriangle.GetPointIds().SetId(0, 0) +aTriangle.GetPointIds().SetId(1, 1) +aTriangle.GetPointIds().SetId(2, 2) + aTriangleGrid = vtk.vtkUnstructuredGrid() -aTriangleGrid.Allocate(1,1) -aTriangleGrid.InsertNextCell(aTriangle.GetCellType(),aTriangle.GetPointIds()) +aTriangleGrid.Allocate(1, 1) +aTriangleGrid.InsertNextCell(aTriangle.GetCellType(), aTriangle.GetPointIds()) aTriangleGrid.SetPoints(trianglePoints) aTriangleGrid.GetPointData().SetTCoords(triangleTCoords) + aTriangleMapper = vtk.vtkDataSetMapper() aTriangleMapper.SetInputData(aTriangleGrid) + aTriangleActor = vtk.vtkActor() aTriangleActor.SetMapper(aTriangleMapper) -aTriangleActor.AddPosition(4,0,2) +aTriangleActor.AddPosition(4, 0, 2) aTriangleActor.GetProperty().BackfaceCullingOn() + # Polygon polygonPoints = vtk.vtkPoints() polygonPoints.SetNumberOfPoints(4) -polygonPoints.InsertPoint(0,0,0,0) -polygonPoints.InsertPoint(1,1,0,0) -polygonPoints.InsertPoint(2,1,1,0) -polygonPoints.InsertPoint(3,0,1,0) +polygonPoints.InsertPoint(0, 0, 0, 0) +polygonPoints.InsertPoint(1, 1, 0, 0) +polygonPoints.InsertPoint(2, 1, 1, 0) +polygonPoints.InsertPoint(3, 0, 1, 0) + aPolygon = vtk.vtkPolygon() aPolygon.GetPointIds().SetNumberOfIds(4) -aPolygon.GetPointIds().SetId(0,0) -aPolygon.GetPointIds().SetId(1,1) -aPolygon.GetPointIds().SetId(2,2) -aPolygon.GetPointIds().SetId(3,3) +aPolygon.GetPointIds().SetId(0, 0) +aPolygon.GetPointIds().SetId(1, 1) +aPolygon.GetPointIds().SetId(2, 2) +aPolygon.GetPointIds().SetId(3, 3) + aPolygonGrid = vtk.vtkUnstructuredGrid() -aPolygonGrid.Allocate(1,1) -aPolygonGrid.InsertNextCell(aPolygon.GetCellType(),aPolygon.GetPointIds()) +aPolygonGrid.Allocate(1, 1) +aPolygonGrid.InsertNextCell(aPolygon.GetCellType(), aPolygon.GetPointIds()) aPolygonGrid.SetPoints(polygonPoints) + aPolygonMapper = vtk.vtkDataSetMapper() aPolygonMapper.SetInputData(aPolygonGrid) + aPolygonActor = vtk.vtkActor() aPolygonActor.SetMapper(aPolygonMapper) -aPolygonActor.AddPosition(6,0,2) +aPolygonActor.AddPosition(6, 0, 2) aPolygonActor.GetProperty().BackfaceCullingOn() + # Triangle strip triangleStripPoints = vtk.vtkPoints() triangleStripPoints.SetNumberOfPoints(5) -triangleStripPoints.InsertPoint(0,0,1,0) -triangleStripPoints.InsertPoint(1,0,0,0) -triangleStripPoints.InsertPoint(2,1,1,0) -triangleStripPoints.InsertPoint(3,1,0,0) -triangleStripPoints.InsertPoint(4,2,1,0) +triangleStripPoints.InsertPoint(0, 0, 1, 0) +triangleStripPoints.InsertPoint(1, 0, 0, 0) +triangleStripPoints.InsertPoint(2, 1, 1, 0) +triangleStripPoints.InsertPoint(3, 1, 0, 0) +triangleStripPoints.InsertPoint(4, 2, 1, 0) + triangleStripTCoords = vtk.vtkFloatArray() triangleStripTCoords.SetNumberOfComponents(2) triangleStripTCoords.SetNumberOfTuples(3) -triangleStripTCoords.InsertTuple2(0,1,1) -triangleStripTCoords.InsertTuple2(1,2,2) -triangleStripTCoords.InsertTuple2(2,3,3) -triangleStripTCoords.InsertTuple2(3,4,4) -triangleStripTCoords.InsertTuple2(4,5,5) +triangleStripTCoords.InsertTuple2(0, 1, 1) +triangleStripTCoords.InsertTuple2(1, 2, 2) +triangleStripTCoords.InsertTuple2(2, 3, 3) +triangleStripTCoords.InsertTuple2(3, 4, 4) +triangleStripTCoords.InsertTuple2(4, 5, 5) + aTriangleStrip = vtk.vtkTriangleStrip() aTriangleStrip.GetPointIds().SetNumberOfIds(5) -aTriangleStrip.GetPointIds().SetId(0,0) -aTriangleStrip.GetPointIds().SetId(1,1) -aTriangleStrip.GetPointIds().SetId(2,2) -aTriangleStrip.GetPointIds().SetId(3,3) -aTriangleStrip.GetPointIds().SetId(4,4) +aTriangleStrip.GetPointIds().SetId(0, 0) +aTriangleStrip.GetPointIds().SetId(1, 1) +aTriangleStrip.GetPointIds().SetId(2, 2) +aTriangleStrip.GetPointIds().SetId(3, 3) +aTriangleStrip.GetPointIds().SetId(4, 4) + aTriangleStripGrid = vtk.vtkUnstructuredGrid() -aTriangleStripGrid.Allocate(1,1) -aTriangleStripGrid.InsertNextCell(aTriangleStrip.GetCellType(),aTriangleStrip.GetPointIds()) +aTriangleStripGrid.Allocate(1, 1) +aTriangleStripGrid.InsertNextCell(aTriangleStrip.GetCellType(), aTriangleStrip.GetPointIds()) aTriangleStripGrid.SetPoints(triangleStripPoints) aTriangleStripGrid.GetPointData().SetTCoords(triangleStripTCoords) + aTriangleStripMapper = vtk.vtkDataSetMapper() aTriangleStripMapper.SetInputData(aTriangleStripGrid) + aTriangleStripActor = vtk.vtkActor() aTriangleStripActor.SetMapper(aTriangleStripMapper) -aTriangleStripActor.AddPosition(8,0,2) +aTriangleStripActor.AddPosition(8, 0, 2) aTriangleStripActor.GetProperty().BackfaceCullingOn() + # Line linePoints = vtk.vtkPoints() linePoints.SetNumberOfPoints(2) -linePoints.InsertPoint(0,0,0,0) -linePoints.InsertPoint(1,1,1,0) +linePoints.InsertPoint(0, 0, 0, 0) +linePoints.InsertPoint(1, 1, 1, 0) + aLine = vtk.vtkLine() -aLine.GetPointIds().SetId(0,0) -aLine.GetPointIds().SetId(1,1) +aLine.GetPointIds().SetId(0, 0) +aLine.GetPointIds().SetId(1, 1) + aLineGrid = vtk.vtkUnstructuredGrid() -aLineGrid.Allocate(1,1) -aLineGrid.InsertNextCell(aLine.GetCellType(),aLine.GetPointIds()) +aLineGrid.Allocate(1, 1) +aLineGrid.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds()) aLineGrid.SetPoints(linePoints) + aLineMapper = vtk.vtkDataSetMapper() aLineMapper.SetInputData(aLineGrid) + aLineActor = vtk.vtkActor() aLineActor.SetMapper(aLineMapper) -aLineActor.AddPosition(0,0,4) +aLineActor.AddPosition(0, 0, 4) aLineActor.GetProperty().BackfaceCullingOn() + # Polyline polyLinePoints = vtk.vtkPoints() polyLinePoints.SetNumberOfPoints(3) -polyLinePoints.InsertPoint(0,0,0,0) -polyLinePoints.InsertPoint(1,1,1,0) -polyLinePoints.InsertPoint(2,1,0,0) +polyLinePoints.InsertPoint(0, 0, 0, 0) +polyLinePoints.InsertPoint(1, 1, 1, 0) +polyLinePoints.InsertPoint(2, 1, 0, 0) + aPolyLine = vtk.vtkPolyLine() aPolyLine.GetPointIds().SetNumberOfIds(3) -aPolyLine.GetPointIds().SetId(0,0) -aPolyLine.GetPointIds().SetId(1,1) -aPolyLine.GetPointIds().SetId(2,2) +aPolyLine.GetPointIds().SetId(0, 0) +aPolyLine.GetPointIds().SetId(1, 1) +aPolyLine.GetPointIds().SetId(2, 2) + aPolyLineGrid = vtk.vtkUnstructuredGrid() -aPolyLineGrid.Allocate(1,1) -aPolyLineGrid.InsertNextCell(aPolyLine.GetCellType(),aPolyLine.GetPointIds()) +aPolyLineGrid.Allocate(1, 1) +aPolyLineGrid.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds()) aPolyLineGrid.SetPoints(polyLinePoints) + aPolyLineMapper = vtk.vtkDataSetMapper() aPolyLineMapper.SetInputData(aPolyLineGrid) + aPolyLineActor = vtk.vtkActor() aPolyLineActor.SetMapper(aPolyLineMapper) -aPolyLineActor.AddPosition(2,0,4) +aPolyLineActor.AddPosition(2, 0, 4) aPolyLineActor.GetProperty().BackfaceCullingOn() + # Vertex vertexPoints = vtk.vtkPoints() vertexPoints.SetNumberOfPoints(1) -vertexPoints.InsertPoint(0,0,0,0) +vertexPoints.InsertPoint(0, 0, 0, 0) + aVertex = vtk.vtkVertex() -aVertex.GetPointIds().SetId(0,0) +aVertex.GetPointIds().SetId(0, 0) + aVertexGrid = vtk.vtkUnstructuredGrid() -aVertexGrid.Allocate(1,1) -aVertexGrid.InsertNextCell(aVertex.GetCellType(),aVertex.GetPointIds()) +aVertexGrid.Allocate(1, 1) +aVertexGrid.InsertNextCell(aVertex.GetCellType(), aVertex.GetPointIds()) aVertexGrid.SetPoints(vertexPoints) + aVertexMapper = vtk.vtkDataSetMapper() aVertexMapper.SetInputData(aVertexGrid) + aVertexActor = vtk.vtkActor() aVertexActor.SetMapper(aVertexMapper) -aVertexActor.AddPosition(0,0,6) +aVertexActor.AddPosition(0, 0, 6) aVertexActor.GetProperty().BackfaceCullingOn() + # Polyvertex polyVertexPoints = vtk.vtkPoints() polyVertexPoints.SetNumberOfPoints(3) -polyVertexPoints.InsertPoint(0,0,0,0) -polyVertexPoints.InsertPoint(1,1,0,0) -polyVertexPoints.InsertPoint(2,1,1,0) +polyVertexPoints.InsertPoint(0, 0, 0, 0) +polyVertexPoints.InsertPoint(1, 1, 0, 0) +polyVertexPoints.InsertPoint(2, 1, 1, 0) + aPolyVertex = vtk.vtkPolyVertex() aPolyVertex.GetPointIds().SetNumberOfIds(3) -aPolyVertex.GetPointIds().SetId(0,0) -aPolyVertex.GetPointIds().SetId(1,1) -aPolyVertex.GetPointIds().SetId(2,2) +aPolyVertex.GetPointIds().SetId(0, 0) +aPolyVertex.GetPointIds().SetId(1, 1) +aPolyVertex.GetPointIds().SetId(2, 2) + aPolyVertexGrid = vtk.vtkUnstructuredGrid() -aPolyVertexGrid.Allocate(1,1) -aPolyVertexGrid.InsertNextCell(aPolyVertex.GetCellType(),aPolyVertex.GetPointIds()) +aPolyVertexGrid.Allocate(1, 1) +aPolyVertexGrid.InsertNextCell(aPolyVertex.GetCellType(), aPolyVertex.GetPointIds()) aPolyVertexGrid.SetPoints(polyVertexPoints) + aPolyVertexMapper = vtk.vtkDataSetMapper() aPolyVertexMapper.SetInputData(aPolyVertexGrid) + aPolyVertexActor = vtk.vtkActor() aPolyVertexActor.SetMapper(aPolyVertexMapper) -aPolyVertexActor.AddPosition(2,0,6) +aPolyVertexActor.AddPosition(2, 0, 6) aPolyVertexActor.GetProperty().BackfaceCullingOn() + # Pentagonal prism pentaPoints = vtk.vtkPoints() pentaPoints.SetNumberOfPoints(10) -pentaPoints.InsertPoint(0,0.25,0.0,0.0) -pentaPoints.InsertPoint(1,0.75,0.0,0.0) -pentaPoints.InsertPoint(2,1.0,0.5,0.0) -pentaPoints.InsertPoint(3,0.5,1.0,0.0) -pentaPoints.InsertPoint(4,0.0,0.5,0.0) -pentaPoints.InsertPoint(5,0.25,0.0,1.0) -pentaPoints.InsertPoint(6,0.75,0.0,1.0) -pentaPoints.InsertPoint(7,1.0,0.5,1.0) -pentaPoints.InsertPoint(8,0.5,1.0,1.0) -pentaPoints.InsertPoint(9,0.0,0.5,1.0) +pentaPoints.InsertPoint(0, 0.25, 0.0, 0.0) +pentaPoints.InsertPoint(1, 0.75, 0.0, 0.0) +pentaPoints.InsertPoint(2, 1.0, 0.5, 0.0) +pentaPoints.InsertPoint(3, 0.5, 1.0, 0.0) +pentaPoints.InsertPoint(4, 0.0, 0.5, 0.0) +pentaPoints.InsertPoint(5, 0.25, 0.0, 1.0) +pentaPoints.InsertPoint(6, 0.75, 0.0, 1.0) +pentaPoints.InsertPoint(7, 1.0, 0.5, 1.0) +pentaPoints.InsertPoint(8, 0.5, 1.0, 1.0) +pentaPoints.InsertPoint(9, 0.0, 0.5, 1.0) + aPenta = vtk.vtkPentagonalPrism() -aPenta.GetPointIds().SetId(0,0) -aPenta.GetPointIds().SetId(1,1) -aPenta.GetPointIds().SetId(2,2) -aPenta.GetPointIds().SetId(3,3) -aPenta.GetPointIds().SetId(4,4) -aPenta.GetPointIds().SetId(5,5) -aPenta.GetPointIds().SetId(6,6) -aPenta.GetPointIds().SetId(7,7) -aPenta.GetPointIds().SetId(8,8) -aPenta.GetPointIds().SetId(9,9) +aPenta.GetPointIds().SetId(0, 0) +aPenta.GetPointIds().SetId(1, 1) +aPenta.GetPointIds().SetId(2, 2) +aPenta.GetPointIds().SetId(3, 3) +aPenta.GetPointIds().SetId(4, 4) +aPenta.GetPointIds().SetId(5, 5) +aPenta.GetPointIds().SetId(6, 6) +aPenta.GetPointIds().SetId(7, 7) +aPenta.GetPointIds().SetId(8, 8) +aPenta.GetPointIds().SetId(9, 9) + aPentaGrid = vtk.vtkUnstructuredGrid() -aPentaGrid.Allocate(1,1) -aPentaGrid.InsertNextCell(aPenta.GetCellType(),aPenta.GetPointIds()) +aPentaGrid.Allocate(1, 1) +aPentaGrid.InsertNextCell(aPenta.GetCellType(), aPenta.GetPointIds()) aPentaGrid.SetPoints(pentaPoints) + aPentaMapper = vtk.vtkDataSetMapper() aPentaMapper.SetInputData(aPentaGrid) + aPentaActor = vtk.vtkActor() aPentaActor.SetMapper(aPentaMapper) -aPentaActor.AddPosition(10,0,0) +aPentaActor.AddPosition(10, 0, 0) aPentaActor.GetProperty().BackfaceCullingOn() + # Hexagonal prism hexaPoints = vtk.vtkPoints() hexaPoints.SetNumberOfPoints(12) -hexaPoints.InsertPoint(0,0.0,0.0,0.0) -hexaPoints.InsertPoint(1,0.5,0.0,0.0) -hexaPoints.InsertPoint(2,1.0,0.5,0.0) -hexaPoints.InsertPoint(3,1.0,1.0,0.0) -hexaPoints.InsertPoint(4,0.5,1.0,0.0) -hexaPoints.InsertPoint(5,0.0,0.5,0.0) -hexaPoints.InsertPoint(6,0.0,0.0,1.0) -hexaPoints.InsertPoint(7,0.5,0.0,1.0) -hexaPoints.InsertPoint(8,1.0,0.5,1.0) -hexaPoints.InsertPoint(9,1.0,1.0,1.0) -hexaPoints.InsertPoint(10,0.5,1.0,1.0) -hexaPoints.InsertPoint(11,0.0,0.5,1.0) +hexaPoints.InsertPoint(0, 0.0, 0.0, 0.0) +hexaPoints.InsertPoint(1, 0.5, 0.0, 0.0) +hexaPoints.InsertPoint(2, 1.0, 0.5, 0.0) +hexaPoints.InsertPoint(3, 1.0, 1.0, 0.0) +hexaPoints.InsertPoint(4, 0.5, 1.0, 0.0) +hexaPoints.InsertPoint(5, 0.0, 0.5, 0.0) +hexaPoints.InsertPoint(6, 0.0, 0.0, 1.0) +hexaPoints.InsertPoint(7, 0.5, 0.0, 1.0) +hexaPoints.InsertPoint(8, 1.0, 0.5, 1.0) +hexaPoints.InsertPoint(9, 1.0, 1.0, 1.0) +hexaPoints.InsertPoint(10, 0.5, 1.0, 1.0) +hexaPoints.InsertPoint(11, 0.0, 0.5, 1.0) + aHexa = vtk.vtkHexagonalPrism() -aHexa.GetPointIds().SetId(0,0) -aHexa.GetPointIds().SetId(1,1) -aHexa.GetPointIds().SetId(2,2) -aHexa.GetPointIds().SetId(3,3) -aHexa.GetPointIds().SetId(4,4) -aHexa.GetPointIds().SetId(5,5) -aHexa.GetPointIds().SetId(6,6) -aHexa.GetPointIds().SetId(7,7) -aHexa.GetPointIds().SetId(8,8) -aHexa.GetPointIds().SetId(9,9) -aHexa.GetPointIds().SetId(10,10) -aHexa.GetPointIds().SetId(11,11) +aHexa.GetPointIds().SetId(0, 0) +aHexa.GetPointIds().SetId(1, 1) +aHexa.GetPointIds().SetId(2, 2) +aHexa.GetPointIds().SetId(3, 3) +aHexa.GetPointIds().SetId(4, 4) +aHexa.GetPointIds().SetId(5, 5) +aHexa.GetPointIds().SetId(6, 6) +aHexa.GetPointIds().SetId(7, 7) +aHexa.GetPointIds().SetId(8, 8) +aHexa.GetPointIds().SetId(9, 9) +aHexa.GetPointIds().SetId(10, 10) +aHexa.GetPointIds().SetId(11, 11) + aHexaGrid = vtk.vtkUnstructuredGrid() -aHexaGrid.Allocate(1,1) -aHexaGrid.InsertNextCell(aHexa.GetCellType(),aHexa.GetPointIds()) +aHexaGrid.Allocate(1, 1) +aHexaGrid.InsertNextCell(aHexa.GetCellType(), aHexa.GetPointIds()) aHexaGrid.SetPoints(hexaPoints) + aHexaMapper = vtk.vtkDataSetMapper() aHexaMapper.SetInputData(aHexaGrid) + aHexaActor = vtk.vtkActor() aHexaActor.SetMapper(aHexaMapper) -aHexaActor.AddPosition(12,0,0) +aHexaActor.AddPosition(12, 0, 0) aHexaActor.GetProperty().BackfaceCullingOn() -ren1.SetBackground(1,1,1) + +ren1.SetBackground(1, 1, 1) + ren1.AddActor(aVoxelActor) -aVoxelActor.GetProperty().SetDiffuseColor(1,0,0) +aVoxelActor.GetProperty().SetDiffuseColor(1, 0, 0) + ren1.AddActor(aHexahedronActor) -aHexahedronActor.GetProperty().SetDiffuseColor(1,1,0) +aHexahedronActor.GetProperty().SetDiffuseColor(1, 1, 0) + ren1.AddActor(aTetraActor) -aTetraActor.GetProperty().SetDiffuseColor(0,1,0) +aTetraActor.GetProperty().SetDiffuseColor(0, 1, 0) + ren1.AddActor(aWedgeActor) -aWedgeActor.GetProperty().SetDiffuseColor(0,1,1) +aWedgeActor.GetProperty().SetDiffuseColor(0, 1, 1) + ren1.AddActor(aPyramidActor) -aPyramidActor.GetProperty().SetDiffuseColor(1,0,1) +aPyramidActor.GetProperty().SetDiffuseColor(1, 0, 1) + ren1.AddActor(aPixelActor) -aPixelActor.GetProperty().SetDiffuseColor(0,1,1) +aPixelActor.GetProperty().SetDiffuseColor(0, 1, 1) + ren1.AddActor(aQuadActor) -aQuadActor.GetProperty().SetDiffuseColor(1,0,1) +aQuadActor.GetProperty().SetDiffuseColor(1, 0, 1) + ren1.AddActor(aTriangleActor) -aTriangleActor.GetProperty().SetDiffuseColor(.3,1,.5) +aTriangleActor.GetProperty().SetDiffuseColor(.3, 1, .5) + ren1.AddActor(aPolygonActor) -aPolygonActor.GetProperty().SetDiffuseColor(1,.4,.5) +aPolygonActor.GetProperty().SetDiffuseColor(1, .4, .5) + ren1.AddActor(aTriangleStripActor) -aTriangleStripActor.GetProperty().SetDiffuseColor(.3,.7,1) +aTriangleStripActor.GetProperty().SetDiffuseColor(.3, .7, 1) + ren1.AddActor(aLineActor) -aLineActor.GetProperty().SetDiffuseColor(.2,1,1) +aLineActor.GetProperty().SetDiffuseColor(.2, 1, 1) + ren1.AddActor(aPolyLineActor) -aPolyLineActor.GetProperty().SetDiffuseColor(1,1,1) +aPolyLineActor.GetProperty().SetDiffuseColor(1, 1, 1) + ren1.AddActor(aVertexActor) -aVertexActor.GetProperty().SetDiffuseColor(1,1,1) +aVertexActor.GetProperty().SetDiffuseColor(1, 1, 1) + ren1.AddActor(aPolyVertexActor) -aPolyVertexActor.GetProperty().SetDiffuseColor(1,1,1) +aPolyVertexActor.GetProperty().SetDiffuseColor(1, 1, 1) + ren1.AddActor(aPentaActor) -aPentaActor.GetProperty().SetDiffuseColor(1,1,0) +aPentaActor.GetProperty().SetDiffuseColor(1, 1, 0) + ren1.AddActor(aHexaActor) -aHexaActor.GetProperty().SetDiffuseColor(1,1,0) +aHexaActor.GetProperty().SetDiffuseColor(1, 1, 0) + # # get the cell center of each type and put a glyph there # ball = vtk.vtkSphereSource() ball.SetRadius(.2) -for cell in "aVoxel aHexahedron aWedge aPyramid aTetra aPixel aQuad aTriangle aPolygon aTriangleStrip aLine aPolyLine aVertex aPolyVertex aPenta aHexa".split(): - locals()[get_variable_name("", cell, "Scalars")] = vtk.vtkFloatArray() - N = locals()[get_variable_name("", cell, "Grid")].GetNumberOfPoints() - locals()[get_variable_name("", cell, "Scalar")] = vtk.vtkFloatArray() - locals()[get_variable_name("", cell, "Scalar")].SetNumberOfTuples(N) - locals()[get_variable_name("", cell, "Scalar")].SetNumberOfComponents(1) + +cellType = ['aVoxel', 'aHexahedron', 'aWedge', 'aPyramid', 'aTetra', + 'aQuad', 'aTriangle', 'aTriangleStrip', 'aLine', + 'aPolyLine', 'aVertex', 'aPolyVertex', 'aPixel', + 'aPolygon', 'aPenta', 'aHexa'] +for cell in cellType: + N = eval(cell + 'Grid').GetNumberOfPoints() + + vn = cell + 'Scalar' + exec(vn + ' = vtk.vtkFloatArray()') + eval(vn).SetNumberOfTuples(N) + eval(vn).SetNumberOfComponents(1) + i = 0 while i < N: - locals()[get_variable_name("", cell, "Scalar")].SetValue(i,0) + eval(vn).SetValue(i, 0) i = i + 1 - locals()[get_variable_name("", cell, "Scalar")].SetValue(0,4) - locals()[get_variable_name("", cell, "Grid")].GetPointData().SetScalars(locals()[get_variable_name("", cell, "Scalar")]) - - pass -# write to the temp directory if possible, otherwise use . -dir = "." -if (info.commands(globals(), locals(), "rtTester") == "rtTester"): - dir = rtTester.GetTempDirectory() - pass -for cell in "aVoxel aHexahedron aWedge aPyramid aTetra aQuad aTriangle aTriangleStrip aLine aPolyLine aVertex aPolyVertex aPixel aPolygon aPenta aHexa".split(): - locals()[get_variable_name("", cell, "derivs")] = vtk.vtkCellDerivatives() - locals()[get_variable_name("", cell, "derivs")].SetInputData(locals()[get_variable_name("", cell, "Grid")]) - locals()[get_variable_name("", cell, "derivs")].SetVectorModeToComputeGradient() - FileName = dir - FileName += cell - FileName += ".vtk" - # make sure the directory is writeable first - if (catch.catch(globals(),"""channel = open("" + str(dir) + "/test.tmp", "w")""") == 0): - channel.close() - file.delete("-force", "" + str(dir) + "/test.tmp") - locals()[get_variable_name("", cell, "Writer")] = vtk.vtkUnstructuredGridWriter() - locals()[get_variable_name("", cell, "Writer")].SetInputConnection(locals()[get_variable_name("", cell, "derivs")].GetOutputPort()) - locals()[get_variable_name("", cell, "Writer")].SetFileName(FileName) - locals()[get_variable_name("", cell, "Writer")].Write() - # delete the file - file.delete("-force", FileName) - pass - locals()[get_variable_name("", cell, "Centers")] = vtk.vtkCellCenters() - locals()[get_variable_name("", cell, "Centers")].SetInputConnection(locals()[get_variable_name("", cell, "derivs")].GetOutputPort()) - locals()[get_variable_name("", cell, "Centers")].VertexCellsOn() - locals()[get_variable_name("", cell, "hog")] = vtk.vtkHedgeHog() - locals()[get_variable_name("", cell, "hog")].SetInputConnection(locals()[get_variable_name("", cell, "Centers")].GetOutputPort()) - locals()[get_variable_name("", cell, "mapHog")] = vtk.vtkPolyDataMapper() - locals()[get_variable_name("", cell, "mapHog")].SetInputConnection(locals()[get_variable_name("", cell, "hog")].GetOutputPort()) - locals()[get_variable_name("", cell, "mapHog")].SetScalarModeToUseCellData() - locals()[get_variable_name("", cell, "mapHog")].ScalarVisibilityOff() - locals()[get_variable_name("", cell, "hogActor")] = vtk.vtkActor() - locals()[get_variable_name("", cell, "hogActor")].SetMapper(locals()[get_variable_name("", cell, "mapHog")]) - locals()[get_variable_name("", cell, "hogActor")].GetProperty().SetColor(0,1,0) - locals()[get_variable_name("", cell, "Glyph3D")] = vtk.vtkGlyph3D() - locals()[get_variable_name("", cell, "Glyph3D")].SetInputConnection(locals()[get_variable_name("", cell, "Centers")].GetOutputPort()) - locals()[get_variable_name("", cell, "Glyph3D")].SetSourceData(ball.GetOutput()) - locals()[get_variable_name("", cell, "CentersMapper")] = vtk.vtkPolyDataMapper() - locals()[get_variable_name("", cell, "CentersMapper")].SetInputConnection(locals()[get_variable_name("", cell, "Glyph3D")].GetOutputPort()) - locals()[get_variable_name("", cell, "CentersActor")] = vtk.vtkActor() - locals()[get_variable_name("", cell, "CentersActor")].SetMapper(locals()[get_variable_name("", cell, "CentersMapper")]) - locals()[get_variable_name("", cell, "hogActor")].SetPosition(locals()[get_variable_name("", cell, "Actor")].GetPosition()) - ren1.AddActor(locals()[get_variable_name("", cell, "hogActor")]) - locals()[get_variable_name("", cell, "hogActor")].GetProperty().SetRepresentationToWireframe() - - pass + eval(vn).SetValue(0, 4) + + eval(cell + 'Grid').GetPointData().SetScalars(eval(vn)) + + for cell in cellType: + exec(cell + 'derivs' + ' = vtk.vtkCellDerivatives()') + eval(cell + 'derivs').SetInputData(eval(cell + 'Grid')) + eval(cell + 'derivs').SetVectorModeToComputeGradient() + + exec(cell + 'Centers' + ' = vtk.vtkCellCenters()') + eval(cell + 'Centers').SetInputConnection(eval(cell + 'derivs').GetOutputPort()) + eval(cell + 'Centers').VertexCellsOn() + + exec(cell + 'hog' + ' = vtk.vtkHedgeHog()') + eval(cell + 'hog').SetInputConnection(eval(cell + 'Centers').GetOutputPort()) + + exec(cell + 'mapHog' + ' = vtk.vtkPolyDataMapper()') + eval(cell + 'mapHog').SetInputConnection(eval(cell + 'hog').GetOutputPort()) + eval(cell + 'mapHog').SetScalarModeToUseCellData() + eval(cell + 'mapHog').ScalarVisibilityOff() + + exec(cell + 'hogActor' + ' = vtk.vtkActor()') + eval(cell + 'hogActor').SetMapper(eval(cell + 'mapHog')) + eval(cell + 'hogActor').GetProperty().SetColor(0, 1, 0) + + exec(cell + 'Glyph3D' + ' = vtk.vtkGlyph3D()') + eval(cell + 'Glyph3D').SetInputConnection(eval(cell + 'Centers').GetOutputPort()) + eval(cell + 'Glyph3D').SetSourceData(ball.GetOutput()) + + exec(cell + 'CentersMapper' + ' = vtk.vtkPolyDataMapper()') + eval(cell + 'CentersMapper').SetInputConnection(eval(cell + 'Glyph3D').GetOutputPort()) + + exec(cell + 'CentersActor' + ' = vtk.vtkActor()') + eval(cell + 'CentersActor').SetMapper(eval(cell + 'CentersMapper')) + + eval(cell + 'hogActor').SetPosition(eval(cell + 'Actor').GetPosition()) + ren1.AddActor(eval(cell + 'hogActor')) + eval(cell + 'hogActor').GetProperty().SetRepresentationToWireframe() + + ren1.ResetCamera() ren1.GetActiveCamera().Azimuth(30) ren1.GetActiveCamera().Elevation(20) ren1.GetActiveCamera().Dolly(3.0) ren1.ResetCameraClippingRange() -renWin.SetSize(300,150) + +renWin.SetSize(300, 150) + renWin.Render() + # render the image # iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Filters/General/Testing/Python/TestDiscreteMarchingCubes.py b/Filters/General/Testing/Python/TestDiscreteMarchingCubes.py index 16fb293e7d3..07417c01f95 100755 --- a/Filters/General/Testing/Python/TestDiscreteMarchingCubes.py +++ b/Filters/General/Testing/Python/TestDiscreteMarchingCubes.py @@ -11,71 +11,82 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + +math = vtk.vtkMath() + # Generate some random colors -def MakeColors (lut,n,__vtk__temp0=0,__vtk__temp1=0): - catch.catch(globals(),"""math = vtk.vtkMath()""") +def MakeColors (lut, n): lut.SetNumberOfColors(n) - lut.SetTableRange(0,expr.expr(globals(), locals(),["n","-1"])) + lut.SetTableRange(0, n - 1) lut.SetScaleToLinear() lut.Build() - lut.SetTableValue(0,0,0,0,1) + lut.SetTableValue(0, 0, 0, 0, 1) math.RandomSeed(5071) i = 1 while i < n: - lut.SetTableValue(i,math.Random(.2,1),math.Random(.2,1),math.Random(.2,1),1) - i = i + 1 - + lut.SetTableValue(i, math.Random(.2, 1), + math.Random(.2, 1), math.Random(.2, 1), 1) + i += 1 lut = vtk.vtkLookupTable() -MakeColors(lut,256) +MakeColors(lut, 256) n = 20 radius = 10 + # This has been moved outside the loop so that the code can be correctly # translated to python -catch.catch(globals(),"""blobImage = vtk.vtkImageData()""") +blobImage = vtk.vtkImageData() + i = 0 while i < n: - catch.catch(globals(),"""sphere = vtk.vtkSphere()""") + sphere = vtk.vtkSphere() sphere.SetRadius(radius) - max = expr.expr(globals(), locals(),["50","-","radius"]) - sphere.SetCenter(expr.expr(globals(), locals(),["int","(","math.Random(-max,max)",")"]),expr.expr(globals(), locals(),["int","(","math.Random(-max,max)",")"]),expr.expr(globals(), locals(),["int","(","math.Random(-max,max)",")"])) - catch.catch(globals(),"""sampler = vtk.vtkSampleFunction()""") + max = 50 - radius + sphere.SetCenter(int(math.Random(-max, max)), + int(math.Random(-max, max)), int(math.Random(-max, max))) + + sampler = vtk.vtkSampleFunction() sampler.SetImplicitFunction(sphere) sampler.SetOutputScalarTypeToFloat() - sampler.SetSampleDimensions(51,51,51) - sampler.SetModelBounds(-50,50,-50,50,-50,50) - catch.catch(globals(),"""thres = vtk.vtkImageThreshold()""") + sampler.SetSampleDimensions(51, 51, 51) + sampler.SetModelBounds(-50, 50, -50, 50, -50, 50) + + thres = vtk.vtkImageThreshold() thres.SetInputConnection(sampler.GetOutputPort()) - thres.ThresholdByLower(expr.expr(globals(), locals(),["radius","*","radius"])) + thres.ThresholdByLower(radius * radius) thres.ReplaceInOn() thres.ReplaceOutOn() - thres.SetInValue(expr.expr(globals(), locals(),["i","+","1"])) + thres.SetInValue(i + 1) thres.SetOutValue(0) thres.Update() if (i == 0): blobImage.DeepCopy(thres.GetOutput()) - pass - catch.catch(globals(),"""maxValue = vtk.vtkImageMathematics()""") - maxValue.SetInputData(0,blobImage) - maxValue.SetInputData(1,thres.GetOutput()) + + maxValue = vtk.vtkImageMathematics() + maxValue.SetInputData(0, blobImage) + maxValue.SetInputData(1, thres.GetOutput()) maxValue.SetOperationToMax() maxValue.Modified() maxValue.Update() + blobImage.DeepCopy(maxValue.GetOutput()) - i = i + 1 + + i += 1 discrete = vtk.vtkDiscreteMarchingCubes() discrete.SetInputData(blobImage) -discrete.GenerateValues(n,1,n) +discrete.GenerateValues(n, 1, n) + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(discrete.GetOutputPort()) mapper.SetLookupTable(lut) -mapper.SetScalarRange(0,lut.GetNumberOfColors()) +mapper.SetScalarRange(0, lut.GetNumberOfColors()) + actor = vtk.vtkActor() actor.SetMapper(mapper) + ren1.AddActor(actor) + renWin.Render() -# render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Filters/General/Testing/Python/TestGraphLayoutFilter.py b/Filters/General/Testing/Python/TestGraphLayoutFilter.py index a4f00054d6a..24a713e851e 100755 --- a/Filters/General/Testing/Python/TestGraphLayoutFilter.py +++ b/Filters/General/Testing/Python/TestGraphLayoutFilter.py @@ -4,19 +4,29 @@ 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 + # Create a simple graph (it's jittered from optimum) pts = vtk.vtkPoints() pts.SetNumberOfPoints(10) -pts.SetPoint(0,-0.5,1.0,-0.3) -pts.SetPoint(1,-3.0,0.1,0.2) -pts.SetPoint(2,0.0,0.0,0.0) -pts.SetPoint(3,1.2,-0.1,-0.2) -pts.SetPoint(4,0.2,-3.0,0.2) -pts.SetPoint(5,-4.2,-5.5,0.7) -pts.SetPoint(6,1.2,-7.3,-0.6) -pts.SetPoint(7,4.2,-5.5,0.7) -pts.SetPoint(8,0.0,0.0,-0.4) -pts.SetPoint(9,0.0,0.0,0.8) +pts.SetPoint(0, -0.5, 1.0, -0.3) +pts.SetPoint(1, -3.0, 0.1, 0.2) +pts.SetPoint(2, 0.0, 0.0, 0.0) +pts.SetPoint(3, 1.2, -0.1, -0.2) +pts.SetPoint(4, 0.2, -3.0, 0.2) +pts.SetPoint(5, -4.2, -5.5, 0.7) +pts.SetPoint(6, 1.2, -7.3, -0.6) +pts.SetPoint(7, 4.2, -5.5, 0.7) +pts.SetPoint(8, 0.0, 0.0, -0.4) +pts.SetPoint(9, 0.0, 0.0, 0.8) + lines = vtk.vtkCellArray() lines.InsertNextCell(4) lines.InsertCellPoint(0) @@ -41,69 +51,85 @@ lines.InsertCellPoint(8) lines.InsertNextCell(2) lines.InsertCellPoint(2) lines.InsertCellPoint(9) + pd = vtk.vtkPolyData() pd.SetPoints(pts) pd.SetLines(lines) + layout2D = vtk.vtkGraphLayoutFilter() layout2D.SetInputData(pd) layout2D.SetMaxNumberOfIterations(100) layout2D.ThreeDimensionalLayoutOff() layout2D.AutomaticBoundsComputationOff() -layout2D.SetGraphBounds(-2.0,0.0,-1.0,1.0,-1.0,1.0) +layout2D.SetGraphBounds(-2.0, 0.0, -1.0, 1.0, -1.0, 1.0) + layout3D = vtk.vtkGraphLayoutFilter() layout3D.SetInputData(pd) layout3D.SetMaxNumberOfIterations(100) layout3D.ThreeDimensionalLayoutOn() layout3D.AutomaticBoundsComputationOff() -layout3D.SetGraphBounds(0.0,2.0,-1.0,1.0,-1.0,1.0) +layout3D.SetGraphBounds(0.0, 2.0, -1.0, 1.0, -1.0, 1.0) + apf = vtk.vtkAppendPolyData() apf.AddInputConnection(layout2D.GetOutputPort()) apf.AddInputConnection(layout3D.GetOutputPort()) + tubes = vtk.vtkTubeFilter() tubes.SetInputConnection(apf.GetOutputPort()) tubes.SetRadius(0.01) tubes.SetNumberOfSides(6) + mapEdges = vtk.vtkPolyDataMapper() mapEdges.SetInputConnection(tubes.GetOutputPort()) + edgeActor = vtk.vtkActor() edgeActor.SetMapper(mapEdges) -edgeActor.GetProperty().SetColor(peacock) -edgeActor.GetProperty().SetSpecularColor(1,1,1) +edgeActor.GetProperty().SetColor(GetRGBColor('peacock')) +edgeActor.GetProperty().SetSpecularColor(1, 1, 1) edgeActor.GetProperty().SetSpecular(0.3) edgeActor.GetProperty().SetSpecularPower(20) edgeActor.GetProperty().SetAmbient(0.2) edgeActor.GetProperty().SetDiffuse(0.8) + ball = vtk.vtkSphereSource() ball.SetRadius(0.025) ball.SetThetaResolution(12) ball.SetPhiResolution(12) balls = vtk.vtkGlyph3D() + balls.SetInputConnection(apf.GetOutputPort()) balls.SetSourceConnection(ball.GetOutputPort()) + mapBalls = vtk.vtkPolyDataMapper() mapBalls.SetInputConnection(balls.GetOutputPort()) + ballActor = vtk.vtkActor() ballActor.SetMapper(mapBalls) -ballActor.GetProperty().SetColor(hot_pink) -ballActor.GetProperty().SetSpecularColor(1,1,1) +ballActor.GetProperty().SetColor(GetRGBColor('hot_pink')) +ballActor.GetProperty().SetSpecularColor(1, 1, 1) ballActor.GetProperty().SetSpecular(0.3) ballActor.GetProperty().SetSpecularPower(20) ballActor.GetProperty().SetAmbient(0.2) ballActor.GetProperty().SetDiffuse(0.8) + ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + ren1.AddActor(edgeActor) ren1.AddActor(ballActor) -ren1.SetBackground(1,1,1) -renWin.SetSize(400,250) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(400, 250) + cam1 = ren1.GetActiveCamera() -cam1.SetClippingRange(3.55085,6.01004) -cam1.SetFocalPoint(0.0427,-0.0149608,0.0) -cam1.SetPosition(0.0427,-0.0149608,4.63462) -cam1.SetViewUp(0,1,0) +cam1.SetClippingRange(3.55085, 6.01004) +cam1.SetFocalPoint(0.0427, -0.0149608, 0.0) +cam1.SetPosition(0.0427, -0.0149608, 4.63462) +cam1.SetViewUp(0, 1, 0) + iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/General/Testing/Python/TestMultiBlockStreamer.py b/Filters/General/Testing/Python/TestMultiBlockStreamer.py index ca1bde0c6a0..7fa83400b74 100755 --- a/Filters/General/Testing/Python/TestMultiBlockStreamer.py +++ b/Filters/General/Testing/Python/TestMultiBlockStreamer.py @@ -8,16 +8,18 @@ VTK_DATA_ROOT = vtkGetDataRoot() alg = vtk.vtkAlgorithm() pip = vtk.vtkCompositeDataPipeline() alg.SetDefaultExecutivePrototype(pip) -del pip +#del pip + Ren1 = vtk.vtkRenderer() -Ren1.SetBackground(0.33,0.35,0.43) +Ren1.SetBackground(0.33, 0.35, 0.43) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(Ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + Plot3D0 = vtk.vtkMultiBlockPLOT3DReader() -Plot3D0.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") -Plot3D0.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") +Plot3D0.SetFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") +Plot3D0.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") Plot3D0.SetBinaryFile(1) Plot3D0.SetMultiGrid(0) Plot3D0.SetHasByteCount(0) @@ -26,15 +28,19 @@ Plot3D0.SetTwoDimensionalGeometry(0) Plot3D0.SetForceRead(0) Plot3D0.SetByteOrder(0) Plot3D0.Update() + output = Plot3D0.GetOutput().GetBlock(0) + Geometry5 = vtk.vtkStructuredGridOutlineFilter() Geometry5.SetInputData(output) + Mapper5 = vtk.vtkPolyDataMapper() Mapper5.SetInputConnection(Geometry5.GetOutputPort()) Mapper5.SetImmediateModeRendering(1) Mapper5.UseLookupTableScalarRangeOn() Mapper5.SetScalarVisibility(0) Mapper5.SetScalarModeToDefault() + Actor5 = vtk.vtkActor() Actor5.SetMapper(Mapper5) Actor5.GetProperty().SetRepresentationToSurface() @@ -43,38 +49,44 @@ Actor5.GetProperty().SetAmbient(0.15) Actor5.GetProperty().SetDiffuse(0.85) Actor5.GetProperty().SetSpecular(0.1) Actor5.GetProperty().SetSpecularPower(100) -Actor5.GetProperty().SetSpecularColor(1,1,1) -Actor5.GetProperty().SetColor(1,1,1) +Actor5.GetProperty().SetSpecularColor(1, 1, 1) +Actor5.GetProperty().SetColor(1, 1, 1) + Ren1.AddActor(Actor5) + ExtractGrid0 = vtk.vtkExtractGrid() ExtractGrid0.SetInputData(output) -ExtractGrid0.SetVOI(0,14,0,32,0,24) -ExtractGrid0.SetSampleRate(1,1,1) +ExtractGrid0.SetVOI(0, 14, 0, 32, 0, 24) +ExtractGrid0.SetSampleRate(1, 1, 1) ExtractGrid0.SetIncludeBoundary(0) + ExtractGrid1 = vtk.vtkExtractGrid() ExtractGrid1.SetInputData(output) -ExtractGrid1.SetVOI(14,29,0,32,0,24) -ExtractGrid1.SetSampleRate(1,1,1) +ExtractGrid1.SetVOI(14, 29, 0, 32, 0, 24) +ExtractGrid1.SetSampleRate(1, 1, 1) ExtractGrid1.SetIncludeBoundary(0) + ExtractGrid2 = vtk.vtkExtractGrid() ExtractGrid2.SetInputData(output) -ExtractGrid2.SetVOI(29,56,0,32,0,24) -ExtractGrid2.SetSampleRate(1,1,1) +ExtractGrid2.SetVOI(29, 56, 0, 32, 0, 24) +ExtractGrid2.SetSampleRate(1, 1, 1) ExtractGrid2.SetIncludeBoundary(0) + LineSourceWidget0 = vtk.vtkLineSource() -LineSourceWidget0.SetPoint1(3.05638,-3.00497,28.2211) -LineSourceWidget0.SetPoint2(3.05638,3.95916,28.2211) +LineSourceWidget0.SetPoint1(3.05638, -3.00497, 28.2211) +LineSourceWidget0.SetPoint2(3.05638, 3.95916, 28.2211) LineSourceWidget0.SetResolution(20) + mbds = vtk.vtkMultiBlockDataSet() mbds.SetNumberOfBlocks(3) + i = 0 while i < 3: - locals()[get_variable_name("ExtractGrid", i, "")].Update() - locals()[get_variable_name("sg", i, "")] = vtk.vtkStructuredGrid() - locals()[get_variable_name("sg", i, "")].ShallowCopy(locals()[get_variable_name("ExtractGrid", i, "")].GetOutput()) - mbds.SetBlock(i,locals()[get_variable_name("sg", i, "")]) - del locals()[get_variable_name("sg", i, "")] - i = i + 1 + eval("ExtractGrid" + str(i)).Update() + exec("sg" + str(i) + " = vtk.vtkStructuredGrid()") + eval("sg" + str(i)).ShallowCopy(eval("ExtractGrid" + str(i)).GetOutput()) + mbds.SetBlock(i, eval("sg" + str(i))) + i += 1 Stream0 = vtk.vtkStreamTracer() Stream0.SetInputData(mbds) @@ -86,24 +98,29 @@ Stream0.SetIntegrationDirection(0) Stream0.SetIntegratorType(0) Stream0.SetMaximumNumberOfSteps(2000) Stream0.SetTerminalSpeed(1e-12) -del mbds + +#del mbds + aa = vtk.vtkAssignAttribute() aa.SetInputConnection(Stream0.GetOutputPort()) -aa.Assign("Normals","NORMALS","POINT_DATA") +aa.Assign("Normals", "NORMALS", "POINT_DATA") + Ribbon0 = vtk.vtkRibbonFilter() Ribbon0.SetInputConnection(aa.GetOutputPort()) Ribbon0.SetWidth(0.1) Ribbon0.SetAngle(0) -Ribbon0.SetDefaultNormal(0,0,1) +Ribbon0.SetDefaultNormal(0, 0, 1) Ribbon0.SetVaryWidth(0) + LookupTable1 = vtk.vtkLookupTable() LookupTable1.SetNumberOfTableValues(256) -LookupTable1.SetHueRange(0,0.66667) -LookupTable1.SetSaturationRange(1,1) -LookupTable1.SetValueRange(1,1) -LookupTable1.SetTableRange(0.197813,0.710419) +LookupTable1.SetHueRange(0, 0.66667) +LookupTable1.SetSaturationRange(1, 1) +LookupTable1.SetValueRange(1, 1) +LookupTable1.SetTableRange(0.197813, 0.710419) LookupTable1.SetVectorComponent(0) LookupTable1.Build() + Mapper10 = vtk.vtkPolyDataMapper() Mapper10.SetInputConnection(Ribbon0.GetOutputPort()) Mapper10.SetImmediateModeRendering(1) @@ -112,6 +129,7 @@ Mapper10.SetScalarVisibility(1) Mapper10.SetScalarModeToUsePointFieldData() Mapper10.SelectColorArray("Density") Mapper10.SetLookupTable(LookupTable1) + Actor10 = vtk.vtkActor() Actor10.SetMapper(Mapper10) Actor10.GetProperty().SetRepresentationToSurface() @@ -120,11 +138,13 @@ Actor10.GetProperty().SetAmbient(0.15) Actor10.GetProperty().SetDiffuse(0.85) Actor10.GetProperty().SetSpecular(0) Actor10.GetProperty().SetSpecularPower(1) -Actor10.GetProperty().SetSpecularColor(1,1,1) +Actor10.GetProperty().SetSpecularColor(1, 1, 1) + Ren1.AddActor(Actor10) -# enable user interface interactor + iren.Initialize() -# prevent the tk window from showing up then start the event loop + alg.SetDefaultExecutivePrototype(None) -del alg -# --- end of script -- +#del alg + +#iren.Start() diff --git a/Filters/General/Testing/Python/TestRandomAttributeGenerator.py b/Filters/General/Testing/Python/TestRandomAttributeGenerator.py index 1b5942e53cf..f35093e6109 100755 --- a/Filters/General/Testing/Python/TestRandomAttributeGenerator.py +++ b/Filters/General/Testing/Python/TestRandomAttributeGenerator.py @@ -1,56 +1,76 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Create the RenderWindow, Renderer and interactive renderer # ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) + # make sure to have the same regression image on all platforms. renWin.SetMultiSamples(0) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Force a starting random value raMath = vtk.vtkMath() raMath.RandomSeed(6) + # Generate random attributes on a plane # ps = vtk.vtkPlaneSource() ps.SetXResolution(10) ps.SetYResolution(10) + ag = vtk.vtkRandomAttributeGenerator() ag.SetInputConnection(ps.GetOutputPort()) ag.GenerateAllDataOn() + ss = vtk.vtkSphereSource() ss.SetPhiResolution(16) ss.SetThetaResolution(32) + tg = vtk.vtkTensorGlyph() tg.SetInputConnection(ag.GetOutputPort()) tg.SetSourceConnection(ss.GetOutputPort()) tg.SetScaleFactor(0.1) tg.SetMaxScaleFactor(10) tg.ClampScalingOn() + n = vtk.vtkPolyDataNormals() n.SetInputConnection(tg.GetOutputPort()) + cs = vtk.vtkConeSource() cs.SetResolution(6) + glyph = vtk.vtkGlyph3D() glyph.SetInputConnection(ag.GetOutputPort()) glyph.SetSourceConnection(cs.GetOutputPort()) glyph.SetScaleModeToDataScalingOff() glyph.SetScaleFactor(0.05) + pdm = vtk.vtkPolyDataMapper() pdm.SetInputConnection(n.GetOutputPort()) -#pdm SetInputConnection [glyph GetOutputPort] + +# pdm SetInputConnection [glyph GetOutputPort] a = vtk.vtkActor() a.SetMapper(pdm) + pm = vtk.vtkPolyDataMapper() pm.SetInputConnection(ps.GetOutputPort()) + pa = vtk.vtkActor() pa.SetMapper(pm) + ren1.AddActor(a) ren1.AddActor(pa) -ren1.SetBackground(0,0,0) -renWin.SetSize(300,300) +ren1.SetBackground(0, 0, 0) + +renWin.SetSize(300, 300) + renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Filters/General/Testing/Python/TestRectilinearGridToTetrahedra.py b/Filters/General/Testing/Python/TestRectilinearGridToTetrahedra.py index 9878bd81183..e0869640a28 100755 --- a/Filters/General/Testing/Python/TestRectilinearGridToTetrahedra.py +++ b/Filters/General/Testing/Python/TestRectilinearGridToTetrahedra.py @@ -4,68 +4,98 @@ from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() -### SetUp the pipeline +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 + +# SetUp the pipeline FormMesh = vtk.vtkRectilinearGridToTetrahedra() -FormMesh.SetInput(4,2,2,1,1,1,0.001) +FormMesh.SetInput(4, 2, 2, 1, 1, 1, 0.001) FormMesh.RememberVoxelIdOn() + TetraEdges = vtk.vtkExtractEdges() TetraEdges.SetInputConnection(FormMesh.GetOutputPort()) + tubes = vtk.vtkTubeFilter() tubes.SetInputConnection(TetraEdges.GetOutputPort()) tubes.SetRadius(0.05) tubes.SetNumberOfSides(6) -### Run the pipeline 3 times, with different conversions to TetMesh -Tubes1 = vtk.vtkPolyData() + +# Run the pipeline 3 times, with different conversions to TetMesh FormMesh.SetTetraPerCellTo5() + tubes.Update() + +Tubes1 = vtk.vtkPolyData() Tubes1.DeepCopy(tubes.GetOutput()) -Tubes2 = vtk.vtkPolyData() + FormMesh.SetTetraPerCellTo6() + tubes.Update() + +Tubes2 = vtk.vtkPolyData() Tubes2.DeepCopy(tubes.GetOutput()) -Tubes3 = vtk.vtkPolyData() + FormMesh.SetTetraPerCellTo12() + tubes.Update() + +Tubes3 = vtk.vtkPolyData() Tubes3.DeepCopy(tubes.GetOutput()) -### Run the pipeline once more, this time converting some cells to -### 5 and some data to 12 TetMesh -### Determine which cells are which + +# Run the pipeline once more, this time converting some cells to +# 5 and some data to 12 TetMesh +# Determine which cells are which DivTypes = vtk.vtkIntArray() numCell = FormMesh.GetInput().GetNumberOfCells() DivTypes.SetNumberOfValues(numCell) + i = 0 while i < numCell: - DivTypes.SetValue(i,expr.expr(globals(), locals(),["5","+","(","7","*","(","i","%","4","))"])) - i = i + 1 + DivTypes.SetValue(i, 5 + (7 * (i % 4))) + i += 1 -### Finish this pipeline -Tubes4 = vtk.vtkPolyData() +# Finish this pipeline FormMesh.SetTetraPerCellTo5And12() FormMesh.GetInput().GetCellData().SetScalars(DivTypes) + tubes.Update() + +Tubes4 = vtk.vtkPolyData() Tubes4.DeepCopy(tubes.GetOutput()) -### Finish the 4 pipelines + +# Finish the 4 pipelines i = 1 while i < 5: - locals()[get_variable_name("mapEdges", i, "")] = vtk.vtkPolyDataMapper() - locals()[get_variable_name("mapEdges", i, "")].SetInputData(locals()[get_variable_name("Tubes", i, "")]) - locals()[get_variable_name("edgeActor", i, "")] = vtk.vtkActor() - locals()[get_variable_name("edgeActor", i, "")].SetMapper(locals()[get_variable_name("mapEdges", i, "")]) - locals()[get_variable_name("edgeActor", i, "")].GetProperty().SetColor(peacock) - locals()[get_variable_name("edgeActor", i, "")].GetProperty().SetSpecularColor(1,1,1) - locals()[get_variable_name("edgeActor", i, "")].GetProperty().SetSpecular(0.3) - locals()[get_variable_name("edgeActor", i, "")].GetProperty().SetSpecularPower(20) - locals()[get_variable_name("edgeActor", i, "")].GetProperty().SetAmbient(0.2) - locals()[get_variable_name("edgeActor", i, "")].GetProperty().SetDiffuse(0.8) - locals()[get_variable_name("ren", i, "")] = vtk.vtkRenderer() - locals()[get_variable_name("ren", i, "")].AddActor(locals()[get_variable_name("edgeActor", i, "")]) - locals()[get_variable_name("ren", i, "")].SetBackground(0,0,0) - locals()[get_variable_name("ren", i, "")].ResetCamera() - locals()[get_variable_name("ren", i, "")].GetActiveCamera().Zoom(1) - locals()[get_variable_name("ren", i, "")].GetActiveCamera().SetPosition(1.73906,12.7987,-0.257808) - locals()[get_variable_name("ren", i, "")].GetActiveCamera().SetViewUp(0.992444,0.00890284,-0.122379) - locals()[get_variable_name("ren", i, "")].GetActiveCamera().SetClippingRange(9.36398,15.0496) - i = i + 1 + idx = str(i) + exec("mapEdges" + idx + " = vtk.vtkPolyDataMapper()") + eval("mapEdges" + idx).SetInputData(eval("Tubes" + idx)) + + exec("edgeActor" + idx + " = vtk.vtkActor()") + eval("edgeActor" + idx).SetMapper(eval("mapEdges" + idx)) + eval("edgeActor" + idx).GetProperty().SetColor(GetRGBColor('peacock')) + eval("edgeActor" + idx).GetProperty().SetSpecularColor(1, 1, 1) + eval("edgeActor" + idx).GetProperty().SetSpecular(0.3) + eval("edgeActor" + idx).GetProperty().SetSpecularPower(20) + eval("edgeActor" + idx).GetProperty().SetAmbient(0.2) + eval("edgeActor" + idx).GetProperty().SetDiffuse(0.8) + + exec("ren" + idx + " = vtk.vtkRenderer()") + eval("ren" + idx).AddActor(eval("edgeActor" + idx)) + eval("ren" + idx).SetBackground(0, 0, 0) + eval("ren" + idx).ResetCamera() + eval("ren" + idx).GetActiveCamera().Zoom(1) + eval("ren" + idx).GetActiveCamera().SetPosition( + 1.73906, 12.7987, -0.257808) + eval("ren" + idx).GetActiveCamera().SetViewUp( + 0.992444, 0.00890284, -0.122379) + eval("ren" + idx).GetActiveCamera().SetClippingRange(9.36398, 15.0496) + i += 1 # Create graphics objects # Create the rendering window, renderer, and interactive renderer @@ -74,16 +104,19 @@ renWin.AddRenderer(ren1) renWin.AddRenderer(ren2) renWin.AddRenderer(ren3) renWin.AddRenderer(ren4) -renWin.SetSize(600,300) + +renWin.SetSize(600, 300) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size -ren1.SetViewport(.75,0,1,1) -ren2.SetViewport(.50,0,.75,1) -ren3.SetViewport(.25,0,.50,1) -ren4.SetViewport(0,0,.25,1) +ren1.SetViewport(.75, 0, 1, 1) +ren2.SetViewport(.50, 0, .75, 1) +ren3.SetViewport(.25, 0, .50, 1) +ren4.SetViewport(0, 0, .25, 1) + # render the image # iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/General/Testing/Python/WarpScalarImage.py b/Filters/General/Testing/Python/WarpScalarImage.py index e4aa991f32d..8cf76c44179 100755 --- a/Filters/General/Testing/Python/WarpScalarImage.py +++ b/Filters/General/Testing/Python/WarpScalarImage.py @@ -1,12 +1,22 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() + # create a rendering window renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) -renWin.SetSize(200,200) + +renWin.SetSize(200, 200) + +iren = vtk.vtkRenderWindowInteractor() +iren.SetRenderWindow(renWin) + wavelet = vtk.vtkRTAnalyticSource() -wavelet.SetWholeExtent(-100,100,-100,100,0,0) -wavelet.SetCenter(0,0,0) +wavelet.SetWholeExtent(-100, 100, -100, 100, 0, 0) +wavelet.SetCenter(0, 0, 0) wavelet.SetMaximum(255) wavelet.SetStandardDeviation(.5) wavelet.SetXFreq(60) @@ -16,16 +26,25 @@ wavelet.SetXMag(10) wavelet.SetYMag(18) wavelet.SetZMag(5) wavelet.SetSubsampleRate(1) + warp = vtk.vtkWarpScalar() warp.SetInputConnection(wavelet.GetOutputPort()) + mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(warp.GetOutputPort()) -mapper.SetScalarRange(75,290) +mapper.SetScalarRange(75, 290) + actor = vtk.vtkActor() actor.SetMapper(mapper) + renderer = vtk.vtkRenderer() renderer.AddActor(actor) renderer.ResetCamera() renderer.GetActiveCamera().Elevation(-10) + renWin.AddRenderer(renderer) -# --- end of script -- + +# render the image +# +iren.Initialize() +#iren.Start() diff --git a/Filters/General/Testing/Python/WarpVectorImage.py b/Filters/General/Testing/Python/WarpVectorImage.py index 3556777ee7e..463e9576b58 100755 --- a/Filters/General/Testing/Python/WarpVectorImage.py +++ b/Filters/General/Testing/Python/WarpVectorImage.py @@ -1,21 +1,30 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # create pipeline # reader = vtk.vtkDataSetReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/RectGrid2.vtk") +reader.SetFileName(VTK_DATA_ROOT + "/Data/RectGrid2.vtk") reader.Update() + warper = vtk.vtkWarpVector() warper.SetInputConnection(reader.GetOutputPort()) warper.SetScaleFactor(0.2) + extract = vtk.vtkExtractGrid() extract.SetInputConnection(warper.GetOutputPort()) -extract.SetVOI(0,100,0,100,7,15) +extract.SetVOI(0, 100, 0, 100, 7, 15) + mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(extract.GetOutputPort()) -mapper.SetScalarRange(0.197813,0.710419) +mapper.SetScalarRange(0.197813, 0.710419) + actor = vtk.vtkActor() actor.SetMapper(mapper) + # Graphics stuff # Create the RenderWindow, Renderer and both Actors # @@ -25,18 +34,21 @@ renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(actor) -ren1.SetBackground(1,1,1) -renWin.SetSize(400,400) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(400, 400) + cam1 = ren1.GetActiveCamera() -cam1.SetClippingRange(3.76213,10.712) -cam1.SetFocalPoint(-0.0842503,-0.136905,0.610234) -cam1.SetPosition(2.53813,2.2678,-5.22172) -cam1.SetViewUp(-0.241047,0.930635,0.275343) -iren.Initialize() +cam1.SetClippingRange(3.76213, 10.712) +cam1.SetFocalPoint(-0.0842503, -0.136905, 0.610234) +cam1.SetPosition(2.53813, 2.2678, -5.22172) +cam1.SetViewUp(-0.241047, 0.930635, 0.275343) + # render the image # -# prevent the tk window from showing up then start the event loop -# --- end of script -- +iren.Initialize() +#iren.Start() diff --git a/Filters/General/Testing/Python/backdrop.py b/Filters/General/Testing/Python/backdrop.py new file mode 100644 index 00000000000..77436c43191 --- /dev/null +++ b/Filters/General/Testing/Python/backdrop.py @@ -0,0 +1,74 @@ +"""this is python equivalent of ./Wrapping/Tcl/vtktesting/backdrop.tcl +This script is used while running python tests translated from Tcl.""" + +import vtk + +basePlane = None +baseMapper = None +base = None + +backPlane = None +backMapper = None +back = None + +leftPlane = None +leftMapper = None +left = None + +def BuildBackdrop (minX, maxX, minY, maxY, minZ, maxZ, thickness): + global basePlane + global baseMapper + global base + global backPlane + global backMapper + global back + global left + global leftPlane + global leftMapper + + if not basePlane: + basePlane = vtk.vtkCubeSource() + basePlane.SetCenter( (maxX + minX)/2.0, minY, (maxZ + minZ)/2.0) + basePlane.SetXLength(maxX-minX) + basePlane.SetYLength(thickness) + basePlane.SetZLength(maxZ - minZ) + + if not baseMapper: + baseMapper = vtk.vtkPolyDataMapper() + baseMapper.SetInputConnection(basePlane.GetOutputPort()) + + if not base: + base = vtk.vtkActor() + base.SetMapper(baseMapper) + + if not backPlane: + backPlane = vtk.vtkCubeSource() + backPlane.SetCenter( (maxX + minX)/2.0, (maxY + minY)/2.0, minZ) + backPlane.SetXLength(maxX-minX) + backPlane.SetYLength(maxY - minY) + backPlane.SetZLength(thickness) + + if not backMapper: + backMapper = vtk.vtkPolyDataMapper() + backMapper.SetInputConnection(backPlane.GetOutputPort()) + + if not back: + back = vtk.vtkActor() + back.SetMapper(backMapper) + + if not leftPlane: + leftPlane = vtk.vtkCubeSource() + leftPlane.SetCenter( minX, (maxY+minY)/2.0, (maxZ+minZ)/2.0) + leftPlane.SetXLength(thickness) + leftPlane.SetYLength(maxY-minY) + leftPlane.SetZLength(maxZ-minZ) + + if not leftMapper: + leftMapper = vtk.vtkPolyDataMapper() + leftMapper.SetInputConnection(leftPlane.GetOutputPort()) + + if not left: + left = vtk.vtkActor() + left.SetMapper(leftMapper) + + return [base, back, left] diff --git a/Filters/General/Testing/Python/blankGrid.py b/Filters/General/Testing/Python/blankGrid.py index 9163da3b8c0..6da83ffb135 100755 --- a/Filters/General/Testing/Python/blankGrid.py +++ b/Filters/General/Testing/Python/blankGrid.py @@ -4,123 +4,159 @@ 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 + # Demonstrate how to use structured grid blanking with an image. There are two # techniques demonstrated: one uses an image to perform the blanking; # the other uses scalar values to do the same thing. Both images should # be identical. # -# get the interactor ui # create pipeline - start by extracting a single plane from the grid # pl3d = vtk.vtkMultiBlockPLOT3DReader() -pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") -pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") +pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") +pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() + output = pl3d.GetOutput().GetBlock(0) + plane = vtk.vtkExtractGrid() plane.SetInputData(output) -plane.SetVOI(0,57,0,33,0,0) +plane.SetVOI(0, 57, 0, 33, 0, 0) plane.Update() + # Create some data to use for the (image) blanking # blankImage = vtk.vtkImageData() -#vtkType.h has definitions for vtk datatypes VTK_INT, VTK_FLOAT, etc. that -#don't get wrapped in Tcl. + +# vtkType.h has definitions for vtk datatypes VTK_INT, VTK_FLOAT, etc. that +# don't get wrapped in Tcl. VTK_UNSIGNED_CHAR = 3 -blankImage.SetDimensions(57,33,1) -blankImage.AllocateScalars(VTK_UNSIGNED_CHAR,1) + +blankImage.SetDimensions(57, 33, 1) +blankImage.AllocateScalars(VTK_UNSIGNED_CHAR, 1) blankImage.GetPointData().GetScalars().SetName("blankScalars") + blanking = blankImage.GetPointData().GetScalars() -numBlanks = expr.expr(globals(), locals(),["57","*","33"]) +numBlanks = 57 * 33 i = 0 while i < numBlanks: - blanking.SetComponent(i,0,1) - i = i + 1 + blanking.SetComponent(i, 0, 1) + i += 1 # Manually blank out areas corresponding to dilution holes -blanking.SetComponent(318,0,0) -blanking.SetComponent(945,0,0) -blanking.SetComponent(1572,0,0) -blanking.SetComponent(641,0,0) -blanking.SetComponent(1553,0,0) +blanking.SetComponent(318, 0, 0) +blanking.SetComponent(945, 0, 0) +blanking.SetComponent(1572, 0, 0) +blanking.SetComponent(641, 0, 0) +blanking.SetComponent(1553, 0, 0) + # The first blanking technique uses the image to set the blanking values # blankIt = vtk.vtkBlankStructuredGridWithImage() blankIt.SetInputConnection(plane.GetOutputPort()) blankIt.SetBlankingInputData(blankImage) + blankedPlane = vtk.vtkStructuredGridGeometryFilter() blankedPlane.SetInputConnection(blankIt.GetOutputPort()) -blankedPlane.SetExtent(0,100,0,100,0,0) +blankedPlane.SetExtent(0, 100, 0, 100, 0, 0) + planeMapper = vtk.vtkPolyDataMapper() planeMapper.SetInputConnection(blankedPlane.GetOutputPort()) -planeMapper.SetScalarRange(0.197813,0.710419) +planeMapper.SetScalarRange(0.197813, 0.710419) + planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) + # The second blanking technique uses grid data values to create the blanking. # Here we borrow the image data and threshold on that. # anotherGrid = vtk.vtkStructuredGrid() anotherGrid.CopyStructure(plane.GetOutput()) anotherGrid.GetPointData().SetScalars(blankImage.GetPointData().GetScalars()) + blankGrid = vtk.vtkBlankStructuredGrid() blankGrid.SetInputData(anotherGrid) blankGrid.SetArrayName("blankScalars") blankGrid.SetMinBlankingValue(-0.5) blankGrid.SetMaxBlankingValue(0.5) + blankedPlane2 = vtk.vtkStructuredGridGeometryFilter() blankedPlane2.SetInputConnection(blankGrid.GetOutputPort()) -blankedPlane2.SetExtent(0,100,0,100,0,0) +blankedPlane2.SetExtent(0, 100, 0, 100, 0, 0) + planeMapper2 = vtk.vtkPolyDataMapper() planeMapper2.SetInputConnection(blankedPlane2.GetOutputPort()) -planeMapper2.SetScalarRange(0.197813,0.710419) +planeMapper2.SetScalarRange(0.197813, 0.710419) + planeActor2 = vtk.vtkActor() planeActor2.SetMapper(planeMapper2) + # An outline around the data # outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(output) + outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) -outlineActor.GetProperty().SetColor(black) +outlineActor.GetProperty().SetColor(GetRGBColor('black')) + outlineMapper2 = vtk.vtkPolyDataMapper() outlineMapper2.SetInputConnection(outline.GetOutputPort()) + outlineActor2 = vtk.vtkActor() outlineActor2.SetMapper(outlineMapper2) -outlineActor2.GetProperty().SetColor(black) +outlineActor2.GetProperty().SetColor(GetRGBColor('black')) + # create planes # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() -ren1.SetViewport(0,0,0.5,1) +ren1.SetViewport(0, 0, 0.5, 1) ren2 = vtk.vtkRenderer() -ren2.SetViewport(0.5,0,1,1) +ren2.SetViewport(0.5, 0, 1, 1) renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) renWin.AddRenderer(ren2) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) ren1.AddActor(planeActor) + ren2.AddActor(outlineActor2) ren2.AddActor(planeActor2) -ren1.SetBackground(1,1,1) -ren2.SetBackground(1,1,1) -renWin.SetSize(500,250) + +ren1.SetBackground(1, 1, 1) +ren2.SetBackground(1, 1, 1) + +renWin.SetSize(500, 250) + cam1 = ren1.GetActiveCamera() -cam1.SetClippingRange(3.95297,50) -cam1.SetFocalPoint(8.88908,0.595038,29.3342) -cam1.SetPosition(-12.3332,31.7479,41.2387) -cam1.SetViewUp(0.060772,-0.319905,0.945498) +cam1.SetClippingRange(3.95297, 50) +cam1.SetFocalPoint(8.88908, 0.595038, 29.3342) +cam1.SetPosition(-12.3332, 31.7479, 41.2387) +cam1.SetViewUp(0.060772, -0.319905, 0.945498) + ren2.SetActiveCamera(ren1.GetActiveCamera()) + # render the image # renWin.Render() + iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/General/Testing/Python/clipComb.py b/Filters/General/Testing/Python/clipComb.py index 474fb31ce45..7fc4e6a3ade 100755 --- a/Filters/General/Testing/Python/clipComb.py +++ b/Filters/General/Testing/Python/clipComb.py @@ -7,41 +7,53 @@ VTK_DATA_ROOT = vtkGetDataRoot() # create pipeline # pl3d = vtk.vtkMultiBlockPLOT3DReader() -pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") -pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") +pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") +pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() + output = pl3d.GetOutput().GetBlock(0) + # create a crazy implicit function center = output.GetCenter() sphere = vtk.vtkSphere() sphere.SetCenter(center) sphere.SetRadius(2.0) + sphere2 = vtk.vtkSphere() -sphere2.SetCenter(expr.expr(globals(), locals(),["lindex(center,0)","+","4.0"]),lindex(center,1),lindex(center,2)) +sphere2.SetCenter(center[0] + 4.0, center[1], center[2]) sphere2.SetRadius(4.0) -bool = vtk.vtkImplicitBoolean() -bool.SetOperationTypeToUnion() -bool.AddFunction(sphere) -bool.AddFunction(sphere2) + +boolOp = vtk.vtkImplicitBoolean() +boolOp.SetOperationTypeToUnion() +boolOp.AddFunction(sphere) +boolOp.AddFunction(sphere2) + # clip the structured grid to produce a tetrahedral mesh clip = vtk.vtkClipDataSet() clip.SetInputData(output) -clip.SetClipFunction(bool) +clip.SetClipFunction(boolOp) clip.InsideOutOn() + gf = vtk.vtkGeometryFilter() gf.SetInputConnection(clip.GetOutputPort()) + clipMapper = vtk.vtkPolyDataMapper() clipMapper.SetInputConnection(gf.GetOutputPort()) + clipActor = vtk.vtkActor() clipActor.SetMapper(clipMapper) + outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(output) + outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -49,21 +61,25 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(clipActor) ren1.AddActor(outlineActor) -ren1.SetBackground(1,1,1) -renWin.SetSize(250,250) -ren1.SetBackground(0.1,0.2,0.4) + +ren1.SetBackground(1, 1, 1) +renWin.SetSize(250, 250) +ren1.SetBackground(0.1, 0.2, 0.4) + cam1 = ren1.GetActiveCamera() -cam1.SetClippingRange(3.95297,50) -cam1.SetFocalPoint(8.88908,0.595038,29.3342) -cam1.SetPosition(-12.3332,31.7479,41.2387) -cam1.SetViewUp(0.060772,-0.319905,0.945498) +cam1.SetClippingRange(3.95297, 50) +cam1.SetFocalPoint(8.88908, 0.595038, 29.3342) +cam1.SetPosition(-12.3332, 31.7479, 41.2387) +cam1.SetViewUp(0.060772, -0.319905, 0.945498) iren.Initialize() + # render the image # renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Filters/General/Testing/Python/clipHex.py b/Filters/General/Testing/Python/clipHex.py index d3272d80f0e..b92d8bb2612 100755 --- a/Filters/General/Testing/Python/clipHex.py +++ b/Filters/General/Testing/Python/clipHex.py @@ -4,7 +4,16 @@ from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() -#define a Single Cube +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 + +# define a Single Cube Scalars = vtk.vtkFloatArray() Scalars.InsertNextValue(1.0) Scalars.InsertNextValue(1.0) @@ -14,15 +23,17 @@ Scalars.InsertNextValue(0.0) Scalars.InsertNextValue(0.0) Scalars.InsertNextValue(0.0) Scalars.InsertNextValue(0.0) + Points = vtk.vtkPoints() -Points.InsertNextPoint(0,0,0) -Points.InsertNextPoint(1,0,0) -Points.InsertNextPoint(1,1,0) -Points.InsertNextPoint(0,1,0) -Points.InsertNextPoint(0,0,1) -Points.InsertNextPoint(1,0,1) -Points.InsertNextPoint(1,1,1) -Points.InsertNextPoint(0,1,1) +Points.InsertNextPoint(0, 0, 0) +Points.InsertNextPoint(1, 0, 0) +Points.InsertNextPoint(1, 1, 0) +Points.InsertNextPoint(0, 1, 0) +Points.InsertNextPoint(0, 0, 1) +Points.InsertNextPoint(1, 0, 1) +Points.InsertNextPoint(1, 1, 1) +Points.InsertNextPoint(0, 1, 1) + Ids = vtk.vtkIdList() Ids.InsertNextId(0) Ids.InsertNextId(1) @@ -32,103 +43,130 @@ Ids.InsertNextId(4) Ids.InsertNextId(5) Ids.InsertNextId(6) Ids.InsertNextId(7) + Grid = vtk.vtkUnstructuredGrid() -Grid.Allocate(10,10) -Grid.InsertNextCell(12,Ids) +Grid.Allocate(10, 10) +Grid.InsertNextCell(12, Ids) Grid.SetPoints(Points) Grid.GetPointData().SetScalars(Scalars) -#Clip the hex + +# Clip the hex clipper = vtk.vtkClipDataSet() clipper.SetInputData(Grid) clipper.SetValue(0.5) + # build tubes for the triangle edges # tetEdges = vtk.vtkExtractEdges() tetEdges.SetInputConnection(clipper.GetOutputPort()) + tetEdgeTubes = vtk.vtkTubeFilter() tetEdgeTubes.SetInputConnection(tetEdges.GetOutputPort()) tetEdgeTubes.SetRadius(.005) tetEdgeTubes.SetNumberOfSides(6) tetEdgeTubes.UseDefaultNormalOn() -tetEdgeTubes.SetDefaultNormal(.577,.577,.577) +tetEdgeTubes.SetDefaultNormal(.577, .577, .577) + tetEdgeMapper = vtk.vtkPolyDataMapper() tetEdgeMapper.SetInputConnection(tetEdgeTubes.GetOutputPort()) tetEdgeMapper.ScalarVisibilityOff() + tetEdgeActor = vtk.vtkActor() tetEdgeActor.SetMapper(tetEdgeMapper) -tetEdgeActor.GetProperty().SetDiffuseColor(lamp_black) +tetEdgeActor.GetProperty().SetDiffuseColor(GetRGBColor('lamp_black')) tetEdgeActor.GetProperty().SetSpecular(.4) tetEdgeActor.GetProperty().SetSpecularPower(10) -#shrink the triangles so we can see each one + +# shrink the triangles so we can see each one aShrinker = vtk.vtkShrinkFilter() aShrinker.SetShrinkFactor(1) aShrinker.SetInputConnection(clipper.GetOutputPort()) + aMapper = vtk.vtkDataSetMapper() aMapper.ScalarVisibilityOff() aMapper.SetInputConnection(aShrinker.GetOutputPort()) + Tets = vtk.vtkActor() Tets.SetMapper(aMapper) -Tets.GetProperty().SetDiffuseColor(banana) -#build a model of the cube +Tets.GetProperty().SetDiffuseColor(GetRGBColor('banana')) + +# build a model of the cube CubeModel = vtk.vtkCubeSource() -CubeModel.SetCenter(.5,.5,.5) +CubeModel.SetCenter(.5, .5, .5) + Edges = vtk.vtkExtractEdges() Edges.SetInputConnection(CubeModel.GetOutputPort()) + Tubes = vtk.vtkTubeFilter() Tubes.SetInputConnection(Edges.GetOutputPort()) Tubes.SetRadius(.01) Tubes.SetNumberOfSides(6) Tubes.UseDefaultNormalOn() -Tubes.SetDefaultNormal(.577,.577,.577) +Tubes.SetDefaultNormal(.577, .577, .577) + TubeMapper = vtk.vtkPolyDataMapper() TubeMapper.SetInputConnection(Tubes.GetOutputPort()) + CubeEdges = vtk.vtkActor() CubeEdges.SetMapper(TubeMapper) -CubeEdges.GetProperty().SetDiffuseColor(khaki) +CubeEdges.GetProperty().SetDiffuseColor(GetRGBColor('khaki')) CubeEdges.GetProperty().SetSpecular(.4) CubeEdges.GetProperty().SetSpecularPower(10) + # build the vertices of the cube # Sphere = vtk.vtkSphereSource() Sphere.SetRadius(0.04) Sphere.SetPhiResolution(20) Sphere.SetThetaResolution(20) + ThresholdIn = vtk.vtkThresholdPoints() ThresholdIn.SetInputData(Grid) ThresholdIn.ThresholdByUpper(.5) + Vertices = vtk.vtkGlyph3D() Vertices.SetInputConnection(ThresholdIn.GetOutputPort()) Vertices.SetSourceConnection(Sphere.GetOutputPort()) + SphereMapper = vtk.vtkPolyDataMapper() SphereMapper.SetInputConnection(Vertices.GetOutputPort()) SphereMapper.ScalarVisibilityOff() + CubeVertices = vtk.vtkActor() CubeVertices.SetMapper(SphereMapper) -CubeVertices.GetProperty().SetDiffuseColor(tomato) -CubeVertices.GetProperty().SetDiffuseColor(tomato) -#define the text for the labels +CubeVertices.GetProperty().SetDiffuseColor(GetRGBColor('tomato')) + +# define the text for the labels caseLabel = vtk.vtkVectorText() caseLabel.SetText("Case 2") + aLabelTransform = vtk.vtkTransform() aLabelTransform.Identity() -aLabelTransform.Translate(-.2,0,1.25) -aLabelTransform.Scale(.05,.05,.05) +aLabelTransform.Translate(-.2, 0, 1.25) +aLabelTransform.Scale(.05, .05, .05) + labelTransform = vtk.vtkTransformPolyDataFilter() labelTransform.SetTransform(aLabelTransform) labelTransform.SetInputConnection(caseLabel.GetOutputPort()) + labelMapper = vtk.vtkPolyDataMapper() labelMapper.SetInputConnection(labelTransform.GetOutputPort()) + labelActor = vtk.vtkActor() labelActor.SetMapper(labelMapper) -#define the base + +# define the base baseModel = vtk.vtkCubeSource() baseModel.SetXLength(1.5) baseModel.SetYLength(.01) baseModel.SetZLength(1.5) + baseMapper = vtk.vtkPolyDataMapper() baseMapper.SetInputConnection(baseModel.GetOutputPort()) + base = vtk.vtkActor() base.SetMapper(baseMapper) + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -136,22 +174,41 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # position the base -base.SetPosition(.5,-.09,.5) +base.SetPosition(.5, -.09, .5) ren1.AddActor(tetEdgeActor) ren1.AddActor(base) ren1.AddActor(labelActor) ren1.AddActor(CubeEdges) ren1.AddActor(CubeVertices) ren1.AddActor(Tets) -ren1.SetBackground(slate_grey) +ren1.SetBackground(GetRGBColor('slate_grey')) + +def case2(scalars, IN, OUT, caseLabel): + scalars.InsertValue(0, IN) + scalars.InsertValue(1, IN) + scalars.InsertValue(2, OUT) + scalars.InsertValue(3, OUT) + scalars.InsertValue(4, OUT) + scalars.InsertValue(5, OUT) + scalars.InsertValue(6, OUT) + scalars.InsertValue(7, OUT) + if IN == 1: + caseLabel.SetText("Case 2 - 00000011") + else: + caseLabel.SetText("Case 2c - 11111100") + case2(Scalars, 1, 0, caseLabel) -renWin.SetSize(400,400) +renWin.SetSize(400, 400) + ren1.ResetCamera() ren1.GetActiveCamera().Dolly(1.2) ren1.GetActiveCamera().Azimuth(30) ren1.GetActiveCamera().Elevation(20) ren1.ResetCameraClippingRange() + renWin.Render() + iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Filters/General/Testing/Python/clipPyramid.py b/Filters/General/Testing/Python/clipPyramid.py index 12264a69059..fbde1d04f6d 100755 --- a/Filters/General/Testing/Python/clipPyramid.py +++ b/Filters/General/Testing/Python/clipPyramid.py @@ -4,7 +4,16 @@ from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() -#define a Single Cube +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 + +# define a Single Cube Scalars = vtk.vtkFloatArray() Scalars.InsertNextValue(1.0) Scalars.InsertNextValue(0.0) @@ -12,110 +21,138 @@ Scalars.InsertNextValue(0.0) Scalars.InsertNextValue(0.0) Scalars.InsertNextValue(0.0) Scalars.InsertNextValue(0.0) + Points = vtk.vtkPoints() -Points.InsertNextPoint(0,0,0) -Points.InsertNextPoint(1,0,0) -Points.InsertNextPoint(1,1,0) -Points.InsertNextPoint(0,1,0) -Points.InsertNextPoint(.5,.5,1) +Points.InsertNextPoint(0, 0, 0) +Points.InsertNextPoint(1, 0, 0) +Points.InsertNextPoint(1, 1, 0) +Points.InsertNextPoint(0, 1, 0) +Points.InsertNextPoint(.5, .5, 1) + Ids = vtk.vtkIdList() Ids.InsertNextId(0) Ids.InsertNextId(1) Ids.InsertNextId(2) Ids.InsertNextId(3) Ids.InsertNextId(4) + Grid = vtk.vtkUnstructuredGrid() -Grid.Allocate(10,10) -Grid.InsertNextCell(14,Ids) +Grid.Allocate(10, 10) +Grid.InsertNextCell(14, Ids) Grid.SetPoints(Points) Grid.GetPointData().SetScalars(Scalars) -#Clip the pyramid + +# Clip the pyramid clipper = vtk.vtkClipDataSet() clipper.SetInputData(Grid) clipper.SetValue(0.5) + # build tubes for the triangle edges # pyrEdges = vtk.vtkExtractEdges() pyrEdges.SetInputConnection(clipper.GetOutputPort()) + pyrEdgeTubes = vtk.vtkTubeFilter() pyrEdgeTubes.SetInputConnection(pyrEdges.GetOutputPort()) pyrEdgeTubes.SetRadius(.005) pyrEdgeTubes.SetNumberOfSides(6) + pyrEdgeMapper = vtk.vtkPolyDataMapper() pyrEdgeMapper.SetInputConnection(pyrEdgeTubes.GetOutputPort()) pyrEdgeMapper.ScalarVisibilityOff() + pyrEdgeActor = vtk.vtkActor() pyrEdgeActor.SetMapper(pyrEdgeMapper) -pyrEdgeActor.GetProperty().SetDiffuseColor(lamp_black) +pyrEdgeActor.GetProperty().SetDiffuseColor(GetRGBColor('lamp_black')) pyrEdgeActor.GetProperty().SetSpecular(.4) pyrEdgeActor.GetProperty().SetSpecularPower(10) -#shrink the triangles so we can see each one + +# shrink the triangles so we can see each one aShrinker = vtk.vtkShrinkFilter() aShrinker.SetShrinkFactor(1) aShrinker.SetInputConnection(clipper.GetOutputPort()) + aMapper = vtk.vtkDataSetMapper() aMapper.ScalarVisibilityOff() aMapper.SetInputConnection(aShrinker.GetOutputPort()) + Pyrs = vtk.vtkActor() Pyrs.SetMapper(aMapper) -Pyrs.GetProperty().SetDiffuseColor(banana) -#build a model of the pyramid +Pyrs.GetProperty().SetDiffuseColor(GetRGBColor('banana')) + +# build a model of the pyramid Edges = vtk.vtkExtractEdges() Edges.SetInputData(Grid) + Tubes = vtk.vtkTubeFilter() Tubes.SetInputConnection(Edges.GetOutputPort()) Tubes.SetRadius(.01) Tubes.SetNumberOfSides(6) + TubeMapper = vtk.vtkPolyDataMapper() TubeMapper.SetInputConnection(Tubes.GetOutputPort()) TubeMapper.ScalarVisibilityOff() + CubeEdges = vtk.vtkActor() CubeEdges.SetMapper(TubeMapper) -CubeEdges.GetProperty().SetDiffuseColor(khaki) +CubeEdges.GetProperty().SetDiffuseColor(GetRGBColor('khaki')) CubeEdges.GetProperty().SetSpecular(.4) CubeEdges.GetProperty().SetSpecularPower(10) + # build the vertices of the pyramid # Sphere = vtk.vtkSphereSource() Sphere.SetRadius(0.04) Sphere.SetPhiResolution(20) Sphere.SetThetaResolution(20) + ThresholdIn = vtk.vtkThresholdPoints() ThresholdIn.SetInputData(Grid) ThresholdIn.ThresholdByUpper(.5) + Vertices = vtk.vtkGlyph3D() Vertices.SetInputConnection(ThresholdIn.GetOutputPort()) Vertices.SetSourceConnection(Sphere.GetOutputPort()) + SphereMapper = vtk.vtkPolyDataMapper() SphereMapper.SetInputConnection(Vertices.GetOutputPort()) SphereMapper.ScalarVisibilityOff() + CubeVertices = vtk.vtkActor() CubeVertices.SetMapper(SphereMapper) -CubeVertices.GetProperty().SetDiffuseColor(tomato) -CubeVertices.GetProperty().SetDiffuseColor(tomato) -#define the text for the labels +CubeVertices.GetProperty().SetDiffuseColor(GetRGBColor('tomato')) + +# define the text for the labels caseLabel = vtk.vtkVectorText() caseLabel.SetText("Case 1") + aLabelTransform = vtk.vtkTransform() aLabelTransform.Identity() -aLabelTransform.Translate(-.2,0,1.25) -aLabelTransform.Scale(.05,.05,.05) +aLabelTransform.Translate(-.2, 0, 1.25) +aLabelTransform.Scale(.05, .05, .05) + labelTransform = vtk.vtkTransformPolyDataFilter() labelTransform.SetTransform(aLabelTransform) labelTransform.SetInputConnection(caseLabel.GetOutputPort()) + labelMapper = vtk.vtkPolyDataMapper() labelMapper.SetInputConnection(labelTransform.GetOutputPort()) + labelActor = vtk.vtkActor() labelActor.SetMapper(labelMapper) -#define the base + +# define the base baseModel = vtk.vtkCubeSource() baseModel.SetXLength(1.5) baseModel.SetYLength(.01) baseModel.SetZLength(1.5) + baseMapper = vtk.vtkPolyDataMapper() baseMapper.SetInputConnection(baseModel.GetOutputPort()) + base = vtk.vtkActor() base.SetMapper(baseMapper) + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -123,39 +160,47 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # position the base -base.SetPosition(.5,-.09,.5) +base.SetPosition(.5, -.09, .5) + ren1.AddActor(pyrEdgeActor) ren1.AddActor(base) ren1.AddActor(labelActor) ren1.AddActor(CubeEdges) ren1.AddActor(CubeVertices) ren1.AddActor(Pyrs) -ren1.SetBackground(slate_grey) -renWin.SetSize(400,400) +ren1.SetBackground(GetRGBColor('slate_grey')) + +renWin.SetSize(400, 400) + ren1.ResetCamera() ren1.GetActiveCamera().Dolly(1.3) ren1.GetActiveCamera().Elevation(15) ren1.ResetCameraClippingRange() + renWin.Render() + iren.Initialize() -mask = "1 2 4 8 16 32" -def cases (id,__vtk__temp0=0,__vtk__temp1=0): - global mask + +def cases (id, mask): i = 0 while i < 5: - m = lindex(mask,i) - if (expr.expr(globals(), locals(),["m","&","id"]) == 0): - Scalars.SetValue(i,0) + m = mask[i] + if m & id == 0: + Scalars.SetValue(i, 0) pass else: - Scalars.SetValue(i,1) + Scalars.SetValue(i, 1) pass - caseLabel.SetText("Case " + str(id) + "") - i = i + 1 + caseLabel.SetText("Case " + str(id)) + i += 1 Grid.Modified() renWin.Render() -cases(20) -# --- end of script -- +mask = [1, 2, 4, 8, 16, 32] + +cases(20, mask) + +# iren.Start() diff --git a/Filters/General/Testing/Python/clipQuadraticCells.py b/Filters/General/Testing/Python/clipQuadraticCells.py index 24ac25368dd..4a27e1a35d2 100755 --- a/Filters/General/Testing/Python/clipQuadraticCells.py +++ b/Filters/General/Testing/Python/clipQuadraticCells.py @@ -1,29 +1,37 @@ #!/usr/bin/env python +import sys import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() +# Prevent .pyc files being created. +# Stops the vtk source being polluted +# by .pyc files. +sys.dont_write_bytecode = True + +import backdrop + # clip every quadratic cell type # Create a scene with one of each cell type. # QuadraticEdge edgePoints = vtk.vtkPoints() edgePoints.SetNumberOfPoints(3) -edgePoints.InsertPoint(0,0,0,0) -edgePoints.InsertPoint(1,1.0,0,0) -edgePoints.InsertPoint(2,0.5,0.25,0) +edgePoints.InsertPoint(0, 0, 0, 0) +edgePoints.InsertPoint(1, 1.0, 0, 0) +edgePoints.InsertPoint(2, 0.5, 0.25, 0) edgeScalars = vtk.vtkFloatArray() edgeScalars.SetNumberOfTuples(3) -edgeScalars.InsertValue(0,0.0) -edgeScalars.InsertValue(1,0.0) -edgeScalars.InsertValue(2,0.9) +edgeScalars.InsertValue(0, 0.0) +edgeScalars.InsertValue(1, 0.0) +edgeScalars.InsertValue(2, 0.9) aEdge = vtk.vtkQuadraticEdge() -aEdge.GetPointIds().SetId(0,0) -aEdge.GetPointIds().SetId(1,1) -aEdge.GetPointIds().SetId(2,2) +aEdge.GetPointIds().SetId(0, 0) +aEdge.GetPointIds().SetId(1, 1) +aEdge.GetPointIds().SetId(2, 2) aEdgeGrid = vtk.vtkUnstructuredGrid() -aEdgeGrid.Allocate(1,1) -aEdgeGrid.InsertNextCell(aEdge.GetCellType(),aEdge.GetPointIds()) +aEdgeGrid.Allocate(1, 1) +aEdgeGrid.InsertNextCell(aEdge.GetCellType(), aEdge.GetPointIds()) aEdgeGrid.SetPoints(edgePoints) aEdgeGrid.GetPointData().SetScalars(edgeScalars) edgeclips = vtk.vtkClipDataSet() @@ -43,33 +51,34 @@ aEdgeclipActor = vtk.vtkActor() aEdgeclipActor.SetMapper(aEdgeclipMapper) aEdgeclipActor.GetProperty().BackfaceCullingOn() aEdgeclipActor.GetProperty().SetAmbient(1.0) + # Quadratic triangle triPoints = vtk.vtkPoints() triPoints.SetNumberOfPoints(6) -triPoints.InsertPoint(0,0.0,0.0,0.0) -triPoints.InsertPoint(1,1.0,0.0,0.0) -triPoints.InsertPoint(2,0.5,0.8,0.0) -triPoints.InsertPoint(3,0.5,0.0,0.0) -triPoints.InsertPoint(4,0.75,0.4,0.0) -triPoints.InsertPoint(5,0.25,0.4,0.0) +triPoints.InsertPoint(0, 0.0, 0.0, 0.0) +triPoints.InsertPoint(1, 1.0, 0.0, 0.0) +triPoints.InsertPoint(2, 0.5, 0.8, 0.0) +triPoints.InsertPoint(3, 0.5, 0.0, 0.0) +triPoints.InsertPoint(4, 0.75, 0.4, 0.0) +triPoints.InsertPoint(5, 0.25, 0.4, 0.0) triScalars = vtk.vtkFloatArray() triScalars.SetNumberOfTuples(6) -triScalars.InsertValue(0,0.0) -triScalars.InsertValue(1,0.0) -triScalars.InsertValue(2,0.0) -triScalars.InsertValue(3,1.0) -triScalars.InsertValue(4,0.0) -triScalars.InsertValue(5,0.0) +triScalars.InsertValue(0, 0.0) +triScalars.InsertValue(1, 0.0) +triScalars.InsertValue(2, 0.0) +triScalars.InsertValue(3, 1.0) +triScalars.InsertValue(4, 0.0) +triScalars.InsertValue(5, 0.0) aTri = vtk.vtkQuadraticTriangle() -aTri.GetPointIds().SetId(0,0) -aTri.GetPointIds().SetId(1,1) -aTri.GetPointIds().SetId(2,2) -aTri.GetPointIds().SetId(3,3) -aTri.GetPointIds().SetId(4,4) -aTri.GetPointIds().SetId(5,5) +aTri.GetPointIds().SetId(0, 0) +aTri.GetPointIds().SetId(1, 1) +aTri.GetPointIds().SetId(2, 2) +aTri.GetPointIds().SetId(3, 3) +aTri.GetPointIds().SetId(4, 4) +aTri.GetPointIds().SetId(5, 5) aTriGrid = vtk.vtkUnstructuredGrid() -aTriGrid.Allocate(1,1) -aTriGrid.InsertNextCell(aTri.GetCellType(),aTri.GetPointIds()) +aTriGrid.Allocate(1, 1) +aTriGrid.InsertNextCell(aTri.GetCellType(), aTri.GetPointIds()) aTriGrid.SetPoints(triPoints) aTriGrid.GetPointData().SetScalars(triScalars) triclips = vtk.vtkClipDataSet() @@ -89,39 +98,40 @@ aTriclipActor = vtk.vtkActor() aTriclipActor.SetMapper(aTriclipMapper) aTriclipActor.GetProperty().BackfaceCullingOn() aTriclipActor.GetProperty().SetAmbient(1.0) + # Quadratic quadrilateral quadPoints = vtk.vtkPoints() quadPoints.SetNumberOfPoints(8) -quadPoints.InsertPoint(0,0.0,0.0,0.0) -quadPoints.InsertPoint(1,1.0,0.0,0.0) -quadPoints.InsertPoint(2,1.0,1.0,0.0) -quadPoints.InsertPoint(3,0.0,1.0,0.0) -quadPoints.InsertPoint(4,0.5,0.0,0.0) -quadPoints.InsertPoint(5,1.0,0.5,0.0) -quadPoints.InsertPoint(6,0.5,1.0,0.0) -quadPoints.InsertPoint(7,0.0,0.5,0.0) +quadPoints.InsertPoint(0, 0.0, 0.0, 0.0) +quadPoints.InsertPoint(1, 1.0, 0.0, 0.0) +quadPoints.InsertPoint(2, 1.0, 1.0, 0.0) +quadPoints.InsertPoint(3, 0.0, 1.0, 0.0) +quadPoints.InsertPoint(4, 0.5, 0.0, 0.0) +quadPoints.InsertPoint(5, 1.0, 0.5, 0.0) +quadPoints.InsertPoint(6, 0.5, 1.0, 0.0) +quadPoints.InsertPoint(7, 0.0, 0.5, 0.0) quadScalars = vtk.vtkFloatArray() quadScalars.SetNumberOfTuples(8) -quadScalars.InsertValue(0,0.0) -quadScalars.InsertValue(1,0.0) -quadScalars.InsertValue(2,1.0) -quadScalars.InsertValue(3,1.0) -quadScalars.InsertValue(4,1.0) -quadScalars.InsertValue(5,0.0) -quadScalars.InsertValue(6,0.0) -quadScalars.InsertValue(7,0.0) +quadScalars.InsertValue(0, 0.0) +quadScalars.InsertValue(1, 0.0) +quadScalars.InsertValue(2, 1.0) +quadScalars.InsertValue(3, 1.0) +quadScalars.InsertValue(4, 1.0) +quadScalars.InsertValue(5, 0.0) +quadScalars.InsertValue(6, 0.0) +quadScalars.InsertValue(7, 0.0) aQuad = vtk.vtkQuadraticQuad() -aQuad.GetPointIds().SetId(0,0) -aQuad.GetPointIds().SetId(1,1) -aQuad.GetPointIds().SetId(2,2) -aQuad.GetPointIds().SetId(3,3) -aQuad.GetPointIds().SetId(4,4) -aQuad.GetPointIds().SetId(5,5) -aQuad.GetPointIds().SetId(6,6) -aQuad.GetPointIds().SetId(7,7) +aQuad.GetPointIds().SetId(0, 0) +aQuad.GetPointIds().SetId(1, 1) +aQuad.GetPointIds().SetId(2, 2) +aQuad.GetPointIds().SetId(3, 3) +aQuad.GetPointIds().SetId(4, 4) +aQuad.GetPointIds().SetId(5, 5) +aQuad.GetPointIds().SetId(6, 6) +aQuad.GetPointIds().SetId(7, 7) aQuadGrid = vtk.vtkUnstructuredGrid() -aQuadGrid.Allocate(1,1) -aQuadGrid.InsertNextCell(aQuad.GetCellType(),aQuad.GetPointIds()) +aQuadGrid.Allocate(1, 1) +aQuadGrid.InsertNextCell(aQuad.GetCellType(), aQuad.GetPointIds()) aQuadGrid.SetPoints(quadPoints) aQuadGrid.GetPointData().SetScalars(quadScalars) quadclips = vtk.vtkClipDataSet() @@ -141,42 +151,43 @@ aQuadclipActor = vtk.vtkActor() aQuadclipActor.SetMapper(aQuadclipMapper) aQuadclipActor.GetProperty().BackfaceCullingOn() aQuadclipActor.GetProperty().SetAmbient(1.0) + # BiQuadratic quadrilateral BquadPoints = vtk.vtkPoints() BquadPoints.SetNumberOfPoints(9) -BquadPoints.InsertPoint(0,0.0,0.0,0.0) -BquadPoints.InsertPoint(1,1.0,0.0,0.0) -BquadPoints.InsertPoint(2,1.0,1.0,0.0) -BquadPoints.InsertPoint(3,0.0,1.0,0.0) -BquadPoints.InsertPoint(4,0.5,0.0,0.0) -BquadPoints.InsertPoint(5,1.0,0.5,0.0) -BquadPoints.InsertPoint(6,0.5,1.0,0.0) -BquadPoints.InsertPoint(7,0.0,0.5,0.0) -BquadPoints.InsertPoint(8,0.5,0.5,0.0) +BquadPoints.InsertPoint(0, 0.0, 0.0, 0.0) +BquadPoints.InsertPoint(1, 1.0, 0.0, 0.0) +BquadPoints.InsertPoint(2, 1.0, 1.0, 0.0) +BquadPoints.InsertPoint(3, 0.0, 1.0, 0.0) +BquadPoints.InsertPoint(4, 0.5, 0.0, 0.0) +BquadPoints.InsertPoint(5, 1.0, 0.5, 0.0) +BquadPoints.InsertPoint(6, 0.5, 1.0, 0.0) +BquadPoints.InsertPoint(7, 0.0, 0.5, 0.0) +BquadPoints.InsertPoint(8, 0.5, 0.5, 0.0) BquadScalars = vtk.vtkFloatArray() BquadScalars.SetNumberOfTuples(9) -BquadScalars.InsertValue(0,1.0) -BquadScalars.InsertValue(1,1.0) -BquadScalars.InsertValue(2,1.0) -BquadScalars.InsertValue(3,1.0) -BquadScalars.InsertValue(4,0.0) -BquadScalars.InsertValue(5,0.0) -BquadScalars.InsertValue(6,0.0) -BquadScalars.InsertValue(7,0.0) -BquadScalars.InsertValue(8,1.0) +BquadScalars.InsertValue(0, 1.0) +BquadScalars.InsertValue(1, 1.0) +BquadScalars.InsertValue(2, 1.0) +BquadScalars.InsertValue(3, 1.0) +BquadScalars.InsertValue(4, 0.0) +BquadScalars.InsertValue(5, 0.0) +BquadScalars.InsertValue(6, 0.0) +BquadScalars.InsertValue(7, 0.0) +BquadScalars.InsertValue(8, 1.0) BQuad = vtk.vtkBiQuadraticQuad() -BQuad.GetPointIds().SetId(0,0) -BQuad.GetPointIds().SetId(1,1) -BQuad.GetPointIds().SetId(2,2) -BQuad.GetPointIds().SetId(3,3) -BQuad.GetPointIds().SetId(4,4) -BQuad.GetPointIds().SetId(5,5) -BQuad.GetPointIds().SetId(6,6) -BQuad.GetPointIds().SetId(7,7) -BQuad.GetPointIds().SetId(8,8) +BQuad.GetPointIds().SetId(0, 0) +BQuad.GetPointIds().SetId(1, 1) +BQuad.GetPointIds().SetId(2, 2) +BQuad.GetPointIds().SetId(3, 3) +BQuad.GetPointIds().SetId(4, 4) +BQuad.GetPointIds().SetId(5, 5) +BQuad.GetPointIds().SetId(6, 6) +BQuad.GetPointIds().SetId(7, 7) +BQuad.GetPointIds().SetId(8, 8) BQuadGrid = vtk.vtkUnstructuredGrid() -BQuadGrid.Allocate(1,1) -BQuadGrid.InsertNextCell(BQuad.GetCellType(),BQuad.GetPointIds()) +BQuadGrid.Allocate(1, 1) +BQuadGrid.InsertNextCell(BQuad.GetCellType(), BQuad.GetPointIds()) BQuadGrid.SetPoints(BquadPoints) BQuadGrid.GetPointData().SetScalars(BquadScalars) Bquadclips = vtk.vtkClipDataSet() @@ -196,33 +207,34 @@ BQuadclipActor = vtk.vtkActor() BQuadclipActor.SetMapper(BQuadclipMapper) BQuadclipActor.GetProperty().BackfaceCullingOn() BQuadclipActor.GetProperty().SetAmbient(1.0) + # Quadratic linear quadrilateral QLquadPoints = vtk.vtkPoints() QLquadPoints.SetNumberOfPoints(6) -QLquadPoints.InsertPoint(0,0.0,0.0,0.0) -QLquadPoints.InsertPoint(1,1.0,0.0,0.0) -QLquadPoints.InsertPoint(2,1.0,1.0,0.0) -QLquadPoints.InsertPoint(3,0.0,1.0,0.0) -QLquadPoints.InsertPoint(4,0.5,0.0,0.0) -QLquadPoints.InsertPoint(5,0.5,1.0,0.0) +QLquadPoints.InsertPoint(0, 0.0, 0.0, 0.0) +QLquadPoints.InsertPoint(1, 1.0, 0.0, 0.0) +QLquadPoints.InsertPoint(2, 1.0, 1.0, 0.0) +QLquadPoints.InsertPoint(3, 0.0, 1.0, 0.0) +QLquadPoints.InsertPoint(4, 0.5, 0.0, 0.0) +QLquadPoints.InsertPoint(5, 0.5, 1.0, 0.0) QLquadScalars = vtk.vtkFloatArray() QLquadScalars.SetNumberOfTuples(6) -QLquadScalars.InsertValue(0,1.0) -QLquadScalars.InsertValue(1,1.0) -QLquadScalars.InsertValue(2,0.0) -QLquadScalars.InsertValue(3,0.0) -QLquadScalars.InsertValue(4,0.0) -QLquadScalars.InsertValue(5,1.0) +QLquadScalars.InsertValue(0, 1.0) +QLquadScalars.InsertValue(1, 1.0) +QLquadScalars.InsertValue(2, 0.0) +QLquadScalars.InsertValue(3, 0.0) +QLquadScalars.InsertValue(4, 0.0) +QLquadScalars.InsertValue(5, 1.0) QLQuad = vtk.vtkQuadraticLinearQuad() -QLQuad.GetPointIds().SetId(0,0) -QLQuad.GetPointIds().SetId(1,1) -QLQuad.GetPointIds().SetId(2,2) -QLQuad.GetPointIds().SetId(3,3) -QLQuad.GetPointIds().SetId(4,4) -QLQuad.GetPointIds().SetId(5,5) +QLQuad.GetPointIds().SetId(0, 0) +QLQuad.GetPointIds().SetId(1, 1) +QLQuad.GetPointIds().SetId(2, 2) +QLQuad.GetPointIds().SetId(3, 3) +QLQuad.GetPointIds().SetId(4, 4) +QLQuad.GetPointIds().SetId(5, 5) QLQuadGrid = vtk.vtkUnstructuredGrid() -QLQuadGrid.Allocate(1,1) -QLQuadGrid.InsertNextCell(QLQuad.GetCellType(),QLQuad.GetPointIds()) +QLQuadGrid.Allocate(1, 1) +QLQuadGrid.InsertNextCell(QLQuad.GetCellType(), QLQuad.GetPointIds()) QLQuadGrid.SetPoints(QLquadPoints) QLQuadGrid.GetPointData().SetScalars(QLquadScalars) QLquadclips = vtk.vtkClipDataSet() @@ -242,45 +254,46 @@ QLQuadclipActor = vtk.vtkActor() QLQuadclipActor.SetMapper(QLQuadclipMapper) QLQuadclipActor.GetProperty().BackfaceCullingOn() QLQuadclipActor.GetProperty().SetAmbient(1.0) + # Quadratic tetrahedron tetPoints = vtk.vtkPoints() tetPoints.SetNumberOfPoints(10) -tetPoints.InsertPoint(0,0.0,0.0,0.0) -tetPoints.InsertPoint(1,1.0,0.0,0.0) -tetPoints.InsertPoint(2,0.5,0.8,0.0) -tetPoints.InsertPoint(3,0.5,0.4,1.0) -tetPoints.InsertPoint(4,0.5,0.0,0.0) -tetPoints.InsertPoint(5,0.75,0.4,0.0) -tetPoints.InsertPoint(6,0.25,0.4,0.0) -tetPoints.InsertPoint(7,0.25,0.2,0.5) -tetPoints.InsertPoint(8,0.75,0.2,0.5) -tetPoints.InsertPoint(9,0.50,0.6,0.5) +tetPoints.InsertPoint(0, 0.0, 0.0, 0.0) +tetPoints.InsertPoint(1, 1.0, 0.0, 0.0) +tetPoints.InsertPoint(2, 0.5, 0.8, 0.0) +tetPoints.InsertPoint(3, 0.5, 0.4, 1.0) +tetPoints.InsertPoint(4, 0.5, 0.0, 0.0) +tetPoints.InsertPoint(5, 0.75, 0.4, 0.0) +tetPoints.InsertPoint(6, 0.25, 0.4, 0.0) +tetPoints.InsertPoint(7, 0.25, 0.2, 0.5) +tetPoints.InsertPoint(8, 0.75, 0.2, 0.5) +tetPoints.InsertPoint(9, 0.50, 0.6, 0.5) tetScalars = vtk.vtkFloatArray() tetScalars.SetNumberOfTuples(10) -tetScalars.InsertValue(0,1.0) -tetScalars.InsertValue(1,1.0) -tetScalars.InsertValue(2,1.0) -tetScalars.InsertValue(3,1.0) -tetScalars.InsertValue(4,0.0) -tetScalars.InsertValue(5,0.0) -tetScalars.InsertValue(6,0.0) -tetScalars.InsertValue(7,0.0) -tetScalars.InsertValue(8,0.0) -tetScalars.InsertValue(9,0.0) +tetScalars.InsertValue(0, 1.0) +tetScalars.InsertValue(1, 1.0) +tetScalars.InsertValue(2, 1.0) +tetScalars.InsertValue(3, 1.0) +tetScalars.InsertValue(4, 0.0) +tetScalars.InsertValue(5, 0.0) +tetScalars.InsertValue(6, 0.0) +tetScalars.InsertValue(7, 0.0) +tetScalars.InsertValue(8, 0.0) +tetScalars.InsertValue(9, 0.0) aTet = vtk.vtkQuadraticTetra() -aTet.GetPointIds().SetId(0,0) -aTet.GetPointIds().SetId(1,1) -aTet.GetPointIds().SetId(2,2) -aTet.GetPointIds().SetId(3,3) -aTet.GetPointIds().SetId(4,4) -aTet.GetPointIds().SetId(5,5) -aTet.GetPointIds().SetId(6,6) -aTet.GetPointIds().SetId(7,7) -aTet.GetPointIds().SetId(8,8) -aTet.GetPointIds().SetId(9,9) +aTet.GetPointIds().SetId(0, 0) +aTet.GetPointIds().SetId(1, 1) +aTet.GetPointIds().SetId(2, 2) +aTet.GetPointIds().SetId(3, 3) +aTet.GetPointIds().SetId(4, 4) +aTet.GetPointIds().SetId(5, 5) +aTet.GetPointIds().SetId(6, 6) +aTet.GetPointIds().SetId(7, 7) +aTet.GetPointIds().SetId(8, 8) +aTet.GetPointIds().SetId(9, 9) aTetGrid = vtk.vtkUnstructuredGrid() -aTetGrid.Allocate(1,1) -aTetGrid.InsertNextCell(aTet.GetCellType(),aTet.GetPointIds()) +aTetGrid.Allocate(1, 1) +aTetGrid.InsertNextCell(aTet.GetCellType(), aTet.GetPointIds()) aTetGrid.SetPoints(tetPoints) aTetGrid.GetPointData().SetScalars(tetScalars) tetclips = vtk.vtkClipDataSet() @@ -299,75 +312,76 @@ aTetActor.GetProperty().SetAmbient(1.0) aTetclipActor = vtk.vtkActor() aTetclipActor.SetMapper(aTetclipMapper) aTetclipActor.GetProperty().SetAmbient(1.0) + # Quadratic hexahedron hexPoints = vtk.vtkPoints() hexPoints.SetNumberOfPoints(20) -hexPoints.InsertPoint(0,0,0,0) -hexPoints.InsertPoint(1,1,0,0) -hexPoints.InsertPoint(2,1,1,0) -hexPoints.InsertPoint(3,0,1,0) -hexPoints.InsertPoint(4,0,0,1) -hexPoints.InsertPoint(5,1,0,1) -hexPoints.InsertPoint(6,1,1,1) -hexPoints.InsertPoint(7,0,1,1) -hexPoints.InsertPoint(8,0.5,0,0) -hexPoints.InsertPoint(9,1,0.5,0) -hexPoints.InsertPoint(10,0.5,1,0) -hexPoints.InsertPoint(11,0,0.5,0) -hexPoints.InsertPoint(12,0.5,0,1) -hexPoints.InsertPoint(13,1,0.5,1) -hexPoints.InsertPoint(14,0.5,1,1) -hexPoints.InsertPoint(15,0,0.5,1) -hexPoints.InsertPoint(16,0,0,0.5) -hexPoints.InsertPoint(17,1,0,0.5) -hexPoints.InsertPoint(18,1,1,0.5) -hexPoints.InsertPoint(19,0,1,0.5) +hexPoints.InsertPoint(0, 0, 0, 0) +hexPoints.InsertPoint(1, 1, 0, 0) +hexPoints.InsertPoint(2, 1, 1, 0) +hexPoints.InsertPoint(3, 0, 1, 0) +hexPoints.InsertPoint(4, 0, 0, 1) +hexPoints.InsertPoint(5, 1, 0, 1) +hexPoints.InsertPoint(6, 1, 1, 1) +hexPoints.InsertPoint(7, 0, 1, 1) +hexPoints.InsertPoint(8, 0.5, 0, 0) +hexPoints.InsertPoint(9, 1, 0.5, 0) +hexPoints.InsertPoint(10, 0.5, 1, 0) +hexPoints.InsertPoint(11, 0, 0.5, 0) +hexPoints.InsertPoint(12, 0.5, 0, 1) +hexPoints.InsertPoint(13, 1, 0.5, 1) +hexPoints.InsertPoint(14, 0.5, 1, 1) +hexPoints.InsertPoint(15, 0, 0.5, 1) +hexPoints.InsertPoint(16, 0, 0, 0.5) +hexPoints.InsertPoint(17, 1, 0, 0.5) +hexPoints.InsertPoint(18, 1, 1, 0.5) +hexPoints.InsertPoint(19, 0, 1, 0.5) hexScalars = vtk.vtkFloatArray() hexScalars.SetNumberOfTuples(20) -hexScalars.InsertValue(0,1.0) -hexScalars.InsertValue(1,1.0) -hexScalars.InsertValue(2,1.0) -hexScalars.InsertValue(3,1.0) -hexScalars.InsertValue(4,1.0) -hexScalars.InsertValue(5,1.0) -hexScalars.InsertValue(6,1.0) -hexScalars.InsertValue(7,1.0) -hexScalars.InsertValue(8,0.0) -hexScalars.InsertValue(9,0.0) -hexScalars.InsertValue(10,0.0) -hexScalars.InsertValue(11,0.0) -hexScalars.InsertValue(12,0.0) -hexScalars.InsertValue(13,0.0) -hexScalars.InsertValue(14,0.0) -hexScalars.InsertValue(15,0.0) -hexScalars.InsertValue(16,0.0) -hexScalars.InsertValue(17,0.0) -hexScalars.InsertValue(18,0.0) -hexScalars.InsertValue(19,0.0) +hexScalars.InsertValue(0, 1.0) +hexScalars.InsertValue(1, 1.0) +hexScalars.InsertValue(2, 1.0) +hexScalars.InsertValue(3, 1.0) +hexScalars.InsertValue(4, 1.0) +hexScalars.InsertValue(5, 1.0) +hexScalars.InsertValue(6, 1.0) +hexScalars.InsertValue(7, 1.0) +hexScalars.InsertValue(8, 0.0) +hexScalars.InsertValue(9, 0.0) +hexScalars.InsertValue(10, 0.0) +hexScalars.InsertValue(11, 0.0) +hexScalars.InsertValue(12, 0.0) +hexScalars.InsertValue(13, 0.0) +hexScalars.InsertValue(14, 0.0) +hexScalars.InsertValue(15, 0.0) +hexScalars.InsertValue(16, 0.0) +hexScalars.InsertValue(17, 0.0) +hexScalars.InsertValue(18, 0.0) +hexScalars.InsertValue(19, 0.0) aHex = vtk.vtkQuadraticHexahedron() -aHex.GetPointIds().SetId(0,0) -aHex.GetPointIds().SetId(1,1) -aHex.GetPointIds().SetId(2,2) -aHex.GetPointIds().SetId(3,3) -aHex.GetPointIds().SetId(4,4) -aHex.GetPointIds().SetId(5,5) -aHex.GetPointIds().SetId(6,6) -aHex.GetPointIds().SetId(7,7) -aHex.GetPointIds().SetId(8,8) -aHex.GetPointIds().SetId(9,9) -aHex.GetPointIds().SetId(10,10) -aHex.GetPointIds().SetId(11,11) -aHex.GetPointIds().SetId(12,12) -aHex.GetPointIds().SetId(13,13) -aHex.GetPointIds().SetId(14,14) -aHex.GetPointIds().SetId(15,15) -aHex.GetPointIds().SetId(16,16) -aHex.GetPointIds().SetId(17,17) -aHex.GetPointIds().SetId(18,18) -aHex.GetPointIds().SetId(19,19) +aHex.GetPointIds().SetId(0, 0) +aHex.GetPointIds().SetId(1, 1) +aHex.GetPointIds().SetId(2, 2) +aHex.GetPointIds().SetId(3, 3) +aHex.GetPointIds().SetId(4, 4) +aHex.GetPointIds().SetId(5, 5) +aHex.GetPointIds().SetId(6, 6) +aHex.GetPointIds().SetId(7, 7) +aHex.GetPointIds().SetId(8, 8) +aHex.GetPointIds().SetId(9, 9) +aHex.GetPointIds().SetId(10, 10) +aHex.GetPointIds().SetId(11, 11) +aHex.GetPointIds().SetId(12, 12) +aHex.GetPointIds().SetId(13, 13) +aHex.GetPointIds().SetId(14, 14) +aHex.GetPointIds().SetId(15, 15) +aHex.GetPointIds().SetId(16, 16) +aHex.GetPointIds().SetId(17, 17) +aHex.GetPointIds().SetId(18, 18) +aHex.GetPointIds().SetId(19, 19) aHexGrid = vtk.vtkUnstructuredGrid() -aHexGrid.Allocate(1,1) -aHexGrid.InsertNextCell(aHex.GetCellType(),aHex.GetPointIds()) +aHexGrid.Allocate(1, 1) +aHexGrid.InsertNextCell(aHex.GetCellType(), aHex.GetPointIds()) aHexGrid.SetPoints(hexPoints) aHexGrid.GetPointData().SetScalars(hexScalars) hexclips = vtk.vtkClipDataSet() @@ -386,96 +400,97 @@ aHexActor.GetProperty().SetAmbient(1.0) aHexclipActor = vtk.vtkActor() aHexclipActor.SetMapper(aHexclipMapper) aHexclipActor.GetProperty().SetAmbient(1.0) + # TriQuadratic hexahedron TQhexPoints = vtk.vtkPoints() TQhexPoints.SetNumberOfPoints(27) -TQhexPoints.InsertPoint(0,0,0,0) -TQhexPoints.InsertPoint(1,1,0,0) -TQhexPoints.InsertPoint(2,1,1,0) -TQhexPoints.InsertPoint(3,0,1,0) -TQhexPoints.InsertPoint(4,0,0,1) -TQhexPoints.InsertPoint(5,1,0,1) -TQhexPoints.InsertPoint(6,1,1,1) -TQhexPoints.InsertPoint(7,0,1,1) -TQhexPoints.InsertPoint(8,0.5,0,0) -TQhexPoints.InsertPoint(9,1,0.5,0) -TQhexPoints.InsertPoint(10,0.5,1,0) -TQhexPoints.InsertPoint(11,0,0.5,0) -TQhexPoints.InsertPoint(12,0.5,0,1) -TQhexPoints.InsertPoint(13,1,0.5,1) -TQhexPoints.InsertPoint(14,0.5,1,1) -TQhexPoints.InsertPoint(15,0,0.5,1) -TQhexPoints.InsertPoint(16,0,0,0.5) -TQhexPoints.InsertPoint(17,1,0,0.5) -TQhexPoints.InsertPoint(18,1,1,0.5) -TQhexPoints.InsertPoint(19,0,1,0.5) -TQhexPoints.InsertPoint(22,0.5,0,0.5) -TQhexPoints.InsertPoint(21,1,0.5,0.5) -TQhexPoints.InsertPoint(23,0.5,1,0.5) -TQhexPoints.InsertPoint(20,0,0.5,0.5) -TQhexPoints.InsertPoint(24,0.5,0.5,0.0) -TQhexPoints.InsertPoint(25,0.5,0.5,1) -TQhexPoints.InsertPoint(26,0.5,0.5,0.5) +TQhexPoints.InsertPoint(0, 0, 0, 0) +TQhexPoints.InsertPoint(1, 1, 0, 0) +TQhexPoints.InsertPoint(2, 1, 1, 0) +TQhexPoints.InsertPoint(3, 0, 1, 0) +TQhexPoints.InsertPoint(4, 0, 0, 1) +TQhexPoints.InsertPoint(5, 1, 0, 1) +TQhexPoints.InsertPoint(6, 1, 1, 1) +TQhexPoints.InsertPoint(7, 0, 1, 1) +TQhexPoints.InsertPoint(8, 0.5, 0, 0) +TQhexPoints.InsertPoint(9, 1, 0.5, 0) +TQhexPoints.InsertPoint(10, 0.5, 1, 0) +TQhexPoints.InsertPoint(11, 0, 0.5, 0) +TQhexPoints.InsertPoint(12, 0.5, 0, 1) +TQhexPoints.InsertPoint(13, 1, 0.5, 1) +TQhexPoints.InsertPoint(14, 0.5, 1, 1) +TQhexPoints.InsertPoint(15, 0, 0.5, 1) +TQhexPoints.InsertPoint(16, 0, 0, 0.5) +TQhexPoints.InsertPoint(17, 1, 0, 0.5) +TQhexPoints.InsertPoint(18, 1, 1, 0.5) +TQhexPoints.InsertPoint(19, 0, 1, 0.5) +TQhexPoints.InsertPoint(22, 0.5, 0, 0.5) +TQhexPoints.InsertPoint(21, 1, 0.5, 0.5) +TQhexPoints.InsertPoint(23, 0.5, 1, 0.5) +TQhexPoints.InsertPoint(20, 0, 0.5, 0.5) +TQhexPoints.InsertPoint(24, 0.5, 0.5, 0.0) +TQhexPoints.InsertPoint(25, 0.5, 0.5, 1) +TQhexPoints.InsertPoint(26, 0.5, 0.5, 0.5) TQhexScalars = vtk.vtkFloatArray() TQhexScalars.SetNumberOfTuples(27) -TQhexScalars.InsertValue(0,1.0) -TQhexScalars.InsertValue(1,1.0) -TQhexScalars.InsertValue(2,1.0) -TQhexScalars.InsertValue(3,1.0) -TQhexScalars.InsertValue(4,1.0) -TQhexScalars.InsertValue(5,1.0) -TQhexScalars.InsertValue(6,1.0) -TQhexScalars.InsertValue(7,1.0) -TQhexScalars.InsertValue(8,0.0) -TQhexScalars.InsertValue(9,0.0) -TQhexScalars.InsertValue(10,0.0) -TQhexScalars.InsertValue(11,0.0) -TQhexScalars.InsertValue(12,0.0) -TQhexScalars.InsertValue(13,0.0) -TQhexScalars.InsertValue(14,0.0) -TQhexScalars.InsertValue(15,0.0) -TQhexScalars.InsertValue(16,0.0) -TQhexScalars.InsertValue(17,0.0) -TQhexScalars.InsertValue(18,0.0) -TQhexScalars.InsertValue(19,0.0) -TQhexScalars.InsertValue(20,0.0) -TQhexScalars.InsertValue(21,0.0) -TQhexScalars.InsertValue(22,0.0) -TQhexScalars.InsertValue(23,0.0) -TQhexScalars.InsertValue(24,0.0) -TQhexScalars.InsertValue(25,0.0) -TQhexScalars.InsertValue(26,0.0) +TQhexScalars.InsertValue(0, 1.0) +TQhexScalars.InsertValue(1, 1.0) +TQhexScalars.InsertValue(2, 1.0) +TQhexScalars.InsertValue(3, 1.0) +TQhexScalars.InsertValue(4, 1.0) +TQhexScalars.InsertValue(5, 1.0) +TQhexScalars.InsertValue(6, 1.0) +TQhexScalars.InsertValue(7, 1.0) +TQhexScalars.InsertValue(8, 0.0) +TQhexScalars.InsertValue(9, 0.0) +TQhexScalars.InsertValue(10, 0.0) +TQhexScalars.InsertValue(11, 0.0) +TQhexScalars.InsertValue(12, 0.0) +TQhexScalars.InsertValue(13, 0.0) +TQhexScalars.InsertValue(14, 0.0) +TQhexScalars.InsertValue(15, 0.0) +TQhexScalars.InsertValue(16, 0.0) +TQhexScalars.InsertValue(17, 0.0) +TQhexScalars.InsertValue(18, 0.0) +TQhexScalars.InsertValue(19, 0.0) +TQhexScalars.InsertValue(20, 0.0) +TQhexScalars.InsertValue(21, 0.0) +TQhexScalars.InsertValue(22, 0.0) +TQhexScalars.InsertValue(23, 0.0) +TQhexScalars.InsertValue(24, 0.0) +TQhexScalars.InsertValue(25, 0.0) +TQhexScalars.InsertValue(26, 0.0) TQHex = vtk.vtkTriQuadraticHexahedron() -TQHex.GetPointIds().SetId(0,0) -TQHex.GetPointIds().SetId(1,1) -TQHex.GetPointIds().SetId(2,2) -TQHex.GetPointIds().SetId(3,3) -TQHex.GetPointIds().SetId(4,4) -TQHex.GetPointIds().SetId(5,5) -TQHex.GetPointIds().SetId(6,6) -TQHex.GetPointIds().SetId(7,7) -TQHex.GetPointIds().SetId(8,8) -TQHex.GetPointIds().SetId(9,9) -TQHex.GetPointIds().SetId(10,10) -TQHex.GetPointIds().SetId(11,11) -TQHex.GetPointIds().SetId(12,12) -TQHex.GetPointIds().SetId(13,13) -TQHex.GetPointIds().SetId(14,14) -TQHex.GetPointIds().SetId(15,15) -TQHex.GetPointIds().SetId(16,16) -TQHex.GetPointIds().SetId(17,17) -TQHex.GetPointIds().SetId(18,18) -TQHex.GetPointIds().SetId(19,19) -TQHex.GetPointIds().SetId(20,20) -TQHex.GetPointIds().SetId(21,21) -TQHex.GetPointIds().SetId(22,22) -TQHex.GetPointIds().SetId(23,23) -TQHex.GetPointIds().SetId(24,24) -TQHex.GetPointIds().SetId(25,25) -TQHex.GetPointIds().SetId(26,26) +TQHex.GetPointIds().SetId(0, 0) +TQHex.GetPointIds().SetId(1, 1) +TQHex.GetPointIds().SetId(2, 2) +TQHex.GetPointIds().SetId(3, 3) +TQHex.GetPointIds().SetId(4, 4) +TQHex.GetPointIds().SetId(5, 5) +TQHex.GetPointIds().SetId(6, 6) +TQHex.GetPointIds().SetId(7, 7) +TQHex.GetPointIds().SetId(8, 8) +TQHex.GetPointIds().SetId(9, 9) +TQHex.GetPointIds().SetId(10, 10) +TQHex.GetPointIds().SetId(11, 11) +TQHex.GetPointIds().SetId(12, 12) +TQHex.GetPointIds().SetId(13, 13) +TQHex.GetPointIds().SetId(14, 14) +TQHex.GetPointIds().SetId(15, 15) +TQHex.GetPointIds().SetId(16, 16) +TQHex.GetPointIds().SetId(17, 17) +TQHex.GetPointIds().SetId(18, 18) +TQHex.GetPointIds().SetId(19, 19) +TQHex.GetPointIds().SetId(20, 20) +TQHex.GetPointIds().SetId(21, 21) +TQHex.GetPointIds().SetId(22, 22) +TQHex.GetPointIds().SetId(23, 23) +TQHex.GetPointIds().SetId(24, 24) +TQHex.GetPointIds().SetId(25, 25) +TQHex.GetPointIds().SetId(26, 26) TQHexGrid = vtk.vtkUnstructuredGrid() -TQHexGrid.Allocate(1,1) -TQHexGrid.InsertNextCell(TQHex.GetCellType(),TQHex.GetPointIds()) +TQHexGrid.Allocate(1, 1) +TQHexGrid.InsertNextCell(TQHex.GetCellType(), TQHex.GetPointIds()) TQHexGrid.SetPoints(TQhexPoints) TQHexGrid.GetPointData().SetScalars(TQhexScalars) TQhexclips = vtk.vtkClipDataSet() @@ -494,87 +509,88 @@ TQHexActor.GetProperty().SetAmbient(1.0) TQHexclipActor = vtk.vtkActor() TQHexclipActor.SetMapper(TQHexclipMapper) TQHexclipActor.GetProperty().SetAmbient(1.0) + # BiQuadratic Quadratic hexahedron BQhexPoints = vtk.vtkPoints() BQhexPoints.SetNumberOfPoints(24) -BQhexPoints.InsertPoint(0,0,0,0) -BQhexPoints.InsertPoint(1,1,0,0) -BQhexPoints.InsertPoint(2,1,1,0) -BQhexPoints.InsertPoint(3,0,1,0) -BQhexPoints.InsertPoint(4,0,0,1) -BQhexPoints.InsertPoint(5,1,0,1) -BQhexPoints.InsertPoint(6,1,1,1) -BQhexPoints.InsertPoint(7,0,1,1) -BQhexPoints.InsertPoint(8,0.5,0,0) -BQhexPoints.InsertPoint(9,1,0.5,0) -BQhexPoints.InsertPoint(10,0.5,1,0) -BQhexPoints.InsertPoint(11,0,0.5,0) -BQhexPoints.InsertPoint(12,0.5,0,1) -BQhexPoints.InsertPoint(13,1,0.5,1) -BQhexPoints.InsertPoint(14,0.5,1,1) -BQhexPoints.InsertPoint(15,0,0.5,1) -BQhexPoints.InsertPoint(16,0,0,0.5) -BQhexPoints.InsertPoint(17,1,0,0.5) -BQhexPoints.InsertPoint(18,1,1,0.5) -BQhexPoints.InsertPoint(19,0,1,0.5) -BQhexPoints.InsertPoint(22,0.5,0,0.5) -BQhexPoints.InsertPoint(21,1,0.5,0.5) -BQhexPoints.InsertPoint(23,0.5,1,0.5) -BQhexPoints.InsertPoint(20,0,0.5,0.5) +BQhexPoints.InsertPoint(0, 0, 0, 0) +BQhexPoints.InsertPoint(1, 1, 0, 0) +BQhexPoints.InsertPoint(2, 1, 1, 0) +BQhexPoints.InsertPoint(3, 0, 1, 0) +BQhexPoints.InsertPoint(4, 0, 0, 1) +BQhexPoints.InsertPoint(5, 1, 0, 1) +BQhexPoints.InsertPoint(6, 1, 1, 1) +BQhexPoints.InsertPoint(7, 0, 1, 1) +BQhexPoints.InsertPoint(8, 0.5, 0, 0) +BQhexPoints.InsertPoint(9, 1, 0.5, 0) +BQhexPoints.InsertPoint(10, 0.5, 1, 0) +BQhexPoints.InsertPoint(11, 0, 0.5, 0) +BQhexPoints.InsertPoint(12, 0.5, 0, 1) +BQhexPoints.InsertPoint(13, 1, 0.5, 1) +BQhexPoints.InsertPoint(14, 0.5, 1, 1) +BQhexPoints.InsertPoint(15, 0, 0.5, 1) +BQhexPoints.InsertPoint(16, 0, 0, 0.5) +BQhexPoints.InsertPoint(17, 1, 0, 0.5) +BQhexPoints.InsertPoint(18, 1, 1, 0.5) +BQhexPoints.InsertPoint(19, 0, 1, 0.5) +BQhexPoints.InsertPoint(22, 0.5, 0, 0.5) +BQhexPoints.InsertPoint(21, 1, 0.5, 0.5) +BQhexPoints.InsertPoint(23, 0.5, 1, 0.5) +BQhexPoints.InsertPoint(20, 0, 0.5, 0.5) BQhexScalars = vtk.vtkFloatArray() BQhexScalars.SetNumberOfTuples(24) -BQhexScalars.InsertValue(0,1.0) -BQhexScalars.InsertValue(1,1.0) -BQhexScalars.InsertValue(2,1.0) -BQhexScalars.InsertValue(3,1.0) -BQhexScalars.InsertValue(4,1.0) -BQhexScalars.InsertValue(5,1.0) -BQhexScalars.InsertValue(6,1.0) -BQhexScalars.InsertValue(7,1.0) -BQhexScalars.InsertValue(8,0.0) -BQhexScalars.InsertValue(9,0.0) -BQhexScalars.InsertValue(10,0.0) -BQhexScalars.InsertValue(11,0.0) -BQhexScalars.InsertValue(12,0.0) -BQhexScalars.InsertValue(13,0.0) -BQhexScalars.InsertValue(14,0.0) -BQhexScalars.InsertValue(15,0.0) -BQhexScalars.InsertValue(16,0.0) -BQhexScalars.InsertValue(17,0.0) -BQhexScalars.InsertValue(18,0.0) -BQhexScalars.InsertValue(19,0.0) -BQhexScalars.InsertValue(20,0.0) -BQhexScalars.InsertValue(21,0.0) -BQhexScalars.InsertValue(22,0.0) -BQhexScalars.InsertValue(23,0.0) +BQhexScalars.InsertValue(0, 1.0) +BQhexScalars.InsertValue(1, 1.0) +BQhexScalars.InsertValue(2, 1.0) +BQhexScalars.InsertValue(3, 1.0) +BQhexScalars.InsertValue(4, 1.0) +BQhexScalars.InsertValue(5, 1.0) +BQhexScalars.InsertValue(6, 1.0) +BQhexScalars.InsertValue(7, 1.0) +BQhexScalars.InsertValue(8, 0.0) +BQhexScalars.InsertValue(9, 0.0) +BQhexScalars.InsertValue(10, 0.0) +BQhexScalars.InsertValue(11, 0.0) +BQhexScalars.InsertValue(12, 0.0) +BQhexScalars.InsertValue(13, 0.0) +BQhexScalars.InsertValue(14, 0.0) +BQhexScalars.InsertValue(15, 0.0) +BQhexScalars.InsertValue(16, 0.0) +BQhexScalars.InsertValue(17, 0.0) +BQhexScalars.InsertValue(18, 0.0) +BQhexScalars.InsertValue(19, 0.0) +BQhexScalars.InsertValue(20, 0.0) +BQhexScalars.InsertValue(21, 0.0) +BQhexScalars.InsertValue(22, 0.0) +BQhexScalars.InsertValue(23, 0.0) BQHex = vtk.vtkBiQuadraticQuadraticHexahedron() -BQHex.GetPointIds().SetId(0,0) -BQHex.GetPointIds().SetId(1,1) -BQHex.GetPointIds().SetId(2,2) -BQHex.GetPointIds().SetId(3,3) -BQHex.GetPointIds().SetId(4,4) -BQHex.GetPointIds().SetId(5,5) -BQHex.GetPointIds().SetId(6,6) -BQHex.GetPointIds().SetId(7,7) -BQHex.GetPointIds().SetId(8,8) -BQHex.GetPointIds().SetId(9,9) -BQHex.GetPointIds().SetId(10,10) -BQHex.GetPointIds().SetId(11,11) -BQHex.GetPointIds().SetId(12,12) -BQHex.GetPointIds().SetId(13,13) -BQHex.GetPointIds().SetId(14,14) -BQHex.GetPointIds().SetId(15,15) -BQHex.GetPointIds().SetId(16,16) -BQHex.GetPointIds().SetId(17,17) -BQHex.GetPointIds().SetId(18,18) -BQHex.GetPointIds().SetId(19,19) -BQHex.GetPointIds().SetId(20,20) -BQHex.GetPointIds().SetId(21,21) -BQHex.GetPointIds().SetId(22,22) -BQHex.GetPointIds().SetId(23,23) +BQHex.GetPointIds().SetId(0, 0) +BQHex.GetPointIds().SetId(1, 1) +BQHex.GetPointIds().SetId(2, 2) +BQHex.GetPointIds().SetId(3, 3) +BQHex.GetPointIds().SetId(4, 4) +BQHex.GetPointIds().SetId(5, 5) +BQHex.GetPointIds().SetId(6, 6) +BQHex.GetPointIds().SetId(7, 7) +BQHex.GetPointIds().SetId(8, 8) +BQHex.GetPointIds().SetId(9, 9) +BQHex.GetPointIds().SetId(10, 10) +BQHex.GetPointIds().SetId(11, 11) +BQHex.GetPointIds().SetId(12, 12) +BQHex.GetPointIds().SetId(13, 13) +BQHex.GetPointIds().SetId(14, 14) +BQHex.GetPointIds().SetId(15, 15) +BQHex.GetPointIds().SetId(16, 16) +BQHex.GetPointIds().SetId(17, 17) +BQHex.GetPointIds().SetId(18, 18) +BQHex.GetPointIds().SetId(19, 19) +BQHex.GetPointIds().SetId(20, 20) +BQHex.GetPointIds().SetId(21, 21) +BQHex.GetPointIds().SetId(22, 22) +BQHex.GetPointIds().SetId(23, 23) BQHexGrid = vtk.vtkUnstructuredGrid() -BQHexGrid.Allocate(1,1) -BQHexGrid.InsertNextCell(BQHex.GetCellType(),BQHex.GetPointIds()) +BQHexGrid.Allocate(1, 1) +BQHexGrid.InsertNextCell(BQHex.GetCellType(), BQHex.GetPointIds()) BQHexGrid.SetPoints(BQhexPoints) BQHexGrid.GetPointData().SetScalars(BQhexScalars) BQhexclips = vtk.vtkClipDataSet() @@ -593,60 +609,61 @@ BQHexActor.GetProperty().SetAmbient(1.0) BQHexclipActor = vtk.vtkActor() BQHexclipActor.SetMapper(BQHexclipMapper) BQHexclipActor.GetProperty().SetAmbient(1.0) + # Quadratic wedge wedgePoints = vtk.vtkPoints() wedgePoints.SetNumberOfPoints(15) -wedgePoints.InsertPoint(0,0,0,0) -wedgePoints.InsertPoint(1,1,0,0) -wedgePoints.InsertPoint(2,0,1,0) -wedgePoints.InsertPoint(3,0,0,1) -wedgePoints.InsertPoint(4,1,0,1) -wedgePoints.InsertPoint(5,0,1,1) -wedgePoints.InsertPoint(6,0.5,0,0) -wedgePoints.InsertPoint(7,0.5,0.5,0) -wedgePoints.InsertPoint(8,0,0.5,0) -wedgePoints.InsertPoint(9,0.5,0,1) -wedgePoints.InsertPoint(10,0.5,0.5,1) -wedgePoints.InsertPoint(11,0,0.5,1) -wedgePoints.InsertPoint(12,0,0,0.5) -wedgePoints.InsertPoint(13,1,0,0.5) -wedgePoints.InsertPoint(14,0,1,0.5) +wedgePoints.InsertPoint(0, 0, 0, 0) +wedgePoints.InsertPoint(1, 1, 0, 0) +wedgePoints.InsertPoint(2, 0, 1, 0) +wedgePoints.InsertPoint(3, 0, 0, 1) +wedgePoints.InsertPoint(4, 1, 0, 1) +wedgePoints.InsertPoint(5, 0, 1, 1) +wedgePoints.InsertPoint(6, 0.5, 0, 0) +wedgePoints.InsertPoint(7, 0.5, 0.5, 0) +wedgePoints.InsertPoint(8, 0, 0.5, 0) +wedgePoints.InsertPoint(9, 0.5, 0, 1) +wedgePoints.InsertPoint(10, 0.5, 0.5, 1) +wedgePoints.InsertPoint(11, 0, 0.5, 1) +wedgePoints.InsertPoint(12, 0, 0, 0.5) +wedgePoints.InsertPoint(13, 1, 0, 0.5) +wedgePoints.InsertPoint(14, 0, 1, 0.5) wedgeScalars = vtk.vtkFloatArray() wedgeScalars.SetNumberOfTuples(15) -wedgeScalars.InsertValue(0,1.0) -wedgeScalars.InsertValue(1,1.0) -wedgeScalars.InsertValue(2,1.0) -wedgeScalars.InsertValue(3,1.0) -wedgeScalars.InsertValue(4,1.0) -wedgeScalars.InsertValue(5,1.0) -wedgeScalars.InsertValue(6,0.0) -wedgeScalars.InsertValue(7,0.0) -wedgeScalars.InsertValue(8,0.0) -wedgeScalars.InsertValue(9,0.0) -wedgeScalars.InsertValue(10,0.0) -wedgeScalars.InsertValue(11,0.0) -wedgeScalars.InsertValue(12,0.0) -wedgeScalars.InsertValue(13,0.0) -wedgeScalars.InsertValue(14,0.0) +wedgeScalars.InsertValue(0, 1.0) +wedgeScalars.InsertValue(1, 1.0) +wedgeScalars.InsertValue(2, 1.0) +wedgeScalars.InsertValue(3, 1.0) +wedgeScalars.InsertValue(4, 1.0) +wedgeScalars.InsertValue(5, 1.0) +wedgeScalars.InsertValue(6, 0.0) +wedgeScalars.InsertValue(7, 0.0) +wedgeScalars.InsertValue(8, 0.0) +wedgeScalars.InsertValue(9, 0.0) +wedgeScalars.InsertValue(10, 0.0) +wedgeScalars.InsertValue(11, 0.0) +wedgeScalars.InsertValue(12, 0.0) +wedgeScalars.InsertValue(13, 0.0) +wedgeScalars.InsertValue(14, 0.0) aWedge = vtk.vtkQuadraticWedge() -aWedge.GetPointIds().SetId(0,0) -aWedge.GetPointIds().SetId(1,1) -aWedge.GetPointIds().SetId(2,2) -aWedge.GetPointIds().SetId(3,3) -aWedge.GetPointIds().SetId(4,4) -aWedge.GetPointIds().SetId(5,5) -aWedge.GetPointIds().SetId(6,6) -aWedge.GetPointIds().SetId(7,7) -aWedge.GetPointIds().SetId(8,8) -aWedge.GetPointIds().SetId(9,9) -aWedge.GetPointIds().SetId(10,10) -aWedge.GetPointIds().SetId(11,11) -aWedge.GetPointIds().SetId(12,12) -aWedge.GetPointIds().SetId(13,13) -aWedge.GetPointIds().SetId(14,14) +aWedge.GetPointIds().SetId(0, 0) +aWedge.GetPointIds().SetId(1, 1) +aWedge.GetPointIds().SetId(2, 2) +aWedge.GetPointIds().SetId(3, 3) +aWedge.GetPointIds().SetId(4, 4) +aWedge.GetPointIds().SetId(5, 5) +aWedge.GetPointIds().SetId(6, 6) +aWedge.GetPointIds().SetId(7, 7) +aWedge.GetPointIds().SetId(8, 8) +aWedge.GetPointIds().SetId(9, 9) +aWedge.GetPointIds().SetId(10, 10) +aWedge.GetPointIds().SetId(11, 11) +aWedge.GetPointIds().SetId(12, 12) +aWedge.GetPointIds().SetId(13, 13) +aWedge.GetPointIds().SetId(14, 14) aWedgeGrid = vtk.vtkUnstructuredGrid() -aWedgeGrid.Allocate(1,1) -aWedgeGrid.InsertNextCell(aWedge.GetCellType(),aWedge.GetPointIds()) +aWedgeGrid.Allocate(1, 1) +aWedgeGrid.InsertNextCell(aWedge.GetCellType(), aWedge.GetPointIds()) aWedgeGrid.SetPoints(wedgePoints) aWedgeGrid.GetPointData().SetScalars(wedgeScalars) wedgeclips = vtk.vtkClipDataSet() @@ -665,52 +682,54 @@ aWedgeActor.GetProperty().SetAmbient(1.0) aWedgeclipActor = vtk.vtkActor() aWedgeclipActor.SetMapper(aWedgeclipMapper) aWedgeclipActor.GetProperty().SetAmbient(1.0) + # Quadratic linear wedge QLwedgePoints = vtk.vtkPoints() QLwedgePoints.SetNumberOfPoints(12) -QLwedgePoints.InsertPoint(0,0,0,0) -QLwedgePoints.InsertPoint(1,1,0,0) -QLwedgePoints.InsertPoint(2,0,1,0) -QLwedgePoints.InsertPoint(3,0,0,1) -QLwedgePoints.InsertPoint(4,1,0,1) -QLwedgePoints.InsertPoint(5,0,1,1) -QLwedgePoints.InsertPoint(6,0.5,0,0) -QLwedgePoints.InsertPoint(7,0.5,0.5,0) -QLwedgePoints.InsertPoint(8,0,0.5,0) -QLwedgePoints.InsertPoint(9,0.5,0,1) -QLwedgePoints.InsertPoint(10,0.5,0.5,1) -QLwedgePoints.InsertPoint(11,0,0.5,1) +QLwedgePoints.InsertPoint(0, 0, 0, 0) +QLwedgePoints.InsertPoint(1, 1, 0, 0) +QLwedgePoints.InsertPoint(2, 0, 1, 0) +QLwedgePoints.InsertPoint(3, 0, 0, 1) +QLwedgePoints.InsertPoint(4, 1, 0, 1) +QLwedgePoints.InsertPoint(5, 0, 1, 1) +QLwedgePoints.InsertPoint(6, 0.5, 0, 0) +QLwedgePoints.InsertPoint(7, 0.5, 0.5, 0) +QLwedgePoints.InsertPoint(8, 0, 0.5, 0) +QLwedgePoints.InsertPoint(9, 0.5, 0, 1) +QLwedgePoints.InsertPoint(10, 0.5, 0.5, 1) +QLwedgePoints.InsertPoint(11, 0, 0.5, 1) QLwedgeScalars = vtk.vtkFloatArray() QLwedgeScalars.SetNumberOfTuples(12) -QLwedgeScalars.InsertValue(0,1.0) -QLwedgeScalars.InsertValue(1,1.0) -QLwedgeScalars.InsertValue(2,1.0) -QLwedgeScalars.InsertValue(3,1.0) -QLwedgeScalars.InsertValue(4,1.0) -QLwedgeScalars.InsertValue(5,1.0) -QLwedgeScalars.InsertValue(6,0.0) -QLwedgeScalars.InsertValue(7,0.0) -QLwedgeScalars.InsertValue(8,0.0) -QLwedgeScalars.InsertValue(9,0.0) -QLwedgeScalars.InsertValue(10,0.0) -QLwedgeScalars.InsertValue(11,0.0) +QLwedgeScalars.InsertValue(0, 1.0) +QLwedgeScalars.InsertValue(1, 1.0) +QLwedgeScalars.InsertValue(2, 1.0) +QLwedgeScalars.InsertValue(3, 1.0) +QLwedgeScalars.InsertValue(4, 1.0) +QLwedgeScalars.InsertValue(5, 1.0) +QLwedgeScalars.InsertValue(6, 0.0) +QLwedgeScalars.InsertValue(7, 0.0) +QLwedgeScalars.InsertValue(8, 0.0) +QLwedgeScalars.InsertValue(9, 0.0) +QLwedgeScalars.InsertValue(10, 0.0) +QLwedgeScalars.InsertValue(11, 0.0) QLWedge = vtk.vtkQuadraticLinearWedge() -QLWedge.GetPointIds().SetId(0,0) -QLWedge.GetPointIds().SetId(1,1) -QLWedge.GetPointIds().SetId(2,2) -QLWedge.GetPointIds().SetId(3,3) -QLWedge.GetPointIds().SetId(4,4) -QLWedge.GetPointIds().SetId(5,5) -QLWedge.GetPointIds().SetId(6,6) -QLWedge.GetPointIds().SetId(7,7) -QLWedge.GetPointIds().SetId(8,8) -QLWedge.GetPointIds().SetId(9,9) -QLWedge.GetPointIds().SetId(10,10) -QLWedge.GetPointIds().SetId(11,11) -#QLaWedge DebugOn +QLWedge.GetPointIds().SetId(0, 0) +QLWedge.GetPointIds().SetId(1, 1) +QLWedge.GetPointIds().SetId(2, 2) +QLWedge.GetPointIds().SetId(3, 3) +QLWedge.GetPointIds().SetId(4, 4) +QLWedge.GetPointIds().SetId(5, 5) +QLWedge.GetPointIds().SetId(6, 6) +QLWedge.GetPointIds().SetId(7, 7) +QLWedge.GetPointIds().SetId(8, 8) +QLWedge.GetPointIds().SetId(9, 9) +QLWedge.GetPointIds().SetId(10, 10) +QLWedge.GetPointIds().SetId(11, 11) + +# QLaWedge DebugOn QLWedgeGrid = vtk.vtkUnstructuredGrid() -QLWedgeGrid.Allocate(1,1) -QLWedgeGrid.InsertNextCell(QLWedge.GetCellType(),QLWedge.GetPointIds()) +QLWedgeGrid.Allocate(1, 1) +QLWedgeGrid.InsertNextCell(QLWedge.GetCellType(), QLWedge.GetPointIds()) QLWedgeGrid.SetPoints(QLwedgePoints) QLWedgeGrid.GetPointData().SetScalars(QLwedgeScalars) QLwedgeclips = vtk.vtkClipDataSet() @@ -729,70 +748,72 @@ QLWedgeActor.GetProperty().SetAmbient(1.0) QLWedgeclipActor = vtk.vtkActor() QLWedgeclipActor.SetMapper(QLWedgeclipMapper) QLWedgeclipActor.GetProperty().SetAmbient(1.0) + # BiQuadratic wedge BQwedgePoints = vtk.vtkPoints() BQwedgePoints.SetNumberOfPoints(18) -BQwedgePoints.InsertPoint(0,0,0,0) -BQwedgePoints.InsertPoint(1,1,0,0) -BQwedgePoints.InsertPoint(2,0,1,0) -BQwedgePoints.InsertPoint(3,0,0,1) -BQwedgePoints.InsertPoint(4,1,0,1) -BQwedgePoints.InsertPoint(5,0,1,1) -BQwedgePoints.InsertPoint(6,0.5,0,0) -BQwedgePoints.InsertPoint(7,0.5,0.5,0) -BQwedgePoints.InsertPoint(8,0,0.5,0) -BQwedgePoints.InsertPoint(9,0.5,0,1) -BQwedgePoints.InsertPoint(10,0.5,0.5,1) -BQwedgePoints.InsertPoint(11,0,0.5,1) -BQwedgePoints.InsertPoint(12,0,0,0.5) -BQwedgePoints.InsertPoint(13,1,0,0.5) -BQwedgePoints.InsertPoint(14,0,1,0.5) -BQwedgePoints.InsertPoint(15,0.5,0,0.5) -BQwedgePoints.InsertPoint(16,0.5,0.5,0.5) -BQwedgePoints.InsertPoint(17,0,0.5,0.5) +BQwedgePoints.InsertPoint(0, 0, 0, 0) +BQwedgePoints.InsertPoint(1, 1, 0, 0) +BQwedgePoints.InsertPoint(2, 0, 1, 0) +BQwedgePoints.InsertPoint(3, 0, 0, 1) +BQwedgePoints.InsertPoint(4, 1, 0, 1) +BQwedgePoints.InsertPoint(5, 0, 1, 1) +BQwedgePoints.InsertPoint(6, 0.5, 0, 0) +BQwedgePoints.InsertPoint(7, 0.5, 0.5, 0) +BQwedgePoints.InsertPoint(8, 0, 0.5, 0) +BQwedgePoints.InsertPoint(9, 0.5, 0, 1) +BQwedgePoints.InsertPoint(10, 0.5, 0.5, 1) +BQwedgePoints.InsertPoint(11, 0, 0.5, 1) +BQwedgePoints.InsertPoint(12, 0, 0, 0.5) +BQwedgePoints.InsertPoint(13, 1, 0, 0.5) +BQwedgePoints.InsertPoint(14, 0, 1, 0.5) +BQwedgePoints.InsertPoint(15, 0.5, 0, 0.5) +BQwedgePoints.InsertPoint(16, 0.5, 0.5, 0.5) +BQwedgePoints.InsertPoint(17, 0, 0.5, 0.5) BQwedgeScalars = vtk.vtkFloatArray() BQwedgeScalars.SetNumberOfTuples(18) -BQwedgeScalars.InsertValue(0,1.0) -BQwedgeScalars.InsertValue(1,1.0) -BQwedgeScalars.InsertValue(2,1.0) -BQwedgeScalars.InsertValue(3,1.0) -BQwedgeScalars.InsertValue(4,1.0) -BQwedgeScalars.InsertValue(5,1.0) -BQwedgeScalars.InsertValue(6,0.0) -BQwedgeScalars.InsertValue(7,0.0) -BQwedgeScalars.InsertValue(8,0.0) -BQwedgeScalars.InsertValue(9,0.0) -BQwedgeScalars.InsertValue(10,0.0) -BQwedgeScalars.InsertValue(11,0.0) -BQwedgeScalars.InsertValue(12,0.0) -BQwedgeScalars.InsertValue(13,0.0) -BQwedgeScalars.InsertValue(14,0.0) -BQwedgeScalars.InsertValue(15,0.0) -BQwedgeScalars.InsertValue(16,0.0) -BQwedgeScalars.InsertValue(17,0.0) +BQwedgeScalars.InsertValue(0, 1.0) +BQwedgeScalars.InsertValue(1, 1.0) +BQwedgeScalars.InsertValue(2, 1.0) +BQwedgeScalars.InsertValue(3, 1.0) +BQwedgeScalars.InsertValue(4, 1.0) +BQwedgeScalars.InsertValue(5, 1.0) +BQwedgeScalars.InsertValue(6, 0.0) +BQwedgeScalars.InsertValue(7, 0.0) +BQwedgeScalars.InsertValue(8, 0.0) +BQwedgeScalars.InsertValue(9, 0.0) +BQwedgeScalars.InsertValue(10, 0.0) +BQwedgeScalars.InsertValue(11, 0.0) +BQwedgeScalars.InsertValue(12, 0.0) +BQwedgeScalars.InsertValue(13, 0.0) +BQwedgeScalars.InsertValue(14, 0.0) +BQwedgeScalars.InsertValue(15, 0.0) +BQwedgeScalars.InsertValue(16, 0.0) +BQwedgeScalars.InsertValue(17, 0.0) BQWedge = vtk.vtkBiQuadraticQuadraticWedge() -BQWedge.GetPointIds().SetId(0,0) -BQWedge.GetPointIds().SetId(1,1) -BQWedge.GetPointIds().SetId(2,2) -BQWedge.GetPointIds().SetId(3,3) -BQWedge.GetPointIds().SetId(4,4) -BQWedge.GetPointIds().SetId(5,5) -BQWedge.GetPointIds().SetId(6,6) -BQWedge.GetPointIds().SetId(7,7) -BQWedge.GetPointIds().SetId(8,8) -BQWedge.GetPointIds().SetId(9,9) -BQWedge.GetPointIds().SetId(10,10) -BQWedge.GetPointIds().SetId(11,11) -BQWedge.GetPointIds().SetId(12,12) -BQWedge.GetPointIds().SetId(13,13) -BQWedge.GetPointIds().SetId(14,14) -BQWedge.GetPointIds().SetId(15,15) -BQWedge.GetPointIds().SetId(16,16) -BQWedge.GetPointIds().SetId(17,17) -#BQWedge DebugOn +BQWedge.GetPointIds().SetId(0, 0) +BQWedge.GetPointIds().SetId(1, 1) +BQWedge.GetPointIds().SetId(2, 2) +BQWedge.GetPointIds().SetId(3, 3) +BQWedge.GetPointIds().SetId(4, 4) +BQWedge.GetPointIds().SetId(5, 5) +BQWedge.GetPointIds().SetId(6, 6) +BQWedge.GetPointIds().SetId(7, 7) +BQWedge.GetPointIds().SetId(8, 8) +BQWedge.GetPointIds().SetId(9, 9) +BQWedge.GetPointIds().SetId(10, 10) +BQWedge.GetPointIds().SetId(11, 11) +BQWedge.GetPointIds().SetId(12, 12) +BQWedge.GetPointIds().SetId(13, 13) +BQWedge.GetPointIds().SetId(14, 14) +BQWedge.GetPointIds().SetId(15, 15) +BQWedge.GetPointIds().SetId(16, 16) +BQWedge.GetPointIds().SetId(17, 17) + +# BQWedge DebugOn BQWedgeGrid = vtk.vtkUnstructuredGrid() -BQWedgeGrid.Allocate(1,1) -BQWedgeGrid.InsertNextCell(BQWedge.GetCellType(),BQWedge.GetPointIds()) +BQWedgeGrid.Allocate(1, 1) +BQWedgeGrid.InsertNextCell(BQWedge.GetCellType(), BQWedge.GetPointIds()) BQWedgeGrid.SetPoints(BQwedgePoints) BQWedgeGrid.GetPointData().SetScalars(BQwedgeScalars) BQwedgeclips = vtk.vtkClipDataSet() @@ -811,54 +832,55 @@ BQWedgeActor.GetProperty().SetAmbient(1.0) BQWedgeclipActor = vtk.vtkActor() BQWedgeclipActor.SetMapper(BQWedgeclipMapper) BQWedgeclipActor.GetProperty().SetAmbient(1.0) + # Quadratic pyramid pyraPoints = vtk.vtkPoints() pyraPoints.SetNumberOfPoints(13) -pyraPoints.InsertPoint(0,0,0,0) -pyraPoints.InsertPoint(1,1,0,0) -pyraPoints.InsertPoint(2,1,1,0) -pyraPoints.InsertPoint(3,0,1,0) -pyraPoints.InsertPoint(4,0,0,1) -pyraPoints.InsertPoint(5,0.5,0,0) -pyraPoints.InsertPoint(6,1,0.5,0) -pyraPoints.InsertPoint(7,0.5,1,0) -pyraPoints.InsertPoint(8,0,0.5,0) -pyraPoints.InsertPoint(9,0,0,0.5) -pyraPoints.InsertPoint(10,0.5,0,0.5) -pyraPoints.InsertPoint(11,0.5,0.5,0.5) -pyraPoints.InsertPoint(12,0,0.5,0.5) +pyraPoints.InsertPoint(0, 0, 0, 0) +pyraPoints.InsertPoint(1, 1, 0, 0) +pyraPoints.InsertPoint(2, 1, 1, 0) +pyraPoints.InsertPoint(3, 0, 1, 0) +pyraPoints.InsertPoint(4, 0, 0, 1) +pyraPoints.InsertPoint(5, 0.5, 0, 0) +pyraPoints.InsertPoint(6, 1, 0.5, 0) +pyraPoints.InsertPoint(7, 0.5, 1, 0) +pyraPoints.InsertPoint(8, 0, 0.5, 0) +pyraPoints.InsertPoint(9, 0, 0, 0.5) +pyraPoints.InsertPoint(10, 0.5, 0, 0.5) +pyraPoints.InsertPoint(11, 0.5, 0.5, 0.5) +pyraPoints.InsertPoint(12, 0, 0.5, 0.5) pyraScalars = vtk.vtkFloatArray() pyraScalars.SetNumberOfTuples(13) -pyraScalars.InsertValue(0,1.0) -pyraScalars.InsertValue(1,1.0) -pyraScalars.InsertValue(2,1.0) -pyraScalars.InsertValue(3,1.0) -pyraScalars.InsertValue(4,1.0) -pyraScalars.InsertValue(5,0.0) -pyraScalars.InsertValue(6,0.0) -pyraScalars.InsertValue(7,0.0) -pyraScalars.InsertValue(8,0.0) -pyraScalars.InsertValue(9,0.0) -pyraScalars.InsertValue(10,0.0) -pyraScalars.InsertValue(11,0.0) -pyraScalars.InsertValue(12,0.0) +pyraScalars.InsertValue(0, 1.0) +pyraScalars.InsertValue(1, 1.0) +pyraScalars.InsertValue(2, 1.0) +pyraScalars.InsertValue(3, 1.0) +pyraScalars.InsertValue(4, 1.0) +pyraScalars.InsertValue(5, 0.0) +pyraScalars.InsertValue(6, 0.0) +pyraScalars.InsertValue(7, 0.0) +pyraScalars.InsertValue(8, 0.0) +pyraScalars.InsertValue(9, 0.0) +pyraScalars.InsertValue(10, 0.0) +pyraScalars.InsertValue(11, 0.0) +pyraScalars.InsertValue(12, 0.0) aPyramid = vtk.vtkQuadraticPyramid() -aPyramid.GetPointIds().SetId(0,0) -aPyramid.GetPointIds().SetId(1,1) -aPyramid.GetPointIds().SetId(2,2) -aPyramid.GetPointIds().SetId(3,3) -aPyramid.GetPointIds().SetId(4,4) -aPyramid.GetPointIds().SetId(5,5) -aPyramid.GetPointIds().SetId(6,6) -aPyramid.GetPointIds().SetId(7,7) -aPyramid.GetPointIds().SetId(8,8) -aPyramid.GetPointIds().SetId(9,9) -aPyramid.GetPointIds().SetId(10,10) -aPyramid.GetPointIds().SetId(11,11) -aPyramid.GetPointIds().SetId(12,12) +aPyramid.GetPointIds().SetId(0, 0) +aPyramid.GetPointIds().SetId(1, 1) +aPyramid.GetPointIds().SetId(2, 2) +aPyramid.GetPointIds().SetId(3, 3) +aPyramid.GetPointIds().SetId(4, 4) +aPyramid.GetPointIds().SetId(5, 5) +aPyramid.GetPointIds().SetId(6, 6) +aPyramid.GetPointIds().SetId(7, 7) +aPyramid.GetPointIds().SetId(8, 8) +aPyramid.GetPointIds().SetId(9, 9) +aPyramid.GetPointIds().SetId(10, 10) +aPyramid.GetPointIds().SetId(11, 11) +aPyramid.GetPointIds().SetId(12, 12) aPyramidGrid = vtk.vtkUnstructuredGrid() -aPyramidGrid.Allocate(1,1) -aPyramidGrid.InsertNextCell(aPyramid.GetCellType(),aPyramid.GetPointIds()) +aPyramidGrid.Allocate(1, 1) +aPyramidGrid.InsertNextCell(aPyramid.GetCellType(), aPyramid.GetPointIds()) aPyramidGrid.SetPoints(pyraPoints) aPyramidGrid.GetPointData().SetScalars(pyraScalars) pyraclips = vtk.vtkClipDataSet() @@ -877,6 +899,7 @@ aPyramidActor.GetProperty().SetAmbient(1.0) aPyramidclipActor = vtk.vtkActor() aPyramidclipActor.SetMapper(aPyramidclipMapper) aPyramidclipActor.GetProperty().SetAmbient(1.0) + # Create the rendering related stuff. # Since some of our actors are a single vertex, we need to remove all # cullers so the single vertex actors will render @@ -886,73 +909,93 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) -ren1.SetBackground(.1,.2,.3) -renWin.SetSize(400,200) +ren1.SetBackground(.1, .2, .3) + +renWin.SetSize(400, 200) + # specify properties ren1.AddActor(aEdgeActor) ren1.AddActor(aEdgeclipActor) + ren1.AddActor(aTriActor) ren1.AddActor(aTriclipActor) + ren1.AddActor(aQuadActor) ren1.AddActor(aQuadclipActor) + ren1.AddActor(BQuadActor) ren1.AddActor(BQuadclipActor) + ren1.AddActor(QLQuadActor) ren1.AddActor(QLQuadclipActor) + ren1.AddActor(aTetActor) ren1.AddActor(aTetclipActor) + ren1.AddActor(aHexActor) ren1.AddActor(aHexclipActor) + ren1.AddActor(TQHexActor) ren1.AddActor(TQHexclipActor) + ren1.AddActor(BQHexActor) ren1.AddActor(BQHexclipActor) + ren1.AddActor(aWedgeActor) ren1.AddActor(aWedgeclipActor) + ren1.AddActor(BQWedgeActor) ren1.AddActor(BQWedgeclipActor) + ren1.AddActor(QLWedgeActor) ren1.AddActor(QLWedgeclipActor) + ren1.AddActor(aPyramidActor) ren1.AddActor(aPyramidclipActor) + # places everyone!! -aEdgeclipActor.AddPosition(0,2,0) -aTriActor.AddPosition(2,0,0) -aTriclipActor.AddPosition(2,2,0) -aQuadActor.AddPosition(4,0,0) -BQuadActor.AddPosition(4,0,2) -QLQuadActor.AddPosition(4,0,4) -aQuadclipActor.AddPosition(4,2,0) -BQuadclipActor.AddPosition(4,2,2) -QLQuadclipActor.AddPosition(4,2,4) -aTetActor.AddPosition(6,0,0) -aTetclipActor.AddPosition(6,2,0) -aHexActor.AddPosition(8,0,0) -TQHexActor.AddPosition(8,0,2) -BQHexActor.AddPosition(8,0,4) -aHexclipActor.AddPosition(8,2,0) -TQHexclipActor.AddPosition(8,2,2) -BQHexclipActor.AddPosition(8,2,4) -aWedgeActor.AddPosition(10,0,0) -QLWedgeActor.AddPosition(10,0,2) -BQWedgeActor.AddPosition(10,0,4) -aWedgeclipActor.AddPosition(10,2,0) -QLWedgeclipActor.AddPosition(10,2,2) -BQWedgeclipActor.AddPosition(10,2,4) -aPyramidActor.AddPosition(12,0,0) -aPyramidclipActor.AddPosition(12,2,0) -[base, back, left] = BuildBackdrop(-1, 15, -1, 4, -1, 6, .1) +aEdgeclipActor.AddPosition(0, 2, 0) +aTriActor.AddPosition(2, 0, 0) +aTriclipActor.AddPosition(2, 2, 0) +aQuadActor.AddPosition(4, 0, 0) +BQuadActor.AddPosition(4, 0, 2) +QLQuadActor.AddPosition(4, 0, 4) +aQuadclipActor.AddPosition(4, 2, 0) +BQuadclipActor.AddPosition(4, 2, 2) +QLQuadclipActor.AddPosition(4, 2, 4) +aTetActor.AddPosition(6, 0, 0) +aTetclipActor.AddPosition(6, 2, 0) +aHexActor.AddPosition(8, 0, 0) +TQHexActor.AddPosition(8, 0, 2) +BQHexActor.AddPosition(8, 0, 4) +aHexclipActor.AddPosition(8, 2, 0) +TQHexclipActor.AddPosition(8, 2, 2) +BQHexclipActor.AddPosition(8, 2, 4) +aWedgeActor.AddPosition(10, 0, 0) +QLWedgeActor.AddPosition(10, 0, 2) +BQWedgeActor.AddPosition(10, 0, 4) +aWedgeclipActor.AddPosition(10, 2, 0) +QLWedgeclipActor.AddPosition(10, 2, 2) +BQWedgeclipActor.AddPosition(10, 2, 4) +aPyramidActor.AddPosition(12, 0, 0) +aPyramidclipActor.AddPosition(12, 2, 0) + +[base, back, left] = backdrop.BuildBackdrop(-1, 15, -1, 4, -1, 6, .1) + ren1.AddActor(base) -base.GetProperty().SetDiffuseColor(.2,.2,.2) +base.GetProperty().SetDiffuseColor(.2, .2, .2) ren1.AddActor(left) -left.GetProperty().SetDiffuseColor(.2,.2,.2) +left.GetProperty().SetDiffuseColor(.2, .2, .2) ren1.AddActor(back) -back.GetProperty().SetDiffuseColor(.2,.2,.2) +back.GetProperty().SetDiffuseColor(.2, .2, .2) + ren1.ResetCamera() ren1.GetActiveCamera().Dolly(2.5) ren1.ResetCameraClippingRange() + renWin.Render() + # render the image # iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Filters/General/Testing/Python/clipTet.py b/Filters/General/Testing/Python/clipTet.py index 55c8fc71abb..2d75fbb8ddf 100755 --- a/Filters/General/Testing/Python/clipTet.py +++ b/Filters/General/Testing/Python/clipTet.py @@ -4,115 +4,152 @@ from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() -#define a Single Cube +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 + +# define a Single Cube Scalars = vtk.vtkFloatArray() Scalars.InsertNextValue(1.0) Scalars.InsertNextValue(0.0) Scalars.InsertNextValue(0.0) Scalars.InsertNextValue(1.0) + Points = vtk.vtkPoints() -Points.InsertNextPoint(0,0,0) -Points.InsertNextPoint(1,0,0) -Points.InsertNextPoint(0,1,0) -Points.InsertNextPoint(0,0,1) +Points.InsertNextPoint(0, 0, 0) +Points.InsertNextPoint(1, 0, 0) +Points.InsertNextPoint(0, 1, 0) +Points.InsertNextPoint(0, 0, 1) + Ids = vtk.vtkIdList() Ids.InsertNextId(0) Ids.InsertNextId(1) Ids.InsertNextId(2) Ids.InsertNextId(3) -Grid = vtk.vtkUnstructuredGrid() -Grid.Allocate(10,10) -Grid.InsertNextCell(10,Ids) -Grid.SetPoints(Points) -Grid.GetPointData().SetScalars(Scalars) -#Clip the tetra + +grid = vtk.vtkUnstructuredGrid() +grid.Allocate(10, 10) +grid.InsertNextCell(10, Ids) +grid.SetPoints(Points) +grid.GetPointData().SetScalars(Scalars) + +# Clip the tetra clipper = vtk.vtkClipDataSet() -clipper.SetInputData(Grid) +clipper.SetInputData(grid) clipper.SetValue(0.5) clipper.Update() + # build tubes for the triangle edges # tetEdges = vtk.vtkExtractEdges() tetEdges.SetInputConnection(clipper.GetOutputPort()) + tetEdgeTubes = vtk.vtkTubeFilter() tetEdgeTubes.SetInputConnection(tetEdges.GetOutputPort()) tetEdgeTubes.SetRadius(.005) tetEdgeTubes.SetNumberOfSides(6) + tetEdgeMapper = vtk.vtkPolyDataMapper() tetEdgeMapper.SetInputConnection(tetEdgeTubes.GetOutputPort()) tetEdgeMapper.ScalarVisibilityOff() + tetEdgeActor = vtk.vtkActor() tetEdgeActor.SetMapper(tetEdgeMapper) -tetEdgeActor.GetProperty().SetDiffuseColor(lamp_black) +tetEdgeActor.GetProperty().SetDiffuseColor(GetRGBColor('lamp_black')) tetEdgeActor.GetProperty().SetSpecular(.4) tetEdgeActor.GetProperty().SetSpecularPower(10) -#shrink the triangles so we can see each one + +# shrink the triangles so we can see each one aShrinker = vtk.vtkShrinkFilter() aShrinker.SetShrinkFactor(1) aShrinker.SetInputConnection(clipper.GetOutputPort()) + aMapper = vtk.vtkDataSetMapper() aMapper.ScalarVisibilityOff() aMapper.SetInputConnection(aShrinker.GetOutputPort()) + Tets = vtk.vtkActor() Tets.SetMapper(aMapper) -Tets.GetProperty().SetDiffuseColor(banana) -#build a model of the cube +Tets.GetProperty().SetDiffuseColor(GetRGBColor('banana')) + +# build a model of the cube Edges = vtk.vtkExtractEdges() -Edges.SetInputData(Grid) +Edges.SetInputData(grid) + Tubes = vtk.vtkTubeFilter() Tubes.SetInputConnection(Edges.GetOutputPort()) Tubes.SetRadius(.01) Tubes.SetNumberOfSides(6) + TubeMapper = vtk.vtkPolyDataMapper() TubeMapper.SetInputConnection(Tubes.GetOutputPort()) TubeMapper.ScalarVisibilityOff() + CubeEdges = vtk.vtkActor() CubeEdges.SetMapper(TubeMapper) -CubeEdges.GetProperty().SetDiffuseColor(khaki) +CubeEdges.GetProperty().SetDiffuseColor(GetRGBColor('khaki')) CubeEdges.GetProperty().SetSpecular(.4) CubeEdges.GetProperty().SetSpecularPower(10) + # build the vertices of the cube # Sphere = vtk.vtkSphereSource() Sphere.SetRadius(0.04) Sphere.SetPhiResolution(20) Sphere.SetThetaResolution(20) + ThresholdIn = vtk.vtkThresholdPoints() -ThresholdIn.SetInputData(Grid) +ThresholdIn.SetInputData(grid) ThresholdIn.ThresholdByUpper(.5) + Vertices = vtk.vtkGlyph3D() Vertices.SetInputConnection(ThresholdIn.GetOutputPort()) Vertices.SetSourceConnection(Sphere.GetOutputPort()) + SphereMapper = vtk.vtkPolyDataMapper() SphereMapper.SetInputConnection(Vertices.GetOutputPort()) SphereMapper.ScalarVisibilityOff() + CubeVertices = vtk.vtkActor() CubeVertices.SetMapper(SphereMapper) -CubeVertices.GetProperty().SetDiffuseColor(tomato) -CubeVertices.GetProperty().SetDiffuseColor(tomato) -#define the text for the labels +CubeVertices.GetProperty().SetDiffuseColor(GetRGBColor('tomato')) + +# define the text for the labels caseLabel = vtk.vtkVectorText() caseLabel.SetText("Case 1") + aLabelTransform = vtk.vtkTransform() aLabelTransform.Identity() -aLabelTransform.Translate(-.2,0,1.25) -aLabelTransform.Scale(.05,.05,.05) +aLabelTransform.Translate(-.2, 0, 1.25) +aLabelTransform.Scale(.05, .05, .05) + labelTransform = vtk.vtkTransformPolyDataFilter() labelTransform.SetTransform(aLabelTransform) labelTransform.SetInputConnection(caseLabel.GetOutputPort()) + labelMapper = vtk.vtkPolyDataMapper() labelMapper.SetInputConnection(labelTransform.GetOutputPort()) + labelActor = vtk.vtkActor() labelActor.SetMapper(labelMapper) -#define the base + +# define the base baseModel = vtk.vtkCubeSource() baseModel.SetXLength(1.5) baseModel.SetYLength(.01) baseModel.SetZLength(1.5) + baseMapper = vtk.vtkPolyDataMapper() baseMapper.SetInputConnection(baseModel.GetOutputPort()) + base = vtk.vtkActor() base.SetMapper(baseMapper) + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -120,41 +157,50 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # position the base -base.SetPosition(.5,-.09,.5) +base.SetPosition(.5, -.09, .5) + ren1.AddActor(tetEdgeActor) ren1.AddActor(base) ren1.AddActor(labelActor) ren1.AddActor(CubeEdges) ren1.AddActor(CubeVertices) ren1.AddActor(Tets) -ren1.SetBackground(slate_grey) -Grid.Modified() -renWin.SetSize(400,400) +ren1.SetBackground(GetRGBColor('slate_grey')) + +grid.Modified() + +renWin.SetSize(400, 400) + ren1.ResetCamera() ren1.GetActiveCamera().Dolly(1.2) ren1.GetActiveCamera().Azimuth(30) ren1.GetActiveCamera().Elevation(20) ren1.ResetCameraClippingRange() + renWin.Render() + iren.Initialize() -mask = "1 2 4 8 16 32" -def cases (id,__vtk__temp0=0,__vtk__temp1=0): - global mask + +def cases (id, mask): i = 0 while i < 4: - m = lindex(mask,i) - if (expr.expr(globals(), locals(),["m","&","id"]) == 0): - Scalars.SetValue(i,0) + m = mask[i] + if m & id == 0: + Scalars.SetValue(i, 0) pass else: - Scalars.SetValue(i,1) + Scalars.SetValue(i, 1) pass - caseLabel.SetText("Case " + str(id) + "") - i = i + 1 + caseLabel.SetText("Case " + str(id)) + i += 1 - Grid.Modified() + grid.Modified() renWin.Render() -cases(3) -# --- end of script -- +mask = [1, 2, 4, 8, 16, 32] + +cases(3, mask) + +# iren.Start() diff --git a/Filters/General/Testing/Python/clipWedge.py b/Filters/General/Testing/Python/clipWedge.py index 456d0546fc3..c4c15a9d0af 100755 --- a/Filters/General/Testing/Python/clipWedge.py +++ b/Filters/General/Testing/Python/clipWedge.py @@ -4,7 +4,16 @@ from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() -#define a Single Cube +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 + +# define a Single Cube Scalars = vtk.vtkFloatArray() Scalars.InsertNextValue(1.0) Scalars.InsertNextValue(0.0) @@ -12,13 +21,15 @@ Scalars.InsertNextValue(0.0) Scalars.InsertNextValue(0.0) Scalars.InsertNextValue(0.0) Scalars.InsertNextValue(0.0) + Points = vtk.vtkPoints() -Points.InsertNextPoint(0,0,0) -Points.InsertNextPoint(1,0,0) -Points.InsertNextPoint(0,0,1) -Points.InsertNextPoint(0,1,0) -Points.InsertNextPoint(1,1,0) -Points.InsertNextPoint(0,1,1) +Points.InsertNextPoint(0, 0, 0) +Points.InsertNextPoint(1, 0, 0) +Points.InsertNextPoint(0, 0, 1) +Points.InsertNextPoint(0, 1, 0) +Points.InsertNextPoint(1, 1, 0) +Points.InsertNextPoint(0, 1, 1) + Ids = vtk.vtkIdList() Ids.InsertNextId(0) Ids.InsertNextId(1) @@ -26,15 +37,18 @@ Ids.InsertNextId(2) Ids.InsertNextId(3) Ids.InsertNextId(4) Ids.InsertNextId(5) -Grid = vtk.vtkUnstructuredGrid() -Grid.Allocate(10,10) -Grid.InsertNextCell(13,Ids) -Grid.SetPoints(Points) -Grid.GetPointData().SetScalars(Scalars) -#Clip the wedge + +grid = vtk.vtkUnstructuredGrid() +grid.Allocate(10, 10) +grid.InsertNextCell(13, Ids) +grid.SetPoints(Points) +grid.GetPointData().SetScalars(Scalars) + +# Clip the wedge clipper = vtk.vtkClipDataSet() -clipper.SetInputData(Grid) +clipper.SetInputData(grid) clipper.SetValue(0.5) + # build tubes for the triangle edges # wedgeEdges = vtk.vtkExtractEdges() @@ -48,10 +62,11 @@ wedgeEdgeMapper.SetInputConnection(wedgeEdgeTubes.GetOutputPort()) wedgeEdgeMapper.ScalarVisibilityOff() wedgeEdgeActor = vtk.vtkActor() wedgeEdgeActor.SetMapper(wedgeEdgeMapper) -wedgeEdgeActor.GetProperty().SetDiffuseColor(lamp_black) +wedgeEdgeActor.GetProperty().SetDiffuseColor(GetRGBColor('lamp_black')) wedgeEdgeActor.GetProperty().SetSpecular(.4) wedgeEdgeActor.GetProperty().SetSpecularPower(10) -#shrink the triangles so we can see each one + +# shrink the triangles so we can see each one aShrinker = vtk.vtkShrinkFilter() aShrinker.SetShrinkFactor(1) aShrinker.SetInputConnection(clipper.GetOutputPort()) @@ -60,10 +75,11 @@ aMapper.ScalarVisibilityOff() aMapper.SetInputConnection(aShrinker.GetOutputPort()) Wedges = vtk.vtkActor() Wedges.SetMapper(aMapper) -Wedges.GetProperty().SetDiffuseColor(banana) -#build a model of the cube +Wedges.GetProperty().SetDiffuseColor(GetRGBColor('banana')) + +# build a model of the cube Edges = vtk.vtkExtractEdges() -Edges.SetInputData(Grid) +Edges.SetInputData(grid) Tubes = vtk.vtkTubeFilter() Tubes.SetInputConnection(Edges.GetOutputPort()) Tubes.SetRadius(.01) @@ -73,9 +89,10 @@ TubeMapper.SetInputConnection(Tubes.GetOutputPort()) TubeMapper.ScalarVisibilityOff() CubeEdges = vtk.vtkActor() CubeEdges.SetMapper(TubeMapper) -CubeEdges.GetProperty().SetDiffuseColor(khaki) +CubeEdges.GetProperty().SetDiffuseColor(GetRGBColor('khaki')) CubeEdges.GetProperty().SetSpecular(.4) CubeEdges.GetProperty().SetSpecularPower(10) + # build the vertices of the cube # Sphere = vtk.vtkSphereSource() @@ -83,7 +100,7 @@ Sphere.SetRadius(0.04) Sphere.SetPhiResolution(20) Sphere.SetThetaResolution(20) ThresholdIn = vtk.vtkThresholdPoints() -ThresholdIn.SetInputData(Grid) +ThresholdIn.SetInputData(grid) ThresholdIn.ThresholdByUpper(.5) Vertices = vtk.vtkGlyph3D() Vertices.SetInputConnection(ThresholdIn.GetOutputPort()) @@ -93,31 +110,39 @@ SphereMapper.SetInputConnection(Vertices.GetOutputPort()) SphereMapper.ScalarVisibilityOff() CubeVertices = vtk.vtkActor() CubeVertices.SetMapper(SphereMapper) -CubeVertices.GetProperty().SetDiffuseColor(tomato) -CubeVertices.GetProperty().SetDiffuseColor(tomato) -#define the text for the labels +CubeVertices.GetProperty().SetDiffuseColor(GetRGBColor('tomato')) + +# define the text for the labels caseLabel = vtk.vtkVectorText() caseLabel.SetText("Case 1") + aLabelTransform = vtk.vtkTransform() aLabelTransform.Identity() -aLabelTransform.Translate(-.2,0,1.25) -aLabelTransform.Scale(.05,.05,.05) +aLabelTransform.Translate(-.2, 0, 1.25) +aLabelTransform.Scale(.05, .05, .05) + labelTransform = vtk.vtkTransformPolyDataFilter() labelTransform.SetTransform(aLabelTransform) labelTransform.SetInputConnection(caseLabel.GetOutputPort()) + labelMapper = vtk.vtkPolyDataMapper() labelMapper.SetInputConnection(labelTransform.GetOutputPort()) + labelActor = vtk.vtkActor() labelActor.SetMapper(labelMapper) -#define the base + +# define the base baseModel = vtk.vtkCubeSource() baseModel.SetXLength(1.5) baseModel.SetYLength(.01) baseModel.SetZLength(1.5) + baseMapper = vtk.vtkPolyDataMapper() baseMapper.SetInputConnection(baseModel.GetOutputPort()) + base = vtk.vtkActor() base.SetMapper(baseMapper) + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -125,40 +150,46 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # position the base -base.SetPosition(.5,-.09,.5) +base.SetPosition(.5, -.09, .5) ren1.AddActor(wedgeEdgeActor) ren1.AddActor(base) ren1.AddActor(labelActor) ren1.AddActor(CubeEdges) ren1.AddActor(CubeVertices) ren1.AddActor(Wedges) -ren1.SetBackground(slate_grey) -renWin.SetSize(400,400) +ren1.SetBackground(GetRGBColor('slate_grey')) + +renWin.SetSize(400, 400) + ren1.ResetCamera() ren1.GetActiveCamera().Dolly(1.2) ren1.GetActiveCamera().Azimuth(30) ren1.GetActiveCamera().Elevation(20) ren1.ResetCameraClippingRange() + renWin.Render() iren.Initialize() -mask = "1 2 4 8 16 32" -def cases (id,__vtk__temp0=0,__vtk__temp1=0): - global mask + +def cases (id, mask): i = 0 while i < 6: - m = lindex(mask,i) - if (expr.expr(globals(), locals(),["m","&","id"]) == 0): - Scalars.SetValue(i,0) + m = mask[i] + if m & id == 0: + Scalars.SetValue(i, 0) pass else: - Scalars.SetValue(i,1) + Scalars.SetValue(i, 1) pass caseLabel.SetText("Case " + str(id) + "") - i = i + 1 + i += 1 - Grid.Modified() + grid.Modified() renWin.Render() -cases(7) -# --- end of script -- +mask = [1, 2, 4, 8, 16, 32] + +cases(7, mask) + +# iren.Start() diff --git a/Filters/General/Testing/Python/contoursToSurface.py b/Filters/General/Testing/Python/contoursToSurface.py index 811aa7a0b7d..d745e3d1e34 100755 --- a/Filters/General/Testing/Python/contoursToSurface.py +++ b/Filters/General/Testing/Python/contoursToSurface.py @@ -25,94 +25,84 @@ while z < 30: while xtraY < 90: x = -10 y = -10 - x = expr.expr(globals(), locals(),["x","+","xtraX"]) - y = expr.expr(globals(), locals(),["y","+","xtraY"]) - if (expr.expr(globals(), locals(),["z","%","12"]) == 0): + x = x + xtraX + y = y + xtraY + if z % 12 == 0: x = x + 1 - pass - if (expr.expr(globals(), locals(),["z","%","12"]) == 1): + if z % 12 == 1: x = x + 2 - pass - if (expr.expr(globals(), locals(),["z","%","12"]) == 2): + if z % 12 == 2: x = x + 3 - pass - if (expr.expr(globals(), locals(),["z","%","12"]) == 3): + if z % 12 == 3: x = x + 3 y = y + 1 - pass - if (expr.expr(globals(), locals(),["z","%","12"]) == 4): + if z % 12 == 4: x = x + 3 y = y + 2 - pass - if (expr.expr(globals(), locals(),["z","%","12"]) == 5): + if z % 12 == 5: x = x + 3 y = y + 3 - pass - if (expr.expr(globals(), locals(),["z","%","12"]) == 6): + if z % 12 == 6: x = x + 2 y = y + 3 - pass - if (expr.expr(globals(), locals(),["z","%","12"]) == 7): + if z % 12 == 7: x = x + 1 y = y + 3 - pass - if (expr.expr(globals(), locals(),["z","%","12"]) == 8): + if z % 12 == 8: y = y + 3 - pass - if (expr.expr(globals(), locals(),["z","%","12"]) == 9): + if z % 12 == 9: y = y + 2 - pass - if (expr.expr(globals(), locals(),["z","%","12"]) == 10): + if z % 12 == 10: y = y + 1 - pass - if (expr.expr(globals(), locals(),["(","xtraX","!=","30","and","xtraY","!=","30",")","or","(","xtraX","==","xtraY",")"])): + + if (xtraX != 30 and xtraY != 30) or (xtraX == xtraY): polys.InsertNextCell(4) - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","0"]),expr.expr(globals(), locals(),["y","+","0"]),z) + points.InsertPoint(i, x + 0, y + 0, z) polys.InsertCellPoint(i) - i = i + 1 - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","20"]),expr.expr(globals(), locals(),["y","+","0"]),z) + i += 1 + points.InsertPoint(i, x + 20, y + 0, z) polys.InsertCellPoint(i) - i = i + 1 - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","20"]),expr.expr(globals(), locals(),["y","+","20"]),z) + i += 1 + points.InsertPoint(i, x + 20, y + 20, z) polys.InsertCellPoint(i) - i = i + 1 - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","0"]),expr.expr(globals(), locals(),["y","+","20"]),z) + i += 1 + points.InsertPoint(i, x + 0, y + 20, z) polys.InsertCellPoint(i) - i = i + 1 + i += 1 polys.InsertNextCell(4) - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","4"]),expr.expr(globals(), locals(),["y","+","4"]),z) + points.InsertPoint(i, x + 4, y + 4, z) polys.InsertCellPoint(i) - i = i + 1 - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","16"]),expr.expr(globals(), locals(),["y","+","4"]),z) + i += 1 + points.InsertPoint(i, x + 16, y + 4, z) polys.InsertCellPoint(i) - i = i + 1 - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","16"]),expr.expr(globals(), locals(),["y","+","16"]),z) + i += 1 + points.InsertPoint(i, x + 16, y + 16, z) polys.InsertCellPoint(i) - i = i + 1 - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","4"]),expr.expr(globals(), locals(),["y","+","16"]),z) + i += 1 + points.InsertPoint(i, x + 4, y + 16, z) polys.InsertCellPoint(i) - i = i + 1 - pass - if (expr.expr(globals(), locals(),["xtraX","!=","30","or","xtraY","!=","30"])): + i += 1 + + if xtraX != 30 or xtraY != 30: polys.InsertNextCell(4) - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","8"]),expr.expr(globals(), locals(),["y","+","8"]),z) + points.InsertPoint(i, x + 8, y + 8, z) polys.InsertCellPoint(i) - i = i + 1 - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","12"]),expr.expr(globals(), locals(),["y","+","8"]),z) + i += 1 + points.InsertPoint(i, x + 12, y + 8, z) polys.InsertCellPoint(i) - i = i + 1 - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","12"]),expr.expr(globals(), locals(),["y","+","12"]),z) + i += 1 + points.InsertPoint(i, x + 12, y + 12, z) polys.InsertCellPoint(i) - i = i + 1 - points.InsertPoint(i,expr.expr(globals(), locals(),["x","+","8"]),expr.expr(globals(), locals(),["y","+","12"]),z) + i += 1 + points.InsertPoint(i, x + 8, y + 12, z) polys.InsertCellPoint(i) - i = i + 1 - pass - xtraY = xtraY + 30 + i += 1 + + xtraY += 30 - xtraX = xtraX + 30 + xtraX += 30 - z = z + 1 + z += 1 # # Create a representation of the contours used as input @@ -120,37 +110,47 @@ while z < 30: contours = vtk.vtkPolyData() contours.SetPoints(points) contours.SetPolys(polys) + contourMapper = vtk.vtkPolyDataMapper() contourMapper.SetInputData(contours) + contourActor = vtk.vtkActor() contourActor.SetMapper(contourMapper) -contourActor.GetProperty().SetColor(1,0,0) +contourActor.GetProperty().SetColor(1, 0, 0) contourActor.GetProperty().SetAmbient(1) contourActor.GetProperty().SetDiffuse(0) contourActor.GetProperty().SetRepresentationToWireframe() + ren1.AddViewProp(contourActor) ren1.ResetCamera() ren1.GetActiveCamera().Azimuth(10) ren1.GetActiveCamera().Elevation(30) ren1.ResetCameraClippingRange() -renWin.SetSize(300,300) -renWin.Render() + +renWin.SetSize(300, 300) + renWin.Render() -# prevent the tk window from showing up then start the event loop -# +# renWin.Render() + # Create the contour to surface filter # f = vtk.vtkVoxelContoursToSurfaceFilter() f.SetInputData(contours) f.SetMemoryLimitInBytes(100000) + m = vtk.vtkPolyDataMapper() m.SetInputConnection(f.GetOutputPort()) m.ScalarVisibilityOff() m.ImmediateModeRenderingOn() + a = vtk.vtkActor() a.SetMapper(m) + ren1.AddViewProp(a) + contourActor.VisibilityOff() -ren1.SetBackground(.1,.2,.4) + +ren1.SetBackground(.1, .2, .4) + renWin.Render() -# --- end of script -- +#iren.Start() diff --git a/Filters/General/Testing/Python/cursor2D.py b/Filters/General/Testing/Python/cursor2D.py index 57ea3cea646..ba769060240 100755 --- a/Filters/General/Testing/Python/cursor2D.py +++ b/Filters/General/Testing/Python/cursor2D.py @@ -1,9 +1,14 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() + # create four cursors configured differently cursor = vtk.vtkCursor2D() -cursor.SetModelBounds(15,45,15,45,0,0) -cursor.SetFocalPoint(30,30,0) +cursor.SetModelBounds(15, 45, 15, 45, 0, 0) +cursor.SetFocalPoint(30, 30, 0) cursor.AllOff() cursor.AxesOn() cursor.OutlineOn() @@ -11,10 +16,11 @@ cursorMapper = vtk.vtkPolyDataMapper2D() cursorMapper.SetInputConnection(cursor.GetOutputPort()) cursorActor = vtk.vtkActor2D() cursorActor.SetMapper(cursorMapper) -cursorActor.GetProperty().SetColor(1,0,0) +cursorActor.GetProperty().SetColor(1, 0, 0) + cursor2 = vtk.vtkCursor2D() -cursor2.SetModelBounds(75,105,15,45,0,0) -cursor2.SetFocalPoint(90,30,0) +cursor2.SetModelBounds(75, 105, 15, 45, 0, 0) +cursor2.SetFocalPoint(90, 30, 0) cursor2.AllOff() cursor2.AxesOn() cursor2.OutlineOn() @@ -23,10 +29,11 @@ cursor2Mapper = vtk.vtkPolyDataMapper2D() cursor2Mapper.SetInputConnection(cursor2.GetOutputPort()) cursor2Actor = vtk.vtkActor2D() cursor2Actor.SetMapper(cursor2Mapper) -cursor2Actor.GetProperty().SetColor(0,1,0) +cursor2Actor.GetProperty().SetColor(0, 1, 0) + cursor3 = vtk.vtkCursor2D() -cursor3.SetModelBounds(15,45,75,105,0,0) -cursor3.SetFocalPoint(30,90,0) +cursor3.SetModelBounds(15, 45, 75, 105, 0, 0) +cursor3.SetFocalPoint(30, 90, 0) cursor3.AllOff() cursor3.AxesOn() cursor3.OutlineOff() @@ -36,10 +43,11 @@ cursor3Mapper = vtk.vtkPolyDataMapper2D() cursor3Mapper.SetInputConnection(cursor3.GetOutputPort()) cursor3Actor = vtk.vtkActor2D() cursor3Actor.SetMapper(cursor3Mapper) -cursor3Actor.GetProperty().SetColor(0,1,0) +cursor3Actor.GetProperty().SetColor(0, 1, 0) + cursor4 = vtk.vtkCursor2D() -cursor4.SetModelBounds(75,105,75,105,0,0) -cursor4.SetFocalPoint(90,90,0) +cursor4.SetModelBounds(75, 105, 75, 105, 0, 0) +cursor4.SetFocalPoint(90, 90, 0) cursor4.AllOff() cursor4.AxesOn() cursor4.SetRadius(0.0) @@ -47,21 +55,25 @@ cursor4Mapper = vtk.vtkPolyDataMapper2D() cursor4Mapper.SetInputConnection(cursor4.GetOutputPort()) cursor4Actor = vtk.vtkActor2D() cursor4Actor.SetMapper(cursor4Mapper) -cursor4Actor.GetProperty().SetColor(1,0,0) +cursor4Actor.GetProperty().SetColor(1, 0, 0) + # rendering support ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # read data ren1.AddActor(cursorActor) ren1.AddActor(cursor2Actor) ren1.AddActor(cursor3Actor) ren1.AddActor(cursor4Actor) -ren1.SetBackground(0,0,0) -renWin.SetSize(120,120) +ren1.SetBackground(0, 0, 0) + +renWin.SetSize(120, 120) + renWin.Render() + iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/General/Testing/Python/edgePoints.py b/Filters/General/Testing/Python/edgePoints.py index ff46e569c4a..b56c904f2ec 100755 --- a/Filters/General/Testing/Python/edgePoints.py +++ b/Filters/General/Testing/Python/edgePoints.py @@ -4,27 +4,40 @@ 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 + # create pipeline # reader reads slices v16 = vtk.vtkVolume16Reader() -v16.SetDataDimensions(64,64) +v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() -v16.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter") -v16.SetDataSpacing(3.2,3.2,1.5) -v16.SetImageRange(30,50) +v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") +v16.SetDataSpacing(3.2, 3.2, 1.5) +v16.SetImageRange(30, 50) v16.SetDataMask(0x7fff) + # create points on edges edgePoints = vtk.vtkEdgePoints() edgePoints.SetInputConnection(v16.GetOutputPort()) edgePoints.SetValue(1150) + # mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(edgePoints.GetOutputPort()) mapper.ImmediateModeRenderingOn() mapper.ScalarVisibilityOff() + head = vtk.vtkActor() head.SetMapper(mapper) -head.GetProperty().SetColor(raw_sienna) +head.GetProperty().SetColor(GetRGBColor('raw_sienna')) + # Create the RenderWindow, Renderer and Interactor # ren1 = vtk.vtkRenderer() @@ -32,19 +45,23 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(head) -ren1.SetBackground(1,1,1) -renWin.SetSize(300,300) -ren1.SetBackground(slate_grey) -ren1.GetActiveCamera().SetPosition(99.8847,537.86,22.4716) -ren1.GetActiveCamera().SetFocalPoint(99.8847,109.81,15) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(300, 300) + +ren1.SetBackground(GetRGBColor('slate_grey')) +ren1.GetActiveCamera().SetPosition(99.8847, 537.86, 22.4716) +ren1.GetActiveCamera().SetFocalPoint(99.8847, 109.81, 15) ren1.GetActiveCamera().SetViewAngle(20) -ren1.GetActiveCamera().SetViewUp(0,-1,0) +ren1.GetActiveCamera().SetViewUp(0, -1, 0) ren1.ResetCameraClippingRange() + # render the image # renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Filters/General/Testing/Python/mcubes.py b/Filters/General/Testing/Python/mcubes.py index 6ad5da6852b..a748e2fa0b3 100755 --- a/Filters/General/Testing/Python/mcubes.py +++ b/Filters/General/Testing/Python/mcubes.py @@ -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 + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -11,45 +20,54 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create pipeline # v16 = vtk.vtkVolume16Reader() -v16.SetDataDimensions(64,64) -v16.GetOutput().SetOrigin(0.0,0.0,0.0) +v16.SetDataDimensions(64, 64) +v16.GetOutput().SetOrigin(0.0, 0.0, 0.0) v16.SetDataByteOrderToLittleEndian() -v16.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter") -v16.SetImageRange(1,93) -v16.SetDataSpacing(3.2,3.2,1.5) +v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") +v16.SetImageRange(1, 93) +v16.SetDataSpacing(3.2, 3.2, 1.5) v16.Update() + iso = vtk.vtkMarchingContourFilter() iso.SetInputConnection(v16.GetOutputPort()) -iso.SetValue(0,1125) +iso.SetValue(0, 1125) + isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(iso.GetOutputPort()) isoMapper.ScalarVisibilityOff() + isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) -isoActor.GetProperty().SetColor(antique_white) +isoActor.GetProperty().SetColor(GetRGBColor('antique_white')) + outline = vtk.vtkOutlineFilter() outline.SetInputConnection(v16.GetOutputPort()) + outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.VisibilityOff() + # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) ren1.AddActor(isoActor) -ren1.SetBackground(0.2,0.3,0.4) -renWin.SetSize(200,200) +ren1.SetBackground(0.2, 0.3, 0.4) + +renWin.SetSize(200, 200) + ren1.ResetCamera() ren1.GetActiveCamera().Elevation(90) -ren1.GetActiveCamera().SetViewUp(0,0,-1) +ren1.GetActiveCamera().SetViewUp(0, 0, -1) ren1.GetActiveCamera().Dolly(1.5) ren1.ResetCameraClippingRange() + renWin.Render() -# render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Filters/General/Testing/Python/recursiveDC.py b/Filters/General/Testing/Python/recursiveDC.py index ee039d14cc8..295c61d2287 100755 --- a/Filters/General/Testing/Python/recursiveDC.py +++ b/Filters/General/Testing/Python/recursiveDC.py @@ -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 + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -12,10 +21,11 @@ renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create pipeline # reader = vtk.vtkStructuredPointsReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/ironProt.vtk") +reader.SetFileName(VTK_DATA_ROOT + "/Data/ironProt.vtk") iso = vtk.vtkRecursiveDividingCubes() iso.SetInputConnection(reader.GetOutputPort()) iso.SetValue(128) @@ -27,29 +37,35 @@ isoMapper.ScalarVisibilityOff() isoMapper.ImmediateModeRenderingOn() isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) -isoActor.GetProperty().SetColor(bisque) +isoActor.GetProperty().SetColor(GetRGBColor('bisque')) + outline = vtk.vtkOutlineFilter() outline.SetInputConnection(reader.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) -outlineActor.GetProperty().SetColor(black) +outlineActor.GetProperty().SetColor(GetRGBColor('black')) + # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) ren1.AddActor(isoActor) -renWin.SetSize(250,250) -ren1.SetBackground(0.1,0.2,0.4) + +renWin.SetSize(250, 250) + +ren1.SetBackground(0.1, 0.2, 0.4) + +renWin.Render() + cam1 = vtk.vtkCamera() -cam1.SetClippingRange(19.1589,957.946) -cam1.SetFocalPoint(33.7014,26.706,30.5867) -cam1.SetPosition(150.841,89.374,-107.462) -cam1.SetViewUp(-0.190015,0.944614,0.267578) +cam1.SetClippingRange(19.1589, 957.946) +cam1.SetFocalPoint(33.7014, 26.706, 30.5867) +cam1.SetPosition(150.841, 89.374, -107.462) +cam1.SetViewUp(-0.190015, 0.944614, 0.267578) cam1.Dolly(3) + ren1.SetActiveCamera(cam1) + iren.Initialize() -# render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/General/Testing/Python/warplens.py b/Filters/General/Testing/Python/warplens.py index 294a6f9b42e..bd68bdd2bdf 100755 --- a/Filters/General/Testing/Python/warplens.py +++ b/Filters/General/Testing/Python/warplens.py @@ -10,16 +10,19 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # load in the texture map # pngReader = vtk.vtkPNGReader() -pngReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/camscene.png") +pngReader.SetFileName(VTK_DATA_ROOT + "/Data/camscene.png") pngReader.Update() -xWidth = lindex(pngReader.GetOutput().GetDimensions(),0) -yHeight = lindex(pngReader.GetOutput().GetDimensions(),1) + +xWidth = pngReader.GetOutput().GetDimensions()[0] +yHeight = pngReader.GetOutput().GetDimensions()[1] + wl = vtk.vtkWarpLens() wl.SetInputConnection(pngReader.GetOutputPort()) -wl.SetPrincipalPoint(2.4507,1.7733) +wl.SetPrincipalPoint(2.4507, 1.7733) wl.SetFormatWidth(4.792) wl.SetFormatHeight(3.6) wl.SetImageWidth(xWidth) @@ -28,25 +31,36 @@ wl.SetK1(0.01307) wl.SetK2(0.0003102) wl.SetP1(1.953e-005) wl.SetP2(-9.655e-005) + gf = vtk.vtkGeometryFilter() gf.SetInputConnection(wl.GetOutputPort()) + tf = vtk.vtkTriangleFilter() tf.SetInputConnection(gf.GetOutputPort()) + strip = vtk.vtkStripper() strip.SetInputConnection(tf.GetOutputPort()) strip.SetMaximumLength(250) + dsm = vtk.vtkPolyDataMapper() dsm.SetInputConnection(strip.GetOutputPort()) + planeActor = vtk.vtkActor() planeActor.SetMapper(dsm) + # Add the actors to the renderer, set the background and size ren1.AddActor(planeActor) -ren1.SetBackground(0.1,0.2,0.4) -renWin.SetSize(300,300) +ren1.SetBackground(0.1, 0.2, 0.4) + +renWin.SetSize(300, 300) + # render the image iren.Initialize() + renWin.Render() + ren1.GetActiveCamera().Zoom(1.4) + renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Filters/Geometry/Testing/Python/officeStreamPoints.py b/Filters/Geometry/Testing/Python/officeStreamPoints.py index 4181dd87eba..0fb2b0242f6 100755 --- a/Filters/Geometry/Testing/Python/officeStreamPoints.py +++ b/Filters/Geometry/Testing/Python/officeStreamPoints.py @@ -9,203 +9,218 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # read data # reader = vtk.vtkStructuredGridReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/office.binary.vtk") +reader.SetFileName(VTK_DATA_ROOT + "/Data/office.binary.vtk") reader.Update() -#force a read to occur + +# force a read to occur # to add coverage for vtkOnePieceExtentTranslator translator = vtk.vtkOnePieceExtentTranslator() -reader.GetExecutive().SetExtentTranslator(0,translator) +reader.GetExecutive().SetExtentTranslator(0, translator) + length = reader.GetOutput().GetLength() maxVelocity = reader.GetOutput().GetPointData().GetVectors().GetMaxNorm() -maxTime = expr.expr(globals(), locals(),["35.0","*","length","/","maxVelocity"]) +maxTime = 35.0 * length / maxVelocity + table1 = vtk.vtkStructuredGridGeometryFilter() table1.SetInputConnection(reader.GetOutputPort()) -table1.SetExtent(11,15,7,9,8,8) +table1.SetExtent(11, 15, 7, 9, 8, 8) mapTable1 = vtk.vtkPolyDataMapper() mapTable1.SetInputConnection(table1.GetOutputPort()) mapTable1.ScalarVisibilityOff() table1Actor = vtk.vtkActor() table1Actor.SetMapper(mapTable1) -table1Actor.GetProperty().SetColor(.59,.427,.392) +table1Actor.GetProperty().SetColor(.59, .427, .392) + table2 = vtk.vtkStructuredGridGeometryFilter() table2.SetInputConnection(reader.GetOutputPort()) -table2.SetExtent(11,15,10,12,8,8) +table2.SetExtent(11, 15, 10, 12, 8, 8) mapTable2 = vtk.vtkPolyDataMapper() mapTable2.SetInputConnection(table2.GetOutputPort()) mapTable2.ScalarVisibilityOff() table2Actor = vtk.vtkActor() table2Actor.SetMapper(mapTable2) -table2Actor.GetProperty().SetColor(.59,.427,.392) +table2Actor.GetProperty().SetColor(.59, .427, .392) + FilingCabinet1 = vtk.vtkStructuredGridGeometryFilter() FilingCabinet1.SetInputConnection(reader.GetOutputPort()) -FilingCabinet1.SetExtent(15,15,7,9,0,8) +FilingCabinet1.SetExtent(15, 15, 7, 9, 0, 8) mapFilingCabinet1 = vtk.vtkPolyDataMapper() mapFilingCabinet1.SetInputConnection(FilingCabinet1.GetOutputPort()) mapFilingCabinet1.ScalarVisibilityOff() FilingCabinet1Actor = vtk.vtkActor() FilingCabinet1Actor.SetMapper(mapFilingCabinet1) -FilingCabinet1Actor.GetProperty().SetColor(.8,.8,.6) +FilingCabinet1Actor.GetProperty().SetColor(.8, .8, .6) + FilingCabinet2 = vtk.vtkStructuredGridGeometryFilter() FilingCabinet2.SetInputConnection(reader.GetOutputPort()) -FilingCabinet2.SetExtent(15,15,10,12,0,8) +FilingCabinet2.SetExtent(15, 15, 10, 12, 0, 8) mapFilingCabinet2 = vtk.vtkPolyDataMapper() mapFilingCabinet2.SetInputConnection(FilingCabinet2.GetOutputPort()) mapFilingCabinet2.ScalarVisibilityOff() FilingCabinet2Actor = vtk.vtkActor() FilingCabinet2Actor.SetMapper(mapFilingCabinet2) -FilingCabinet2Actor.GetProperty().SetColor(.8,.8,.6) +FilingCabinet2Actor.GetProperty().SetColor(.8, .8, .6) + bookshelf1Top = vtk.vtkStructuredGridGeometryFilter() bookshelf1Top.SetInputConnection(reader.GetOutputPort()) -bookshelf1Top.SetExtent(13,13,0,4,0,11) +bookshelf1Top.SetExtent(13, 13, 0, 4, 0, 11) mapBookshelf1Top = vtk.vtkPolyDataMapper() mapBookshelf1Top.SetInputConnection(bookshelf1Top.GetOutputPort()) mapBookshelf1Top.ScalarVisibilityOff() bookshelf1TopActor = vtk.vtkActor() bookshelf1TopActor.SetMapper(mapBookshelf1Top) -bookshelf1TopActor.GetProperty().SetColor(.8,.8,.6) +bookshelf1TopActor.GetProperty().SetColor(.8, .8, .6) bookshelf1Bottom = vtk.vtkStructuredGridGeometryFilter() bookshelf1Bottom.SetInputConnection(reader.GetOutputPort()) -bookshelf1Bottom.SetExtent(20,20,0,4,0,11) +bookshelf1Bottom.SetExtent(20, 20, 0, 4, 0, 11) mapBookshelf1Bottom = vtk.vtkPolyDataMapper() mapBookshelf1Bottom.SetInputConnection(bookshelf1Bottom.GetOutputPort()) mapBookshelf1Bottom.ScalarVisibilityOff() bookshelf1BottomActor = vtk.vtkActor() bookshelf1BottomActor.SetMapper(mapBookshelf1Bottom) -bookshelf1BottomActor.GetProperty().SetColor(.8,.8,.6) +bookshelf1BottomActor.GetProperty().SetColor(.8, .8, .6) bookshelf1Front = vtk.vtkStructuredGridGeometryFilter() bookshelf1Front.SetInputConnection(reader.GetOutputPort()) -bookshelf1Front.SetExtent(13,20,0,0,0,11) +bookshelf1Front.SetExtent(13, 20, 0, 0, 0, 11) mapBookshelf1Front = vtk.vtkPolyDataMapper() mapBookshelf1Front.SetInputConnection(bookshelf1Front.GetOutputPort()) mapBookshelf1Front.ScalarVisibilityOff() bookshelf1FrontActor = vtk.vtkActor() bookshelf1FrontActor.SetMapper(mapBookshelf1Front) -bookshelf1FrontActor.GetProperty().SetColor(.8,.8,.6) +bookshelf1FrontActor.GetProperty().SetColor(.8, .8, .6) bookshelf1Back = vtk.vtkStructuredGridGeometryFilter() bookshelf1Back.SetInputConnection(reader.GetOutputPort()) -bookshelf1Back.SetExtent(13,20,4,4,0,11) +bookshelf1Back.SetExtent(13, 20, 4, 4, 0, 11) mapBookshelf1Back = vtk.vtkPolyDataMapper() mapBookshelf1Back.SetInputConnection(bookshelf1Back.GetOutputPort()) mapBookshelf1Back.ScalarVisibilityOff() bookshelf1BackActor = vtk.vtkActor() bookshelf1BackActor.SetMapper(mapBookshelf1Back) -bookshelf1BackActor.GetProperty().SetColor(.8,.8,.6) +bookshelf1BackActor.GetProperty().SetColor(.8, .8, .6) bookshelf1LHS = vtk.vtkStructuredGridGeometryFilter() bookshelf1LHS.SetInputConnection(reader.GetOutputPort()) -bookshelf1LHS.SetExtent(13,20,0,4,0,0) +bookshelf1LHS.SetExtent(13, 20, 0, 4, 0, 0) mapBookshelf1LHS = vtk.vtkPolyDataMapper() mapBookshelf1LHS.SetInputConnection(bookshelf1LHS.GetOutputPort()) mapBookshelf1LHS.ScalarVisibilityOff() bookshelf1LHSActor = vtk.vtkActor() bookshelf1LHSActor.SetMapper(mapBookshelf1LHS) -bookshelf1LHSActor.GetProperty().SetColor(.8,.8,.6) +bookshelf1LHSActor.GetProperty().SetColor(.8, .8, .6) bookshelf1RHS = vtk.vtkStructuredGridGeometryFilter() bookshelf1RHS.SetInputConnection(reader.GetOutputPort()) -bookshelf1RHS.SetExtent(13,20,0,4,11,11) +bookshelf1RHS.SetExtent(13, 20, 0, 4, 11, 11) mapBookshelf1RHS = vtk.vtkPolyDataMapper() mapBookshelf1RHS.SetInputConnection(bookshelf1RHS.GetOutputPort()) mapBookshelf1RHS.ScalarVisibilityOff() bookshelf1RHSActor = vtk.vtkActor() bookshelf1RHSActor.SetMapper(mapBookshelf1RHS) -bookshelf1RHSActor.GetProperty().SetColor(.8,.8,.6) +bookshelf1RHSActor.GetProperty().SetColor(.8, .8, .6) + bookshelf2Top = vtk.vtkStructuredGridGeometryFilter() bookshelf2Top.SetInputConnection(reader.GetOutputPort()) -bookshelf2Top.SetExtent(13,13,15,19,0,11) +bookshelf2Top.SetExtent(13, 13, 15, 19, 0, 11) mapBookshelf2Top = vtk.vtkPolyDataMapper() mapBookshelf2Top.SetInputConnection(bookshelf2Top.GetOutputPort()) mapBookshelf2Top.ScalarVisibilityOff() bookshelf2TopActor = vtk.vtkActor() bookshelf2TopActor.SetMapper(mapBookshelf2Top) -bookshelf2TopActor.GetProperty().SetColor(.8,.8,.6) +bookshelf2TopActor.GetProperty().SetColor(.8, .8, .6) bookshelf2Bottom = vtk.vtkStructuredGridGeometryFilter() bookshelf2Bottom.SetInputConnection(reader.GetOutputPort()) -bookshelf2Bottom.SetExtent(20,20,15,19,0,11) +bookshelf2Bottom.SetExtent(20, 20, 15, 19, 0, 11) mapBookshelf2Bottom = vtk.vtkPolyDataMapper() mapBookshelf2Bottom.SetInputConnection(bookshelf2Bottom.GetOutputPort()) mapBookshelf2Bottom.ScalarVisibilityOff() bookshelf2BottomActor = vtk.vtkActor() bookshelf2BottomActor.SetMapper(mapBookshelf2Bottom) -bookshelf2BottomActor.GetProperty().SetColor(.8,.8,.6) +bookshelf2BottomActor.GetProperty().SetColor(.8, .8, .6) bookshelf2Front = vtk.vtkStructuredGridGeometryFilter() bookshelf2Front.SetInputConnection(reader.GetOutputPort()) -bookshelf2Front.SetExtent(13,20,15,15,0,11) +bookshelf2Front.SetExtent(13, 20, 15, 15, 0, 11) mapBookshelf2Front = vtk.vtkPolyDataMapper() mapBookshelf2Front.SetInputConnection(bookshelf2Front.GetOutputPort()) mapBookshelf2Front.ScalarVisibilityOff() bookshelf2FrontActor = vtk.vtkActor() bookshelf2FrontActor.SetMapper(mapBookshelf2Front) -bookshelf2FrontActor.GetProperty().SetColor(.8,.8,.6) +bookshelf2FrontActor.GetProperty().SetColor(.8, .8, .6) bookshelf2Back = vtk.vtkStructuredGridGeometryFilter() bookshelf2Back.SetInputConnection(reader.GetOutputPort()) -bookshelf2Back.SetExtent(13,20,19,19,0,11) +bookshelf2Back.SetExtent(13, 20, 19, 19, 0, 11) mapBookshelf2Back = vtk.vtkPolyDataMapper() mapBookshelf2Back.SetInputConnection(bookshelf2Back.GetOutputPort()) mapBookshelf2Back.ScalarVisibilityOff() bookshelf2BackActor = vtk.vtkActor() bookshelf2BackActor.SetMapper(mapBookshelf2Back) -bookshelf2BackActor.GetProperty().SetColor(.8,.8,.6) +bookshelf2BackActor.GetProperty().SetColor(.8, .8, .6) bookshelf2LHS = vtk.vtkStructuredGridGeometryFilter() bookshelf2LHS.SetInputConnection(reader.GetOutputPort()) -bookshelf2LHS.SetExtent(13,20,15,19,0,0) +bookshelf2LHS.SetExtent(13, 20, 15, 19, 0, 0) mapBookshelf2LHS = vtk.vtkPolyDataMapper() mapBookshelf2LHS.SetInputConnection(bookshelf2LHS.GetOutputPort()) mapBookshelf2LHS.ScalarVisibilityOff() bookshelf2LHSActor = vtk.vtkActor() bookshelf2LHSActor.SetMapper(mapBookshelf2LHS) -bookshelf2LHSActor.GetProperty().SetColor(.8,.8,.6) +bookshelf2LHSActor.GetProperty().SetColor(.8, .8, .6) bookshelf2RHS = vtk.vtkStructuredGridGeometryFilter() bookshelf2RHS.SetInputConnection(reader.GetOutputPort()) -bookshelf2RHS.SetExtent(13,20,15,19,11,11) +bookshelf2RHS.SetExtent(13, 20, 15, 19, 11, 11) mapBookshelf2RHS = vtk.vtkPolyDataMapper() mapBookshelf2RHS.SetInputConnection(bookshelf2RHS.GetOutputPort()) mapBookshelf2RHS.ScalarVisibilityOff() bookshelf2RHSActor = vtk.vtkActor() bookshelf2RHSActor.SetMapper(mapBookshelf2RHS) -bookshelf2RHSActor.GetProperty().SetColor(.8,.8,.6) +bookshelf2RHSActor.GetProperty().SetColor(.8, .8, .6) + window = vtk.vtkStructuredGridGeometryFilter() window.SetInputConnection(reader.GetOutputPort()) -window.SetExtent(20,20,6,13,10,13) +window.SetExtent(20, 20, 6, 13, 10, 13) mapWindow = vtk.vtkPolyDataMapper() mapWindow.SetInputConnection(window.GetOutputPort()) mapWindow.ScalarVisibilityOff() windowActor = vtk.vtkActor() windowActor.SetMapper(mapWindow) -windowActor.GetProperty().SetColor(.3,.3,.5) +windowActor.GetProperty().SetColor(.3, .3, .5) + outlet = vtk.vtkStructuredGridGeometryFilter() outlet.SetInputConnection(reader.GetOutputPort()) -outlet.SetExtent(0,0,9,10,14,16) +outlet.SetExtent(0, 0, 9, 10, 14, 16) mapOutlet = vtk.vtkPolyDataMapper() mapOutlet.SetInputConnection(outlet.GetOutputPort()) mapOutlet.ScalarVisibilityOff() outletActor = vtk.vtkActor() outletActor.SetMapper(mapOutlet) -outletActor.GetProperty().SetColor(0,0,0) +outletActor.GetProperty().SetColor(0, 0, 0) + inlet = vtk.vtkStructuredGridGeometryFilter() inlet.SetInputConnection(reader.GetOutputPort()) -inlet.SetExtent(0,0,9,10,0,6) +inlet.SetExtent(0, 0, 9, 10, 0, 6) mapInlet = vtk.vtkPolyDataMapper() mapInlet.SetInputConnection(inlet.GetOutputPort()) mapInlet.ScalarVisibilityOff() inletActor = vtk.vtkActor() inletActor.SetMapper(mapInlet) -inletActor.GetProperty().SetColor(0,0,0) +inletActor.GetProperty().SetColor(0, 0, 0) + outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputConnection(reader.GetOutputPort()) mapOutline = vtk.vtkPolyDataMapper() mapOutline.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(mapOutline) -outlineActor.GetProperty().SetColor(0,0,0) +outlineActor.GetProperty().SetColor(0, 0, 0) + # Create source for streamtubes streamer = vtk.vtkStreamPoints() streamer.SetInputConnection(reader.GetOutputPort()) -streamer.SetStartPosition(0.1,2.1,0.5) +streamer.SetStartPosition(0.1, 2.1, 0.5) streamer.SetMaximumPropagationTime(500) streamer.SetTimeIncrement(0.5) streamer.SetIntegrationDirectionToForward() + cone = vtk.vtkConeSource() cone.SetResolution(8) cones = vtk.vtkGlyph3D() @@ -213,11 +228,14 @@ cones.SetInputConnection(streamer.GetOutputPort()) cones.SetSourceConnection(cone.GetOutputPort()) cones.SetScaleFactor(0.5) cones.SetScaleModeToScaleByVector() + mapCones = vtk.vtkPolyDataMapper() mapCones.SetInputConnection(cones.GetOutputPort()) mapCones.SetScalarRange(reader.GetOutput().GetScalarRange()) + conesActor = vtk.vtkActor() conesActor.SetMapper(mapCones) + ren1.AddActor(table1Actor) ren1.AddActor(table2Actor) ren1.AddActor(FilingCabinet1Actor) @@ -239,15 +257,19 @@ ren1.AddActor(outletActor) ren1.AddActor(inletActor) ren1.AddActor(outlineActor) ren1.AddActor(conesActor) -ren1.SetBackground(0.4,0.4,0.5) + +ren1.SetBackground(0.4, 0.4, 0.5) + aCamera = vtk.vtkCamera() -aCamera.SetClippingRange(0.7724,39) -aCamera.SetFocalPoint(1.14798,3.08416,2.47187) -aCamera.SetPosition(-2.64683,-3.55525,3.55848) -aCamera.SetViewUp(0.0511273,0.132773,0.989827) +aCamera.SetClippingRange(0.7724, 39) +aCamera.SetFocalPoint(1.14798, 3.08416, 2.47187) +aCamera.SetPosition(-2.64683, -3.55525, 3.55848) +aCamera.SetViewUp(0.0511273, 0.132773, 0.989827) aCamera.SetViewAngle(15.5033) + ren1.SetActiveCamera(aCamera) -renWin.SetSize(500,300) + +renWin.SetSize(500, 300) + iren.Initialize() -# interact with data -# --- end of script -- +#iren.Start() diff --git a/Filters/Geometry/Testing/Python/rectGrid.py b/Filters/Geometry/Testing/Python/rectGrid.py index f2562306baf..566893370b4 100755 --- a/Filters/Geometry/Testing/Python/rectGrid.py +++ b/Filters/Geometry/Testing/Python/rectGrid.py @@ -4,40 +4,54 @@ 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 + VTK_VARY_RADIUS_BY_VECTOR = 2 + # create pipeline # reader = vtk.vtkDataSetReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/RectGrid2.vtk") +reader.SetFileName(VTK_DATA_ROOT + "/Data/RectGrid2.vtk") reader.Update() + toRectilinearGrid = vtk.vtkCastToConcrete() toRectilinearGrid.SetInputConnection(reader.GetOutputPort()) toRectilinearGrid.Update() plane = vtk.vtkRectilinearGridGeometryFilter() plane.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) -plane.SetExtent(0,100,0,100,15,15) +plane.SetExtent(0, 100, 0, 100, 15, 15) warper = vtk.vtkWarpVector() warper.SetInputConnection(plane.GetOutputPort()) warper.SetScaleFactor(0.05) planeMapper = vtk.vtkDataSetMapper() planeMapper.SetInputConnection(warper.GetOutputPort()) -planeMapper.SetScalarRange(0.197813,0.710419) +planeMapper.SetScalarRange(0.197813, 0.710419) planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) + cutPlane = vtk.vtkPlane() cutPlane.SetOrigin(reader.GetOutput().GetCenter()) -cutPlane.SetNormal(1,0,0) +cutPlane.SetNormal(1, 0, 0) planeCut = vtk.vtkCutter() planeCut.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) planeCut.SetCutFunction(cutPlane) cutMapper = vtk.vtkDataSetMapper() cutMapper.SetInputConnection(planeCut.GetOutputPort()) -cutMapper.SetScalarRange(reader.GetOutput().GetPointData().GetScalars().GetRange()) +cutMapper.SetScalarRange( + reader.GetOutput().GetPointData().GetScalars().GetRange()) cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) + iso = vtk.vtkContourFilter() iso.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) -iso.SetValue(0,0.7) +iso.SetValue(0, 0.7) normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(iso.GetOutputPort()) normals.SetFeatureAngle(45) @@ -46,15 +60,17 @@ isoMapper.SetInputConnection(normals.GetOutputPort()) isoMapper.ScalarVisibilityOff() isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) -isoActor.GetProperty().SetColor(bisque) +isoActor.GetProperty().SetColor(GetRGBColor('bisque')) isoActor.GetProperty().SetRepresentationToWireframe() + streamer = vtk.vtkStreamLine() streamer.SetInputConnection(reader.GetOutputPort()) -streamer.SetStartPosition(-1.2,-0.1,1.3) +streamer.SetStartPosition(-1.2, -0.1, 1.3) streamer.SetMaximumPropagationTime(500) streamer.SetStepLength(0.05) streamer.SetIntegrationStepLength(0.05) streamer.SetIntegrationDirectionToIntegrateBothDirections() + streamTube = vtk.vtkTubeFilter() streamTube.SetInputConnection(streamer.GetOutputPort()) streamTube.SetRadius(0.025) @@ -62,17 +78,20 @@ streamTube.SetNumberOfSides(6) streamTube.SetVaryRadius(VTK_VARY_RADIUS_BY_VECTOR) mapStreamTube = vtk.vtkPolyDataMapper() mapStreamTube.SetInputConnection(streamTube.GetOutputPort()) -mapStreamTube.SetScalarRange(reader.GetOutput().GetPointData().GetScalars().GetRange()) +mapStreamTube.SetScalarRange( + reader.GetOutput().GetPointData().GetScalars().GetRange()) streamTubeActor = vtk.vtkActor() streamTubeActor.SetMapper(mapStreamTube) streamTubeActor.GetProperty().BackfaceCullingOn() + outline = vtk.vtkOutlineFilter() outline.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) -outlineActor.GetProperty().SetColor(black) +outlineActor.GetProperty().SetColor(GetRGBColor('black')) + # Graphics stuff # Create the RenderWindow, Renderer and both Actors # @@ -82,6 +101,7 @@ renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) @@ -89,15 +109,15 @@ ren1.AddActor(planeActor) ren1.AddActor(cutActor) ren1.AddActor(isoActor) ren1.AddActor(streamTubeActor) -ren1.SetBackground(1,1,1) -renWin.SetSize(400,400) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(400, 400) + cam1 = ren1.GetActiveCamera() -cam1.SetClippingRange(3.76213,10.712) -cam1.SetFocalPoint(-0.0842503,-0.136905,0.610234) -cam1.SetPosition(2.53813,2.2678,-5.22172) -cam1.SetViewUp(-0.241047,0.930635,0.275343) +cam1.SetClippingRange(3.76213, 10.712) +cam1.SetFocalPoint(-0.0842503, -0.136905, 0.610234) +cam1.SetPosition(2.53813, 2.2678, -5.22172) +cam1.SetViewUp(-0.241047, 0.930635, 0.275343) + iren.Initialize() -# render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Hybrid/Testing/Python/3DMorph.py b/Filters/Hybrid/Testing/Python/3DMorph.py index b2408426f18..169e26026c8 100755 --- a/Filters/Hybrid/Testing/Python/3DMorph.py +++ b/Filters/Hybrid/Testing/Python/3DMorph.py @@ -4,45 +4,56 @@ 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 + # use implicit modeller / interpolation to perform 3D morphing # -# make the letter v +# make the letter v, t and k letterV = vtk.vtkVectorText() letterV.SetText("v") -# read the geometry file containing the letter t letterT = vtk.vtkVectorText() letterT.SetText("t") -# read the geometry file containing the letter k letterK = vtk.vtkVectorText() letterK.SetText("k") + # create implicit models of each blobbyV = vtk.vtkImplicitModeller() blobbyV.SetInputConnection(letterV.GetOutputPort()) blobbyV.SetMaximumDistance(.2) -blobbyV.SetSampleDimensions(50,50,12) -blobbyV.SetModelBounds(-0.5,1.5,-0.5,1.5,-0.5,0.5) -# create implicit models of each +blobbyV.SetSampleDimensions(50, 50, 12) +blobbyV.SetModelBounds(-0.5, 1.5, -0.5, 1.5, -0.5, 0.5) + blobbyT = vtk.vtkImplicitModeller() blobbyT.SetInputConnection(letterT.GetOutputPort()) blobbyT.SetMaximumDistance(.2) -blobbyT.SetSampleDimensions(50,50,12) -blobbyT.SetModelBounds(-0.5,1.5,-0.5,1.5,-0.5,0.5) -# create implicit models of each +blobbyT.SetSampleDimensions(50, 50, 12) +blobbyT.SetModelBounds(-0.5, 1.5, -0.5, 1.5, -0.5, 0.5) + blobbyK = vtk.vtkImplicitModeller() blobbyK.SetInputConnection(letterK.GetOutputPort()) blobbyK.SetMaximumDistance(.2) -blobbyK.SetSampleDimensions(50,50,12) -blobbyK.SetModelBounds(-0.5,1.5,-0.5,1.5,-0.5,0.5) +blobbyK.SetSampleDimensions(50, 50, 12) +blobbyK.SetModelBounds(-0.5, 1.5, -0.5, 1.5, -0.5, 0.5) + # Interpolate the data interpolate = vtk.vtkInterpolateDataSetAttributes() interpolate.AddInputConnection(blobbyV.GetOutputPort()) interpolate.AddInputConnection(blobbyT.GetOutputPort()) interpolate.AddInputConnection(blobbyK.GetOutputPort()) interpolate.SetT(0.0) + # extract an iso surface blobbyIso = vtk.vtkContourFilter() blobbyIso.SetInputConnection(interpolate.GetOutputPort()) -blobbyIso.SetValue(0,0.1) +blobbyIso.SetValue(0, 0.1) + # map to rendering primitives blobbyMapper = vtk.vtkPolyDataMapper() blobbyMapper.SetInputConnection(blobbyIso.GetOutputPort()) @@ -50,7 +61,8 @@ blobbyMapper.ScalarVisibilityOff() # now an actor blobby = vtk.vtkActor() blobby.SetMapper(blobbyMapper) -blobby.GetProperty().SetDiffuseColor(banana) +blobby.GetProperty().SetDiffuseColor(GetRGBColor('banana')) + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -58,30 +70,35 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + camera = vtk.vtkCamera() -camera.SetClippingRange(0.265,13.2) -camera.SetFocalPoint(0.539,0.47464,0) -camera.SetPosition(0.539,0.474674,2.644) -camera.SetViewUp(0,1,0) +camera.SetClippingRange(0.265, 13.2) +camera.SetFocalPoint(0.539, 0.47464, 0) +camera.SetPosition(0.539, 0.474674, 2.644) +camera.SetViewUp(0, 1, 0) + ren1.SetActiveCamera(camera) + # now make a renderer and tell it about lights and actors -renWin.SetSize(300,350) + +renWin.SetSize(300, 350) + ren1.AddActor(blobby) -ren1.SetBackground(1,1,1) +ren1.SetBackground(1, 1, 1) renWin.Render() + subIters = 4.0 i = 0 while i < 2: j = 1 while j <= subIters: - t = expr.expr(globals(), locals(),["i","+","j","/","subIters"]) + t = i + j / subIters interpolate.SetT(t) renWin.Render() - j = j + 1 + j += 1 + i += 1 - i = i + 1 renWin.Render() -# render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +iren.Initialize() +#iren.Start() diff --git a/Filters/Hybrid/Testing/Python/TestGreedyTerrainDecimation.py b/Filters/Hybrid/Testing/Python/TestGreedyTerrainDecimation.py index 3aaf38129b8..d424da9d1c0 100755 --- a/Filters/Hybrid/Testing/Python/TestGreedyTerrainDecimation.py +++ b/Filters/Hybrid/Testing/Python/TestGreedyTerrainDecimation.py @@ -5,38 +5,45 @@ from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() lut = vtk.vtkLookupTable() -lut.SetHueRange(0.6,0) -lut.SetSaturationRange(1.0,0) -lut.SetValueRange(0.5,1.0) +lut.SetHueRange(0.6, 0) +lut.SetSaturationRange(1.0, 0) +lut.SetValueRange(0.5, 1.0) + # Read the data: a height field results demReader = vtk.vtkDEMReader() -demReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/SainteHelens.dem") +demReader.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem") demReader.Update() -lo = lindex(demReader.GetOutput().GetScalarRange(),0) -hi = lindex(demReader.GetOutput().GetScalarRange(),1) + +lo = demReader.GetOutput().GetScalarRange()[0] +hi = demReader.GetOutput().GetScalarRange()[1] + # Decimate the terrain deci = vtk.vtkGreedyTerrainDecimation() deci.SetInputConnection(demReader.GetOutputPort()) deci.BoundaryVertexDeletionOn() -# deci SetErrorMeasureToSpecifiedReduction -# deci SetReduction 0.95 +# deci.SetErrorMeasureToSpecifiedReduction() +# deci.SetReduction(0.95) deci.SetErrorMeasureToNumberOfTriangles() deci.SetNumberOfTriangles(5000) -# deci SetErrorMeasureToAbsoluteError -# deci SetAbsoluteError 25.0 -# deci SetErrorMeasureToRelativeError -# deci SetAbsoluteError 0.01 +# deci.SetErrorMeasureToAbsoluteError() +# deci.SetAbsoluteError(25.0) +# deci.SetErrorMeasureToRelativeError() +# deci.SetAbsoluteError(0.01) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(deci.GetOutputPort()) normals.SetFeatureAngle(60) normals.ConsistencyOn() normals.SplittingOff() + demMapper = vtk.vtkPolyDataMapper() demMapper.SetInputConnection(normals.GetOutputPort()) -demMapper.SetScalarRange(lo,hi) +demMapper.SetScalarRange(lo, hi) demMapper.SetLookupTable(lut) + actor = vtk.vtkLODActor() actor.SetMapper(demMapper) + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -44,16 +51,22 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(actor) -ren1.SetBackground(.1,.2,.4) + +ren1.SetBackground(.1, .2, .4) iren.SetDesiredUpdateRate(5) -ren1.GetActiveCamera().SetViewUp(0,0,1) -ren1.GetActiveCamera().SetPosition(-99900,-21354,131801) -ren1.GetActiveCamera().SetFocalPoint(41461,41461,2815) + +ren1.GetActiveCamera().SetViewUp(0, 0, 1) +ren1.GetActiveCamera().SetPosition(-99900, -21354, 131801) +ren1.GetActiveCamera().SetFocalPoint(41461, 41461, 2815) ren1.ResetCamera() ren1.GetActiveCamera().Dolly(1.2) ren1.ResetCameraClippingRange() + renWin.Render() -# --- end of script -- + +iren.Initialize() +#iren.Start() diff --git a/Filters/Hybrid/Testing/Python/TestProcrustes.py b/Filters/Hybrid/Testing/Python/TestProcrustes.py index 3b76ea6b72a..7ed5babb72b 100755 --- a/Filters/Hybrid/Testing/Python/TestProcrustes.py +++ b/Filters/Hybrid/Testing/Python/TestProcrustes.py @@ -5,91 +5,116 @@ from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() sphere = vtk.vtkSphereSource() + # make two copies of the shape and distort them a little transform1 = vtk.vtkTransform() -transform1.Translate(0.2,0.1,0.3) -transform1.Scale(1.3,1.1,0.8) +transform1.Translate(0.2, 0.1, 0.3) +transform1.Scale(1.3, 1.1, 0.8) + transform2 = vtk.vtkTransform() -transform2.Translate(0.3,0.7,0.1) -transform2.Scale(1.0,0.1,1.8) +transform2.Translate(0.3, 0.7, 0.1) +transform2.Scale(1.0, 0.1, 1.8) + transformer1 = vtk.vtkTransformPolyDataFilter() transformer1.SetInputConnection(sphere.GetOutputPort()) transformer1.SetTransform(transform1) + transformer2 = vtk.vtkTransformPolyDataFilter() transformer2.SetInputConnection(sphere.GetOutputPort()) transformer2.SetTransform(transform2) + # map these three shapes into the first renderer map1a = vtk.vtkPolyDataMapper() map1a.SetInputConnection(sphere.GetOutputPort()) Actor1a = vtk.vtkActor() Actor1a.SetMapper(map1a) -Actor1a.GetProperty().SetDiffuseColor(1.0000,0.3882,0.2784) +Actor1a.GetProperty().SetDiffuseColor(1.0000, 0.3882, 0.2784) map1b = vtk.vtkPolyDataMapper() map1b.SetInputConnection(transformer1.GetOutputPort()) Actor1b = vtk.vtkActor() Actor1b.SetMapper(map1b) -Actor1b.GetProperty().SetDiffuseColor(0.3882,1.0000,0.2784) +Actor1b.GetProperty().SetDiffuseColor(0.3882, 1.0000, 0.2784) map1c = vtk.vtkPolyDataMapper() map1c.SetInputConnection(transformer2.GetOutputPort()) Actor1c = vtk.vtkActor() Actor1c.SetMapper(map1c) -Actor1c.GetProperty().SetDiffuseColor(0.3882,0.2784,1.0000) -# -- align the shapes using Procrustes (using SetModeToRigidBody) -- +Actor1c.GetProperty().SetDiffuseColor(0.3882, 0.2784, 1.0000) + +# align the shapes using Procrustes (using SetModeToRigidBody) group = vtk.vtkMultiBlockDataGroupFilter() group.AddInputConnection(sphere.GetOutputPort()) group.AddInputConnection(transformer1.GetOutputPort()) group.AddInputConnection(transformer2.GetOutputPort()) + procrustes1 = vtk.vtkProcrustesAlignmentFilter() procrustes1.SetInputConnection(group.GetOutputPort()) procrustes1.GetLandmarkTransform().SetModeToRigidBody() procrustes1.Update() + # map the aligned shapes into the second renderer map2a = vtk.vtkPolyDataMapper() map2a.SetInputData(procrustes1.GetOutput().GetBlock(0)) + Actor2a = vtk.vtkActor() Actor2a.SetMapper(map2a) -Actor2a.GetProperty().SetDiffuseColor(1.0000,0.3882,0.2784) +Actor2a.GetProperty().SetDiffuseColor(1.0000, 0.3882, 0.2784) + map2b = vtk.vtkPolyDataMapper() map2b.SetInputData(procrustes1.GetOutput().GetBlock(1)) + Actor2b = vtk.vtkActor() Actor2b.SetMapper(map2b) -Actor2b.GetProperty().SetDiffuseColor(0.3882,1.0000,0.2784) +Actor2b.GetProperty().SetDiffuseColor(0.3882, 1.0000, 0.2784) + map2c = vtk.vtkPolyDataMapper() map2c.SetInputData(procrustes1.GetOutput().GetBlock(2)) + Actor2c = vtk.vtkActor() Actor2c.SetMapper(map2c) -Actor2c.GetProperty().SetDiffuseColor(0.3882,0.2784,1.0000) -# -- align the shapes using Procrustes (using SetModeToSimilarity (default)) -- +Actor2c.GetProperty().SetDiffuseColor(0.3882, 0.2784, 1.0000) + +# align the shapes using Procrustes (using SetModeToSimilarity (default)) procrustes2 = vtk.vtkProcrustesAlignmentFilter() procrustes2.SetInputConnection(group.GetOutputPort()) procrustes2.Update() + # map the aligned shapes into the third renderer map3a = vtk.vtkPolyDataMapper() map3a.SetInputData(procrustes2.GetOutput().GetBlock(0)) + Actor3a = vtk.vtkActor() Actor3a.SetMapper(map3a) -Actor3a.GetProperty().SetDiffuseColor(1.0000,0.3882,0.2784) +Actor3a.GetProperty().SetDiffuseColor(1.0000, 0.3882, 0.2784) + map3b = vtk.vtkPolyDataMapper() map3b.SetInputData(procrustes2.GetOutput().GetBlock(1)) + Actor3b = vtk.vtkActor() Actor3b.SetMapper(map3b) -Actor3b.GetProperty().SetDiffuseColor(0.3882,1.0000,0.2784) +Actor3b.GetProperty().SetDiffuseColor(0.3882, 1.0000, 0.2784) + map3c = vtk.vtkPolyDataMapper() map3c.SetInputData(procrustes2.GetOutput().GetBlock(2)) + Actor3c = vtk.vtkActor() Actor3c.SetMapper(map3c) -Actor3c.GetProperty().SetDiffuseColor(0.3882,0.2784,1.0000) +Actor3c.GetProperty().SetDiffuseColor(0.3882, 0.2784, 1.0000) + # Create the RenderWindow and its three Renderers ren1 = vtk.vtkRenderer() ren2 = vtk.vtkRenderer() ren3 = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) renWin.AddRenderer(ren2) renWin.AddRenderer(ren3) -renWin.SetSize(300,100) + +renWin.SetSize(300, 100) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer ren1.AddActor(Actor1a) ren1.AddActor(Actor1b) @@ -100,23 +125,30 @@ ren2.AddActor(Actor2c) ren3.AddActor(Actor3a) ren3.AddActor(Actor3b) ren3.AddActor(Actor3c) + # set the properties of the renderers -ren1.SetBackground(1,1,1) -ren1.SetViewport(0.0,0.0,0.33,1.0) +ren1.SetBackground(1, 1, 1) +ren1.SetViewport(0.0, 0.0, 0.33, 1.0) ren1.ResetCamera() -ren1.GetActiveCamera().SetPosition(1,-1,0) + +ren1.GetActiveCamera().SetPosition(1, -1, 0) ren1.ResetCamera() -ren2.SetBackground(1,1,1) -ren2.SetViewport(0.33,0.0,0.66,1.0) + +ren2.SetBackground(1, 1, 1) +ren2.SetViewport(0.33, 0.0, 0.66, 1.0) ren2.ResetCamera() -ren2.GetActiveCamera().SetPosition(1,-1,0) + +ren2.GetActiveCamera().SetPosition(1, -1, 0) ren2.ResetCamera() -ren3.SetBackground(1,1,1) -ren3.SetViewport(0.66,0.0,1.0,1.0) + +ren3.SetBackground(1, 1, 1) +ren3.SetViewport(0.66, 0.0, 1.0, 1.0) ren3.ResetCamera() -ren3.GetActiveCamera().SetPosition(1,-1,0) + +ren3.GetActiveCamera().SetPosition(1, -1, 0) ren3.ResetCamera() + renWin.Render() -catch.catch(globals(),"""iren.AddObserver(UserEvent) - {wm.deiconify(.vtkInteract)""") -# --- end of script -- + +iren.Initialize() +#iren.Start() diff --git a/Filters/Hybrid/Testing/Python/TestProcrustesRigidCentroid.py b/Filters/Hybrid/Testing/Python/TestProcrustesRigidCentroid.py index 1649d2274f7..cc948f51cb4 100755 --- a/Filters/Hybrid/Testing/Python/TestProcrustesRigidCentroid.py +++ b/Filters/Hybrid/Testing/Python/TestProcrustesRigidCentroid.py @@ -1,92 +1,126 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() sphere = vtk.vtkSphereSource() + # make two copies of the shape and distort them a little transform1 = vtk.vtkTransform() -transform1.Translate(0.2,0.1,0.3) -transform1.Scale(1.3,1.1,0.8) +transform1.Translate(0.2, 0.1, 0.3) +transform1.Scale(1.3, 1.1, 0.8) + transform2 = vtk.vtkTransform() -transform2.Translate(0.3,0.7,0.1) -transform2.Scale(1.0,0.1,1.8) +transform2.Translate(0.3, 0.7, 0.1) +transform2.Scale(1.0, 0.1, 1.8) + transformer1 = vtk.vtkTransformPolyDataFilter() transformer1.SetInputConnection(sphere.GetOutputPort()) transformer1.SetTransform(transform1) + transformer2 = vtk.vtkTransformPolyDataFilter() transformer2.SetInputConnection(sphere.GetOutputPort()) transformer2.SetTransform(transform2) + # map these three shapes into the first renderer map1a = vtk.vtkPolyDataMapper() map1a.SetInputConnection(sphere.GetOutputPort()) + Actor1a = vtk.vtkActor() Actor1a.SetMapper(map1a) -Actor1a.GetProperty().SetDiffuseColor(1.0000,0.3882,0.2784) +Actor1a.GetProperty().SetDiffuseColor(1.0000, 0.3882, 0.2784) + map1b = vtk.vtkPolyDataMapper() map1b.SetInputConnection(transformer1.GetOutputPort()) + Actor1b = vtk.vtkActor() Actor1b.SetMapper(map1b) -Actor1b.GetProperty().SetDiffuseColor(0.3882,1.0000,0.2784) +Actor1b.GetProperty().SetDiffuseColor(0.3882, 1.0000, 0.2784) + map1c = vtk.vtkPolyDataMapper() map1c.SetInputConnection(transformer2.GetOutputPort()) + Actor1c = vtk.vtkActor() Actor1c.SetMapper(map1c) -Actor1c.GetProperty().SetDiffuseColor(0.3882,0.2784,1.0000) +Actor1c.GetProperty().SetDiffuseColor(0.3882, 0.2784, 1.0000) + group = vtk.vtkMultiBlockDataGroupFilter() group.AddInputConnection(sphere.GetOutputPort()) group.AddInputConnection(transformer1.GetOutputPort()) group.AddInputConnection(transformer2.GetOutputPort()) -# -- align the shapes using Procrustes (using SetModeToRigidBody) -- + +# align the shapes using Procrustes (using SetModeToRigidBody) procrustes1 = vtk.vtkProcrustesAlignmentFilter() procrustes1.SetInputConnection(group.GetOutputPort()) procrustes1.GetLandmarkTransform().SetModeToRigidBody() procrustes1.StartFromCentroidOn() procrustes1.Update() + # map the aligned shapes into the second renderer map2a = vtk.vtkPolyDataMapper() map2a.SetInputData(procrustes1.GetOutput().GetBlock(0)) + Actor2a = vtk.vtkActor() Actor2a.SetMapper(map2a) -Actor2a.GetProperty().SetDiffuseColor(1.0000,0.3882,0.2784) +Actor2a.GetProperty().SetDiffuseColor(1.0000, 0.3882, 0.2784) + map2b = vtk.vtkPolyDataMapper() map2b.SetInputData(procrustes1.GetOutput().GetBlock(1)) + Actor2b = vtk.vtkActor() Actor2b.SetMapper(map2b) -Actor2b.GetProperty().SetDiffuseColor(0.3882,1.0000,0.2784) +Actor2b.GetProperty().SetDiffuseColor(0.3882, 1.0000, 0.2784) + map2c = vtk.vtkPolyDataMapper() map2c.SetInputData(procrustes1.GetOutput().GetBlock(2)) + Actor2c = vtk.vtkActor() Actor2c.SetMapper(map2c) -Actor2c.GetProperty().SetDiffuseColor(0.3882,0.2784,1.0000) -# -- align the shapes using Procrustes (using SetModeToSimilarity (default)) -- +Actor2c.GetProperty().SetDiffuseColor(0.3882, 0.2784, 1.0000) + +# align the shapes using Procrustes (using SetModeToSimilarity (default)) procrustes2 = vtk.vtkProcrustesAlignmentFilter() procrustes2.SetInputConnection(group.GetOutputPort()) procrustes2.Update() + # map the aligned shapes into the third renderer map3a = vtk.vtkPolyDataMapper() map3a.SetInputData(procrustes2.GetOutput().GetBlock(0)) + Actor3a = vtk.vtkActor() Actor3a.SetMapper(map3a) -Actor3a.GetProperty().SetDiffuseColor(1.0000,0.3882,0.2784) +Actor3a.GetProperty().SetDiffuseColor(1.0000, 0.3882, 0.2784) + map3b = vtk.vtkPolyDataMapper() map3b.SetInputData(procrustes2.GetOutput().GetBlock(1)) + Actor3b = vtk.vtkActor() Actor3b.SetMapper(map3b) -Actor3b.GetProperty().SetDiffuseColor(0.3882,1.0000,0.2784) +Actor3b.GetProperty().SetDiffuseColor(0.3882, 1.0000, 0.2784) + map3c = vtk.vtkPolyDataMapper() map3c.SetInputData(procrustes2.GetOutput().GetBlock(2)) + Actor3c = vtk.vtkActor() Actor3c.SetMapper(map3c) -Actor3c.GetProperty().SetDiffuseColor(0.3882,0.2784,1.0000) +Actor3c.GetProperty().SetDiffuseColor(0.3882, 0.2784, 1.0000) + # Create the RenderWindow and its three Renderers ren1 = vtk.vtkRenderer() ren2 = vtk.vtkRenderer() ren3 = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) renWin.AddRenderer(ren2) renWin.AddRenderer(ren3) -renWin.SetSize(300,100) + +renWin.SetSize(300, 100) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer ren1.AddActor(Actor1a) ren1.AddActor(Actor1b) @@ -97,27 +131,31 @@ ren2.AddActor(Actor2c) ren3.AddActor(Actor3a) ren3.AddActor(Actor3b) ren3.AddActor(Actor3c) + # set the properties of the renderers -ren1.SetBackground(1,1,1) -ren1.SetViewport(0.0,0.0,0.33,1.0) +ren1.SetBackground(1, 1, 1) +ren1.SetViewport(0.0, 0.0, 0.33, 1.0) ren1.ResetCamera() -ren1.GetActiveCamera().SetPosition(1,-1,0) +ren1.GetActiveCamera().SetPosition(1, -1, 0) ren1.ResetCamera() -ren2.SetBackground(1,1,1) -ren2.SetViewport(0.33,0.0,0.66,1.0) -#ren2 ResetCamera -#[ren2 GetActiveCamera] SetPosition 1 -1 0 -#ren2 ResetCamera +ren2.SetBackground(1, 1, 1) +ren2.SetViewport(0.33, 0.0, 0.66, 1.0) + +# ren2.ResetCamera() +# ren2.GetActiveCamera().SetPosition(1. -1, 0) +# ren2.ResetCamera() ren2.SetActiveCamera(ren1.GetActiveCamera()) -ren3.SetBackground(1,1,1) -ren3.SetViewport(0.66,0.0,1.0,1.0) + +ren3.SetBackground(1, 1, 1) +ren3.SetViewport(0.66, 0.0, 1.0, 1.0) ren3.ResetCamera() -ren3.GetActiveCamera().SetPosition(1,-1,0) +ren3.GetActiveCamera().SetPosition(1, -1, 0) ren3.ResetCamera() + renWin.Render() print Actor1b.GetCenter() print Actor2b.GetCenter() print Actor3b.GetCenter() -catch.catch(globals(),"""iren.AddObserver(UserEvent) - {wm.deiconify(.vtkInteract)""") -# --- end of script -- + +iren.Initialize() +#iren.Start() diff --git a/Filters/Hybrid/Testing/Python/TestProjectedTerrainPath.py b/Filters/Hybrid/Testing/Python/TestProjectedTerrainPath.py index c1ccc266abb..a182092b55a 100755 --- a/Filters/Hybrid/Testing/Python/TestProjectedTerrainPath.py +++ b/Filters/Hybrid/Testing/Python/TestProjectedTerrainPath.py @@ -5,42 +5,51 @@ from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() lut = vtk.vtkLookupTable() -lut.SetHueRange(0.6,0) -lut.SetSaturationRange(1.0,0) -lut.SetValueRange(0.5,1.0) +lut.SetHueRange(0.6, 0) +lut.SetSaturationRange(1.0, 0) +lut.SetValueRange(0.5, 1.0) + # Read the data: a height field results demReader = vtk.vtkDEMReader() -demReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/SainteHelens.dem") +demReader.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem") demReader.Update() -lo = lindex(demReader.GetOutput().GetScalarRange(),0) -hi = lindex(demReader.GetOutput().GetScalarRange(),1) + +lo = demReader.GetOutput().GetScalarRange()[0] +hi = demReader.GetOutput().GetScalarRange()[1] + surface = vtk.vtkImageDataGeometryFilter() surface.SetInputConnection(demReader.GetOutputPort()) + warp = vtk.vtkWarpScalar() warp.SetInputConnection(surface.GetOutputPort()) warp.SetScaleFactor(1) warp.UseNormalOn() -warp.SetNormal(0,0,1) +warp.SetNormal(0, 0, 1) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(warp.GetOutputPort()) normals.SetFeatureAngle(60) normals.SplittingOff() + demMapper = vtk.vtkPolyDataMapper() demMapper.SetInputConnection(normals.GetOutputPort()) -demMapper.SetScalarRange(lo,hi) +demMapper.SetScalarRange(lo, hi) demMapper.SetLookupTable(lut) + demActor = vtk.vtkLODActor() demActor.SetMapper(demMapper) + # Create some paths pts = vtk.vtkPoints() -pts.InsertNextPoint(562669,5.1198e+006,1992.77) -pts.InsertNextPoint(562801,5.11618e+006,2534.97) -pts.InsertNextPoint(562913,5.11157e+006,1911.1) -pts.InsertNextPoint(559849,5.11083e+006,1681.34) -pts.InsertNextPoint(562471,5.11633e+006,2593.57) -pts.InsertNextPoint(563223,5.11616e+006,2598.31) -pts.InsertNextPoint(566579,5.11127e+006,1697.83) -pts.InsertNextPoint(569000,5.11127e+006,1697.83) +pts.InsertNextPoint(562669, 5.1198e+006, 1992.77) +pts.InsertNextPoint(562801, 5.11618e+006, 2534.97) +pts.InsertNextPoint(562913, 5.11157e+006, 1911.1) +pts.InsertNextPoint(559849, 5.11083e+006, 1681.34) +pts.InsertNextPoint(562471, 5.11633e+006, 2593.57) +pts.InsertNextPoint(563223, 5.11616e+006, 2598.31) +pts.InsertNextPoint(566579, 5.11127e+006, 1697.83) +pts.InsertNextPoint(569000, 5.11127e+006, 1697.83) + lines = vtk.vtkCellArray() lines.InsertNextCell(3) lines.InsertCellPoint(0) @@ -52,9 +61,11 @@ lines.InsertCellPoint(4) lines.InsertCellPoint(5) lines.InsertCellPoint(6) lines.InsertCellPoint(7) + terrainPaths = vtk.vtkPolyData() terrainPaths.SetPoints(pts) terrainPaths.SetLines(lines) + projectedPaths = vtk.vtkProjectedTerrainPath() projectedPaths.SetInputData(terrainPaths) projectedPaths.SetSourceConnection(demReader.GetOutputPort()) @@ -62,11 +73,14 @@ projectedPaths.SetHeightOffset(25) projectedPaths.SetHeightTolerance(5) projectedPaths.SetProjectionModeToNonOccluded() projectedPaths.SetProjectionModeToHug() + pathMapper = vtk.vtkPolyDataMapper() pathMapper.SetInputConnection(projectedPaths.GetOutputPort()) + paths = vtk.vtkActor() paths.SetMapper(pathMapper) -paths.GetProperty().SetColor(1,0,0) +paths.GetProperty().SetColor(1, 0, 0) + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -74,17 +88,24 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(demActor) ren1.AddActor(paths) -ren1.SetBackground(.1,.2,.4) +ren1.SetBackground(.1, .2, .4) + iren.SetDesiredUpdateRate(5) -ren1.GetActiveCamera().SetViewUp(0,0,1) -ren1.GetActiveCamera().SetPosition(-99900,-21354,131801) -ren1.GetActiveCamera().SetFocalPoint(41461,41461,2815) + +ren1.GetActiveCamera().SetViewUp(0, 0, 1) +ren1.GetActiveCamera().SetPosition(-99900, -21354, 131801) +ren1.GetActiveCamera().SetFocalPoint(41461, 41461, 2815) ren1.ResetCamera() + ren1.GetActiveCamera().Dolly(1.2) ren1.ResetCameraClippingRange() + renWin.Render() -# --- end of script -- + +iren.Initialize() +#iren.Start() diff --git a/Filters/Hybrid/Testing/Python/banana.py b/Filters/Hybrid/Testing/Python/banana.py index 8de91901625..81164a3fdb4 100755 --- a/Filters/Hybrid/Testing/Python/banana.py +++ b/Filters/Hybrid/Testing/Python/banana.py @@ -10,63 +10,72 @@ sphere.SetPhiResolution(40) sphere.SetThetaResolution(40) sphere.Update() sphereData = sphere.GetOutput() + # create a data array to hold the weighting coefficients tfarray = vtk.vtkFloatArray() npoints = sphereData.GetNumberOfPoints() tfarray.SetNumberOfComponents(2) tfarray.SetNumberOfTuples(npoints) + # parameterize the sphere along the z axis, and fill the weights # with (1.0-a, a) to linearly interpolate across the shape i = 0 while i < npoints: pt = sphereData.GetPoint(i) - x = lindex(pt,0) - y = lindex(pt,1) - z = lindex(pt,2) - #foreach {x y z} $pt {} - # -0.5 < z < 0.5 - zn = expr.expr(globals(), locals(),["z","+","0.5"]) - zn1 = expr.expr(globals(), locals(),["1.0","-","zn"]) + x = pt[0] + y = pt[1] + z = pt[2] + zn = z + 0.5 + zn1 = 1.0 - zn if (zn > 1.0): zn = 1.0 - pass if (zn1 < 0.0): zn1 = 0.0 - pass - tfarray.SetComponent(i,0,zn1) - tfarray.SetComponent(i,1,zn) - i = i + 1 + tfarray.SetComponent(i, 0, zn1) + tfarray.SetComponent(i, 1, zn) + i += 1 # create field data to hold the array, and bind it to the sphere fd = vtk.vtkFieldData() tfarray.SetName("weights") sphereData.GetPointData().AddArray(tfarray) + # use an ordinary transform to stretch the shape stretch = vtk.vtkTransform() -stretch.Scale(1,1,3.2) +stretch.Scale(1, 1, 3.2) + stretchFilter = vtk.vtkTransformFilter() stretchFilter.SetInputData(sphereData) stretchFilter.SetTransform(stretch) + # now, for the weighted transform stuff weightedTrans = vtk.vtkWeightedTransformFilter() + # create two transforms to interpolate between identity = vtk.vtkTransform() identity.Identity() + rotated = vtk.vtkTransform() rotatedAngle = 45 rotated.RotateX(rotatedAngle) + weightedTrans.SetNumberOfTransforms(2) -weightedTrans.SetTransform(identity,0) -weightedTrans.SetTransform(rotated,1) +weightedTrans.SetTransform(identity, 0) +weightedTrans.SetTransform(rotated, 1) + # which data array should the filter use ? weightedTrans.SetWeightArray("weights") + weightedTrans.SetInputConnection(stretchFilter.GetOutputPort()) + weightedTransMapper = vtk.vtkPolyDataMapper() weightedTransMapper.SetInputConnection(weightedTrans.GetOutputPort()) + weightedTransActor = vtk.vtkActor() weightedTransActor.SetMapper(weightedTransMapper) -weightedTransActor.GetProperty().SetDiffuseColor(0.8,0.8,0.1) +weightedTransActor.GetProperty().SetDiffuseColor(0.8, 0.8, 0.1) weightedTransActor.GetProperty().SetRepresentationToSurface() + # create simple poly data so we can apply glyph # # Create the rendering stuff @@ -76,20 +85,26 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + ren1.AddActor(weightedTransActor) -ren1.SetBackground(0.1,0.2,0.5) -renWin.SetSize(300,300) +ren1.SetBackground(0.1, 0.2, 0.5) + +renWin.SetSize(300, 300) + ren1.ResetCamera() ren1.GetActiveCamera().Azimuth(90) ren1.GetActiveCamera().Dolly(1) + # Get handles to some useful objects # renWin.Render() -# prevent the tk window from showing up then start the event loop -def cmd (s,__vtk__temp0=0,__vtk__temp1=0): + +def cmd (s): rotated.Identity() rotated.RotateX(s) renWin.Render() cmd(rotatedAngle) -# --- end of script -- + +iren.Initialize() +#iren.Start() diff --git a/Filters/Hybrid/Testing/Python/largeImageOffset.py b/Filters/Hybrid/Testing/Python/largeImageOffset.py index ba48f0d1af5..ee98599a802 100755 --- a/Filters/Hybrid/Testing/Python/largeImageOffset.py +++ b/Filters/Hybrid/Testing/Python/largeImageOffset.py @@ -7,49 +7,59 @@ VTK_DATA_ROOT = vtkGetDataRoot() ren1 = vtk.vtkRenderer() renWin1 = vtk.vtkRenderWindow() renWin1.AddRenderer(ren1) + importer = vtk.vtk3DSImporter() importer.SetRenderWindow(renWin1) importer.ComputeNormalsOn() -importer.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/iflamigm.3ds") +importer.SetFileName(VTK_DATA_ROOT + "/Data/iflamigm.3ds") importer.Read() -importer.GetRenderer().SetBackground(0.1,0.2,0.4) -importer.GetRenderWindow().SetSize(150,150) + +importer.GetRenderer().SetBackground(0.1, 0.2, 0.4) +importer.GetRenderWindow().SetSize(150, 150) + # # the importer created the renderer renCollection = renWin1.GetRenderers() renCollection.InitTraversal() + ren = renCollection.GetNextItem() + # # change view up to +z # -ren.GetActiveCamera().SetWindowCenter(-0.2,0.3) -ren.GetActiveCamera().SetPosition(0,1,0) -ren.GetActiveCamera().SetFocalPoint(0,0,0) -ren.GetActiveCamera().SetViewUp(0,0,1) +ren.GetActiveCamera().SetWindowCenter(-0.2, 0.3) +ren.GetActiveCamera().SetPosition(0, 1, 0) +ren.GetActiveCamera().SetFocalPoint(0, 0, 0) +ren.GetActiveCamera().SetViewUp(0, 0, 1) + # # let the renderer compute good position and focal point # ren.ResetCamera() ren.GetActiveCamera().Dolly(1.4) ren1.ResetCameraClippingRange() + # render the large image # renderLarge = vtk.vtkRenderLargeImage() renderLarge.SetInput(ren1) renderLarge.SetMagnification(3) renderLarge.Update() + viewer = vtk.vtkImageViewer() viewer.SetInputConnection(renderLarge.GetOutputPort()) viewer.SetColorWindow(255) viewer.SetColorLevel(127.5) viewer.Render() + # on several opengl X window unix implementations # multiple context deletes cause errors -# so we leak the renWin1 in this test for unix -if (tcl_platform("platform") == "unix"): +# so we leak the renWin in this test for unix +if renWin1.IsA('vtkXOpenGLRenderWindow'): renWin1.Register(ren1) dl = vtk.vtkDebugLeaks() dl.SetExitError(0) del dl - pass -# --- end of script -- + +# iren.Initialize() +# iren.Start() diff --git a/Filters/Hybrid/Testing/Python/largeImageParallel.py b/Filters/Hybrid/Testing/Python/largeImageParallel.py index 97cab04ee2d..69ddd75e9fa 100755 --- a/Filters/Hybrid/Testing/Python/largeImageParallel.py +++ b/Filters/Hybrid/Testing/Python/largeImageParallel.py @@ -7,49 +7,59 @@ VTK_DATA_ROOT = vtkGetDataRoot() ren1 = vtk.vtkRenderer() renWin1 = vtk.vtkRenderWindow() renWin1.AddRenderer(ren1) + importer = vtk.vtk3DSImporter() importer.SetRenderWindow(renWin1) importer.ComputeNormalsOn() -importer.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/iflamigm.3ds") +importer.SetFileName(VTK_DATA_ROOT + "/Data/iflamigm.3ds") importer.Read() -importer.GetRenderer().SetBackground(0.1,0.2,0.4) -importer.GetRenderWindow().SetSize(150,150) + +importer.GetRenderer().SetBackground(0.1, 0.2, 0.4) +importer.GetRenderWindow().SetSize(150, 150) + # # the importer created the renderer renCollection = renWin1.GetRenderers() renCollection.InitTraversal() + ren = renCollection.GetNextItem() + # # change view up to +z # ren.GetActiveCamera().ParallelProjectionOn() -ren.GetActiveCamera().SetPosition(0,1,0) -ren.GetActiveCamera().SetFocalPoint(0,0,0) -ren.GetActiveCamera().SetViewUp(0,0,1) +ren.GetActiveCamera().SetPosition(0, 1, 0) +ren.GetActiveCamera().SetFocalPoint(0, 0, 0) +ren.GetActiveCamera().SetViewUp(0, 0, 1) + # # let the renderer compute good position and focal point # ren.ResetCamera() ren.GetActiveCamera().Zoom(1.4) ren1.ResetCameraClippingRange() + # render the large image # renderLarge = vtk.vtkRenderLargeImage() renderLarge.SetInput(ren1) renderLarge.SetMagnification(3) renderLarge.Update() + viewer = vtk.vtkImageViewer() viewer.SetInputConnection(renderLarge.GetOutputPort()) viewer.SetColorWindow(255) viewer.SetColorLevel(127.5) viewer.Render() + # on several opengl X window unix implementations # multiple context deletes cause errors # so we leak the renWin1 in this test for unix -if (tcl_platform("platform") == "unix"): +if renWin1.IsA('vtkXOpenGLRenderWindow'): renWin1.Register(ren1) dl = vtk.vtkDebugLeaks() dl.SetExitError(0) del dl - pass -# --- end of script -- + +# iren.Initialize() +# iren.Start() diff --git a/Filters/Modeling/Testing/Python/Hyper.py b/Filters/Modeling/Testing/Python/Hyper.py index 7f43ecd763a..4172341c140 100755 --- a/Filters/Modeling/Testing/Python/Hyper.py +++ b/Filters/Modeling/Testing/Python/Hyper.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot @@ -12,41 +13,54 @@ renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + VTK_INTEGRATE_BOTH_DIRECTIONS = 2 + # # generate tensors ptLoad = vtk.vtkPointLoad() ptLoad.SetLoadValue(100.0) -ptLoad.SetSampleDimensions(20,20,20) +ptLoad.SetSampleDimensions(20, 20, 20) ptLoad.ComputeEffectiveStressOn() -ptLoad.SetModelBounds(-10,10,-10,10,-10,10) +ptLoad.SetModelBounds(-10, 10, -10, 10, -10, 10) + # -# If the current directory is writable, then test the witers +# If the current directory is writable, then test the writers # -if (catch.catch(globals(),"""channel = open("test.tmp", "w")""") == 0): +try: + channel = open("wSP.vtk", "wb") channel.close() - file.delete("-force", "test.tmp") + wSP = vtk.vtkDataSetWriter() wSP.SetInputConnection(ptLoad.GetOutputPort()) wSP.SetFileName("wSP.vtk") wSP.SetTensorsName("pointload") wSP.SetScalarsName("effective_stress") wSP.Write() + rSP = vtk.vtkDataSetReader() rSP.SetFileName("wSP.vtk") rSP.SetTensorsName("pointload") rSP.SetScalarsName("effective_stress") rSP.Update() + input = rSP.GetOutput() - file.delete("-force", "wSP.vtk") - pass -else: + + # cleanup + # + try: + os.remove("wSP.vtk") + except OSError: + pass + +except IOError: + print "Unable to test the writer/reader." input = ptLoad.GetOutput() - pass + # Generate hyperstreamlines s1 = vtk.vtkHyperStreamline() s1.SetInputData(input) -s1.SetStartPosition(9,9,-9) +s1.SetStartPosition(9, 9, -9) s1.IntegrateMinorEigenvector() s1.SetMaximumPropagationDistance(18.0) s1.SetIntegrationStepLength(0.1) @@ -55,20 +69,24 @@ s1.SetRadius(0.25) s1.SetNumberOfSides(18) s1.SetIntegrationDirection(VTK_INTEGRATE_BOTH_DIRECTIONS) s1.Update() + # Map hyperstreamlines lut = vtk.vtkLogLookupTable() -lut.SetHueRange(.6667,0.0) +lut.SetHueRange(.6667, 0.0) + s1Mapper = vtk.vtkPolyDataMapper() s1Mapper.SetInputConnection(s1.GetOutputPort()) s1Mapper.SetLookupTable(lut) +# force update for scalar range ptLoad.Update() -#force update for scalar range s1Mapper.SetScalarRange(ptLoad.GetOutput().GetScalarRange()) + s1Actor = vtk.vtkActor() s1Actor.SetMapper(s1Mapper) + s2 = vtk.vtkHyperStreamline() s2.SetInputData(input) -s2.SetStartPosition(-9,-9,-9) +s2.SetStartPosition(-9, -9, -9) s2.IntegrateMinorEigenvector() s2.SetMaximumPropagationDistance(18.0) s2.SetIntegrationStepLength(0.1) @@ -77,15 +95,18 @@ s2.SetRadius(0.25) s2.SetNumberOfSides(18) s2.SetIntegrationDirection(VTK_INTEGRATE_BOTH_DIRECTIONS) s2.Update() + s2Mapper = vtk.vtkPolyDataMapper() s2Mapper.SetInputConnection(s2.GetOutputPort()) s2Mapper.SetLookupTable(lut) s2Mapper.SetScalarRange(input.GetScalarRange()) + s2Actor = vtk.vtkActor() s2Actor.SetMapper(s2Mapper) + s3 = vtk.vtkHyperStreamline() s3.SetInputData(input) -s3.SetStartPosition(9,-9,-9) +s3.SetStartPosition(9, -9, -9) s3.IntegrateMinorEigenvector() s3.SetMaximumPropagationDistance(18.0) s3.SetIntegrationStepLength(0.1) @@ -94,15 +115,18 @@ s3.SetRadius(0.25) s3.SetNumberOfSides(18) s3.SetIntegrationDirection(VTK_INTEGRATE_BOTH_DIRECTIONS) s3.Update() + s3Mapper = vtk.vtkPolyDataMapper() s3Mapper.SetInputConnection(s3.GetOutputPort()) s3Mapper.SetLookupTable(lut) s3Mapper.SetScalarRange(input.GetScalarRange()) + s3Actor = vtk.vtkActor() s3Actor.SetMapper(s3Mapper) + s4 = vtk.vtkHyperStreamline() s4.SetInputData(input) -s4.SetStartPosition(-9,9,-9) +s4.SetStartPosition(-9, 9, -9) s4.IntegrateMinorEigenvector() s4.SetMaximumPropagationDistance(18.0) s4.SetIntegrationStepLength(0.1) @@ -111,51 +135,64 @@ s4.SetRadius(0.25) s4.SetNumberOfSides(18) s4.SetIntegrationDirection(VTK_INTEGRATE_BOTH_DIRECTIONS) s4.Update() + s4Mapper = vtk.vtkPolyDataMapper() s4Mapper.SetInputConnection(s4.GetOutputPort()) s4Mapper.SetLookupTable(lut) s4Mapper.SetScalarRange(input.GetScalarRange()) + s4Actor = vtk.vtkActor() s4Actor.SetMapper(s4Mapper) + # plane for context # g = vtk.vtkImageDataGeometryFilter() g.SetInputData(input) -g.SetExtent(0,100,0,100,0,0) +g.SetExtent(0, 100, 0, 100, 0, 0) g.Update() -#for scalar range + +# for scalar range gm = vtk.vtkPolyDataMapper() gm.SetInputConnection(g.GetOutputPort()) gm.SetScalarRange(g.GetOutput().GetScalarRange()) + ga = vtk.vtkActor() ga.SetMapper(gm) + # Create outline around data # outline = vtk.vtkOutlineFilter() outline.SetInputData(input) + outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) -outlineActor.GetProperty().SetColor(0,0,0) +outlineActor.GetProperty().SetColor(0, 0, 0) + # Create cone indicating application of load # coneSrc = vtk.vtkConeSource() coneSrc.SetRadius(.5) coneSrc.SetHeight(2) + coneMap = vtk.vtkPolyDataMapper() coneMap.SetInputConnection(coneSrc.GetOutputPort()) + coneActor = vtk.vtkActor() coneActor.SetMapper(coneMap) -coneActor.SetPosition(0,0,11) +coneActor.SetPosition(0, 0, 11) coneActor.RotateY(90) -coneActor.GetProperty().SetColor(1,0,0) +coneActor.GetProperty().SetColor(1, 0, 0) + camera = vtk.vtkCamera() -camera.SetFocalPoint(0.113766,-1.13665,-1.01919) -camera.SetPosition(-29.4886,-63.1488,26.5807) +camera.SetFocalPoint(0.113766, -1.13665, -1.01919) +camera.SetPosition(-29.4886, -63.1488, 26.5807) camera.SetViewAngle(24.4617) -camera.SetViewUp(0.17138,0.331163,0.927879) -camera.SetClippingRange(1,100) +camera.SetViewUp(0.17138, 0.331163, 0.927879) +camera.SetClippingRange(1, 100) + ren1.AddActor(s1Actor) ren1.AddActor(s2Actor) ren1.AddActor(s3Actor) @@ -163,9 +200,13 @@ ren1.AddActor(s4Actor) ren1.AddActor(outlineActor) ren1.AddActor(coneActor) ren1.AddActor(ga) -ren1.SetBackground(1.0,1.0,1.0) + +ren1.SetBackground(1.0, 1.0, 1.0) ren1.SetActiveCamera(camera) -renWin.SetSize(300,300) + +renWin.SetSize(300, 300) + renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +iren.Initialize() +#iren.Start() diff --git a/Filters/Modeling/Testing/Python/TestFillHolesFilter.py b/Filters/Modeling/Testing/Python/TestFillHolesFilter.py index da8f72a10c1..6c10ded8049 100755 --- a/Filters/Modeling/Testing/Python/TestFillHolesFilter.py +++ b/Filters/Modeling/Testing/Python/TestFillHolesFilter.py @@ -1,4 +1,8 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Create the RenderWindow, Renderer and both Actors # @@ -7,6 +11,7 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Create some data, remove some polygons pd = vtk.vtkPolyData() pts = vtk.vtkPoints() @@ -15,53 +20,59 @@ pd.SetPoints(pts) pd.SetPolys(polys) xRes = 10 yRes = 10 -xPtsRes = expr.expr(globals(), locals(),["xRes","+","1"]) -yPtsRes = expr.expr(globals(), locals(),["yRes","+","1"]) -#insert points +xPtsRes = xRes + 1 +yPtsRes = yRes + 1 + +# insert points j = 0 while j < yPtsRes: i = 0 while i < xPtsRes: - pts.InsertNextPoint(i,j,0.0) - i = i + 1 - - j = j + 1 + pts.InsertNextPoint(i, j, 0.0) + i += 1 + j += 1 -#insert cells +# insert cells j = 1 while j <= yRes: i = 1 while i <= xRes: - cellId = expr.expr(globals(), locals(),["i","-1","+","yRes","*(","j","-1",")"]) - if (cellId != 48 and cellId != 12 and cellId != 13 and cellId != 23 and cellId != 60 and cellId != 83 and cellId != 72 and cellId != 76 and cellId != 77 and cellId != 78 and cellId != 87): + cellId = i - 1 + yRes * (j - 1) + if (cellId != 48 and cellId != 12 and cellId != 13 + and cellId != 23 and cellId != 60 and cellId != 83 + and cellId != 72 and cellId != 76 and cellId != 77 + and cellId != 78 and cellId != 87): polys.InsertNextCell(4) - polys.InsertCellPoint(expr.expr(globals(), locals(),["i","-","1","+","((","j","-1",")*","yPtsRes",")"])) - polys.InsertCellPoint(expr.expr(globals(), locals(),["i","+","((","j","-1",")*","yPtsRes",")"])) - polys.InsertCellPoint(expr.expr(globals(), locals(),["i","+","(","j","*","yPtsRes",")"])) - polys.InsertCellPoint(expr.expr(globals(), locals(),["i","-","1","+","(","j","*","yPtsRes",")"])) + polys.InsertCellPoint(i - 1 + ((j - 1) * yPtsRes)) + polys.InsertCellPoint(i + ((j - 1) * yPtsRes)) + polys.InsertCellPoint(i + (j * yPtsRes)) + polys.InsertCellPoint(i - 1 + (j * yPtsRes)) pass - i = i + 1 - - j = j + 1 + i += 1 + j += 1 # Fill the holes fill = vtk.vtkFillHolesFilter() fill.SetInputData(pd) fill.SetHoleSize(20.0) + # Mapping and actor map = vtk.vtkPolyDataMapper() # map SetInput pd map.SetInputConnection(fill.GetOutputPort()) + actor = vtk.vtkActor() actor.SetMapper(map) -actor.GetProperty().SetColor(1,0,0) +actor.GetProperty().SetColor(1, 0, 0) + # Add the actors to the renderer, set the background and size # ren1.AddActor(actor) -ren1.SetBackground(1,1,1) -renWin.SetSize(300,300) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(300, 300) + # render the image # iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Modeling/Testing/Python/TestImageMarchingCubes.py b/Filters/Modeling/Testing/Python/TestImageMarchingCubes.py index 3208015035c..051b5fd30a1 100755 --- a/Filters/Modeling/Testing/Python/TestImageMarchingCubes.py +++ b/Filters/Modeling/Testing/Python/TestImageMarchingCubes.py @@ -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 + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -11,47 +20,59 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create pipeline # v16 = vtk.vtkVolume16Reader() -v16.SetDataDimensions(64,64) -v16.GetOutput().SetOrigin(0.0,0.0,0.0) +v16.SetDataDimensions(64, 64) +v16.GetOutput().SetOrigin(0.0, 0.0, 0.0) v16.SetDataByteOrderToLittleEndian() -v16.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter") -v16.SetImageRange(1,93) -v16.SetDataSpacing(3.2,3.2,1.5) +v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") +v16.SetImageRange(1, 93) +v16.SetDataSpacing(3.2, 3.2, 1.5) v16.Update() + iso = vtk.vtkImageMarchingCubes() iso.SetInputConnection(v16.GetOutputPort()) -iso.SetValue(0,1150) +iso.SetValue(0, 1150) iso.SetInputMemoryLimit(1000) + isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(iso.GetOutputPort()) isoMapper.ScalarVisibilityOff() isoMapper.ImmediateModeRenderingOn() + isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) -isoActor.GetProperty().SetColor(antique_white) +isoActor.GetProperty().SetColor(GetRGBColor('antique_white')) + outline = vtk.vtkOutlineFilter() outline.SetInputConnection(v16.GetOutputPort()) + outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.VisibilityOff() + # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) ren1.AddActor(isoActor) -ren1.SetBackground(0.2,0.3,0.4) -renWin.SetSize(200,200) +ren1.SetBackground(0.2, 0.3, 0.4) + +renWin.SetSize(200, 200) + ren1.ResetCamera() ren1.GetActiveCamera().Elevation(90) -ren1.GetActiveCamera().SetViewUp(0,0,-1) +ren1.GetActiveCamera().SetViewUp(0, 0, -1) ren1.GetActiveCamera().Azimuth(180) ren1.ResetCameraClippingRange() + renWin.Render() + # render the image # -# prevent the tk window from showing up then start the event loop -# --- end of script -- +iren.Initialize() +#iren.Start() diff --git a/Filters/Modeling/Testing/Python/TestSpherePuzzleArrows.py b/Filters/Modeling/Testing/Python/TestSpherePuzzleArrows.py index 4bc75c2dcf5..1643e4c633b 100755 --- a/Filters/Modeling/Testing/Python/TestSpherePuzzleArrows.py +++ b/Filters/Modeling/Testing/Python/TestSpherePuzzleArrows.py @@ -4,71 +4,85 @@ from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() -# prevent the tk window from showing up then start the event loop -renWin = vtk.vtkRenderWindow() # create a rendering window and renderer ren1 = vtk.vtkRenderer() +renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) -renWin.SetSize(400,400) +iren = vtk.vtkRenderWindowInteractor() +iren.SetRenderWindow(renWin) + +renWin.SetSize(400, 400) + puzzle = vtk.vtkSpherePuzzle() + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(puzzle.GetOutputPort()) + actor = vtk.vtkActor() actor.SetMapper(mapper) + arrows = vtk.vtkSpherePuzzleArrows() + mapper2 = vtk.vtkPolyDataMapper() mapper2.SetInputConnection(arrows.GetOutputPort()) + actor2 = vtk.vtkActor() actor2.SetMapper(mapper2) + # Add the actors to the renderer, set the background and size # ren1.AddActor(actor) ren1.AddActor(actor2) -ren1.SetBackground(0.1,0.2,0.4) +ren1.SetBackground(0.1, 0.2, 0.4) LastVal = -1 -def MotionCallback (x,y,__vtk__temp0=0,__vtk__temp1=0): + +def MotionCallback (x, y): global LastVal - # Compute display point from Tk display point. WindowY = 400 - y = expr.expr(globals(), locals(),["WindowY","-","y"]) - z = ren1.GetZ(x,y) - ren1.SetDisplayPoint(x,y,z) + y = WindowY - y + z = ren1.GetZ(x, y) + ren1.SetDisplayPoint(x, y, z) ren1.DisplayToWorld() pt = ren1.GetWorldPoint() - #tk_messageBox -message "$pt" - x = lindex(pt,0) - y = lindex(pt,1) - z = lindex(pt,2) - val = puzzle.SetPoint(x,y,z) + print pt ############### + x = pt[0] + y = pt[1] + z = pt[2] + val = puzzle.SetPoint(x, y, z) if (val != LastVal): renWin.Render() LastVal = val pass -def ButtonCallback (x,y,__vtk__temp0=0,__vtk__temp1=0): - # Compute display point from Tk display point. +def ButtonCallback (x, y): WindowY = 400 - y = expr.expr(globals(), locals(),["WindowY","-","y"]) - z = ren1.GetZ(x,y) - ren1.SetDisplayPoint(x,y,z) + y = WindowY - y + z = ren1.GetZ(x, y) + ren1.SetDisplayPoint(x, y, z) ren1.DisplayToWorld() pt = ren1.GetWorldPoint() - #tk_messageBox -message "$pt" - x = lindex(pt,0) - y = lindex(pt,1) - z = lindex(pt,2) +# print pt + x = pt[0] + y = pt[1] + z = pt[2] i = 0 while i <= 100: - puzzle.SetPoint(x,y,z) + puzzle.SetPoint(x, y, z) puzzle.MovePoint(i) renWin.Render() - i = expr.expr(globals(), locals(),["i","+","5"]) + i += 5 renWin.Render() + cam = ren1.GetActiveCamera() cam.Elevation(-40) -ButtonCallback(261,272) + +ButtonCallback(261, 272) + arrows.SetPermutation(puzzle) + renWin.Render() -# --- end of script -- + +iren.Initialize() +#iren.Start() diff --git a/Filters/Modeling/Testing/Python/eleState.py b/Filters/Modeling/Testing/Python/eleState.py index 079f358412a..d19cf809cb9 100755 --- a/Filters/Modeling/Testing/Python/eleState.py +++ b/Filters/Modeling/Testing/Python/eleState.py @@ -6,51 +6,68 @@ VTK_DATA_ROOT = vtkGetDataRoot() # This example demonstrates the use of the linear extrusion filter and # the USA state outline vtk dataset. It also tests the triangulation filter. -# get the interactor ui + # Create the RenderWindow, Renderer and both Actors ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create pipeline - read data # reader = vtk.vtkPolyDataReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/usa.vtk") +reader.SetFileName(VTK_DATA_ROOT + "/Data/usa.vtk") + # okay, now create some extrusion filters with actors for each US state math = vtk.vtkMath() i = 0 while i < 51: - locals()[get_variable_name("extractCell", i, "")] = vtk.vtkGeometryFilter() - locals()[get_variable_name("extractCell", i, "")].SetInputConnection(reader.GetOutputPort()) - locals()[get_variable_name("extractCell", i, "")].CellClippingOn() - locals()[get_variable_name("extractCell", i, "")].SetCellMinimum(i) - locals()[get_variable_name("extractCell", i, "")].SetCellMaximum(i) - locals()[get_variable_name("tf", i, "")] = vtk.vtkTriangleFilter() - locals()[get_variable_name("tf", i, "")].SetInputConnection(locals()[get_variable_name("extractCell", i, "")].GetOutputPort()) - locals()[get_variable_name("extrude", i, "")] = vtk.vtkLinearExtrusionFilter() - locals()[get_variable_name("extrude", i, "")].SetInputConnection(locals()[get_variable_name("tf", i, "")].GetOutputPort()) - locals()[get_variable_name("extrude", i, "")].SetExtrusionType(1) - locals()[get_variable_name("extrude", i, "")].SetVector(0,0,1) - locals()[get_variable_name("extrude", i, "")].CappingOn() - locals()[get_variable_name("extrude", i, "")].SetScaleFactor(math.Random(1,10)) - locals()[get_variable_name("mapper", i, "")] = vtk.vtkPolyDataMapper() - locals()[get_variable_name("mapper", i, "")].SetInputConnection(locals()[get_variable_name("extrude", i, "")].GetOutputPort()) - locals()[get_variable_name("actor", i, "")] = vtk.vtkActor() - locals()[get_variable_name("actor", i, "")].SetMapper(locals()[get_variable_name("mapper", i, "")]) - locals()[get_variable_name("actor", i, "")].GetProperty().SetColor(math.Random(0,1),math.Random(0,1),math.Random(0,1)) - ren1.AddActor(locals()[get_variable_name("actor", i, "")]) - i = i + 1 - -ren1.SetBackground(1,1,1) -renWin.SetSize(500,250) + idx = str(i) + exec("extractCell" + idx + " = vtk.vtkGeometryFilter()") + eval("extractCell" + idx).SetInputConnection(reader.GetOutputPort()) + eval("extractCell" + idx).CellClippingOn() + eval("extractCell" + idx).SetCellMinimum(i) + eval("extractCell" + idx).SetCellMaximum(i) + + exec("tf" + idx + " = vtk.vtkTriangleFilter()") + eval("tf" + idx).SetInputConnection( + eval("extractCell" + idx).GetOutputPort()) + + exec("extrude" + idx + " = vtk.vtkLinearExtrusionFilter()") + eval("extrude" + idx).SetInputConnection( + eval("tf" + idx).GetOutputPort()) + eval("extrude" + idx).SetExtrusionType(1) + eval("extrude" + idx).SetVector(0, 0, 1) + eval("extrude" + idx).CappingOn() + eval("extrude" + idx).SetScaleFactor(math.Random(1, 10)) + + exec("mapper" + idx + " = vtk.vtkPolyDataMapper()") + eval("mapper" + idx).SetInputConnection( + eval("extrude" + idx).GetOutputPort()) + + exec("actor" + idx + " = vtk.vtkActor()") + eval("actor" + idx).SetMapper(eval("mapper" + idx)) + eval("actor" + idx).GetProperty().SetColor(math.Random(0, 1), + math.Random(0, 1), math.Random(0, 1)) + + ren1.AddActor(eval("actor" + idx)) + + i += 1 + +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(500, 250) + cam1 = ren1.GetActiveCamera() -cam1.SetClippingRange(10.2299,511.497) -cam1.SetPosition(-119.669,-25.5502,79.0198) -cam1.SetFocalPoint(-115.96,41.6709,1.99546) -cam1.SetViewUp(-0.0013035,0.753456,0.657497) +cam1.SetClippingRange(10.2299, 511.497) +cam1.SetPosition(-119.669, -25.5502, 79.0198) +cam1.SetFocalPoint(-115.96, 41.6709, 1.99546) +cam1.SetViewUp(-0.0013035, 0.753456, 0.657497) + # render the image # renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +iren.Initialize() +#iren.Start() diff --git a/Filters/Modeling/Testing/Python/smoothCyl.py b/Filters/Modeling/Testing/Python/smoothCyl.py index 3edd5af18b4..3570ae3c780 100755 --- a/Filters/Modeling/Testing/Python/smoothCyl.py +++ b/Filters/Modeling/Testing/Python/smoothCyl.py @@ -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 + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -11,21 +20,26 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create a semi-cylinder # line = vtk.vtkLineSource() -line.SetPoint1(0,1,0) -line.SetPoint2(0,1,2) +line.SetPoint1(0, 1, 0) +line.SetPoint2(0, 1, 2) line.SetResolution(10) + lineSweeper = vtk.vtkRotationalExtrusionFilter() lineSweeper.SetResolution(20) lineSweeper.SetInputConnection(line.GetOutputPort()) lineSweeper.SetAngle(270) + bump = vtk.vtkBrownianPoints() bump.SetInputConnection(lineSweeper.GetOutputPort()) + warp = vtk.vtkWarpVector() warp.SetInputConnection(bump.GetOutputPort()) warp.SetScaleFactor(.2) + smooth = vtk.vtkSmoothPolyDataFilter() smooth.SetInputConnection(warp.GetOutputPort()) smooth.SetNumberOfIterations(50) @@ -33,35 +47,45 @@ smooth.BoundarySmoothingOn() smooth.SetFeatureAngle(120) smooth.SetEdgeAngle(90) smooth.SetRelaxationFactor(.025) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(smooth.GetOutputPort()) + cylMapper = vtk.vtkPolyDataMapper() cylMapper.SetInputConnection(normals.GetOutputPort()) + cylActor = vtk.vtkActor() cylActor.SetMapper(cylMapper) cylActor.GetProperty().SetInterpolationToGouraud() cylActor.GetProperty().SetInterpolationToFlat() -cylActor.GetProperty().SetColor(beige) +cylActor.GetProperty().SetColor(GetRGBColor('beige')) + originalMapper = vtk.vtkPolyDataMapper() originalMapper.SetInputConnection(bump.GetOutputPort()) + originalActor = vtk.vtkActor() originalActor.SetMapper(originalMapper) originalActor.GetProperty().SetInterpolationToFlat() -cylActor.GetProperty().SetColor(tomato) + +cylActor.GetProperty().SetColor(GetRGBColor('tomato')) + # Add the actors to the renderer, set the background and size # ren1.AddActor(cylActor) -#ren1 AddActor originalActor -ren1.SetBackground(1,1,1) -renWin.SetSize(200,300) +# ren1 AddActor originalActor +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(200, 300) + camera = vtk.vtkCamera() -camera.SetClippingRange(0.576398,28.8199) -camera.SetFocalPoint(0.0463079,-0.0356571,1.01993) -camera.SetPosition(-2.47044,2.39516,-3.56066) -camera.SetViewUp(0.607296,-0.513537,-0.606195) +camera.SetClippingRange(0.576398, 28.8199) +camera.SetFocalPoint(0.0463079, -0.0356571, 1.01993) +camera.SetPosition(-2.47044, 2.39516, -3.56066) +camera.SetViewUp(0.607296, -0.513537, -0.606195) + ren1.SetActiveCamera(camera) + # render the image # iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Modeling/Testing/Python/smoothCyl2.py b/Filters/Modeling/Testing/Python/smoothCyl2.py index d512f315b4a..54a6a687ce2 100755 --- a/Filters/Modeling/Testing/Python/smoothCyl2.py +++ b/Filters/Modeling/Testing/Python/smoothCyl2.py @@ -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 + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -11,21 +20,26 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create a semi-cylinder # line = vtk.vtkLineSource() -line.SetPoint1(0,1,0) -line.SetPoint2(0,1,2) +line.SetPoint1(0, 1, 0) +line.SetPoint2(0, 1, 2) line.SetResolution(10) + lineSweeper = vtk.vtkRotationalExtrusionFilter() lineSweeper.SetResolution(20) lineSweeper.SetInputConnection(line.GetOutputPort()) lineSweeper.SetAngle(270) + bump = vtk.vtkBrownianPoints() bump.SetInputConnection(lineSweeper.GetOutputPort()) + warp = vtk.vtkWarpVector() warp.SetInputConnection(bump.GetOutputPort()) warp.SetScaleFactor(.2) + smooth = vtk.vtkWindowedSincPolyDataFilter() smooth.SetInputConnection(warp.GetOutputPort()) smooth.SetNumberOfIterations(20) @@ -33,35 +47,44 @@ smooth.BoundarySmoothingOn() smooth.SetFeatureAngle(120) smooth.SetEdgeAngle(90) smooth.SetPassBand(0.1) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(smooth.GetOutputPort()) + cylMapper = vtk.vtkPolyDataMapper() cylMapper.SetInputConnection(normals.GetOutputPort()) + cylActor = vtk.vtkActor() cylActor.SetMapper(cylMapper) cylActor.GetProperty().SetInterpolationToGouraud() cylActor.GetProperty().SetInterpolationToFlat() -cylActor.GetProperty().SetColor(beige) +cylActor.GetProperty().SetColor(GetRGBColor('beige')) + originalMapper = vtk.vtkPolyDataMapper() originalMapper.SetInputConnection(bump.GetOutputPort()) originalActor = vtk.vtkActor() originalActor.SetMapper(originalMapper) originalActor.GetProperty().SetInterpolationToFlat() -cylActor.GetProperty().SetColor(tomato) + +cylActor.GetProperty().SetColor(GetRGBColor('tomato')) + # Add the actors to the renderer, set the background and size # ren1.AddActor(cylActor) -#ren1 AddActor originalActor -ren1.SetBackground(1,1,1) -renWin.SetSize(200,300) +# ren1 AddActor originalActor +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(200, 300) + camera = vtk.vtkCamera() -camera.SetClippingRange(0.576398,28.8199) -camera.SetFocalPoint(0.0463079,-0.0356571,1.01993) -camera.SetPosition(-2.47044,2.39516,-3.56066) -camera.SetViewUp(0.607296,-0.513537,-0.606195) +camera.SetClippingRange(0.576398, 28.8199) +camera.SetFocalPoint(0.0463079, -0.0356571, 1.01993) +camera.SetPosition(-2.47044, 2.39516, -3.56066) +camera.SetViewUp(0.607296, -0.513537, -0.606195) + ren1.SetActiveCamera(camera) + # render the image # iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Sources/Testing/Python/TestButtonSource.py b/Filters/Sources/Testing/Python/TestButtonSource.py index a046def96b5..2d6cabb51cd 100755 --- a/Filters/Sources/Testing/Python/TestButtonSource.py +++ b/Filters/Sources/Testing/Python/TestButtonSource.py @@ -7,13 +7,16 @@ VTK_DATA_ROOT = vtkGetDataRoot() # Test the button source # The image to map on the button r = vtk.vtkJPEGReader() -r.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/beach.jpg") +r.SetFileName(VTK_DATA_ROOT + "/Data/beach.jpg") r.Update() + t = vtk.vtkTexture() t.SetInputConnection(r.GetOutputPort()) + dims = r.GetOutput().GetDimensions() -d1 = lindex(dims,0) -d2 = lindex(dims,1) +d1 = dims[0] +d2 = dims[1] + # The first elliptical button bs = vtk.vtkEllipticalButtonSource() bs.SetWidth(2) @@ -24,11 +27,14 @@ bs.SetRadialRatio(1.1) bs.SetShoulderResolution(8) bs.SetTextureResolution(4) bs.TwoSidedOn() + bMapper = vtk.vtkPolyDataMapper() bMapper.SetInputConnection(bs.GetOutputPort()) + b1 = vtk.vtkActor() b1.SetMapper(bMapper) b1.SetTexture(t) + # The second elliptical button bs2 = vtk.vtkEllipticalButtonSource() bs2.SetWidth(2) @@ -39,41 +45,50 @@ bs2.SetRadialRatio(1.1) bs2.SetShoulderResolution(8) bs2.SetTextureResolution(4) bs2.TwoSidedOn() -bs2.SetCenter(2,0,0) +bs2.SetCenter(2, 0, 0) bs2.SetTextureStyleToFitImage() -bs2.SetTextureDimensions(d1,d2) +bs2.SetTextureDimensions(d1, d2) + b2Mapper = vtk.vtkPolyDataMapper() b2Mapper.SetInputConnection(bs2.GetOutputPort()) + b2 = vtk.vtkActor() b2.SetMapper(b2Mapper) b2.SetTexture(t) + # The third rectangular button bs3 = vtk.vtkRectangularButtonSource() bs3.SetWidth(1.5) bs3.SetHeight(0.75) bs3.SetDepth(0.2) bs3.TwoSidedOn() -bs3.SetCenter(0,1,0) -bs3.SetTextureDimensions(d1,d2) +bs3.SetCenter(0, 1, 0) +bs3.SetTextureDimensions(d1, d2) + b3Mapper = vtk.vtkPolyDataMapper() b3Mapper.SetInputConnection(bs3.GetOutputPort()) + b3 = vtk.vtkActor() b3.SetMapper(b3Mapper) b3.SetTexture(t) + # The fourth rectangular button bs4 = vtk.vtkRectangularButtonSource() bs4.SetWidth(1.5) bs4.SetHeight(0.75) bs4.SetDepth(0.2) bs4.TwoSidedOn() -bs4.SetCenter(2,1,0) +bs4.SetCenter(2, 1, 0) bs4.SetTextureStyleToFitImage() -bs4.SetTextureDimensions(d1,d2) +bs4.SetTextureDimensions(d1, d2) + b4Mapper = vtk.vtkPolyDataMapper() b4Mapper.SetInputConnection(bs4.GetOutputPort()) + b4 = vtk.vtkActor() b4.SetMapper(b4Mapper) b4.SetTexture(t) + # Create the RenderWindow, Renderer and Interactive Renderer # ren1 = vtk.vtkRenderer() @@ -81,14 +96,18 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + ren1.AddActor(b1) ren1.AddActor(b2) ren1.AddActor(b3) ren1.AddActor(b4) -ren1.SetBackground(0,0,0) -renWin.SetSize(250,150) +ren1.SetBackground(0, 0, 0) + +renWin.SetSize(250, 150) + renWin.Render() ren1.GetActiveCamera().Zoom(1.5) renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +iren.Initialize() +#iren.Start() diff --git a/Filters/Sources/Testing/Python/glyph2D.py b/Filters/Sources/Testing/Python/glyph2D.py index 5d716ee228a..8c6ebd9611c 100755 --- a/Filters/Sources/Testing/Python/glyph2D.py +++ b/Filters/Sources/Testing/Python/glyph2D.py @@ -7,21 +7,26 @@ VTK_DATA_ROOT = vtkGetDataRoot() # Create some random points, scalars, and vectors to glyph # pd = vtk.vtkPolyData() + pts = vtk.vtkPoints() + scalars = vtk.vtkFloatArray() + vectors = vtk.vtkFloatArray() vectors.SetNumberOfComponents(3) + pd.SetPoints(pts) pd.GetPointData().SetScalars(scalars) pd.GetPointData().SetVectors(vectors) + math = vtk.vtkMath() size = 500 i = 0 while i < 100: - pts.InsertNextPoint(math.Random(0,expr.expr(globals(), locals(),["size","-","1"])),math.Random(0,expr.expr(globals(), locals(),["size","-","1"])),0.0) - scalars.InsertNextValue(math.Random(0.0,5)) - vectors.InsertNextTuple3(math.Random(-1,1),math.Random(-1,1),0.0) - i = i + 1 + pts.InsertNextPoint(math.Random(0, size - 1), math.Random(0, size - 1), 0.0) + scalars.InsertNextValue(math.Random(0.0, 5)) + vectors.InsertNextTuple3(math.Random(-1, 1), math.Random(-1, 1), 0.0) + i += 1 gs = vtk.vtkGlyphSource2D() gs.SetGlyphTypeToCircle() @@ -29,24 +34,28 @@ gs.SetScale(20) gs.FilledOff() gs.CrossOn() gs.Update() + gs1 = vtk.vtkGlyphSource2D() gs1.SetGlyphTypeToTriangle() gs1.SetScale(20) gs1.FilledOff() gs1.CrossOn() gs1.Update() + gs2 = vtk.vtkGlyphSource2D() gs2.SetGlyphTypeToSquare() gs2.SetScale(20) gs2.FilledOff() gs2.CrossOn() gs2.Update() + gs3 = vtk.vtkGlyphSource2D() gs3.SetGlyphTypeToDiamond() gs3.SetScale(20) gs3.FilledOff() gs3.CrossOn() gs3.Update() + gs4 = vtk.vtkGlyphSource2D() gs4.SetGlyphTypeToDiamond() gs4.SetScale(20) @@ -54,29 +63,34 @@ gs4.FilledOn() gs4.DashOn() gs4.CrossOff() gs4.Update() + gs5 = vtk.vtkGlyphSource2D() gs5.SetGlyphTypeToThickArrow() gs5.SetScale(20) gs5.FilledOn() gs5.CrossOff() gs5.Update() + # Create a table of glyphs glypher = vtk.vtkGlyph2D() glypher.SetInputData(pd) -glypher.SetSourceData(0,gs.GetOutput()) -glypher.SetSourceData(1,gs1.GetOutput()) -glypher.SetSourceData(2,gs2.GetOutput()) -glypher.SetSourceData(3,gs3.GetOutput()) -glypher.SetSourceData(4,gs4.GetOutput()) -glypher.SetSourceData(5,gs5.GetOutput()) +glypher.SetSourceData(0, gs.GetOutput()) +glypher.SetSourceData(1, gs1.GetOutput()) +glypher.SetSourceData(2, gs2.GetOutput()) +glypher.SetSourceData(3, gs3.GetOutput()) +glypher.SetSourceData(4, gs4.GetOutput()) +glypher.SetSourceData(5, gs5.GetOutput()) glypher.SetIndexModeToScalar() -glypher.SetRange(0,5) +glypher.SetRange(0, 5) glypher.SetScaleModeToDataScalingOff() + mapper = vtk.vtkPolyDataMapper2D() mapper.SetInputConnection(glypher.GetOutputPort()) -mapper.SetScalarRange(0,5) +mapper.SetScalarRange(0, 5) + glyphActor = vtk.vtkActor2D() glyphActor.SetMapper(mapper) + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -85,14 +99,15 @@ renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(glyphActor) -ren1.SetBackground(1,1,1) -renWin.SetSize(size,size) +ren1.SetBackground(1, 1, 1) +renWin.SetSize(size, size) renWin.Render() + # render the image # iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Filters/Texture/Testing/Python/triangularTCoords.py b/Filters/Texture/Testing/Python/triangularTCoords.py index db1bb1e1d5b..84ea428d381 100755 --- a/Filters/Texture/Testing/Python/triangularTCoords.py +++ b/Filters/Texture/Testing/Python/triangularTCoords.py @@ -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 + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -11,43 +20,55 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + aTriangularTexture = vtk.vtkTriangularTexture() aTriangularTexture.SetTexturePattern(2) aTriangularTexture.SetScaleFactor(1.3) aTriangularTexture.SetXSize(64) aTriangularTexture.SetYSize(64) + aSphere = vtk.vtkSphereSource() aSphere.SetThetaResolution(20) aSphere.SetPhiResolution(20) + tCoords = vtk.vtkTriangularTCoords() tCoords.SetInputConnection(aSphere.GetOutputPort()) + triangleMapper = vtk.vtkPolyDataMapper() triangleMapper.SetInputConnection(tCoords.GetOutputPort()) + aTexture = vtk.vtkTexture() aTexture.SetInputConnection(aTriangularTexture.GetOutputPort()) aTexture.InterpolateOn() + texturedActor = vtk.vtkActor() texturedActor.SetMapper(triangleMapper) texturedActor.SetTexture(aTexture) texturedActor.GetProperty().BackfaceCullingOn() -texturedActor.GetProperty().SetDiffuseColor(banana) +texturedActor.GetProperty().SetDiffuseColor(GetRGBColor('banana')) texturedActor.GetProperty().SetSpecular(.4) texturedActor.GetProperty().SetSpecularPower(40) + aCube = vtk.vtkCubeSource() aCube.SetXLength(.5) aCube.SetYLength(.5) + aCubeMapper = vtk.vtkPolyDataMapper() aCubeMapper.SetInputConnection(aCube.GetOutputPort()) + cubeActor = vtk.vtkActor() cubeActor.SetMapper(aCubeMapper) -cubeActor.GetProperty().SetDiffuseColor(tomato) -ren1.SetBackground(slate_grey) +cubeActor.GetProperty().SetDiffuseColor(GetRGBColor('tomato')) + +ren1.SetBackground(GetRGBColor('slate_grey')) ren1.AddActor(cubeActor) ren1.AddActor(texturedActor) + ren1.ResetCamera() + ren1.GetActiveCamera().Zoom(1.5) + # render the image # iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/IO/EnSight/Testing/Python/EnSightRectGridASCII.py b/IO/EnSight/Testing/Python/EnSightRectGridASCII.py index 8812a6c5ef9..689e9116766 100755 --- a/IO/EnSight/Testing/Python/EnSightRectGridASCII.py +++ b/IO/EnSight/Testing/Python/EnSightRectGridASCII.py @@ -4,84 +4,115 @@ 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 + VTK_VARY_RADIUS_BY_VECTOR = 2 + # create pipeline # -reader = vtk.vtkGenericEnSightReader() # Make sure all algorithms use the composite data pipeline cdp = vtk.vtkCompositeDataPipeline() + +reader = vtk.vtkGenericEnSightReader() reader.SetDefaultExecutivePrototype(cdp) -reader.SetCaseFileName("" + str(VTK_DATA_ROOT) + "/Data/EnSight/RectGrid_ascii.case") +reader.SetCaseFileName(VTK_DATA_ROOT + "/Data/EnSight/RectGrid_ascii.case") reader.Update() + toRectilinearGrid = vtk.vtkCastToConcrete() -# toRectilinearGrid SetInputConnection [reader GetOutputPort] toRectilinearGrid.SetInputData(reader.GetOutput().GetBlock(0)) toRectilinearGrid.Update() + plane = vtk.vtkRectilinearGridGeometryFilter() plane.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) -plane.SetExtent(0,100,0,100,15,15) +plane.SetExtent(0, 100, 0, 100, 15, 15) + tri = vtk.vtkTriangleFilter() tri.SetInputConnection(plane.GetOutputPort()) + warper = vtk.vtkWarpVector() warper.SetInputConnection(tri.GetOutputPort()) warper.SetScaleFactor(0.05) + planeMapper = vtk.vtkDataSetMapper() planeMapper.SetInputConnection(warper.GetOutputPort()) -planeMapper.SetScalarRange(0.197813,0.710419) +planeMapper.SetScalarRange(0.197813, 0.710419) + planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) + cutPlane = vtk.vtkPlane() -# eval cutPlane SetOrigin [[reader GetOutput] GetCenter] cutPlane.SetOrigin(reader.GetOutput().GetBlock(0).GetCenter()) -cutPlane.SetNormal(1,0,0) +cutPlane.SetNormal(1, 0, 0) + planeCut = vtk.vtkCutter() planeCut.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) planeCut.SetCutFunction(cutPlane) + cutMapper = vtk.vtkDataSetMapper() cutMapper.SetInputConnection(planeCut.GetOutputPort()) -cutMapper.SetScalarRange(reader.GetOutput().GetBlock(0).GetPointData().GetScalars().GetRange()) +cutMapper.SetScalarRange( + reader.GetOutput().GetBlock(0).GetPointData().GetScalars().GetRange()) + cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) + iso = vtk.vtkContourFilter() iso.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) -iso.SetValue(0,0.7) +iso.SetValue(0, 0.7) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(iso.GetOutputPort()) normals.SetFeatureAngle(45) + isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(normals.GetOutputPort()) isoMapper.ScalarVisibilityOff() + isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) -isoActor.GetProperty().SetColor(bisque) +isoActor.GetProperty().SetColor(GetRGBColor('bisque')) isoActor.GetProperty().SetRepresentationToWireframe() + streamer = vtk.vtkStreamLine() -# streamer SetInputConnection [reader GetOutputPort] streamer.SetInputData(reader.GetOutput().GetBlock(0)) -streamer.SetStartPosition(-1.2,-0.1,1.3) +streamer.SetStartPosition(-1.2, -0.1, 1.3) streamer.SetMaximumPropagationTime(500) streamer.SetStepLength(0.05) streamer.SetIntegrationStepLength(0.05) streamer.SetIntegrationDirectionToIntegrateBothDirections() + streamTube = vtk.vtkTubeFilter() streamTube.SetInputConnection(streamer.GetOutputPort()) streamTube.SetRadius(0.025) streamTube.SetNumberOfSides(6) streamTube.SetVaryRadius(VTK_VARY_RADIUS_BY_VECTOR) + mapStreamTube = vtk.vtkPolyDataMapper() mapStreamTube.SetInputConnection(streamTube.GetOutputPort()) -mapStreamTube.SetScalarRange(reader.GetOutput().GetBlock(0).GetPointData().GetScalars().GetRange()) -# [[[[reader GetOutput] GetPointData] GetScalars] GetRange] +mapStreamTube.SetScalarRange( + reader.GetOutput().GetBlock(0).GetPointData().GetScalars().GetRange()) + streamTubeActor = vtk.vtkActor() streamTubeActor.SetMapper(mapStreamTube) streamTubeActor.GetProperty().BackfaceCullingOn() + outline = vtk.vtkOutlineFilter() outline.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) + outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) -outlineActor.GetProperty().SetColor(black) +outlineActor.GetProperty().SetColor(GetRGBColor('black')) + # Graphics stuff # Create the RenderWindow, Renderer and both Actors # @@ -91,6 +122,7 @@ renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) @@ -98,16 +130,19 @@ ren1.AddActor(planeActor) ren1.AddActor(cutActor) ren1.AddActor(isoActor) ren1.AddActor(streamTubeActor) -ren1.SetBackground(1,1,1) -renWin.SetSize(400,400) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(400, 400) + cam1 = ren1.GetActiveCamera() -cam1.SetClippingRange(3.76213,10.712) -cam1.SetFocalPoint(-0.0842503,-0.136905,0.610234) -cam1.SetPosition(2.53813,2.2678,-5.22172) -cam1.SetViewUp(-0.241047,0.930635,0.275343) +cam1.SetClippingRange(3.76213, 10.712) +cam1.SetFocalPoint(-0.0842503, -0.136905, 0.610234) +cam1.SetPosition(2.53813, 2.2678, -5.22172) +cam1.SetViewUp(-0.241047, 0.930635, 0.275343) + +reader.SetDefaultExecutivePrototype(None) + iren.Initialize() # render the image # -# prevent the tk window from showing up then start the event loop -reader.SetDefaultExecutivePrototype(None) -# --- end of script -- +#iren.Start() diff --git a/IO/EnSight/Testing/Python/EnSightRectGridBin.py b/IO/EnSight/Testing/Python/EnSightRectGridBin.py index f701fc3d861..96c73625c15 100755 --- a/IO/EnSight/Testing/Python/EnSightRectGridBin.py +++ b/IO/EnSight/Testing/Python/EnSightRectGridBin.py @@ -4,84 +4,114 @@ 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 + VTK_VARY_RADIUS_BY_VECTOR = 2 # create pipeline # -reader = vtk.vtkGenericEnSightReader() # Make sure all algorithms use the composite data pipeline cdp = vtk.vtkCompositeDataPipeline() + +reader = vtk.vtkGenericEnSightReader() reader.SetDefaultExecutivePrototype(cdp) -reader.SetCaseFileName("" + str(VTK_DATA_ROOT) + "/Data/EnSight/RectGrid_bin.case") +reader.SetCaseFileName(VTK_DATA_ROOT + "/Data/EnSight/RectGrid_bin.case") reader.Update() + toRectilinearGrid = vtk.vtkCastToConcrete() -# toRectilinearGrid SetInputConnection [reader GetOutputPort] toRectilinearGrid.SetInputData(reader.GetOutput().GetBlock(0)) toRectilinearGrid.Update() + plane = vtk.vtkRectilinearGridGeometryFilter() plane.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) -plane.SetExtent(0,100,0,100,15,15) +plane.SetExtent(0, 100, 0, 100, 15, 15) + tri = vtk.vtkTriangleFilter() tri.SetInputConnection(plane.GetOutputPort()) + warper = vtk.vtkWarpVector() warper.SetInputConnection(tri.GetOutputPort()) warper.SetScaleFactor(0.05) + planeMapper = vtk.vtkDataSetMapper() planeMapper.SetInputConnection(warper.GetOutputPort()) -planeMapper.SetScalarRange(0.197813,0.710419) +planeMapper.SetScalarRange(0.197813, 0.710419) + planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) + cutPlane = vtk.vtkPlane() -# eval cutPlane SetOrigin [[reader GetOutput] GetCenter] cutPlane.SetOrigin(reader.GetOutput().GetBlock(0).GetCenter()) -cutPlane.SetNormal(1,0,0) +cutPlane.SetNormal(1, 0, 0) + planeCut = vtk.vtkCutter() planeCut.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) planeCut.SetCutFunction(cutPlane) + cutMapper = vtk.vtkDataSetMapper() cutMapper.SetInputConnection(planeCut.GetOutputPort()) -cutMapper.SetScalarRange(reader.GetOutput().GetBlock(0).GetPointData().GetScalars().GetRange()) +cutMapper.SetScalarRange( + reader.GetOutput().GetBlock(0).GetPointData().GetScalars().GetRange()) + cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) + iso = vtk.vtkContourFilter() iso.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) -iso.SetValue(0,0.7) +iso.SetValue(0, 0.7) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(iso.GetOutputPort()) normals.SetFeatureAngle(45) + isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(normals.GetOutputPort()) isoMapper.ScalarVisibilityOff() + isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) -isoActor.GetProperty().SetColor(bisque) +isoActor.GetProperty().SetColor(GetRGBColor('bisque')) isoActor.GetProperty().SetRepresentationToWireframe() + streamer = vtk.vtkStreamLine() -# streamer SetInputConnection [reader GetOutputPort] streamer.SetInputData(reader.GetOutput().GetBlock(0)) -streamer.SetStartPosition(-1.2,-0.1,1.3) +streamer.SetStartPosition(-1.2, -0.1, 1.3) streamer.SetMaximumPropagationTime(500) streamer.SetStepLength(0.05) streamer.SetIntegrationStepLength(0.05) streamer.SetIntegrationDirectionToIntegrateBothDirections() + streamTube = vtk.vtkTubeFilter() streamTube.SetInputConnection(streamer.GetOutputPort()) streamTube.SetRadius(0.025) streamTube.SetNumberOfSides(6) streamTube.SetVaryRadius(VTK_VARY_RADIUS_BY_VECTOR) + mapStreamTube = vtk.vtkPolyDataMapper() mapStreamTube.SetInputConnection(streamTube.GetOutputPort()) -mapStreamTube.SetScalarRange(reader.GetOutput().GetBlock(0).GetPointData().GetScalars().GetRange()) -# [[[[reader GetOutput] GetPointData] GetScalars] GetRange] +mapStreamTube.SetScalarRange( + reader.GetOutput().GetBlock(0).GetPointData().GetScalars().GetRange()) + streamTubeActor = vtk.vtkActor() streamTubeActor.SetMapper(mapStreamTube) streamTubeActor.GetProperty().BackfaceCullingOn() + outline = vtk.vtkOutlineFilter() outline.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) + outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) -outlineActor.GetProperty().SetColor(black) +outlineActor.GetProperty().SetColor(GetRGBColor('black')) + # Graphics stuff # Create the RenderWindow, Renderer and both Actors # @@ -91,6 +121,7 @@ renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) @@ -98,16 +129,19 @@ ren1.AddActor(planeActor) ren1.AddActor(cutActor) ren1.AddActor(isoActor) ren1.AddActor(streamTubeActor) -ren1.SetBackground(1,1,1) -renWin.SetSize(400,400) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(400, 400) + cam1 = ren1.GetActiveCamera() -cam1.SetClippingRange(3.76213,10.712) -cam1.SetFocalPoint(-0.0842503,-0.136905,0.610234) -cam1.SetPosition(2.53813,2.2678,-5.22172) -cam1.SetViewUp(-0.241047,0.930635,0.275343) +cam1.SetClippingRange(3.76213, 10.712) +cam1.SetFocalPoint(-0.0842503, -0.136905, 0.610234) +cam1.SetPosition(2.53813, 2.2678, -5.22172) +cam1.SetViewUp(-0.241047, 0.930635, 0.275343) + +reader.SetDefaultExecutivePrototype(None) + iren.Initialize() # render the image # -# prevent the tk window from showing up then start the event loop -reader.SetDefaultExecutivePrototype(None) -# --- end of script -- +#iren.Start() diff --git a/IO/Geometry/Testing/Python/Plot3DScalars.py b/IO/Geometry/Testing/Python/Plot3DScalars.py index 165ecafc240..3eeafa1ac73 100755 --- a/IO/Geometry/Testing/Python/Plot3DScalars.py +++ b/IO/Geometry/Testing/Python/Plot3DScalars.py @@ -12,71 +12,94 @@ VTK_DATA_ROOT = vtkGetDataRoot() renWin = vtk.vtkRenderWindow() iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) -scalarLabels = "Density Pressure Temperature Enthalpy Internal_Energy Kinetic_Energy Velocity_Magnitude Stagnation_Energy Entropy Swirl" -scalarFunctions = "100 110 120 130 140 144 153 163 170 184" +scalarLabels = ["Density", "Pressure", "Temperature", "Enthalpy", + "Internal_Energy", "Kinetic_Energy", "Velocity_Magnitude", + "Stagnation_Energy", "Entropy", "Swirl"] +scalarFunctions = ["100", "110", "120", "130", + "140", "144", "153", + "163", "170", "184"] + camera = vtk.vtkCamera() + light = vtk.vtkLight() + math = vtk.vtkMath() + # All text actors will share the same text prop textProp = vtk.vtkTextProperty() textProp.SetFontSize(10) textProp.SetFontFamilyToArial() -textProp.SetColor(0,0,0) +textProp.SetColor(0, 0, 0) + i = 0 -for scalarFunction in scalarFunctions.split(): - locals()[get_variable_name("pl3d", scalarFunction, "")] = vtk.vtkMultiBlockPLOT3DReader() - locals()[get_variable_name("pl3d", scalarFunction, "")].SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinxyz.bin") - locals()[get_variable_name("pl3d", scalarFunction, "")].SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinq.bin") - locals()[get_variable_name("pl3d", scalarFunction, "")].SetScalarFunctionNumber(expr.expr(globals(), locals(),["int","(","scalarFunction",")"])) - locals()[get_variable_name("pl3d", scalarFunction, "")].Update() - output = locals()[get_variable_name("pl3d", scalarFunction, "")].GetOutput().GetBlock(0) - locals()[get_variable_name("plane", scalarFunction, "")] = vtk.vtkStructuredGridGeometryFilter() - locals()[get_variable_name("plane", scalarFunction, "")].SetInputData(output) - locals()[get_variable_name("plane", scalarFunction, "")].SetExtent(25,25,0,100,0,100) - locals()[get_variable_name("mapper", scalarFunction, "")] = vtk.vtkPolyDataMapper() - locals()[get_variable_name("mapper", scalarFunction, "")].SetInputConnection(locals()[get_variable_name("plane", scalarFunction, "")].GetOutputPort()) - locals()[get_variable_name("mapper", scalarFunction, "")].SetScalarRange(output.GetPointData().GetScalars().GetRange()) - locals()[get_variable_name("actor", scalarFunction, "")] = vtk.vtkActor() - locals()[get_variable_name("actor", scalarFunction, "")].SetMapper(locals()[get_variable_name("mapper", scalarFunction, "")]) - locals()[get_variable_name("ren", scalarFunction, "")] = vtk.vtkRenderer() - locals()[get_variable_name("ren", scalarFunction, "")].SetBackground(0,0,.5) - locals()[get_variable_name("ren", scalarFunction, "")].SetActiveCamera(camera) - locals()[get_variable_name("ren", scalarFunction, "")].AddLight(light) - renWin.AddRenderer(locals()[get_variable_name("ren", scalarFunction, "")]) - locals()[get_variable_name("ren", scalarFunction, "")].SetBackground(math.Random(.5,1),math.Random(.5,1),math.Random(.5,1)) - locals()[get_variable_name("ren", scalarFunction, "")].AddActor(locals()[get_variable_name("actor", scalarFunction, "")]) - locals()[get_variable_name("textMapper", scalarFunction, "")] = vtk.vtkTextMapper() - locals()[get_variable_name("textMapper", scalarFunction, "")].SetInput(lindex(scalarLabels,i)) - locals()[get_variable_name("textMapper", scalarFunction, "")].SetTextProperty(textProp) - locals()[get_variable_name("text", scalarFunction, "")] = vtk.vtkActor2D() - locals()[get_variable_name("text", scalarFunction, "")].SetMapper(locals()[get_variable_name("textMapper", scalarFunction, "")]) - locals()[get_variable_name("text", scalarFunction, "")].SetPosition(2,3) - if (info.command(globals(), locals(), "rtExMath") == ""): - locals()[get_variable_name("ren", scalarFunction, "")].AddActor2D(locals()[get_variable_name("text", scalarFunction, "")]) - pass - i = i + 1 - - pass +for scalarFunction in scalarFunctions: + exec("pl3d" + scalarFunction + " = vtk.vtkMultiBlockPLOT3DReader()") + eval("pl3d" + scalarFunction).SetXYZFileName( + VTK_DATA_ROOT + "/Data/bluntfinxyz.bin") + eval("pl3d" + scalarFunction).SetQFileName( + VTK_DATA_ROOT + "/Data/bluntfinq.bin") + eval("pl3d" + scalarFunction).SetScalarFunctionNumber(int(scalarFunction)) + eval("pl3d" + scalarFunction).Update() + + output = eval("pl3d" + scalarFunction).GetOutput().GetBlock(0) + + exec("plane" + scalarFunction + " = vtk.vtkStructuredGridGeometryFilter()") + eval("plane" + scalarFunction).SetInputData(output) + eval("plane" + scalarFunction).SetExtent(25, 25, 0, 100, 0, 100) + + exec("mapper" + scalarFunction + " = vtk.vtkPolyDataMapper()") + eval("mapper" + scalarFunction).SetInputConnection( + eval("plane" + scalarFunction).GetOutputPort()) + eval("mapper" + scalarFunction).SetScalarRange( + output.GetPointData().GetScalars().GetRange()) + + exec("actor" + scalarFunction + " = vtk.vtkActor()") + eval("actor" + scalarFunction).SetMapper(eval("mapper" + scalarFunction)) + + exec("ren" + scalarFunction + " = vtk.vtkRenderer()") + eval("ren" + scalarFunction).SetBackground(0, 0, .5) + eval("ren" + scalarFunction).SetActiveCamera(camera) + eval("ren" + scalarFunction).AddLight(light) + + renWin.AddRenderer(eval("ren" + scalarFunction)) + + eval("ren" + scalarFunction).SetBackground( + math.Random(.5, 1), math.Random(.5, 1), math.Random(.5, 1)) + eval("ren" + scalarFunction).AddActor(eval("actor" + scalarFunction)) + + exec("textMapper" + scalarFunction + " = vtk.vtkTextMapper()") + eval("textMapper" + scalarFunction).SetInput(scalarLabels[i]) + eval("textMapper" + scalarFunction).SetTextProperty(textProp) + +# exec("text" + scalarFunction + " = vtk.vtkActor2D()") +# eval("text" + scalarFunction).SetMapper(eval("textMapper" + scalarFunction)) +# eval("text" + scalarFunction).SetPosition(2, 3) +# +# eval("ren" + scalarFunction).AddActor2D(eval("text" + scalarFunction)) + + i += 1 # -# now layout renderers +# now layout the renderers column = 1 row = 1 -deltaX = expr.expr(globals(), locals(),["1.0","/","5.0"]) -deltaY = expr.expr(globals(), locals(),["1.0","/","2.0"]) -for scalarFunction in scalarFunctions.split(): - locals()[get_variable_name("ren", scalarFunction, "")].SetViewport(expr.expr(globals(), locals(),["(","column","-","1",")","*","deltaX"]),expr.expr(globals(), locals(),["(","row","-","1",")","*","deltaY"]),expr.expr(globals(), locals(),["column","*","deltaX"]),expr.expr(globals(), locals(),["row","*","deltaY"])) - column = column + 1 +deltaX = 1.0 / 5.0 +deltaY = 1.0 / 2.0 +for scalarFunction in scalarFunctions: + eval("ren" + scalarFunction).SetViewport( + (column - 1) * deltaX, (row - 1) * deltaY, column * deltaX, row * deltaY) + column += 1 if (column > 5): column = 1 - row = row + 1 - pass + row += 1 + +camera.SetViewUp(0, 1, 0) +camera.SetFocalPoint(0, 0, 0) +camera.SetPosition(1, 0, 0) - pass -camera.SetViewUp(0,1,0) -camera.SetFocalPoint(0,0,0) -camera.SetPosition(1,0,0) ren100.ResetCamera() + camera.Dolly(1.25) + ren100.ResetCameraClippingRange() ren110.ResetCameraClippingRange() ren120.ResetCameraClippingRange() @@ -87,12 +110,14 @@ ren153.ResetCameraClippingRange() ren163.ResetCameraClippingRange() ren170.ResetCameraClippingRange() ren184.ResetCameraClippingRange() + light.SetPosition(camera.GetPosition()) light.SetFocalPoint(camera.GetFocalPoint()) -renWin.SetSize(600,180) + +renWin.SetSize(600, 180) renWin.Render() -iren.Initialize() + # render the image # -# prevent the tk window from showing up then start the event loop -# --- end of script -- +iren.Initialize() +# iren.Start() diff --git a/IO/Geometry/Testing/Python/Plot3DVectors.py b/IO/Geometry/Testing/Python/Plot3DVectors.py index eb9c0d7c56a..3b8011853ae 100755 --- a/IO/Geometry/Testing/Python/Plot3DVectors.py +++ b/IO/Geometry/Testing/Python/Plot3DVectors.py @@ -12,86 +12,106 @@ VTK_DATA_ROOT = vtkGetDataRoot() renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) ren1 = vtk.vtkRenderer() -ren1.SetBackground(.8,.8,.2) +ren1.SetBackground(.8, .8, .2) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) -vectorLabels = "Velocity Vorticity Momentum Pressure_Gradient" -vectorFunctions = "200 201 202 210" + +vectorLabels = ["Velocity", "Vorticity", "Momentum", "Pressure_Gradient"] +vectorFunctions = ["200", "201", "202", "210"] + camera = vtk.vtkCamera() + light = vtk.vtkLight() + # All text actors will share the same text prop textProp = vtk.vtkTextProperty() textProp.SetFontSize(10) textProp.SetFontFamilyToArial() -textProp.SetColor(.3,1,1) +textProp.SetColor(.3, 1, 1) + i = 0 -for vectorFunction in vectorFunctions.split(): - locals()[get_variable_name("pl3d", vectorFunction, "")] = vtk.vtkMultiBlockPLOT3DReader() - locals()[get_variable_name("pl3d", vectorFunction, "")].SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinxyz.bin") - locals()[get_variable_name("pl3d", vectorFunction, "")].SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinq.bin") - locals()[get_variable_name("pl3d", vectorFunction, "")].SetVectorFunctionNumber(expr.expr(globals(), locals(),["int","(","vectorFunction",")"])) - locals()[get_variable_name("pl3d", vectorFunction, "")].Update() - output = locals()[get_variable_name("pl3d", vectorFunction, "")].GetOutput().GetBlock(0) - locals()[get_variable_name("plane", vectorFunction, "")] = vtk.vtkStructuredGridGeometryFilter() - locals()[get_variable_name("plane", vectorFunction, "")].SetInputData(output) - locals()[get_variable_name("plane", vectorFunction, "")].SetExtent(25,25,0,100,0,100) - locals()[get_variable_name("hog", vectorFunction, "")] = vtk.vtkHedgeHog() - locals()[get_variable_name("hog", vectorFunction, "")].SetInputConnection(locals()[get_variable_name("plane", vectorFunction, "")].GetOutputPort()) +for vectorFunction in vectorFunctions: + exec("pl3d" + vectorFunction + " = vtk.vtkMultiBlockPLOT3DReader()") + eval("pl3d" + vectorFunction).SetXYZFileName( + VTK_DATA_ROOT + "/Data/bluntfinxyz.bin") + eval("pl3d" + vectorFunction).SetQFileName( + VTK_DATA_ROOT + "/Data/bluntfinq.bin") + eval("pl3d" + vectorFunction).SetVectorFunctionNumber(int(vectorFunction)) + eval("pl3d" + vectorFunction).Update() + + output = eval("pl3d" + vectorFunction).GetOutput().GetBlock(0) + + exec("plane" + vectorFunction + " = vtk.vtkStructuredGridGeometryFilter()") + eval("plane" + vectorFunction).SetInputData(output) + eval("plane" + vectorFunction).SetExtent(25, 25, 0, 100, 0, 100) + + exec("hog" + vectorFunction + " = vtk.vtkHedgeHog()") + eval("hog" + vectorFunction).SetInputConnection( + eval("plane" + vectorFunction).GetOutputPort()) + maxnorm = output.GetPointData().GetVectors().GetMaxNorm() - locals()[get_variable_name("hog", vectorFunction, "")].SetScaleFactor(expr.expr(globals(), locals(),["1.0","/","maxnorm"])) - locals()[get_variable_name("mapper", vectorFunction, "")] = vtk.vtkPolyDataMapper() - locals()[get_variable_name("mapper", vectorFunction, "")].SetInputConnection(locals()[get_variable_name("hog", vectorFunction, "")].GetOutputPort()) - locals()[get_variable_name("actor", vectorFunction, "")] = vtk.vtkActor() - locals()[get_variable_name("actor", vectorFunction, "")].SetMapper(locals()[get_variable_name("mapper", vectorFunction, "")]) - locals()[get_variable_name("ren", vectorFunction, "")] = vtk.vtkRenderer() - locals()[get_variable_name("ren", vectorFunction, "")].SetBackground(0.5,.5,.5) - locals()[get_variable_name("ren", vectorFunction, "")].SetActiveCamera(camera) - locals()[get_variable_name("ren", vectorFunction, "")].AddLight(light) - renWin.AddRenderer(locals()[get_variable_name("ren", vectorFunction, "")]) - locals()[get_variable_name("ren", vectorFunction, "")].AddActor(locals()[get_variable_name("actor", vectorFunction, "")]) - locals()[get_variable_name("textMapper", vectorFunction, "")] = vtk.vtkTextMapper() - locals()[get_variable_name("textMapper", vectorFunction, "")].SetInput(lindex(vectorLabels,i)) - locals()[get_variable_name("textMapper", vectorFunction, "")].SetTextProperty(textProp) - locals()[get_variable_name("text", vectorFunction, "")] = vtk.vtkActor2D() - locals()[get_variable_name("text", vectorFunction, "")].SetMapper(locals()[get_variable_name("textMapper", vectorFunction, "")]) - locals()[get_variable_name("text", vectorFunction, "")].SetPosition(2,5) - if (info.command(globals(), locals(), "rtExMath") == ""): - locals()[get_variable_name("ren", vectorFunction, "")].AddActor2D(locals()[get_variable_name("text", vectorFunction, "")]) - pass - i = i + 1 - - pass + + eval("hog" + vectorFunction).SetScaleFactor(1.0 / maxnorm) + + exec("mapper" + vectorFunction + " = vtk.vtkPolyDataMapper()") + eval("mapper" + vectorFunction).SetInputConnection( + eval("hog" + vectorFunction).GetOutputPort()) + + exec("actor" + vectorFunction + " = vtk.vtkActor()") + eval("actor" + vectorFunction).SetMapper(eval("mapper" + vectorFunction)) + + exec("ren" + vectorFunction + " = vtk.vtkRenderer()") + eval("ren" + vectorFunction).SetBackground(0.5, .5, .5) + eval("ren" + vectorFunction).SetActiveCamera(camera) + eval("ren" + vectorFunction).AddLight(light) + + renWin.AddRenderer(eval("ren" + vectorFunction)) + + eval("ren" + vectorFunction).AddActor(eval("actor" + vectorFunction)) + + exec("textMapper" + vectorFunction + " = vtk.vtkTextMapper()") + eval("textMapper" + vectorFunction).SetInput(vectorLabels[i]) + eval("textMapper" + vectorFunction).SetTextProperty(textProp) + exec("text" + vectorFunction + " = vtk.vtkActor2D()") + + eval("text" + vectorFunction).SetMapper(eval("textMapper" + vectorFunction)) + eval("text" + vectorFunction).SetPosition(2, 5) + eval("ren" + vectorFunction).AddActor2D(eval("text" + vectorFunction)) + i += 1 + # # now layout renderers column = 1 row = 1 -deltaX = expr.expr(globals(), locals(),["1.0","/","2.0"]) -deltaY = expr.expr(globals(), locals(),["1.0","/","2.0"]) -for vectorFunction in vectorFunctions.split(): - locals()[get_variable_name("ren", vectorFunction, "")].SetViewport(expr.expr(globals(), locals(),["(","column","-","1",")","*","deltaX","+","(","deltaX","*",".05",")"]),expr.expr(globals(), locals(),["(","row","-","1",")","*","deltaY","+","(","deltaY","*",".05",")"]),expr.expr(globals(), locals(),["column","*","deltaX","-","(","deltaX","*",".05",")"]),expr.expr(globals(), locals(),["row","*","deltaY","-","(","deltaY","*",".05",")"])) - column = column + 1 +deltaX = 1.0 / 2.0 +deltaY = 1.0 / 2.0 +for vectorFunction in vectorFunctions: + eval("ren" + vectorFunction).SetViewport( + (column - 1) * deltaX + (deltaX * .05), + (row - 1) * deltaY + (deltaY * .05), + column * deltaX - (deltaX * .05), + row * deltaY - (deltaY * .05)) + column += 1 if (column > 2): column = 1 - row = row + 1 - pass + row += 1 - pass -camera.SetViewUp(1,0,0) -camera.SetFocalPoint(0,0,0) -camera.SetPosition(.4,-.5,-.75) +camera.SetViewUp(1, 0, 0) +camera.SetFocalPoint(0, 0, 0) +camera.SetPosition(.4, -.5, -.75) ren200.ResetCamera() camera.Dolly(1.25) -ren200.ResetCameraClippingRange() -ren201.ResetCameraClippingRange() -ren202.ResetCameraClippingRange() -ren210.ResetCameraClippingRange() + +for vectorFunction in vectorFunctions: + eval("ren" + vectorFunction).ResetCameraClippingRange() + light.SetPosition(camera.GetPosition()) light.SetFocalPoint(camera.GetFocalPoint()) -renWin.SetSize(350,350) + +renWin.SetSize(350, 350) + renWin.Render() + iren.Initialize() -# render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/IO/Geometry/Testing/Python/TestChacoReader.py b/IO/Geometry/Testing/Python/TestChacoReader.py index 6e6d66a4272..85c4df71891 100755 --- a/IO/Geometry/Testing/Python/TestChacoReader.py +++ b/IO/Geometry/Testing/Python/TestChacoReader.py @@ -1,22 +1,30 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # read in a Chaco file chReader = vtk.vtkChacoReader() -chReader.SetBaseName("" + str(VTK_DATA_ROOT) + "/Data/vwgt") +chReader.SetBaseName(VTK_DATA_ROOT + "/Data/vwgt") chReader.SetGenerateGlobalElementIdArray(1) chReader.SetGenerateGlobalNodeIdArray(1) chReader.SetGenerateEdgeWeightArrays(1) chReader.SetGenerateVertexWeightArrays(1) + geom = vtk.vtkGeometryFilter() geom.SetInputConnection(chReader.GetOutputPort()) + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(geom.GetOutputPort()) mapper.SetColorModeToMapScalars() mapper.SetScalarModeToUsePointFieldData() mapper.SelectColorArray("VertexWeight1") -mapper.SetScalarRange(1,5) +mapper.SetScalarRange(1, 5) + actor0 = vtk.vtkActor() actor0.SetMapper(mapper) + # Create the RenderWindow, Renderer and interactor # ren1 = vtk.vtkRenderer() @@ -24,12 +32,16 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actor to the renderer, set the background and size # ren1.AddActor(actor0) -ren1.SetBackground(0,0,0) -renWin.SetSize(300,300) +ren1.SetBackground(0, 0, 0) + +renWin.SetSize(300, 300) + iren.Initialize() + renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/IO/Geometry/Testing/Python/TestSimplePointsReader.py b/IO/Geometry/Testing/Python/TestSimplePointsReader.py index e5b953ee616..a8d531bcd31 100755 --- a/IO/Geometry/Testing/Python/TestSimplePointsReader.py +++ b/IO/Geometry/Testing/Python/TestSimplePointsReader.py @@ -1,19 +1,31 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() reader = vtk.vtkSimplePointsReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/points.txt") +reader.SetFileName(VTK_DATA_ROOT + "/Data/points.txt") + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(reader.GetOutputPort()) + actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetPointSize(5) + ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + ren1.AddActor(actor) -renWin.SetSize(300,300) + +renWin.SetSize(300, 300) + iren.Initialize() + renWin.Render() -# --- end of script -- + +#iren.Start() diff --git a/IO/Geometry/Testing/Python/motor.py b/IO/Geometry/Testing/Python/motor.py index 6f3f1b5a82e..806f1c9a141 100755 --- a/IO/Geometry/Testing/Python/motor.py +++ b/IO/Geometry/Testing/Python/motor.py @@ -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 + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -11,103 +20,133 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create cutting planes planes = vtk.vtkPlanes() points = vtk.vtkPoints() norms = vtk.vtkFloatArray() + norms.SetNumberOfComponents(3) -points.InsertPoint(0,0.0,0.0,0.0) -norms.InsertTuple3(0,0.0,0.0,1.0) -points.InsertPoint(1,0.0,0.0,0.0) -norms.InsertTuple3(1,-1.0,0.0,0.0) +points.InsertPoint(0, 0.0, 0.0, 0.0) +norms.InsertTuple3(0, 0.0, 0.0, 1.0) +points.InsertPoint(1, 0.0, 0.0, 0.0) +norms.InsertTuple3(1, -1.0, 0.0, 0.0) planes.SetPoints(points) planes.SetNormals(norms) + # texture texReader = vtk.vtkStructuredPointsReader() -texReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/texThres2.vtk") +texReader.SetFileName(VTK_DATA_ROOT + "/Data/texThres2.vtk") texture = vtk.vtkTexture() texture.SetInputConnection(texReader.GetOutputPort()) texture.InterpolateOff() texture.RepeatOff() + # read motor parts...each part colored separately # byu = vtk.vtkBYUReader() -byu.SetGeometryFileName("" + str(VTK_DATA_ROOT) + "/Data/motor.g") +byu.SetGeometryFileName(VTK_DATA_ROOT + "/Data/motor.g") byu.SetPartNumber(1) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(byu.GetOutputPort()) + tex1 = vtk.vtkImplicitTextureCoords() tex1.SetInputConnection(normals.GetOutputPort()) tex1.SetRFunction(planes) -# tex1 FlipTextureOn +# tex1.FlipTextureOn() + byuMapper = vtk.vtkDataSetMapper() byuMapper.SetInputConnection(tex1.GetOutputPort()) + byuActor = vtk.vtkActor() byuActor.SetMapper(byuMapper) byuActor.SetTexture(texture) -byuActor.GetProperty().SetColor(cold_grey) +byuActor.GetProperty().SetColor(GetRGBColor('cold_grey')) + byu2 = vtk.vtkBYUReader() -byu2.SetGeometryFileName("" + str(VTK_DATA_ROOT) + "/Data/motor.g") +byu2.SetGeometryFileName(VTK_DATA_ROOT + "/Data/motor.g") byu2.SetPartNumber(2) + normals2 = vtk.vtkPolyDataNormals() normals2.SetInputConnection(byu2.GetOutputPort()) + tex2 = vtk.vtkImplicitTextureCoords() tex2.SetInputConnection(normals2.GetOutputPort()) tex2.SetRFunction(planes) -# tex2 FlipTextureOn +# tex2.FlipTextureOn() + byuMapper2 = vtk.vtkDataSetMapper() byuMapper2.SetInputConnection(tex2.GetOutputPort()) + byuActor2 = vtk.vtkActor() byuActor2.SetMapper(byuMapper2) byuActor2.SetTexture(texture) -byuActor2.GetProperty().SetColor(peacock) +byuActor2.GetProperty().SetColor(GetRGBColor('peacock')) + byu3 = vtk.vtkBYUReader() -byu3.SetGeometryFileName("" + str(VTK_DATA_ROOT) + "/Data/motor.g") +byu3.SetGeometryFileName(VTK_DATA_ROOT + "/Data/motor.g") byu3.SetPartNumber(3) + triangle3 = vtk.vtkTriangleFilter() triangle3.SetInputConnection(byu3.GetOutputPort()) + normals3 = vtk.vtkPolyDataNormals() normals3.SetInputConnection(triangle3.GetOutputPort()) + tex3 = vtk.vtkImplicitTextureCoords() tex3.SetInputConnection(normals3.GetOutputPort()) tex3.SetRFunction(planes) -# tex3 FlipTextureOn +# tex3.FlipTextureOn() + byuMapper3 = vtk.vtkDataSetMapper() byuMapper3.SetInputConnection(tex3.GetOutputPort()) + byuActor3 = vtk.vtkActor() byuActor3.SetMapper(byuMapper3) byuActor3.SetTexture(texture) -byuActor3.GetProperty().SetColor(raw_sienna) +byuActor3.GetProperty().SetColor(GetRGBColor('raw_sienna')) + byu4 = vtk.vtkBYUReader() -byu4.SetGeometryFileName("" + str(VTK_DATA_ROOT) + "/Data/motor.g") +byu4.SetGeometryFileName(VTK_DATA_ROOT + "/Data/motor.g") byu4.SetPartNumber(4) + normals4 = vtk.vtkPolyDataNormals() normals4.SetInputConnection(byu4.GetOutputPort()) + tex4 = vtk.vtkImplicitTextureCoords() tex4.SetInputConnection(normals4.GetOutputPort()) tex4.SetRFunction(planes) -# tex4 FlipTextureOn +# tex4.FlipTextureOn() + byuMapper4 = vtk.vtkDataSetMapper() byuMapper4.SetInputConnection(tex4.GetOutputPort()) + byuActor4 = vtk.vtkActor() byuActor4.SetMapper(byuMapper4) byuActor4.SetTexture(texture) -byuActor4.GetProperty().SetColor(banana) +byuActor4.GetProperty().SetColor(GetRGBColor('banana')) + byu5 = vtk.vtkBYUReader() -byu5.SetGeometryFileName("" + str(VTK_DATA_ROOT) + "/Data/motor.g") +byu5.SetGeometryFileName(VTK_DATA_ROOT + "/Data/motor.g") byu5.SetPartNumber(5) + normals5 = vtk.vtkPolyDataNormals() normals5.SetInputConnection(byu5.GetOutputPort()) + tex5 = vtk.vtkImplicitTextureCoords() tex5.SetInputConnection(normals5.GetOutputPort()) tex5.SetRFunction(planes) -# tex5 FlipTextureOn +# tex5.FlipTextureOn() + byuMapper5 = vtk.vtkDataSetMapper() byuMapper5.SetInputConnection(tex5.GetOutputPort()) + byuActor5 = vtk.vtkActor() byuActor5.SetMapper(byuMapper5) byuActor5.SetTexture(texture) -byuActor5.GetProperty().SetColor(peach_puff) +byuActor5.GetProperty().SetColor(GetRGBColor('peach_puff')) + # Add the actors to the renderer, set the background and size # ren1.AddActor(byuActor) @@ -116,16 +155,18 @@ ren1.AddActor(byuActor3) byuActor3.VisibilityOff() ren1.AddActor(byuActor4) ren1.AddActor(byuActor5) -ren1.SetBackground(1,1,1) -renWin.SetSize(300,300) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(300, 300) + camera = vtk.vtkCamera() -camera.SetFocalPoint(0.0286334,0.0362996,0.0379685) -camera.SetPosition(1.37067,1.08629,-1.30349) +camera.SetFocalPoint(0.0286334, 0.0362996, 0.0379685) +camera.SetPosition(1.37067, 1.08629, -1.30349) camera.SetViewAngle(17.673) -camera.SetClippingRange(1,10) -camera.SetViewUp(-0.376306,-0.5085,-0.774482) +camera.SetClippingRange(1, 10) +camera.SetViewUp(-0.376306, -0.5085, -0.774482) ren1.SetActiveCamera(camera) + # render the image iren.Initialize() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/IO/Image/Testing/Python/TestImageWriters.py b/IO/Image/Testing/Python/TestImageWriters.py index fdc3ae9a936..ffdb68c9dae 100755 --- a/IO/Image/Testing/Python/TestImageWriters.py +++ b/IO/Image/Testing/Python/TestImageWriters.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot @@ -6,7 +7,7 @@ VTK_DATA_ROOT = vtkGetDataRoot() # Image pipeline image1 = vtk.vtkTIFFReader() -image1.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/beach.tif") +image1.SetFileName(VTK_DATA_ROOT + "/Data/beach.tif") # "beach.tif" image contains ORIENTATION tag which is # ORIENTATION_TOPLEFT (row 0 top, col 0 lhs) type. The TIFF # reader parses this tag and sets the internal TIFF image @@ -15,89 +16,78 @@ image1.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/beach.tif") # SetOrientationType method with parameter value of 4. image1.SetOrientationType(4) image1.Update() + sp = vtk.vtkStructuredPoints() sp.SetDimensions(image1.GetOutput().GetDimensions()) sp.SetExtent(image1.GetOutput().GetExtent()) -sp.SetScalarType(image1.GetOutput().GetScalarType(),image1.GetOutputInformation(0)) -sp.SetNumberOfScalarComponents(image1.GetOutput().GetNumberOfScalarComponents(),image1.GetOutputInformation(0)) +sp.SetScalarType( + image1.GetOutput().GetScalarType(), image1.GetOutputInformation(0)) +sp.SetNumberOfScalarComponents( + image1.GetOutput().GetNumberOfScalarComponents(), + image1.GetOutputInformation(0)) sp.GetPointData().SetScalars(image1.GetOutput().GetPointData().GetScalars()) + luminance = vtk.vtkImageLuminance() luminance.SetInputData(sp) + +# Let's create a dictionary to test the writers, the key will be the writer +# and the value the file name used by the writer. +filenames = ["tiff1.tif", "tiff2.tif", "bmp1.bmp", "bmp2.bmp", + "pnm1.pnm", "pnm2.pnm", "psw1.ps", "psw2.ps", + "pngw1.png", "pngw2.png", "jpgw1.jpg", "jpgw2.jpg"] +writerObjects = list() +writerObjectTypes = ["vtk.vtkTIFFWriter()", "vtk.vtkBMPWriter()", + "vtk.vtkPNMWriter()", "vtk.vtkPostScriptWriter()", + "vtk.vtkPNGWriter()", "vtk.vtkJPEGWriter()" ] +idx = 0 +for fn in filenames: + # Create the writer object + exec(fn.split(".")[0] + " = " + writerObjectTypes[int(idx / 2)]) + # Append the writer object to the list called writerObjects + writerObjects.append(eval(fn.split(".")[0])) + idx += 1 + +# Now create the dictionary. +writers = dict() +for idx in range(len(writerObjects)): + writers.update({writerObjects[idx]: filenames[idx]}) + # -# write to the temp directory if possible, otherwise use . +# If the current directory is writable, then test the writers # -dir = "." -if (info.commands(globals(), locals(), "rtTester") == "rtTester"): - dir = rtTester.GetTempDirectory() - pass -# make sure it is writeable first -if (catch.catch(globals(),"""channel = open("" + str(dir) + "/test.tmp", "w")""") == 0): - channel.close() - file.delete("-force", "" + str(dir) + "/test.tmp") - tiff1 = vtk.vtkTIFFWriter() - tiff1.SetInputConnection(image1.GetOutputPort()) - tiff1.SetFileName("" + str(dir) + "/tiff1.tif") - tiff2 = vtk.vtkTIFFWriter() - tiff2.SetInputConnection(luminance.GetOutputPort()) - tiff2.SetFileName("" + str(dir) + "/tiff2.tif") - bmp1 = vtk.vtkBMPWriter() - bmp1.SetInputConnection(image1.GetOutputPort()) - bmp1.SetFileName("" + str(dir) + "/bmp1.bmp") - bmp2 = vtk.vtkBMPWriter() - bmp2.SetInputConnection(luminance.GetOutputPort()) - bmp2.SetFileName("" + str(dir) + "/bmp2.bmp") - pnm1 = vtk.vtkPNMWriter() - pnm1.SetInputConnection(image1.GetOutputPort()) - pnm1.SetFileName("" + str(dir) + "/pnm1.pnm") - pnm2 = vtk.vtkPNMWriter() - pnm2.SetInputConnection(luminance.GetOutputPort()) - pnm2.SetFileName("" + str(dir) + "/pnm2.pnm") - psw1 = vtk.vtkPostScriptWriter() - psw1.SetInputConnection(image1.GetOutputPort()) - psw1.SetFileName("" + str(dir) + "/psw1.ps") - psw2 = vtk.vtkPostScriptWriter() - psw2.SetInputConnection(luminance.GetOutputPort()) - psw2.SetFileName("" + str(dir) + "/psw2.ps") - pngw1 = vtk.vtkPNGWriter() - pngw1.SetInputConnection(image1.GetOutputPort()) - pngw1.SetFileName("" + str(dir) + "/pngw1.png") - pngw2 = vtk.vtkPNGWriter() - pngw2.SetInputConnection(luminance.GetOutputPort()) - pngw2.SetFileName("" + str(dir) + "/pngw2.png") - jpgw1 = vtk.vtkJPEGWriter() - jpgw1.SetInputConnection(image1.GetOutputPort()) - jpgw1.SetFileName("" + str(dir) + "/jpgw1.jpg") - jpgw2 = vtk.vtkJPEGWriter() - jpgw2.SetInputConnection(luminance.GetOutputPort()) - jpgw2.SetFileName("" + str(dir) + "/jpgw2.jpg") - tiff1.Write() - tiff2.Write() - bmp1.Write() - bmp2.Write() - pnm1.Write() - pnm2.Write() - psw1.Write() - psw2.Write() - pngw1.Write() - pngw2.Write() - jpgw1.Write() - jpgw2.Write() - file.delete("-force", "" + str(dir) + "/tiff1.tif") - file.delete("-force", "" + str(dir) + "/tiff2.tif") - file.delete("-force", "" + str(dir) + "/bmp1.bmp") - file.delete("-force", "" + str(dir) + "/bmp2.bmp") - file.delete("-force", "" + str(dir) + "/pnm1.pnm") - file.delete("-force", "" + str(dir) + "/pnm2.pnm") - file.delete("-force", "" + str(dir) + "/psw1.ps") - file.delete("-force", "" + str(dir) + "/psw2.ps") - file.delete("-force", "" + str(dir) + "/pngw1.png") - file.delete("-force", "" + str(dir) + "/pngw2.png") - file.delete("-force", "" + str(dir) + "/jpgw1.jpg") - file.delete("-force", "" + str(dir) + "/jpgw2.jpg") - pass -viewer = vtk.vtkImageViewer() -viewer.SetInputConnection(luminance.GetOutputPort()) -viewer.SetColorWindow(255) -viewer.SetColorLevel(127.5) -viewer.Render() -# --- end of script -- +try: + for writer in writers: + # The file name + fn = writers[writer] + # Use the file name to determine whether we are working + # with the image or luninance. + il = int(fn.split(".")[0][-1:]) + + # Can we write to the directory? + channel = open(fn, "wb") + channel.close() + + if il == 1: + writer.SetInputConnection(image1.GetOutputPort()) + elif il == 2: + writer.SetInputConnection(luminance.GetOutputPort()) + else: + continue + writer.SetFileName(fn) + writer.Write() + + # cleanup + # + try: + os.remove(fn) + except OSError: + pass + + viewer = vtk.vtkImageViewer() + viewer.SetInputConnection(luminance.GetOutputPort()) + viewer.SetColorWindow(255) + viewer.SetColorLevel(127.5) + viewer.Render() + +except IOError: + print "Unable to test the writers." diff --git a/IO/Image/Testing/Python/TestMetaImage2D.py b/IO/Image/Testing/Python/TestMetaImage2D.py index 7ff51e6bd63..2beca609a15 100755 --- a/IO/Image/Testing/Python/TestMetaImage2D.py +++ b/IO/Image/Testing/Python/TestMetaImage2D.py @@ -1,14 +1,22 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # This scripts shows a compressed spectrum of an image. # Image pipeline reader = vtk.vtkMetaImageReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/foot/foot.mha") +reader.SetFileName(VTK_DATA_ROOT + "/Data/foot/foot.mha") + viewer = vtk.vtkImageViewer2() viewer.SetInputConnection(reader.GetOutputPort()) viewer.SetColorWindow(255) viewer.SetColorLevel(127.5) + viewInt = vtk.vtkRenderWindowInteractor() viewer.SetupInteractor(viewInt) viewer.Render() -# --- end of script -- + +# This is needed if you want to interact with the image. +# viewInt.Start() diff --git a/IO/Image/Testing/Python/TestSetFileNames.py b/IO/Image/Testing/Python/TestSetFileNames.py index f7d9671e194..8cee89f1782 100755 --- a/IO/Image/Testing/Python/TestSetFileNames.py +++ b/IO/Image/Testing/Python/TestSetFileNames.py @@ -1,14 +1,21 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() globFileNames = vtk.vtkGlobFileNames() -globFileNames.AddFileNames("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter.*") +globFileNames.AddFileNames(VTK_DATA_ROOT + "/Data/headsq/quarter.*") + sortFileNames = vtk.vtkSortFileNames() sortFileNames.SetInputFileNames(globFileNames.GetFileNames()) sortFileNames.NumericSortOn() + reader = vtk.vtkImageReader2() reader.SetFileNames(sortFileNames.GetFileNames()) -reader.SetDataExtent(0,63,0,63,1,1) +reader.SetDataExtent(0, 63, 0, 63, 1, 1) reader.SetDataByteOrderToLittleEndian() + # set Z slice to 2: if output is not numerically sorted, the wrong # slice will be shown viewer = vtk.vtkImageViewer() @@ -16,7 +23,5 @@ viewer.SetInputConnection(reader.GetOutputPort()) viewer.SetZSlice(2) viewer.SetColorWindow(2000) viewer.SetColorLevel(1000) -viewer.GetRenderer().SetBackground(0,0,0) +viewer.GetRenderer().SetBackground(0, 0, 0) viewer.Render() -del reader -# --- end of script -- diff --git a/IO/Image/Testing/Python/dem.py b/IO/Image/Testing/Python/dem.py index 0273613b9a4..64597623d09 100755 --- a/IO/Image/Testing/Python/dem.py +++ b/IO/Image/Testing/Python/dem.py @@ -11,74 +11,91 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + Scale = 5 + lut = vtk.vtkLookupTable() -lut.SetHueRange(0.6,0) -lut.SetSaturationRange(1.0,0) -lut.SetValueRange(0.5,1.0) +lut.SetHueRange(0.6, 0) +lut.SetSaturationRange(1.0, 0) +lut.SetValueRange(0.5, 1.0) + demModel = vtk.vtkDEMReader() -demModel.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/SainteHelens.dem") +demModel.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem") demModel.Update() -catch.catch(globals(),"""#demModel.Print()""") -lo = expr.expr(globals(), locals(),["Scale","*","lindex(demModel.GetElevationBounds(),0)"]) -hi = expr.expr(globals(), locals(),["Scale","*","lindex(demModel.GetElevationBounds(),1)"]) + +lo = Scale * demModel.GetElevationBounds()[0] +hi = Scale * demModel.GetElevationBounds()[1] demActor = vtk.vtkLODActor() + # create a pipeline for each lod mapper -lods = "4 8 16" -for lod in lods.split(): - locals()[get_variable_name("shrink", lod, "")] = vtk.vtkImageShrink3D() - locals()[get_variable_name("shrink", lod, "")].SetShrinkFactors(expr.expr(globals(), locals(),["int","(","lod",")"]),expr.expr(globals(), locals(),["int","(","lod",")"]),1) - locals()[get_variable_name("shrink", lod, "")].SetInputConnection(demModel.GetOutputPort()) - locals()[get_variable_name("shrink", lod, "")].AveragingOn() - locals()[get_variable_name("geom", lod, "")] = vtk.vtkImageDataGeometryFilter() - locals()[get_variable_name("geom", lod, "")].SetInputConnection(locals()[get_variable_name("shrink", lod, "")].GetOutputPort()) - locals()[get_variable_name("geom", lod, "")].ReleaseDataFlagOn() - locals()[get_variable_name("warp", lod, "")] = vtk.vtkWarpScalar() - locals()[get_variable_name("warp", lod, "")].SetInputConnection(locals()[get_variable_name("geom", lod, "")].GetOutputPort()) - locals()[get_variable_name("warp", lod, "")].SetNormal(0,0,1) - locals()[get_variable_name("warp", lod, "")].UseNormalOn() - locals()[get_variable_name("warp", lod, "")].SetScaleFactor(Scale) - locals()[get_variable_name("warp", lod, "")].ReleaseDataFlagOn() - locals()[get_variable_name("elevation", lod, "")] = vtk.vtkElevationFilter() - locals()[get_variable_name("elevation", lod, "")].SetInputConnection(locals()[get_variable_name("warp", lod, "")].GetOutputPort()) - locals()[get_variable_name("elevation", lod, "")].SetLowPoint(0,0,lo) - locals()[get_variable_name("elevation", lod, "")].SetHighPoint(0,0,hi) - locals()[get_variable_name("elevation", lod, "")].SetScalarRange(lo,hi) - locals()[get_variable_name("elevation", lod, "")].ReleaseDataFlagOn() - locals()[get_variable_name("toPoly", lod, "")] = vtk.vtkCastToConcrete() - locals()[get_variable_name("toPoly", lod, "")].SetInputConnection(locals()[get_variable_name("elevation", lod, "")].GetOutputPort()) - locals()[get_variable_name("normals", lod, "")] = vtk.vtkPolyDataNormals() - locals()[get_variable_name("normals", lod, "")].SetInputConnection(locals()[get_variable_name("toPoly", lod, "")].GetOutputPort()) - locals()[get_variable_name("normals", lod, "")].SetFeatureAngle(60) - locals()[get_variable_name("normals", lod, "")].ConsistencyOff() - locals()[get_variable_name("normals", lod, "")].SplittingOff() - locals()[get_variable_name("normals", lod, "")].ReleaseDataFlagOn() - locals()[get_variable_name("demMapper", lod, "")] = vtk.vtkPolyDataMapper() - locals()[get_variable_name("demMapper", lod, "")].SetInputConnection(locals()[get_variable_name("normals", lod, "")].GetOutputPort()) - locals()[get_variable_name("demMapper", lod, "")].SetScalarRange(lo,hi) - locals()[get_variable_name("demMapper", lod, "")].SetLookupTable(lut) - locals()[get_variable_name("demMapper", lod, "")].ImmediateModeRenderingOn() - locals()[get_variable_name("demMapper", lod, "")].Update() - demActor.AddLODMapper(locals()[get_variable_name("demMapper", lod, "")]) - - pass +lods = ["4", "8", "16"] +for lod in lods: + exec("shrink" + lod + " = vtk.vtkImageShrink3D()") + eval("shrink" + lod).SetShrinkFactors(int(lod), int(lod), 1) + eval("shrink" + lod).SetInputConnection(demModel.GetOutputPort()) + eval("shrink" + lod).AveragingOn() + + exec("geom" + lod + " = vtk.vtkImageDataGeometryFilter()") + eval("geom" + lod).SetInputConnection(eval("shrink" + lod).GetOutputPort()) + eval("geom" + lod).ReleaseDataFlagOn() + + exec("warp" + lod + " = vtk.vtkWarpScalar()") + eval("warp" + lod).SetInputConnection(eval("geom" + lod).GetOutputPort()) + eval("warp" + lod).SetNormal(0, 0, 1) + eval("warp" + lod).UseNormalOn() + eval("warp" + lod).SetScaleFactor(Scale) + eval("warp" + lod).ReleaseDataFlagOn() + + exec("elevation" + lod + " = vtk.vtkElevationFilter()") + eval("elevation" + lod).SetInputConnection( + eval("warp" + lod).GetOutputPort()) + eval("elevation" + lod).SetLowPoint(0, 0, lo) + eval("elevation" + lod).SetHighPoint(0, 0, hi) + eval("elevation" + lod).SetScalarRange(lo, hi) + eval("elevation" + lod).ReleaseDataFlagOn() + + exec("toPoly" + lod + " = vtk.vtkCastToConcrete()") + eval("toPoly" + lod).SetInputConnection( + eval("elevation" + lod).GetOutputPort()) + + exec("normals" + lod + " = vtk.vtkPolyDataNormals()") + eval("normals" + lod).SetInputConnection( + eval("toPoly" + lod).GetOutputPort()) + eval("normals" + lod).SetFeatureAngle(60) + eval("normals" + lod).ConsistencyOff() + eval("normals" + lod).SplittingOff() + eval("normals" + lod).ReleaseDataFlagOn() + + exec("demMapper" + lod + " = vtk.vtkPolyDataMapper()") + eval("demMapper" + lod).SetInputConnection( + eval("normals" + lod).GetOutputPort()) + eval("demMapper" + lod).SetScalarRange(lo, hi) + eval("demMapper" + lod).SetLookupTable(lut) + eval("demMapper" + lod).ImmediateModeRenderingOn() + eval("demMapper" + lod).Update() + + demActor.AddLODMapper(eval("demMapper" + lod)) + # Add the actors to the renderer, set the background and size # ren1.AddActor(demActor) -ren1.SetBackground(.4,.4,.4) +ren1.SetBackground(.4, .4, .4) iren.SetDesiredUpdateRate(1) -def TkCheckAbort (__vtk__temp0=0,__vtk__temp1=0): + +def TkCheckAbort (object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) - pass -renWin.AddObserver("AbortCheckEvent",TkCheckAbort) -ren1.GetActiveCamera().SetViewUp(0,0,1) -ren1.GetActiveCamera().SetPosition(-99900,-21354,131801) -ren1.GetActiveCamera().SetFocalPoint(41461,41461,2815) +renWin.AddObserver("AbortCheckEvent", TkCheckAbort) + +ren1.GetActiveCamera().SetViewUp(0, 0, 1) +ren1.GetActiveCamera().SetPosition(-99900, -21354, 131801) +ren1.GetActiveCamera().SetFocalPoint(41461, 41461, 2815) ren1.ResetCamera() ren1.GetActiveCamera().Dolly(1.2) ren1.ResetCameraClippingRange() + renWin.Render() -# --- end of script -- + +#iren.Start() diff --git a/IO/MINC/Testing/Python/TestMINCImageReader.py b/IO/MINC/Testing/Python/TestMINCImageReader.py index 51d561a8b5a..7eae483ca40 100755 --- a/IO/MINC/Testing/Python/TestMINCImageReader.py +++ b/IO/MINC/Testing/Python/TestMINCImageReader.py @@ -1,14 +1,17 @@ #!/usr/bin/env python import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Image pipeline reader = vtk.vtkMINCImageReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/t3_grid_0.mnc") +reader.SetFileName(VTK_DATA_ROOT + "/Data/t3_grid_0.mnc") viewer = vtk.vtkImageViewer() viewer.SetInputConnection(reader.GetOutputPort()) viewer.SetColorWindow(65535) viewer.SetColorLevel(0) -#make interface +# make interface viewer.Render() diff --git a/IO/MINC/Testing/Python/TestMINCImageWriter.py b/IO/MINC/Testing/Python/TestMINCImageWriter.py index a1330dbf2ad..12c4364e8f4 100755 --- a/IO/MINC/Testing/Python/TestMINCImageWriter.py +++ b/IO/MINC/Testing/Python/TestMINCImageWriter.py @@ -1,54 +1,76 @@ #!/usr/bin/env python +import os +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Image pipeline reader = vtk.vtkMINCImageReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/t3_grid_0.mnc") +reader.SetFileName(VTK_DATA_ROOT + "/Data/t3_grid_0.mnc") reader.RescaleRealValuesOn() attributes = vtk.vtkMINCImageAttributes() image = reader + +# The current directory must be writeable. # -# write to the temp directory if possible, otherwise use . -# -dir = "." -if (info.commands(globals(), locals(), "rtTester") == "rtTester"): - dir = rtTester.GetTempDirectory() - pass -# make sure it is writeable first -if (catch.catch(globals(),"""channel = open("" + str(dir) + "/test.tmp", "w")""") == 0): +try: + channel = open("minc1.mnc", "wb") channel.close() - file.delete("-force", "" + str(dir) + "/test.tmp") + minc1 = vtk.vtkMINCImageWriter() minc1.SetInputConnection(reader.GetOutputPort()) - minc1.SetFileName("" + str(dir) + "/minc1.mnc") + minc1.SetFileName("minc1.mnc") + attributes.ShallowCopy(reader.GetImageAttributes()) - attributes.SetAttributeValueAsString("patient","full_name","DOE^JOHN DAVID") + attributes.SetAttributeValueAsString( + "patient", "full_name", "DOE^JOHN DAVID") + minc2 = vtk.vtkMINCImageWriter() minc2.SetImageAttributes(attributes) minc2.SetInputConnection(reader.GetOutputPort()) - minc2.SetFileName("" + str(dir) + "/minc2.mnc") + minc2.SetFileName("minc2.mnc") + minc3 = vtk.vtkMINCImageWriter() minc3.SetImageAttributes(attributes) minc3.AddInputConnection(reader.GetOutputPort()) minc3.AddInputConnection(reader.GetOutputPort()) - minc3.SetFileName("" + str(dir) + "/minc3.mnc") + minc3.SetFileName("minc3.mnc") + minc1.Write() minc2.Write() minc3.Write() + reader2 = vtk.vtkMINCImageReader() - reader2.SetFileName("" + str(dir) + "/minc3.mnc") + reader2.SetFileName("minc3.mnc") reader2.RescaleRealValuesOn() reader2.SetTimeStep(1) reader2.Update() image = reader2 - file.delete("-force", "" + str(dir) + "/minc1.mnc") - file.delete("-force", "" + str(dir) + "/minc2.mnc") - file.delete("-force", "" + str(dir) + "/minc3.mnc") - # write out the file header for coverage + + # cleanup + # + try: + os.remove("minc1.mnc") + except OSError: + pass + try: + os.remove("minc2.mnc") + except OSError: + pass + try: + os.remove("minc3.mnc") + except OSError: + pass + + # Write out the file header for coverage attributes.PrintFileHeader() - pass -viewer = vtk.vtkImageViewer() -viewer.SetInputConnection(image.GetOutputPort()) -viewer.SetColorWindow(100) -viewer.SetColorLevel(0) -viewer.Render() -# --- end of script -- + + viewer = vtk.vtkImageViewer() + viewer.SetInputConnection(image.GetOutputPort()) + viewer.SetColorWindow(100) + viewer.SetColorLevel(0) + viewer.Render() + +except IOError: + print "Unable to test the writer/reader." diff --git a/IO/MINC/Testing/Python/TestMNIObjects.py b/IO/MINC/Testing/Python/TestMNIObjects.py index 1bcb8ab976e..507ed517676 100755 --- a/IO/MINC/Testing/Python/TestMNIObjects.py +++ b/IO/MINC/Testing/Python/TestMNIObjects.py @@ -1,110 +1,141 @@ #!/usr/bin/env python +import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() +# The current directory must be writeable. # -# write to the temp directory if possible, otherwise use . -# -dir = "." -if (info.commands(globals(), locals(), "rtTester") == "rtTester"): - dir = rtTester.GetTempDirectory() - pass -ren1 = vtk.vtkRenderer() -ren1.SetViewport(0,0,0.33,1) -ren2 = vtk.vtkRenderer() -ren2.SetViewport(0.33,0,0.67,1) -ren3 = vtk.vtkRenderer() -ren3.SetViewport(0.67,0,1,1) -renWin = vtk.vtkRenderWindow() -renWin.SetSize(600,200) -renWin.AddRenderer(ren1) -renWin.AddRenderer(ren2) -renWin.AddRenderer(ren3) -renWin.SetMultiSamples(0) -property0 = vtk.vtkProperty() -property0.SetDiffuseColor(0.95,0.90,0.70) -filename = "" + str(VTK_DATA_ROOT) + "/Data/mni-surface-mesh.obj" -asciiReader = vtk.vtkMNIObjectReader() -property1 = asciiReader.GetProperty() -if (asciiReader.CanReadFile("" + str(filename) + "") != 0): - asciiReader.SetFileName("" + str(filename) + "") - pass -# this is just to remove the normals, to increase coverage, -# i.e. by forcing the writer to generate normals -removeNormals = vtk.vtkClipClosedSurface() -removeNormals.SetInputConnection(asciiReader.GetOutputPort()) -# this is to make triangle strips, also to increase coverage, -# because it forces the writer to decompose the strips -stripper = vtk.vtkStripper() -stripper.SetInputConnection(removeNormals.GetOutputPort()) -# test binary writing and reading for polygons -binaryWriter = vtk.vtkMNIObjectWriter() -binaryWriter.SetInputConnection(stripper.GetOutputPort()) -binaryWriter.SetFileName("" + str(dir) + "/mni-surface-mesh-binary.obj") -binaryWriter.SetProperty(property0) -binaryWriter.SetFileTypeToBinary() -binaryWriter.Write() -binaryReader = vtk.vtkMNIObjectReader() -binaryReader.SetFileName("" + str(dir) + "/mni-surface-mesh-binary.obj") -property2 = binaryReader.GetProperty() -# make a polyline object with color scalars -scalars = vtk.vtkCurvatures() -scalars.SetInputConnection(asciiReader.GetOutputPort()) -colors = vtk.vtkLookupTable() -colors.SetRange(-14.5104,29.0208) -colors.SetAlphaRange(1.0,1.0) -colors.SetSaturationRange(1.0,1.0) -colors.SetValueRange(1.0,1.0) -colors.SetHueRange(0.0,1.0) -colors.Build() -# this is just to test using the SetMapper option of vtkMNIObjectWriter -mapper = vtk.vtkDataSetMapper() -mapper.SetLookupTable(colors) -mapper.UseLookupTableScalarRangeOn() -edges = vtk.vtkExtractEdges() -edges.SetInputConnection(scalars.GetOutputPort()) -# test ascii writing and reading for lines -lineWriter = vtk.vtkMNIObjectWriter() -lineWriter.SetMapper(mapper) -#lineWriter SetLookupTable colors -lineWriter.SetInputConnection(edges.GetOutputPort()) -lineWriter.SetFileName("" + str(dir) + "/mni-wire-mesh-ascii.obj") -lineWriter.Write() -lineReader = vtk.vtkMNIObjectReader() -lineReader.SetFileName("" + str(dir) + "/mni-wire-mesh-ascii.obj") -# display all the results -mapper1 = vtk.vtkDataSetMapper() -mapper1.SetInputConnection(asciiReader.GetOutputPort()) -mapper2 = vtk.vtkDataSetMapper() -mapper2.SetInputConnection(binaryReader.GetOutputPort()) -mapper3 = vtk.vtkDataSetMapper() -mapper3.SetInputConnection(lineReader.GetOutputPort()) -actor1 = vtk.vtkActor() -actor1.SetMapper(mapper1) -actor1.SetProperty(property1) -actor2 = vtk.vtkActor() -actor2.SetMapper(mapper2) -actor2.SetProperty(property2) -actor3 = vtk.vtkActor() -actor3.SetMapper(mapper3) -ren1.AddActor(actor1) -ren2.AddActor(actor2) -ren3.AddActor(actor3) -iren = vtk.vtkRenderWindowInteractor() -iren.SetRenderWindow(renWin) -ren1.ResetCamera() -ren1.GetActiveCamera().Dolly(1.2) -ren1.ResetCameraClippingRange() -ren2.ResetCamera() -ren2.GetActiveCamera().Dolly(1.2) -ren2.ResetCameraClippingRange() -ren3.ResetCamera() -ren3.GetActiveCamera().Dolly(1.2) -ren3.ResetCameraClippingRange() -iren.Render() -# render the image -# -iren.Initialize() -# --- end of script -- +try: + channel = open("mni-surface-mesh-binary.obj", "wb") + channel.close() + + ren1 = vtk.vtkRenderer() + ren1.SetViewport(0, 0, 0.33, 1) + ren2 = vtk.vtkRenderer() + ren2.SetViewport(0.33, 0, 0.67, 1) + ren3 = vtk.vtkRenderer() + ren3.SetViewport(0.67, 0, 1, 1) + renWin = vtk.vtkRenderWindow() + renWin.SetSize(600, 200) + renWin.AddRenderer(ren1) + renWin.AddRenderer(ren2) + renWin.AddRenderer(ren3) + renWin.SetMultiSamples(0) + property0 = vtk.vtkProperty() + property0.SetDiffuseColor(0.95, 0.90, 0.70) + filename = VTK_DATA_ROOT + "/Data/mni-surface-mesh.obj" + asciiReader = vtk.vtkMNIObjectReader() + property1 = asciiReader.GetProperty() + if (asciiReader.CanReadFile(str(filename)) != 0): + asciiReader.SetFileName(str(filename)) + + # this is just to remove the normals, to increase coverage, + # i.e. by forcing the writer to generate normals + removeNormals = vtk.vtkClipClosedSurface() + removeNormals.SetInputConnection(asciiReader.GetOutputPort()) + + # this is to make triangle strips, also to increase coverage, + # because it forces the writer to decompose the strips + stripper = vtk.vtkStripper() + stripper.SetInputConnection(removeNormals.GetOutputPort()) + + # test binary writing and reading for polygons + binaryWriter = vtk.vtkMNIObjectWriter() + binaryWriter.SetInputConnection(stripper.GetOutputPort()) + binaryWriter.SetFileName("mni-surface-mesh-binary.obj") + binaryWriter.SetProperty(property0) + binaryWriter.SetFileTypeToBinary() + binaryWriter.Write() + + binaryReader = vtk.vtkMNIObjectReader() + binaryReader.SetFileName("mni-surface-mesh-binary.obj") + + property2 = binaryReader.GetProperty() + + # make a polyline object with color scalars + scalars = vtk.vtkCurvatures() + scalars.SetInputConnection(asciiReader.GetOutputPort()) + + colors = vtk.vtkLookupTable() + colors.SetRange(-14.5104, 29.0208) + colors.SetAlphaRange(1.0, 1.0) + colors.SetSaturationRange(1.0, 1.0) + colors.SetValueRange(1.0, 1.0) + colors.SetHueRange(0.0, 1.0) + colors.Build() + + # this is just to test using the SetMapper option of vtkMNIObjectWriter + mapper = vtk.vtkDataSetMapper() + mapper.SetLookupTable(colors) + mapper.UseLookupTableScalarRangeOn() + edges = vtk.vtkExtractEdges() + edges.SetInputConnection(scalars.GetOutputPort()) + # test ascii writing and reading for lines + lineWriter = vtk.vtkMNIObjectWriter() + lineWriter.SetMapper(mapper) + # lineWriter SetLookupTable colors + lineWriter.SetInputConnection(edges.GetOutputPort()) + lineWriter.SetFileName("mni-wire-mesh-ascii.obj") + lineWriter.Write() + + lineReader = vtk.vtkMNIObjectReader() + lineReader.SetFileName("mni-wire-mesh-ascii.obj") + + # display all the results + mapper1 = vtk.vtkDataSetMapper() + mapper1.SetInputConnection(asciiReader.GetOutputPort()) + + mapper2 = vtk.vtkDataSetMapper() + mapper2.SetInputConnection(binaryReader.GetOutputPort()) + + mapper3 = vtk.vtkDataSetMapper() + mapper3.SetInputConnection(lineReader.GetOutputPort()) + + actor1 = vtk.vtkActor() + actor1.SetMapper(mapper1) + actor1.SetProperty(property1) + + actor2 = vtk.vtkActor() + actor2.SetMapper(mapper2) + actor2.SetProperty(property2) + + actor3 = vtk.vtkActor() + actor3.SetMapper(mapper3) + + ren1.AddActor(actor1) + ren2.AddActor(actor2) + ren3.AddActor(actor3) + + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) + ren1.ResetCamera() + ren1.GetActiveCamera().Dolly(1.2) + ren1.ResetCameraClippingRange() + ren2.ResetCamera() + ren2.GetActiveCamera().Dolly(1.2) + ren2.ResetCameraClippingRange() + ren3.ResetCamera() + ren3.GetActiveCamera().Dolly(1.2) + ren3.ResetCameraClippingRange() + iren.Render() + + # cleanup + # + try: + os.remove("mni-surface-mesh-binary.obj") + except OSError: + pass + try: + os.remove("mni-wire-mesh-ascii.obj") + except OSError: + pass + + # render the image + # + iren.Initialize() +# iren.Start() + +except IOError: + print "Unable to test the writer/reader." diff --git a/IO/MINC/Testing/Python/TestMNITagPoints.py b/IO/MINC/Testing/Python/TestMNITagPoints.py index 2f8ca729ebd..7d3279e0102 100755 --- a/IO/MINC/Testing/Python/TestMNITagPoints.py +++ b/IO/MINC/Testing/Python/TestMNITagPoints.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot @@ -6,102 +7,126 @@ VTK_DATA_ROOT = vtkGetDataRoot() # Test label reading from an MNI tag file # -# write to the temp directory if possible, otherwise use . -# -dir = "." -if (info.commands(globals(), locals(), "rtTester") == "rtTester"): - dir = rtTester.GetTempDirectory() - pass -# create some random points in a sphere -# -sphere1 = vtk.vtkPointSource() -sphere1.SetNumberOfPoints(13) -xform = vtk.vtkTransform() -xform.RotateWXYZ(20,1,0,0) -xformFilter = vtk.vtkTransformFilter() -xformFilter.SetTransform(xform) -xformFilter.SetInputConnection(sphere1.GetOutputPort()) -labels = vtk.vtkStringArray() -labels.InsertNextValue("0") -labels.InsertNextValue("1") -labels.InsertNextValue("2") -labels.InsertNextValue("3") -labels.InsertNextValue("Halifax") -labels.InsertNextValue("Toronto") -labels.InsertNextValue("Vancouver") -labels.InsertNextValue("Larry") -labels.InsertNextValue("Bob") -labels.InsertNextValue("Jackie") -labels.InsertNextValue("10") -labels.InsertNextValue("11") -labels.InsertNextValue("12") -weights = vtk.vtkDoubleArray() -weights.InsertNextValue(1.0) -weights.InsertNextValue(1.1) -weights.InsertNextValue(1.2) -weights.InsertNextValue(1.3) -weights.InsertNextValue(1.4) -weights.InsertNextValue(1.5) -weights.InsertNextValue(1.6) -weights.InsertNextValue(1.7) -weights.InsertNextValue(1.8) -weights.InsertNextValue(1.9) -weights.InsertNextValue(0.9) -weights.InsertNextValue(0.8) -weights.InsertNextValue(0.7) -fname = "" + str(dir) + "/mni-tagtest.tag" -writer = vtk.vtkMNITagPointWriter() -writer.SetFileName("" + str(fname) + "") -writer.SetInputConnection(sphere1.GetOutputPort()) -writer.SetInputConnection(1,xformFilter.GetOutputPort()) -writer.SetLabelText(labels) -writer.SetWeights(weights) -writer.SetComments("Volume 1: sphere points\nVolume 2: transformed points") -writer.Write() -reader = vtk.vtkMNITagPointReader() -reader.CanReadFile("" + str(fname) + "") -reader.SetFileName("" + str(fname) + "") -textProp = vtk.vtkTextProperty() -textProp.SetFontSize(12) -textProp.SetColor(1.0,1.0,0.5) -labelHier = vtk.vtkPointSetToLabelHierarchy() -labelHier.SetInputConnection(reader.GetOutputPort()) -labelHier.SetTextProperty(textProp) -labelHier.SetLabelArrayName("LabelText") -labelHier.SetMaximumDepth(15) -labelHier.SetTargetLabelCount(12) -labelMapper = vtk.vtkLabelPlacementMapper() -labelMapper.SetInputConnection(labelHier.GetOutputPort()) -labelMapper.UseDepthBufferOff() -labelMapper.SetShapeToRect() -labelMapper.SetStyleToOutline() -labelActor = vtk.vtkActor2D() -labelActor.SetMapper(labelMapper) -glyphSource = vtk.vtkSphereSource() -glyphSource.SetRadius(0.01) -glyph = vtk.vtkGlyph3D() -glyph.SetSourceConnection(glyphSource.GetOutputPort()) -glyph.SetInputConnection(reader.GetOutputPort()) -mapper = vtk.vtkDataSetMapper() -mapper.SetInputConnection(glyph.GetOutputPort()) -actor = vtk.vtkActor() -actor.SetMapper(mapper) -# Create rendering stuff -ren1 = vtk.vtkRenderer() -renWin = vtk.vtkRenderWindow() -renWin.SetMultiSamples(0) -renWin.AddRenderer(ren1) -iren = vtk.vtkRenderWindowInteractor() -iren.SetRenderWindow(renWin) -# Add the actors to the renderer, set the background and size -# -ren1.AddViewProp(actor) -ren1.AddViewProp(labelActor) -ren1.SetBackground(0,0,0) -renWin.SetSize(300,300) -renWin.Render() -# render the image + +# The current directory must be writeable. # -renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +try: + fname = "mni-tagtest.tag" + channel = open(fname, "wb") + channel.close() + + # create some random points in a sphere + # + sphere1 = vtk.vtkPointSource() + sphere1.SetNumberOfPoints(13) + + xform = vtk.vtkTransform() + xform.RotateWXYZ(20, 1, 0, 0) + + xformFilter = vtk.vtkTransformFilter() + xformFilter.SetTransform(xform) + xformFilter.SetInputConnection(sphere1.GetOutputPort()) + + labels = vtk.vtkStringArray() + labels.InsertNextValue("0") + labels.InsertNextValue("1") + labels.InsertNextValue("2") + labels.InsertNextValue("3") + labels.InsertNextValue("Halifax") + labels.InsertNextValue("Toronto") + labels.InsertNextValue("Vancouver") + labels.InsertNextValue("Larry") + labels.InsertNextValue("Bob") + labels.InsertNextValue("Jackie") + labels.InsertNextValue("10") + labels.InsertNextValue("11") + labels.InsertNextValue("12") + + weights = vtk.vtkDoubleArray() + weights.InsertNextValue(1.0) + weights.InsertNextValue(1.1) + weights.InsertNextValue(1.2) + weights.InsertNextValue(1.3) + weights.InsertNextValue(1.4) + weights.InsertNextValue(1.5) + weights.InsertNextValue(1.6) + weights.InsertNextValue(1.7) + weights.InsertNextValue(1.8) + weights.InsertNextValue(1.9) + weights.InsertNextValue(0.9) + weights.InsertNextValue(0.8) + weights.InsertNextValue(0.7) + + writer = vtk.vtkMNITagPointWriter() + writer.SetFileName(fname) + writer.SetInputConnection(sphere1.GetOutputPort()) + writer.SetInputConnection(1, xformFilter.GetOutputPort()) + writer.SetLabelText(labels) + writer.SetWeights(weights) + writer.SetComments("Volume 1: sphere points\nVolume 2: transformed points") + writer.Write() + + reader = vtk.vtkMNITagPointReader() + reader.CanReadFile(fname) + reader.SetFileName(fname) + + textProp = vtk.vtkTextProperty() + textProp.SetFontSize(12) + textProp.SetColor(1.0, 1.0, 0.5) + + labelHier = vtk.vtkPointSetToLabelHierarchy() + labelHier.SetInputConnection(reader.GetOutputPort()) + labelHier.SetTextProperty(textProp) + labelHier.SetLabelArrayName("LabelText") + labelHier.SetMaximumDepth(15) + labelHier.SetTargetLabelCount(12) + + labelMapper = vtk.vtkLabelPlacementMapper() + labelMapper.SetInputConnection(labelHier.GetOutputPort()) + labelMapper.UseDepthBufferOff() + labelMapper.SetShapeToRect() + labelMapper.SetStyleToOutline() + + labelActor = vtk.vtkActor2D() + labelActor.SetMapper(labelMapper) + + glyphSource = vtk.vtkSphereSource() + glyphSource.SetRadius(0.01) + + glyph = vtk.vtkGlyph3D() + glyph.SetSourceConnection(glyphSource.GetOutputPort()) + glyph.SetInputConnection(reader.GetOutputPort()) + + mapper = vtk.vtkDataSetMapper() + mapper.SetInputConnection(glyph.GetOutputPort()) + + actor = vtk.vtkActor() + actor.SetMapper(mapper) + + # Create rendering stuff + ren1 = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() + renWin.SetMultiSamples(0) + renWin.AddRenderer(ren1) + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size + # + ren1.AddViewProp(actor) + ren1.AddViewProp(labelActor) + ren1.SetBackground(0, 0, 0) + + renWin.SetSize(300, 300) + + renWin.Render() + try: + os.remove(fname) + except OSError: + pass + + # render the image + # +# iren.Start() + +except IOError: + print "Unable to test the writer/reader." diff --git a/IO/MINC/Testing/Python/TestMNITransforms.py b/IO/MINC/Testing/Python/TestMNITransforms.py index 0445406062a..325ade0b120 100755 --- a/IO/MINC/Testing/Python/TestMNITransforms.py +++ b/IO/MINC/Testing/Python/TestMNITransforms.py @@ -1,122 +1,156 @@ #!/usr/bin/env python +import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() +# The current directory must be writeable. # -# write to the temp directory if possible, otherwise use . -# -dir = "." -if (info.commands(globals(), locals(), "rtTester") == "rtTester"): - dir = rtTester.GetTempDirectory() - pass -# first, create an image to warp -imageGrid = vtk.vtkImageGridSource() -imageGrid.SetGridSpacing(16,16,0) -imageGrid.SetGridOrigin(0,0,0) -imageGrid.SetDataExtent(0,255,0,255,0,0) -imageGrid.SetDataScalarTypeToUnsignedChar() -table = vtk.vtkLookupTable() -table.SetTableRange(0,1) -table.SetValueRange(1.0,0.0) -table.SetSaturationRange(0.0,0.0) -table.SetHueRange(0.0,0.0) -table.SetAlphaRange(0.0,1.0) -table.Build() -alpha = vtk.vtkImageMapToColors() -alpha.SetInputConnection(imageGrid.GetOutputPort()) -alpha.SetLookupTable(table) -reader1 = vtk.vtkBMPReader() -reader1.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/masonry.bmp") -blend = vtk.vtkImageBlend() -blend.AddInputConnection(reader1.GetOutputPort()) -blend.AddInputConnection(alpha.GetOutputPort()) -# next, create a ThinPlateSpline transform -p1 = vtk.vtkPoints() -p1.SetNumberOfPoints(8) -p1.SetPoint(0,0,0,0) -p1.SetPoint(1,0,255,0) -p1.SetPoint(2,255,0,0) -p1.SetPoint(3,255,255,0) -p1.SetPoint(4,96,96,0) -p1.SetPoint(5,96,159,0) -p1.SetPoint(6,159,159,0) -p1.SetPoint(7,159,96,0) -p2 = vtk.vtkPoints() -p2.SetNumberOfPoints(8) -p2.SetPoint(0,0,0,0) -p2.SetPoint(1,0,255,0) -p2.SetPoint(2,255,0,0) -p2.SetPoint(3,255,255,0) -p2.SetPoint(4,96,159,0) -p2.SetPoint(5,159,159,0) -p2.SetPoint(6,159,96,0) -p2.SetPoint(7,96,96,0) -thinPlate0 = vtk.vtkThinPlateSplineTransform() -thinPlate0.SetSourceLandmarks(p1) -thinPlate0.SetTargetLandmarks(p2) -thinPlate0.SetBasisToR2LogR() -filename = "" + str(dir) + "/mni-thinplatespline.xfm" -# write the tps to a file -tpsWriter = vtk.vtkMNITransformWriter() -tpsWriter.SetFileName("" + str(filename) + "") -tpsWriter.SetTransform(thinPlate0) -tpsWriter.Write() -# read it back -tpsReader = vtk.vtkMNITransformReader() -if (tpsReader.CanReadFile("" + str(filename) + "") != 0): - tpsReader.SetFileName("" + str(filename) + "") - pass -thinPlate = tpsReader.GetTransform() -# make a linear transform -linearTransform = vtk.vtkTransform() -linearTransform.PostMultiply() -linearTransform.Translate(-127.5,-127.5,0) -linearTransform.RotateZ(30) -linearTransform.Translate(+127.5,+127.5,0) -# remove the linear part of the thin plate -tpsGeneral = vtk.vtkGeneralTransform() -tpsGeneral.SetInput(thinPlate) -tpsGeneral.PreMultiply() -tpsGeneral.Concatenate(linearTransform.GetInverse().GetMatrix()) -# convert the thin plate spline into a grid -transformToGrid = vtk.vtkTransformToGrid() -transformToGrid.SetInput(tpsGeneral) -transformToGrid.SetGridSpacing(16,16,1) -transformToGrid.SetGridOrigin(-64.5,-64.5,0) -transformToGrid.SetGridExtent(0,24,0,24,0,0) -transformToGrid.Update() -gridTransform = vtk.vtkGridTransform() -gridTransform.SetDisplacementGridConnection(transformToGrid.GetOutputPort()) -gridTransform.SetInterpolationModeToCubic() -# add back the linear part -gridGeneral = vtk.vtkGeneralTransform() -gridGeneral.SetInput(gridTransform) -gridGeneral.PreMultiply() -gridGeneral.Concatenate(linearTransform.GetMatrix()) -# invert for reslice -gridGeneral.Inverse() -# write to a file -gridWriter = vtk.vtkMNITransformWriter() -gridWriter.SetFileName("" + str(dir) + "/mni-grid.xfm") -gridWriter.SetComments("TestMNITransforms output transform") -gridWriter.SetTransform(gridGeneral) -gridWriter.Write() -# read it back -gridReader = vtk.vtkMNITransformReader() -gridReader.SetFileName("" + str(dir) + "/mni-grid.xfm") -transform = gridReader.GetTransform() -# apply the grid warp to the image -reslice = vtk.vtkImageReslice() -reslice.SetInputConnection(blend.GetOutputPort()) -reslice.SetResliceTransform(transform) -reslice.SetInterpolationModeToLinear() -# set the window/level to 255.0/127.5 to view full range -viewer = vtk.vtkImageViewer() -viewer.SetInputConnection(reslice.GetOutputPort()) -viewer.SetColorWindow(255.0) -viewer.SetColorLevel(127.5) -viewer.SetZSlice(0) -viewer.Render() -# --- end of script -- +try: + filename = "mni-thinplatespline.xfm" + channel = open(filename, "wb") + channel.close() + + # first, create an image to warp + imageGrid = vtk.vtkImageGridSource() + imageGrid.SetGridSpacing(16, 16, 0) + imageGrid.SetGridOrigin(0, 0, 0) + imageGrid.SetDataExtent(0, 255, 0, 255, 0, 0) + imageGrid.SetDataScalarTypeToUnsignedChar() + + table = vtk.vtkLookupTable() + table.SetTableRange(0, 1) + table.SetValueRange(1.0, 0.0) + table.SetSaturationRange(0.0, 0.0) + table.SetHueRange(0.0, 0.0) + table.SetAlphaRange(0.0, 1.0) + table.Build() + + alpha = vtk.vtkImageMapToColors() + alpha.SetInputConnection(imageGrid.GetOutputPort()) + alpha.SetLookupTable(table) + + reader1 = vtk.vtkBMPReader() + reader1.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp") + + blend = vtk.vtkImageBlend() + blend.AddInputConnection(reader1.GetOutputPort()) + blend.AddInputConnection(alpha.GetOutputPort()) + + # next, create a ThinPlateSpline transform + p1 = vtk.vtkPoints() + p1.SetNumberOfPoints(8) + p1.SetPoint(0, 0, 0, 0) + p1.SetPoint(1, 0, 255, 0) + p1.SetPoint(2, 255, 0, 0) + p1.SetPoint(3, 255, 255, 0) + p1.SetPoint(4, 96, 96, 0) + p1.SetPoint(5, 96, 159, 0) + p1.SetPoint(6, 159, 159, 0) + p1.SetPoint(7, 159, 96, 0) + + p2 = vtk.vtkPoints() + p2.SetNumberOfPoints(8) + p2.SetPoint(0, 0, 0, 0) + p2.SetPoint(1, 0, 255, 0) + p2.SetPoint(2, 255, 0, 0) + p2.SetPoint(3, 255, 255, 0) + p2.SetPoint(4, 96, 159, 0) + p2.SetPoint(5, 159, 159, 0) + p2.SetPoint(6, 159, 96, 0) + p2.SetPoint(7, 96, 96, 0) + + thinPlate0 = vtk.vtkThinPlateSplineTransform() + thinPlate0.SetSourceLandmarks(p1) + thinPlate0.SetTargetLandmarks(p2) + thinPlate0.SetBasisToR2LogR() + + # write the tps to a file + tpsWriter = vtk.vtkMNITransformWriter() + tpsWriter.SetFileName(filename) + tpsWriter.SetTransform(thinPlate0) + tpsWriter.Write() + # read it back + tpsReader = vtk.vtkMNITransformReader() + if (tpsReader.CanReadFile(filename) != 0): + tpsReader.SetFileName(filename) + + thinPlate = tpsReader.GetTransform() + + # make a linear transform + linearTransform = vtk.vtkTransform() + linearTransform.PostMultiply() + linearTransform.Translate(-127.5, -127.5, 0) + linearTransform.RotateZ(30) + linearTransform.Translate(+127.5, +127.5, 0) + + # remove the linear part of the thin plate + tpsGeneral = vtk.vtkGeneralTransform() + tpsGeneral.SetInput(thinPlate) + tpsGeneral.PreMultiply() + tpsGeneral.Concatenate(linearTransform.GetInverse().GetMatrix()) + + # convert the thin plate spline into a grid + transformToGrid = vtk.vtkTransformToGrid() + transformToGrid.SetInput(tpsGeneral) + transformToGrid.SetGridSpacing(16, 16, 1) + transformToGrid.SetGridOrigin(-64.5, -64.5, 0) + transformToGrid.SetGridExtent(0, 24, 0, 24, 0, 0) + transformToGrid.Update() + + gridTransform = vtk.vtkGridTransform() + gridTransform.SetDisplacementGridConnection( + transformToGrid.GetOutputPort()) + gridTransform.SetInterpolationModeToCubic() + + # add back the linear part + gridGeneral = vtk.vtkGeneralTransform() + gridGeneral.SetInput(gridTransform) + gridGeneral.PreMultiply() + gridGeneral.Concatenate(linearTransform.GetMatrix()) + + # invert for reslice + gridGeneral.Inverse() + # write to a file + gridWriter = vtk.vtkMNITransformWriter() + gridWriter.SetFileName("mni-grid.xfm") + gridWriter.SetComments("TestMNITransforms output transform") + gridWriter.SetTransform(gridGeneral) + gridWriter.Write() + + # read it back + gridReader = vtk.vtkMNITransformReader() + gridReader.SetFileName("mni-grid.xfm") + transform = gridReader.GetTransform() + + # apply the grid warp to the image + reslice = vtk.vtkImageReslice() + reslice.SetInputConnection(blend.GetOutputPort()) + reslice.SetResliceTransform(transform) + reslice.SetInterpolationModeToLinear() + + # set the window/level to 255.0/127.5 to view full range + viewer = vtk.vtkImageViewer() + viewer.SetInputConnection(reslice.GetOutputPort()) + viewer.SetColorWindow(255.0) + viewer.SetColorLevel(127.5) + viewer.SetZSlice(0) + viewer.Render() + + try: + os.remove("mni-grid.xfm") + except OSError: + pass + try: + os.remove("mni-grid_grid.mnc") + except OSError: + pass + + try: + os.remove(filename) + except OSError: + pass + +except IOError: + print "Unable to test the writer/reader." diff --git a/IO/PLY/Testing/Python/TestPLYReadWrite.py b/IO/PLY/Testing/Python/TestPLYReadWrite.py index 56f692dd0ce..ceb30784636 100755 --- a/IO/PLY/Testing/Python/TestPLYReadWrite.py +++ b/IO/PLY/Testing/Python/TestPLYReadWrite.py @@ -1,91 +1,133 @@ #!/usr/bin/env python +import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() -ss = vtk.vtkSphereSource() -ss.SetPhiResolution(10) -ss.SetThetaResolution(20) -ele = vtk.vtkSimpleElevationFilter() -ele.SetInputConnection(ss.GetOutputPort()) -pd2cd = vtk.vtkPointDataToCellData() -pd2cd.SetInputConnection(ele.GetOutputPort()) -# First way or writing -w = vtk.vtkPLYWriter() -w.SetInputConnection(pd2cd.GetOutputPort()) -w.SetFileName("plyWriter.ply") -w.SetFileTypeToBinary() -w.SetDataByteOrderToLittleEndian() -w.SetColorModeToUniformCellColor() -w.SetColor(255,0,0) -w.Write() -r = vtk.vtkPLYReader() -r.SetFileName("plyWriter.ply") -r.Update() -file.delete("-force", "plyWriter.ply") -plyMapper = vtk.vtkPolyDataMapper() -plyMapper.SetInputConnection(r.GetOutputPort()) -plyActor = vtk.vtkActor() -plyActor.SetMapper(plyMapper) -# Second way or writing - it will map through a lookup table -lut = vtk.vtkLookupTable() -lut.Build() -w2 = vtk.vtkPLYWriter() -w2.SetInputConnection(pd2cd.GetOutputPort()) -w2.SetFileName("plyWriter.ply") -w2.SetFileTypeToBinary() -w2.SetDataByteOrderToLittleEndian() -w2.SetColorModeToDefault() -w2.SetLookupTable(lut) -w2.SetArrayName("Elevation") -w2.SetComponent(0) -w2.Write() -r2 = vtk.vtkPLYReader() -r2.SetFileName("plyWriter.ply") -r2.Update() -plyMapper2 = vtk.vtkPolyDataMapper() -plyMapper2.SetInputConnection(r2.GetOutputPort()) -plyActor2 = vtk.vtkActor() -plyActor2.SetMapper(plyMapper2) -plyActor2.AddPosition(1,0,0) -# Third way or writing - it will read the previous file with rgb cell color -r3 = vtk.vtkPLYReader() -r3.SetFileName("plyWriter.ply") -r3.Update() -w3 = vtk.vtkPLYWriter() -w3.SetInputConnection(r3.GetOutputPort()) -w3.SetFileName("plyWriter.ply") -w3.SetFileTypeToBinary() -w3.SetDataByteOrderToLittleEndian() -w3.SetColorModeToDefault() -w3.SetArrayName("RGB") -w3.SetComponent(0) -w3.Write() -r4 = vtk.vtkPLYReader() -r4.SetFileName("plyWriter.ply") -r4.Update() -plyMapper3 = vtk.vtkPolyDataMapper() -plyMapper3.SetInputConnection(r4.GetOutputPort()) -plyActor3 = vtk.vtkActor() -plyActor3.SetMapper(plyMapper3) -plyActor3.AddPosition(2,0,0) -file.delete("-force", "plyWriter.ply") -# Create the RenderWindow, Renderer and both Actors +# NOTE: This test only works if the current directory is writable # -ren1 = vtk.vtkRenderer() -renWin = vtk.vtkRenderWindow() -renWin.AddRenderer(ren1) -iren = vtk.vtkRenderWindowInteractor() -iren.SetRenderWindow(renWin) -# Add the actors to the renderer, set the background and size -# -ren1.AddActor(plyActor) -ren1.AddActor(plyActor2) -ren1.AddActor(plyActor3) -renWin.SetSize(325,125) -iren.Initialize() -renWin.Render() -ren1.GetActiveCamera().Zoom(3.0) -# prevent the tk window from showing up then start the event loop -# --- end of script -- +try: + filename = "plyWriter.ply" + channel = open(filename, "wb") + channel.close() + + ss = vtk.vtkSphereSource() + ss.SetPhiResolution(10) + ss.SetThetaResolution(20) + + ele = vtk.vtkSimpleElevationFilter() + ele.SetInputConnection(ss.GetOutputPort()) + + pd2cd = vtk.vtkPointDataToCellData() + pd2cd.SetInputConnection(ele.GetOutputPort()) + + # First way or writing + w = vtk.vtkPLYWriter() + w.SetInputConnection(pd2cd.GetOutputPort()) + w.SetFileName(filename) + w.SetFileTypeToBinary() + w.SetDataByteOrderToLittleEndian() + w.SetColorModeToUniformCellColor() + w.SetColor(255, 0, 0) + w.Write() + + r = vtk.vtkPLYReader() + r.SetFileName(filename) + r.Update() + + # cleanup + # + try: + os.remove(filename) + except OSError: + pass + + plyMapper = vtk.vtkPolyDataMapper() + plyMapper.SetInputConnection(r.GetOutputPort()) + + plyActor = vtk.vtkActor() + plyActor.SetMapper(plyMapper) + + # Second way or writing - it will map through a lookup table + lut = vtk.vtkLookupTable() + lut.Build() + + w2 = vtk.vtkPLYWriter() + w2.SetInputConnection(pd2cd.GetOutputPort()) + w2.SetFileName(filename) + w2.SetFileTypeToBinary() + w2.SetDataByteOrderToLittleEndian() + w2.SetColorModeToDefault() + w2.SetLookupTable(lut) + w2.SetArrayName("Elevation") + w2.SetComponent(0) + w2.Write() + + r2 = vtk.vtkPLYReader() + r2.SetFileName(filename) + r2.Update() + + plyMapper2 = vtk.vtkPolyDataMapper() + plyMapper2.SetInputConnection(r2.GetOutputPort()) + + plyActor2 = vtk.vtkActor() + plyActor2.SetMapper(plyMapper2) + plyActor2.AddPosition(1, 0, 0) + + # Third way or writing - it will read the previous file with rgb cell color + r3 = vtk.vtkPLYReader() + r3.SetFileName(filename) + r3.Update() + + w3 = vtk.vtkPLYWriter() + w3.SetInputConnection(r3.GetOutputPort()) + w3.SetFileName(filename) + w3.SetFileTypeToBinary() + w3.SetDataByteOrderToLittleEndian() + w3.SetColorModeToDefault() + w3.SetArrayName("RGB") + w3.SetComponent(0) + w3.Write() + + r4 = vtk.vtkPLYReader() + r4.SetFileName(filename) + r4.Update() + + plyMapper3 = vtk.vtkPolyDataMapper() + plyMapper3.SetInputConnection(r4.GetOutputPort()) + plyActor3 = vtk.vtkActor() + plyActor3.SetMapper(plyMapper3) + plyActor3.AddPosition(2, 0, 0) + + # cleanup + # + try: + os.remove(filename) + except OSError: + pass + + # Create the RenderWindow, Renderer and both Actors + # + ren1 = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() + renWin.AddRenderer(ren1) + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) + + # Add the actors to the renderer, set the background and size + # + ren1.AddActor(plyActor) + ren1.AddActor(plyActor2) + ren1.AddActor(plyActor3) + + renWin.SetSize(325, 125) + + iren.Initialize() + renWin.Render() + ren1.GetActiveCamera().Zoom(3.0) + +# iren.Start() + +except IOError: + print "Unable to test the writers." diff --git a/Imaging/Core/Testing/Python/TestBlendStencil.py b/Imaging/Core/Testing/Python/TestBlendStencil.py index 703a899614b..01ce59079ae 100755 --- a/Imaging/Core/Testing/Python/TestBlendStencil.py +++ b/Imaging/Core/Testing/Python/TestBlendStencil.py @@ -1,38 +1,49 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # do alpha-blending of two images, but also clip with stencil reader1 = vtk.vtkBMPReader() -reader1.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/masonry.bmp") +reader1.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp") + reader2 = vtk.vtkPNMReader() -reader2.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/B.pgm") +reader2.SetFileName(VTK_DATA_ROOT + "/Data/B.pgm") + table = vtk.vtkLookupTable() -table.SetTableRange(0,127) -table.SetValueRange(0.0,1.0) -table.SetSaturationRange(0.0,0.0) -table.SetHueRange(0.0,0.0) -table.SetAlphaRange(0.9,0.0) +table.SetTableRange(0, 127) +table.SetValueRange(0.0, 1.0) +table.SetSaturationRange(0.0, 0.0) +table.SetHueRange(0.0, 0.0) +table.SetAlphaRange(0.9, 0.0) table.Build() + translate = vtk.vtkImageTranslateExtent() translate.SetInputConnection(reader2.GetOutputPort()) -translate.SetTranslation(60,60,0) +translate.SetTranslation(60, 60, 0) + sphere = vtk.vtkSphere() -sphere.SetCenter(121,131,0) +sphere.SetCenter(121, 131, 0) sphere.SetRadius(70) + functionToStencil = vtk.vtkImplicitFunctionToImageStencil() functionToStencil.SetInput(sphere) -functionToStencil.GetExecutive().SetUpdateExtent(0,0,255,0,255,0,0) +functionToStencil.GetExecutive().SetUpdateExtent(0, 0, 255, 0, 255, 0, 0) + blend = vtk.vtkImageBlend() blend.SetInputConnection(reader1.GetOutputPort()) blend.AddInputConnection(translate.GetOutputPort()) + # excercise the ReplaceNthInputConnection method -blend.ReplaceNthInputConnection(1,reader1.GetOutputPort()) -blend.ReplaceNthInputConnection(1,translate.GetOutputPort()) -blend.SetOpacity(1,0.8) +blend.ReplaceNthInputConnection(1, reader1.GetOutputPort()) +blend.ReplaceNthInputConnection(1, translate.GetOutputPort()) +blend.SetOpacity(1, 0.8) blend.SetStencilConnection(functionToStencil.GetOutputPort()) + viewer = vtk.vtkImageViewer() viewer.SetInputConnection(blend.GetOutputPort()) viewer.SetColorWindow(255.0) viewer.SetColorLevel(127.5) viewer.SetZSlice(0) viewer.Render() -# --- end of script -- diff --git a/Imaging/Core/Testing/Python/TestExtractVOI.py b/Imaging/Core/Testing/Python/TestExtractVOI.py index 08acc2440c4..ca7fa5b2355 100755 --- a/Imaging/Core/Testing/Python/TestExtractVOI.py +++ b/Imaging/Core/Testing/Python/TestExtractVOI.py @@ -1,42 +1,59 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # to mark the origin sphere = vtk.vtkSphereSource() sphere.SetRadius(2.0) + sphereMapper = vtk.vtkPolyDataMapper() sphereMapper.SetInputConnection(sphere.GetOutputPort()) sphereMapper.ImmediateModeRenderingOn() + sphereActor = vtk.vtkActor() sphereActor.SetMapper(sphereMapper) + rt = vtk.vtkRTAnalyticSource() -rt.SetWholeExtent(-50,50,-50,50,0,0) +rt.SetWholeExtent(-50, 50, -50, 50, 0, 0) + voi = vtk.vtkExtractVOI() voi.SetInputConnection(rt.GetOutputPort()) -voi.SetVOI(-11,39,5,45,0,0) -voi.SetSampleRate(5,5,1) -# Get rid ambiguous triagulation issues. +voi.SetVOI(-11, 39, 5, 45, 0, 0) +voi.SetSampleRate(5, 5, 1) + +# Get rid of ambiguous triagulation issues. surf = vtk.vtkDataSetSurfaceFilter() surf.SetInputConnection(voi.GetOutputPort()) + tris = vtk.vtkTriangleFilter() tris.SetInputConnection(surf.GetOutputPort()) + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(tris.GetOutputPort()) mapper.ImmediateModeRenderingOn() -mapper.SetScalarRange(130,280) +mapper.SetScalarRange(130, 280) + actor = vtk.vtkActor() actor.SetMapper(mapper) + ren = vtk.vtkRenderer() ren.AddActor(actor) ren.AddActor(sphereActor) ren.ResetCamera() -camera = ren.GetActiveCamera() -#$camera SetPosition 68.1939 -23.4323 12.6465 -#$camera SetViewUp 0.46563 0.882375 0.0678508 -#$camera SetFocalPoint 3.65707 11.4552 1.83509 -#$camera SetClippingRange 59.2626 101.825 + +# camera = ren.GetActiveCamera() +# camera.SetPosition(68.1939, -23.4323, 12.6465) +# camera.SetViewUp(0.46563, 0.882375, 0.0678508) +# camera.SetFocalPoint(3.65707, 11.4552, 1.83509) +# camera.SetClippingRange(59.2626, 101.825) + renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Imaging/Core/Testing/Python/TestHybridMedian2D.py b/Imaging/Core/Testing/Python/TestHybridMedian2D.py index e2c922f47f4..0a1813f03a0 100755 --- a/Imaging/Core/Testing/Python/TestHybridMedian2D.py +++ b/Imaging/Core/Testing/Python/TestHybridMedian2D.py @@ -7,67 +7,76 @@ VTK_DATA_ROOT = vtkGetDataRoot() # Show the constant kernel. Smooth an impulse function. imageCanvas = vtk.vtkImageCanvasSource2D() imageCanvas.SetScalarTypeToDouble() -imageCanvas.SetExtent(1,256,1,256,0,0) +imageCanvas.SetExtent(1, 256, 1, 256, 0, 0) # back ground zero imageCanvas.SetDrawColor(0) -imageCanvas.FillBox(1,256,1,256) +imageCanvas.FillBox(1, 256, 1, 256) imageCanvas.SetDrawColor(255) -imageCanvas.FillBox(30,225,30,225) +imageCanvas.FillBox(30, 225, 30, 225) imageCanvas.SetDrawColor(0) -imageCanvas.FillBox(60,195,60,195) +imageCanvas.FillBox(60, 195, 60, 195) imageCanvas.SetDrawColor(255) -imageCanvas.FillTube(100,100,154,154,40.0) +imageCanvas.FillTube(100, 100, 154, 154, 40.0) imageCanvas.SetDrawColor(0) -imageCanvas.DrawSegment(45,45,45,210) -imageCanvas.DrawSegment(45,210,210,210) -imageCanvas.DrawSegment(210,210,210,45) -imageCanvas.DrawSegment(210,45,45,45) -imageCanvas.DrawSegment(100,150,150,100) -imageCanvas.DrawSegment(110,160,160,110) -imageCanvas.DrawSegment(90,140,140,90) -imageCanvas.DrawSegment(120,170,170,120) -imageCanvas.DrawSegment(80,130,130,80) +imageCanvas.DrawSegment(45, 45, 45, 210) +imageCanvas.DrawSegment(45, 210, 210, 210) +imageCanvas.DrawSegment(210, 210, 210, 45) +imageCanvas.DrawSegment(210, 45, 45, 45) +imageCanvas.DrawSegment(100, 150, 150, 100) +imageCanvas.DrawSegment(110, 160, 160, 110) +imageCanvas.DrawSegment(90, 140, 140, 90) +imageCanvas.DrawSegment(120, 170, 170, 120) +imageCanvas.DrawSegment(80, 130, 130, 80) imageCanvas.Update() + shotNoiseAmplitude = 255.0 shotNoiseFraction = 0.1 -#set shotNoiseExtent "1 256 1 256 0 0" + +# set shotNoiseExtent "1 256 1 256 0 0" shotNoiseSource = vtk.vtkImageNoiseSource() -shotNoiseSource.SetWholeExtent(1,256,1,256,0,0) -#$shotNoiseExtent +shotNoiseSource.SetWholeExtent(1, 256, 1, 256, 0, 0) +# $shotNoiseExtent shotNoiseSource.SetMinimum(0.0) shotNoiseSource.SetMaximum(1.0) shotNoiseSource.ReleaseDataFlagOff() + shotNoiseThresh1 = vtk.vtkImageThreshold() shotNoiseThresh1.SetInputConnection(shotNoiseSource.GetOutputPort()) -shotNoiseThresh1.ThresholdByLower(expr.expr(globals(), locals(),["1.0","-","shotNoiseFraction"])) +shotNoiseThresh1.ThresholdByLower(1.0 - shotNoiseFraction) shotNoiseThresh1.SetInValue(0) shotNoiseThresh1.SetOutValue(shotNoiseAmplitude) shotNoiseThresh1.Update() + shotNoiseThresh2 = vtk.vtkImageThreshold() shotNoiseThresh2.SetInputConnection(shotNoiseSource.GetOutputPort()) shotNoiseThresh2.ThresholdByLower(shotNoiseFraction) -shotNoiseThresh2.SetInValue(expr.expr(globals(), locals(),["-","shotNoiseAmplitude"])) +shotNoiseThresh2.SetInValue(-shotNoiseAmplitude) shotNoiseThresh2.SetOutValue(0.0) shotNoiseThresh2.Update() + shotNoise = vtk.vtkImageMathematics() shotNoise.SetInput1Data(shotNoiseThresh1.GetOutput()) shotNoise.SetInput2Data(shotNoiseThresh2.GetOutput()) shotNoise.SetOperationToAdd() shotNoise.Update() + add = vtk.vtkImageMathematics() add.SetInput1Data(shotNoise.GetOutput()) add.SetInput2Data(imageCanvas.GetOutput()) add.SetOperationToAdd() + median = vtk.vtkImageMedian3D() median.SetInputConnection(add.GetOutputPort()) -median.SetKernelSize(3,3,1) +median.SetKernelSize(3, 3, 1) + hybrid1 = vtk.vtkImageHybridMedian2D() hybrid1.SetInputConnection(add.GetOutputPort()) hybrid2 = vtk.vtkImageHybridMedian2D() hybrid2.SetInputConnection(hybrid1.GetOutputPort()) + viewer = vtk.vtkImageViewer() viewer.SetInputConnection(hybrid1.GetOutputPort()) viewer.SetColorWindow(256) viewer.SetColorLevel(127.5) +viewer.GetRenderWindow().SetSize(256, 256) viewer.Render() -# --- end of script -- diff --git a/Imaging/Core/Testing/Python/TestImageWeightedSum.py b/Imaging/Core/Testing/Python/TestImageWeightedSum.py index 4a4ace71305..301df477924 100755 --- a/Imaging/Core/Testing/Python/TestImageWeightedSum.py +++ b/Imaging/Core/Testing/Python/TestImageWeightedSum.py @@ -1,39 +1,49 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Image pipeline reader = vtk.vtkImageReader() reader.ReleaseDataFlagOff() reader.SetDataByteOrderToLittleEndian() -reader.SetDataExtent(0,63,0,63,1,93) +reader.SetDataExtent(0, 63, 0, 63, 1, 93) reader.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") reader.SetDataMask(0x7fff) + mag = vtk.vtkImageMagnify() mag.SetInputConnection(reader.GetOutputPort()) -mag.SetMagnificationFactors(4,4,1) +mag.SetMagnificationFactors(4, 4, 1) + th = vtk.vtkImageThreshold() th.SetInputConnection(mag.GetOutputPort()) th.SetReplaceIn(1) th.SetReplaceOut(1) -th.ThresholdBetween(-1000,1000) +th.ThresholdBetween(-1000, 1000) th.SetOutValue(0) th.SetInValue(2000) + cast = vtk.vtkImageCast() cast.SetInputConnection(mag.GetOutputPort()) cast.SetOutputScalarTypeToFloat() + cast2 = vtk.vtkImageCast() cast2.SetInputConnection(th.GetOutputPort()) cast2.SetOutputScalarTypeToFloat() + sum = vtk.vtkImageWeightedSum() sum.AddInputConnection(cast.GetOutputPort()) sum.AddInputConnection(cast2.GetOutputPort()) -sum.SetWeight(0,10) -sum.SetWeight(1,4) +sum.SetWeight(0, 10) +sum.SetWeight(1, 4) + viewer = vtk.vtkImageViewer() viewer.SetInputConnection(sum.GetOutputPort()) viewer.SetZSlice(22) viewer.SetColorWindow(1819) viewer.SetColorLevel(939) -sum.SetWeight(0,1) -#make interface +sum.SetWeight(0, 1) +# make interface +viewer.SetSize(256, 256) viewer.Render() -# --- end of script -- diff --git a/Imaging/Core/Testing/Python/TestInPlaceFilter.py b/Imaging/Core/Testing/Python/TestInPlaceFilter.py index 9b3b57b5f3f..e532162e084 100755 --- a/Imaging/Core/Testing/Python/TestInPlaceFilter.py +++ b/Imaging/Core/Testing/Python/TestInPlaceFilter.py @@ -13,38 +13,45 @@ CURSOR_Z = 20 IMAGE_MAG_X = 2 IMAGE_MAG_Y = 2 IMAGE_MAG_Z = 1 + # pipeline stuff reader = vtk.vtkSLCReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/nut.slc") -# make the image a little biger +reader.SetFileName(VTK_DATA_ROOT + "/Data/nut.slc") + +# make the image a little bigger magnify1 = vtk.vtkImageMagnify() magnify1.SetInputConnection(reader.GetOutputPort()) -magnify1.SetMagnificationFactors(IMAGE_MAG_X,IMAGE_MAG_Y,IMAGE_MAG_Z) +magnify1.SetMagnificationFactors(IMAGE_MAG_X, IMAGE_MAG_Y, IMAGE_MAG_Z) magnify1.ReleaseDataFlagOn() + magnify2 = vtk.vtkImageMagnify() magnify2.SetInputConnection(reader.GetOutputPort()) -magnify2.SetMagnificationFactors(IMAGE_MAG_X,IMAGE_MAG_Y,IMAGE_MAG_Z) +magnify2.SetMagnificationFactors(IMAGE_MAG_X, IMAGE_MAG_Y, IMAGE_MAG_Z) magnify2.ReleaseDataFlagOn() + # a filter that does in place processing (magnify ReleaseDataFlagOn) cursor = vtk.vtkImageCursor3D() cursor.SetInputConnection(magnify1.GetOutputPort()) -cursor.SetCursorPosition(expr.expr(globals(), locals(),["CURSOR_X","*","IMAGE_MAG_X"]),expr.expr(globals(), locals(),["CURSOR_Y","*","IMAGE_MAG_Y"]),expr.expr(globals(), locals(),["CURSOR_Z","*","IMAGE_MAG_Z"])) +cursor.SetCursorPosition(CURSOR_X * IMAGE_MAG_X, + CURSOR_Y * IMAGE_MAG_Y, + CURSOR_Z * IMAGE_MAG_Z) cursor.SetCursorValue(255) -cursor.SetCursorRadius(expr.expr(globals(), locals(),["50","*","IMAGE_MAG_X"])) +cursor.SetCursorRadius(50 * IMAGE_MAG_X) + # stream to increase coverage of in place filter. -# put thge two together in one image +# put the two together in one image imageAppend = vtk.vtkImageAppend() imageAppend.SetAppendAxis(0) imageAppend.AddInputConnection(magnify2.GetOutputPort()) imageAppend.AddInputConnection(cursor.GetOutputPort()) + viewer = vtk.vtkImageViewer() viewer.SetInputConnection(imageAppend.GetOutputPort()) -viewer.SetZSlice(expr.expr(globals(), locals(),["CURSOR_Z","*","IMAGE_MAG_Z"])) +viewer.SetZSlice(CURSOR_Z * IMAGE_MAG_Z) viewer.SetColorWindow(200) viewer.SetColorLevel(80) -#viewer DebugOn +# viewer DebugOn viewer.Render() -viewer.SetPosition(50,50) -#make interface +viewer.SetPosition(50, 50) +# make interface viewer.Render() -# --- end of script -- diff --git a/Imaging/Core/Testing/Python/TestMapToWindowLevelColors.py b/Imaging/Core/Testing/Python/TestMapToWindowLevelColors.py index c2578762473..2dfcee5b997 100755 --- a/Imaging/Core/Testing/Python/TestMapToWindowLevelColors.py +++ b/Imaging/Core/Testing/Python/TestMapToWindowLevelColors.py @@ -9,20 +9,23 @@ MAX_ITERATIONS_1 = RANGE MAX_ITERATIONS_2 = RANGE XRAD = 200 YRAD = 200 + mandelbrot1 = vtk.vtkImageMandelbrotSource() mandelbrot1.SetMaximumNumberOfIterations(150) -mandelbrot1.SetWholeExtent(0,expr.expr(globals(), locals(),["XRAD","-1"]),0,expr.expr(globals(), locals(),["YRAD","-1"]),0,0) -mandelbrot1.SetSampleCX(expr.expr(globals(), locals(),["1.3","/","XRAD"]),expr.expr(globals(), locals(),["1.3","/","XRAD"]),expr.expr(globals(), locals(),["1.3","/","XRAD"]),expr.expr(globals(), locals(),["1.3","/","XRAD"])) -mandelbrot1.SetOriginCX(-0.72,0.22,0.0,0.0) -mandelbrot1.SetProjectionAxes(0,1,2) +mandelbrot1.SetWholeExtent(0, XRAD - 1, 0, YRAD - 1, 0, 0) +mandelbrot1.SetSampleCX(1.3 / XRAD, 1.3 / XRAD, 1.3 / XRAD, 1.3 / XRAD) +mandelbrot1.SetOriginCX(-0.72, 0.22, 0.0, 0.0) +mandelbrot1.SetProjectionAxes(0, 1, 2) + mapToWL = vtk.vtkImageMapToWindowLevelColors() mapToWL.SetInputConnection(mandelbrot1.GetOutputPort()) mapToWL.SetWindow(RANGE) -mapToWL.SetLevel(expr.expr(globals(), locals(),["RANGE","/","3.0"])) +mapToWL.SetLevel(RANGE / 3.0) + + # set the window/level to 255.0/127.5 to view full range viewer = vtk.vtkImageViewer() viewer.SetInputConnection(mapToWL.GetOutputPort()) viewer.SetColorWindow(255.0) viewer.SetColorLevel(127.5) viewer.Render() -# --- end of script -- diff --git a/Imaging/Core/Testing/Python/TestSeparableFilter.py b/Imaging/Core/Testing/Python/TestSeparableFilter.py index da6b137d732..a42d6b80156 100755 --- a/Imaging/Core/Testing/Python/TestSeparableFilter.py +++ b/Imaging/Core/Testing/Python/TestSeparableFilter.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import math import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot @@ -6,35 +7,37 @@ VTK_DATA_ROOT = vtkGetDataRoot() # Image pipeline reader = vtk.vtkPNGReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/fullhead15.png") +reader.SetFileName(VTK_DATA_ROOT + "/Data/fullhead15.png") + # Take the gradient in X, and smooth in Y # Create a simple gradient filter kernel = vtk.vtkFloatArray() kernel.SetNumberOfTuples(3) -kernel.InsertValue(0,-1) -kernel.InsertValue(1,0) -kernel.InsertValue(2,1) +kernel.InsertValue(0, -1) +kernel.InsertValue(1, 0) +kernel.InsertValue(2, 1) + # Create a gaussian for Y sigma = 1.5 -sigma2 = expr.expr(globals(), locals(),["sigma","*","sigma"]) +sigma2 = sigma * sigma gaussian = vtk.vtkFloatArray() gaussian.SetNumberOfTuples(31) i = 0 while i < 31: - x = expr.expr(globals(), locals(),["i","-","15"]) - g = expr.expr(globals(), locals(),["exp","(","-","(","x","*","x",")","/","(","2.0","*","sigma2",")",")","/","(","sqrt","(","2.0","*","3.1415",")","*","sigma",")"]) - gaussian.InsertValue(i,g) - i = i + 1 + x = i - 15 + g = math.exp(-(x * x) / (2.0 * sigma2)) / (math.sqrt (2.0 * 3.1415) * sigma) + gaussian.InsertValue(i, g) + i += 1 convolve = vtk.vtkImageSeparableConvolution() convolve.SetInputConnection(reader.GetOutputPort()) convolve.SetDimensionality(2) convolve.SetXKernel(kernel) convolve.SetYKernel(gaussian) + viewer = vtk.vtkImageViewer() -#viewer DebugOn +# viewer DebugOn viewer.SetInputConnection(convolve.GetOutputPort()) viewer.SetColorWindow(500) viewer.SetColorLevel(100) viewer.Render() -# --- end of script -- diff --git a/Imaging/Core/Testing/Python/voxelModel.py b/Imaging/Core/Testing/Python/voxelModel.py index 5cbf0ff967d..a2eddd1cf2d 100755 --- a/Imaging/Core/Testing/Python/voxelModel.py +++ b/Imaging/Core/Testing/Python/voxelModel.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot @@ -11,48 +12,72 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + sphereModel = vtk.vtkSphereSource() sphereModel.SetThetaResolution(10) sphereModel.SetPhiResolution(10) + voxelModel = vtk.vtkVoxelModeller() voxelModel.SetInputConnection(sphereModel.GetOutputPort()) -voxelModel.SetSampleDimensions(21,21,21) -voxelModel.SetModelBounds(-1.5,1.5,-1.5,1.5,-1.5,1.5) +voxelModel.SetSampleDimensions(21, 21, 21) +voxelModel.SetModelBounds(-1.5, 1.5, -1.5, 1.5, -1.5, 1.5) voxelModel.SetScalarTypeToBit() voxelModel.SetForegroundValue(1) voxelModel.SetBackgroundValue(0) -if (catch.catch(globals(),"""channel = open("voxelModel.vtk", "w")""") == 0): + +# +# If the current directory is writable, then test the writers +# +try: + channel = open("voxelModel.vtk", "wb") channel.close() - file.delete("-force", "voxelModel.vtk") + aWriter = vtk.vtkDataSetWriter() aWriter.SetFileName("voxelModel.vtk") aWriter.SetInputConnection(voxelModel.GetOutputPort()) aWriter.Update() + aReader = vtk.vtkDataSetReader() aReader.SetFileName("voxelModel.vtk") + voxelSurface = vtk.vtkContourFilter() voxelSurface.SetInputConnection(aReader.GetOutputPort()) - voxelSurface.SetValue(0,.999) + voxelSurface.SetValue(0, .999) + voxelMapper = vtk.vtkPolyDataMapper() voxelMapper.SetInputConnection(voxelSurface.GetOutputPort()) + voxelActor = vtk.vtkActor() voxelActor.SetMapper(voxelMapper) + sphereMapper = vtk.vtkPolyDataMapper() sphereMapper.SetInputConnection(sphereModel.GetOutputPort()) + sphereActor = vtk.vtkActor() sphereActor.SetMapper(sphereMapper) + ren1.AddActor(sphereActor) ren1.AddActor(voxelActor) - ren1.SetBackground(.1,.2,.4) - renWin.SetSize(256,256) + ren1.SetBackground(.1, .2, .4) + + renWin.SetSize(256, 256) + ren1.ResetCamera() - ren1.GetActiveCamera().SetViewUp(0,-1,0) + ren1.GetActiveCamera().SetViewUp(0, -1, 0) ren1.GetActiveCamera().Azimuth(180) ren1.GetActiveCamera().Dolly(1.75) ren1.ResetCameraClippingRange() + + # cleanup + # + try: + os.remove("voxelModel.vtk") + except OSError: + pass + iren.Initialize() # render the image - # - # prevent the tk window from showing up then start the event loop - pass -# --- end of script -- +# iren.Start() + +except IOError: + print "Unable to test the writer/reader." diff --git a/Imaging/Hybrid/Testing/Python/genHead.py b/Imaging/Hybrid/Testing/Python/genHead.py index 049922a14aa..edfa9fc6eda 100755 --- a/Imaging/Hybrid/Testing/Python/genHead.py +++ b/Imaging/Hybrid/Testing/Python/genHead.py @@ -1,21 +1,35 @@ #!/usr/bin/env python +import os import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() -if (catch.catch(globals(),"""channel = open("fullHead.tri", "w")""") == 0): +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 + +# +# The current directory must be writeable. +# +try: + channel = open("fullHead.tri", "wb") channel.close() - file.delete("-force", "fullHead.tri") - file.delete("-force", "fullHead.lim") + # reader reads slices v16 = vtk.vtkVolume16Reader() - v16.SetDataDimensions(64,64) + v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() - v16.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter") - v16.SetDataSpacing(3.2,3.2,1.5) - v16.SetImageRange(30,50) + v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") + v16.SetDataSpacing(3.2, 3.2, 1.5) + v16.SetImageRange(30, 50) v16.SetDataMask(0x7fff) + # write isosurface to file mcubes = vtk.vtkSliceCubes() mcubes.SetReader(v16) @@ -23,6 +37,7 @@ if (catch.catch(globals(),"""channel = open("fullHead.tri", "w")""") == 0): mcubes.SetFileName("fullHead.tri") mcubes.SetLimitsFileName("fullHead.lim") mcubes.Update() + # read from file reader = vtk.vtkMCubesReader() reader.SetFileName("fullHead.tri") @@ -31,7 +46,8 @@ if (catch.catch(globals(),"""channel = open("fullHead.tri", "w")""") == 0): mapper.SetInputConnection(reader.GetOutputPort()) head = vtk.vtkActor() head.SetMapper(mapper) - head.GetProperty().SetColor(raw_sienna) + head.GetProperty().SetColor(GetRGBColor('raw_sienna')) + # Create the RenderWindow, Renderer and Interactor # ren1 = vtk.vtkRenderer() @@ -39,22 +55,40 @@ if (catch.catch(globals(),"""channel = open("fullHead.tri", "w")""") == 0): renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(head) - ren1.SetBackground(1,1,1) - renWin.SetSize(500,500) - ren1.SetBackground(slate_grey) - ren1.GetActiveCamera().SetPosition(99.8847,537.926,15) - ren1.GetActiveCamera().SetFocalPoint(99.8847,109.81,15) + ren1.SetBackground(1, 1, 1) + + renWin.SetSize(500, 500) + + ren1.SetBackground(GetRGBColor('slate_grey')) + + ren1.GetActiveCamera().SetPosition(99.8847, 537.926, 15) + ren1.GetActiveCamera().SetFocalPoint(99.8847, 109.81, 15) ren1.GetActiveCamera().SetViewAngle(20) - ren1.GetActiveCamera().SetViewUp(0,0,-1) + ren1.GetActiveCamera().SetViewUp(0, 0, -1) ren1.ResetCameraClippingRange() + + # cleanup + # + try: + os.remove("fullHead.tri") + except OSError: + pass + try: + os.remove("fullHead.lim") + except OSError: + pass + # render the image # renWin.Render() - # prevent the tk window from showing up then start the event loop - file.delete("-force", "fullHead.tri") - file.delete("-force", "fullHead.lim") - pass -# --- end of script -- + + iren.Initialize() + # render the image +# iren.Start() + +except IOError: + print "Unable to test the writer/reader." diff --git a/Imaging/Hybrid/Testing/Python/iceCream.py b/Imaging/Hybrid/Testing/Python/iceCream.py index 44d56db7734..34ffca8e34f 100755 --- a/Imaging/Hybrid/Testing/Python/iceCream.py +++ b/Imaging/Hybrid/Testing/Python/iceCream.py @@ -4,79 +4,108 @@ 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 + ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create implicit function primitives cone = vtk.vtkCone() cone.SetAngle(20) + vertPlane = vtk.vtkPlane() -vertPlane.SetOrigin(.1,0,0) -vertPlane.SetNormal(-1,0,0) +vertPlane.SetOrigin(.1, 0, 0) +vertPlane.SetNormal(-1, 0, 0) + basePlane = vtk.vtkPlane() -basePlane.SetOrigin(1.2,0,0) -basePlane.SetNormal(1,0,0) +basePlane.SetOrigin(1.2, 0, 0) +basePlane.SetNormal(1, 0, 0) + iceCream = vtk.vtkSphere() -iceCream.SetCenter(1.333,0,0) +iceCream.SetCenter(1.333, 0, 0) iceCream.SetRadius(0.5) + bite = vtk.vtkSphere() -bite.SetCenter(1.5,0,0.5) +bite.SetCenter(1.5, 0, 0.5) bite.SetRadius(0.25) + # combine primitives to build ice-cream cone theCone = vtk.vtkImplicitBoolean() theCone.SetOperationTypeToIntersection() theCone.AddFunction(cone) theCone.AddFunction(vertPlane) theCone.AddFunction(basePlane) + theCream = vtk.vtkImplicitBoolean() theCream.SetOperationTypeToDifference() theCream.AddFunction(iceCream) theCream.AddFunction(bite) + # iso-surface to create geometry theConeSample = vtk.vtkSampleFunction() theConeSample.SetImplicitFunction(theCone) -theConeSample.SetModelBounds(-1,1.5,-1.25,1.25,-1.25,1.25) -theConeSample.SetSampleDimensions(60,60,60) +theConeSample.SetModelBounds(-1, 1.5, -1.25, 1.25, -1.25, 1.25) +theConeSample.SetSampleDimensions(60, 60, 60) theConeSample.ComputeNormalsOff() + theConeSurface = vtk.vtkMarchingContourFilter() theConeSurface.SetInputConnection(theConeSample.GetOutputPort()) -theConeSurface.SetValue(0,0.0) +theConeSurface.SetValue(0, 0.0) + coneMapper = vtk.vtkPolyDataMapper() coneMapper.SetInputConnection(theConeSurface.GetOutputPort()) coneMapper.ScalarVisibilityOff() + coneActor = vtk.vtkActor() coneActor.SetMapper(coneMapper) -coneActor.GetProperty().SetColor(chocolate) +coneActor.GetProperty().SetColor(GetRGBColor('chocolate')) + # iso-surface to create geometry theCreamSample = vtk.vtkSampleFunction() theCreamSample.SetImplicitFunction(theCream) -theCreamSample.SetModelBounds(0,2.5,-1.25,1.25,-1.25,1.25) -theCreamSample.SetSampleDimensions(60,60,60) +theCreamSample.SetModelBounds(0, 2.5, -1.25, 1.25, -1.25, 1.25) +theCreamSample.SetSampleDimensions(60, 60, 60) theCreamSample.ComputeNormalsOff() + theCreamSurface = vtk.vtkMarchingContourFilter() theCreamSurface.SetInputConnection(theCreamSample.GetOutputPort()) -theCreamSurface.SetValue(0,0.0) +theCreamSurface.SetValue(0, 0.0) + creamMapper = vtk.vtkPolyDataMapper() creamMapper.SetInputConnection(theCreamSurface.GetOutputPort()) creamMapper.ScalarVisibilityOff() + creamActor = vtk.vtkActor() creamActor.SetMapper(creamMapper) -creamActor.GetProperty().SetColor(mint) +creamActor.GetProperty().SetColor(GetRGBColor('mint')) + # Add the actors to the renderer, set the background and size # ren1.AddActor(coneActor) ren1.AddActor(creamActor) -ren1.SetBackground(1,1,1) -renWin.SetSize(250,250) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(250, 250) + ren1.ResetCamera() ren1.GetActiveCamera().Roll(90) ren1.GetActiveCamera().Dolly(1.5) ren1.ResetCameraClippingRange() + iren.Initialize() + # render the image # renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Interaction/Style/Testing/Python/TestFlyTo.py b/Interaction/Style/Testing/Python/TestFlyTo.py index 3492204da43..449e02d0420 100755 --- a/Interaction/Style/Testing/Python/TestFlyTo.py +++ b/Interaction/Style/Testing/Python/TestFlyTo.py @@ -4,52 +4,73 @@ 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 + ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create a sphere source and actor # sphere = vtk.vtkSphereSource() + sphereMapper = vtk.vtkPolyDataMapper() sphereMapper.SetInputConnection(sphere.GetOutputPort()) + sphereActor = vtk.vtkLODActor() sphereActor.SetMapper(sphereMapper) -sphereActor.GetProperty().SetDiffuseColor(banana) +sphereActor.GetProperty().SetDiffuseColor(GetRGBColor('banana')) sphereActor.GetProperty().SetSpecular(.4) sphereActor.GetProperty().SetSpecularPower(20) + # create the spikes using a cone source and the sphere source # cone = vtk.vtkConeSource() cone.SetResolution(20) + glyph = vtk.vtkGlyph3D() glyph.SetInputConnection(sphere.GetOutputPort()) glyph.SetSourceConnection(cone.GetOutputPort()) glyph.SetVectorModeToUseNormal() glyph.SetScaleModeToScaleByVector() glyph.SetScaleFactor(0.25) + spikeMapper = vtk.vtkPolyDataMapper() spikeMapper.SetInputConnection(glyph.GetOutputPort()) + spikeActor = vtk.vtkLODActor() spikeActor.SetMapper(spikeMapper) -spikeActor.GetProperty().SetDiffuseColor(tomato) +spikeActor.GetProperty().SetDiffuseColor(GetRGBColor('tomato')) spikeActor.GetProperty().SetSpecular(.4) spikeActor.GetProperty().SetSpecularPower(20) + # Add the actors to the renderer, set the background and size # ren1.AddActor(sphereActor) ren1.AddActor(spikeActor) -ren1.SetBackground(0.1,0.2,0.4) -renWin.SetSize(300,300) +ren1.SetBackground(0.1, 0.2, 0.4) + +renWin.SetSize(300, 300) + # render the image # ren1.ResetCamera() + cam1 = ren1.GetActiveCamera() cam1.Zoom(1.4) cam1.Azimuth(30) cam1.Elevation(30) renWin.Render() -iren.FlyTo(ren1,0.37723,0.154699,0.204326) -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +iren.FlyTo(ren1, 0.37723, 0.154699, 0.204326) + +#iren.Start() diff --git a/Parallel/Core/Testing/Python/TestPolyDataPieces.py b/Parallel/Core/Testing/Python/TestPolyDataPieces.py index aef1cda6bc1..54f78acf9ed 100755 --- a/Parallel/Core/Testing/Python/TestPolyDataPieces.py +++ b/Parallel/Core/Testing/Python/TestPolyDataPieces.py @@ -1,4 +1,8 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() math = vtk.vtkMath() math.RandomSeed(22) @@ -34,25 +38,25 @@ mapper2 = vtk.vtkPolyDataMapper() mapper2.SetInputConnection(extract2.GetOutputPort()) mapper2.SetNumberOfPieces(2) mapper2.SetPiece(1) -mapper2.SetScalarRange(0,4) +mapper2.SetScalarRange(0, 4) mapper2.SetScalarModeToUseCellFieldData() mapper2.SetColorModeToMapScalars() -mapper2.ColorByArrayComponent("vtkGhostLevels",0) +mapper2.ColorByArrayComponent("vtkGhostLevels", 0) mapper2.SetGhostLevel(4) # check the pipeline size extract2.UpdateInformation() psize = vtk.vtkPipelineSize() -if (psize.GetEstimatedSize(extract2,0,0) > 100): +if (psize.GetEstimatedSize(extract2, 0, 0) > 100): print ("ERROR: Pipeline Size increased") pass -if (psize.GetNumberOfSubPieces(10,mapper2) != 2): +if (psize.GetNumberOfSubPieces(10, mapper2) != 2): print ("ERROR: Number of sub pieces changed") pass actor2 = vtk.vtkActor() actor2.SetMapper(mapper2) -actor2.SetPosition(1.5,0,0) +actor2.SetPosition(1.5, 0, 0) sphere3 = vtk.vtkSphereSource() sphere3.SetPhiResolution(32) @@ -67,11 +71,11 @@ ps3.SetInputConnection(extract3.GetOutputPort()) mapper3 = vtk.vtkPolyDataMapper() mapper3.SetInputConnection(ps3.GetOutputPort()) mapper3.SetNumberOfSubPieces(8) -mapper3.SetScalarRange(0,8) +mapper3.SetScalarRange(0, 8) actor3 = vtk.vtkActor() actor3.SetMapper(mapper3) -actor3.SetPosition(0,-1.5,0) +actor3.SetPosition(0, -1.5, 0) sphere4 = vtk.vtkSphereSource() sphere4.SetPhiResolution(32) @@ -88,11 +92,11 @@ ps4.SetInputConnection(extract4.GetOutputPort()) mapper4 = vtk.vtkPolyDataMapper() mapper4.SetInputConnection(ps4.GetOutputPort()) mapper4.SetNumberOfSubPieces(8) -mapper4.SetScalarRange(0,8) +mapper4.SetScalarRange(0, 8) actor4 = vtk.vtkActor() actor4.SetMapper(mapper4) -actor4.SetPosition(1.5,-1.5,0) +actor4.SetPosition(1.5, -1.5, 0) ren = vtk.vtkRenderer() ren.AddActor(actor) @@ -106,4 +110,4 @@ renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Parallel/Core/Testing/Python/TestUnstructuredPieces.py b/Parallel/Core/Testing/Python/TestUnstructuredPieces.py index c43b685827b..4d76744060d 100755 --- a/Parallel/Core/Testing/Python/TestUnstructuredPieces.py +++ b/Parallel/Core/Testing/Python/TestUnstructuredPieces.py @@ -1,41 +1,58 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() + math = vtk.vtkMath() math.RandomSeed(22) pl3d = vtk.vtkMultiBlockPLOT3DReader() -pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") -pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") +pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") +pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") pl3d.SetScalarFunctionNumber(100) pl3d.Update() + output = pl3d.GetOutput().GetBlock(0) + dst = vtk.vtkDataSetTriangleFilter() dst.SetInputData(output) + extract = vtk.vtkExtractUnstructuredGridPiece() extract.SetInputConnection(dst.GetOutputPort()) + cf = vtk.vtkContourFilter() cf.SetInputConnection(extract.GetOutputPort()) -cf.SetValue(0,0.24) +cf.SetValue(0, 0.24) + pdn = vtk.vtkPolyDataNormals() pdn.SetInputConnection(cf.GetOutputPort()) + ps = vtk.vtkPieceScalars() ps.SetInputConnection(pdn.GetOutputPort()) + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(ps.GetOutputPort()) mapper.SetNumberOfPieces(3) + actor = vtk.vtkActor() actor.SetMapper(mapper) + ren = vtk.vtkRenderer() ren.AddActor(actor) ren.ResetCamera() + camera = ren.GetActiveCamera() -#$camera SetPosition 68.1939 -23.4323 12.6465 -#$camera SetViewUp 0.46563 0.882375 0.0678508 -#$camera SetFocalPoint 3.65707 11.4552 1.83509 -#$camera SetClippingRange 59.2626 101.825 +# $camera SetPosition 68.1939 -23.4323 12.6465 +# $camera SetViewUp 0.46563 0.882375 0.0678508 +# $camera SetFocalPoint 3.65707 11.4552 1.83509 +# $camera SetClippingRange 59.2626 101.825 + renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) iren.Initialize() -# --- end of script -- + +#iren.Start() diff --git a/Rendering/Annotation/Testing/Python/cubeAxes.py b/Rendering/Annotation/Testing/Python/cubeAxes.py index dc8cbeb1548..42e115a36a3 100755 --- a/Rendering/Annotation/Testing/Python/cubeAxes.py +++ b/Rendering/Annotation/Testing/Python/cubeAxes.py @@ -7,58 +7,74 @@ VTK_DATA_ROOT = vtkGetDataRoot() # read in an interesting object and outline it # fohe = vtk.vtkBYUReader() -fohe.SetGeometryFileName("" + str(VTK_DATA_ROOT) + "/Data/teapot.g") +fohe.SetGeometryFileName(VTK_DATA_ROOT + "/Data/teapot.g") + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(fohe.GetOutputPort()) + foheMapper = vtk.vtkPolyDataMapper() foheMapper.SetInputConnection(normals.GetOutputPort()) + foheActor = vtk.vtkLODActor() foheActor.SetMapper(foheMapper) + outline = vtk.vtkOutlineFilter() outline.SetInputConnection(normals.GetOutputPort()) + mapOutline = vtk.vtkPolyDataMapper() mapOutline.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(mapOutline) -outlineActor.GetProperty().SetColor(0,0,0) +outlineActor.GetProperty().SetColor(0, 0, 0) + # Create the RenderWindow, Renderer, and setup viewports camera = vtk.vtkCamera() -camera.SetClippingRange(1.60187,20.0842) -camera.SetFocalPoint(0.21406,1.5,0) -camera.SetPosition(11.63,6.32,5.77) -camera.SetViewUp(0.180325,0.549245,-0.815974) +camera.SetClippingRange(1.60187, 20.0842) +camera.SetFocalPoint(0.21406, 1.5, 0) +camera.SetPosition(11.63, 6.32, 5.77) +camera.SetViewUp(0.180325, 0.549245, -0.815974) + light = vtk.vtkLight() -light.SetFocalPoint(0.21406,1.5,0) -light.SetPosition(8.3761,4.94858,4.12505) +light.SetFocalPoint(0.21406, 1.5, 0) +light.SetPosition(8.3761, 4.94858, 4.12505) + ren1 = vtk.vtkRenderer() -ren1.SetViewport(0,0,0.5,1.0) +ren1.SetViewport(0, 0, 0.5, 1.0) ren1.SetActiveCamera(camera) ren1.AddLight(light) + ren2 = vtk.vtkRenderer() -ren2.SetViewport(0.5,0,1.0,1.0) +ren2.SetViewport(0.5, 0, 1.0, 1.0) ren2.SetActiveCamera(camera) ren2.AddLight(light) + renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) renWin.AddRenderer(ren2) renWin.SetWindowName("VTK - Cube Axes") -renWin.SetSize(790,400) + +renWin.SetSize(790, 400) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddViewProp(foheActor) ren1.AddViewProp(outlineActor) + ren2.AddViewProp(foheActor) -if (info.command(globals(), locals(), "rtExMath") == ""): - ren2.AddViewProp(outlineActor) - pass -ren1.SetBackground(0.1,0.2,0.4) -ren2.SetBackground(0.1,0.2,0.4) +ren2.AddViewProp(outlineActor) + +ren1.SetBackground(0.1, 0.2, 0.4) +ren2.SetBackground(0.1, 0.2, 0.4) + tprop = vtk.vtkTextProperty() -tprop.SetColor(1,1,1) +tprop.SetColor(1, 1, 1) tprop.ShadowOn() + axes = vtk.vtkCubeAxesActor2D() axes.SetInputConnection(normals.GetOutputPort()) axes.SetCamera(ren1.GetActiveCamera()) @@ -67,7 +83,9 @@ axes.SetFlyModeToOuterEdges() axes.SetFontFactor(0.8) axes.SetAxisTitleTextProperty(tprop) axes.SetAxisLabelTextProperty(tprop) + ren1.AddViewProp(axes) + axes2 = vtk.vtkCubeAxesActor2D() axes2.SetViewProp(foheActor) axes2.SetCamera(ren2.GetActiveCamera()) @@ -77,17 +95,21 @@ axes2.SetFontFactor(axes.GetFontFactor()) axes2.ScalingOff() axes2.SetAxisTitleTextProperty(tprop) axes2.SetAxisLabelTextProperty(tprop) + ren2.AddViewProp(axes2) + renWin.Render() + # render the image # iren.Initialize() -def TkCheckAbort (__vtk__temp0=0,__vtk__temp1=0): + +def TkCheckAbort (object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) pass -renWin.AddObserver("AbortCheckEvent",TkCheckAbort) -# prevent the tk window from showing up then start the event loop -# --- end of script -- +renWin.AddObserver("AbortCheckEvent", TkCheckAbort) + +#iren.Start() diff --git a/Rendering/Annotation/Testing/Python/cubeAxes2.py b/Rendering/Annotation/Testing/Python/cubeAxes2.py index b78c49746e9..7edf238a8f8 100755 --- a/Rendering/Annotation/Testing/Python/cubeAxes2.py +++ b/Rendering/Annotation/Testing/Python/cubeAxes2.py @@ -1,51 +1,69 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # read in an interesting object and outline it # fohe = vtk.vtkBYUReader() -fohe.SetGeometryFileName("" + str(VTK_DATA_ROOT) + "/Data/teapot.g") +fohe.SetGeometryFileName(VTK_DATA_ROOT + "/Data/teapot.g") + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(fohe.GetOutputPort()) + foheMapper = vtk.vtkPolyDataMapper() foheMapper.SetInputConnection(normals.GetOutputPort()) + foheActor = vtk.vtkLODActor() foheActor.SetMapper(foheMapper) + outline = vtk.vtkOutlineFilter() outline.SetInputConnection(normals.GetOutputPort()) + mapOutline = vtk.vtkPolyDataMapper() mapOutline.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(mapOutline) -outlineActor.GetProperty().SetColor(0,0,0) +outlineActor.GetProperty().SetColor(0, 0, 0) + # Create the RenderWindow, Renderer, and setup viewports camera = vtk.vtkCamera() -camera.SetClippingRange(1.60187,20.0842) -camera.SetFocalPoint(0.21406,1.5,0) -camera.SetPosition(11.63,6.32,5.77) -camera.SetViewUp(0.180325,0.549245,-0.815974) +camera.SetClippingRange(1.60187, 20.0842) +camera.SetFocalPoint(0.21406, 1.5, 0) +camera.SetPosition(11.63, 6.32, 5.77) +camera.SetViewUp(0.180325, 0.549245, -0.815974) + light = vtk.vtkLight() -light.SetFocalPoint(0.21406,1.5,0) -light.SetPosition(8.3761,4.94858,4.12505) +light.SetFocalPoint(0.21406, 1.5, 0) +light.SetPosition(8.3761, 4.94858, 4.12505) + ren1 = vtk.vtkRenderer() -ren1.SetViewport(0,0,0.33,0.5) +ren1.SetViewport(0, 0, 0.33, 0.5) ren1.SetActiveCamera(camera) ren1.AddLight(light) + ren2 = vtk.vtkRenderer() -ren2.SetViewport(0.33,0,0.66,0.5) +ren2.SetViewport(0.33, 0, 0.66, 0.5) ren2.SetActiveCamera(camera) ren2.AddLight(light) + ren3 = vtk.vtkRenderer() -ren3.SetViewport(0.66,0,1.0,0.5) +ren3.SetViewport(0.66, 0, 1.0, 0.5) ren3.SetActiveCamera(camera) ren3.AddLight(light) + ren4 = vtk.vtkRenderer() -ren4.SetViewport(0,0.5,0.5,1.0) +ren4.SetViewport(0, 0.5, 0.5, 1.0) ren4.SetActiveCamera(camera) ren4.AddLight(light) + ren5 = vtk.vtkRenderer() -ren5.SetViewport(0.5,0.5,1.0,1.0) +ren5.SetViewport(0.5, 0.5, 1.0, 1.0) ren5.SetActiveCamera(camera) ren5.AddLight(light) + renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) @@ -54,82 +72,109 @@ renWin.AddRenderer(ren3) renWin.AddRenderer(ren4) renWin.AddRenderer(ren5) renWin.SetWindowName("VTK - Cube Axes") -renWin.SetSize(600,600) + +renWin.SetSize(600, 600) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddViewProp(foheActor) ren1.AddViewProp(outlineActor) + ren2.AddViewProp(foheActor) -if (info.command(globals(), locals(), "rtExMath") == ""): - ren2.AddViewProp(outlineActor) - pass +ren2.AddViewProp(outlineActor) + ren3.AddViewProp(foheActor) ren3.AddViewProp(outlineActor) + ren4.AddViewProp(foheActor) ren4.AddViewProp(outlineActor) + ren5.AddViewProp(foheActor) -ren1.SetBackground(0.1,0.2,0.4) -ren2.SetBackground(0.1,0.2,0.4) -ren3.SetBackground(0.1,0.2,0.4) -ren4.SetBackground(0.1,0.2,0.4) -ren5.SetBackground(0.1,0.2,0.4) + +ren1.SetBackground(0.1, 0.2, 0.4) +ren2.SetBackground(0.1, 0.2, 0.4) +ren3.SetBackground(0.1, 0.2, 0.4) +ren4.SetBackground(0.1, 0.2, 0.4) +ren5.SetBackground(0.1, 0.2, 0.4) + normals.Update() + bounds = normals.GetOutput().GetBounds() + axes = vtk.vtkCubeAxesActor() -axes.SetBounds(lindex(bounds,0),lindex(bounds,1),lindex(bounds,2),lindex(bounds,3),lindex(bounds,4),lindex(bounds,5)) +axes.SetBounds( + bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]) axes.SetCamera(ren1.GetActiveCamera()) axes.SetXLabelFormat("%6.1f") axes.SetYLabelFormat("%6.1f") axes.SetZLabelFormat("%6.1f") axes.SetFlyModeToOuterEdges() + ren1.AddViewProp(axes) + axes2 = vtk.vtkCubeAxesActor() -axes2.SetBounds(lindex(bounds,0),lindex(bounds,1),lindex(bounds,2),lindex(bounds,3),lindex(bounds,4),lindex(bounds,5)) +axes2.SetBounds( + bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]) axes2.SetCamera(ren2.GetActiveCamera()) axes2.SetXLabelFormat(axes.GetXLabelFormat()) axes2.SetYLabelFormat(axes.GetYLabelFormat()) axes2.SetZLabelFormat(axes.GetZLabelFormat()) axes2.SetFlyModeToClosestTriad() + ren2.AddViewProp(axes2) + axes3 = vtk.vtkCubeAxesActor() -axes3.SetBounds(lindex(bounds,0),lindex(bounds,1),lindex(bounds,2),lindex(bounds,3),lindex(bounds,4),lindex(bounds,5)) +axes3.SetBounds( + bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]) axes3.SetCamera(ren2.GetActiveCamera()) axes3.SetXLabelFormat(axes.GetXLabelFormat()) axes3.SetYLabelFormat(axes.GetYLabelFormat()) axes3.SetZLabelFormat(axes.GetZLabelFormat()) axes3.SetFlyModeToFurthestTriad() + ren3.AddViewProp(axes3) + bounds2 = axes3.GetBounds() + axes4 = vtk.vtkCubeAxesActor() -axes4.SetBounds(lindex(bounds2,0),lindex(bounds2,1),lindex(bounds2,2),lindex(bounds2,3),lindex(bounds2,4),lindex(bounds2,5)) +axes4.SetBounds( + bounds2[0], bounds2[1], bounds2[2], bounds2[3], bounds2[4], bounds2[5]) axes4.SetCamera(ren2.GetActiveCamera()) axes4.SetXLabelFormat(axes.GetXLabelFormat()) axes4.SetYLabelFormat(axes.GetYLabelFormat()) axes4.SetZLabelFormat(axes.GetZLabelFormat()) axes4.SetFlyModeToStaticTriad() + ren4.AddViewProp(axes4) + axes5 = vtk.vtkCubeAxesActor() -axes5.SetBounds(lindex(bounds2,0),lindex(bounds2,1),lindex(bounds2,2),lindex(bounds2,3),lindex(bounds2,4),lindex(bounds2,5)) +axes5.SetBounds( + bounds2[0], bounds2[1], bounds2[2], bounds2[3], bounds2[4], bounds2[5]) axes5.SetCamera(ren2.GetActiveCamera()) axes5.SetXLabelFormat(axes.GetXLabelFormat()) axes5.SetYLabelFormat(axes.GetYLabelFormat()) axes5.SetZLabelFormat(axes.GetZLabelFormat()) axes5.SetFlyModeToStaticEdges() + ren5.AddViewProp(axes5) + renWin.Render() # render the image # iren.Initialize() -def TkCheckAbort (__vtk__temp0=0,__vtk__temp1=0): + +def TkCheckAbort (object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) pass -renWin.AddObserver("AbortCheckEvent",TkCheckAbort) -# prevent the tk window from showing up then start the event loop -# for testing +renWin.AddObserver("AbortCheckEvent", TkCheckAbort) + + threshold = 13 -# --- end of script -- + +#iren.Start() diff --git a/Rendering/Annotation/Testing/Python/cubeAxes3.py b/Rendering/Annotation/Testing/Python/cubeAxes3.py index e7d1b56183a..aef6f1c7708 100755 --- a/Rendering/Annotation/Testing/Python/cubeAxes3.py +++ b/Rendering/Annotation/Testing/Python/cubeAxes3.py @@ -1,4 +1,8 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # This example illustrates how one may explicitly specify the range of each # axes that's used to define the prop, while displaying data with a different @@ -10,69 +14,89 @@ # read in an interesting object and outline it # fohe = vtk.vtkBYUReader() -fohe.SetGeometryFileName("" + str(VTK_DATA_ROOT) + "/Data/teapot.g") +fohe.SetGeometryFileName(VTK_DATA_ROOT + "/Data/teapot.g") + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(fohe.GetOutputPort()) + foheMapper = vtk.vtkPolyDataMapper() foheMapper.SetInputConnection(normals.GetOutputPort()) + foheActor = vtk.vtkLODActor() foheActor.SetMapper(foheMapper) -foheActor.GetProperty().SetDiffuseColor(0.7,0.3,0.0) +foheActor.GetProperty().SetDiffuseColor(0.7, 0.3, 0.0) + outline = vtk.vtkOutlineFilter() outline.SetInputConnection(normals.GetOutputPort()) + mapOutline = vtk.vtkPolyDataMapper() mapOutline.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(mapOutline) -outlineActor.GetProperty().SetColor(0,0,0) +outlineActor.GetProperty().SetColor(0, 0, 0) + # Create the RenderWindow, Renderer, and setup viewports camera = vtk.vtkCamera() -camera.SetClippingRange(1.0,100.0) -camera.SetFocalPoint(0.9,1.0,0.0) -camera.SetPosition(11.63,6.0,10.77) +camera.SetClippingRange(1.0, 100.0) +camera.SetFocalPoint(0.9, 1.0, 0.0) +camera.SetPosition(11.63, 6.0, 10.77) + light = vtk.vtkLight() -light.SetFocalPoint(0.21406,1.5,0) -light.SetPosition(8.3761,4.94858,4.12505) +light.SetFocalPoint(0.21406, 1.5, 0) +light.SetPosition(8.3761, 4.94858, 4.12505) + ren2 = vtk.vtkRenderer() ren2.SetActiveCamera(camera) ren2.AddLight(light) + renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.AddRenderer(ren2) renWin.SetWindowName("VTK - Cube Axes custom range") -renWin.SetSize(600,600) + +renWin.SetSize(600, 600) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren2.AddViewProp(foheActor) ren2.AddViewProp(outlineActor) -ren2.SetBackground(0.1,0.2,0.4) +ren2.SetBackground(0.1, 0.2, 0.4) + normals.Update() + bounds = normals.GetOutput().GetBounds() axes2 = vtk.vtkCubeAxesActor() -axes2.SetBounds(lindex(bounds,0),lindex(bounds,1),lindex(bounds,2),lindex(bounds,3),lindex(bounds,4),lindex(bounds,5)) -axes2.SetXAxisRange(20,300) -axes2.SetYAxisRange(-0.01,0.01) +axes2.SetBounds( + bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]) +axes2.SetXAxisRange(20, 300) +axes2.SetYAxisRange(-0.01, 0.01) axes2.SetCamera(ren2.GetActiveCamera()) axes2.SetXLabelFormat("%6.1f") axes2.SetYLabelFormat("%6.1f") axes2.SetZLabelFormat("%6.1f") axes2.SetFlyModeToClosestTriad() axes2.SetScreenSize(20.0) + ren2.AddViewProp(axes2) + renWin.Render() ren2.ResetCamera() renWin.Render() + # render the image # iren.Initialize() -def TkCheckAbort (__vtk__temp0=0,__vtk__temp1=0): + +def TkCheckAbort (object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) pass -renWin.AddObserver("AbortCheckEvent",TkCheckAbort) -# prevent the tk window from showing up then start the event loop -# --- end of script -- +renWin.AddObserver("AbortCheckEvent", TkCheckAbort) + +#iren.Start() diff --git a/Rendering/Core/Testing/Python/PolyDataMapperAllPolygons.py b/Rendering/Core/Testing/Python/PolyDataMapperAllPolygons.py index 1703eb46eff..7afd0d5d08b 100755 --- a/Rendering/Core/Testing/Python/PolyDataMapperAllPolygons.py +++ b/Rendering/Core/Testing/Python/PolyDataMapperAllPolygons.py @@ -9,122 +9,144 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + bmpReader = vtk.vtkBMPReader() -bmpReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/masonry.bmp") +bmpReader.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp") + texture = vtk.vtkTexture() texture.SetInputConnection(bmpReader.GetOutputPort()) + triangleStripPoints = vtk.vtkPoints() triangleStripPoints.SetNumberOfPoints(5) -triangleStripPoints.InsertPoint(0,0,1,0) -triangleStripPoints.InsertPoint(1,0,0,.5) -triangleStripPoints.InsertPoint(2,1,1,.3) -triangleStripPoints.InsertPoint(3,1,0,.6) -triangleStripPoints.InsertPoint(4,2,1,.1) +triangleStripPoints.InsertPoint(0, 0, 1, 0) +triangleStripPoints.InsertPoint(1, 0, 0, .5) +triangleStripPoints.InsertPoint(2, 1, 1, .3) +triangleStripPoints.InsertPoint(3, 1, 0, .6) +triangleStripPoints.InsertPoint(4, 2, 1, .1) + triangleStripTCoords = vtk.vtkFloatArray() triangleStripTCoords.SetNumberOfComponents(2) triangleStripTCoords.SetNumberOfTuples(5) -triangleStripTCoords.InsertTuple2(0,0,1) -triangleStripTCoords.InsertTuple2(1,0,0) -triangleStripTCoords.InsertTuple2(2,.5,1) -triangleStripTCoords.InsertTuple2(3,.5,0) -triangleStripTCoords.InsertTuple2(4,1,1) +triangleStripTCoords.InsertTuple2(0, 0, 1) +triangleStripTCoords.InsertTuple2(1, 0, 0) +triangleStripTCoords.InsertTuple2(2, .5, 1) +triangleStripTCoords.InsertTuple2(3, .5, 0) +triangleStripTCoords.InsertTuple2(4, 1, 1) + triangleStripPointScalars = vtk.vtkFloatArray() triangleStripPointScalars.SetNumberOfTuples(5) -triangleStripPointScalars.InsertValue(0,1) -triangleStripPointScalars.InsertValue(1,0) -triangleStripPointScalars.InsertValue(2,0) -triangleStripPointScalars.InsertValue(3,0) -triangleStripPointScalars.InsertValue(4,0) +triangleStripPointScalars.InsertValue(0, 1) +triangleStripPointScalars.InsertValue(1, 0) +triangleStripPointScalars.InsertValue(2, 0) +triangleStripPointScalars.InsertValue(3, 0) +triangleStripPointScalars.InsertValue(4, 0) + triangleStripCellScalars = vtk.vtkFloatArray() triangleStripCellScalars.SetNumberOfTuples(1) -triangleStripCellScalars.InsertValue(0,1) +triangleStripCellScalars.InsertValue(0, 1) + triangleStripPointNormals = vtk.vtkFloatArray() triangleStripPointNormals.SetNumberOfComponents(3) triangleStripPointNormals.SetNumberOfTuples(5) -triangleStripPointNormals.InsertTuple3(0,0,0,1) -triangleStripPointNormals.InsertTuple3(1,0,1,0) -triangleStripPointNormals.InsertTuple3(2,0,1,1) -triangleStripPointNormals.InsertTuple3(3,1,0,0) -triangleStripPointNormals.InsertTuple3(4,1,0,1) +triangleStripPointNormals.InsertTuple3(0, 0, 0, 1) +triangleStripPointNormals.InsertTuple3(1, 0, 1, 0) +triangleStripPointNormals.InsertTuple3(2, 0, 1, 1) +triangleStripPointNormals.InsertTuple3(3, 1, 0, 0) +triangleStripPointNormals.InsertTuple3(4, 1, 0, 1) + triangleStripCellNormals = vtk.vtkFloatArray() triangleStripCellNormals.SetNumberOfComponents(3) triangleStripCellNormals.SetNumberOfTuples(1) -triangleStripCellNormals.InsertTuple3(0,0,0,1) +triangleStripCellNormals.InsertTuple3(0, 0, 0, 1) + aTriangleStrip = vtk.vtkTriangleStrip() aTriangleStrip.GetPointIds().SetNumberOfIds(5) -aTriangleStrip.GetPointIds().SetId(0,0) -aTriangleStrip.GetPointIds().SetId(1,1) -aTriangleStrip.GetPointIds().SetId(2,2) -aTriangleStrip.GetPointIds().SetId(3,3) -aTriangleStrip.GetPointIds().SetId(4,4) +aTriangleStrip.GetPointIds().SetId(0, 0) +aTriangleStrip.GetPointIds().SetId(1, 1) +aTriangleStrip.GetPointIds().SetId(2, 2) +aTriangleStrip.GetPointIds().SetId(3, 3) +aTriangleStrip.GetPointIds().SetId(4, 4) + lut = vtk.vtkLookupTable() lut.SetNumberOfColors(5) -lut.SetTableValue(0,0,0,1,1) -lut.SetTableValue(1,0,1,0,1) -lut.SetTableValue(2,0,1,1,1) -lut.SetTableValue(3,1,0,0,1) -lut.SetTableValue(4,1,0,1,1) -masks = "0 1 2 3 4 5 6 7 10 11 14 15 16 18 20 22 26 30" +lut.SetTableValue(0, 0, 0, 1, 1) +lut.SetTableValue(1, 0, 1, 0, 1) +lut.SetTableValue(2, 0, 1, 1, 1) +lut.SetTableValue(3, 1, 0, 0, 1) +lut.SetTableValue(4, 1, 0, 1, 1) + +masks = [0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 14, 15, 16, 18, 20, 22, 26, 30] +types = ["strip", "triangle"] i = 0 j = 0 k = 0 -types = "strip triangle" -for type in types.split(): - for mask in masks.split(): - locals()[get_variable_name("grid", i, "")] = vtk.vtkUnstructuredGrid() - locals()[get_variable_name("grid", i, "")].Allocate(1,1) - locals()[get_variable_name("grid", i, "")].InsertNextCell(aTriangleStrip.GetCellType(),aTriangleStrip.GetPointIds()) - locals()[get_variable_name("grid", i, "")].SetPoints(triangleStripPoints) - locals()[get_variable_name("geometry", i, "")] = vtk.vtkGeometryFilter() - locals()[get_variable_name("geometry", i, "")].SetInputData(locals()[get_variable_name("grid", i, "")]) - locals()[get_variable_name("triangles", i, "")] = vtk.vtkTriangleFilter() - locals()[get_variable_name("triangles", i, "")].SetInputConnection(locals()[get_variable_name("geometry", i, "")].GetOutputPort()) - locals()[get_variable_name("mapper", i, "")] = vtk.vtkPolyDataMapper() +for type in types: + for mask in masks: + idx = str(i) + exec("grid" + idx + " = vtk.vtkUnstructuredGrid()") + eval("grid" + idx).Allocate(1, 1) + eval("grid" + idx).InsertNextCell(aTriangleStrip.GetCellType(), + aTriangleStrip.GetPointIds()) + eval("grid" + idx).SetPoints(triangleStripPoints) + + exec("geometry" + idx + " = vtk.vtkGeometryFilter()") + eval("geometry" + idx).SetInputData(eval("grid" + idx)) + + exec("triangles" + idx + " = vtk.vtkTriangleFilter()") + eval("triangles" + idx).SetInputConnection( + eval("geometry" + idx).GetOutputPort()) + + exec("mapper" + idx + " = vtk.vtkPolyDataMapper()") if (type == "strip"): - locals()[get_variable_name("mapper", i, "")].SetInputConnection(locals()[get_variable_name("geometry", i, "")].GetOutputPort()) - pass + eval("mapper" + idx).SetInputConnection( + eval("geometry" + idx).GetOutputPort()) + if (type == "triangle"): - locals()[get_variable_name("mapper", i, "")].SetInputConnection(locals()[get_variable_name("triangles", i, "")].GetOutputPort()) - pass - locals()[get_variable_name("mapper", i, "")].SetLookupTable(lut) - locals()[get_variable_name("mapper", i, "")].SetScalarRange(0,4) - locals()[get_variable_name("actor", i, "")] = vtk.vtkActor() - locals()[get_variable_name("actor", i, "")].SetMapper(locals()[get_variable_name("mapper", i, "")]) - if (expr.expr(globals(), locals(),["mask","&","1"]) != 0): - locals()[get_variable_name("grid", i, "")].GetPointData().SetNormals(triangleStripPointNormals) - pass - if (expr.expr(globals(), locals(),["mask","&","2"]) != 0): - locals()[get_variable_name("grid", i, "")].GetPointData().SetScalars(triangleStripPointScalars) - locals()[get_variable_name("mapper", i, "")].SetScalarModeToUsePointData() - pass - if (expr.expr(globals(), locals(),["mask","&","4"]) != 0): - locals()[get_variable_name("grid", i, "")].GetPointData().SetTCoords(triangleStripTCoords) - locals()[get_variable_name("actor", i, "")].SetTexture(texture) - pass - if (expr.expr(globals(), locals(),["mask","&","8"]) != 0): - locals()[get_variable_name("grid", i, "")].GetCellData().SetScalars(triangleStripCellScalars) - locals()[get_variable_name("mapper", i, "")].SetScalarModeToUseCellData() - pass - if (expr.expr(globals(), locals(),["mask","&","16"]) != 0): - locals()[get_variable_name("grid", i, "")].GetCellData().SetNormals(triangleStripCellNormals) - pass - locals()[get_variable_name("actor", i, "")].AddPosition(expr.expr(globals(), locals(),["j","*","2"]),expr.expr(globals(), locals(),["k","*","2"]),0) - ren1.AddActor(locals()[get_variable_name("actor", i, "")]) - j = j + 1 + eval("mapper" + idx).SetInputConnection( + eval("triangles" + idx).GetOutputPort()) + + eval("mapper" + idx).SetLookupTable(lut) + eval("mapper" + idx).SetScalarRange(0, 4) + + exec("actor" + idx + " = vtk.vtkActor()") + eval("actor" + idx).SetMapper(eval("mapper" + idx)) + + if mask & 1 != 0: + eval("grid" + idx).GetPointData().SetNormals( + triangleStripPointNormals) + if mask & 2 != 0: + eval("grid" + idx).GetPointData().SetScalars( + triangleStripPointScalars) + eval("mapper" + idx).SetScalarModeToUsePointData() + if mask & 4 != 0: + eval("grid" + idx).GetPointData().SetTCoords( + triangleStripTCoords) + eval("actor" + idx).SetTexture(texture) + if mask & 8 != 0: + eval("grid" + idx).GetCellData().SetScalars( + triangleStripCellScalars) + eval("mapper" + idx).SetScalarModeToUseCellData() + if mask & 16 != 0: + eval("grid" + idx).GetCellData().SetNormals( + triangleStripCellNormals) + + eval("actor" + idx).AddPosition(j * 2, k * 2, 0) + + ren1.AddActor(eval("actor" + idx)) + + j += 1 if (j >= 6): j = 0 - k = k + 1 - pass - i = i + 1 + k += 1 + i += 1 - pass +renWin.SetSize(480, 480) - pass -renWin.SetSize(480,480) -ren1.SetBackground(.7,.3,.1) +ren1.SetBackground(.7, .3, .1) ren1.ResetCameraClippingRange() renWin.Render() + # render the image # iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Rendering/Core/Testing/Python/PolyDataMapperAllWireframe.py b/Rendering/Core/Testing/Python/PolyDataMapperAllWireframe.py index d4b4e28ddf1..e877b91e3f9 100755 --- a/Rendering/Core/Testing/Python/PolyDataMapperAllWireframe.py +++ b/Rendering/Core/Testing/Python/PolyDataMapperAllWireframe.py @@ -10,124 +10,148 @@ renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + pnmReader = vtk.vtkBMPReader() -pnmReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/masonry.bmp") +pnmReader.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp") + texture = vtk.vtkTexture() texture.SetInputConnection(pnmReader.GetOutputPort()) + triangleStripPoints = vtk.vtkPoints() triangleStripPoints.SetNumberOfPoints(5) -triangleStripPoints.InsertPoint(0,0,1,0) -triangleStripPoints.InsertPoint(1,0,0,.5) -triangleStripPoints.InsertPoint(2,1,1,.3) -triangleStripPoints.InsertPoint(3,1,0,.6) -triangleStripPoints.InsertPoint(4,2,1,.1) +triangleStripPoints.InsertPoint(0, 0, 1, 0) +triangleStripPoints.InsertPoint(1, 0, 0, .5) +triangleStripPoints.InsertPoint(2, 1, 1, .3) +triangleStripPoints.InsertPoint(3, 1, 0, .6) +triangleStripPoints.InsertPoint(4, 2, 1, .1) + triangleStripTCoords = vtk.vtkFloatArray() triangleStripTCoords.SetNumberOfComponents(2) triangleStripTCoords.SetNumberOfTuples(5) -triangleStripTCoords.InsertTuple2(0,0,1) -triangleStripTCoords.InsertTuple2(1,0,0) -triangleStripTCoords.InsertTuple2(2,.5,1) -triangleStripTCoords.InsertTuple2(3,.5,0) -triangleStripTCoords.InsertTuple2(4,1,1) +triangleStripTCoords.InsertTuple2(0, 0, 1) +triangleStripTCoords.InsertTuple2(1, 0, 0) +triangleStripTCoords.InsertTuple2(2, .5, 1) +triangleStripTCoords.InsertTuple2(3, .5, 0) +triangleStripTCoords.InsertTuple2(4, 1, 1) + triangleStripPointScalars = vtk.vtkFloatArray() triangleStripPointScalars.SetNumberOfTuples(5) -triangleStripPointScalars.InsertValue(0,1) -triangleStripPointScalars.InsertValue(1,0) -triangleStripPointScalars.InsertValue(2,0) -triangleStripPointScalars.InsertValue(3,0) -triangleStripPointScalars.InsertValue(4,0) +triangleStripPointScalars.InsertValue(0, 1) +triangleStripPointScalars.InsertValue(1, 0) +triangleStripPointScalars.InsertValue(2, 0) +triangleStripPointScalars.InsertValue(3, 0) +triangleStripPointScalars.InsertValue(4, 0) + triangleStripCellScalars = vtk.vtkFloatArray() triangleStripCellScalars.SetNumberOfTuples(1) -triangleStripCellScalars.InsertValue(0,1) +triangleStripCellScalars.InsertValue(0, 1) + triangleStripPointNormals = vtk.vtkFloatArray() triangleStripPointNormals.SetNumberOfComponents(3) triangleStripPointNormals.SetNumberOfTuples(5) -triangleStripPointNormals.InsertTuple3(0,0,0,1) -triangleStripPointNormals.InsertTuple3(1,0,1,0) -triangleStripPointNormals.InsertTuple3(2,0,1,1) -triangleStripPointNormals.InsertTuple3(3,1,0,0) -triangleStripPointNormals.InsertTuple3(4,1,0,1) +triangleStripPointNormals.InsertTuple3(0, 0, 0, 1) +triangleStripPointNormals.InsertTuple3(1, 0, 1, 0) +triangleStripPointNormals.InsertTuple3(2, 0, 1, 1) +triangleStripPointNormals.InsertTuple3(3, 1, 0, 0) +triangleStripPointNormals.InsertTuple3(4, 1, 0, 1) + triangleStripCellNormals = vtk.vtkFloatArray() triangleStripCellNormals.SetNumberOfComponents(3) triangleStripCellNormals.SetNumberOfTuples(1) -triangleStripCellNormals.InsertTuple3(0,1,1,1) +triangleStripCellNormals.InsertTuple3(0, 1, 1, 1) + aTriangleStrip = vtk.vtkTriangleStrip() aTriangleStrip.GetPointIds().SetNumberOfIds(5) -aTriangleStrip.GetPointIds().SetId(0,0) -aTriangleStrip.GetPointIds().SetId(1,1) -aTriangleStrip.GetPointIds().SetId(2,2) -aTriangleStrip.GetPointIds().SetId(3,3) -aTriangleStrip.GetPointIds().SetId(4,4) +aTriangleStrip.GetPointIds().SetId(0, 0) +aTriangleStrip.GetPointIds().SetId(1, 1) +aTriangleStrip.GetPointIds().SetId(2, 2) +aTriangleStrip.GetPointIds().SetId(3, 3) +aTriangleStrip.GetPointIds().SetId(4, 4) + lut = vtk.vtkLookupTable() lut.SetNumberOfColors(5) -lut.SetTableValue(0,0,0,1,1) -lut.SetTableValue(1,0,1,0,1) -lut.SetTableValue(2,0,1,1,1) -lut.SetTableValue(3,1,0,0,1) -lut.SetTableValue(4,1,0,1,1) -masks = "0 1 2 3 4 5 6 7 10 11 14 15 16 18 20 22 26 30" +lut.SetTableValue(0, 0, 0, 1, 1) +lut.SetTableValue(1, 0, 1, 0, 1) +lut.SetTableValue(2, 0, 1, 1, 1) +lut.SetTableValue(3, 1, 0, 0, 1) +lut.SetTableValue(4, 1, 0, 1, 1) + +masks = [0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 14, 15, 16, 18, 20, 22, 26, 30] +types = ["strip", "triangle"] i = 0 j = 0 k = 0 -types = "strip triangle" -for type in types.split(): - for mask in masks.split(): - locals()[get_variable_name("grid", i, "")] = vtk.vtkUnstructuredGrid() - locals()[get_variable_name("grid", i, "")].Allocate(1,1) - locals()[get_variable_name("grid", i, "")].InsertNextCell(aTriangleStrip.GetCellType(),aTriangleStrip.GetPointIds()) - locals()[get_variable_name("grid", i, "")].SetPoints(triangleStripPoints) - locals()[get_variable_name("geometry", i, "")] = vtk.vtkGeometryFilter() - locals()[get_variable_name("geometry", i, "")].SetInputData(locals()[get_variable_name("grid", i, "")]) - locals()[get_variable_name("triangles", i, "")] = vtk.vtkTriangleFilter() - locals()[get_variable_name("triangles", i, "")].SetInputConnection(locals()[get_variable_name("geometry", i, "")].GetOutputPort()) - locals()[get_variable_name("mapper", i, "")] = vtk.vtkPolyDataMapper() +for type in types: + for mask in masks: + idx = str(i) + exec("grid" + idx + " = vtk.vtkUnstructuredGrid()") + eval("grid" + idx).Allocate(1, 1) + eval("grid" + idx).InsertNextCell( + aTriangleStrip.GetCellType(), aTriangleStrip.GetPointIds()) + eval("grid" + idx).SetPoints(triangleStripPoints) + + exec("geometry" + idx + " = vtk.vtkGeometryFilter()") + eval("geometry" + idx).SetInputData(eval("grid" + idx)) + + exec("triangles" + idx + " = vtk.vtkTriangleFilter()") + eval("triangles" + idx).SetInputConnection( + eval("geometry" + idx).GetOutputPort()) + + exec("mapper" + idx + " = vtk.vtkPolyDataMapper()") if (type == "strip"): - locals()[get_variable_name("mapper", i, "")].SetInputConnection(locals()[get_variable_name("geometry", i, "")].GetOutputPort()) - pass + eval("mapper" + idx).SetInputConnection( + eval("geometry" + idx).GetOutputPort()) + if (type == "triangle"): - locals()[get_variable_name("mapper", i, "")].SetInputConnection(locals()[get_variable_name("triangles", i, "")].GetOutputPort()) - pass - locals()[get_variable_name("mapper", i, "")].SetLookupTable(lut) - locals()[get_variable_name("mapper", i, "")].SetScalarRange(0,4) - locals()[get_variable_name("actor", i, "")] = vtk.vtkActor() - locals()[get_variable_name("actor", i, "")].SetMapper(locals()[get_variable_name("mapper", i, "")]) - if (expr.expr(globals(), locals(),["mask","&","1"]) != 0): - locals()[get_variable_name("grid", i, "")].GetPointData().SetNormals(triangleStripPointNormals) - pass - if (expr.expr(globals(), locals(),["mask","&","2"]) != 0): - locals()[get_variable_name("grid", i, "")].GetPointData().SetScalars(triangleStripPointScalars) - locals()[get_variable_name("mapper", i, "")].SetScalarModeToUsePointData() - pass - if (expr.expr(globals(), locals(),["mask","&","4"]) != 0): - locals()[get_variable_name("grid", i, "")].GetPointData().SetTCoords(triangleStripTCoords) - locals()[get_variable_name("actor", i, "")].SetTexture(texture) - pass - if (expr.expr(globals(), locals(),["mask","&","8"]) != 0): - locals()[get_variable_name("grid", i, "")].GetCellData().SetScalars(triangleStripCellScalars) - locals()[get_variable_name("mapper", i, "")].SetScalarModeToUseCellData() - pass - if (expr.expr(globals(), locals(),["mask","&","16"]) != 0): - locals()[get_variable_name("grid", i, "")].GetCellData().SetNormals(triangleStripCellNormals) - pass - locals()[get_variable_name("actor", i, "")].AddPosition(expr.expr(globals(), locals(),["j","*","2"]),expr.expr(globals(), locals(),["k","*","2"]),0) - ren1.AddActor(locals()[get_variable_name("actor", i, "")]) - locals()[get_variable_name("actor", i, "")].GetProperty().SetRepresentationToWireframe() - j = j + 1 + eval("mapper" + idx).SetInputConnection( + eval("triangles" + idx).GetOutputPort()) + + eval("mapper" + idx).SetLookupTable(lut) + eval("mapper" + idx).SetScalarRange(0, 4) + + exec("actor" + idx + " = vtk.vtkActor()") + eval("actor" + idx).SetMapper(eval("mapper" + idx)) + + if mask & 1 != 0: + eval("grid" + idx).GetPointData().SetNormals( + triangleStripPointNormals) + if mask & 2 != 0: + eval("grid" + idx).GetPointData().SetScalars( + triangleStripPointScalars) + eval("mapper" + idx).SetScalarModeToUsePointData() + if mask & 4 != 0: + eval("grid" + idx).GetPointData().SetTCoords( + triangleStripTCoords) + eval("actor" + idx).SetTexture(texture) + if mask & 8 != 0: + eval("grid" + idx).GetCellData().SetScalars( + triangleStripCellScalars) + eval("mapper" + idx).SetScalarModeToUseCellData() + if mask & 16 != 0: + eval("grid" + idx).GetCellData().SetNormals( + triangleStripCellNormals) + + eval("actor" + idx).AddPosition(j * 2, k * 2, 0) + + ren1.AddActor(eval("actor" + idx)) + eval("actor" + idx).GetProperty().SetRepresentationToWireframe() + + j += 1 if (j >= 6): j = 0 - k = k + 1 - pass - i = i + 1 + k += 1 + i += 1 - pass +renWin.SetSize(480, 480) - pass -renWin.SetSize(480,480) -ren1.SetBackground(.7,.3,.1) +ren1.SetBackground(.7, .3, .1) ren1.ResetCameraClippingRange() renWin.Render() + # render the image # iren.Initialize() + threshold = 15 -# --- end of script -- + +#iren.Start() diff --git a/Rendering/Core/Testing/Python/TestCameraInterpolator.py b/Rendering/Core/Testing/Python/TestCameraInterpolator.py index 38634d8edb5..cf691f478b1 100755 --- a/Rendering/Core/Testing/Python/TestCameraInterpolator.py +++ b/Rendering/Core/Testing/Python/TestCameraInterpolator.py @@ -5,33 +5,41 @@ from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() lut = vtk.vtkLookupTable() -lut.SetHueRange(0.6,0) -lut.SetSaturationRange(1.0,0) -lut.SetValueRange(0.5,1.0) +lut.SetHueRange(0.6, 0) +lut.SetSaturationRange(1.0, 0) +lut.SetValueRange(0.5, 1.0) + # Read the data: a height field results demReader = vtk.vtkDEMReader() -demReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/SainteHelens.dem") +demReader.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem") demReader.Update() -lo = lindex(demReader.GetOutput().GetScalarRange(),0) -hi = lindex(demReader.GetOutput().GetScalarRange(),1) + +lo = demReader.GetOutput().GetScalarRange()[0] +hi = demReader.GetOutput().GetScalarRange()[1] + surface = vtk.vtkImageDataGeometryFilter() surface.SetInputConnection(demReader.GetOutputPort()) + warp = vtk.vtkWarpScalar() warp.SetInputConnection(surface.GetOutputPort()) warp.SetScaleFactor(1) warp.UseNormalOn() -warp.SetNormal(0,0,1) +warp.SetNormal(0, 0, 1) warp.Update() + normals = vtk.vtkPolyDataNormals() normals.SetInputData(warp.GetPolyDataOutput()) normals.SetFeatureAngle(60) normals.SplittingOff() + demMapper = vtk.vtkPolyDataMapper() demMapper.SetInputConnection(normals.GetOutputPort()) -demMapper.SetScalarRange(lo,hi) +demMapper.SetScalarRange(lo, hi) demMapper.SetLookupTable(lut) + demActor = vtk.vtkLODActor() demActor.SetMapper(demMapper) + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -39,67 +47,79 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Add the actors to the renderer, set the background and size # ren1.AddActor(demActor) -ren1.SetBackground(0,0,0) -renWin.SetSize(300,300) -ren1.SetBackground(0.1,0.2,0.4) +ren1.SetBackground(0, 0, 0) + +renWin.SetSize(300, 300) + +ren1.SetBackground(0.1, 0.2, 0.4) # render the image # renWin.Render() -# prevent the tk window from showing up then start the event loop + view1 = vtk.vtkCamera() -view1.SetClippingRange(30972.2,35983.7) -view1.SetFocalPoint(562835,5.11498e+006,2294.5) -view1.SetPosition(562835,5.11498e+006,35449.9) +view1.SetClippingRange(30972.2, 35983.7) +view1.SetFocalPoint(562835, 5.11498e+006, 2294.5) +view1.SetPosition(562835, 5.11498e+006, 35449.9) view1.SetViewAngle(30) -view1.SetViewUp(0,1,0) +view1.SetViewUp(0, 1, 0) + view2 = vtk.vtkCamera() -view2.SetClippingRange(9013.43,13470.4) -view2.SetFocalPoint(562835,5.11498e+006,2294.5) -view2.SetPosition(562835,5.11498e+006,13269.4) +view2.SetClippingRange(9013.43, 13470.4) +view2.SetFocalPoint(562835, 5.11498e+006, 2294.5) +view2.SetPosition(562835, 5.11498e+006, 13269.4) view2.SetViewAngle(30) -view2.SetViewUp(0,1,0) +view2.SetViewUp(0, 1, 0) + view3 = vtk.vtkCamera() -view3.SetClippingRange(4081.2,13866.4) -view3.SetFocalPoint(562853,5.11586e+006,2450.05) -view3.SetPosition(562853,5.1144e+006,10726.6) +view3.SetClippingRange(4081.2, 13866.4) +view3.SetFocalPoint(562853, 5.11586e+006, 2450.05) +view3.SetPosition(562853, 5.1144e+006, 10726.6) view3.SetViewAngle(30) -view3.SetViewUp(0,0.984808,0.173648) +view3.SetViewUp(0, 0.984808, 0.173648) + view4 = vtk.vtkCamera() -view4.SetClippingRange(14.0481,14048.1) -view4.SetFocalPoint(562880,5.11652e+006,2733.15) -view4.SetPosition(562974,5.11462e+006,6419.98) +view4.SetClippingRange(14.0481, 14048.1) +view4.SetFocalPoint(562880, 5.11652e+006, 2733.15) +view4.SetPosition(562974, 5.11462e+006, 6419.98) view4.SetViewAngle(30) -view4.SetViewUp(0.0047047,0.888364,0.459116) +view4.SetViewUp(0.0047047, 0.888364, 0.459116) + view5 = vtk.vtkCamera() -view5.SetClippingRange(14.411,14411) -view5.SetFocalPoint(562910,5.11674e+006,3027.15) -view5.SetPosition(562414,5.11568e+006,3419.87) +view5.SetClippingRange(14.411, 14411) +view5.SetFocalPoint(562910, 5.11674e+006, 3027.15) +view5.SetPosition(562414, 5.11568e+006, 3419.87) view5.SetViewAngle(30) -view5.SetViewUp(-0.0301976,0.359864,0.932516) +view5.SetViewUp(-0.0301976, 0.359864, 0.932516) + interpolator = vtk.vtkCameraInterpolator() interpolator.SetInterpolationTypeToSpline() -interpolator.AddCamera(0,view1) -interpolator.AddCamera(5,view2) -interpolator.AddCamera(7.5,view3) -interpolator.AddCamera(9.0,view4) -interpolator.AddCamera(11.0,view5) +interpolator.AddCamera(0, view1) +interpolator.AddCamera(5, view2) +interpolator.AddCamera(7.5, view3) +interpolator.AddCamera(9.0, view4) +interpolator.AddCamera(11.0, view5) + camera = vtk.vtkCamera() ren1.SetActiveCamera(camera) -def animate (__vtk__temp0=0,__vtk__temp1=0): + +def animate(): numSteps = 500 min = interpolator.GetMinimumT() max = interpolator.GetMaximumT() i = 0 while i <= numSteps: - t = expr.expr(globals(), locals(),["double","(","i",")","*","(","max","-","min",")","/","double","(","numSteps",")"]) - interpolator.InterpolateCamera(t,camera) + t = float(i) * (max - min) / float(numSteps) + interpolator.InterpolateCamera(t, camera) renWin.Render() - i = i + 1 + i += 1 + + +interpolator.InterpolateCamera(8.2, camera) +# animate() -interpolator.InterpolateCamera(8.2,camera) -#animate -# --- end of script -- +#iren.Start() diff --git a/Rendering/Core/Testing/Python/TestGenericVertexAttributesGLSL.py b/Rendering/Core/Testing/Python/TestGenericVertexAttributesGLSL.py index b2edada76e8..f4042bfa291 100755 --- a/Rendering/Core/Testing/Python/TestGenericVertexAttributesGLSL.py +++ b/Rendering/Core/Testing/Python/TestGenericVertexAttributesGLSL.py @@ -1,4 +1,9 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() + # tests the support to pass generic vertex attributes to be used in Cg shaders. xmlMaterial = '''<?xml version="1.0" encoding="UTF-8"?> @@ -34,32 +39,43 @@ iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) renderer = vtk.vtkRenderer() renWin.AddRenderer(renderer) + src1 = vtk.vtkSphereSource() src1.SetRadius(5) src1.SetPhiResolution(20) src1.SetThetaResolution(20) + randomVectors = vtk.vtkBrownianPoints() randomVectors.SetMinimumSpeed(0) randomVectors.SetMaximumSpeed(1) randomVectors.SetInputConnection(src1.GetOutputPort()) + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(randomVectors.GetOutputPort()) + actor = vtk.vtkActor() actor.SetMapper(mapper) + # Load the material. Here, we are loading a material -# defined in the Vtk Library. One can also specify +# defined in the VTK Library. One can also specify # a filename to a material description xml. actor.GetProperty().LoadMaterialFromString(xmlMaterial) # Set red color to show if shading fails. -actor.GetProperty().SetColor(1.0,0,0) +actor.GetProperty().SetColor(1.0, 0, 0) # Turn shading on. Otherwise, shaders are not used. actor.GetProperty().ShadingOn() + # Map PointData.BrownianVectors (all 3 components) to genAttrVector -mapper.MapDataArrayToVertexAttribute("genAttrVector","BrownianVectors",0,-1) +mapper.MapDataArrayToVertexAttribute("genAttrVector", "BrownianVectors", 0, -1) + renderer.AddActor(actor) -renderer.SetBackground(0.5,0.5,0.5) +renderer.SetBackground(0.5, 0.5, 0.5) + renWin.Render() + renderer.GetActiveCamera().Azimuth(-50) renderer.GetActiveCamera().Roll(70) + renWin.Render() -# --- end of script -- + +#iren.Start() diff --git a/Rendering/Core/Testing/Python/TestLeaderActor2D.py b/Rendering/Core/Testing/Python/TestLeaderActor2D.py index a7d85f53942..219685080a2 100755 --- a/Rendering/Core/Testing/Python/TestLeaderActor2D.py +++ b/Rendering/Core/Testing/Python/TestLeaderActor2D.py @@ -1,38 +1,46 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # create pipeline # leader = vtk.vtkLeaderActor2D() leader.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport() -leader.GetPositionCoordinate().SetValue(0.1,0.1) +leader.GetPositionCoordinate().SetValue(0.1, 0.1) leader.GetPosition2Coordinate().SetCoordinateSystemToNormalizedViewport() -leader.GetPosition2Coordinate().SetValue(0.75,0.23) +leader.GetPosition2Coordinate().SetValue(0.75, 0.23) leader.SetArrowStyleToFilled() leader.SetLabel("") + leader2 = vtk.vtkLeaderActor2D() leader2.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport() -leader2.GetPositionCoordinate().SetValue(0.9,0.1) +leader2.GetPositionCoordinate().SetValue(0.9, 0.1) leader2.GetPosition2Coordinate().SetCoordinateSystemToNormalizedViewport() -leader2.GetPosition2Coordinate().SetValue(0.75,0.83) +leader2.GetPosition2Coordinate().SetValue(0.75, 0.83) leader2.SetArrowStyleToOpen() leader2.SetArrowPlacementToPoint1() leader2.SetLabel("Leader2") + leader3 = vtk.vtkLeaderActor2D() leader3.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport() -leader3.GetPositionCoordinate().SetValue(0.1,0.9) +leader3.GetPositionCoordinate().SetValue(0.1, 0.9) leader3.GetPosition2Coordinate().SetCoordinateSystemToNormalizedViewport() -leader3.GetPosition2Coordinate().SetValue(0.6,0.3) +leader3.GetPosition2Coordinate().SetValue(0.6, 0.3) leader3.SetArrowStyleToHollow() leader3.SetLabel("Leader3") + leader4 = vtk.vtkLeaderActor2D() leader4.GetPositionCoordinate().SetCoordinateSystemToNormalizedViewport() -leader4.GetPositionCoordinate().SetValue(0.1,0.75) +leader4.GetPositionCoordinate().SetValue(0.1, 0.75) leader4.GetPosition2Coordinate().SetCoordinateSystemToNormalizedViewport() -leader4.GetPosition2Coordinate().SetValue(0.1,0.25) +leader4.GetPosition2Coordinate().SetValue(0.1, 0.25) leader4.SetArrowPlacementToNone() leader4.SetRadius(1.0) leader4.SetLabel("Leader4") leader4.AutoLabelOn() + # Create graphics stuff # Create the RenderWindow, Renderer and both Actors # @@ -41,13 +49,15 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + ren1.AddActor(leader) ren1.AddActor(leader2) ren1.AddActor(leader3) ren1.AddActor(leader4) -renWin.SetSize(250,250) + +renWin.SetSize(250, 250) + # render the image # renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Rendering/Core/Testing/Python/TestOpacity2.py b/Rendering/Core/Testing/Python/TestOpacity2.py index 1df9c64e1c8..943837f7d7d 100755 --- a/Rendering/Core/Testing/Python/TestOpacity2.py +++ b/Rendering/Core/Testing/Python/TestOpacity2.py @@ -1,78 +1,100 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() cone = vtk.vtkConeSource() cone.SetHeight(3.0) cone.SetRadius(1.0) cone.SetResolution(10) + coneMapper = vtk.vtkPolyDataMapper() coneMapper.SetInputConnection(cone.GetOutputPort()) + # Actor for opacity as a property value. coneActor = vtk.vtkActor() coneActor.SetMapper(coneMapper) coneActor.GetProperty().SetOpacity(0.5) + # Actor for opacity thru LUT. elevation = vtk.vtkElevationFilter() elevation.SetInputConnection(cone.GetOutputPort()) + coneMapper2 = vtk.vtkPolyDataMapper() coneMapper2.SetInputConnection(elevation.GetOutputPort()) + lut = vtk.vtkLookupTable() -lut.SetAlphaRange(0.9,0.1) -lut.SetHueRange(0,0) -lut.SetSaturationRange(1,1) -lut.SetValueRange(1,1) +lut.SetAlphaRange(0.9, 0.1) +lut.SetHueRange(0, 0) +lut.SetSaturationRange(1, 1) +lut.SetValueRange(1, 1) + coneMapper2.SetLookupTable(lut) coneMapper2.SetScalarModeToUsePointData() coneMapper2.SetScalarVisibility(1) coneMapper2.InterpolateScalarsBeforeMappingOn() + coneActorLUT = vtk.vtkActor() coneActorLUT.SetMapper(coneMapper2) -coneActorLUT.SetPosition(0.1,1.0,0) +coneActorLUT.SetPosition(0.1, 1.0, 0) coneActorLUT.GetProperty().SetOpacity(0.99) + # Actor for opacity thru texture. reader = vtk.vtkPNGReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/alphachannel.png") +reader.SetFileName(VTK_DATA_ROOT + "/Data/alphachannel.png") reader.Update() + sphere = vtk.vtkSphereSource() + texture = vtk.vtkTexture() texture.SetInputConnection(reader.GetOutputPort()) + coneMapper3 = vtk.vtkPolyDataMapper() coneMapper3.SetInputConnection(sphere.GetOutputPort()) + coneActorTexture = vtk.vtkActor() coneActorTexture.SetTexture(texture) coneActorTexture.SetMapper(coneMapper3) -coneActorTexture.SetPosition(0,-1.0,0) -coneActorTexture.GetProperty().SetColor(0.5,0.5,1) +coneActorTexture.SetPosition(0, -1.0, 0) +coneActorTexture.GetProperty().SetColor(0.5, 0.5, 1) coneActorTexture.GetProperty().SetOpacity(0.99) + ren1 = vtk.vtkRenderer() ren1.AddActor(coneActor) ren1.AddActor(coneActorLUT) ren1.AddActor(coneActorTexture) -ren1.SetBackground(0.1,0.2,0.4) +ren1.SetBackground(0.1, 0.2, 0.4) ren1.SetUseDepthPeeling(1) ren1.SetMaximumNumberOfPeels(200) ren1.SetOcclusionRatio(0.1) + renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.SetAlphaBitPlanes(1) renWin.AddRenderer(ren1) -renWin.SetSize(300,300) + +renWin.SetSize(300, 300) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) style = vtk.vtkInteractorStyleTrackballCamera() iren.SetInteractorStyle(style) iren.Initialize() + camera = ren1.GetActiveCamera() -camera.SetPosition(9,-1,3) +camera.SetPosition(9, -1, 3) camera.SetViewAngle(30) -camera.SetViewUp(0.05,0.96,0.24) -camera.SetFocalPoint(0,0.25,0) +camera.SetViewUp(0.05, 0.96, 0.24) +camera.SetFocalPoint(0, 0.25, 0) ren1.ResetCameraClippingRange() + renWin.Render() + print ren1.GetLastRenderingUsedDepthPeeling() if (ren1.GetLastRenderingUsedDepthPeeling()): print "depth peeling was used" - pass else: print "depth peeling was not used (alpha blending instead)" - pass -# --- end of script -- + +#iren.Start() diff --git a/Rendering/Core/Testing/Python/TestTransformCoordinateSystems.py b/Rendering/Core/Testing/Python/TestTransformCoordinateSystems.py index 132acde4745..893d38ae736 100755 --- a/Rendering/Core/Testing/Python/TestTransformCoordinateSystems.py +++ b/Rendering/Core/Testing/Python/TestTransformCoordinateSystems.py @@ -1,4 +1,8 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Create the RenderWindow, Renderer and both Actors # @@ -8,39 +12,47 @@ renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # pipeline stuff # sphere = vtk.vtkSphereSource() sphere.SetPhiResolution(10) sphere.SetThetaResolution(20) + xform = vtk.vtkTransformCoordinateSystems() xform.SetInputConnection(sphere.GetOutputPort()) xform.SetInputCoordinateSystemToWorld() xform.SetOutputCoordinateSystemToDisplay() xform.SetViewport(ren1) + gs = vtk.vtkGlyphSource2D() gs.SetGlyphTypeToCircle() gs.SetScale(20) gs.FilledOff() gs.CrossOn() gs.Update() + # Create a table of glyphs glypher = vtk.vtkGlyph2D() glypher.SetInputConnection(xform.GetOutputPort()) -glypher.SetSourceData(0,gs.GetOutput()) +glypher.SetSourceData(0, gs.GetOutput()) glypher.SetScaleModeToDataScalingOff() + mapper = vtk.vtkPolyDataMapper2D() mapper.SetInputConnection(glypher.GetOutputPort()) + glyphActor = vtk.vtkActor2D() glyphActor.SetMapper(mapper) + # Add the actors to the renderer, set the background and size # ren1.AddActor(glyphActor) -ren1.SetBackground(0,0,0) -renWin.SetSize(300,300) +ren1.SetBackground(0, 0, 0) + +renWin.SetSize(300, 300) + iren.Initialize() renWin.Render() + # render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Rendering/Core/Testing/Python/TestWindowToImageTransparency.py b/Rendering/Core/Testing/Python/TestWindowToImageTransparency.py index 648453e8e9e..6cb4afd2a72 100755 --- a/Rendering/Core/Testing/Python/TestWindowToImageTransparency.py +++ b/Rendering/Core/Testing/Python/TestWindowToImageTransparency.py @@ -1,4 +1,8 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Create the RenderWindow and Renderer ren1 = vtk.vtkRenderer() @@ -7,51 +11,62 @@ renWin.AddRenderer(ren1) renWin.SetAlphaBitPlanes(1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create a default polygonal sphere sphere = vtk.vtkSphereSource() sphmapper = vtk.vtkPolyDataMapper() sphmapper.SetInputConnection(sphere.GetOutputPort()) + sphactor = vtk.vtkActor() sphactor.SetMapper(sphmapper) + # Add the actors to the renderer, set the background to initial # color (which is also transparent), set size. ren1.AddActor(sphactor) -ren1.SetBackground(0.1,0.2,0.4) -renWin.SetSize(256,256) +ren1.SetBackground(0.1, 0.2, 0.4) + +renWin.SetSize(256, 256) + # render first image renWin.Render() -if (0 == renWin.GetAlphaBitPlanes()): +if 0 == renWin.GetAlphaBitPlanes(): print "Failed to find a visual with alpha bit planes." exit(0) +else: + print "GetAlphaBitPlanes: " + str(renWin.GetAlphaBitPlanes()) - print "GetAlphaBitPlanes: " + renWin.GetAlphaBitPlanes() - pass # create window to image filter, grabbing RGB and alpha w2i = vtk.vtkWindowToImageFilter() w2i.SetInput(renWin) w2i.SetInputBufferTypeToRGBA() + # grab window w2i.Update() + # copy the output outputData = w2i.GetOutput().NewInstance() outputData.DeepCopy(w2i.GetOutput()) + # set up mappers and actors to display the image im = vtk.vtkImageMapper() im.SetColorWindow(255) im.SetColorLevel(127.5) im.SetInputData(outputData) + ia2 = vtk.vtkActor2D() ia2.SetMapper(im) + # now, change the image (background is now green) -sphactor.SetScale(2,2,2) -ren1.SetBackground(0,1,0) +sphactor.SetScale(2, 2, 2) + +ren1.SetBackground(0, 1, 0) # add the image of the sphere (keeping the original sphere too) ren1.AddActor(ia2) -ren1.SetViewport(0,0,1,1) +ren1.SetViewport(0, 0, 1, 1) + # render result (the polygonal sphere appears behind a smaller image # of itself). Background of original image is transparent, so you # can see through it back to the larger sphere and new background. renWin.Render() -# prevent the tk window from showing up then start the event loop -outputData.UnRegister(None) # not needed in python -# --- end of script -- + +#iren.Start(); diff --git a/Rendering/Core/Testing/Python/TexturedSphere.py b/Rendering/Core/Testing/Python/TexturedSphere.py index 2e844bbac66..d89e76da5e3 100755 --- a/Rendering/Core/Testing/Python/TexturedSphere.py +++ b/Rendering/Core/Testing/Python/TexturedSphere.py @@ -1,52 +1,66 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # # Texture a sphere. # + # renderer and interactor ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # read the volume reader = vtk.vtkJPEGReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/beach.jpg") +reader.SetFileName(VTK_DATA_ROOT + "/Data/beach.jpg") + #--------------------------------------------------------- # Do the surface rendering sphereSource = vtk.vtkSphereSource() sphereSource.SetRadius(100) + textureSphere = vtk.vtkTextureMapToSphere() textureSphere.SetInputConnection(sphereSource.GetOutputPort()) + sphereStripper = vtk.vtkStripper() sphereStripper.SetInputConnection(textureSphere.GetOutputPort()) sphereStripper.SetMaximumLength(5) + sphereMapper = vtk.vtkPolyDataMapper() sphereMapper.SetInputConnection(sphereStripper.GetOutputPort()) sphereMapper.ScalarVisibilityOff() + sphereTexture = vtk.vtkTexture() sphereTexture.SetInputConnection(reader.GetOutputPort()) sphereProperty = vtk.vtkProperty() -#sphereProperty BackfaceCullingOn +# sphereProperty.BackfaceCullingOn() + sphere = vtk.vtkActor() sphere.SetMapper(sphereMapper) sphere.SetTexture(sphereTexture) sphere.SetProperty(sphereProperty) + #--------------------------------------------------------- ren.AddViewProp(sphere) + camera = ren.GetActiveCamera() -camera.SetFocalPoint(0,0,0) -camera.SetPosition(100,400,-100) -camera.SetViewUp(0,0,-1) +camera.SetFocalPoint(0, 0, 0) +camera.SetPosition(100, 400, -100) +camera.SetViewUp(0, 0, -1) + ren.ResetCameraClippingRange() renWin.Render() #--------------------------------------------------------- # test-related code -def TkCheckAbort (__vtk__temp0=0,__vtk__temp1=0): +def TkCheckAbort (object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) - pass iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Rendering/Core/Testing/Python/cowHair.py b/Rendering/Core/Testing/Python/cowHair.py index 7e4c9ccee64..4dc6b67b354 100755 --- a/Rendering/Core/Testing/Python/cowHair.py +++ b/Rendering/Core/Testing/Python/cowHair.py @@ -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 + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -11,34 +20,44 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # read data # wavefront = vtk.vtkOBJReader() -wavefront.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/Viewpoint/cow.obj") +wavefront.SetFileName(VTK_DATA_ROOT + "/Data/Viewpoint/cow.obj") wavefront.Update() + cone = vtk.vtkConeSource() cone.SetResolution(6) cone.SetRadius(.1) + transform = vtk.vtkTransform() -transform.Translate(0.5,0.0,0.0) +transform.Translate(0.5, 0.0, 0.0) transformF = vtk.vtkTransformPolyDataFilter() transformF.SetInputConnection(cone.GetOutputPort()) transformF.SetTransform(transform) + # we just clean the normals for efficiency (keep down number of cones) clean = vtk.vtkCleanPolyData() clean.SetInputConnection(wavefront.GetOutputPort()) + glyph = vtk.vtkHedgeHog() glyph.SetInputConnection(clean.GetOutputPort()) glyph.SetVectorModeToUseNormal() glyph.SetScaleFactor(0.4) + hairMapper = vtk.vtkPolyDataMapper() hairMapper.SetInputConnection(glyph.GetOutputPort()) + hair = vtk.vtkActor() hair.SetMapper(hairMapper) + cowMapper = vtk.vtkPolyDataMapper() cowMapper.SetInputConnection(wavefront.GetOutputPort()) + cow = vtk.vtkActor() cow.SetMapper(cowMapper) + # Add the actors to the renderer, set the background and size # ren1.AddActor(cow) @@ -48,15 +67,23 @@ ren1.GetActiveCamera().Dolly(2) ren1.GetActiveCamera().Azimuth(30) ren1.GetActiveCamera().Elevation(30) ren1.ResetCameraClippingRange() -hair.GetProperty().SetDiffuseColor(saddle_brown) -hair.GetProperty().SetAmbientColor(thistle) + +hair.GetProperty().SetDiffuseColor(GetRGBColor('saddle_brown')) +hair.GetProperty().SetAmbientColor(GetRGBColor('thistle')) hair.GetProperty().SetAmbient(.3) -cow.GetProperty().SetDiffuseColor(beige) -renWin.SetSize(320,240) -ren1.SetBackground(.1,.2,.4) + +# Beige in vtk.vtkNamedColors() is compliant with +# http://en.wikipedia.org/wiki/Web_colors and is a different color. +# so we revert to the one used in colors.tcl. +# cow.GetProperty().SetDiffuseColor(GetRGBColor('beige')) +cow.GetProperty().SetDiffuseColor(163 / 255.0, 148 / 255.0, 128 / 255.0) + +renWin.SetSize(320, 240) +ren1.SetBackground(.1, .2, .4) + iren.Initialize() renWin.Render() + # render the image # -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Rendering/Core/Testing/Python/cowHair2.py b/Rendering/Core/Testing/Python/cowHair2.py index 019fc057ddd..4f384fff806 100755 --- a/Rendering/Core/Testing/Python/cowHair2.py +++ b/Rendering/Core/Testing/Python/cowHair2.py @@ -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 + # This differs from cowHair because it checks the "MergingOff" feature # of vtkCleanPolyData....it should give the same result. # Create the RenderWindow, Renderer and both Actors @@ -13,35 +22,44 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # read data # wavefront = vtk.vtkOBJReader() -wavefront.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/Viewpoint/cow.obj") +wavefront.SetFileName(VTK_DATA_ROOT + "/Data/Viewpoint/cow.obj") wavefront.Update() + cone = vtk.vtkConeSource() cone.SetResolution(6) cone.SetRadius(.1) + transform = vtk.vtkTransform() -transform.Translate(0.5,0.0,0.0) +transform.Translate(0.5, 0.0, 0.0) transformF = vtk.vtkTransformPolyDataFilter() transformF.SetInputConnection(cone.GetOutputPort()) transformF.SetTransform(transform) + # we just clean the normals for efficiency (keep down number of cones) clean = vtk.vtkCleanPolyData() clean.SetInputConnection(wavefront.GetOutputPort()) clean.PointMergingOff() + glyph = vtk.vtkHedgeHog() glyph.SetInputConnection(clean.GetOutputPort()) glyph.SetVectorModeToUseNormal() glyph.SetScaleFactor(0.4) + hairMapper = vtk.vtkPolyDataMapper() hairMapper.SetInputConnection(glyph.GetOutputPort()) + hair = vtk.vtkActor() hair.SetMapper(hairMapper) + cowMapper = vtk.vtkPolyDataMapper() cowMapper.SetInputConnection(wavefront.GetOutputPort()) cow = vtk.vtkActor() cow.SetMapper(cowMapper) + # Add the actors to the renderer, set the background and size # ren1.AddActor(cow) @@ -51,15 +69,28 @@ ren1.GetActiveCamera().Dolly(2) ren1.GetActiveCamera().Azimuth(30) ren1.GetActiveCamera().Elevation(30) ren1.ResetCameraClippingRange() -hair.GetProperty().SetDiffuseColor(saddle_brown) -hair.GetProperty().SetAmbientColor(thistle) + +# hair.GetProperty().SetDiffuseColor(saddle_brown) +# hair.GetProperty().SetAmbientColor(thistle) +# hair.GetProperty().SetAmbient(.3) +# +# cow.GetProperty().SetDiffuseColor(beige) +hair.GetProperty().SetDiffuseColor(GetRGBColor('saddle_brown')) +hair.GetProperty().SetAmbientColor(GetRGBColor('thistle')) hair.GetProperty().SetAmbient(.3) -cow.GetProperty().SetDiffuseColor(beige) -renWin.SetSize(320,240) -ren1.SetBackground(.1,.2,.4) + +# Beige in vtk.vtkNamedColors() is compliant with +# http://en.wikipedia.org/wiki/Web_colors and is a different color. +# so we revert to the one used in colors.tcl. +# cow.GetProperty().SetDiffuseColor(GetRGBColor('beige')) +cow.GetProperty().SetDiffuseColor(163 / 255.0, 148 / 255.0, 128 / 255.0) + +renWin.SetSize(320, 240) + +ren1.SetBackground(.1, .2, .4) iren.Initialize() renWin.Render() + # render the image # -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Rendering/Core/Testing/Python/rendererSource.py b/Rendering/Core/Testing/Python/rendererSource.py index 07556af9ef3..cf2d191691a 100755 --- a/Rendering/Core/Testing/Python/rendererSource.py +++ b/Rendering/Core/Testing/Python/rendererSource.py @@ -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 + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -13,83 +22,109 @@ renWin.AddRenderer(ren1) renWin.AddRenderer(ren2) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # create pipeline for ren1 # pl3d2 = vtk.vtkMultiBlockPLOT3DReader() -pl3d2.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") -pl3d2.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") +pl3d2.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") +pl3d2.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") pl3d2.SetScalarFunctionNumber(153) pl3d2.Update() + output2 = pl3d2.GetOutput().GetBlock(0) + pl3d = vtk.vtkMultiBlockPLOT3DReader() -pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") -pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") +pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") +pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") pl3d.SetScalarFunctionNumber(120) pl3d.SetVectorFunctionNumber(202) pl3d.Update() + output = pl3d.GetOutput().GetBlock(0) + iso = vtk.vtkContourFilter() iso.SetInputData(output) -iso.SetValue(0,-100000) +iso.SetValue(0, -100000) + probe2 = vtk.vtkProbeFilter() probe2.SetInputConnection(iso.GetOutputPort()) probe2.SetSourceData(output2) + cast2 = vtk.vtkCastToConcrete() cast2.SetInputConnection(probe2.GetOutputPort()) + normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(cast2.GetOutputPort()) normals.SetFeatureAngle(45) + isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(normals.GetOutputPort()) isoMapper.ScalarVisibilityOn() isoMapper.SetScalarRange(output2.GetPointData().GetScalars().GetRange()) + isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) -isoActor.GetProperty().SetColor(bisque) +isoActor.GetProperty().SetColor(GetRGBColor('bisque')) + outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(output) + outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) + outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) + # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) ren1.AddActor(isoActor) -ren1.SetBackground(1,1,1) -ren1.SetViewport(0,0,.5,1) -renWin.SetSize(512,256) -ren1.SetBackground(0.1,0.2,0.4) +ren1.SetBackground(1, 1, 1) +ren1.SetViewport(0, 0, .5, 1) + +renWin.SetSize(512, 256) + +ren1.SetBackground(0.1, 0.2, 0.4) ren1.ResetCamera() + cam1 = ren1.GetActiveCamera() -cam1.SetClippingRange(3.95297,50) -cam1.SetFocalPoint(9.71821,0.458166,29.3999) -cam1.SetPosition(2.7439,-37.3196,38.7167) -cam1.SetViewUp(-0.16123,0.264271,0.950876) +cam1.SetClippingRange(3.95297, 50) +cam1.SetFocalPoint(9.71821, 0.458166, 29.3999) +cam1.SetPosition(2.7439, -37.3196, 38.7167) +cam1.SetViewUp(-0.16123, 0.264271, 0.950876) + aPlane = vtk.vtkPlaneSource() + aPlaneMapper = vtk.vtkPolyDataMapper() aPlaneMapper.SetInputConnection(aPlane.GetOutputPort()) aPlaneMapper.ImmediateModeRenderingOn() + screen = vtk.vtkActor() screen.SetMapper(aPlaneMapper) + ren2.AddActor(screen) -ren2.SetViewport(.5,0,1,1) +ren2.SetViewport(.5, 0, 1, 1) ren2.GetActiveCamera().Azimuth(30) ren2.GetActiveCamera().Elevation(30) -ren2.SetBackground(.8,.4,.3) +ren2.SetBackground(.8, .4, .3) ren1.ResetCameraClippingRange() ren2.ResetCamera() ren2.ResetCameraClippingRange() + renWin.Render() + ren1Image = vtk.vtkRendererSource() ren1Image.SetInput(ren1) ren1Image.DepthValuesOn() + aTexture = vtk.vtkTexture() aTexture.SetInputConnection(ren1Image.GetOutputPort()) + screen.SetTexture(aTexture) -renWin.Render() + +# renWin.Render() # render the image # renWin.Render() -# prevent the tk window from showing up then start the event loop -# --- end of script -- + +#iren.Start() diff --git a/Rendering/LOD/Testing/Python/TestQuadricLODActor.py b/Rendering/LOD/Testing/Python/TestQuadricLODActor.py index 4d5d5b4abe5..54c0bc35084 100755 --- a/Rendering/LOD/Testing/Python/TestQuadricLODActor.py +++ b/Rendering/LOD/Testing/Python/TestQuadricLODActor.py @@ -1,4 +1,17 @@ #!/usr/bin/env python +import vtk +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 # Test the quadric decimation LOD actor # @@ -7,32 +20,36 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # pipeline stuff # sphere = vtk.vtkSphereSource() sphere.SetPhiResolution(150) sphere.SetThetaResolution(150) + plane = vtk.vtkPlaneSource() plane.SetXResolution(150) plane.SetYResolution(150) + mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(sphere.GetOutputPort()) mapper.SetInputConnection(plane.GetOutputPort()) + actor = vtk.vtkQuadricLODActor() actor.SetMapper(mapper) actor.DeferLODConstructionOff() actor.GetProperty().SetRepresentationToWireframe() -actor.GetProperty().SetDiffuseColor(tomato) +actor.GetProperty().SetDiffuseColor(GetRGBColor('tomato')) actor.GetProperty().SetDiffuse(.8) actor.GetProperty().SetSpecular(.4) actor.GetProperty().SetSpecularPower(30) + # Add the actors to the renderer, set the background and size # ren1.AddActor(actor) -ren1.SetBackground(1,1,1) -renWin.SetSize(300,300) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(300, 300) + iren.Initialize() -# render the image -# -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Rendering/Label/Testing/Python/labeledContours.py b/Rendering/Label/Testing/Python/labeledContours.py index 442ccb8dc5e..6ce0e001f0a 100755 --- a/Rendering/Label/Testing/Python/labeledContours.py +++ b/Rendering/Label/Testing/Python/labeledContours.py @@ -13,54 +13,66 @@ renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Read a slice and contour it v16 = vtk.vtkVolume16Reader() -v16.SetDataDimensions(64,64) -v16.GetOutput().SetOrigin(0.0,0.0,0.0) +v16.SetDataDimensions(64, 64) +v16.GetOutput().SetOrigin(0.0, 0.0, 0.0) v16.SetDataByteOrderToLittleEndian() -v16.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter") -v16.SetImageRange(45,45) -v16.SetDataSpacing(3.2,3.2,1.5) +v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") +v16.SetImageRange(45, 45) +v16.SetDataSpacing(3.2, 3.2, 1.5) + iso = vtk.vtkContourFilter() iso.SetInputConnection(v16.GetOutputPort()) -iso.GenerateValues(6,500,1150) +iso.GenerateValues(6, 500, 1150) iso.Update() + numPts = iso.GetOutput().GetNumberOfPoints() + isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(iso.GetOutputPort()) isoMapper.ScalarVisibilityOn() isoMapper.SetScalarRange(iso.GetOutput().GetScalarRange()) isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) + # Subsample the points and label them mask = vtk.vtkMaskPoints() mask.SetInputConnection(iso.GetOutputPort()) -mask.SetOnRatio(expr.expr(globals(), locals(),["numPts","/","50"])) +mask.SetOnRatio(numPts / 50) mask.SetMaximumNumberOfPoints(50) mask.RandomModeOn() + # Create labels for points - only show visible points visPts = vtk.vtkSelectVisiblePoints() visPts.SetInputConnection(mask.GetOutputPort()) visPts.SetRenderer(ren1) + ldm = vtk.vtkLabeledDataMapper() ldm.SetInputConnection(mask.GetOutputPort()) -# ldm SetLabelFormat "%g" +# ldm.SetLabelFormat("%g") ldm.SetLabelModeToLabelScalars() + tprop = ldm.GetLabelTextProperty() tprop.SetFontFamilyToArial() tprop.SetFontSize(10) -tprop.SetColor(1,0,0) +tprop.SetColor(1, 0, 0) + contourLabels = vtk.vtkActor2D() contourLabels.SetMapper(ldm) + # Add the actors to the renderer, set the background and size # ren1.AddActor2D(isoActor) ren1.AddActor2D(contourLabels) -ren1.SetBackground(1,1,1) -renWin.SetSize(500,500) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(500, 500) + renWin.Render() ren1.GetActiveCamera().Zoom(1.5) + # render the image # -# prevent the tk window from showing up then start the event loop -# --- end of script -- +#iren.Start() diff --git a/Rendering/Label/Testing/Python/labeledMesh.py b/Rendering/Label/Testing/Python/labeledMesh.py index b3b28460f7e..37a2543d88e 100755 --- a/Rendering/Label/Testing/Python/labeledMesh.py +++ b/Rendering/Label/Testing/Python/labeledMesh.py @@ -5,7 +5,7 @@ from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() # demonstrate use of point labeling and the selection window -# get the interactor ui + # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() @@ -13,18 +13,21 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # Create a selection window xmin = 200 xLength = 100 -xmax = expr.expr(globals(), locals(),["xmin","+","xLength"]) +xmax = xmin + xLength ymin = 200 yLength = 100 -ymax = expr.expr(globals(), locals(),["ymin","+","yLength"]) +ymax = ymin + yLength + pts = vtk.vtkPoints() -pts.InsertPoint(0,xmin,ymin,0) -pts.InsertPoint(1,xmax,ymin,0) -pts.InsertPoint(2,xmax,ymax,0) -pts.InsertPoint(3,xmin,ymax,0) +pts.InsertPoint(0, xmin, ymin, 0) +pts.InsertPoint(1, xmax, ymin, 0) +pts.InsertPoint(2, xmax, ymax, 0) +pts.InsertPoint(3, xmin, ymax, 0) + rect = vtk.vtkCellArray() rect.InsertNextCell(5) rect.InsertCellPoint(0) @@ -32,95 +35,112 @@ rect.InsertCellPoint(1) rect.InsertCellPoint(2) rect.InsertCellPoint(3) rect.InsertCellPoint(0) + selectRect = vtk.vtkPolyData() selectRect.SetPoints(pts) selectRect.SetLines(rect) + rectMapper = vtk.vtkPolyDataMapper2D() rectMapper.SetInputData(selectRect) + rectActor = vtk.vtkActor2D() rectActor.SetMapper(rectMapper) + # Create asphere sphere = vtk.vtkSphereSource() + sphereMapper = vtk.vtkPolyDataMapper() sphereMapper.SetInputConnection(sphere.GetOutputPort()) sphereMapper.GlobalImmediateModeRenderingOn() + sphereActor = vtk.vtkActor() sphereActor.SetMapper(sphereMapper) + # Generate ids for labeling ids = vtk.vtkIdFilter() ids.SetInputConnection(sphere.GetOutputPort()) ids.PointIdsOn() ids.CellIdsOn() ids.FieldDataOn() + # Create labels for points visPts = vtk.vtkSelectVisiblePoints() visPts.SetInputConnection(ids.GetOutputPort()) visPts.SetRenderer(ren1) visPts.SelectionWindowOn() -visPts.SetSelection(xmin,expr.expr(globals(), locals(),["xmin","+","xLength"]),ymin,expr.expr(globals(), locals(),["ymin","+","yLength"])) +visPts.SetSelection(xmin, xmin + xLength, ymin, ymin + yLength) + ldm = vtk.vtkLabeledDataMapper() ldm.SetInputConnection(visPts.GetOutputPort()) -# ldm SetLabelFormat "%g" -# ldm SetLabelModeToLabelScalars -# ldm SetLabelModeToLabelNormals +# ldm.SetLabelFormat.("%g") +# ldm.SetLabelModeToLabelScalars() +# ldm.SetLabelModeToLabelNormals() ldm.SetLabelModeToLabelFieldData() -# ldm SetLabeledComponent 0 +# ldm.SetLabeledComponent(0) + pointLabels = vtk.vtkActor2D() pointLabels.SetMapper(ldm) + # Create labels for cells cc = vtk.vtkCellCenters() cc.SetInputConnection(ids.GetOutputPort()) + visCells = vtk.vtkSelectVisiblePoints() visCells.SetInputConnection(cc.GetOutputPort()) visCells.SetRenderer(ren1) visCells.SelectionWindowOn() -visCells.SetSelection(xmin,expr.expr(globals(), locals(),["xmin","+","xLength"]),ymin,expr.expr(globals(), locals(),["ymin","+","yLength"])) +visCells.SetSelection(xmin, xmin + xLength, ymin, ymin + yLength) + cellMapper = vtk.vtkLabeledDataMapper() cellMapper.SetInputConnection(visCells.GetOutputPort()) -# cellMapper SetLabelFormat "%g" -# cellMapper SetLabelModeToLabelScalars -# cellMapper SetLabelModeToLabelNormals +# cellMapper.SetLabelFormat("%g") +# cellMapper.SetLabelModeToLabelScalars() +# cellMapper.SetLabelModeToLabelNormals() cellMapper.SetLabelModeToLabelFieldData() -cellMapper.GetLabelTextProperty().SetColor(0,1,0) +cellMapper.GetLabelTextProperty().SetColor(0, 1, 0) + cellLabels = vtk.vtkActor2D() cellLabels.SetMapper(cellMapper) + # Add the actors to the renderer, set the background and size # ren1.AddActor(sphereActor) ren1.AddActor2D(rectActor) ren1.AddActor2D(pointLabels) ren1.AddActor2D(cellLabels) -ren1.SetBackground(1,1,1) -renWin.SetSize(500,500) +ren1.SetBackground(1, 1, 1) + +renWin.SetSize(500, 500) + renWin.Render() # render the image # -# prevent the tk window from showing up then start the event loop -def PlaceWindow (xmin,ymin,__vtk__temp0=0,__vtk__temp1=0): + +def PlaceWindow (xmin, ymin): global xLength, yLength - xmax = expr.expr(globals(), locals(),["xmin","+","xLength"]) - ymax = expr.expr(globals(), locals(),["ymin","+","yLength"]) - visPts.SetSelection(xmin,xmax,ymin,ymax) - visCells.SetSelection(xmin,xmax,ymin,ymax) - pts.InsertPoint(0,xmin,ymin,0) - pts.InsertPoint(1,xmax,ymin,0) - pts.InsertPoint(2,xmax,ymax,0) - pts.InsertPoint(3,xmin,ymax,0) + xmax = xmin + xLength + ymax = ymin + yLength + visPts.SetSelection(xmin, xmax, ymin, ymax) + visCells.SetSelection(xmin, xmax, ymin, ymax) + pts.InsertPoint(0, xmin, ymin, 0) + pts.InsertPoint(1, xmax, ymin, 0) + pts.InsertPoint(2, xmax, ymax, 0) + pts.InsertPoint(3, xmin, ymax, 0) pts.Modified() - #because insertions don't modify object - performance reasons + # because insertions don't modify object - performance reasons renWin.Render() -def MoveWindow (__vtk__temp0=0,__vtk__temp1=0): +def MoveWindow (): y = 100 while y < 300: x = 100 while x < 300: - PlaceWindow(x,y) - x = x + 25 - - y = y + 25 + PlaceWindow(x, y) + x += 25 + y += 25 MoveWindow() -PlaceWindow(xmin,ymin) -# --- end of script -- +PlaceWindow(xmin, ymin) + +#iren.Start() diff --git a/Rendering/Volume/Testing/Python/VolumeOutlineSource.py b/Rendering/Volume/Testing/Python/VolumeOutlineSource.py index 8a216ea567f..d761d1c7d07 100755 --- a/Rendering/Volume/Testing/Python/VolumeOutlineSource.py +++ b/Rendering/Volume/Testing/Python/VolumeOutlineSource.py @@ -1,68 +1,91 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Simple volume rendering example. reader = vtk.vtkSLCReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/sphere.slc") +reader.SetFileName(VTK_DATA_ROOT + "/Data/sphere.slc") + # Create transfer functions for opacity and color opacityTransferFunction = vtk.vtkPiecewiseFunction() -opacityTransferFunction.AddPoint(0,0.0) -opacityTransferFunction.AddPoint(30,0.0) -opacityTransferFunction.AddPoint(80,0.5) -opacityTransferFunction.AddPoint(255,0.5) +opacityTransferFunction.AddPoint(0, 0.0) +opacityTransferFunction.AddPoint(30, 0.0) +opacityTransferFunction.AddPoint(80, 0.5) +opacityTransferFunction.AddPoint(255, 0.5) + colorTransferFunction = vtk.vtkColorTransferFunction() -colorTransferFunction.AddRGBPoint(0.0,0.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(64.0,1.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(128.0,0.0,0.0,1.0) -colorTransferFunction.AddRGBPoint(192.0,0.0,1.0,0.0) -colorTransferFunction.AddRGBPoint(255.0,0.0,0.2,0.0) +colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0) +colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0) +colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0) + # Create properties, mappers, volume actors, and ray cast function volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) volumeProperty.SetInterpolationTypeToLinear() volumeProperty.ShadeOn() + ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) -renWin.SetSize(600,300) + +renWin.SetSize(600, 300) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + renWin.SetMultiSamples(0) -ren1.SetBackground(0.1,0.2,0.4) +ren1.SetBackground(0.1, 0.2, 0.4) + i = 0 while i < 2: j = 0 while j < 4: - locals()[get_variable_name("volumeMapper_", i, "_", j, "")] = vtk.vtkVolumeTextureMapper2D() - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetInputConnection(reader.GetOutputPort()) - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].CroppingOn() - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetCroppingRegionPlanes(17.5,32.5,17.5,32.5,17.5,32.5) - locals()[get_variable_name("volume_", i, "_", j, "")] = vtk.vtkVolume() - locals()[get_variable_name("volume_", i, "_", j, "")].SetMapper(locals()[get_variable_name("volumeMapper_", i, "_", j, "")]) - locals()[get_variable_name("volume_", i, "_", j, "")].SetProperty(volumeProperty) - locals()[get_variable_name("outline_", i, "_", j, "")] = vtk.vtkVolumeOutlineSource() - locals()[get_variable_name("outline_", i, "_", j, "")].SetVolumeMapper(locals()[get_variable_name("volumeMapper_", i, "_", j, "")]) - locals()[get_variable_name("outlineMapper_", i, "_", j, "")] = vtk.vtkDataSetMapper() - locals()[get_variable_name("outlineMapper_", i, "_", j, "")].SetInputConnection(locals()[get_variable_name("outline_", i, "_", j, "")].GetOutputPort()) - locals()[get_variable_name("outlineActor_", i, "_", j, "")] = vtk.vtkActor() - locals()[get_variable_name("outlineActor_", i, "_", j, "")].SetMapper(locals()[get_variable_name("outlineMapper_", i, "_", j, "")]) - locals()[get_variable_name("userMatrix_", i, "_", j, "")] = vtk.vtkTransform() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].PostMultiply() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Identity() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Translate(-25,-25,-25) + idx = str(i) + "_" + str(j) + + exec("volumeMapper_" + idx + " = vtk.vtkVolumeTextureMapper2D()") + eval("volumeMapper_" + idx).SetInputConnection(reader.GetOutputPort()) + eval("volumeMapper_" + idx).CroppingOn() + eval("volumeMapper_" + idx).SetCroppingRegionPlanes( + 17.5, 32.5, 17.5, 32.5, 17.5, 32.5) + + exec("volume_" + idx + " = vtk.vtkVolume()") + eval("volume_" + idx).SetMapper(eval("volumeMapper_" + idx)) + eval("volume_" + idx).SetProperty(volumeProperty) + + exec("outline_" + idx + " = vtk.vtkVolumeOutlineSource()") + eval("outline_" + idx).SetVolumeMapper(eval("volumeMapper_" + idx)) + + exec("outlineMapper_" + idx + " = vtk.vtkDataSetMapper()") + eval("outlineMapper_" + idx).SetInputConnection( + eval("outline_" + idx).GetOutputPort()) + + exec("outlineActor_" + idx + " = vtk.vtkActor()") + eval("outlineActor_" + idx).SetMapper(eval("outlineMapper_" + idx)) + + exec("userMatrix_" + idx + " = vtk.vtkTransform()") + eval("userMatrix_" + idx).PostMultiply() + eval("userMatrix_" + idx).Identity() + eval("userMatrix_" + idx).Translate(-25, -25, -25) if (i == 0): - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateX(expr.expr(globals(), locals(),["j","*","87","+","23"])) - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateY(16) - pass + eval("userMatrix_" + idx).RotateX(j * 87 + 23) + eval("userMatrix_" + idx).RotateY(16) else: - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateX(27) - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateY(expr.expr(globals(), locals(),["j","*","87","+","19"])) - pass - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Translate(expr.expr(globals(), locals(),["j","*","65","+","25"]),expr.expr(globals(), locals(),["i","*","55","+","25"]),0) - locals()[get_variable_name("volume_", i, "_", j, "")].SetUserTransform(locals()[get_variable_name("userMatrix_", i, "_", j, "")]) - locals()[get_variable_name("outlineActor_", i, "_", j, "")].SetUserTransform(locals()[get_variable_name("userMatrix_", i, "_", j, "")]) - ren1.AddViewProp(locals()[get_variable_name("outlineActor_", i, "_", j, "")]) - ren1.AddViewProp(locals()[get_variable_name("volume_", i, "_", j, "")]) + eval("userMatrix_" + idx).RotateX(27) + eval("userMatrix_" + idx).RotateY(j * 87 + 19) + eval("userMatrix_" + idx).Translate(j * 65 + 25, i * 55 + 25, 0) + + eval("volume_" + idx).SetUserTransform(eval("userMatrix_" + idx)) + + eval("outlineActor_" + idx).SetUserTransform(eval("userMatrix_" + idx)) + + ren1.AddViewProp(eval("outlineActor_" + idx)) + ren1.AddViewProp(eval("volume_" + idx)) + j = j + 1 i = i + 1 @@ -75,35 +98,48 @@ volumeMapper_1_0.SetCroppingRegionFlagsToFence() volumeMapper_1_1.SetCroppingRegionFlagsToInvertedFence() volumeMapper_1_2.SetCroppingRegionFlags(1) volumeMapper_1_3.SetCroppingRegionFlags(67117057) + outline_0_1.GenerateScalarsOn() + outline_0_2.GenerateScalarsOn() outline_0_2.SetActivePlaneId(1) -outline_0_2.SetColor(1,0,1) +outline_0_2.SetColor(1, 0, 1) + outline_0_3.GenerateScalarsOn() outline_0_3.SetActivePlaneId(2) -outline_0_3.SetActivePlaneColor(0,1,1) -outlineActor_1_0.GetProperty().SetColor(0,1,0) +outline_0_3.SetActivePlaneColor(0, 1, 1) + +outlineActor_1_0.GetProperty().SetColor(0, 1, 0) + outline_1_1.GenerateFacesOn() volume_1_1.VisibilityOff() + outline_1_2.GenerateFacesOn() outline_1_2.GenerateScalarsOn() + volume_1_2.VisibilityOff() + outline_1_3.GenerateFacesOn() outline_1_3.GenerateScalarsOn() outline_1_3.SetActivePlaneId(1) + volume_1_3.VisibilityOff() + ren1.GetCullers().InitTraversal() + culler = ren1.GetCullers().GetNextItem() culler.SetSortingStyleToBackToFront() + ren1.ResetCamera() ren1.GetActiveCamera().Zoom(2.35) renWin.Render() -def TkCheckAbort (__vtk__temp0=0,__vtk__temp1=0): + +def TkCheckAbort (object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) - pass -renWin.AddObserver("AbortCheckEvent",TkCheckAbort) +renWin.AddObserver("AbortCheckEvent", TkCheckAbort) + iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Rendering/Volume/Testing/Python/VolumeOutlineSourceClipped.py b/Rendering/Volume/Testing/Python/VolumeOutlineSourceClipped.py index c3d078d3859..de28fcf1a62 100755 --- a/Rendering/Volume/Testing/Python/VolumeOutlineSourceClipped.py +++ b/Rendering/Volume/Testing/Python/VolumeOutlineSourceClipped.py @@ -1,58 +1,76 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Simple volume rendering example. reader = vtk.vtkSLCReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/sphere.slc") +reader.SetFileName(VTK_DATA_ROOT + "/Data/sphere.slc") + # Create transfer functions for opacity and color opacityTransferFunction = vtk.vtkPiecewiseFunction() -opacityTransferFunction.AddPoint(0,0.0) -opacityTransferFunction.AddPoint(30,0.0) -opacityTransferFunction.AddPoint(80,0.5) -opacityTransferFunction.AddPoint(255,0.5) +opacityTransferFunction.AddPoint(0, 0.0) +opacityTransferFunction.AddPoint(30, 0.0) +opacityTransferFunction.AddPoint(80, 0.5) +opacityTransferFunction.AddPoint(255, 0.5) + colorTransferFunction = vtk.vtkColorTransferFunction() -colorTransferFunction.AddRGBPoint(0.0,0.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(64.0,1.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(128.0,0.0,0.0,1.0) -colorTransferFunction.AddRGBPoint(192.0,0.0,1.0,0.0) -colorTransferFunction.AddRGBPoint(255.0,0.0,0.2,0.0) +colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0) +colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0) +colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0) + # Create properties, mappers, volume actors, and ray cast function volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) volumeProperty.SetInterpolationTypeToLinear() volumeProperty.ShadeOn() + ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) -renWin.SetSize(300,300) + +renWin.SetSize(300, 300) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) renWin.SetMultiSamples(0) -ren1.SetBackground(0.1,0.2,0.4) +ren1.SetBackground(0.1, 0.2, 0.4) + # Translate the volume to center it at (0,0,0) userTrans = vtk.vtkTransform() userTrans.PostMultiply() userTrans.Identity() -userTrans.Translate(-24.5,-24.5,-24.5) +userTrans.Translate(-24.5, -24.5, -24.5) + # Clipping planes are in world coords plane1 = vtk.vtkPlane() -plane1.SetOrigin(-24,0,0) -plane1.SetNormal(1,0,0) +plane1.SetOrigin(-24, 0, 0) +plane1.SetNormal(1, 0, 0) + plane2 = vtk.vtkPlane() -plane2.SetOrigin(24,0,0) -plane2.SetNormal(-1,0,0) +plane2.SetOrigin(24, 0, 0) +plane2.SetNormal(-1, 0, 0) + plane3 = vtk.vtkPlane() -plane3.SetOrigin(0,-15,0) -plane3.SetNormal(0.163176,0.925417,-0.342020) +plane3.SetOrigin(0, -15, 0) +plane3.SetNormal(0.163176, 0.925417, -0.342020) + plane4 = vtk.vtkPlane() -plane4.SetOrigin(0,24,0) -plane4.SetNormal(0,-1,0) +plane4.SetOrigin(0, 24, 0) +plane4.SetNormal(0, -1, 0) + plane5 = vtk.vtkPlane() -plane5.SetOrigin(0,0,-24) -plane5.SetNormal(0,0,1) +plane5.SetOrigin(0, 0, -24) +plane5.SetNormal(0, 0, 1) + plane6 = vtk.vtkPlane() -plane6.SetOrigin(0,0,24) -plane6.SetNormal(0,0,-1) +plane6.SetOrigin(0, 0, 24) +plane6.SetNormal(0, 0, -1) + clippingPlanes = vtk.vtkPlaneCollection() clippingPlanes.AddItem(plane1) clippingPlanes.AddItem(plane2) @@ -60,46 +78,62 @@ clippingPlanes.AddItem(plane3) clippingPlanes.AddItem(plane4) clippingPlanes.AddItem(plane5) clippingPlanes.AddItem(plane6) + # Cropping planes are in data coords volumeMapper1 = vtk.vtkVolumeTextureMapper2D() volumeMapper1.SetInputConnection(reader.GetOutputPort()) volumeMapper1.CroppingOn() -volumeMapper1.SetCroppingRegionPlanes(16,33,16,33,16,33) +volumeMapper1.SetCroppingRegionPlanes(16, 33, 16, 33, 16, 33) volumeMapper1.SetClippingPlanes(clippingPlanes) + volume1 = vtk.vtkVolume() volume1.SetMapper(volumeMapper1) volume1.SetProperty(volumeProperty) + outline1 = vtk.vtkVolumeOutlineSource() outline1.SetVolumeMapper(volumeMapper1) outline1.GenerateFacesOn() outline1.GenerateScalarsOn() + preTrans1 = vtk.vtkTransformPolyDataFilter() preTrans1.SetInputConnection(outline1.GetOutputPort()) preTrans1.SetTransform(userTrans) + outlineClip1 = vtk.vtkClipClosedSurface() outlineClip1.SetInputConnection(preTrans1.GetOutputPort()) outlineClip1.SetClippingPlanes(clippingPlanes) outlineClip1.GenerateFacesOff() outlineClip1.GenerateOutlineOn() outlineClip1.SetScalarModeToColors() -outlineClip1.SetClipColor(1,1,0) +outlineClip1.SetClipColor(1, 1, 0) outlineClip1.SetActivePlaneId(2) -outlineClip1.SetActivePlaneColor(0,1,0) +outlineClip1.SetActivePlaneColor(0, 1, 0) + postTrans1 = vtk.vtkTransformPolyDataFilter() postTrans1.SetInputConnection(outlineClip1.GetOutputPort()) postTrans1.SetTransform(userTrans.GetInverse()) + outlineMapper1 = vtk.vtkDataSetMapper() outlineMapper1.SetInputConnection(postTrans1.GetOutputPort()) + outlineActor1 = vtk.vtkActor() outlineActor1.SetMapper(outlineMapper1) + volume1.SetUserTransform(userTrans) + outlineActor1.SetUserTransform(userTrans) + ren1.AddViewProp(outlineActor1) ren1.AddViewProp(volume1) + volumeMapper1.SetCroppingRegionFlagsToFence() + outline1.GenerateScalarsOn() + ren1.ResetCamera() ren1.GetActiveCamera().Zoom(1.35) + renWin.Render() + iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Rendering/Volume/Testing/Python/VolumePickerCrop.py b/Rendering/Volume/Testing/Python/VolumePickerCrop.py index 9e806396792..1fbef8111db 100755 --- a/Rendering/Volume/Testing/Python/VolumePickerCrop.py +++ b/Rendering/Volume/Testing/Python/VolumePickerCrop.py @@ -1,4 +1,8 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # volume render a medical data set # renderer and interactor @@ -7,35 +11,42 @@ renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + # read the volume v16 = vtk.vtkVolume16Reader() -v16.SetDataDimensions(64,64) -v16.SetImageRange(1,93) +v16.SetDataDimensions(64, 64) +v16.SetImageRange(1, 93) v16.SetDataByteOrderToLittleEndian() -v16.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter") -v16.SetDataSpacing(3.2,3.2,1.5) +v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") +v16.SetDataSpacing(3.2, 3.2, 1.5) + #--------------------------------------------------------- # set up the volume rendering rayCastFunction = vtk.vtkVolumeRayCastCompositeFunction() + volumeMapper = vtk.vtkVolumeRayCastMapper() volumeMapper.SetInputConnection(v16.GetOutputPort()) volumeMapper.SetVolumeRayCastFunction(rayCastFunction) volumeMapper.CroppingOn() -volumeMapper.SetCroppingRegionPlanes(0.0,141.6,0.0,201.6,0.0,138.0) +volumeMapper.SetCroppingRegionPlanes(0.0, 141.6, 0.0, 201.6, 0.0, 138.0) + volumeColor = vtk.vtkColorTransferFunction() -volumeColor.AddRGBPoint(0,0.0,0.0,0.0) -volumeColor.AddRGBPoint(180,0.3,0.1,0.2) -volumeColor.AddRGBPoint(1000,1.0,0.7,0.6) -volumeColor.AddRGBPoint(2000,1.0,1.0,0.9) +volumeColor.AddRGBPoint(0, 0.0, 0.0, 0.0) +volumeColor.AddRGBPoint(180, 0.3, 0.1, 0.2) +volumeColor.AddRGBPoint(1000, 1.0, 0.7, 0.6) +volumeColor.AddRGBPoint(2000, 1.0, 1.0, 0.9) + volumeScalarOpacity = vtk.vtkPiecewiseFunction() -volumeScalarOpacity.AddPoint(0,0.0) -volumeScalarOpacity.AddPoint(180,0.0) -volumeScalarOpacity.AddPoint(1000,0.2) -volumeScalarOpacity.AddPoint(2000,0.8) +volumeScalarOpacity.AddPoint(0, 0.0) +volumeScalarOpacity.AddPoint(180, 0.0) +volumeScalarOpacity.AddPoint(1000, 0.2) +volumeScalarOpacity.AddPoint(2000, 0.8) + volumeGradientOpacity = vtk.vtkPiecewiseFunction() -volumeGradientOpacity.AddPoint(0,0.0) -volumeGradientOpacity.AddPoint(90,0.5) -volumeGradientOpacity.AddPoint(100,1.0) +volumeGradientOpacity.AddPoint(0, 0.0) +volumeGradientOpacity.AddPoint(90, 0.5) +volumeGradientOpacity.AddPoint(100, 1.0) + volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(volumeColor) volumeProperty.SetScalarOpacity(volumeScalarOpacity) @@ -45,26 +56,35 @@ volumeProperty.ShadeOn() volumeProperty.SetAmbient(0.6) volumeProperty.SetDiffuse(0.6) volumeProperty.SetSpecular(0.1) + volume = vtk.vtkVolume() volume.SetMapper(volumeMapper) volume.SetProperty(volumeProperty) + #--------------------------------------------------------- # make a transform and some clipping planes transform = vtk.vtkTransform() -transform.RotateWXYZ(-20,0.0,-0.7,0.7) +transform.RotateWXYZ(-20, 0.0, -0.7, 0.7) + volume.SetUserTransform(transform) + c = volume.GetCenter() + volumeClip = vtk.vtkPlane() -volumeClip.SetNormal(0,1,0) -volumeClip.SetOrigin(c[0],c[1],c[2]) +volumeClip.SetNormal(0, 1, 0) +volumeClip.SetOrigin(c[0], c[1], c[2]) volumeMapper.AddClippingPlane(volumeClip) + #--------------------------------------------------------- ren.AddViewProp(volume) + camera = ren.GetActiveCamera() -camera.SetFocalPoint(c[0],c[1],c[2]) -camera.SetPosition(c[0]+500,c[1]-100,c[2]-100) -camera.SetViewUp(0,0,-1) +camera.SetFocalPoint(c[0], c[1], c[2]) +camera.SetPosition(c[0] + 500, c[1] - 100, c[2] - 100) +camera.SetViewUp(0, 0, -1) + ren.ResetCameraClippingRange() + renWin.Render() #--------------------------------------------------------- # The cone source points along the x axis @@ -73,120 +93,174 @@ coneSource.CappingOn() coneSource.SetHeight(12) coneSource.SetRadius(5) coneSource.SetResolution(31) -coneSource.SetCenter(6,0,0) -coneSource.SetDirection(-1,0,0) +coneSource.SetCenter(6, 0, 0) +coneSource.SetDirection(-1, 0, 0) + #--------------------------------------------------------- picker = vtk.vtkVolumePicker() picker.SetTolerance(1e-6) picker.SetVolumeOpacityIsovalue(0.3) + # A function to point an actor along a vector -def PointCone(actor,nx,ny,nz): - if nx<0.0: - actor.RotateWXYZ(180,0,1,0) - actor.RotateWXYZ(180,(nx-1.0)*0.5,ny*0.5,nz*0.5) +def PointCone(actor, nx, ny, nz): + if nx < 0.0: + actor.RotateWXYZ(180, 0, 1, 0) + actor.RotateWXYZ(180, (nx - 1.0) * 0.5, ny * 0.5, nz * 0.5) else: - actor.RotateWXYZ(180,(nx+1.0)*0.5,ny*0.5,nz*0.5) + actor.RotateWXYZ(180, (nx + 1.0) * 0.5, ny * 0.5, nz * 0.5) # Pick part of the volume that is clipped away -picker.Pick(192,103,0,ren) -#puts [picker Print] +picker.Pick(192, 103, 0, ren) + +# puts [picker Print] + p = picker.GetPickPosition() + n = picker.GetPickNormal() + coneActor1 = vtk.vtkActor() coneActor1.PickableOff() + coneMapper1 = vtk.vtkDataSetMapper() coneMapper1.SetInputConnection(coneSource.GetOutputPort()) + coneActor1.SetMapper(coneMapper1) -coneActor1.GetProperty().SetColor(1,0,0) +coneActor1.GetProperty().SetColor(1, 0, 0) coneActor1.GetProperty().BackfaceCullingOn() -coneActor1.SetPosition(p[0],p[1],p[2]) -PointCone(coneActor1,n[0],n[1],n[2]) +coneActor1.SetPosition(p[0], p[1], p[2]) + +PointCone(coneActor1, n[0], n[1], n[2]) + ren.AddViewProp(coneActor1) + # Pick through a cropping plane to some bone # This should usually be left alone, but is used here to increase coverage picker.UseVolumeGradientOpacityOn() -picker.Pick(90,180,0,ren) +picker.Pick(90, 180, 0, ren) + p = picker.GetPickPosition() + n = picker.GetPickNormal() + coneActor2 = vtk.vtkActor() coneActor2.PickableOff() + coneMapper2 = vtk.vtkDataSetMapper() coneMapper2.SetInputConnection(coneSource.GetOutputPort()) + coneActor2.SetMapper(coneMapper2) -coneActor2.GetProperty().SetColor(1,0,0) +coneActor2.GetProperty().SetColor(1, 0, 0) coneActor2.GetProperty().BackfaceCullingOn() -coneActor2.SetPosition(p[0],p[1],p[2]) -PointCone(coneActor2,n[0],n[1],n[2]) +coneActor2.SetPosition(p[0], p[1], p[2]) + +PointCone(coneActor2, n[0], n[1], n[2]) + ren.AddViewProp(coneActor2) + # Pick through a cropping plane to some transparent tissue # Ignore gradient opacity, since it makes it harder to find isosurface + picker.UseVolumeGradientOpacityOff() -picker.Pick(125,195,0,ren) +picker.Pick(125, 195, 0, ren) + p = picker.GetPickPosition() + n = picker.GetPickNormal() + coneActor3 = vtk.vtkActor() coneActor3.PickableOff() + coneMapper3 = vtk.vtkDataSetMapper() coneMapper3.SetInputConnection(coneSource.GetOutputPort()) + coneActor3.SetMapper(coneMapper3) -coneActor3.GetProperty().SetColor(1,0,0) +coneActor3.GetProperty().SetColor(1, 0, 0) coneActor3.GetProperty().BackfaceCullingOn() -coneActor3.SetPosition(p[0],p[1],p[2]) -PointCone(coneActor3,n[0],n[1],n[2]) +coneActor3.SetPosition(p[0], p[1], p[2]) + +PointCone(coneActor3, n[0], n[1], n[2]) + ren.AddViewProp(coneActor3) + # Pick through a clipping plane -picker.Pick(150,160,0,ren) +picker.Pick(150, 160, 0, ren) + p = picker.GetPickPosition() + n = picker.GetPickNormal() + coneActor4 = vtk.vtkActor() coneActor4.PickableOff() + coneMapper4 = vtk.vtkDataSetMapper() coneMapper4.SetInputConnection(coneSource.GetOutputPort()) + coneActor4.SetMapper(coneMapper4) -coneActor4.GetProperty().SetColor(1,0,0) +coneActor4.GetProperty().SetColor(1, 0, 0) coneActor4.GetProperty().BackfaceCullingOn() -coneActor4.SetPosition(p[0],p[1],p[2]) -PointCone(coneActor4,n[0],n[1],n[2]) +coneActor4.SetPosition(p[0], p[1], p[2]) + +PointCone(coneActor4, n[0], n[1], n[2]) + ren.AddViewProp(coneActor4) + # Pick through a cropping plane with PickCroppingPlanesOn picker.PickCroppingPlanesOn() -picker.Pick(125,195,0,ren) +picker.Pick(125, 195, 0, ren) + p = picker.GetPickPosition() + n = picker.GetPickNormal() + coneActor5 = vtk.vtkActor() coneActor5.PickableOff() + coneMapper5 = vtk.vtkDataSetMapper() coneMapper5.SetInputConnection(coneSource.GetOutputPort()) + coneActor5.SetMapper(coneMapper5) -coneActor5.GetProperty().SetColor(0,1,0) +coneActor5.GetProperty().SetColor(0, 1, 0) coneActor5.GetProperty().BackfaceCullingOn() -coneActor5.SetPosition(p[0],p[1],p[2]) -PointCone(coneActor5,n[0],n[1],n[2]) +coneActor5.SetPosition(p[0], p[1], p[2]) + +PointCone(coneActor5, n[0], n[1], n[2]) + ren.AddViewProp(coneActor5) + # Pick through a clipping plane with PickCroppingPlanesOn picker.PickCroppingPlanesOn() -picker.Pick(150,160,0,ren) + +picker.Pick(150, 160, 0, ren) + p = picker.GetPickPosition() + n = picker.GetPickNormal() + coneActor6 = vtk.vtkActor() coneActor6.PickableOff() + coneMapper6 = vtk.vtkDataSetMapper() coneMapper6.SetInputConnection(coneSource.GetOutputPort()) + coneActor6.SetMapper(coneMapper6) -coneActor6.GetProperty().SetColor(0,1,0) +coneActor6.GetProperty().SetColor(0, 1, 0) coneActor6.GetProperty().BackfaceCullingOn() -coneActor6.SetPosition(p[0],p[1],p[2]) -PointCone(coneActor6,n[0],n[1],n[2]) +coneActor6.SetPosition(p[0], p[1], p[2]) + +PointCone(coneActor6, n[0], n[1], n[2]) + ren.AddViewProp(coneActor6) ren.ResetCameraClippingRange() renWin.Render() + #--------------------------------------------------------- # test-related code -def TkCheckAbort(): +def TkCheckAbort(object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) -renWin.AddObserver('AbortCheckEvent',TkCheckAbort) +renWin.AddObserver("AbortCheckEvent", TkCheckAbort) + iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Rendering/Volume/Testing/Python/gaussian.py b/Rendering/Volume/Testing/Python/gaussian.py index 451b4010b67..b6cd9e88d6c 100755 --- a/Rendering/Volume/Testing/Python/gaussian.py +++ b/Rendering/Volume/Testing/Python/gaussian.py @@ -8,80 +8,101 @@ ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.AddRenderer(ren1) -renWin.SetSize(300,300) + +renWin.SetSize(300, 300) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + camera = vtk.vtkCamera() camera.ParallelProjectionOn() -camera.SetViewUp(0,1,0) -camera.SetFocalPoint(12,10.5,15) -camera.SetPosition(-70,15,34) +camera.SetViewUp(0, 1, 0) +camera.SetFocalPoint(12, 10.5, 15) +camera.SetPosition(-70, 15, 34) camera.ComputeViewPlaneNormal() ren1.SetActiveCamera(camera) # Create the reader for the data -#vtkStructuredPointsReader reader +# vtkStructuredPointsReader reader reader = vtk.vtkGaussianCubeReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/m4_TotalDensity.cube") +reader.SetFileName(VTK_DATA_ROOT + "/Data/m4_TotalDensity.cube") reader.SetHBScale(1.1) reader.SetBScale(10) reader.Update() + range = reader.GetGridOutput().GetPointData().GetScalars().GetRange() -min = lindex(range,0) -max = lindex(range,1) + +min = range[0] +max = range[1] + readerSS = vtk.vtkImageShiftScale() readerSS.SetInputData(reader.GetGridOutput()) -readerSS.SetShift(expr.expr(globals(), locals(),["min","*","-1"])) -readerSS.SetScale(expr.expr(globals(), locals(),["255","/","(","max","-","min",")"])) +readerSS.SetShift(min * -1) +readerSS.SetScale(255 / (max - min)) readerSS.SetOutputScalarTypeToUnsignedChar() + bounds = vtk.vtkOutlineFilter() bounds.SetInputData(reader.GetGridOutput()) + boundsMapper = vtk.vtkPolyDataMapper() boundsMapper.SetInputConnection(bounds.GetOutputPort()) + boundsActor = vtk.vtkActor() boundsActor.SetMapper(boundsMapper) -boundsActor.GetProperty().SetColor(0,0,0) +boundsActor.GetProperty().SetColor(0, 0, 0) + contour = vtk.vtkContourFilter() contour.SetInputData(reader.GetGridOutput()) -contour.GenerateValues(5,0,.05) +contour.GenerateValues(5, 0, .05) + contourMapper = vtk.vtkPolyDataMapper() contourMapper.SetInputConnection(contour.GetOutputPort()) -contourMapper.SetScalarRange(0,.1) -contourMapper.GetLookupTable().SetHueRange(0.32,0) +contourMapper.SetScalarRange(0, .1) +contourMapper.GetLookupTable().SetHueRange(0.32, 0) + contourActor = vtk.vtkActor() contourActor.SetMapper(contourMapper) contourActor.GetProperty().SetOpacity(.5) + # Create transfer mapping scalar value to opacity opacityTransferFunction = vtk.vtkPiecewiseFunction() -opacityTransferFunction.AddPoint(0,0.01) -opacityTransferFunction.AddPoint(255,0.35) +opacityTransferFunction.AddPoint(0, 0.01) +opacityTransferFunction.AddPoint(255, 0.35) opacityTransferFunction.ClampingOn() + # Create transfer mapping scalar value to color colorTransferFunction = vtk.vtkColorTransferFunction() -colorTransferFunction.AddHSVPoint(0.0,0.66,1.0,1.0) -colorTransferFunction.AddHSVPoint(50.0,0.33,1.0,1.0) -colorTransferFunction.AddHSVPoint(100.0,0.00,1.0,1.0) +colorTransferFunction.AddHSVPoint(0.0, 0.66, 1.0, 1.0) +colorTransferFunction.AddHSVPoint(50.0, 0.33, 1.0, 1.0) +colorTransferFunction.AddHSVPoint(100.0, 0.00, 1.0, 1.0) + # The property describes how the data will look volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) volumeProperty.SetInterpolationTypeToLinear() + # The mapper / ray cast function know how to render the data compositeFunction = vtk.vtkVolumeRayCastCompositeFunction() + volumeMapper = vtk.vtkVolumeRayCastMapper() -#vtkVolumeTextureMapper2D volumeMapper +# vtkVolumeTextureMapper2D = vtk.volumeMapper() volumeMapper.SetVolumeRayCastFunction(compositeFunction) volumeMapper.SetInputConnection(readerSS.GetOutputPort()) + # The volume holds the mapper and the property and # can be used to position/orient the volume volume = vtk.vtkVolume() volume.SetMapper(volumeMapper) volume.SetProperty(volumeProperty) + ren1.AddVolume(volume) -#ren1 AddActor contourActor + +# ren1 AddActor contourActor ren1.AddActor(boundsActor) + ###################################################################### Sphere = vtk.vtkSphereSource() -Sphere.SetCenter(0,0,0) +Sphere.SetCenter(0, 0, 0) Sphere.SetRadius(1) Sphere.SetThetaResolution(16) Sphere.SetStartTheta(0) @@ -89,20 +110,23 @@ Sphere.SetEndTheta(360) Sphere.SetPhiResolution(16) Sphere.SetStartPhi(0) Sphere.SetEndPhi(180) + Glyph = vtk.vtkGlyph3D() Glyph.SetInputConnection(reader.GetOutputPort()) Glyph.SetOrient(1) Glyph.SetColorMode(1) -#Glyph ScalingOn +# Glyph.ScalingOn() Glyph.SetScaleMode(2) Glyph.SetScaleFactor(.6) Glyph.SetSourceConnection(Sphere.GetOutputPort()) + AtomsMapper = vtk.vtkPolyDataMapper() AtomsMapper.SetInputConnection(Glyph.GetOutputPort()) AtomsMapper.SetImmediateModeRendering(1) AtomsMapper.UseLookupTableScalarRangeOff() AtomsMapper.SetScalarVisibility(1) AtomsMapper.SetScalarModeToDefault() + Atoms = vtk.vtkActor() Atoms.SetMapper(AtomsMapper) Atoms.GetProperty().SetRepresentationToSurface() @@ -111,8 +135,9 @@ Atoms.GetProperty().SetAmbient(0.15) Atoms.GetProperty().SetDiffuse(0.85) Atoms.GetProperty().SetSpecular(0.1) Atoms.GetProperty().SetSpecularPower(100) -Atoms.GetProperty().SetSpecularColor(1,1,1) -Atoms.GetProperty().SetColor(1,1,1) +Atoms.GetProperty().SetSpecularColor(1, 1, 1) +Atoms.GetProperty().SetColor(1, 1, 1) + Tube = vtk.vtkTubeFilter() Tube.SetInputConnection(reader.GetOutputPort()) Tube.SetNumberOfSides(16) @@ -120,12 +145,14 @@ Tube.SetCapping(0) Tube.SetRadius(0.2) Tube.SetVaryRadius(0) Tube.SetRadiusFactor(10) + BondsMapper = vtk.vtkPolyDataMapper() BondsMapper.SetInputConnection(Tube.GetOutputPort()) BondsMapper.SetImmediateModeRendering(1) BondsMapper.UseLookupTableScalarRangeOff() BondsMapper.SetScalarVisibility(1) BondsMapper.SetScalarModeToDefault() + Bonds = vtk.vtkActor() Bonds.SetMapper(BondsMapper) Bonds.GetProperty().SetRepresentationToSurface() @@ -134,20 +161,23 @@ Bonds.GetProperty().SetAmbient(0.15) Bonds.GetProperty().SetDiffuse(0.85) Bonds.GetProperty().SetSpecular(0.1) Bonds.GetProperty().SetSpecularPower(100) -Bonds.GetProperty().SetSpecularColor(1,1,1) -Bonds.GetProperty().SetColor(1,1,1) +Bonds.GetProperty().SetSpecularColor(1, 1, 1) +Bonds.GetProperty().SetColor(1, 1, 1 + ) ren1.AddActor(Bonds) ren1.AddActor(Atoms) #################################################### -ren1.SetBackground(1,1,1) +ren1.SetBackground(1, 1, 1) ren1.ResetCamera() + renWin.Render() -def TkCheckAbort (__vtk__temp0=0,__vtk__temp1=0): + +def TkCheckAbort (object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) - pass -renWin.AddObserver("AbortCheckEvent",TkCheckAbort) +renWin.AddObserver("AbortCheckEvent", TkCheckAbort) + iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Rendering/Volume/Testing/Python/volRCCropRegions.py b/Rendering/Volume/Testing/Python/volRCCropRegions.py index 1a2877db01c..2d30d0f1faa 100755 --- a/Rendering/Volume/Testing/Python/volRCCropRegions.py +++ b/Rendering/Volume/Testing/Python/volRCCropRegions.py @@ -6,64 +6,77 @@ VTK_DATA_ROOT = vtkGetDataRoot() # Simple volume rendering example. reader = vtk.vtkSLCReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/sphere.slc") +reader.SetFileName(VTK_DATA_ROOT + "/Data/sphere.slc") + # Create transfer functions for opacity and color opacityTransferFunction = vtk.vtkPiecewiseFunction() -opacityTransferFunction.AddPoint(0,0.0) -opacityTransferFunction.AddPoint(30,0.0) -opacityTransferFunction.AddPoint(80,0.5) -opacityTransferFunction.AddPoint(255,0.5) +opacityTransferFunction.AddPoint(0, 0.0) +opacityTransferFunction.AddPoint(30, 0.0) +opacityTransferFunction.AddPoint(80, 0.5) +opacityTransferFunction.AddPoint(255, 0.5) colorTransferFunction = vtk.vtkColorTransferFunction() -colorTransferFunction.AddRGBPoint(0.0,0.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(64.0,1.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(128.0,0.0,0.0,1.0) -colorTransferFunction.AddRGBPoint(192.0,0.0,1.0,0.0) -colorTransferFunction.AddRGBPoint(255.0,0.0,0.2,0.0) + +colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0) +colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0) +colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0) + # Create properties, mappers, volume actors, and ray cast function volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) volumeProperty.SetInterpolationTypeToLinear() volumeProperty.ShadeOn() + compositeFunction = vtk.vtkVolumeRayCastCompositeFunction() + ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) -renWin.SetSize(600,300) + +renWin.SetSize(600, 300) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) -ren1.SetBackground(0.1,0.2,0.4) +ren1.SetBackground(0.1, 0.2, 0.4) + i = 0 while i < 2: j = 0 while j < 4: - locals()[get_variable_name("volumeMapper_", i, "_", j, "")] = vtk.vtkVolumeRayCastMapper() - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetInputConnection(reader.GetOutputPort()) - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetVolumeRayCastFunction(compositeFunction) - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetSampleDistance(0.4) - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].CroppingOn() - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetCroppingRegionPlanes(17,33,17,33,17,33) - locals()[get_variable_name("volume_", i, "_", j, "")] = vtk.vtkVolume() - locals()[get_variable_name("volume_", i, "_", j, "")].SetMapper(locals()[get_variable_name("volumeMapper_", i, "_", j, "")]) - locals()[get_variable_name("volume_", i, "_", j, "")].SetProperty(volumeProperty) - locals()[get_variable_name("userMatrix_", i, "_", j, "")] = vtk.vtkTransform() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].PostMultiply() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Identity() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Translate(-25,-25,-25) + idx = str(i) + "_" + str(j) + + exec("volumeMapper_" + idx + " = vtk.vtkVolumeRayCastMapper()") + eval("volumeMapper_" + idx).SetInputConnection(reader.GetOutputPort()) + eval("volumeMapper_" + idx).SetVolumeRayCastFunction(compositeFunction) + eval("volumeMapper_" + idx).SetSampleDistance(0.4) + eval("volumeMapper_" + idx).CroppingOn() + eval("volumeMapper_" + idx).SetCroppingRegionPlanes( + 17, 33, 17, 33, 17, 33) + + exec("volume_" + idx + " = vtk.vtkVolume()") + eval("volume_" + idx).SetMapper(eval("volumeMapper_" + idx)) + eval("volume_" + idx).SetProperty(volumeProperty) + + exec("userMatrix_" + idx + " = vtk.vtkTransform()") + eval("userMatrix_" + idx).PostMultiply() + eval("userMatrix_" + idx).Identity() + eval("userMatrix_" + idx).Translate(-25, -25, -25) if (i == 0): - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateX(expr.expr(globals(), locals(),["j","*","87","+","23"])) - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateY(16) - pass + eval("userMatrix_" + idx).RotateX(j * 87 + 23) + eval("userMatrix_" + idx).RotateY(16) else: - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateX(27) - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateY(expr.expr(globals(), locals(),["j","*","87","+","19"])) - pass - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Translate(expr.expr(globals(), locals(),["j","*","55","+","25"]),expr.expr(globals(), locals(),["i","*","55","+","25"]),0) - locals()[get_variable_name("volume_", i, "_", j, "")].SetUserTransform(locals()[get_variable_name("userMatrix_", i, "_", j, "")]) - ren1.AddViewProp(locals()[get_variable_name("volume_", i, "_", j, "")]) - j = j + 1 + eval("userMatrix_" + idx).RotateX(27) + eval("userMatrix_" + idx).RotateY(j * 87 + 19) + eval("userMatrix_" + idx).Translate(j * 55 + 25, i * 55 + 25, 0) + + eval("volume_" + idx).SetUserTransform(eval("userMatrix_" + idx)) - i = i + 1 + ren1.AddViewProp(eval("volume_" + idx)) + + j += 1 + i += 1 volumeMapper_0_0.SetCroppingRegionFlagsToSubVolume() volumeMapper_0_1.SetCroppingRegionFlagsToCross() @@ -73,18 +86,22 @@ volumeMapper_1_0.SetCroppingRegionFlagsToFence() volumeMapper_1_1.SetCroppingRegionFlagsToInvertedFence() volumeMapper_1_2.SetCroppingRegionFlags(1) volumeMapper_1_3.SetCroppingRegionFlags(67117057) + ren1.GetCullers().InitTraversal() + culler = ren1.GetCullers().GetNextItem() culler.SetSortingStyleToBackToFront() + ren1.ResetCamera() ren1.GetActiveCamera().Zoom(3.0) renWin.Render() -def TkCheckAbort (__vtk__temp0=0,__vtk__temp1=0): + +def TkCheckAbort (object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) - pass -renWin.AddObserver("AbortCheckEvent",TkCheckAbort) +renWin.AddObserver("AbortCheckEvent", TkCheckAbort) + iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Rendering/Volume/Testing/Python/volTM2DCropRegions.py b/Rendering/Volume/Testing/Python/volTM2DCropRegions.py index 8def2c2a8a4..16d7e50e7ca 100755 --- a/Rendering/Volume/Testing/Python/volTM2DCropRegions.py +++ b/Rendering/Volume/Testing/Python/volTM2DCropRegions.py @@ -6,61 +6,72 @@ VTK_DATA_ROOT = vtkGetDataRoot() # Simple volume rendering example. reader = vtk.vtkSLCReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/sphere.slc") +reader.SetFileName(VTK_DATA_ROOT + "/Data/sphere.slc") + # Create transfer functions for opacity and color opacityTransferFunction = vtk.vtkPiecewiseFunction() -opacityTransferFunction.AddPoint(0,0.0) -opacityTransferFunction.AddPoint(30,0.0) -opacityTransferFunction.AddPoint(80,0.5) -opacityTransferFunction.AddPoint(255,0.5) +opacityTransferFunction.AddPoint(0, 0.0) +opacityTransferFunction.AddPoint(30, 0.0) +opacityTransferFunction.AddPoint(80, 0.5) +opacityTransferFunction.AddPoint(255, 0.5) + colorTransferFunction = vtk.vtkColorTransferFunction() -colorTransferFunction.AddRGBPoint(0.0,0.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(64.0,1.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(128.0,0.0,0.0,1.0) -colorTransferFunction.AddRGBPoint(192.0,0.0,1.0,0.0) -colorTransferFunction.AddRGBPoint(255.0,0.0,0.2,0.0) +colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0) +colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0) +colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0) + # Create properties, mappers, volume actors, and ray cast function volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) volumeProperty.SetInterpolationTypeToLinear() volumeProperty.ShadeOn() + ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) -renWin.SetSize(600,300) + +renWin.SetSize(600, 300) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) -ren1.SetBackground(0.1,0.2,0.4) +ren1.SetBackground(0.1, 0.2, 0.4) + i = 0 while i < 2: j = 0 while j < 4: - locals()[get_variable_name("volumeMapper_", i, "_", j, "")] = vtk.vtkVolumeTextureMapper2D() - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetInputConnection(reader.GetOutputPort()) - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].CroppingOn() - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetCroppingRegionPlanes(17,33,17,33,17,33) - locals()[get_variable_name("volume_", i, "_", j, "")] = vtk.vtkVolume() - locals()[get_variable_name("volume_", i, "_", j, "")].SetMapper(locals()[get_variable_name("volumeMapper_", i, "_", j, "")]) - locals()[get_variable_name("volume_", i, "_", j, "")].SetProperty(volumeProperty) - locals()[get_variable_name("userMatrix_", i, "_", j, "")] = vtk.vtkTransform() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].PostMultiply() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Identity() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Translate(-25,-25,-25) + idx = str(i) + "_" + str(j) + + exec("volumeMapper_" + idx + " = vtk.vtkVolumeTextureMapper2D()") + eval("volumeMapper_" + idx).SetInputConnection(reader.GetOutputPort()) + eval("volumeMapper_" + idx).CroppingOn() + eval("volumeMapper_" + idx).SetCroppingRegionPlanes( + 17, 33, 17, 33, 17, 33) + + exec("volume_" + idx + " = vtk.vtkVolume()") + eval("volume_" + idx).SetMapper(eval("volumeMapper_" + idx)) + eval("volume_" + idx).SetProperty(volumeProperty) + + exec("userMatrix_" + idx + " = vtk.vtkTransform()") + eval("userMatrix_" + idx).PostMultiply() + eval("userMatrix_" + idx).Identity() + eval("userMatrix_" + idx).Translate(-25, -25, -25) if (i == 0): - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateX(expr.expr(globals(), locals(),["j","*","90","+","20"])) - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateY(20) - pass + eval("userMatrix_" + idx).RotateX(j * 90 + 20) + eval("userMatrix_" + idx).RotateY(20) else: - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateX(20) - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateY(expr.expr(globals(), locals(),["j","*","90","+","20"])) - pass - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Translate(expr.expr(globals(), locals(),["j","*","55","+","25"]),expr.expr(globals(), locals(),["i","*","55","+","25"]),0) - locals()[get_variable_name("volume_", i, "_", j, "")].SetUserTransform(locals()[get_variable_name("userMatrix_", i, "_", j, "")]) - ren1.AddViewProp(locals()[get_variable_name("volume_", i, "_", j, "")]) - j = j + 1 + eval("userMatrix_" + idx).RotateX(20) + eval("userMatrix_" + idx).RotateY(j * 90 + 20) + eval("userMatrix_" + idx).Translate(j * 55 + 25, i * 55 + 25, 0) + eval("volume_" + idx).SetUserTransform(eval("userMatrix_" + idx)) - i = i + 1 + ren1.AddViewProp(eval("volume_" + idx)) + + j += 1 + i += 1 volumeMapper_0_0.SetCroppingRegionFlagsToSubVolume() volumeMapper_0_1.SetCroppingRegionFlagsToCross() @@ -70,18 +81,22 @@ volumeMapper_1_0.SetCroppingRegionFlagsToFence() volumeMapper_1_1.SetCroppingRegionFlagsToInvertedFence() volumeMapper_1_2.SetCroppingRegionFlags(1) volumeMapper_1_3.SetCroppingRegionFlags(67117057) + ren1.GetCullers().InitTraversal() + culler = ren1.GetCullers().GetNextItem() culler.SetSortingStyleToBackToFront() + ren1.ResetCamera() ren1.GetActiveCamera().Zoom(3.0) + renWin.Render() -def TkCheckAbort (__vtk__temp0=0,__vtk__temp1=0): +def TkCheckAbort (object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) - pass -renWin.AddObserver("AbortCheckEvent",TkCheckAbort) +renWin.AddObserver("AbortCheckEvent", TkCheckAbort) + iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Rendering/Volume/Testing/Python/volTM3DCompressedCropRegions.py b/Rendering/Volume/Testing/Python/volTM3DCompressedCropRegions.py index cbbe174eb3b..890d91ce4ba 100755 --- a/Rendering/Volume/Testing/Python/volTM3DCompressedCropRegions.py +++ b/Rendering/Volume/Testing/Python/volTM3DCompressedCropRegions.py @@ -1,66 +1,80 @@ #!/usr/bin/env python -import sys +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Simple volume rendering example. reader = vtk.vtkSLCReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/sphere.slc") +reader.SetFileName(VTK_DATA_ROOT + "/Data/sphere.slc") + # Create transfer functions for opacity and color opacityTransferFunction = vtk.vtkPiecewiseFunction() -opacityTransferFunction.AddPoint(0,0.0) -opacityTransferFunction.AddPoint(30,0.0) -opacityTransferFunction.AddPoint(80,0.5) -opacityTransferFunction.AddPoint(255,0.5) +opacityTransferFunction.AddPoint(0, 0.0) +opacityTransferFunction.AddPoint(30, 0.0) +opacityTransferFunction.AddPoint(80, 0.5) +opacityTransferFunction.AddPoint(255, 0.5) + colorTransferFunction = vtk.vtkColorTransferFunction() -colorTransferFunction.AddRGBPoint(0.0,0.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(64.0,1.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(128.0,0.0,0.0,1.0) -colorTransferFunction.AddRGBPoint(192.0,0.0,1.0,0.0) -colorTransferFunction.AddRGBPoint(255.0,0.0,0.2,0.0) +colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0) +colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0) +colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0) + # Create properties, mappers, volume actors, and ray cast function volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) volumeProperty.SetInterpolationTypeToLinear() volumeProperty.ShadeOn() + ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) -renWin.SetSize(600,300) + +renWin.SetSize(600, 300) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) -ren1.SetBackground(0.1,0.2,0.4) +ren1.SetBackground(0.1, 0.2, 0.4) renWin.Render() + i = 0 while i < 2: j = 0 while j < 4: - locals()[get_variable_name("volumeMapper_", i, "_", j, "")] = vtk.vtkVolumeTextureMapper3D() - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetInputConnection(reader.GetOutputPort()) - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetSampleDistance(0.25) - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].CroppingOn() - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetUseCompressedTexture(1) - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetCroppingRegionPlanes(17,33,17,33,17,33) - locals()[get_variable_name("volume_", i, "_", j, "")] = vtk.vtkVolume() - locals()[get_variable_name("volume_", i, "_", j, "")].SetMapper(locals()[get_variable_name("volumeMapper_", i, "_", j, "")]) - locals()[get_variable_name("volume_", i, "_", j, "")].SetProperty(volumeProperty) - locals()[get_variable_name("userMatrix_", i, "_", j, "")] = vtk.vtkTransform() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].PostMultiply() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Identity() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Translate(-25,-25,-25) + idx = str(i) + "_" + str(j) + + exec("volumeMapper_" + idx + " = vtk.vtkVolumeTextureMapper3D()") + eval("volumeMapper_" + idx).SetInputConnection(reader.GetOutputPort()) + eval("volumeMapper_" + idx).SetSampleDistance(0.25) + eval("volumeMapper_" + idx).CroppingOn() + eval("volumeMapper_" + idx).SetUseCompressedTexture(1) + eval("volumeMapper_" + idx).SetCroppingRegionPlanes( + 17, 33, 17, 33, 17, 33) + + exec("volume_" + idx + " = vtk.vtkVolume()") + eval("volume_" + idx).SetMapper(eval("volumeMapper_" + idx)) + eval("volume_" + idx).SetProperty(volumeProperty) + + exec("userMatrix_" + idx + " = vtk.vtkTransform()") + eval("userMatrix_" + idx).PostMultiply() + eval("userMatrix_" + idx).Identity() + eval("userMatrix_" + idx).Translate(-25, -25, -25) if (i == 0): - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateX(expr.expr(globals(), locals(),["j","*","90","+","20"])) - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateY(20) - pass + eval("userMatrix_" + idx).RotateX(j * 90 + 20) + eval("userMatrix_" + idx).RotateY(20) else: - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateX(20) - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateY(expr.expr(globals(), locals(),["j","*","90","+","20"])) - pass - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Translate(expr.expr(globals(), locals(),["j","*","55","+","25"]),expr.expr(globals(), locals(),["i","*","55","+","25"]),0) - locals()[get_variable_name("volume_", i, "_", j, "")].SetUserTransform(locals()[get_variable_name("userMatrix_", i, "_", j, "")]) - ren1.AddViewProp(locals()[get_variable_name("volume_", i, "_", j, "")]) - j = j + 1 + eval("userMatrix_" + idx).RotateX(20) + eval("userMatrix_" + idx).RotateY(j * 90 + 20) + eval("userMatrix_" + idx).Translate(j * 55 + 25, i * 55 + 25, 0) + eval("volume_" + idx).SetUserTransform(eval("userMatrix_" + idx)) + + ren1.AddViewProp(eval("volume_" + idx)) - i = i + 1 + j += 1 + i += 1 volumeMapper_0_0.SetCroppingRegionFlagsToSubVolume() volumeMapper_0_1.SetCroppingRegionFlagsToCross() @@ -70,21 +84,26 @@ volumeMapper_1_0.SetCroppingRegionFlagsToFence() volumeMapper_1_1.SetCroppingRegionFlagsToInvertedFence() volumeMapper_1_2.SetCroppingRegionFlags(1) volumeMapper_1_3.SetCroppingRegionFlags(67117057) + ren1.GetCullers().InitTraversal() + culler = ren1.GetCullers().GetNextItem() culler.SetSortingStyleToBackToFront() -valid = volumeMapper_0_0.IsRenderSupported(volumeProperty,ren1) + +valid = volumeMapper_0_0.IsRenderSupported(volumeProperty, ren1) if (valid == 0): print "Required Extensions Not Supported" sys.exit(0) + ren1.ResetCamera() ren1.GetActiveCamera().Zoom(3.0) + renWin.Render() -def TkCheckAbort (__vtk__temp0=0,__vtk__temp1=0): + +def TkCheckAbort (object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) - pass iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Rendering/Volume/Testing/Python/volTM3DCropRegions.py b/Rendering/Volume/Testing/Python/volTM3DCropRegions.py index f25f38beed5..0efc1944fcb 100755 --- a/Rendering/Volume/Testing/Python/volTM3DCropRegions.py +++ b/Rendering/Volume/Testing/Python/volTM3DCropRegions.py @@ -1,64 +1,81 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Simple volume rendering example. reader = vtk.vtkSLCReader() -reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/sphere.slc") +reader.SetFileName(VTK_DATA_ROOT + "/Data/sphere.slc") + # Create transfer functions for opacity and color opacityTransferFunction = vtk.vtkPiecewiseFunction() -opacityTransferFunction.AddPoint(0,0.0) -opacityTransferFunction.AddPoint(30,0.0) -opacityTransferFunction.AddPoint(80,0.5) -opacityTransferFunction.AddPoint(255,0.5) +opacityTransferFunction.AddPoint(0, 0.0) +opacityTransferFunction.AddPoint(30, 0.0) +opacityTransferFunction.AddPoint(80, 0.5) +opacityTransferFunction.AddPoint(255, 0.5) + colorTransferFunction = vtk.vtkColorTransferFunction() -colorTransferFunction.AddRGBPoint(0.0,0.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(64.0,1.0,0.0,0.0) -colorTransferFunction.AddRGBPoint(128.0,0.0,0.0,1.0) -colorTransferFunction.AddRGBPoint(192.0,0.0,1.0,0.0) -colorTransferFunction.AddRGBPoint(255.0,0.0,0.2,0.0) +colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0) +colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0) +colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0) +colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0) + # Create properties, mappers, volume actors, and ray cast function volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) volumeProperty.SetInterpolationTypeToLinear() volumeProperty.ShadeOn() + ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) -renWin.SetSize(600,300) + +renWin.SetSize(600, 300) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) -ren1.SetBackground(0.1,0.2,0.4) +ren1.SetBackground(0.1, 0.2, 0.4) + renWin.Render() i = 0 while i < 2: j = 0 while j < 4: - locals()[get_variable_name("volumeMapper_", i, "_", j, "")] = vtk.vtkVolumeTextureMapper3D() - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetInputConnection(reader.GetOutputPort()) - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetSampleDistance(0.25) - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].CroppingOn() - locals()[get_variable_name("volumeMapper_", i, "_", j, "")].SetCroppingRegionPlanes(17,33,17,33,17,33) - locals()[get_variable_name("volume_", i, "_", j, "")] = vtk.vtkVolume() - locals()[get_variable_name("volume_", i, "_", j, "")].SetMapper(locals()[get_variable_name("volumeMapper_", i, "_", j, "")]) - locals()[get_variable_name("volume_", i, "_", j, "")].SetProperty(volumeProperty) - locals()[get_variable_name("userMatrix_", i, "_", j, "")] = vtk.vtkTransform() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].PostMultiply() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Identity() - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Translate(-25,-25,-25) + idx = str(i) + "_" + str(j) + + exec("volumeMapper_" + idx + " = vtk.vtkVolumeTextureMapper3D()") + eval("volumeMapper_" + idx).SetInputConnection(reader.GetOutputPort()) + eval("volumeMapper_" + idx).SetSampleDistance(0.25) + eval("volumeMapper_" + idx).CroppingOn() + eval("volumeMapper_" + idx).SetCroppingRegionPlanes( + 17, 33, 17, 33, 17, 33) + + exec("volume_" + idx + " = vtk.vtkVolume()") + eval("volume_" + idx).SetMapper(eval("volumeMapper_" + idx)) + eval("volume_" + idx).SetProperty(volumeProperty) + + exec("userMatrix_" + idx + " = vtk.vtkTransform()") + eval("userMatrix_" + idx).PostMultiply() + eval("userMatrix_" + idx).Identity() + eval("userMatrix_" + idx).Translate(-25, -25, -25) if (i == 0): - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateX(expr.expr(globals(), locals(),["j","*","90","+","20"])) - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateY(20) + eval("userMatrix_" + idx).RotateX(j * 90 + 20) + eval("userMatrix_" + idx).RotateY(20) pass else: - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateX(20) - locals()[get_variable_name("userMatrix_", i, "_", j, "")].RotateY(expr.expr(globals(), locals(),["j","*","90","+","20"])) + eval("userMatrix_" + idx).RotateX(20) + eval("userMatrix_" + idx).RotateY(j * 90 + 20) pass - locals()[get_variable_name("userMatrix_", i, "_", j, "")].Translate(expr.expr(globals(), locals(),["j","*","55","+","25"]),expr.expr(globals(), locals(),["i","*","55","+","25"]),0) - locals()[get_variable_name("volume_", i, "_", j, "")].SetUserTransform(locals()[get_variable_name("userMatrix_", i, "_", j, "")]) - ren1.AddViewProp(locals()[get_variable_name("volume_", i, "_", j, "")]) - j = j + 1 + eval("userMatrix_" + idx).Translate(j * 55 + 25, i * 55 + 25, 0) + eval("volume_" + idx).SetUserTransform(eval("userMatrix_" + idx)) - i = i + 1 + ren1.AddViewProp(eval("volume_" + idx)) + + j += 1 + i += 1 volumeMapper_0_0.SetCroppingRegionFlagsToSubVolume() volumeMapper_0_1.SetCroppingRegionFlagsToCross() @@ -68,26 +85,30 @@ volumeMapper_1_0.SetCroppingRegionFlagsToFence() volumeMapper_1_1.SetCroppingRegionFlagsToInvertedFence() volumeMapper_1_2.SetCroppingRegionFlags(1) volumeMapper_1_3.SetCroppingRegionFlags(67117057) + ren1.GetCullers().InitTraversal() + culler = ren1.GetCullers().GetNextItem() culler.SetSortingStyleToBackToFront() -valid = volumeMapper_0_0.IsRenderSupported(volumeProperty,ren1) -if (): + +valid = volumeMapper_0_0.IsRenderSupported(volumeProperty, ren1) +if not valid: ren1.RemoveAllViewProps() t = vtk.vtkTextActor() t.SetInput("Required Extensions Not Supported") - t.SetDisplayPosition(300,150) + t.SetDisplayPosition(300, 150) t.GetTextProperty().SetJustificationToCentered() ren1.AddViewProp(t) pass + ren1.ResetCamera() ren1.GetActiveCamera().Zoom(3.0) renWin.Render() -def TkCheckAbort (__vtk__temp0=0,__vtk__temp1=0): + +def TkCheckAbort (object_binding, event_name): foo = renWin.GetEventPending() if (foo != 0): renWin.SetAbortRender(1) - pass iren.Initialize() -# --- end of script -- +#iren.Start() diff --git a/Rendering/Volume/Testing/Python/volTM3DRotateClip.py b/Rendering/Volume/Testing/Python/volTM3DRotateClip.py index 5c60d0a07d0..f4d1ee85b00 100755 --- a/Rendering/Volume/Testing/Python/volTM3DRotateClip.py +++ b/Rendering/Volume/Testing/Python/volTM3DRotateClip.py @@ -1,47 +1,59 @@ #!/usr/bin/env python +import vtk +from vtk.test import Testing +from vtk.util.misc import vtkGetDataRoot +VTK_DATA_ROOT = vtkGetDataRoot() # Simple volume rendering example. reader = vtk.vtkImageReader() reader.SetDataByteOrderToLittleEndian() -reader.SetDataExtent(0,63,0,63,1,93) -reader.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter") +reader.SetDataExtent(0, 63, 0, 63, 1, 93) +reader.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") reader.SetDataMask(0x7fff) -reader.SetDataSpacing(2,2,1) +reader.SetDataSpacing(2, 2, 1) reader.SetDataScalarTypeToUnsignedShort() reader.Update() + changeFilter = vtk.vtkImageChangeInformation() changeFilter.SetInputConnection(reader.GetOutputPort()) -changeFilter.SetOutputOrigin(-63,-63,-46) +changeFilter.SetOutputOrigin(-63, -63, -46) + # Create transfer functions for opacity and color opacityTransferFunction = vtk.vtkPiecewiseFunction() -opacityTransferFunction.AddPoint(600,0.0) -opacityTransferFunction.AddPoint(2000,1.0) +opacityTransferFunction.AddPoint(600, 0.0) +opacityTransferFunction.AddPoint(2000, 1.0) + colorTransferFunction = vtk.vtkColorTransferFunction() colorTransferFunction.ClampingOff() -colorTransferFunction.AddHSVPoint(0.0,0.01,1.0,1.0) -colorTransferFunction.AddHSVPoint(1000.0,0.50,1.0,1.0) -colorTransferFunction.AddHSVPoint(2000.0,0.99,1.0,1.0) +colorTransferFunction.AddHSVPoint(0.0, 0.01, 1.0, 1.0) +colorTransferFunction.AddHSVPoint(1000.0, 0.50, 1.0, 1.0) +colorTransferFunction.AddHSVPoint(2000.0, 0.99, 1.0, 1.0) colorTransferFunction.SetColorSpaceToHSV() + # Create properties, mappers, volume actors, and ray cast function volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(colorTransferFunction) volumeProperty.SetScalarOpacity(opacityTransferFunction) + volumeMapper = vtk.vtkVolumeTextureMapper3D() volumeMapper.SetInputConnection(changeFilter.GetOutputPort()) volumeMapper.SetSampleDistance(0.25) + volume = vtk.vtkVolume() volume.SetMapper(volumeMapper) volume.SetProperty(volumeProperty) + # Create geometric sphere sphereSource = vtk.vtkSphereSource() sphereSource.SetRadius(65) sphereSource.SetThetaResolution(20) sphereSource.SetPhiResolution(40) + # Compute random scalars (colors) for each cell randomColors = vtk.vtkProgrammableAttributeDataFilter() randomColors.SetInputConnection(sphereSource.GetOutputPort()) -def colorCells (__vtk__temp0=0,__vtk__temp1=0): +def colorCells (): randomColorGenerator = vtk.vtkMath() input = randomColors.GetInput() output = randomColors.GetOutput() @@ -50,69 +62,83 @@ def colorCells (__vtk__temp0=0,__vtk__temp1=0): colors.SetNumberOfTuples(numCells) i = 0 while i < numCells: - colors.SetValue(i,randomColorGenerator.Random(0,1)) + colors.SetValue(i, randomColorGenerator.Random(0, 1)) i = i + 1 output.GetCellData().CopyScalarsOff() output.GetCellData().PassData(input.GetCellData()) output.GetCellData().SetScalars(colors) del colors - #reference counting - it's ok + # reference counting - it's ok del randomColorGenerator randomColors.SetExecuteMethod(colorCells) + # This does not need a hierarchical mapper, but hierarchical # mapper could use a test that has clipping so we use it here sphereMapper = vtk.vtkHierarchicalPolyDataMapper() sphereMapper.SetInputConnection(randomColors.GetOutputPort(0)) + sphereActor = vtk.vtkActor() sphereActor.SetMapper(sphereMapper) + # Set up the planes plane1 = vtk.vtkPlane() -plane1.SetOrigin(0,0,-10) -plane1.SetNormal(0,0,1) +plane1.SetOrigin(0, 0, -10) +plane1.SetNormal(0, 0, 1) plane2 = vtk.vtkPlane() -plane2.SetOrigin(0,0,10) -plane2.SetNormal(0,0,-1) +plane2.SetOrigin(0, 0, 10) +plane2.SetNormal(0, 0, -1) plane3 = vtk.vtkPlane() -plane3.SetOrigin(-10,0,0) -plane3.SetNormal(1,0,0) +plane3.SetOrigin(-10, 0, 0) +plane3.SetNormal(1, 0, 0) plane4 = vtk.vtkPlane() -plane4.SetOrigin(10,0,0) -plane4.SetNormal(-1,0,0) +plane4.SetOrigin(10, 0, 0) +plane4.SetNormal(-1, 0, 0) + sphereMapper.AddClippingPlane(plane1) sphereMapper.AddClippingPlane(plane2) volumeMapper.AddClippingPlane(plane3) volumeMapper.AddClippingPlane(plane4) + # Okay now the graphics stuff ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.ReportGraphicErrorsOn() renWin.AddRenderer(ren1) -renWin.SetSize(256,256) + +renWin.SetSize(256, 256) + iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) + ren1.GetCullers().InitTraversal() culler = ren1.GetCullers().GetNextItem() culler.SetSortingStyleToBackToFront() + ren1.AddViewProp(sphereActor) -ren1.SetBackground(0.1,0.2,0.4) +ren1.SetBackground(0.1, 0.2, 0.4) + renWin.Render() + ren1.GetActiveCamera().Azimuth(45) ren1.GetActiveCamera().Elevation(15) ren1.GetActiveCamera().Roll(45) ren1.GetActiveCamera().Zoom(2.0) -valid = volumeMapper.IsRenderSupported(volumeProperty,ren1) + ren1.AddViewProp(volume) -if (): + +valid = volumeMapper.IsRenderSupported(volumeProperty, ren1) +if not valid: ren1.RemoveAllViewProps() t = vtk.vtkTextActor() t.SetInput("Required Extensions Not Supported") - t.SetDisplayPosition(128,128) + t.SetDisplayPosition(128, 128) t.GetTextProperty().SetJustificationToCentered() ren1.AddViewProp(t) - pass + iren.Initialize() + i = 0 while i < 5: volume.RotateY(17) @@ -120,6 +146,7 @@ while i < 5: sphereActor.RotateX(13) sphereActor.RotateY(17) renWin.Render() - i = i + 1 + i += 1 -# --- end of script -- +# This is needed if you want to interact with the image. +#iren.Start() -- GitLab