Newer
Older
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonDataModel import vtkQuadric
from vtkmodules.vtkFiltersCore import vtkContourFilter
from vtkmodules.vtkFiltersModeling import vtkOutlineFilter
from vtkmodules.vtkImagingHybrid import vtkSampleFunction
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer
)
def Sphere():
# create the quadric function definition
quadric.SetCoefficients(1, 1, 1, 0, 0, 0, 0, 0, 0, 0)
# F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
# F(x,y,z) = 1*x^2 + 1*y^2 + 1*z^2
def EllipticParaboloid():
# create the quadric function definition
quadric.SetCoefficients(1, 1, 0, 0, 0, 0, 0, 0, -1, 0)
# F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
# F(x,y,z) = 1*x^2 + 1*y^2
PlotFunction(quadric, 10.0)
def HyperbolicParaboloid():
# create the quadric function definition
quadric.SetCoefficients(1, -1, 0, 0, 0, 0, 0, 0, 0, 0)
# F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
# F(x,y,z) = 1*x^2 - 1*y^2
def Cylinder():
# create the quadric function definition
quadric.SetCoefficients(1, 1, 0, 0, 0, 0, 0, 0, 0, 0)
# F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
# F(x,y,z) = 1*x^2 + 1*y^2
def HyperboloidOneSheet():
# create the quadric function definition
quadric.SetCoefficients(1, 1, -1, 0, 0, 0, 0, 0, 0, 0)
# F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
# F(x,y,z) = 1*x^2 + 1*y^2
def HyperboloidTwoSheets():
# create the quadric function definition
quadric.SetCoefficients(1, 1, -1, 0, 0, 0, 0, 0, 0, 0)
# F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
# F(x,y,z) = 1*x^2 + 1*y^2
def Ellipsoid():
# create the quadric function definition
quadric.SetCoefficients(1, 1, 2, 0, 0, 0, 0, 0, 0, 0)
# F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
# F(x,y,z) = 1*x^2 + 1*y^2 + 1*z^2
def Cone():
# create the quadric function definition
quadric.SetCoefficients(1, 1, -1, 0, 0, 0, 0, 0, 0, 0)
# F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
# F(x,y,z) = 1*x^2 + 1*y^2 - 1*z^2
PlotFunction(quadric, 0.0)
def Other():
# create the quadric function definition
quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)
# F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
# F(x,y,z) = 0.5*x^2 + 1*y^2 + 0.2*z^2 + 0*x*y + 0.1*y*z + 0*x*z + 0*x + 0.2*y + 0*z + 0
PlotFunction(quadric, 1.0)
sample.SetSampleDimensions(50, 50, 50)
# double xmin = 0, xmax=1, ymin=0, ymax=1, zmin=0, zmax=1
bounds = [-10, 11, -10, 10, -10, 10]
sample.SetModelBounds(bounds)
# create the 0 isosurface
contours.SetInputConnection(sample.GetOutputPort())
contourMapper.SetInputConnection(contours.GetOutputPort())
# -- create a box around the function to indicate the sampling volume --
outline.SetInputConnection(sample.GetOutputPort())
outlineMapper.SetInputConnection(outline.GetOutputPort())
outlineActor.GetProperty().SetColor(colors.GetColor3d('Black'))
ren1 = vtkRenderer()
renWin = vtkRenderWindow()
renWin.SetWindowName('DisplayQuadricSurfaces')
# add the actors to the scene
ren1.AddActor(contourActor)
ren1.AddActor(outlineActor)
ren1.SetBackground(colors.GetColor3d('AliceBlue'))
ren1.GetActiveCamera().Azimuth(-55)
ren1.GetActiveCamera().Elevation(15)
def main():
# Choose one!
# Other()
# Sphere()
# Cone()
# Ellipsoid()
# Cylinder()
# HyperboloidOneSheet()
# HyperboloidTwoSheets()
# HyperbolicParaboloid()
EllipticParaboloid()
if __name__ == '__main__':
main()