Skip to content

Commit 33a8ebc

Browse files
committed
feat(mapper): allow control over coordinate precision shifting and scaling
Introduces the `(set|get)CoordinateShiftScaleEnabled` property to `vtkMapper` and its subclasses. This new property provides an API to explicitly enable/disable the automatic coordinate shifting and scaling mechanism within polydata mappers, which is typically used to improve rendering precision for geometry with large coordinate values. fix #3330
1 parent b5f6856 commit 33a8ebc

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export interface IMapperInitialValues extends IAbstractMapper3DInitialValues {
3535
interpolateScalarsBeforeMapping?: boolean;
3636
forceCompileOnly?: number;
3737
useInvertibleColors?: boolean;
38+
coordShiftScaleEnabled?: boolean;
3839
customShaderAttributes?: any;
3940
}
4041

@@ -467,6 +468,17 @@ export interface vtkMapper
467468
setInterpolateScalarsBeforeMapping(
468469
interpolateScalarsBeforeMapping: boolean
469470
): boolean;
471+
472+
/**
473+
* Control whether the mapper should automatically shift and scale
474+
* the coordinates to improve precision. This is enabled by default.
475+
*
476+
* @param {Boolean} coordShiftScaleEnabled
477+
* @default true
478+
*/
479+
setCoordShiftScaleEnabled(
480+
coordShiftScaleEnabled: boolean
481+
): boolean;
470482
}
471483

472484
/**

Sources/Rendering/Core/Mapper/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ const DEFAULT_VALUES = {
794794
invertibleScalars: null,
795795

796796
customShaderAttributes: [],
797+
798+
coordShiftScaleEnabled: true,
797799
};
798800

799801
// ----------------------------------------------------------------------------
@@ -825,6 +827,7 @@ export function extend(publicAPI, model, initialValues = {}) {
825827
'scalarVisibility',
826828
'static',
827829
'useLookupTableScalarRange',
830+
'coordShiftScaleEnabled',
828831
'customShaderAttributes', // point data array names that will be transferred to the VBO
829832
]);
830833
macro.setGetArray(publicAPI, model, ['scalarRange'], 2);

Sources/Rendering/OpenGL/Glyph3DMapper/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,14 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
694694
const garray = model.renderable.getMatrixArray();
695695

696696
const pts = model.renderable.getInputData(0).getPoints();
697-
const { useShiftAndScale, coordShift, coordScale } =
698-
computeCoordShiftAndScale(pts);
697+
let useShiftAndScale = false;
698+
let coordShift = 0.0;
699+
let coordScale = 1.0;
700+
701+
if (model.coordShiftAndScaleEnabled && pts) {
702+
({ useShiftAndScale, coordShift, coordScale } =
703+
computeCoordShiftAndScale(pts));
704+
}
699705

700706
if (model.hardwareSupport) {
701707
// update the buffer objects if needed

Sources/Rendering/OpenGL/PolyDataMapper/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,9 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
12581258
const numClipPlanes = model.renderable.getNumberOfClippingPlanes();
12591259
const planeEquations = [];
12601260

1261-
const shiftScaleEnabled = cellBO.getCABO().getCoordShiftAndScaleEnabled();
1261+
const shiftScaleEnabled =
1262+
model.renderable.coordShiftScaleEnabled &&
1263+
cellBO.getCABO().getCoordShiftAndScaleEnabled();
12621264
const inverseShiftScaleMatrix = shiftScaleEnabled
12631265
? cellBO.getCABO().getInverseShiftAndScaleMatrix()
12641266
: null;
@@ -1460,7 +1462,9 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
14601462
const camm = model.openGLCamera.getKeyMatrixTime().getMTime();
14611463
const progm = program.getLastCameraMTime();
14621464

1463-
const shiftScaleEnabled = cellBO.getCABO().getCoordShiftAndScaleEnabled();
1465+
const shiftScaleEnabled =
1466+
model.renderable.coordShiftScaleEnabled &&
1467+
cellBO.getCABO().getCoordShiftAndScaleEnabled();
14641468
const inverseShiftScaleMatrix = shiftScaleEnabled
14651469
? cellBO.getCABO().getInverseShiftAndScaleMatrix()
14661470
: null;
@@ -2018,7 +2022,7 @@ export function extend(publicAPI, model, initialValues = {}) {
20182022
}
20192023

20202024
// Build VTK API
2021-
macro.setGet(publicAPI, model, ['context']);
2025+
macro.setGet(publicAPI, model, ['context', 'coordShiftScaleEnabled']);
20222026

20232027
model.VBOBuildTime = {};
20242028
macro.obj(model.VBOBuildTime, { mtime: 0 });

0 commit comments

Comments
 (0)