[vtkusers] tube filter with varying radius along spline

John Hunter jdhunter at ace.bsd.uchicago.edu
Thu Oct 9 09:18:40 EDT 2003


I am trying to use a vtkTubeFilter along a spline curve where the
radius of the tube and/or the color of the tube vary with the spline
independent variable (t in the example below).  I am not sure how to
achieve this.  Below is a script which I have been using for testing,
but all the vary radius and vary color calls have been without effect.
I think this is because I do not have the scalar data set properly,
but am not sure how to proceed.  I have looked at the officeTube
example and the streamline example from the VTK textbook, but haven't
been able to adapt these to my case.  Here is the example, any
suggestions will be much appreciated.

import vtk

numberOfInputPoints = 3

# One spline for each direction.
aSplineX = vtk.vtkCardinalSpline()
aSplineY = vtk.vtkCardinalSpline()
aSplineZ = vtk.vtkCardinalSpline()

inputPoints = vtk.vtkPoints()

aSplineX.AddPoint(0, 0)
aSplineY.AddPoint(0, 0)
aSplineZ.AddPoint(0, 0)
inputPoints.InsertPoint(0, 0, 0, 0)

aSplineX.AddPoint(1, 1)
aSplineY.AddPoint(1, 1)
aSplineZ.AddPoint(1, 0)
inputPoints.InsertPoint(1, 1, 1, 0)

aSplineX.AddPoint(2, 2)
aSplineY.AddPoint(2, 4)
aSplineZ.AddPoint(2, 0)
inputPoints.InsertPoint(2, 2, 4, 0)


# Generate the polyline for the spline.
points = vtk.vtkPoints()
profileData = vtk.vtkPolyData()

# Number of points on the spline
numberOfOutputPoints = 40

# Interpolate x, y and z by using the three spline filters and
# create new points
for i in range(numberOfOutputPoints):
    t = (numberOfInputPoints-1.0)/(numberOfOutputPoints-1.0)*i
    points.InsertPoint(i, aSplineX.Evaluate(t), aSplineY.Evaluate(t),
                       aSplineZ.Evaluate(t))

# Create the polyline.
lines = vtk.vtkCellArray()
lines.InsertNextCell(numberOfOutputPoints)
for i in range(numberOfOutputPoints):
    lines.InsertCellPoint(i)
 
profileData.SetPoints(points)
profileData.SetLines(lines)

# Add thickness to the resulting line.
profileTubes = vtk.vtkTubeFilter()
profileTubes.SetNumberOfSides(8)
profileTubes.SetInput(profileData)
profileTubes.SetRadius(.01)
profileTubes.SetRadiusFactor(10000)
profileTubes.SetVaryRadiusToVaryRadiusByScalar()  #??

profileMapper = vtk.vtkPolyDataMapper()
profileMapper.SetInput(profileTubes.GetOutput())
profileMapper.SetScalarModeToUsePointData ()
profileMapper.SetScalarRange(0,2)    # ??
profileMapper.ScalarVisibilityOn()
profileMapper.SetColorModeToMapScalars()

profile = vtk.vtkActor()
profile.SetMapper(profileMapper)
profile.GetProperty().SetSpecular(.3)
profile.GetProperty().SetSpecularPower(30)

# Now create the RenderWindow, Renderer and Interactor
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)

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

# Add the actors
ren.AddActor(profile)

renWin.SetSize(500, 500)

iren.Initialize()
renWin.Render()
iren.Start()


Thanks,
John Hunter 



More information about the vtkusers mailing list