[vtkusers] grid lines for structured grid?

Ed Bachta ebachta at gmail.com
Fri Jul 7 09:11:59 EDT 2006


Hello Doug,

Your points are being rendered white, which happens to be your background
color. If you change your background color to something dark, you will see
the points of your mesh. You could also extract a slice along each dimension
of the mesh, which might give you something more along the lines of what
you're looking for:

#!/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


outline = vtk.vtkOutlineFilter()
outline.SetInput(sgrid)

outline_mapper = vtk.vtkPolyDataMapper()
outline_mapper.SetInputConnection(outline.GetOutputPort())

outline_actor = vtk.vtkActor()
outline_actor.SetMapper(outline_mapper)

def createMeshActor(imin, imax, jmin, jmax, kmin, kmax):

    mesh = vtk.vtkStructuredGridGeometryFilter()
    mesh.SetInput(sgrid)
    mesh.SetExtent(imin, imax, jmin, jmax, kmin, kmax)

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

    meshActor = vtk.vtkActor()
    meshActor.SetMapper(meshMapper)
    meshActor.GetProperty().SetRepresentationToWireframe()

    return meshActor

 # Create the usual rendering stuff
n = 0
renderer = vtk.vtkRenderer()
renderer.AddActor(createMeshActor(n,n,0,dims[1],0,dims[2]))
renderer.AddActor(createMeshActor(0,dims[0],n,n,0,dims[2]))
renderer.AddActor(createMeshActor(0,dims[0],0,dims[1],n,n))

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(renderer)

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

#renderer.AddActor(outline_actor)

renderer.SetBackground(0.25,0.25,0.5)
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()



-- 
Ed Bachta
Visualization and Interactive Spaces
Pervasive Tech Labs at Indiana University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060707/2ef907bf/attachment.htm>


More information about the vtkusers mailing list