[vtkusers] grid lines for structured grid?

Doug Swesty dswesty at blackhole.ess.sunysb.edu
Wed Jul 5 15:54:02 EDT 2006


  Dear VTK-Users,

  I am trying to find a way to draw grid lines 
 representing connections between the points
 of a 3D structured grid.  I have hacked the SGrid
 example code to do what I thought should work 
 use the StructuredGridGeometryFilter.  Unfortunately
 I get a blank window when I run this.  Can anyone 
 tell me what I am doing wrong? Or show me how 
 I can do it correctly?  My code is:

#!/usr/bin/env python
import vtk
import math
from vtk.util.colors import *

rMin=0.5
rMax=1.0
dims = [13,11,11]
size = dims[0]*dims[1]*dims[2]
points = vtk.vtkPoints()
points.Allocate(size,size)
  
deltaZ = 2.0 / (dims[2]-1)
deltaRad = (rMax-rMin) / (dims[1]-1)
x = [0.0, 0.0, 0.0]
for k in range(dims[2]):
    x[2] = -1.0 + k*deltaZ
    kOffset = k * dims[0] * dims[1]
    for j in range(dims[1]):
      radius = rMin + j*deltaRad
      jOffset = j * dims[0]
      for i in range(dims[0]):
        theta = i * 15.0 * vtk.vtkMath.DegreesToRadians()
        x[0] = radius * math.cos(theta)
        x[1] = radius * math.sin(theta)
        offset = i + jOffset + kOffset
        points.InsertPoint(offset,x)

  # Create the structured grid.
sgrid = vtk.vtkStructuredGrid()
sgrid.SetDimensions(dims)         # Set dimensions of grid
sgrid.SetPoints(points)           # Load data for grid point locations

mesh = vtk.vtkStructuredGridGeometryFilter()
mesh.SetInput(sgrid)

meshMapper = vtk.vtkPolyDataMapper()
meshMapper.SetInputConnection(mesh.GetOutputPort())
meshMapper.ScalarVisibilityOff()

meshActor = vtk.vtkActor()
meshActor.GetProperty().SetRepresentationToWireframe()
  # Create the usual rendering stuff
renderer = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

renderer.AddActor(meshActor)
renderer.SetBackground(1,1,1)
renderer.ResetCamera()
renderer.GetActiveCamera().Elevation(60.0)
renderer.GetActiveCamera().Azimuth(30.0)
renderer.GetActiveCamera().Zoom(1.25)
renWin.SetSize(600,600)

  # interact with data
renWin.Render()
iren.Start()



-- 
 ----------------------------------------------------------------------------
  F. Douglas Swesty
  Research Associate Professor
  Department of Physics and Astronomy, SUNY at Stony Brook

  email:  dswesty at mail.astro.sunysb.edu       
  www:    http://www.astro.sunysb.edu/dswesty
  phone:  (631)-632-8055           FAX:    (631)-632-1745

  Postal mail:   Dept. of Physics and Astronomy 
                 SUNY at Stony Brook
                 Stony Brook, NY 11794+3800

 ----------------------------------------------------------------------------





More information about the vtkusers mailing list