Difference between revisions of "VTK/Examples/Python/Geovis/GeoAssignCoordinates"

From KitwarePublic
< VTK‎ | Examples‎ | Python
Jump to: navigation, search
(Created page with "==GeoAssignCoordinates.py== <source lang="python"> #!/usr/bin/python import vtk g = vtk.vtkMutableDirectedGraph() latitude = vtk.vtkDoubleArray() latitude.SetName("latitude") l...")
 
Line 1: Line 1:
 +
* Contributed by Jim McCusker
 +
 
==GeoAssignCoordinates.py==
 
==GeoAssignCoordinates.py==
 
<source lang="python">
 
<source lang="python">

Revision as of 07:31, 21 September 2010

  • Contributed by Jim McCusker

GeoAssignCoordinates.py

#!/usr/bin/python
 
import vtk
 
g = vtk.vtkMutableDirectedGraph()
latitude = vtk.vtkDoubleArray()
latitude.SetName("latitude")
longitude = vtk.vtkDoubleArray()
longitude.SetName("longitude")
for i in range(-90, 90, 10):
    for j in range(-180, 180, 20):
        g.AddVertex()
        latitude.InsertNextValue(i)
        longitude.InsertNextValue(j)
g.GetVertexData().AddArray(latitude)
g.GetVertexData().AddArray(longitude)
 
assign = vtk.vtkGeoAssignCoordinates()
assign.SetInput(g)
assign.SetLatitudeArrayName("latitude")
assign.SetLongitudeArrayName("longitude")
assign.SetGlobeRadius(1.0)
assign.Update()
 
mapper = vtk.vtkGraphMapper()
mapper.SetInputConnection(assign.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren = vtk.vtkRenderer()
ren.AddActor(actor)
iren = vtk.vtkRenderWindowInteractor()
win = vtk.vtkRenderWindow()
win.AddRenderer(ren)
win.SetInteractor(iren)
ren.ResetCamera()
 
iren.Initialize()
iren.Start()