Thanks, that’s helpful.
My previous question is related to the attached script.
I’m able to load the data, and create a tube filter around it.
And I’m able to access the cell points which will allow me to find the line directions (although I haven’t done that below - I just created a quick colormap to test the color mapping).
But the ‘mapper’ and ‘renderer’ below don’t seem to do anything. The tube have no color still (just white).
Thanks for you help,
Larry
import math
import numpy as np
import vtk
print("\n ************ Programmable Filter ************\n")
pdi = self.GetPolyDataInput()
numPoints=pdi.GetNumberOfPoints()
print(“number of points = %d” %numPoints)
points = pdi.GetPoints()
numLines=pdi.GetNumberOfLines()
print(“number of lines = %d” %numLines)
lines = pdi.GetLines()
ncells = lines.GetNumberOfCells()
print(“number of cells = %d” %ncells)
n=5;
bounds = np.zeros(6)
for i in range(n):
curPt = points.GetPoint(i)
print i, curPt
cell = pdi.GetCell(i);
pdi.GetCellBounds(i,bounds)
print “i,cell,cellBounds=”, i, cell
#cellBounds = cell.GetBounds()
#print “i,cell,cellBounds=”, i, cell, cellBounds
print "bounds = "
for j in range(6):
print j,bounds[j]
RBG array (could add Alpha channel too I guess…)
Varying from blue to red
colors = vtk.vtkUnsignedCharArray()
colors.SetName(“Colors”);
colors.SetNumberOfComponents(3);
colors.SetNumberOfTuples(ncells);
for i in range(ncells):
colors.InsertTuple3(i,
int(255 * i/ (ncells - 1)),
0,
int(255 * (ncells - 1 - i)/(ncells - 1)) );
pdi.GetPointData().AddArray(colors);
Create tube filter
tubeFilter=vtk.vtkTubeFilter()
tubeFilter.SetDebug(1)
tubeFilter.SetInputData(pdi)
tubeFilter.SetRadius(0.25)
tubeFilter.SetNumberOfSides(50)
#tubeFilter.GetPointData().AddArray(colors);
print("\n*** vtkTubeFilter output:\n")
print tubeFilter
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(tubeFilter.GetOutputPort());
mapper.ScalarVisibilityOn();
mapper.SetScalarModeToUsePointFieldData();
mapper.SelectColorArray(“Colors”);
tubeFilter.Update()
actor = vtk.vtkActor()
actor.SetMapper(mapper)
pdo = self.GetOutputDataObject(0)
pdo.ShallowCopy(tubeFilter.GetOutput())
self.renderer = vtk.vtkRenderer()
self.renderer.AddActor(actor)