# Glyph2D

VTKExamples/Python/Filtering/Glyph2D

Copy a polydata to every point in the input set. We use a hexagon for the demo.

Other Languages

See (Cxx), (Java)

Question

If you have a simple question about this example contact us at VTKExamplesProject If your question is more complex and may require extended discussion, please use the VTK Discourse Forum

### Code¶

Glyph2D.py

#!/usr/bin/env python

import vtk

def main():
points = vtk.vtkPoints()
points.InsertNextPoint(0,0,0)
points.InsertNextPoint(1,1,0)
points.InsertNextPoint(2,2,0)

polydata = vtk.vtkPolyData()
polydata.SetPoints(points)

# Create anything you want here, we will use a polygon for the demo.
polygonSource = vtk.vtkRegularPolygonSource() #default is 6 sides

glyph2D = vtk.vtkGlyph2D()
glyph2D.SetSourceConnection(polygonSource.GetOutputPort())
glyph2D.SetInputData(polydata)
glyph2D.Update()

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(glyph2D.GetOutputPort())
mapper.Update()

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

# Visualize
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)