[vtkusers] Adding and coloring data to a vtkLineSource

kenichiro yoshimi rccm.kyoshimi at gmail.com
Fri Oct 5 06:59:43 EDT 2018


Hi,

vtkLineSource creates a polyline with n points. Consequently, it
outputs a single cell and the computed cell data contains just one
value and you cannot get the colormap for this. Since there are
multiple points, the point data should be used in stead of the cell
data.

Regards
2018年10月5日(金) 0:45 Andrew E. Slaughter via vtkusers
<vtkusers at public.kitware.com>:
>
> I am trying to create a line that includes “data” along the axis, one value for each cell. However, I cannot get the colormap to show the data. I have attached the script, I would greatly appreciate help getting this working.
>
>
>
> I am using python bindings to VTK7.1 on MacOS.
>
>
>
> Thank you,
>
>
>
> Andrew
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
-------------- next part --------------
#!/usr/bin/env python
import vtk

n = 10        # Number of data points to create
name = "data" # Name of data array generated

# A Line
source = vtk.vtkLineSource()
source.SetResolution(n-1)
source.SetPoint1(0, 0, 0)
source.SetPoint2(0, 1, 0)

# Create and apply nonlinear data along the line
data = vtk.vtkFloatArray()
data.SetName(name)
data.SetNumberOfTuples(n)
for i in xrange(n):
    data.SetValue(i, i*i)

source.Update()
source.GetOutput().GetPointData().AddArray(data)

# Build a tube
tube = vtk.vtkTubeFilter()
tube.SetInputData(source.GetOutput())
tube.SetRadius(0.2)
tube.SetNumberOfSides(100)
tube.SetCapping(True)
tube.Update()

range = tube.GetOutput().GetPointData().GetArray(name).GetRange()

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(tube.GetOutputPort())
mapper.SelectColorArray(name)
mapper.SetScalarModeToUsePointFieldData()
mapper.InterpolateScalarsBeforeMappingOn()
mapper.SetScalarRange(range)

actor = vtk.vtkActor()
actor.SetMapper(mapper)

renderer = vtk.vtkRenderer()
renderer.AddActor(actor)

window = vtk.vtkRenderWindow()
window.AddRenderer(renderer)
window.SetSize(500, 500)

interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(window)
interactor.Initialize()

window.Render()
interactor.Start()


More information about the vtkusers mailing list