I am trying to use the tube filter but instead of using point data to color the tubes, use cell data instead. However, when I have it use cell data, the color just won’t show up. I am just using this example and building from it
Inside add representation, I tried to see what the cell data is coming out of the tube filter
and it displayed [0.2,0.2,0.2,0.2]. So somehow only the first value from my cell data got passed through so I feel like I definitely invoked something wrong.
Here is my code
function addRepresentation(name, filter, props = {}) {
const mapper = vtkMapper.newInstance();
if (filter.isA('vtkPolyData')) {
mapper.setInputData(filter);
} else {
mapper.setInputConnection(filter.getOutputPort());
console.log(filter.getOutputData().getCellData().getArrays()[0].getData())
mapper.setColorModeToMapScalars();
mapper.setScalarVisibility(true)
}
const actor =vtkActor.newInstance();
actor.setMapper(mapper);
actor.getProperty().set(props);
renderer.addActor(actor);
return actor
}
vtkMath.randomSeed(15222);
const numSegments = 4;
function initializePolyData() {
const polyData = vtkPolyData.newInstance();
const points = vtkPoints.newInstance();
points.setNumberOfPoints(numSegments + 1);
var pointData = new Float32Array(3 * (numSegments + 1));
var verts = new Uint32Array(2 * (numSegments + 1));
var lines = new Uint32Array(numSegments + 2);
var scalarsData = new Float32Array(numSegments + 1);
for (let i = 0; i <= numSegments + 1; ++i) {
verts[i] = 1;
verts[i + 1] = i;
}
scalarsData= [0.2,0.4,0.6,0.8];
const scalars = vtkDataArray.newInstance({
name: 'Scalars',
values: scalarsData,
});
lines = [2,0,1,2,2,3,2,4,5,2,6,7];
pointData = [0,0,1,0,0,2,1,0,1,1,0,2,2,0,1,2,0,2,3,0,1,3,0,2]
points.setData(pointData);
console.log(pointData);
console.log(lines);
console.log(scalarsData);
polyData.setPoints(points);
polyData.getLines().setData(lines);
polyData.getCellData().setScalars(scalars);
return polyData;
}
// ----------------------------------------------------------------------------
const polyData = initializePolyData();
const tubeFilter = vtkTubeFilter.newInstance();
tubeFilter.setCapping(false);
tubeFilter.setNumberOfSides(50);
tubeFilter.setRadius(0.1);
tubeFilter.setInputData(polyData);
console.log(tubeFilter);
tubeFilter.setInputArrayToProcess(0, 'Scalars', 'CellData', 'Scalars');
const polyActor = addRepresentation('polyData', polyData, {});
const tubeActor = addRepresentation('tubeFilter', tubeFilter, {});
renderer.resetCamera();
renderWindow.render();