Bug description
canUseTextureMapForColoring in vtkMapper incorrectly returns true for cell data when an indexed lookup table is active.
The indexed lookup check is placed after the cell data shortcut that unconditionally returns true, so it is never reached.
This causes cell data + indexed LUT to take the texture mapping path, which generates NaN colors.
|
publicAPI.canUseTextureMapForColoring = (scalars, cellFlag) => { |
|
if (cellFlag && !(model.colorMode === ColorMode.DIRECT_SCALARS)) { |
|
return true; // cell data always use textures. |
|
} |
|
|
|
if (!model.interpolateScalarsBeforeMapping) { |
|
return false; // user doesn't want us to use texture maps at all. |
|
} |
|
|
|
// index color does not use textures |
|
if (model.lookupTable && model.lookupTable.getIndexedLookup()) { |
|
return false; |
|
} |
|
|
|
if (!scalars) { |
|
// no scalars on this dataset, we don't care if texture is used at all. |
|
return false; |
|
} |
|
|
|
if ( |
|
(model.colorMode === ColorMode.DEFAULT && |
|
scalars.getDataType() === VtkDataTypes.UNSIGNED_CHAR) || |
|
model.colorMode === ColorMode.DIRECT_SCALARS |
|
) { |
|
// Don't use texture is direct coloring using RGB unsigned chars is |
|
// requested. |
|
return false; |
|
} |
|
|
|
return true; |
|
}; |
Steps to reproduce
import vtkMapper from "@kitware/vtk.js/Rendering/Core/Mapper";
import vtkLookupTable from "@kitware/vtk.js/Common/Core/LookupTable";
import vtkPolyData from "@kitware/vtk.js/Common/DataModel/PolyData";
import vtkDataArray from "@kitware/vtk.js/Common/Core/DataArray";
import {
ColorMode,
ScalarMode,
} from "@kitware/vtk.js/Rendering/Core/Mapper/Constants";
const polydata = vtkPolyData.newInstance();
polydata
.getCellData()
.setScalars(
vtkDataArray.newInstance({
name: "Categories",
values: new Uint8Array([0, 1, 2, 3, 0, 1]),
})
);
const lut = vtkLookupTable.newInstance();
lut.setNumberOfColors(4);
lut.build();
lut.setIndexedLookup(true);
lut.setAnnotations(["0", "1", "2", "3"], ["Cat0", "Cat1", "Cat2", "Cat3"]);
const mapper = vtkMapper.newInstance({
scalarMode: ScalarMode.USE_CELL_DATA,
colorMode: ColorMode.MAP_SCALARS,
});
mapper.setInputData(polydata);
mapper.setLookupTable(lut);
mapper.mapScalars(polydata, 1.0);
console.log(mapper.getColorMapColors()); // BUG: null (texture path nulled it)
console.log(mapper.getColorTextureMap()); // BUG: non null (texture was created)
Detailed Behavior
canUseTextureMapForColoring returns true (cell data shortcut fires first)
mapScalarsToTexture is called, which:
- Sets
colorMapColors = null
- Creates a texture from a ramp of float values mapped through the LUT
- Since indexed LUT is active, the float ramp values don't match any annotation strings which returns NaN color.
Expected Behavior
// Expected output:
console.log(mapper.getColorMapColors()); // non null
console.log(mapper.getColorTextureMap()); // null
Environment
- vtk.js version:
- Browsers:
- OS:
Bug description
canUseTextureMapForColoringinvtkMapperincorrectly returnstruefor cell data when an indexed lookup table is active.The indexed lookup check is placed after the cell data shortcut that unconditionally returns
true, so it is never reached.This causes cell data + indexed LUT to take the texture mapping path, which generates NaN colors.
vtk-js/Sources/Rendering/Core/Mapper/index.js
Lines 616 to 646 in f3cfe26
Steps to reproduce
Detailed Behavior
canUseTextureMapForColoringreturnstrue(cell data shortcut fires first)mapScalarsToTextureis called, which:colorMapColors = nullExpected Behavior
Environment