Skip to content

[Bug] canUseTextureMapForColoring returns true for cell data with indexed LUT #3509

@daker

Description

@daker

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:
    1. Sets colorMapColors = null
    2. Creates a texture from a ramp of float values mapped through the LUT
    3. 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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions