ParametricObjects

VTKExamples/Python/GeometricObjects/ParametricObjects

Description

See Parametric Equations for Surfaces by Andrew Maclean for an excellent description of these beautiful parametric surfaces.

You can edit the following code by selecting any one of the functions and the corresponding object will be displayed.

Code

ParametricObjects.py

#!/usr/bin/env python

import vtk


class ParametricObjects(object):
    def ParametricObjects(self):
        # Select one of the following functions.
        # parametricObject = vtk.vtkParametricBoy()
        # parametricObject = vtk.vtkParametricConicSpiral()
        # parametricObject = vtk.vtkParametricCrossCap()
        # parametricObject = vtk.vtkParametricDini()
        # parametricObject = vtk.vtkParametricEllipsoid()
        # parametricObject = vtk.vtkParametricEnneper()
        # parametricObject = vtk.vtkParametricFigure8Klein()
        # parametricObject = vtk.vtkParametricKlein()
        # parametricObject = vtk.vtkParametricMobius()
        # parametricObject = vtk.vtkParametricRandomHills()
        # parametricObject = vtk.vtkParametricRoman()
        # parametricObject = vtk.vtkParametricSpline()
        # parametricObject = vtk.vtkParametricSuperEllipsoid()
        # parametricObject = vtk.vtkParametricSuperToroid()
        parametricObject = vtk.vtkParametricTorus()

        parametricSource = vtk.vtkParametricFunctionSource()
        parametricSource.SetParametricFunction(parametricObject)

        # mapper
        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(parametricSource.GetOutputPort())

        # actor
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        # ------------------------------------------------------------
        # Create the RenderWindow, Renderer and Interactor
        # ------------------------------------------------------------
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        iren = vtk.vtkRenderWindowInteractor()

        renWin.AddRenderer(ren)
        iren.SetRenderWindow(renWin)

        # add actors
        ren.AddViewProp(actor)
        ren.SetBackground(1, 1, 1)  # Background color white

        # enable user interface interactor
        iren.Initialize()
        renWin.Render()
        iren.Start()


if __name__ == "__main__":
    po = ParametricObjects()
    po.ParametricObjects()