mirror of
https://github.com/OpenFOAM/ThirdParty-6.git
synced 2025-12-08 06:57:43 +00:00
60 lines
1.8 KiB
Python
Executable File
60 lines
1.8 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# This example demonstrates the use of the contour filter, and the use of
|
|
# the vtkSampleFunction to generate a volume of data samples from an
|
|
# implicit function.
|
|
|
|
import vtk
|
|
|
|
# VTK supports implicit functions of the form f(x,y,z)=constant. These
|
|
# functions can represent things spheres, cones, etc. Here we use a
|
|
# general form for a quadric to create an elliptical data field.
|
|
quadric = vtk.vtkQuadric()
|
|
quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)
|
|
|
|
# vtkSampleFunction samples an implicit function over the x-y-z range
|
|
# specified (here it defaults to -1,1 in the x,y,z directions).
|
|
sample = vtk.vtkSampleFunction()
|
|
sample.SetSampleDimensions(30, 30, 30)
|
|
sample.SetImplicitFunction(quadric)
|
|
|
|
# Create five surfaces F(x,y,z) = constant between range specified. The
|
|
# GenerateValues() method creates n isocontour values between the range
|
|
# specified.
|
|
contours = vtk.vtkContourFilter()
|
|
contours.SetInputConnection(sample.GetOutputPort())
|
|
contours.GenerateValues(5, 0.0, 1.2)
|
|
|
|
contMapper = vtk.vtkPolyDataMapper()
|
|
contMapper.SetInputConnection(contours.GetOutputPort())
|
|
contMapper.SetScalarRange(0.0, 1.2)
|
|
|
|
contActor = vtk.vtkActor()
|
|
contActor.SetMapper(contMapper)
|
|
|
|
# We'll put a simple outline around the data.
|
|
outline = vtk.vtkOutlineFilter()
|
|
outline.SetInputConnection(sample.GetOutputPort())
|
|
|
|
outlineMapper = vtk.vtkPolyDataMapper()
|
|
outlineMapper.SetInputConnection(outline.GetOutputPort())
|
|
|
|
outlineActor = vtk.vtkActor()
|
|
outlineActor.SetMapper(outlineMapper)
|
|
outlineActor.GetProperty().SetColor(0,0,0)
|
|
|
|
# The usual rendering stuff.
|
|
ren = vtk.vtkRenderer()
|
|
renWin = vtk.vtkRenderWindow()
|
|
renWin.AddRenderer(ren)
|
|
iren = vtk.vtkRenderWindowInteractor()
|
|
iren.SetRenderWindow(renWin)
|
|
|
|
ren.SetBackground(1, 1, 1)
|
|
ren.AddActor(contActor)
|
|
ren.AddActor(outlineActor)
|
|
|
|
iren.Initialize()
|
|
renWin.Render()
|
|
iren.Start()
|