# ColoredSphere

VTKExamples/Python/Rendering/ColoredSphere

### Description

This demonstrates a simple visualization pipeline. A polygonal representation of a sphere is created with the source object vtkSphereSource). The sphere is passed through a filter vtkElevationFilter) that computes the height of each point of the sphere above a plane. The plane is perpendicular to the z-axis, and passes through the point (0,0,-1). The data is finally mapped vtkDataSetMapper) through a lookup table. The mapping process converts height value into colors, and interfaces the sphere geometry to the rendering library. The mapper is assigned to an actor, and then the actor is displayed.

The execution of the pipeline occurs implicitly when we render the actor. Each actor asks its mapper to update itself. The mapper in turn asks its input to update itself. This process continues until a source object is encountered. Then the source will execute if modified since the last render.

Other Languages

See (Cxx), (Java)

### Code

ColoredSphere.py

    #!/usr/bin/env python

    import vtk

    def main():
        colors = vtk.vtkNamedColors()
        renderer = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.AddRenderer(renderer)
        iren = vtk.vtkRenderWindowInteractor()
        iren.SetRenderWindow(renWin)

        sphere = vtk.vtkSphereSource()
        sphere.SetPhiResolution(12)
        sphere.SetThetaResolution(12)

        colorIt = vtk.vtkElevationFilter()
        colorIt.SetInputConnection(sphere.GetOutputPort())
        colorIt.SetLowPoint(0, 0, -1)
        colorIt.SetHighPoint(0, 0, 1)

        mapper = vtk.vtkDataSetMapper()
        mapper.SetInputConnection(colorIt.GetOutputPort())

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

        renderer.AddActor(actor)
        renderer.SetBackground(colors.GetColor3d("SlateGray"))
        renWin.SetSize(640, 480)

        renWin.Render()

        # Interact with the data.
        iren.Start()

    if __name__ == '__main__':
        main()