diff --git a/src/Admin/FindExamplesMissingTestImages.py b/src/Admin/FindExamplesMissingTestImages.py index cb55c49c515f290de2f29f5d6216b73ddd81ba65..adb29f96a671197e09a29e1f117ef59c0e57f503 100755 --- a/src/Admin/FindExamplesMissingTestImages.py +++ b/src/Admin/FindExamplesMissingTestImages.py @@ -90,7 +90,19 @@ for ex in ['CSharp', 'Java', 'Python']: new_k = pk.replace('Cxx', ex) no_image[ex][new_k] = lst -no_image['Java']['Java/IO'].add('WritePolyData') +no_image['Python']['Python/Filtering'].add('IterativeClosestPoints') +no_image['Python']['Python/Arrays'] = no_image['Python']['Python/Arrays'] | {'GetValues', 'RenameArray'} +no_image['Python']['Python/ImageData'].add('SumVTKImages') +no_image['Python']['Python/IO'].add('SumVTKImages') +no_image['Python']['Python/PolyData'] = no_image['Python']['Python/PolyData'] | {'ColoredTriangle', + 'SolidColoredTriangle', + 'TriangleColoredPoints', + 'TriangleCornerVertices', + 'TriangleCorners'} +no_image['Python']['Python/Utilities'].add('VTKVersion') +no_image['Python']['Python/Untested/HasBugs'].add('UnstructuredTransientVolumeRendering') + +no_image['Java']['Java/IO'].add('WriteTriangleToFile') def get_program_parameters(): diff --git a/src/Python.md b/src/Python.md index 59b7151b457b0de85315e6f108470b8146e49812..f94decfd2ecc0a02dbd68185a257e99d616d1fb2 100644 --- a/src/Python.md +++ b/src/Python.md @@ -470,7 +470,6 @@ See [this tutorial](http://www.vtk.org/Wiki/VTK/Tutorials/3DDataTypes) for a bri [TensorAxes](/Python/VisualizationAlgorithms/TensorAxes) | vtkPointLoad vtkTensorGlyph | Display the scaled and oriented principal axes of the stress tensor. [TensorEllipsoids](/Python/VisualizationAlgorithms/TensorEllipsoids) | vtkPointLoad vtkTensorGlyph | Display the scaled and oriented principal axes as tensor ellipsoids representing the stress tensor. [TextSource](/Python/Visualization/TextSource) | vtkTextSource | -[UnstructuredTransientVolumeRendering](/Python/Visualization/UnstructuredTransientVolumeRendering) | vtkUnstructuredGridVolumeRayCastMapper | [VectorText](/Python/Visualization/VectorText) | vtkVectorText | Display high resolution text. [VelocityProfile](/Python/VisualizationAlgorithms/VelocityProfile) | vtkMultiBlockPLOT3DReader vtkStructuredGridGeometryFilter vtkAppendPolyData vtkWarpVector | Warping the geometry of three planes to show flow momentum. [ViewFrog](/Python/Visualization/ViewFrog) | vtkMetaImageReader vtkMarchingCubes vtkImageGaussianSmooth vtkWindowedSincPolyDataFilter | The complete frog without skin. @@ -578,3 +577,9 @@ See [this tutorial](http://www.vtk.org/Wiki/VTK/Tutorials/3DDataTypes) for a bri | -------------- | ---------------------- | ------------- | ------- | [EmbedInPyQt](/Python/Widgets/EmbedInPyQt) | vtkRenderWindowInteractor | Shows how to easily embed VTK in PyQt with QVTKRenderWindowInteractor, first example [EmbedInPyQt2](/Python/Widgets/EmbedInPyQt2) | vtkRenderWindowInteractor | Shows how to embed VTK in PyQt with QVTKRenderWindowInteractor, second example + +## Has Bugs + +| Example Name | Classes Demonstrated | Description | Image | +| -------------- | ---------------------- | ------------- | ------- | +[UnstructuredTransientVolumeRendering](/Python/Untested/HasBugs/UnstructuredTransientVolumeRendering) | vtkUnstructuredGridVolumeRayCastMapper | diff --git a/src/Python/Plotting/SpiderPlot.py b/src/Python/Plotting/SpiderPlot.py index 656fac11ef97411209db3fc68c3915856f87f00c..6fbb0536043f5a4cb95a962846cd940302d3e190 100755 --- a/src/Python/Plotting/SpiderPlot.py +++ b/src/Python/Plotting/SpiderPlot.py @@ -1,11 +1,11 @@ #!/usr/bin/env python -import random - import vtk def main(): + colors = vtk.vtkNamedColors() + numTuples = 12 bitter = vtk.vtkFloatArray() @@ -23,12 +23,20 @@ def main(): oily = vtk.vtkFloatArray() oily.SetNumberOfTuples(numTuples) + rand_seq = vtk.vtkMinimalStandardRandomSequence() + rand_seq.SetSeed(1) + for i in range(numTuples): - bitter.SetTuple1(i, random.randint(1, 10)) - crispy.SetTuple1(i, random.randint(-1, 1)) - crunchy.SetTuple1(i, random.randint(1, 100)) - salty.SetTuple1(i, random.randint(0, 10)) - oily.SetTuple1(i, random.randint(5, 25)) + bitter.SetTuple1(i, rand_seq.GetRangeValue(1, 10)) + rand_seq.Next() + crispy.SetTuple1(i, rand_seq.GetRangeValue(-1, 1)) + rand_seq.Next() + crunchy.SetTuple1(i, rand_seq.GetRangeValue(1, 100)) + rand_seq.Next() + salty.SetTuple1(i, rand_seq.GetRangeValue(0, 10)) + rand_seq.Next() + oily.SetTuple1(i, rand_seq.GetRangeValue(5, 25)) + rand_seq.Next() dobj = vtk.vtkDataObject() dobj.GetFieldData().AddArray(bitter) @@ -39,11 +47,11 @@ def main(): actor = vtk.vtkSpiderPlotActor() actor.SetInputData(dobj) - actor.SetTitle("spider plot") + actor.SetTitle("Spider Plot") actor.SetIndependentVariablesToColumns() actor.GetPositionCoordinate().SetValue(0.05, 0.1, 0.0) actor.GetPosition2Coordinate().SetValue(0.95, 0.85, 0.0) - actor.GetProperty().SetColor(1, 0, 0) + actor.GetProperty().SetColor(colors.GetColor3d('Bisque')) actor.SetAxisLabel(0, "Bitter") actor.SetAxisRange(0, 1, 10) @@ -62,13 +70,18 @@ def main(): actor.GetLegendActor().SetNumberOfEntries(numTuples) for i in range(numTuples): - actor.SetPlotColor(i, random.random(), random.random(), random.random()) + r = rand_seq.GetValue() + rand_seq.Next() + g = rand_seq.GetValue() + rand_seq.Next() + b = rand_seq.GetValue() + rand_seq.Next() + actor.SetPlotColor(i, r, g, b) actor.LegendVisibilityOn() - # // Set text colors (same as actor for backward compat with test) - # actor.GetTitleTextProperty().SetColor(1, 1, 0) - # actor.GetLabelTextProperty().SetColor(1, 0, 0) + actor.GetTitleTextProperty().SetColor(colors.GetColor3d('Yellow')) + actor.GetLabelTextProperty().SetColor(colors.GetColor3d('OrangeRed')) ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() @@ -76,8 +89,8 @@ def main(): iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ren1.AddActor(actor) - ren1.SetBackground(0, 0, 0) - renWin.SetSize(500, 500) + ren1.SetBackground(colors.GetColor3d('Black')) + renWin.SetSize(800, 800) iren.Initialize() renWin.Render() diff --git a/src/Python/RectilinearGrid/RGrid.md b/src/Python/RectilinearGrid/RGrid.md new file mode 100644 index 0000000000000000000000000000000000000000..7af3225a4838fa9e13a8d1e770721b7bee781c22 --- /dev/null +++ b/src/Python/RectilinearGrid/RGrid.md @@ -0,0 +1,4 @@ +### Description + +Creating a rectilinear grid dataset. The coordinates along each axis are defined using an instance of vtkDataArray. + diff --git a/src/Python/RectilinearGrid/RectilinearGrid.py b/src/Python/RectilinearGrid/RectilinearGrid.py index 3c2c539e2c08b3e7d09ae2ed106ceb93035cca2e..c61f86d4fd1c027876773c706ce89e5d238940b6 100755 --- a/src/Python/RectilinearGrid/RectilinearGrid.py +++ b/src/Python/RectilinearGrid/RectilinearGrid.py @@ -1,86 +1,95 @@ import vtk -x = [ - -1.22396, -1.17188, -1.11979, -1.06771, -1.01562, -0.963542, - -0.911458, -0.859375, -0.807292, -0.755208, -0.703125, -0.651042, - -0.598958, -0.546875, -0.494792, -0.442708, -0.390625, -0.338542, - -0.286458, -0.234375, -0.182292, -0.130209, -0.078125, -0.026042, - 0.0260415, 0.078125, 0.130208, 0.182291, 0.234375, 0.286458, - 0.338542, 0.390625, 0.442708, 0.494792, 0.546875, 0.598958, - 0.651042, 0.703125, 0.755208, 0.807292, 0.859375, 0.911458, - 0.963542, 1.01562, 1.06771, 1.11979, 1.17188] - -y = [ - -1.25, -1.17188, -1.09375, -1.01562, -0.9375, -0.859375, - -0.78125, -0.703125, -0.625, -0.546875, -0.46875, -0.390625, - -0.3125, -0.234375, -0.15625, -0.078125, 0, 0.078125, - 0.15625, 0.234375, 0.3125, 0.390625, 0.46875, 0.546875, - 0.625, 0.703125, 0.78125, 0.859375, 0.9375, 1.01562, - 1.09375, 1.17188, 1.25] - -z = [ - 0, 0.1, 0.2, 0.3, 0.4, 0.5, - 0.6, 0.7, 0.75, 0.8, 0.9, 1, - 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, - 1.7, 1.75, 1.8, 1.9, 2, 2.1, - 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, - 2.75, 2.8, 2.9, 3, 3.1, 3.2, - 3.3, 3.4, 3.5, 3.6, 3.7, 3.75, - 3.8, 3.9] - -# Create a rectilinear grid by defining three arrays specifying the -# coordinates in the x-y-z directions. -xCoords = vtk.vtkFloatArray() -for i in x: - xCoords.InsertNextValue(i) - -yCoords = vtk.vtkFloatArray() -for i in y: - yCoords.InsertNextValue(i) - -zCoords = vtk.vtkFloatArray() -for i in z: - zCoords.InsertNextValue(i) - -# The coordinates are assigned to the rectilinear grid. Make sure that -# the number of values in each of the XCoordinates, YCoordinates, -# and ZCoordinates is equal to what is defined in SetDimensions(). -# -rgrid = vtk.vtkRectilinearGrid() -rgrid.SetDimensions(len(x), len(y), len(z)) -rgrid.SetXCoordinates(xCoords) -rgrid.SetYCoordinates(yCoords) -rgrid.SetZCoordinates(zCoords) - -# Extract a plane from the grid to see what we've got. -plane = vtk.vtkRectilinearGridGeometryFilter() -plane.SetInputData(rgrid) -plane.SetExtent(0, 46, 16, 16, 0, 43) - -rgridMapper = vtk.vtkPolyDataMapper() -rgridMapper.SetInputConnection(plane.GetOutputPort()) - -wireActor = vtk.vtkActor() -wireActor.SetMapper(rgridMapper) -wireActor.GetProperty().SetRepresentationToWireframe() -wireActor.GetProperty().SetColor(0, 0, 0) - -# Create the usual rendering stuff. -renderer = vtk.vtkRenderer() -renWin = vtk.vtkRenderWindow() -renWin.AddRenderer(renderer) -iren = vtk.vtkRenderWindowInteractor() -iren.SetRenderWindow(renWin) - -renderer.AddActor(wireActor) -renderer.SetBackground(1, 1, 1) -renderer.ResetCamera() -renderer.GetActiveCamera().Elevation(60.0) -renderer.GetActiveCamera().Azimuth(30.0) -renderer.GetActiveCamera().Zoom(1.0) - -renWin.SetSize(300, 300) - -# interact with data -renWin.Render() -iren.Start() + +def main(): + colors = vtk.vtkNamedColors() + + x = [ + -1.22396, -1.17188, -1.11979, -1.06771, -1.01562, -0.963542, + -0.911458, -0.859375, -0.807292, -0.755208, -0.703125, -0.651042, + -0.598958, -0.546875, -0.494792, -0.442708, -0.390625, -0.338542, + -0.286458, -0.234375, -0.182292, -0.130209, -0.078125, -0.026042, + 0.0260415, 0.078125, 0.130208, 0.182291, 0.234375, 0.286458, + 0.338542, 0.390625, 0.442708, 0.494792, 0.546875, 0.598958, + 0.651042, 0.703125, 0.755208, 0.807292, 0.859375, 0.911458, + 0.963542, 1.01562, 1.06771, 1.11979, 1.17188] + + y = [ + -1.25, -1.17188, -1.09375, -1.01562, -0.9375, -0.859375, + -0.78125, -0.703125, -0.625, -0.546875, -0.46875, -0.390625, + -0.3125, -0.234375, -0.15625, -0.078125, 0, 0.078125, + 0.15625, 0.234375, 0.3125, 0.390625, 0.46875, 0.546875, + 0.625, 0.703125, 0.78125, 0.859375, 0.9375, 1.01562, + 1.09375, 1.17188, 1.25] + + z = [ + 0, 0.1, 0.2, 0.3, 0.4, 0.5, + 0.6, 0.7, 0.75, 0.8, 0.9, 1, + 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, + 1.7, 1.75, 1.8, 1.9, 2, 2.1, + 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, + 2.75, 2.8, 2.9, 3, 3.1, 3.2, + 3.3, 3.4, 3.5, 3.6, 3.7, 3.75, + 3.8, 3.9] + + # Create a rectilinear grid by defining three arrays specifying the + # coordinates in the x-y-z directions. + xCoords = vtk.vtkFloatArray() + for i in x: + xCoords.InsertNextValue(i) + + yCoords = vtk.vtkFloatArray() + for i in y: + yCoords.InsertNextValue(i) + + zCoords = vtk.vtkFloatArray() + for i in z: + zCoords.InsertNextValue(i) + + # The coordinates are assigned to the rectilinear grid. Make sure that + # the number of values in each of the XCoordinates, YCoordinates, + # and ZCoordinates is equal to what is defined in SetDimensions(). + # + rgrid = vtk.vtkRectilinearGrid() + rgrid.SetDimensions(len(x), len(y), len(z)) + rgrid.SetXCoordinates(xCoords) + rgrid.SetYCoordinates(yCoords) + rgrid.SetZCoordinates(zCoords) + + # Extract a plane from the grid to see what we've got. + plane = vtk.vtkRectilinearGridGeometryFilter() + plane.SetInputData(rgrid) + plane.SetExtent(0, 46, 16, 16, 0, 43) + + rgridMapper = vtk.vtkPolyDataMapper() + rgridMapper.SetInputConnection(plane.GetOutputPort()) + + wireActor = vtk.vtkActor() + wireActor.SetMapper(rgridMapper) + wireActor.GetProperty().SetRepresentationToWireframe() + wireActor.GetProperty().SetColor(colors.GetColor3d("Black")) + wireActor.GetProperty().EdgeVisibilityOn() + + # Create the usual rendering stuff. + renderer = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() + renWin.AddRenderer(renderer) + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) + + renderer.AddActor(wireActor) + renderer.SetBackground(colors.GetColor3d("AliceBlue")) + renderer.ResetCamera() + renderer.GetActiveCamera().Elevation(60.0) + renderer.GetActiveCamera().Azimuth(30.0) + renderer.GetActiveCamera().Zoom(1.0) + + renWin.SetSize(300, 300) + + # interact with data + renWin.Render() + iren.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/UnstructuredGrid/UGrid.py b/src/Python/UnstructuredGrid/UGrid.py index fa61153f2f998ef8c03eeff192ef64d9ab37b92c..e50bd3780a03e916e95ebd972dcea9302340c031 100755 --- a/src/Python/UnstructuredGrid/UGrid.py +++ b/src/Python/UnstructuredGrid/UGrid.py @@ -13,6 +13,9 @@ def main(): x = [[0, 0, 0], [1, 0, 0], [2, 0, 0], [0, 1, 0], [1, 1, 0], [2, 1, 0], [0, 0, 1], [1, 0, 1], [2, 0, 1], [0, 1, 1], [1, 1, 1], [2, 1, 1], [0, 1, 2], [1, 1, 2], [2, 1, 2], [0, 1, 3], [1, 1, 3], [2, 1, 3], [0, 1, 4], [1, 1, 4], [2, 1, 4], [0, 1, 5], [1, 1, 5], [2, 1, 5], [0, 1, 6], [1, 1, 6], [2, 1, 6]] + # Here we have kept consistency with the Cxx example of the same name. + # This means we will use slicing in ugrid.InsertNextCell to ensure that the correct + # number of points are used. pts = [[0, 1, 4, 3, 6, 7, 10, 9], [1, 2, 5, 4, 7, 8, 11, 10], [6, 10, 9, 12, 0, 0, 0, 0], [8, 11, 10, 14, 0, 0, 0, 0], [16, 17, 14, 13, 12, 15, 0, 0], [18, 15, 19, 16, 20, 17, 0, 0], [22, 23, 20, 19, 0, 0, 0, 0], [21, 22, 18, 0, 0, 0, 0, 0], [22, 19, 18, 0, 0, 0, 0, 0], @@ -34,16 +37,16 @@ def main(): ugrid.Allocate(100) ugrid.InsertNextCell(vtk.VTK_HEXAHEDRON, 8, pts[0]) ugrid.InsertNextCell(vtk.VTK_HEXAHEDRON, 8, pts[1]) - ugrid.InsertNextCell(vtk.VTK_TETRA, 4, pts[2]) - ugrid.InsertNextCell(vtk.VTK_TETRA, 4, pts[3]) - ugrid.InsertNextCell(vtk.VTK_POLYGON, 6, pts[4]) - ugrid.InsertNextCell(vtk.VTK_TRIANGLE_STRIP, 6, pts[5]) - ugrid.InsertNextCell(vtk.VTK_QUAD, 4, pts[6]) - ugrid.InsertNextCell(vtk.VTK_TRIANGLE, 3, pts[7]) - ugrid.InsertNextCell(vtk.VTK_TRIANGLE, 3, pts[8]) - ugrid.InsertNextCell(vtk.VTK_LINE, 2, pts[9]) - ugrid.InsertNextCell(vtk.VTK_LINE, 2, pts[10]) - ugrid.InsertNextCell(vtk.VTK_VERTEX, 1, pts[11]) + ugrid.InsertNextCell(vtk.VTK_TETRA, 4, pts[2][:4]) + ugrid.InsertNextCell(vtk.VTK_TETRA, 4, pts[3][:4]) + ugrid.InsertNextCell(vtk.VTK_POLYGON, 6, pts[4][:6]) + ugrid.InsertNextCell(vtk.VTK_TRIANGLE_STRIP, 6, pts[5][:6]) + ugrid.InsertNextCell(vtk.VTK_QUAD, 4, pts[6][:4]) + ugrid.InsertNextCell(vtk.VTK_TRIANGLE, 3, pts[7][:3]) + ugrid.InsertNextCell(vtk.VTK_TRIANGLE, 3, pts[8][:3]) + ugrid.InsertNextCell(vtk.VTK_LINE, 2, pts[9][:2]) + ugrid.InsertNextCell(vtk.VTK_LINE, 2, pts[10][:2]) + ugrid.InsertNextCell(vtk.VTK_VERTEX, 1, pts[11][:1]) ugrid.SetPoints(points) diff --git a/src/Python/Visualization/UnstructuredTransientVolumeRendering.md b/src/Python/Untested/HasBugs/UnstructuredTransientVolumeRendering.md similarity index 98% rename from src/Python/Visualization/UnstructuredTransientVolumeRendering.md rename to src/Python/Untested/HasBugs/UnstructuredTransientVolumeRendering.md index 318dc5bfda3f042db4bdc67689a1a171139b6494..ec350f4edafeef3099f673b8550160b933192917 100644 --- a/src/Python/Visualization/UnstructuredTransientVolumeRendering.md +++ b/src/Python/Untested/HasBugs/UnstructuredTransientVolumeRendering.md @@ -1,2 +1,3 @@ ### Description + Volume render unstructured transient data. diff --git a/src/Python/Visualization/UnstructuredTransientVolumeRendering.py b/src/Python/Untested/HasBugs/UnstructuredTransientVolumeRendering.py similarity index 100% rename from src/Python/Visualization/UnstructuredTransientVolumeRendering.py rename to src/Python/Untested/HasBugs/UnstructuredTransientVolumeRendering.py diff --git a/src/Python/Utilities/Animation.py b/src/Python/Utilities/Animation.py index ef6dc0f6dcaabce39e1660f9c2360d2db25fb4fc..f007b218c1f27e763de8de4acd43f55ad360a1b1 100755 --- a/src/Python/Utilities/Animation.py +++ b/src/Python/Utilities/Animation.py @@ -4,34 +4,51 @@ import vtk class vtkTimerCallback(): - def __init__(self): + def __init__(self, steps, actor, iren): self.timer_count = 0 + self.steps = steps + self.actor = actor + self.iren = iren + self.timerId = None def execute(self, obj, event): - print(self.timer_count) - self.actor.SetPosition(self.timer_count, self.timer_count, 0) - iren = obj - iren.GetRenderWindow().Render() - self.timer_count += 1 + step = 0 + while step < self.steps: + print(self.timer_count) + self.actor.SetPosition(self.timer_count / 100.0, self.timer_count / 100.0, 0) + iren = obj + iren.GetRenderWindow().Render() + self.timer_count += 1 + step += 1 + if self.timerId: + iren.DestroyTimer(self.timerId) def main(): + colors = vtk.vtkNamedColors() + # Create a sphere sphereSource = vtk.vtkSphereSource() sphereSource.SetCenter(0.0, 0.0, 0.0) - sphereSource.SetRadius(5) + sphereSource.SetRadius(2) + sphereSource.SetPhiResolution(30) + sphereSource.SetThetaResolution(30) # Create a mapper and actor mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(sphereSource.GetOutputPort()) actor = vtk.vtkActor() + actor.GetProperty().SetColor(colors.GetColor3d("Peacock")) + actor.GetProperty().SetSpecular(0.6) + actor.GetProperty().SetSpecularPower(30) actor.SetMapper(mapper) - # prop = actor.GetProperty() + # actor.SetPosition(-5, -5, 0) # Setup a renderer, render window, and interactor renderer = vtk.vtkRenderer() + renderer.SetBackground(colors.GetColor3d("MistyRose")) renderWindow = vtk.vtkRenderWindow() - # renderWindow.SetWindowName("Test") + renderWindow.SetWindowName("Animation") renderWindow.AddRenderer(renderer) renderWindowInteractor = vtk.vtkRenderWindowInteractor() @@ -39,23 +56,23 @@ def main(): # Add the actor to the scene renderer.AddActor(actor) - renderer.SetBackground(1, 1, 1) # Background color white # Render and interact renderWindow.Render() + renderer.GetActiveCamera().Zoom(.8) + renderWindow.Render() # Initialize must be called prior to creating timer events. renderWindowInteractor.Initialize() # Sign up to receive TimerEvent - cb = vtkTimerCallback() - cb.actor = actor + cb = vtkTimerCallback(200, actor, renderWindowInteractor) renderWindowInteractor.AddObserver('TimerEvent', cb.execute) - renderWindowInteractor.CreateRepeatingTimer(100) + cb.timerId = renderWindowInteractor.CreateRepeatingTimer(500) # start the interaction and timer + renderWindow.Render() renderWindowInteractor.Start() - if __name__ == '__main__': main() diff --git a/src/Python/Utilities/Screenshot.py b/src/Python/Utilities/Screenshot.py index 20cb54b095aa0ed71c474f02671515d8678eea42..e445f41d103e32f890fdc4821eafff5c3a5c3ef9 100755 --- a/src/Python/Utilities/Screenshot.py +++ b/src/Python/Utilities/Screenshot.py @@ -1,45 +1,59 @@ import vtk -# create a rendering window and renderer -ren = vtk.vtkRenderer() -renWin = vtk.vtkRenderWindow() -renWin.AddRenderer(ren) +def main(): + colors = vtk.vtkNamedColors() -# create a renderwindowinteractor -iren = vtk.vtkRenderWindowInteractor() -iren.SetRenderWindow(renWin) + # create a rendering window and renderer + ren = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() + renWin.AddRenderer(ren) -# create source -source = vtk.vtkSphereSource() -source.SetCenter(0, 0, 0) -source.SetRadius(5.0) + # create a renderwindowinteractor + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) -# mapper -mapper = vtk.vtkPolyDataMapper() -mapper.SetInputConnection(source.GetOutputPort()) + # create source + source = vtk.vtkSphereSource() + source.SetCenter(0, 0, 0) + source.SetRadius(5.0) + source.SetPhiResolution(30) + source.SetThetaResolution(30) -# actor -actor = vtk.vtkActor() -actor.SetMapper(mapper) -# color the actor -actor.GetProperty().SetColor(1, 0, 0) # (R,G,B) + # mapper + mapper = vtk.vtkPolyDataMapper() + mapper.SetInputConnection(source.GetOutputPort()) -# assign actor to the renderer -ren.AddActor(actor) + # actor + actor = vtk.vtkActor() + actor.GetProperty().SetColor(colors.GetColor3d("IndianRed")) + actor.GetProperty().SetSpecular(0.6) + actor.GetProperty().SetSpecularPower(30) + actor.SetMapper(mapper) -renWin.Render() + # assign actor to the renderer + ren.AddActor(actor) + ren.SetBackground(colors.GetColor3d("MistyRose")) -# screenshot code: -w2if = vtk.vtkWindowToImageFilter() -w2if.SetInput(renWin) -w2if.Update() -writer = vtk.vtkPNGWriter() -writer.SetFileName("screenshot.png") -writer.SetInputConnection(w2if.GetOutputPort()) -writer.Write() + renWin.Render() -# enable user interface interactor -iren.Initialize() -iren.Start() + # screenshot code: + w2if = vtk.vtkWindowToImageFilter() + w2if.SetInput(renWin) + w2if.SetInputBufferTypeToRGB() + w2if.ReadFrontBufferOff() + w2if.Update() + + writer = vtk.vtkPNGWriter() + writer.SetFileName("TestScreenshot.png") + writer.SetInputConnection(w2if.GetOutputPort()) + writer.Write() + + # enable user interface interactor + iren.Initialize() + iren.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Utilities/VTKWithNumpy.py b/src/Python/Utilities/VTKWithNumpy.py index f00591a0981e0087ab170b707582d4a89c2b603a..d8195efc15b0a1cc177492d6cdf7034e2991db4a 100755 --- a/src/Python/Utilities/VTKWithNumpy.py +++ b/src/Python/Utilities/VTKWithNumpy.py @@ -1,101 +1,102 @@ -# An example from scipy cookbook demonstrating the use of numpy arrys in vtk +# An example from scipy cookbook demonstrating the use of numpy arrays in vtk -import vtk import numpy as np +import vtk + + +def main(): + colors = vtk.vtkNamedColors() + + # We begin by creating the data we want to render. + # For this tutorial, we create a 3D-image containing three overlaping cubes. + # This data can of course easily be replaced by data from a medical CT-scan or anything else three dimensional. + # The only limit is that the data must be reduced to unsigned 8 bit or 16 bit integers. + data_matrix = np.zeros([75, 75, 75], dtype=np.uint8) + data_matrix[0:35, 0:35, 0:35] = 50 + data_matrix[25:55, 25:55, 25:55] = 100 + data_matrix[45:74, 45:74, 45:74] = 150 + + # For VTK to be able to use the data, it must be stored as a VTK-image. + # This can be done by the vtkImageImport-class which + # imports raw data and stores it. + dataImporter = vtk.vtkImageImport() + # The previously created array is converted to a string of chars and imported. + data_string = data_matrix.tostring() + dataImporter.CopyImportVoidPointer(data_string, len(data_string)) + # The type of the newly imported data is set to unsigned char (uint8) + dataImporter.SetDataScalarTypeToUnsignedChar() + # Because the data that is imported only contains an intensity value + # (it isnt RGB-coded or someting similar), the importer must be told this is the case. + dataImporter.SetNumberOfScalarComponents(1) + # The following two functions describe how the data is stored and the dimensions of the array it is stored in. + # For this simple case, all axes are of length 75 and begins with the first element. + # For other data, this is probably not the case. + # I have to admit however, that I honestly dont know the difference between SetDataExtent() + # and SetWholeExtent() although VTK complains if not both are used. + dataImporter.SetDataExtent(0, 74, 0, 74, 0, 74) + dataImporter.SetWholeExtent(0, 74, 0, 74, 0, 74) + + # The following class is used to store transparency-values for later retrival. + # In our case, we want the value 0 to be + # completely opaque whereas the three different cubes are given different transparency-values to show how it works. + alphaChannelFunc = vtk.vtkPiecewiseFunction() + alphaChannelFunc.AddPoint(0, 0.0) + alphaChannelFunc.AddPoint(50, 0.05) + alphaChannelFunc.AddPoint(100, 0.1) + alphaChannelFunc.AddPoint(150, 0.2) + + # This class stores color data and can create color tables from a few color points. + # For this demo, we want the three cubes to be of the colors red green and blue. + colorFunc = vtk.vtkColorTransferFunction() + colorFunc.AddRGBPoint(50, 1.0, 0.0, 0.0) + colorFunc.AddRGBPoint(100, 0.0, 1.0, 0.0) + colorFunc.AddRGBPoint(150, 0.0, 0.0, 1.0) + + # The previous two classes stored properties. + # Because we want to apply these properties to the volume we want to render, + # we have to store them in a class that stores volume properties. + volumeProperty = vtk.vtkVolumeProperty() + volumeProperty.SetColor(colorFunc) + volumeProperty.SetScalarOpacity(alphaChannelFunc) + + volumeMapper = vtk.vtkFixedPointVolumeRayCastMapper() + volumeMapper.SetInputConnection(dataImporter.GetOutputPort()) + + # The class vtkVolume is used to pair the previously declared volume as well as the properties + # to be used when rendering that volume. + volume = vtk.vtkVolume() + volume.SetMapper(volumeMapper) + volume.SetProperty(volumeProperty) + + # With almost everything else ready, its time to initialize the renderer and window, as well as + # creating a method for exiting the application + renderer = vtk.vtkRenderer() + renderWin = vtk.vtkRenderWindow() + renderWin.AddRenderer(renderer) + renderInteractor = vtk.vtkRenderWindowInteractor() + renderInteractor.SetRenderWindow(renderWin) + + # We add the volume to the renderer ... + renderer.AddVolume(volume) + renderer.SetBackground(colors.GetColor3d("MistyRose")) + + # ... and set window size. + renderWin.SetSize(400, 400) + + # A simple function to be called when the user decides to quit the application. + def exitCheck(obj, event): + if obj.GetEventPending() != 0: + obj.SetAbortRender(1) + + # Tell the application to use the function as an exit check. + renderWin.AddObserver("AbortCheckEvent", exitCheck) + + renderInteractor.Initialize() + # Because nothing will be rendered without any input, we order the first render manually + # before control is handed over to the main-loop. + renderWin.Render() + renderInteractor.Start() + -# We begin by creating the data we want to render. -# For this tutorial, we create a 3D-image containing three overlaping cubes. -# This data can of course easily be replaced by data from a medical CT-scan or anything else three dimensional. -# The only limit is that the data must be reduced to unsigned 8 bit or 16 bit integers. -data_matrix = np.zeros([75, 75, 75], dtype=np.uint8) -data_matrix[0:35, 0:35, 0:35] = 50 -data_matrix[25:55, 25:55, 25:55] = 100 -data_matrix[45:74, 45:74, 45:74] = 150 - -# For VTK to be able to use the data, it must be stored as a VTK-image. -# This can be done by the vtkImageImport-class which -# imports raw data and stores it. -dataImporter = vtk.vtkImageImport() -# The previously created array is converted to a string of chars and imported. -data_string = data_matrix.tostring() -dataImporter.CopyImportVoidPointer(data_string, len(data_string)) -# The type of the newly imported data is set to unsigned char (uint8) -dataImporter.SetDataScalarTypeToUnsignedChar() -# Because the data that is imported only contains an intensity value -# (it isnt RGB-coded or someting similar), the importer must be told this is the case. -dataImporter.SetNumberOfScalarComponents(1) -# The following two functions describe how the data is stored and the dimensions of the array it is stored in. -# For this simple case, all axes are of length 75 and begins with the first element. -# For other data, this is probably not the case. -# I have to admit however, that I honestly dont know the difference between SetDataExtent() -# and SetWholeExtent() although VTK complains if not both are used. -dataImporter.SetDataExtent(0, 74, 0, 74, 0, 74) -dataImporter.SetWholeExtent(0, 74, 0, 74, 0, 74) - -# The following class is used to store transparencyv-values for later retrival. -# In our case, we want the value 0 to be -# completly opaque whereas the three different cubes are given different transparency-values to show how it works. -alphaChannelFunc = vtk.vtkPiecewiseFunction() -alphaChannelFunc.AddPoint(0, 0.0) -alphaChannelFunc.AddPoint(50, 0.05) -alphaChannelFunc.AddPoint(100, 0.1) -alphaChannelFunc.AddPoint(150, 0.2) - -# This class stores color data and can create color tables from a few color points. -# For this demo, we want the three cubes to be of the colors red green and blue. -colorFunc = vtk.vtkColorTransferFunction() -colorFunc.AddRGBPoint(50, 1.0, 0.0, 0.0) -colorFunc.AddRGBPoint(100, 0.0, 1.0, 0.0) -colorFunc.AddRGBPoint(150, 0.0, 0.0, 1.0) - -# The previous two classes stored properties. -# Because we want to apply these properties to the volume we want to render, -# we have to store them in a class that stores volume prpoperties. -volumeProperty = vtk.vtkVolumeProperty() -volumeProperty.SetColor(colorFunc) -volumeProperty.SetScalarOpacity(alphaChannelFunc) - -# This class describes how the volume is rendered (through ray tracing). -compositeFunction = vtk.vtkVolumeRayCastCompositeFunction() -# We can finally create our volume. We also have to specify the data for it, -# as well as how the data will be rendered. -volumeMapper = vtk.vtkVolumeRayCastMapper() -volumeMapper.SetVolumeRayCastFunction(compositeFunction) -volumeMapper.SetInputConnection(dataImporter.GetOutputPort()) - -# The class vtkVolume is used to pair the previously declared volume as well as the properties -# to be used when rendering that volume. -volume = vtk.vtkVolume() -volume.SetMapper(volumeMapper) -volume.SetProperty(volumeProperty) - -# With almost everything else ready, its time to initialize the renderer and window, as well as -# creating a method for exiting the application -renderer = vtk.vtkRenderer() -renderWin = vtk.vtkRenderWindow() -renderWin.AddRenderer(renderer) -renderInteractor = vtk.vtkRenderWindowInteractor() -renderInteractor.SetRenderWindow(renderWin) - -# We add the volume to the renderer ... -renderer.AddVolume(volume) -# ... set background color to white ... -renderer.SetBackground(0, 0, 0) -# ... and set window size. -renderWin.SetSize(400, 400) - - -# A simple function to be called when the user decides to quit the application. -def exitCheck(obj, event): - if obj.GetEventPending() != 0: - obj.SetAbortRender(1) - - -# Tell the application to use the function as an exit check. -renderWin.AddObserver("AbortCheckEvent", exitCheck) - -renderInteractor.Initialize() -# Because nothing will be rendered without any input, we order the first render manually -# before control is handed over to the main-loop. -renderWin.Render() -renderInteractor.Start() +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/Camera.py b/src/Python/Visualization/Camera.py index 48b09f957448065b00ca8c2a1ca09ebf322ec70a..8f5f38bf9c7407deabb38fdf6b4a5c4de29d1acf 100755 --- a/src/Python/Visualization/Camera.py +++ b/src/Python/Visualization/Camera.py @@ -1,36 +1,49 @@ import vtk -# Create a sphere -sphereSource = vtk.vtkSphereSource() -sphereSource.SetCenter(0.0, 0.0, 0.0) -sphereSource.SetRadius(10) -sphereSource.Update() - -# Create a mapper and actor -mapper = vtk.vtk.vtkPolyDataMapper() -mapper.SetInputConnection(sphereSource.GetOutputPort()) - -actor = vtk.vtkActor() -actor.SetMapper(mapper) - -camera = vtk.vtkCamera() -camera.SetPosition(0, 0, 100) -camera.SetFocalPoint(0, 0, 0) - -# Create a renderer, render window, and interactor -renderer = vtk.vtkRenderer() -renderer.SetActiveCamera(camera) - -renderWindow = vtk.vtkRenderWindow() -renderWindow.AddRenderer(renderer) -renderWindowInteractor = vtk.vtkRenderWindowInteractor() -renderWindowInteractor.SetRenderWindow(renderWindow) - -# Add the actor to the scene -renderer.AddActor(actor) -renderer.SetBackground(1, 1, 1) # Background color white - -# Render and interact -renderWindow.Render() -renderWindowInteractor.Start() +def main(): + colors = vtk.vtkNamedColors() + + # Create a sphere + sphereSource = vtk.vtkSphereSource() + sphereSource.SetCenter(0.0, 0.0, 0.0) + sphereSource.SetRadius(10) + sphereSource.SetPhiResolution(30) + sphereSource.SetThetaResolution(30) + sphereSource.Update() + + # Create a mapper and actor + mapper = vtk.vtkPolyDataMapper() + mapper.SetInputConnection(sphereSource.GetOutputPort()) + + actor = vtk.vtkActor() + actor.SetMapper(mapper) + actor.GetProperty().SetSpecular(0.6) + actor.GetProperty().SetSpecularPower(30) + actor.GetProperty().SetColor(colors.GetColor3d("LightSkyBlue")) + + camera = vtk.vtkCamera() + camera.SetPosition(0, 0, 100) + camera.SetFocalPoint(0, 0, 0) + + # Create a renderer, render window, and interactor + renderer = vtk.vtkRenderer() + renderer.SetActiveCamera(camera) + + renderWindow = vtk.vtkRenderWindow() + renderWindow.AddRenderer(renderer) + renderWindowInteractor = vtk.vtkRenderWindowInteractor() + renderWindowInteractor.SetRenderWindow(renderWindow) + + # Add the actor to the scene + renderer.AddActor(actor) + renderer.SetBackground(colors.GetColor3d("MistyRose")) + + # Render and interact + renderWindowInteractor.Initialize() + renderWindow.Render() + renderWindowInteractor.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/ClampGlyphSizes.py b/src/Python/Visualization/ClampGlyphSizes.py index 41de23fc91c0c1f77b1d5d7f290414c3550b2e28..959c41e31351b769b8e9f6675cc5a2274665f150 100755 --- a/src/Python/Visualization/ClampGlyphSizes.py +++ b/src/Python/Visualization/ClampGlyphSizes.py @@ -16,83 +16,91 @@ import vtk -# Generate an image data set with multiple attribute arrays to probe and view -# We will glyph these points with cones and scale/orient/color them with the -# various attributes - -# The Wavelet Source is nice for generating a test vtkImageData set -rt = vtk.vtkRTAnalyticSource() -rt.SetWholeExtent(-2, 2, -2, 2, 0, 0) - -# Take the gradient of the only scalar 'RTData' to get a vector attribute -grad = vtk.vtkImageGradient() -grad.SetDimensionality(3) -grad.SetInputConnection(rt.GetOutputPort()) - -# Elevation just to generate another scalar attribute that varies nicely over the data range -elev = vtk.vtkElevationFilter() -# Elevation values will range from 0 to 1 between the Low and High Points -elev.SetLowPoint(-2, 0, 0) -elev.SetHighPoint(2, 0, 0) -elev.SetInputConnection(grad.GetOutputPort()) - -# Generate the cone for the glyphs -sph = vtk.vtkConeSource() -sph.SetRadius(0.1) -sph.SetHeight(0.5) - -# Set up the glyph filter -glyph = vtk.vtkGlyph3D() -glyph.SetInputConnection(elev.GetOutputPort()) -glyph.SetSourceConnection(sph.GetOutputPort()) -glyph.ScalingOn() -glyph.SetScaleModeToScaleByScalar() -glyph.SetVectorModeToUseVector() -glyph.OrientOn() - -# Tell the filter to "clamp" the scalar range -glyph.ClampingOn() - -# Set the overall (multiplicative) scaling factor -glyph.SetScaleFactor(1) - -# Set the Range to "clamp" the data to -# -- see equations above for nonintuitive definition of "clamping" -# The fact that I'm setting the minimum value of the range below -# the minimum of my data (real min=0.0) with the equations above -# forces a minimum non-zero glyph size. - -glyph.SetRange(-0.5, 1) # Change these values to see effect on cone sizes - -# Tell glyph which attribute arrays to use for what -glyph.SetInputArrayToProcess(0, 0, 0, 0, 'Elevation') # scalars -glyph.SetInputArrayToProcess(1, 0, 0, 0, 'RTDataGradient') # vectors -# glyph.SetInputArrayToProcess(2,0,0,0,'nothing') # normals -glyph.SetInputArrayToProcess(3, 0, 0, 0, 'RTData') # colors - -# Calling update because I'm going to use the scalar range to set the color map range -glyph.Update() - -coloring_by = 'RTData' -mapper = vtk.vtkPolyDataMapper() -mapper.SetInputConnection(glyph.GetOutputPort()) -mapper.SetScalarModeToUsePointFieldData() -mapper.SetColorModeToMapScalars() -mapper.ScalarVisibilityOn() -mapper.SetScalarRange(glyph.GetOutputDataObject(0).GetPointData().GetArray(coloring_by).GetRange()) -mapper.SelectColorArray(coloring_by) -actor = vtk.vtkActor() -actor.SetMapper(mapper) - -ren = vtk.vtkRenderer() -ren.AddActor(actor) -renWin = vtk.vtkRenderWindow() -renWin.AddRenderer(ren) -iren = vtk.vtkRenderWindowInteractor() -istyle = vtk.vtkInteractorStyleTrackballCamera() -iren.SetInteractorStyle(istyle) -iren.SetRenderWindow(renWin) -ren.ResetCamera() -renWin.Render() - -iren.Start() + +def main(): + colors = vtk.vtkNamedColors() + + # Generate an image data set with multiple attribute arrays to probe and view + # We will glyph these points with cones and scale/orient/color them with the + # various attributes + + # The Wavelet Source is nice for generating a test vtkImageData set + rt = vtk.vtkRTAnalyticSource() + rt.SetWholeExtent(-2, 2, -2, 2, 0, 0) + + # Take the gradient of the only scalar 'RTData' to get a vector attribute + grad = vtk.vtkImageGradient() + grad.SetDimensionality(3) + grad.SetInputConnection(rt.GetOutputPort()) + + # Elevation just to generate another scalar attribute that varies nicely over the data range + elev = vtk.vtkElevationFilter() + # Elevation values will range from 0 to 1 between the Low and High Points + elev.SetLowPoint(-2, 0, 0) + elev.SetHighPoint(2, 0, 0) + elev.SetInputConnection(grad.GetOutputPort()) + + # Generate the cone for the glyphs + sph = vtk.vtkConeSource() + sph.SetRadius(0.1) + sph.SetHeight(0.5) + + # Set up the glyph filter + glyph = vtk.vtkGlyph3D() + glyph.SetInputConnection(elev.GetOutputPort()) + glyph.SetSourceConnection(sph.GetOutputPort()) + glyph.ScalingOn() + glyph.SetScaleModeToScaleByScalar() + glyph.SetVectorModeToUseVector() + glyph.OrientOn() + + # Tell the filter to "clamp" the scalar range + glyph.ClampingOn() + + # Set the overall (multiplicative) scaling factor + glyph.SetScaleFactor(1) + + # Set the Range to "clamp" the data to + # -- see equations above for nonintuitive definition of "clamping" + # The fact that I'm setting the minimum value of the range below + # the minimum of my data (real min=0.0) with the equations above + # forces a minimum non-zero glyph size. + + glyph.SetRange(-0.5, 1) # Change these values to see effect on cone sizes + + # Tell glyph which attribute arrays to use for what + glyph.SetInputArrayToProcess(0, 0, 0, 0, 'Elevation') # scalars + glyph.SetInputArrayToProcess(1, 0, 0, 0, 'RTDataGradient') # vectors + # glyph.SetInputArrayToProcess(2,0,0,0,'nothing') # normals + glyph.SetInputArrayToProcess(3, 0, 0, 0, 'RTData') # colors + + # Calling update because I'm going to use the scalar range to set the color map range + glyph.Update() + + coloring_by = 'RTData' + mapper = vtk.vtkPolyDataMapper() + mapper.SetInputConnection(glyph.GetOutputPort()) + mapper.SetScalarModeToUsePointFieldData() + mapper.SetColorModeToMapScalars() + mapper.ScalarVisibilityOn() + mapper.SetScalarRange(glyph.GetOutputDataObject(0).GetPointData().GetArray(coloring_by).GetRange()) + mapper.SelectColorArray(coloring_by) + actor = vtk.vtkActor() + actor.SetMapper(mapper) + + ren = vtk.vtkRenderer() + ren.AddActor(actor) + ren.SetBackground(colors.GetColor3d("MidnightBlue")) + renWin = vtk.vtkRenderWindow() + renWin.AddRenderer(ren) + iren = vtk.vtkRenderWindowInteractor() + istyle = vtk.vtkInteractorStyleTrackballCamera() + iren.SetInteractorStyle(istyle) + iren.SetRenderWindow(renWin) + ren.ResetCamera() + renWin.Render() + iren.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/ColorActor.py b/src/Python/Visualization/ColorActor.py index 2a5fbd294294179681c3c9e023e0f5dde325b88f..74d9312dd3aaa2b2074e957abfef3c9201496551 100755 --- a/src/Python/Visualization/ColorActor.py +++ b/src/Python/Visualization/ColorActor.py @@ -1,34 +1,41 @@ import vtk -# create a rendering window and renderer -ren = vtk.vtkRenderer() -renWin = vtk.vtkRenderWindow() -renWin.AddRenderer(ren) - -# create a renderwindowinteractor -iren = vtk.vtkRenderWindowInteractor() -iren.SetRenderWindow(renWin) - -# create source -source = vtk.vtkSphereSource() -source.SetCenter(0, 0, 0) -source.SetRadius(5.0) - -# mapper -mapper = vtk.vtkPolyDataMapper() -mapper.SetInputConnection(source.GetOutputPort()) - -# actor -actor = vtk.vtkActor() -actor.SetMapper(mapper) - -# color the actor -actor.GetProperty().SetColor(1, 0, 0) # (R,G,B) - -# assign actor to the renderer -ren.AddActor(actor) - -# enable user interface interactor -iren.Initialize() -renWin.Render() -iren.Start() + +def main(): + colors = vtk.vtkNamedColors() + + # create a rendering window and renderer + ren = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() + renWin.AddRenderer(ren) + + # create a renderwindowinteractor + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) + + # create source + source = vtk.vtkSphereSource() + source.SetCenter(0, 0, 0) + source.SetRadius(5.0) + + # mapper + mapper = vtk.vtkPolyDataMapper() + mapper.SetInputConnection(source.GetOutputPort()) + + # actor + actor = vtk.vtkActor() + actor.SetMapper(mapper) + actor.GetProperty().SetColor(colors.GetColor3d('Bisque')) + + # assign actor to the renderer + ren.AddActor(actor) + ren.SetBackground(colors.GetColor3d('Navy')) + + # enable user interface interactor + iren.Initialize() + renWin.Render() + iren.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/CubeAxesActor.py b/src/Python/Visualization/CubeAxesActor.py index dd61add458c89a8cb95e03ff8defbabeaed47227..e72c0e5be0db51874f41901f1d6f6439d7083c83 100755 --- a/src/Python/Visualization/CubeAxesActor.py +++ b/src/Python/Visualization/CubeAxesActor.py @@ -5,6 +5,7 @@ import vtk def main(): colors = vtk.vtkNamedColors() + # Create a superquadric superquadricSource = vtk.vtkSuperquadricSource() superquadricSource.SetPhiRoundness(3.1) diff --git a/src/Python/Visualization/GlyphTable.py b/src/Python/Visualization/GlyphTable.py index 635316286cc8507b460b9d355ac97b4c856c2f11..edac91a3915374fae7c84b967382e0a64efa58b7 100755 --- a/src/Python/Visualization/GlyphTable.py +++ b/src/Python/Visualization/GlyphTable.py @@ -1,89 +1,93 @@ import vtk + # This example uses a "glyph table" to change the shape of the 3d glyphs # according to a scalar value. # NOTE: The vtkGlyph3D filter doesn't copy over scalars to the glyphs # generated by a table like this for some reason... -# The Wavelet Source is nice for generating a test vtkImageData set -rt = vtk.vtkRTAnalyticSource() -rt.SetWholeExtent(-2, 2, -2, 2, 0, 0) - -# Take the gradient of the only scalar 'RTData' to get a vector attribute -grad = vtk.vtkImageGradient() -grad.SetDimensionality(3) -grad.SetInputConnection(rt.GetOutputPort()) - -# Elevation just to generate another scalar attribute that varies nicely over the data range -elev = vtk.vtkElevationFilter() -# Elevation values will range from 0 to 1 between the Low and High Points -elev.SetLowPoint(-2, -2, 0) -elev.SetHighPoint(2, 2, 0) -elev.SetInputConnection(grad.GetOutputPort()) - -# Create simple PolyData for glyph table -cs = vtk.vtkCubeSource() -cs.SetXLength(0.5) -cs.SetYLength(1) -cs.SetZLength(2) -ss = vtk.vtkSphereSource() -ss.SetRadius(0.25) -cs2 = vtk.vtkConeSource() -cs2.SetRadius(0.25) -cs2.SetHeight(0.5) - -# Set up the glyph filter -glyph = vtk.vtkGlyph3D() -glyph.SetInputConnection(elev.GetOutputPort()) - -# Here is where we build the glyph table -# that will be indexed into according to the IndexMode -glyph.SetSourceConnection(0, cs.GetOutputPort()) -glyph.SetSourceConnection(1, ss.GetOutputPort()) -glyph.SetSourceConnection(2, cs2.GetOutputPort()) - -glyph.ScalingOn() -glyph.SetScaleModeToScaleByScalar() -glyph.SetVectorModeToUseVector() -glyph.OrientOn() -glyph.SetScaleFactor(1) # Overall scaling factor -glyph.SetRange(0, 1) # Default is (0,1) - -# Tell it to index into the glyph table according to scalars -glyph.SetIndexModeToScalar() - -# Tell glyph which attribute arrays to use for what -glyph.SetInputArrayToProcess(0, 0, 0, 0, 'Elevation') # scalars -glyph.SetInputArrayToProcess(1, 0, 0, 0, 'RTDataGradient') # vectors - -# I would call Update if I could use the scalar range to set the color map range -# glyph.Update() - -coloring_by = 'RTData' -mapper = vtk.vtkPolyDataMapper() -mapper.SetInputConnection(glyph.GetOutputPort()) -mapper.SetScalarModeToUsePointFieldData() -mapper.SetColorModeToMapScalars() -mapper.ScalarVisibilityOn() - -# GetRange() call doesn't work because attributes weren't copied to glyphs -# as they should have been... -# mapper.SetScalarRange(glyph.GetOutputDataObject(0).GetPointData().GetArray(coloring_by).GetRange()) - -mapper.SelectColorArray(coloring_by) -actor = vtk.vtkActor() -actor.SetMapper(mapper) - -ren = vtk.vtkRenderer() -ren.AddActor(actor) -renWin = vtk.vtkRenderWindow() -renWin.AddRenderer(ren) -iren = vtk.vtkRenderWindowInteractor() -istyle = vtk.vtkInteractorStyleTrackballCamera() -iren.SetInteractorStyle(istyle) -iren.SetRenderWindow(renWin) -ren.ResetCamera() -renWin.Render() - -iren.Start() +def main(): + colors = vtk.vtkNamedColors() + + # The Wavelet Source is nice for generating a test vtkImageData set + rt = vtk.vtkRTAnalyticSource() + rt.SetWholeExtent(-2, 2, -2, 2, 0, 0) + + # Take the gradient of the only scalar 'RTData' to get a vector attribute + grad = vtk.vtkImageGradient() + grad.SetDimensionality(3) + grad.SetInputConnection(rt.GetOutputPort()) + + # Elevation just to generate another scalar attribute that varies nicely over the data range + elev = vtk.vtkElevationFilter() + # Elevation values will range from 0 to 1 between the Low and High Points + elev.SetLowPoint(-2, -2, 0) + elev.SetHighPoint(2, 2, 0) + elev.SetInputConnection(grad.GetOutputPort()) + + # Create simple PolyData for glyph table + cs = vtk.vtkCubeSource() + cs.SetXLength(0.5) + cs.SetYLength(1) + cs.SetZLength(2) + ss = vtk.vtkSphereSource() + ss.SetRadius(0.25) + cs2 = vtk.vtkConeSource() + cs2.SetRadius(0.25) + cs2.SetHeight(0.5) + + # Set up the glyph filter + glyph = vtk.vtkGlyph3D() + glyph.SetInputConnection(elev.GetOutputPort()) + + # Here is where we build the glyph table + # that will be indexed into according to the IndexMode + glyph.SetSourceConnection(0, cs.GetOutputPort()) + glyph.SetSourceConnection(1, ss.GetOutputPort()) + glyph.SetSourceConnection(2, cs2.GetOutputPort()) + + glyph.ScalingOn() + glyph.SetScaleModeToScaleByScalar() + glyph.SetVectorModeToUseVector() + glyph.OrientOn() + glyph.SetScaleFactor(1) # Overall scaling factor + glyph.SetRange(0, 1) # Default is (0,1) + + # Tell it to index into the glyph table according to scalars + glyph.SetIndexModeToScalar() + + # Tell glyph which attribute arrays to use for what + glyph.SetInputArrayToProcess(0, 0, 0, 0, 'Elevation') # scalars + glyph.SetInputArrayToProcess(1, 0, 0, 0, 'RTDataGradient') # vectors + + coloring_by = 'Elevation' + mapper = vtk.vtkPolyDataMapper() + mapper.SetInputConnection(glyph.GetOutputPort()) + mapper.SetScalarModeToUsePointFieldData() + mapper.SetColorModeToMapScalars() + mapper.ScalarVisibilityOn() + + # GetRange() call doesn't work because attributes weren't copied to glyphs + # as they should have been... + # mapper.SetScalarRange(glyph.GetOutputDataObject(0).GetPointData().GetArray(coloring_by).GetRange()) + + mapper.SelectColorArray(coloring_by) + actor = vtk.vtkActor() + actor.SetMapper(mapper) + + ren = vtk.vtkRenderer() + ren.AddActor(actor) + renWin = vtk.vtkRenderWindow() + renWin.AddRenderer(ren) + iren = vtk.vtkRenderWindowInteractor() + istyle = vtk.vtkInteractorStyleTrackballCamera() + iren.SetInteractorStyle(istyle) + iren.SetRenderWindow(renWin) + ren.ResetCamera() + renWin.Render() + iren.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/HardwareSelector.py b/src/Python/Visualization/HardwareSelector.py index 6a40b53b585654ffdb4ccc3aab456b5891396383..44726047a04445059e416c24a58d692bed6be6ff 100755 --- a/src/Python/Visualization/HardwareSelector.py +++ b/src/Python/Visualization/HardwareSelector.py @@ -1,9 +1,13 @@ from __future__ import print_function + import vtk import vtk.util.numpy_support as VN # Callback for when selection is changed +# This is global - fix later. +ren1 = vtk.vtkRenderer() + def selectionCallback(caller, eventId): hsel = vtk.vtkHardwareSelector() @@ -24,35 +28,43 @@ def selectionCallback(caller, eventId): print('Visible cell IDs: ', VN.vtk_to_numpy(sel_node.GetSelectionList()).tolist()) -sphere = vtk.vtkSphereSource() -sphere.SetCenter(0, 0, 0) -sphere.SetRadius(5.0) +def main(): + colors = vtk.vtkNamedColors() -sphereMapper = vtk.vtkPolyDataMapper() -sphereMapper.SetInputConnection(sphere.GetOutputPort()) + sphere = vtk.vtkSphereSource() + sphere.SetCenter(0, 0, 0) + sphere.SetRadius(5.0) -sphereActor = vtk.vtkActor() -sphereActor.SetMapper(sphereMapper) + sphereMapper = vtk.vtkPolyDataMapper() + sphereMapper.SetInputConnection(sphere.GetOutputPort()) -ren1 = vtk.vtkRenderer() -ren1.AddActor(sphereActor) -ren1.SetBackground(0.1, 0.2, 0.4) -ren1.GetActiveCamera().ParallelProjectionOn() + sphereActor = vtk.vtkActor() + sphereActor.SetMapper(sphereMapper) + sphereActor.GetProperty().SetColor(colors.GetColor3d('Bisque')) + + ren1.AddActor(sphereActor) + ren1.SetBackground(0.1, 0.2, 0.4) + ren1.GetActiveCamera().ParallelProjectionOn() + ren1.SetBackground(colors.GetColor3d('Navy')) + + renWin = vtk.vtkRenderWindow() + renWin.AddRenderer(ren1) + renWin.SetSize(300, 300) + + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) + iren.AddObserver("UserEvent", selectionCallback) -renWin = vtk.vtkRenderWindow() -renWin.AddRenderer(ren1) -renWin.SetSize(300, 300) + style = vtk.vtkInteractorStyleTrackballCamera() + iren.SetInteractorStyle(style) + renWin.GetInteractor().SetInteractorStyle(style) -iren = vtk.vtkRenderWindowInteractor() -iren.SetRenderWindow(renWin) -iren.AddObserver("UserEvent", selectionCallback) + ren1.ResetCamera() + renWin.Render() -style = vtk.vtkInteractorStyleTrackballCamera() -iren.SetInteractorStyle(style) -renWin.GetInteractor().SetInteractorStyle(style) + iren.Initialize() + iren.Start() -ren1.ResetCamera() -renWin.Render() -iren.Initialize() -iren.Start() +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/InteractorStyleTrackballActor.py b/src/Python/Visualization/InteractorStyleTrackballActor.py index 947cdf6a83e6e8e27a4b43a27e614536c4ca0a20..b7e2c96f6b379b79735c413196ab886f2910612b 100755 --- a/src/Python/Visualization/InteractorStyleTrackballActor.py +++ b/src/Python/Visualization/InteractorStyleTrackballActor.py @@ -1,33 +1,42 @@ import vtk -# create a rendering window and renderer -ren = vtk.vtkRenderer() -renWin = vtk.vtkRenderWindow() -renWin.AddRenderer(ren) -# create a renderwindowinteractor -iren = vtk.vtkRenderWindowInteractor() -iren.SetRenderWindow(renWin) +def main(): + colors = vtk.vtkNamedColors() -style = vtk.vtkInteractorStyleTrackballActor() -iren.SetInteractorStyle(style) + # create a rendering window and renderer + ren = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() + renWin.AddRenderer(ren) -# create source -sphereSource = vtk.vtkSphereSource() -sphereSource.Update() + # create a renderwindowinteractor + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) -# mapper -mapper = vtk.vtkPolyDataMapper() -mapper.SetInputConnection(sphereSource.GetOutputPort()) + style = vtk.vtkInteractorStyleTrackballActor() + iren.SetInteractorStyle(style) -# actor -actor = vtk.vtkActor() -actor.SetMapper(mapper) + # create source + sphereSource = vtk.vtkSphereSource() -# assign actor to the renderer -ren.AddActor(actor) + # mapper + mapper = vtk.vtkPolyDataMapper() + mapper.SetInputConnection(sphereSource.GetOutputPort()) -# enable user interface interactor -iren.Initialize() -renWin.Render() -iren.Start() + # actor + actor = vtk.vtkActor() + actor.SetMapper(mapper) + actor.GetProperty().SetColor(colors.GetColor3d('Chartreuse')) + + # assign actor to the renderer + ren.AddActor(actor) + ren.SetBackground(colors.GetColor3d('PaleGoldenrod')) + + # enable user interface interactor + iren.Initialize() + renWin.Render() + iren.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/InteractorStyleTrackballCamera.py b/src/Python/Visualization/InteractorStyleTrackballCamera.py index 826e3d4974e83250bfa421283f251a5fa7a2af48..ccf14a54ca8bcbaa7fa1c6e1f6f81be8e09f7969 100755 --- a/src/Python/Visualization/InteractorStyleTrackballCamera.py +++ b/src/Python/Visualization/InteractorStyleTrackballCamera.py @@ -1,35 +1,46 @@ import vtk -# create a rendering window and renderer -ren = vtk.vtkRenderer() -renWin = vtk.vtkRenderWindow() -renWin.AddRenderer(ren) - -# create a renderwindowinteractor -iren = vtk.vtkRenderWindowInteractor() -iren.SetRenderWindow(renWin) - -style = vtk.vtkInteractorStyleTrackballCamera() -iren.SetInteractorStyle(style) - -# create source -src = vtk.vtkPointSource() -src.SetCenter(0, 0, 0) -src.SetNumberOfPoints(50) -src.SetRadius(5) - -# mapper -mapper = vtk.vtkPolyDataMapper() -mapper.SetInputConnection(src.GetOutputPort()) - -# actor -actor = vtk.vtkActor() -actor.SetMapper(mapper) - -# assign actor to the renderer -ren.AddActor(actor) - -# enable user interface interactor -iren.Initialize() -renWin.Render() -iren.Start() + +def main(): + colors = vtk.vtkNamedColors() + + # create a rendering window and renderer + ren = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() + renWin.AddRenderer(ren) + + # create a renderwindowinteractor + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) + + style = vtk.vtkInteractorStyleTrackballCamera() + iren.SetInteractorStyle(style) + + # create source + src = vtk.vtkPointSource() + src.SetCenter(0, 0, 0) + src.SetNumberOfPoints(50) + src.SetRadius(5) + + # mapper + mapper = vtk.vtkPolyDataMapper() + mapper.SetInputConnection(src.GetOutputPort()) + + # actor + actor = vtk.vtkActor() + actor.SetMapper(mapper) + actor.GetProperty().SetColor(colors.GetColor3d('Yellow')) + actor.GetProperty().SetPointSize(5) + + # assign actor to the renderer + ren.AddActor(actor) + ren.SetBackground(colors.GetColor3d('RoyalBLue')) + + # enable user interface interactor + iren.Initialize() + renWin.Render() + iren.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/MultipleViewports.py b/src/Python/Visualization/MultipleViewports.py index 7452396a16ff38f09d23687ba9a3f3c3707819fd..d011079b347ba82e1c803e25f5d1b839e44bc078 100755 --- a/src/Python/Visualization/MultipleViewports.py +++ b/src/Python/Visualization/MultipleViewports.py @@ -2,6 +2,8 @@ import vtk def main(): + colors = vtk.vtkNamedColors() + '''One render window, multiple viewports''' rw = vtk.vtkRenderWindow() iren = vtk.vtkRenderWindowInteractor() @@ -11,6 +13,9 @@ def main(): xmaxs = [0.5, 1, 0.5, 1] ymins = [0, 0, .5, .5] ymaxs = [0.5, 0.5, 1, 1] + # Have some fun with colors + ren_bkg = ['AliceBlue', 'GhostWhite', 'WhiteSmoke', 'Seashell'] + actor_color = ['Bisque', 'RosyBrown', 'Goldenrod', 'Chocolate'] for i in range(4): ren = vtk.vtkRenderer() rw.AddRenderer(ren) @@ -25,8 +30,11 @@ def main(): mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(sphereSource.GetOutputPort()) actor = vtk.vtkActor() + actor.GetProperty().SetColor(colors.GetColor3d(actor_color[i])) actor.SetMapper(mapper) ren.AddActor(actor) + ren.SetBackground(colors.GetColor3d(ren_bkg[i])) + ren.ResetCamera() rw.Render() diff --git a/src/Python/Visualization/NamedColors.py b/src/Python/Visualization/NamedColors.py index 2d2a3a361c34b068952120981aafa7828edc53a4..7edbbd48bc214130facfebb1bbf39dbd877b3d87 100755 --- a/src/Python/Visualization/NamedColors.py +++ b/src/Python/Visualization/NamedColors.py @@ -122,15 +122,6 @@ def DisplayCone(nc): renderWindow.Render() - fnsave = "TestNamedColorsIntegration.png" - renLgeIm = vtk.vtkRenderLargeImage() - imgWriter = vtk.vtkPNGWriter() - renLgeIm.SetInput(renderer) - renLgeIm.SetMagnification(1) - imgWriter.SetInputConnection(renLgeIm.GetOutputPort()) - imgWriter.SetFileName(fnsave) - # imgWriter.Write() - return renderWindowInteractor @@ -150,10 +141,4 @@ def main(): if __name__ == "__main__": - requiredMajorVersion = 6 - print(vtk.vtkVersion().GetVTKMajorVersion()) - if vtk.vtkVersion().GetVTKMajorVersion() < requiredMajorVersion: - print("You need VTK Version 6 or greater.") - print("The class vtkNamedColors is in VTK version 6 or greater.") - exit(0) main() diff --git a/src/Python/Visualization/OrientedGlyphs.py b/src/Python/Visualization/OrientedGlyphs.py index 912bb3944e0e0f88e4e1bd6546cb0425d51c36fb..6ea4c3f64dac5bf6dd41ca315a149bdecb13b769 100755 --- a/src/Python/Visualization/OrientedGlyphs.py +++ b/src/Python/Visualization/OrientedGlyphs.py @@ -1,35 +1,46 @@ import vtk -sphereSource = vtk.vtkSphereSource() -sphereSource.Update() -input_data = vtk.vtkPolyData() -input_data.ShallowCopy(sphereSource.GetOutput()) +def main(): + colors = vtk.vtkNamedColors() -arrowSource = vtk.vtkArrowSource() + sphereSource = vtk.vtkSphereSource() + sphereSource.Update() -glyph3D = vtk.vtkGlyph3D() -glyph3D.SetSourceConnection(arrowSource.GetOutputPort()) -glyph3D.SetVectorModeToUseNormal() -glyph3D.SetInputData(input_data) -glyph3D.SetScaleFactor(.2) -glyph3D.Update() + input_data = vtk.vtkPolyData() + input_data.ShallowCopy(sphereSource.GetOutput()) -# Visualize -mapper = vtk.vtkPolyDataMapper() -mapper.SetInputConnection(glyph3D.GetOutputPort()) + arrowSource = vtk.vtkArrowSource() -actor = vtk.vtkActor() -actor.SetMapper(mapper) + glyph3D = vtk.vtkGlyph3D() + glyph3D.SetSourceConnection(arrowSource.GetOutputPort()) + glyph3D.SetVectorModeToUseNormal() + glyph3D.SetInputData(input_data) + glyph3D.SetScaleFactor(.2) + glyph3D.Update() -renderer = vtk.vtkRenderer() -renderWindow = vtk.vtkRenderWindow() -renderWindow.AddRenderer(renderer) -renderWindowInteractor = vtk.vtkRenderWindowInteractor() -renderWindowInteractor.SetRenderWindow(renderWindow) + # Visualize + mapper = vtk.vtkPolyDataMapper() + mapper.SetInputConnection(glyph3D.GetOutputPort()) -renderer.AddActor(actor) -renderer.SetBackground(.3, .6, .3) # Background color green + actor = vtk.vtkActor() + actor.SetMapper(mapper) + actor.GetProperty().SetColor(colors.GetColor3d('Yellow')) -renderWindow.Render() -renderWindowInteractor.Start() + renderer = vtk.vtkRenderer() + renderWindow = vtk.vtkRenderWindow() + renderWindow.AddRenderer(renderer) + renderWindowInteractor = vtk.vtkRenderWindowInteractor() + renderWindowInteractor.SetRenderWindow(renderWindow) + + renderer.AddActor(actor) + renderer.SetBackground(colors.GetColor3d('DarkGreen')) + + renderWindow.Render() + renderer.GetActiveCamera().Zoom(1.5) + renderWindow.Render() + renderWindowInteractor.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/PointSize.py b/src/Python/Visualization/PointSize.py index 16397c18ac0f02ea812862d8349c2a90f1adf033..cbdb425c078855bd7cfaae657d4e7b009a8aeb70 100755 --- a/src/Python/Visualization/PointSize.py +++ b/src/Python/Visualization/PointSize.py @@ -1,37 +1,45 @@ import vtk -# create a rendering window and renderer -ren = vtk.vtkRenderer() -renWin = vtk.vtkRenderWindow() -renWin.AddRenderer(ren) -# create a renderwindowinteractor -iren = vtk.vtkRenderWindowInteractor() -iren.SetRenderWindow(renWin) +def main(): + colors = vtk.vtkNamedColors() + # create a rendering window and renderer + ren = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() + renWin.AddRenderer(ren) -# create source -src = vtk.vtkPointSource() -src.SetCenter(0, 0, 0) -src.SetNumberOfPoints(50) -src.SetRadius(5) -src.Update() + # create a renderwindowinteractor + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) + # create source + src = vtk.vtkPointSource() + src.SetCenter(0, 0, 0) + src.SetNumberOfPoints(50) + src.SetRadius(5) + src.Update() -# mapper -mapper = vtk.vtkPolyDataMapper() -mapper.SetInputConnection(src.GetOutputPort()) + # mapper + mapper = vtk.vtkPolyDataMapper() + mapper.SetInputConnection(src.GetOutputPort()) -# actor -actor = vtk.vtkActor() -actor.SetMapper(mapper) + # actor + actor = vtk.vtkActor() + actor.SetMapper(mapper) + actor.GetProperty().SetColor(colors.GetColor3d('Yellow')) -actor.GetProperty().SetPointSize(5) + actor.GetProperty().SetPointSize(5) -# assign actor to the renderer -ren.AddActor(actor) + # assign actor to the renderer + ren.AddActor(actor) + ren.SetBackground(colors.GetColor3d('RoyalBLue')) -# enable user interface interactor -iren.Initialize() -renWin.Render() -iren.Start() + # enable user interface interactor + iren.Initialize() + renWin.Render() + iren.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/QuadraticSurface.py b/src/Python/Visualization/QuadraticSurface.py index ae22f8d7768d9670b470ef060bc69027abc11dc4..eacbf64826d9fd9e4eb76ae7b229757f77b39fa6 100755 --- a/src/Python/Visualization/QuadraticSurface.py +++ b/src/Python/Visualization/QuadraticSurface.py @@ -101,6 +101,8 @@ def Other(): def PlotFunction(quadric, value): + colors = vtk.vtkNamedColors() + # sample the quadric function sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(50, 50, 50) @@ -141,7 +143,7 @@ def PlotFunction(quadric, value): # create an actor for it outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) - outlineActor.GetProperty().SetColor(0, 0, 0) + outlineActor.GetProperty().SetColor(colors.GetColor3d('Black')) # setup the window ren1 = vtk.vtkRenderer() @@ -153,19 +155,26 @@ def PlotFunction(quadric, value): # add the actors to the scene ren1.AddActor(contourActor) ren1.AddActor(outlineActor) - ren1.SetBackground(1, 1, 1) # Background color white + ren1.SetBackground(colors.GetColor3d('AliceBlue')) # render and interact renWin.Render() iren.Start() -Other() -Sphere() -Cone() -Ellipsoid() -Cylinder() -HyperboloidOneSheet() -HyperboloidTwoSheets() -HyperbolicParaboloid() -EllipticParaboloid() +def main(): + # Choose one! + + # Other() + # Sphere() + # Cone() + # Ellipsoid() + # Cylinder() + # HyperboloidOneSheet() + # HyperboloidTwoSheets() + # HyperbolicParaboloid() + EllipticParaboloid() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/SphereTexture.py b/src/Python/Visualization/SphereTexture.py index d764b2c184444aaa03dcf2c0212ee9d45495d093..50a78a9f832130729911f8defcc959c95c2bd3ce 100755 --- a/src/Python/Visualization/SphereTexture.py +++ b/src/Python/Visualization/SphereTexture.py @@ -11,8 +11,22 @@ import vtk +def get_program_parameters(): + import argparse + description = 'Texture an object with an image.' + epilogue = ''' + ''' + parser = argparse.ArgumentParser(description=description, epilog=epilogue, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('filename', help='masonry-wide.jpg.') + args = parser.parse_args() + return args.filename + + def main(): - jpegfile = "masonry-wide.jpg" + colors = vtk.vtkNamedColors() + + jpegfile = get_program_parameters() # Create a render window ren = vtk.vtkRenderer() @@ -51,6 +65,7 @@ def main(): actor.SetTexture(texture) ren.AddActor(actor) + ren.SetBackground(colors.GetColor3d('RosyBrown')) iren.Initialize() renWin.Render() diff --git a/src/Python/Visualization/StreamLines.py b/src/Python/Visualization/StreamLines.py index bdeaf69148f8bcf489b4365bbd3eae796359aa03..51e618bb0b8f1e93eed065435940dfa396faf608 100755 --- a/src/Python/Visualization/StreamLines.py +++ b/src/Python/Visualization/StreamLines.py @@ -5,58 +5,82 @@ import vtk -pl3d = vtk.vtkMultiBlockPLOT3DReader() - -xyx_file = "combxyz.bin" -q_file = "combq.bin" -pl3d.SetXYZFileName(xyx_file) -pl3d.SetQFileName(q_file) -pl3d.SetScalarFunctionNumber(100) -pl3d.SetVectorFunctionNumber(202) -pl3d.Update() - -seeds = vtk.vtkPlaneSource() -seeds.SetXResolution(4) -seeds.SetYResolution(4) -seeds.SetOrigin(2, -2, 26) -seeds.SetPoint1(2, 2, 26) -seeds.SetPoint2(2, -2, 32) - -streamline = vtk.vtkStreamLine() -streamline.SetInputData(pl3d.GetOutput().GetBlock(0)) -streamline.SetSourceConnection(seeds.GetOutputPort()) -streamline.SetMaximumPropagationTime(200) -streamline.SetIntegrationStepLength(.2) -streamline.SetStepLength(0.001) -streamline.SetNumberOfThreads(1) -streamline.SetIntegrationDirectionToForward() -streamline.VorticityOn() - -streamline_mapper = vtk.vtkPolyDataMapper() -streamline_mapper.SetInputConnection(streamline.GetOutputPort()) -streamline_actor = vtk.vtkActor() -streamline_actor.SetMapper(streamline_mapper) -streamline_actor.VisibilityOn() - -outline = vtk.vtkStructuredGridOutlineFilter() -outline.SetInputData(pl3d.GetOutput().GetBlock(0)) -outline_mapper = vtk.vtkPolyDataMapper() -outline_mapper.SetInputConnection(outline.GetOutputPort()) -outline_actor = vtk.vtkActor() -outline_actor.SetMapper(outline_mapper) -outline_actor.GetProperty().SetColor(1, 1, 1) - -renderer = vtk.vtkRenderer() -render_window = vtk.vtkRenderWindow() -render_window.AddRenderer(renderer) -interactor = vtk.vtkRenderWindowInteractor() -interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera()) -render_window.SetInteractor(interactor) - -renderer.AddActor(streamline_actor) -renderer.AddActor(outline_actor) - -renderer.SetBackground(0.1, 0.2, 0.4) -interactor.Initialize() -render_window.Render() -interactor.Start() + +def get_program_parameters(): + import argparse + description = 'Streamlines.' + epilogue = ''' + ''' + parser = argparse.ArgumentParser(description=description, epilog=epilogue) + parser.add_argument('xyz_file', help='combxyz.bin.') + parser.add_argument('q_file', help='combq.bin.') + args = parser.parse_args() + return args.xyz_file, args.q_file + + +def main(): + colors = vtk.vtkNamedColors() + + colors.SetColor('bkg', [0.1, 0.2, 0.4, 1.0]) + + xyz_file, q_file = get_program_parameters() + + # Read the data. + # + pl3d = vtk.vtkMultiBlockPLOT3DReader() + pl3d.SetXYZFileName(xyz_file) + pl3d.SetQFileName(q_file) + pl3d.SetScalarFunctionNumber(100) + pl3d.SetVectorFunctionNumber(202) + pl3d.Update() + + seeds = vtk.vtkPlaneSource() + seeds.SetXResolution(4) + seeds.SetYResolution(4) + seeds.SetOrigin(2, -2, 26) + seeds.SetPoint1(2, 2, 26) + seeds.SetPoint2(2, -2, 32) + + streamline = vtk.vtkStreamTracer() + streamline.SetInputData(pl3d.GetOutput().GetBlock(0)) + streamline.SetSourceConnection(seeds.GetOutputPort()) + streamline.SetMaximumPropagation(200) + streamline.SetInitialIntegrationStep(.2) + streamline.SetIntegrationDirectionToForward() + + streamline_mapper = vtk.vtkPolyDataMapper() + streamline_mapper.SetInputConnection(streamline.GetOutputPort()) + streamline_actor = vtk.vtkActor() + streamline_actor.SetMapper(streamline_mapper) + streamline_actor.VisibilityOn() + + outline = vtk.vtkStructuredGridOutlineFilter() + outline.SetInputData(pl3d.GetOutput().GetBlock(0)) + outline_mapper = vtk.vtkPolyDataMapper() + outline_mapper.SetInputConnection(outline.GetOutputPort()) + outline_actor = vtk.vtkActor() + outline_actor.SetMapper(outline_mapper) + outline_actor.GetProperty().SetColor(colors.GetColor3d('White')) + + renderer = vtk.vtkRenderer() + render_window = vtk.vtkRenderWindow() + render_window.AddRenderer(renderer) + interactor = vtk.vtkRenderWindowInteractor() + interactor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera()) + render_window.SetInteractor(interactor) + + renderer.AddActor(streamline_actor) + renderer.AddActor(outline_actor) + + renderer.SetBackground(colors.GetColor3d('bkg')) + interactor.Initialize() + render_window.Render() + renderer.GetActiveCamera().SetPosition(-32.8, -12.3, 46.3) + renderer.GetActiveCamera().SetFocalPoint(8.3, 0.03, 29.8) + renderer.GetActiveCamera().SetViewUp(0.2, 0.5, 0.9) + render_window.Render() + interactor.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/TextSource.py b/src/Python/Visualization/TextSource.py index 93559ec92e435debdf320b4cb16cf2251d47741f..7372bbb97d0bec296598094a503f01803b963f64 100755 --- a/src/Python/Visualization/TextSource.py +++ b/src/Python/Visualization/TextSource.py @@ -1,31 +1,38 @@ import vtk -# Create a sphere -textSource = vtk.vtkTextSource() -textSource.SetText("Hello") -textSource.SetForegroundColor(1.0, 0.0, 0.0) -textSource.BackingOn() -textSource.Update() - -# Create a mapper and actor -mapper = vtk.vtkPolyDataMapper() -mapper.SetInputConnection(textSource.GetOutputPort()) - -actor = vtk.vtkActor() -actor.SetMapper(mapper) - -# Create a renderer, render window, and interactor -renderer = vtk.vtkRenderer() -renderWindow = vtk.vtkRenderWindow() -renderWindow.AddRenderer(renderer) -renderWindowInteractor = vtk.vtkRenderWindowInteractor() -renderWindowInteractor.SetRenderWindow(renderWindow) - -# Add the actor to the scene -renderer.AddActor(actor) -renderer.SetBackground(1, 1, 1) # Background color white - -# Render and interact -renderWindow.Render() -renderWindowInteractor.Start() +def main(): + colors = vtk.vtkNamedColors() + + textSource = vtk.vtkTextSource() + textSource.SetText("Hello") + textSource.SetForegroundColor(colors.GetColor3d('DarkSlateGray')) + textSource.SetBackgroundColor(colors.GetColor3d('NavajoWhite')) + textSource.BackingOn() + textSource.Update() + + # Create a mapper and actor + mapper = vtk.vtkPolyDataMapper() + mapper.SetInputConnection(textSource.GetOutputPort()) + + actor = vtk.vtkActor() + actor.SetMapper(mapper) + + # Create a renderer, render window, and interactor + renderer = vtk.vtkRenderer() + renderWindow = vtk.vtkRenderWindow() + renderWindow.AddRenderer(renderer) + renderWindowInteractor = vtk.vtkRenderWindowInteractor() + renderWindowInteractor.SetRenderWindow(renderWindow) + + # Add the actor to the scene + renderer.AddActor(actor) + renderer.SetBackground(colors.GetColor3d('Bisque')) + + # Render and interact + renderWindow.Render() + renderWindowInteractor.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/VectorText.py b/src/Python/Visualization/VectorText.py index 7f4435ffd9c7789a947096a9f4a0b2c78432cd02..1de008e999426f71b6709303e882b2ac83283f4f 100755 --- a/src/Python/Visualization/VectorText.py +++ b/src/Python/Visualization/VectorText.py @@ -1,29 +1,36 @@ import vtk -# Create a sphere -textSource = vtk.vtkVectorText() -textSource.SetText("Hello") -textSource.Update() - -# Create a mapper and actor -mapper = vtk.vtkPolyDataMapper() -mapper.SetInputConnection(textSource.GetOutputPort()) - -actor = vtk.vtkActor() -actor.SetMapper(mapper) -actor.GetProperty().SetColor(1.0, 0.0, 0.0) - -# Create a renderer, render window, and interactor -renderer = vtk.vtkRenderer() -renderWindow = vtk.vtkRenderWindow() -renderWindow.AddRenderer(renderer) -renderWindowInteractor = vtk.vtkRenderWindowInteractor() -renderWindowInteractor.SetRenderWindow(renderWindow) - -# Add the actor to the scene -renderer.AddActor(actor) -renderer.SetBackground(1, 1, 1) # Background color white - -# Render and interact -renderWindow.Render() -renderWindowInteractor.Start() + +def main(): + colors = vtk.vtkNamedColors() + + textSource = vtk.vtkVectorText() + textSource.SetText("Hello") + textSource.Update() + + # Create a mapper and actor + mapper = vtk.vtkPolyDataMapper() + mapper.SetInputConnection(textSource.GetOutputPort()) + + actor = vtk.vtkActor() + actor.SetMapper(mapper) + actor.GetProperty().SetColor(colors.GetColor3d('DarkSlateGray')) + + # Create a renderer, render window, and interactor + renderer = vtk.vtkRenderer() + renderWindow = vtk.vtkRenderWindow() + renderWindow.AddRenderer(renderer) + renderWindowInteractor = vtk.vtkRenderWindowInteractor() + renderWindowInteractor.SetRenderWindow(renderWindow) + + # Add the actor to the scene + renderer.AddActor(actor) + renderer.SetBackground(colors.GetColor3d('Bisque')) + + # Render and interact + renderWindow.Render() + renderWindowInteractor.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Visualization/WindowTitle.py b/src/Python/Visualization/WindowTitle.py index 9d2db2dc90c88db3f6fad6ad694ff20e034509e9..c4a66ee82d8c659d11d474e30343962db1751939 100755 --- a/src/Python/Visualization/WindowTitle.py +++ b/src/Python/Visualization/WindowTitle.py @@ -2,7 +2,8 @@ import vtk def main(): - # Create a sphere + colors = vtk.vtkNamedColors() + sphereSource = vtk.vtkSphereSource() sphereSource.SetCenter(0.0, 0.0, 0.0) sphereSource.SetRadius(5) @@ -12,6 +13,7 @@ def main(): mapper.SetInputConnection(sphereSource.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) + actor.GetProperty().SetColor(colors.GetColor3d('Bisque')) # Setup a renderer, render window, and interactor renderer = vtk.vtkRenderer() @@ -24,14 +26,12 @@ def main(): # Add the actor to the scene renderer.AddActor(actor) - renderer.SetBackground(1, 1, 1) # Background color white + renderer.SetBackground(colors.GetColor3d('Navy')) # Render and interact renderWindow.Render() - # *** SetWindowName after renderWindow.Render() is called *** renderWindow.SetWindowName("Test") - renderWindowInteractor.Start() diff --git a/src/Python/Visualization/pdctf.vtp b/src/Python/Visualization/pdctf.vtp deleted file mode 100644 index e86c250ffdd8baf2fd3d98bf6a5e167ca3515bf9..0000000000000000000000000000000000000000 --- a/src/Python/Visualization/pdctf.vtp +++ /dev/null @@ -1,80 +0,0 @@ -<?xml version="1.0"?> -<VTKFile type="PolyData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor"> - <PolyData> - <Piece NumberOfPoints="16" NumberOfVerts="0" NumberOfLines="0" NumberOfStrips="0" NumberOfPolys="9"> - <PointData Normals="Normals" TCoords="TextureCoordinates"> - <DataArray type="Float32" Name="Normals" NumberOfComponents="3" format="ascii" RangeMin="1" RangeMax="1"> - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - </DataArray> - <DataArray type="Float32" Name="TextureCoordinates" NumberOfComponents="2" format="ascii" RangeMin="0" RangeMax="1.4142135624"> - 0 0 0.33333334327 0 0.66666668653 0 - 1 0 0 0.33333334327 0.33333334327 0.33333334327 - 0.66666668653 0.33333334327 1 0.33333334327 0 0.66666668653 - 0.33333334327 0.66666668653 0.66666668653 0.66666668653 1 0.66666668653 - 0 1 0.33333334327 1 0.66666668653 1 - 1 1 - </DataArray> - </PointData> - <CellData Scalars="colors"> - <DataArray type="UInt8" Name="colors" NumberOfComponents="3" format="ascii" RangeMin="202.16330033" RangeMax="382.78322847"> - 62 165 99 100 191 142 - 141 209 179 182 219 206 - 221 221 221 218 214 188 - 212 200 150 203 180 110 - 190 155 69 - </DataArray> - </CellData> - <Points> - <DataArray type="Float32" Name="Points" NumberOfComponents="3" format="ascii" RangeMin="0.23570226742" RangeMax="0.70710678119"> - -0.5 -0.5 0 -0.16666667163 -0.5 0 - 0.16666667163 -0.5 0 0.5 -0.5 0 - -0.5 -0.16666667163 0 -0.16666667163 -0.16666667163 0 - 0.16666667163 -0.16666667163 0 0.5 -0.16666667163 0 - -0.5 0.16666667163 0 -0.16666667163 0.16666667163 0 - 0.16666667163 0.16666667163 0 0.5 0.16666667163 0 - -0.5 0.5 0 -0.16666667163 0.5 0 - 0.16666667163 0.5 0 0.5 0.5 0 - </DataArray> - </Points> - <Verts> - <DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="0" RangeMax="15"> - </DataArray> - <DataArray type="Int64" Name="offsets" format="ascii" RangeMin="4" RangeMax="36"> - </DataArray> - </Verts> - <Lines> - <DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="0" RangeMax="15"> - </DataArray> - <DataArray type="Int64" Name="offsets" format="ascii" RangeMin="4" RangeMax="36"> - </DataArray> - </Lines> - <Strips> - <DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="0" RangeMax="15"> - </DataArray> - <DataArray type="Int64" Name="offsets" format="ascii" RangeMin="4" RangeMax="36"> - </DataArray> - </Strips> - <Polys> - <DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="0" RangeMax="15"> - 0 1 5 4 1 2 - 6 5 2 3 7 6 - 4 5 9 8 5 6 - 10 9 6 7 11 10 - 8 9 13 12 9 10 - 14 13 10 11 15 14 - </DataArray> - <DataArray type="Int64" Name="offsets" format="ascii" RangeMin="4" RangeMax="36"> - 4 8 12 16 20 24 - 28 32 36 - </DataArray> - </Polys> - </Piece> - </PolyData> -</VTKFile> diff --git a/src/Python/Visualization/pdlut.vtp b/src/Python/Visualization/pdlut.vtp deleted file mode 100644 index 2b70a5839488ebe6b65a36366f18649eab3c0a5e..0000000000000000000000000000000000000000 --- a/src/Python/Visualization/pdlut.vtp +++ /dev/null @@ -1,80 +0,0 @@ -<?xml version="1.0"?> -<VTKFile type="PolyData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor"> - <PolyData> - <Piece NumberOfPoints="16" NumberOfVerts="0" NumberOfLines="0" NumberOfStrips="0" NumberOfPolys="9"> - <PointData Normals="Normals" TCoords="TextureCoordinates"> - <DataArray type="Float32" Name="Normals" NumberOfComponents="3" format="ascii" RangeMin="1" RangeMax="1"> - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - 0 0 1 0 0 1 - </DataArray> - <DataArray type="Float32" Name="TextureCoordinates" NumberOfComponents="2" format="ascii" RangeMin="0" RangeMax="1.4142135624"> - 0 0 0.33333334327 0 0.66666668653 0 - 1 0 0 0.33333334327 0.33333334327 0.33333334327 - 0.66666668653 0.33333334327 1 0.33333334327 0 0.66666668653 - 0.33333334327 0.66666668653 0.66666668653 0.66666668653 1 0.66666668653 - 0 1 0.33333334327 1 0.66666668653 1 - 1 1 - </DataArray> - </PointData> - <CellData Scalars="colors"> - <DataArray type="UInt8" Name="colors" NumberOfComponents="3" format="ascii" RangeMin="165.03938924" RangeMax="410.24382994"> - 227 207 87 255 99 71 - 245 222 179 230 230 250 - 255 125 64 135 38 87 - 250 128 114 189 252 201 - 51 161 201 - </DataArray> - </CellData> - <Points> - <DataArray type="Float32" Name="Points" NumberOfComponents="3" format="ascii" RangeMin="0.23570226742" RangeMax="0.70710678119"> - -0.5 -0.5 0 -0.16666667163 -0.5 0 - 0.16666667163 -0.5 0 0.5 -0.5 0 - -0.5 -0.16666667163 0 -0.16666667163 -0.16666667163 0 - 0.16666667163 -0.16666667163 0 0.5 -0.16666667163 0 - -0.5 0.16666667163 0 -0.16666667163 0.16666667163 0 - 0.16666667163 0.16666667163 0 0.5 0.16666667163 0 - -0.5 0.5 0 -0.16666667163 0.5 0 - 0.16666667163 0.5 0 0.5 0.5 0 - </DataArray> - </Points> - <Verts> - <DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="1e+299" RangeMax="-1e+299"> - </DataArray> - <DataArray type="Int64" Name="offsets" format="ascii" RangeMin="1e+299" RangeMax="-1e+299"> - </DataArray> - </Verts> - <Lines> - <DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="1e+299" RangeMax="-1e+299"> - </DataArray> - <DataArray type="Int64" Name="offsets" format="ascii" RangeMin="1e+299" RangeMax="-1e+299"> - </DataArray> - </Lines> - <Strips> - <DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="1e+299" RangeMax="-1e+299"> - </DataArray> - <DataArray type="Int64" Name="offsets" format="ascii" RangeMin="1e+299" RangeMax="-1e+299"> - </DataArray> - </Strips> - <Polys> - <DataArray type="Int64" Name="connectivity" format="ascii" RangeMin="0" RangeMax="15"> - 0 1 5 4 1 2 - 6 5 2 3 7 6 - 4 5 9 8 5 6 - 10 9 6 7 11 10 - 8 9 13 12 9 10 - 14 13 10 11 15 14 - </DataArray> - <DataArray type="Int64" Name="offsets" format="ascii" RangeMin="4" RangeMax="36"> - 4 8 12 16 20 24 - 28 32 36 - </DataArray> - </Polys> - </Piece> - </PolyData> -</VTKFile> diff --git a/src/Python/Widgets/BalloonWidget.py b/src/Python/Widgets/BalloonWidget.py index 6e37b19dd478432783c5b29e1d76bec58d87e1cc..eaa61b0d68406693999f29f932219de0539a5893 100755 --- a/src/Python/Widgets/BalloonWidget.py +++ b/src/Python/Widgets/BalloonWidget.py @@ -1,55 +1,66 @@ #!/usr/bin/env python import vtk -# Sphere -sphereSource = vtk.vtkSphereSource() -sphereSource.SetCenter(-4.0, 0.0, 0.0) -sphereSource.SetRadius(4.0) - -sphereMapper = vtk.vtkPolyDataMapper() -sphereMapper.SetInputConnection(sphereSource.GetOutputPort()) - -sphereActor = vtk.vtkActor() -sphereActor.SetMapper(sphereMapper) - -# Regular Polygon -regularPolygonSource = vtk.vtkRegularPolygonSource() -regularPolygonSource.SetCenter(4.0, 0.0, 0.0) -regularPolygonSource.SetRadius(4.0) - -regularPolygonMapper = vtk.vtkPolyDataMapper() -regularPolygonMapper.SetInputConnection(regularPolygonSource.GetOutputPort()) - -regularPolygonActor = vtk.vtkActor() -regularPolygonActor.SetMapper(regularPolygonMapper) - -# A renderer and render window -renderer = vtk.vtkRenderer() -renderWindow = vtk.vtkRenderWindow() -renderWindow.AddRenderer(renderer) - -# An interactor -renderWindowInteractor = vtk.vtkRenderWindowInteractor() -renderWindowInteractor.SetRenderWindow(renderWindow) - -# Create the widget -balloonRep = vtk.vtkBalloonRepresentation() -balloonRep.SetBalloonLayoutToImageRight() - -balloonWidget = vtk.vtkBalloonWidget() -balloonWidget.SetInteractor(renderWindowInteractor) -balloonWidget.SetRepresentation(balloonRep) -balloonWidget.AddBalloon(sphereActor, "This is a sphere") -balloonWidget.AddBalloon(regularPolygonActor, "This is a regular polygon") - -# Add the actors to the scene -renderer.AddActor(sphereActor) -renderer.AddActor(regularPolygonActor) - -# Render an image (lights and cameras are created automatically) -renderWindow.Render() -balloonWidget.EnabledOn() - -# Begin mouse interaction -renderWindowInteractor.Start() -renderWindowInteractor.Initialize() + +def main(): + colors = vtk.vtkNamedColors() + + # Sphere + sphereSource = vtk.vtkSphereSource() + sphereSource.SetCenter(-4.0, 0.0, 0.0) + sphereSource.SetRadius(4.0) + + sphereMapper = vtk.vtkPolyDataMapper() + sphereMapper.SetInputConnection(sphereSource.GetOutputPort()) + + sphereActor = vtk.vtkActor() + sphereActor.SetMapper(sphereMapper) + sphereActor.GetProperty().SetColor(colors.GetColor3d("Chocolate")) + + # Regular Polygon + regularPolygonSource = vtk.vtkRegularPolygonSource() + regularPolygonSource.SetCenter(4.0, 0.0, 0.0) + regularPolygonSource.SetRadius(4.0) + + regularPolygonMapper = vtk.vtkPolyDataMapper() + regularPolygonMapper.SetInputConnection(regularPolygonSource.GetOutputPort()) + + regularPolygonActor = vtk.vtkActor() + regularPolygonActor.SetMapper(regularPolygonMapper) + regularPolygonActor.GetProperty().SetColor(colors.GetColor3d("BurlyWood")) + + # A renderer and render window + renderer = vtk.vtkRenderer() + renderWindow = vtk.vtkRenderWindow() + renderWindow.AddRenderer(renderer) + + # An interactor + renderWindowInteractor = vtk.vtkRenderWindowInteractor() + renderWindowInteractor.SetRenderWindow(renderWindow) + + # Create the widget + balloonRep = vtk.vtkBalloonRepresentation() + balloonRep.SetBalloonLayoutToImageRight() + + balloonWidget = vtk.vtkBalloonWidget() + balloonWidget.SetInteractor(renderWindowInteractor) + balloonWidget.SetRepresentation(balloonRep) + balloonWidget.AddBalloon(sphereActor, "This is a sphere") + balloonWidget.AddBalloon(regularPolygonActor, "This is a regular polygon") + + # Add the actors to the scene + renderer.AddActor(sphereActor) + renderer.AddActor(regularPolygonActor) + renderer.SetBackground(colors.GetColor3d("Wheat")) + + # Render an image (lights and cameras are created automatically) + renderWindow.Render() + balloonWidget.EnabledOn() + + # Begin mouse interaction + renderWindowInteractor.Start() + renderWindowInteractor.Initialize() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Widgets/BoxWidget.py b/src/Python/Widgets/BoxWidget.py index 85c0a96144b5b9ec608c7604721a7fc4b5ab886b..bc124e6dfde14ea36ab03aa4c7f0606a7260ce72 100755 --- a/src/Python/Widgets/BoxWidget.py +++ b/src/Python/Widgets/BoxWidget.py @@ -1,5 +1,6 @@ import vtk + # Call back function to resize the cone @@ -9,37 +10,46 @@ def boxCallback(obj, event): obj.GetProp3D().SetUserTransform(t) -# Create a Cone -cone = vtk.vtkConeSource() -cone.SetResolution(20) -coneMapper = vtk.vtkPolyDataMapper() -coneMapper.SetInputConnection(cone.GetOutputPort()) -coneActor = vtk.vtkActor() -coneActor.SetMapper(coneMapper) - -# A renderer and render window -renderer = vtk.vtkRenderer() -renderer.SetBackground(0, 0, 1) -renderer.AddActor(coneActor) - -renwin = vtk.vtkRenderWindow() -renwin.AddRenderer(renderer) - -# An interactor -interactor = vtk.vtkRenderWindowInteractor() -interactor.SetRenderWindow(renwin) - -# A Box widget -boxWidget = vtk.vtkBoxWidget() -boxWidget.SetInteractor(interactor) -boxWidget.SetProp3D(coneActor) -boxWidget.SetPlaceFactor(1.25) # Make the box 1.25x larger than the actor -boxWidget.PlaceWidget() -boxWidget.On() - -# Connect the event to a function -boxWidget.AddObserver("InteractionEvent", boxCallback) - -# Start -interactor.Initialize() -interactor.Start() +def main(): + colors = vtk.vtkNamedColors() + + # Create a Cone + cone = vtk.vtkConeSource() + cone.SetResolution(20) + coneMapper = vtk.vtkPolyDataMapper() + coneMapper.SetInputConnection(cone.GetOutputPort()) + coneActor = vtk.vtkActor() + coneActor.SetMapper(coneMapper) + coneActor.GetProperty().SetColor(colors.GetColor3d("BurlyWood")) + + # A renderer and render window + renderer = vtk.vtkRenderer() + renderer.SetBackground(colors.GetColor3d("Blue")) + renderer.AddActor(coneActor) + + renwin = vtk.vtkRenderWindow() + renwin.AddRenderer(renderer) + + # An interactor + interactor = vtk.vtkRenderWindowInteractor() + interactor.SetRenderWindow(renwin) + + # A Box widget + boxWidget = vtk.vtkBoxWidget() + boxWidget.SetInteractor(interactor) + boxWidget.SetProp3D(coneActor) + boxWidget.SetPlaceFactor(1.25) # Make the box 1.25x larger than the actor + boxWidget.PlaceWidget() + boxWidget.On() + + # Connect the event to a function + boxWidget.AddObserver("InteractionEvent", boxCallback) + + # Start + interactor.Initialize() + renwin.Render() + interactor.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Widgets/CompassWidget.py b/src/Python/Widgets/CompassWidget.py index 69dd0088f9cb1f032e147d8669db46030f150d54..bf7613048b8f0ca890025395d13840a3d27ba03c 100755 --- a/src/Python/Widgets/CompassWidget.py +++ b/src/Python/Widgets/CompassWidget.py @@ -18,6 +18,7 @@ def main(): actor = vtk.vtkActor() actor.SetMapper(mapper) + actor.GetProperty().SetColor(colors.GetColor3d("BurlyWood")) # a renderer and render window renderer = vtk.vtkRenderer() @@ -45,9 +46,9 @@ def main(): renderWindowInteractor.SetInteractorStyle(style) # begin interaction - renderWindowInteractor.Start() - renderWindow.Render() renderWindowInteractor.Initialize() + renderWindow.Render() + renderWindowInteractor.Start() if __name__ == '__main__': diff --git a/src/Python/Widgets/ContourWidget.py b/src/Python/Widgets/ContourWidget.py index 4b131735ab6b03375d4d3442ee486144a1da4a3c..2a552ee9ebe3595fae7ed15df016923b3429811b 100755 --- a/src/Python/Widgets/ContourWidget.py +++ b/src/Python/Widgets/ContourWidget.py @@ -1,64 +1,77 @@ #!/usr/bin/python -import vtk -import sys import math +import sys + +import vtk + + +def main(): + colors = vtk.vtkNamedColors() + + colors.SetColor('bkg', [0.1, 0.2, 0.4, 1.0]) -# Create the RenderWindow, Renderer and both Actors + # Create the RenderWindow, Renderer and both Actors -renderer = vtk.vtkRenderer() -renderWindow = vtk.vtkRenderWindow() -renderWindow.AddRenderer(renderer) + renderer = vtk.vtkRenderer() + renderWindow = vtk.vtkRenderWindow() + renderWindow.AddRenderer(renderer) -interactor = vtk.vtkRenderWindowInteractor() -interactor.SetRenderWindow(renderWindow) + interactor = vtk.vtkRenderWindowInteractor() + interactor.SetRenderWindow(renderWindow) -renderer.SetBackground(0.1, 0.2, 0.4) -renderWindow.SetSize(600, 600) + renderer.SetBackground(colors.GetColor3d("bkg")) + renderWindow.SetSize(600, 600) -contourRep = vtk.vtkOrientedGlyphContourRepresentation() -contourRep.GetLinesProperty().SetColor(1, 0, 0) # set color to red + contourRep = vtk.vtkOrientedGlyphContourRepresentation() + contourRep.GetLinesProperty().SetColor(colors.GetColor3d("Red")) -contourWidget = vtk.vtkContourWidget() -contourWidget.SetInteractor(interactor) -contourWidget.SetRepresentation(contourRep) -contourWidget.On() + contourWidget = vtk.vtkContourWidget() + contourWidget.SetInteractor(interactor) + contourWidget.SetRepresentation(contourRep) + contourWidget.On() -for arg in sys.argv: - if "-Shift" == arg: - contourWidget.GetEventTranslator().RemoveTranslation( - vtk.vtkCommand.LeftButtonPressEvent) - contourWidget.GetEventTranslator().SetTranslation( - vtk.vtkCommand.LeftButtonPressEvent, - vtk.vtkWidgetEvent.Translate) - elif "-Scale" == arg: - contourWidget.GetEventTranslator().RemoveTranslation( - vtk.vtkCommand.LeftButtonPressEvent) - contourWidget.GetEventTranslator().SetTranslation( - vtk.vtkCommand.LeftButtonPressEvent, - vtk.vtkWidgetEvent.Scale) + for arg in sys.argv: + if "-Shift" == arg: + contourWidget.GetEventTranslator().RemoveTranslation( + vtk.vtkCommand.LeftButtonPressEvent) + contourWidget.GetEventTranslator().SetTranslation( + vtk.vtkCommand.LeftButtonPressEvent, + vtk.vtkWidgetEvent.Translate) + elif "-Scale" == arg: + contourWidget.GetEventTranslator().RemoveTranslation( + vtk.vtkCommand.LeftButtonPressEvent) + contourWidget.GetEventTranslator().SetTranslation( + vtk.vtkCommand.LeftButtonPressEvent, + vtk.vtkWidgetEvent.Scale) + pd = vtk.vtkPolyData() -pd = vtk.vtkPolyData() + points = vtk.vtkPoints() -points = vtk.vtkPoints() -lines = vtk.vtkCellArray() + num_pts = 21 + for i in range(0, num_pts): + angle = 2.0 * math.pi * i / 20.0 + points.InsertPoint(i, 0.1 * math.cos(angle), + 0.1 * math.sin(angle), 0.0) + # lines.InsertNextCell(i) + vertex_indices = list(range(0, num_pts)) + vertex_indices.append(0) + lines = vtk.vtkCellArray() + lines.InsertNextCell(num_pts + 1, vertex_indices) -for i in range(0, 21): - angle = 2.0 * math.pi * i / 20.0 - points.InsertPoint(i, 0.1 * math.cos(angle), - 0.1 * math.sin(angle), 0.0) - lines.InsertNextCell(i) + pd.SetPoints(points) + pd.SetLines(lines) -pd.SetPoints(points) -pd.SetLines(lines) + # contourWidget.Initialize(pd, 1) + contourWidget.Initialize(pd, 1) + contourWidget.Render() + renderer.ResetCamera() + renderWindow.Render() -contourWidget.Initialize(pd, 1) -contourWidget.Render() -renderer.ResetCamera() -renderWindow.Render() + interactor.Initialize() + interactor.Start() -interactor.Initialize() -interactor.Start() -contourWidget.Off() +if __name__ == '__main__': + main() diff --git a/src/Python/Widgets/OrientationMarkerWidget.py b/src/Python/Widgets/OrientationMarkerWidget.py index dd22664f68c28f92a8c579119857b34dba1f67d3..cd03114b391ddb50bc6b00fadbd56f265ec14ff7 100755 --- a/src/Python/Widgets/OrientationMarkerWidget.py +++ b/src/Python/Widgets/OrientationMarkerWidget.py @@ -2,46 +2,61 @@ import vtk -# create a rendering window and renderer -ren = vtk.vtkRenderer() -renWin = vtk.vtkRenderWindow() -renWin.AddRenderer(ren) - -# create a renderwindowinteractor -iren = vtk.vtkRenderWindowInteractor() -iren.SetRenderWindow(renWin) - -cube = vtk.vtkCubeSource() -cube.SetXLength(200) -cube.SetYLength(200) -cube.SetZLength(200) -cube.Update() -cm = vtk.vtkPolyDataMapper() -cm.SetInputConnection(cube.GetOutputPort()) -ca = vtk.vtkActor() -ca.SetMapper(cm) - -# assign actor to the renderer -ren.AddActor(ca) - -axesActor = vtk.vtkAnnotatedCubeActor() -axesActor.SetXPlusFaceText('R') -axesActor.SetXMinusFaceText('L') -axesActor.SetYMinusFaceText('H') -axesActor.SetYPlusFaceText('F') -axesActor.SetZMinusFaceText('P') -axesActor.SetZPlusFaceText('A') -axesActor.GetTextEdgesProperty().SetColor(1, 1, 0) -axesActor.GetTextEdgesProperty().SetLineWidth(2) -axesActor.GetCubeProperty().SetColor(0, 0, 1) -axes = vtk.vtkOrientationMarkerWidget() -axes.SetOrientationMarker(axesActor) -axes.SetInteractor(iren) -axes.EnabledOn() -axes.InteractiveOn() -ren.ResetCamera() - -# enable user interface interactor -iren.Initialize() -renWin.Render() -iren.Start() + +def main(): + colors = vtk.vtkNamedColors() + + colors.SetColor('bkg', [0.2, 0.3, 0.7, 1.0]) + + # create a rendering window and renderer + ren = vtk.vtkRenderer() + renWin = vtk.vtkRenderWindow() + renWin.AddRenderer(ren) + + # create a renderwindowinteractor + iren = vtk.vtkRenderWindowInteractor() + iren.SetRenderWindow(renWin) + + cube = vtk.vtkCubeSource() + cube.SetXLength(200) + cube.SetYLength(200) + cube.SetZLength(200) + cube.Update() + cm = vtk.vtkPolyDataMapper() + cm.SetInputConnection(cube.GetOutputPort()) + ca = vtk.vtkActor() + ca.SetMapper(cm) + ca.GetProperty().SetColor(colors.GetColor3d("BurlyWood")) + + # assign actor to the renderer + ren.AddActor(ca) + ren.SetBackground(colors.GetColor3d('bkg')) + + axesActor = vtk.vtkAnnotatedCubeActor() + axesActor.SetXPlusFaceText('R') + axesActor.SetXMinusFaceText('L') + axesActor.SetYMinusFaceText('H') + axesActor.SetYPlusFaceText('F') + axesActor.SetZMinusFaceText('P') + axesActor.SetZPlusFaceText('A') + axesActor.GetTextEdgesProperty().SetColor(colors.GetColor3d("Yellow")) + axesActor.GetTextEdgesProperty().SetLineWidth(2) + axesActor.GetCubeProperty().SetColor(colors.GetColor3d("Blue")) + axes = vtk.vtkOrientationMarkerWidget() + axes.SetOrientationMarker(axesActor) + axes.SetInteractor(iren) + axes.EnabledOn() + axes.InteractiveOn() + ren.ResetCamera() + + # enable user interface interactor + iren.Initialize() + renWin.Render() + ren.GetActiveCamera().SetPosition(-151.5, 540.1, 364.0) + ren.GetActiveCamera().SetViewUp(0.2, 0.6, -0.8) + renWin.Render() + iren.Start() + + +if __name__ == '__main__': + main() diff --git a/src/Python/Widgets/ScalarBarWidget.py b/src/Python/Widgets/ScalarBarWidget.py index e72ad34f83b0690ea23f537917985df5b9216582..0947709616ee23e6c60466d202c1ff5791862442 100755 --- a/src/Python/Widgets/ScalarBarWidget.py +++ b/src/Python/Widgets/ScalarBarWidget.py @@ -6,13 +6,25 @@ import vtk +def get_program_parameters(): + import argparse + description = 'Scalar bar widget.' + epilogue = ''' + ''' + parser = argparse.ArgumentParser(description=description, epilog=epilogue, + formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument('filename', help='uGridEx.vtk.') + args = parser.parse_args() + return args.filename + + def main(): colors = vtk.vtkNamedColors() colors.SetColor('bkg', [0.1, 0.2, 0.4, 1.0]) # The source file - file_name = "uGridEx.vtk" + file_name = get_program_parameters() # Create a custom lut. The lut is used both at the mapper and at the # scalar_bar @@ -58,6 +70,10 @@ def main(): interactor.Initialize() render_window.Render() + renderer.GetActiveCamera().SetPosition(-6.4, 10.3, 1.4) + renderer.GetActiveCamera().SetFocalPoint(1.0, 0.5, 3.0) + renderer.GetActiveCamera().SetViewUp(0.6, 0.4, -0.7) + render_window.Render() interactor.Start() diff --git a/src/Python/Widgets/SphereWidget.py b/src/Python/Widgets/SphereWidget.py index 2bde545e08e81e81e57191f5c87a21a1077fa87b..e29414a72f571d0dbb6fc105c6eccba6e937e44a 100755 --- a/src/Python/Widgets/SphereWidget.py +++ b/src/Python/Widgets/SphereWidget.py @@ -1,5 +1,6 @@ import vtk + # Call back function @@ -7,26 +8,38 @@ def sphereCallback(obj, event): print('Center: {}, {}, {}'.format(*obj.GetCenter())) -# A renderer and render window -renderer = vtk.vtkRenderer() -renderer.SetBackground(1, 1, 1) +def main(): + colors = vtk.vtkNamedColors() + + colors.SetColor('bkg', [0.1, 0.2, 0.4, 1.0]) + + # A renderer and render window + renderer = vtk.vtkRenderer() + renderer.SetBackground(colors.GetColor3d('bkg')) + + renwin = vtk.vtkRenderWindow() + renwin.AddRenderer(renderer) + + # An interactor + interactor = vtk.vtkRenderWindowInteractor() + interactor.SetRenderWindow(renwin) + + # A Sphere widget + sphereWidget = vtk.vtkSphereWidget() + sphereWidget.SetInteractor(interactor) + sphereWidget.SetRepresentationToSurface() + sphereWidget.GetSphereProperty().SetColor(colors.GetColor3d("BurlyWood")) -renwin = vtk.vtkRenderWindow() -renwin.AddRenderer(renderer) + sphereWidget.On() -# An interactor -interactor = vtk.vtkRenderWindowInteractor() -interactor.SetRenderWindow(renwin) + # Connect the event to a function + sphereWidget.AddObserver("InteractionEvent", sphereCallback) -# A Sphere widget -sphereWidget = vtk.vtkSphereWidget() -sphereWidget.SetInteractor(interactor) -sphereWidget.SetRepresentationToSurface() -sphereWidget.On() + # Start + interactor.Initialize() + renwin.Render() + interactor.Start() -# Connect the event to a function -sphereWidget.AddObserver("InteractionEvent", sphereCallback) -# Start -interactor.Initialize() -interactor.Start() +if __name__ == '__main__': + main()