[vtkusers] Visualizing Points

Randy Heiland heiland at ncsa.uiuc.edu
Fri Jun 7 10:34:05 EDT 2002


Here's a self-contained Python example (using vtk 4.x) that offers one
technique:

--Randy

#
# python torus.py
#
from libvtkCommonPython import *
from libvtkGraphicsPython import *
from libvtkRenderingPython import *
from libvtkImagingPython import *
from math import *

ren = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

points = vtkPoints()
npts = 20  # pts per big and small radii
totpts = npts*npts

# Scalars assoc'd with each point
sval = vtkFloatArray()
sval.SetNumberOfTuples(totpts)

points.SetNumberOfPoints( totpts )
c = 2
a = 0.5
k = 0
delta = 2*3.1415 / (npts-1)
# rf.  http://mathworld.wolfram.com/Torus.html
for iv in range(0,npts):
  v = iv*delta
  zval = a*sin(v)
  const = c + a*cos(v)
  for iu in range(0,npts):
    u = iu*delta
    points.InsertPoint(k, const*cos(u), const*sin(u), zval)
    sval.SetValue(k, zval)
    k = k+1

print 'sval range = ',sval.GetRange()

verts = vtkCellArray()
for i in range(0,totpts):
  verts.InsertNextCell( 1 )
  verts.InsertCellPoint( i )

pd = vtkPolyData()
pd.SetPoints( points )
pd.SetVerts( verts )
pd.GetPointData().SetScalars(sval)
pd.Update()
print 'pd range = ',pd.GetPointData().GetScalars().GetRange()

pdMapper = vtkPolyDataMapper()
pdMapper.SetInput(pd)
actor = vtkActor()
actor.SetMapper(pdMapper)

surf = vtkDelaunay3D()
surf.SetInput(pd)
surf.SetAlpha(0.5)

mapper = vtkDataSetMapper()
mapper.SetInput(surf.GetOutput())
mapper.ScalarVisibilityOn()
mapper.SetScalarModeToUsePointData()
mapper.SetColorModeToMapScalars()
mapper.SetScalarRange( -.5, .5)

surfActor = vtkActor()
surfActor.SetMapper(mapper)

ren.AddActor(actor)
ren.AddActor(surfActor)

renWin.Render()
iren.Start()



On Jun 7, 10:04am, Christian Pfaffel wrote:
> Subject: [vtkusers] Visualizing Points
> Hello,
>
> I have a rather simple problem, I think at least. I have a dataset
> consisting of x,y,z coordinates (forming a torus) with a scalar value
> (Magnetic Field) assigned.
> I want to show the surface(and cuts), mapped to
> colors according to its magnetic value. I do not know though which filters
> to use. I have tried to use something like this:
>
> -----------
> bfield = vtkFloatArray()
> points = vtkPoints()
>
> #filling up bfield and points with values
> [...]
>
> bfield.CreateDefaultLookupTable()
> grid = vtkPolyData()
> grid.SetPoints(points)
> grid.GetPointData().SetScalars(bfield)
>
> mapper = vtkDataSetMapper()
> mapper.SetInput(grid)
> mapper.SetLookupTable(bfield.GetLookupTable())
> mapper.SetScalarRange(0,2)
>
> actor = vtkActor()
> actor.SetMapper(mapper)
>
> renderer = vtkRenderer()
> renderer.AddActor(actor)
> renderer.SetBackground(1,1,1)
> renwin = vtkRenderWindow()
> renwin.AddRenderer(renderer)
> iren = vtkRenderWindowInteractor()
> iren.SetRenderWindow(renwin)
> iren.Initialize()
> iren.Start()
>
> ----------
>
> The problem is, I have browsed the example source codes, looked in the
> "VTK Users's Guide", but there never is an example given that shows how to
> make a "surfaceplot".
>
> Any help will be appreciated
>
> regards,
> Christian Pfaffel



More information about the vtkusers mailing list