Hi,
I have been trying to vary the radius of a tube using celldata in vtk.js without success (Tubefilter: unable to use cellData with varyRadius).
To better understand the celldata output of the vtk.js tubefilter I have written the below code, to compare the input and output of the tubefilter.
The output array is different from the input array in terms of number of elements, as well as the values of the elements. The names of the input arrays are also not preserved in the output arrays. This suggests to me that the tubefilter has a bug when dealing with celldata
import vtk from '@kitware/vtk.js/vtk';
import vtkTubeFilter from '@kitware/vtk.js/Filters/General/TubeFilter';
// Need polydata registered in the vtk factory
import '@kitware/vtk.js/Common/Core/Points';
import '@kitware/vtk.js/Common/Core/DataArray';
import '@kitware/vtk.js/Common/Core/CellArray';
import '@kitware/vtk.js/Common/Core/StringArray';
import '@kitware/vtk.js/Common/DataModel/PolyData';
export default () => {
const polydata = vtk({
vtkClass: 'vtkPolyData',
points: {
vtkClass: 'vtkPoints',
dataType: 'Float32Array',
numberOfComponents: 3,
values: [
0, 0, 0,
1, 0, 0.25,
1, 1, 0,
0, 1, 0.25,
],
},
lines: {
vtkClass: 'vtkCellArray',
dataType: 'Uint16Array',
values: [
2, 0, 1,
2, 1, 2,
2, 2, 3,
],
},
pointData: {
vtkClass: 'vtkDataSetAttributes',
activeScalars: 0,
arrays: [
{
data: {
vtkClass: 'vtkDataArray',
name: 'head',
dataType: 'Float32Array',
values: [0, 1, 1, 2],
},
},
{
data: {
vtkClass: 'vtkDataArray',
name: 'elevation',
dataType: 'Float32Array',
values: [1, 2, 3, 4],
},
},
{
data: {
vtkClass: 'vtkDataArray',
name: 'pressure',
dataType: 'Float32Array',
values: [2, 0, 0, 2],
},
},
],
},
cellData: {
vtkClass: 'vtkDataSetAttributes',
activeScalars: 0,
arrays: [
{
data: {
vtkClass: 'vtkDataArray',
name: 'diameter',
dataType: 'Float32Array',
values: [1, 2, 3],
},
},
{
data: {
vtkClass: 'vtkDataArray',
name: 'flow',
dataType: 'Float32Array',
values: [2, 1, 2],
},
},
],
},
});
const tubeFilter = vtkTubeFilter.newInstance();
tubeFilter.setInputData(polydata)
global.polydata = polydata
global.tubeFilter = tubeFilter
when I query the polydata and tubefilter outputs on the console I get the following contradictory results between the polydata and the tubefilter output:
>>polydata.getCellData().getNumberOfArrays()
2
>>polydata.getCellData().getArrayName('diameter').getData()
Uncaught TypeError: polydata.getCellData().getArrayName(...).getData is not a function
<anonymous> debugger eval code:1
debugger eval code:1:49
>>polydata.getCellData().getArrays()[0].getData()
Float32Array(3) [ 1, 2, 3 ]
>>polydata.getCellData().getArrays()[1].getData()
Float32Array(3) [ 2, 1, 2 ]
>>tubeFilter.getOutputData().getCellData().getNumberOfArrays()
2
>>tubeFilter.getOutputData().getCellData().getArrayByName('diameter').getData()
Float32Array(9) [ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
>>tubeFilter.getOutputData().getCellData().getArrays()[0].getData()
Float32Array(9) [ 2, 2, 2, 1, 1, 1, 2, 2, 2 ]
>>tubeFilter.getOutputData().getCellData().getArrays()[1].getData()
Float32Array(9) [ 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
Is this a bug or am I misunderstanding the output of the tubefilter?