Skip to content

Commit 3054982

Browse files
committed
feat(Mapper): Always use textures for cell data coloring
The rendering result is the same at almost no cost But you can change the color map without reuploading the whole VBO when it has the same range
1 parent abe9269 commit 3054982

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

Examples/Applications/GeometryViewer/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ function createPipeline(fileName, fileContents) {
270270

271271
const lookupTable = vtkColorTransferFunction.newInstance();
272272
const source = vtpReader.getOutputData(0);
273+
// interpolateScalarsBeforeMapping is only used when displaying point data
274+
// This setting is not relevant for cell data
273275
const mapper = vtkMapper.newInstance({
274276
interpolateScalarsBeforeMapping: true,
275277
useLookupTableScalarRange: true,

Sources/Rendering/Core/Mapper/index.d.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface IPrimitiveCount {
1414

1515
interface IAbstractScalars {
1616
cellFlag: boolean;
17+
scalars: Nullable<vtkDataArray>;
1718
}
1819

1920
interface ICoincidentTopology {
@@ -55,9 +56,13 @@ export interface vtkMapper extends vtkAbstractMapper3D {
5556
* When rendering multiblock datasets, if any 2 blocks provide different
5657
* lookup tables for the scalars, then also we cannot use textures. This case
5758
* can be handled if required.
58-
* @param input
59+
* @param scalars
60+
* @param cellFlag True when the scalars are per cell instead of per point
5961
*/
60-
canUseTextureMapForColoring(input: any): boolean;
62+
canUseTextureMapForColoring(
63+
scalars: vtkDataArray,
64+
cellFlag: boolean
65+
): boolean;
6166

6267
/**
6368
* Call to force a rebuild of color result arrays on next MapScalars.

Sources/Rendering/Core/Mapper/index.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function vtkMapper(publicAPI, model) {
165165
// Decide between texture color or vertex color.
166166
// Cell data always uses vertex color.
167167
// Only point data can use both texture and vertex coloring.
168-
if (publicAPI.canUseTextureMapForColoring(input)) {
168+
if (publicAPI.canUseTextureMapForColoring(scalars, cellFlag)) {
169169
publicAPI.mapScalarsToTexture(scalars, alpha);
170170
} else {
171171
model.colorCoordinates = null;
@@ -413,7 +413,11 @@ function vtkMapper(publicAPI, model) {
413413
return true;
414414
};
415415

416-
publicAPI.canUseTextureMapForColoring = (input) => {
416+
publicAPI.canUseTextureMapForColoring = (scalars, cellFlag) => {
417+
if (cellFlag) {
418+
return true; // cell data always use textures.
419+
}
420+
417421
if (!model.interpolateScalarsBeforeMapping) {
418422
return false; // user doesn't want us to use texture maps at all.
419423
}
@@ -423,15 +427,6 @@ function vtkMapper(publicAPI, model) {
423427
return false;
424428
}
425429

426-
const gasResult = publicAPI.getAbstractScalars(
427-
input,
428-
model.scalarMode,
429-
model.arrayAccessMode,
430-
model.arrayId,
431-
model.colorByArrayName
432-
);
433-
const scalars = gasResult.scalars;
434-
435430
if (!scalars) {
436431
// no scalars on this dataset, we don't care if texture is used at all.
437432
return false;

Sources/Rendering/OpenGL/PolyDataMapper/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
198198
).result;
199199
} else {
200200
if (
201-
model.renderable.getInterpolateScalarsBeforeMapping() &&
201+
(model.renderable.getAreScalarsMappedFromCells() ||
202+
model.renderable.getInterpolateScalarsBeforeMapping()) &&
202203
model.renderable.getColorCoordinates() &&
203204
!model.drawingEdges
204205
) {

0 commit comments

Comments
 (0)