@kitware/vtk.js 33.0.0-beta.3 → 33.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/Core/DataArray.d.ts +17 -0
- package/Common/Core/DataArray.js +36 -0
- package/Rendering/Core/AbstractImageMapper.d.ts +81 -0
- package/Rendering/Core/AbstractImageMapper.js +5 -2
- package/Rendering/Core/AbstractPicker.d.ts +13 -13
- package/Rendering/Core/AbstractPicker.js +1 -1
- package/Rendering/Core/Actor2D.d.ts +22 -0
- package/Rendering/Core/Actor2D.js +1 -1
- package/Rendering/Core/CellPicker.js +4 -1
- package/Rendering/Core/ImageCPRMapper.js +5 -4
- package/Rendering/Core/ImageProperty.d.ts +20 -1
- package/Rendering/Core/ImageProperty.js +7 -5
- package/Rendering/Core/ImageResliceMapper.d.ts +1 -2
- package/Rendering/Core/ImageResliceMapper.js +5 -4
- package/Rendering/Core/Viewport.js +13 -3
- package/Rendering/Core/VolumeMapper.d.ts +70 -0
- package/Rendering/Core/VolumeMapper.js +10 -5
- package/Rendering/Core/VolumeProperty.d.ts +20 -1
- package/Rendering/Core/VolumeProperty.js +7 -5
- package/Rendering/Misc/SynchronizableRenderWindow/BehaviorManager/CameraSynchronizer.js +2 -2
- package/Rendering/OpenGL/ImageCPRMapper.js +18 -2
- package/Rendering/OpenGL/ImageMapper.js +28 -4
- package/Rendering/OpenGL/ImageResliceMapper.js +20 -4
- package/Rendering/OpenGL/Renderer.js +1 -1
- package/Rendering/OpenGL/Texture.d.ts +29 -8
- package/Rendering/OpenGL/Texture.js +154 -23
- package/Rendering/OpenGL/VolumeMapper.js +22 -4
- package/Rendering/SceneGraph/ViewNode.js +12 -2
- package/Rendering/WebXR/RenderWindowHelper.js +9 -0
- package/Widgets/Core/WidgetManager.d.ts +12 -1
- package/Widgets/Representations/WidgetRepresentation.d.ts +1 -7
- package/Widgets/Widgets3D/ResliceCursorWidget.d.ts +1 -8
- package/package.json +11 -11
|
@@ -228,7 +228,7 @@ function vtkVolumeProperty(publicAPI, model) {
|
|
|
228
228
|
// Object factory
|
|
229
229
|
// ----------------------------------------------------------------------------
|
|
230
230
|
|
|
231
|
-
const
|
|
231
|
+
const defaultValues = initialValues => ({
|
|
232
232
|
colorMixPreset: ColorMixPreset.DEFAULT,
|
|
233
233
|
independentComponents: true,
|
|
234
234
|
interpolationType: InterpolationType.FAST_LINEAR,
|
|
@@ -254,14 +254,16 @@ const DEFAULT_VALUES = {
|
|
|
254
254
|
// local ambient occlusion
|
|
255
255
|
localAmbientOcclusion: false,
|
|
256
256
|
LAOKernelSize: 15,
|
|
257
|
-
LAOKernelRadius: 7
|
|
258
|
-
|
|
257
|
+
LAOKernelRadius: 7,
|
|
258
|
+
updatedExtents: [],
|
|
259
|
+
...initialValues
|
|
260
|
+
});
|
|
259
261
|
|
|
260
262
|
// ----------------------------------------------------------------------------
|
|
261
263
|
|
|
262
264
|
function extend(publicAPI, model) {
|
|
263
265
|
let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
264
|
-
Object.assign(model,
|
|
266
|
+
Object.assign(model, defaultValues(initialValues));
|
|
265
267
|
|
|
266
268
|
// Build VTK API
|
|
267
269
|
macro.obj(publicAPI, model);
|
|
@@ -287,7 +289,7 @@ function extend(publicAPI, model) {
|
|
|
287
289
|
}
|
|
288
290
|
macro.setGet(publicAPI, model, ['colorMixPreset', 'independentComponents', 'interpolationType', 'shade', 'ambient', 'diffuse', 'specular', 'specularPower', 'useLabelOutline', 'labelOutlineOpacity',
|
|
289
291
|
// Properties moved from volume mapper
|
|
290
|
-
'filterMode', 'preferSizeOverAccuracy', 'computeNormalFromOpacity', 'volumetricScatteringBlending', 'globalIlluminationReach', 'anisotropy', 'localAmbientOcclusion', 'LAOKernelSize', 'LAOKernelRadius']);
|
|
292
|
+
'filterMode', 'preferSizeOverAccuracy', 'computeNormalFromOpacity', 'volumetricScatteringBlending', 'globalIlluminationReach', 'anisotropy', 'localAmbientOcclusion', 'LAOKernelSize', 'LAOKernelRadius', 'updatedExtents']);
|
|
291
293
|
|
|
292
294
|
// Property moved from volume mapper
|
|
293
295
|
macro.setGetArray(publicAPI, model, ['ipScalarRange'], 2);
|
|
@@ -33,8 +33,8 @@ function vtkCameraSynchronizer(publicAPI, model) {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// Update listeners automatically
|
|
36
|
-
model.
|
|
37
|
-
model.
|
|
36
|
+
model._onSrcRendererChanged = updateListeners;
|
|
37
|
+
model._onDstRendererChanged = updateListeners;
|
|
38
38
|
function updatePreviousValues(position, focalPoint, viewUp) {
|
|
39
39
|
if (cameraState[0] !== position[0] || cameraState[1] !== position[1] || cameraState[2] !== position[2] || cameraState[3] !== focalPoint[0] || cameraState[4] !== focalPoint[1] || cameraState[5] !== focalPoint[2] || cameraState[6] !== viewUp[0] || cameraState[7] !== viewUp[1] || cameraState[8] !== viewUp[2]) {
|
|
40
40
|
cameraState[0] = position[0];
|
|
@@ -147,6 +147,7 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
|
|
|
147
147
|
publicAPI.buildBufferObjects = (ren, actor) => {
|
|
148
148
|
const image = model.currentImageDataInput;
|
|
149
149
|
const centerline = model.currentCenterlineInput;
|
|
150
|
+
const property = actor.getProperty();
|
|
150
151
|
|
|
151
152
|
// Rebuild the volumeTexture if the data has changed
|
|
152
153
|
const scalars = image?.getPointData()?.getScalars();
|
|
@@ -156,6 +157,8 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
|
|
|
156
157
|
const cachedScalarsEntry = model._openGLRenderWindow.getGraphicsResourceForObject(scalars);
|
|
157
158
|
const volumeTextureHash = getImageDataHash(image, scalars);
|
|
158
159
|
const reBuildTex = !cachedScalarsEntry?.oglObject?.getHandle() || cachedScalarsEntry?.hash !== volumeTextureHash;
|
|
160
|
+
const updatedExtents = property.getUpdatedExtents();
|
|
161
|
+
const hasUpdatedExtents = !!updatedExtents.length;
|
|
159
162
|
if (reBuildTex) {
|
|
160
163
|
model.volumeTexture = vtkOpenGLTexture.newInstance();
|
|
161
164
|
model.volumeTexture.setOpenGLRenderWindow(model._openGLRenderWindow);
|
|
@@ -174,6 +177,13 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
|
|
|
174
177
|
} else {
|
|
175
178
|
model.volumeTexture = cachedScalarsEntry.oglObject;
|
|
176
179
|
}
|
|
180
|
+
if (hasUpdatedExtents) {
|
|
181
|
+
// If hasUpdatedExtents, then the texture is partially updated.
|
|
182
|
+
// clear the array to acknowledge the update.
|
|
183
|
+
property.setUpdatedExtents([]);
|
|
184
|
+
const dims = image.getDimensions();
|
|
185
|
+
model.volumeTexture.create3DFilterableFromDataArray(dims[0], dims[1], dims[2], scalars, false, updatedExtents);
|
|
186
|
+
}
|
|
177
187
|
|
|
178
188
|
// Rebuild the color texture if needed
|
|
179
189
|
const numComp = scalars.getNumberOfComponents();
|
|
@@ -190,7 +200,10 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
|
|
|
190
200
|
const cachedColorEntry = model._openGLRenderWindow.getGraphicsResourceForObject(firstColorTransferFunc);
|
|
191
201
|
const reBuildColorTexture = !cachedColorEntry?.oglObject?.getHandle() || cachedColorEntry?.hash !== colorTextureHash;
|
|
192
202
|
if (reBuildColorTexture) {
|
|
193
|
-
|
|
203
|
+
let cWidth = model.renderable.getColorTextureWidth();
|
|
204
|
+
if (cWidth <= 0) {
|
|
205
|
+
cWidth = model.context.getParameter(model.context.MAX_TEXTURE_SIZE);
|
|
206
|
+
}
|
|
194
207
|
const cSize = cWidth * textureHeight * 3;
|
|
195
208
|
const cTable = new Uint8ClampedArray(cSize);
|
|
196
209
|
model.colorTexture = vtkOpenGLTexture.newInstance();
|
|
@@ -247,7 +260,10 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
|
|
|
247
260
|
const cachedPwfEntry = model._openGLRenderWindow.getGraphicsResourceForObject(firstPwFunc);
|
|
248
261
|
const reBuildPwf = !cachedPwfEntry?.oglObject?.getHandle() || cachedPwfEntry?.hash !== pwfTextureHash;
|
|
249
262
|
if (reBuildPwf) {
|
|
250
|
-
|
|
263
|
+
let pwfWidth = model.renderable.getOpacityTextureWidth();
|
|
264
|
+
if (pwfWidth <= 0) {
|
|
265
|
+
pwfWidth = model.context.getParameter(model.context.MAX_TEXTURE_SIZE);
|
|
266
|
+
}
|
|
251
267
|
const pwfSize = pwfWidth * textureHeight;
|
|
252
268
|
const pwfTable = new Uint8ClampedArray(pwfSize);
|
|
253
269
|
model.pwfTexture = vtkOpenGLTexture.newInstance();
|
|
@@ -590,7 +590,10 @@ function vtkOpenGLImageMapper(publicAPI, model) {
|
|
|
590
590
|
resizable: true
|
|
591
591
|
});
|
|
592
592
|
model.colorTexture.setOpenGLRenderWindow(model._openGLRenderWindow);
|
|
593
|
-
|
|
593
|
+
let cWidth = model.renderable.getColorTextureWidth();
|
|
594
|
+
if (cWidth <= 0) {
|
|
595
|
+
cWidth = model.context.getParameter(model.context.MAX_TEXTURE_SIZE);
|
|
596
|
+
}
|
|
594
597
|
const cSize = cWidth * textureHeight * 3;
|
|
595
598
|
const cTable = new Uint8ClampedArray(cSize);
|
|
596
599
|
// set interpolation on the texture based on property setting
|
|
@@ -653,7 +656,10 @@ function vtkOpenGLImageMapper(publicAPI, model) {
|
|
|
653
656
|
// rebuild opacity tfun?
|
|
654
657
|
const reBuildPwf = !pwfTex?.oglObject?.getHandle() || pwfTex?.hash !== pwfunToString;
|
|
655
658
|
if (reBuildPwf) {
|
|
656
|
-
|
|
659
|
+
let pwfWidth = model.renderable.getOpacityTextureWidth();
|
|
660
|
+
if (pwfWidth <= 0) {
|
|
661
|
+
pwfWidth = model.context.getParameter(model.context.MAX_TEXTURE_SIZE);
|
|
662
|
+
}
|
|
657
663
|
const pwfSize = pwfWidth * textureHeight;
|
|
658
664
|
const pwfTable = new Uint8ClampedArray(pwfSize);
|
|
659
665
|
model.pwfTexture = vtkOpenGLTexture.newInstance({
|
|
@@ -863,10 +869,25 @@ function vtkOpenGLImageMapper(publicAPI, model) {
|
|
|
863
869
|
vtkErrorMacro('Reformat slicing not yet supported.');
|
|
864
870
|
}
|
|
865
871
|
|
|
872
|
+
/**
|
|
873
|
+
*
|
|
874
|
+
* Fetch the ranges of the source volume, `imgScalars`, and use them when
|
|
875
|
+
* creating the texture. Whilst the pre-calculated ranges may not be
|
|
876
|
+
* strictly correct for the slice, it is guaranteed to be within the
|
|
877
|
+
* source volume's range.
|
|
878
|
+
*
|
|
879
|
+
* There is a significant performance improvement by pre-setting the range
|
|
880
|
+
* of the scalars array particularly when scrolling through the source
|
|
881
|
+
* volume as there is no need to calculate the range of the slice scalar.
|
|
882
|
+
*
|
|
883
|
+
* @type{ import("../../../interfaces").vtkRange[] }
|
|
884
|
+
*/
|
|
885
|
+
const ranges = imgScalars.getRanges();
|
|
886
|
+
|
|
866
887
|
// Don't share this resource as `scalars` is created in this function
|
|
867
888
|
// so it is impossible to share
|
|
868
889
|
model.openGLTexture.resetFormatAndType();
|
|
869
|
-
model.openGLTexture.create2DFilterableFromRaw(dims[0], dims[1], numComp, imgScalars.getDataType(), scalars, model.renderable.getPreferSizeOverAccuracy?.());
|
|
890
|
+
model.openGLTexture.create2DFilterableFromRaw(dims[0], dims[1], numComp, imgScalars.getDataType(), scalars, model.renderable.getPreferSizeOverAccuracy?.(), ranges);
|
|
870
891
|
model.openGLTexture.activate();
|
|
871
892
|
model.openGLTexture.sendParameters();
|
|
872
893
|
model.openGLTexture.deactivate();
|
|
@@ -912,7 +933,10 @@ function vtkOpenGLImageMapper(publicAPI, model) {
|
|
|
912
933
|
const toString = `${labelOutlineThicknessArray.join('-')}`;
|
|
913
934
|
const reBuildL = !lTex?.oglObject?.getHandle() || lTex?.hash !== toString;
|
|
914
935
|
if (reBuildL) {
|
|
915
|
-
|
|
936
|
+
let lWidth = model.renderable.getLabelOutlineTextureWidth();
|
|
937
|
+
if (lWidth <= 0) {
|
|
938
|
+
lWidth = model.context.getParameter(model.context.MAX_TEXTURE_SIZE);
|
|
939
|
+
}
|
|
916
940
|
const lHeight = 1;
|
|
917
941
|
const lSize = lWidth * lHeight;
|
|
918
942
|
const lTable = new Uint8Array(lSize);
|
|
@@ -245,6 +245,7 @@ function vtkOpenGLImageResliceMapper(publicAPI, model) {
|
|
|
245
245
|
return model.VBOBuildTime.getMTime() < imageData.getMTime();
|
|
246
246
|
}) || model.VBOBuildTime.getMTime() < model.resliceGeom.getMTime() || model.scalarTextures.length !== model.currentValidInputs.length || !model.scalarTextures.every(texture => !!texture?.getHandle()) || !model.colorTexture?.getHandle() || !model.pwfTexture?.getHandle();
|
|
247
247
|
publicAPI.buildBufferObjects = (ren, actor) => {
|
|
248
|
+
const actorProperties = actor.getProperties();
|
|
248
249
|
model.currentValidInputs.forEach((_ref3, component) => {
|
|
249
250
|
let {
|
|
250
251
|
imageData
|
|
@@ -254,7 +255,10 @@ function vtkOpenGLImageResliceMapper(publicAPI, model) {
|
|
|
254
255
|
const tex = model._openGLRenderWindow.getGraphicsResourceForObject(scalars);
|
|
255
256
|
const scalarsHash = getImageDataHash(imageData, scalars);
|
|
256
257
|
const reBuildTex = !tex?.oglObject?.getHandle() || tex?.hash !== scalarsHash;
|
|
257
|
-
|
|
258
|
+
const actorProperty = actorProperties[component];
|
|
259
|
+
const updatedExtents = actorProperty.getUpdatedExtents();
|
|
260
|
+
const hasUpdatedExtents = !!updatedExtents.length;
|
|
261
|
+
if (reBuildTex && !hasUpdatedExtents) {
|
|
258
262
|
const newScalarTexture = vtkOpenGLTexture.newInstance();
|
|
259
263
|
newScalarTexture.setOpenGLRenderWindow(model._openGLRenderWindow);
|
|
260
264
|
// Build the textures
|
|
@@ -268,11 +272,17 @@ function vtkOpenGLImageResliceMapper(publicAPI, model) {
|
|
|
268
272
|
} else {
|
|
269
273
|
model.scalarTextures[component] = tex.oglObject;
|
|
270
274
|
}
|
|
275
|
+
if (hasUpdatedExtents) {
|
|
276
|
+
// If hasUpdatedExtents, then the texture is partially updated.
|
|
277
|
+
// clear the array to acknowledge the update.
|
|
278
|
+
actorProperty.setUpdatedExtents([]);
|
|
279
|
+
const dims = imageData.getDimensions();
|
|
280
|
+
model.scalarTextures[component].create3DFilterableFromDataArray(dims[0], dims[1], dims[2], scalars, false, updatedExtents);
|
|
281
|
+
}
|
|
271
282
|
replaceGraphicsResource(model._openGLRenderWindow, model._scalarTexturesCore[component], scalars);
|
|
272
283
|
model._scalarTexturesCore[component] = scalars;
|
|
273
284
|
});
|
|
274
285
|
const firstValidInput = model.currentValidInputs[0];
|
|
275
|
-
const actorProperties = actor.getProperties();
|
|
276
286
|
const firstActorProperty = actorProperties[firstValidInput.inputIndex];
|
|
277
287
|
const iComps = firstActorProperty.getIndependentComponents();
|
|
278
288
|
const numIComps = iComps ? model.numberOfComponents : 1;
|
|
@@ -286,7 +296,10 @@ function vtkOpenGLImageResliceMapper(publicAPI, model) {
|
|
|
286
296
|
const cTex = model._openGLRenderWindow.getGraphicsResourceForObject(firstColorTransferFunc);
|
|
287
297
|
const reBuildC = !cTex?.oglObject?.getHandle() || cTex?.hash !== colorFuncHash;
|
|
288
298
|
if (reBuildC) {
|
|
289
|
-
|
|
299
|
+
let cWidth = model.renderable.getColorTextureWidth();
|
|
300
|
+
if (cWidth <= 0) {
|
|
301
|
+
cWidth = model.context.getParameter(model.context.MAX_TEXTURE_SIZE);
|
|
302
|
+
}
|
|
290
303
|
const cSize = cWidth * textureHeight * 3;
|
|
291
304
|
const cTable = new Uint8ClampedArray(cSize);
|
|
292
305
|
const newColorTexture = vtkOpenGLTexture.newInstance();
|
|
@@ -345,7 +358,10 @@ function vtkOpenGLImageResliceMapper(publicAPI, model) {
|
|
|
345
358
|
const pwfTex = model._openGLRenderWindow.getGraphicsResourceForObject(firstPwFunc);
|
|
346
359
|
const reBuildPwf = !pwfTex?.oglObject?.getHandle() || pwfTex?.hash !== opacityFuncHash;
|
|
347
360
|
if (reBuildPwf) {
|
|
348
|
-
|
|
361
|
+
let pwfWidth = model.renderable.getOpacityTextureWidth();
|
|
362
|
+
if (pwfWidth <= 0) {
|
|
363
|
+
pwfWidth = model.context.getParameter(model.context.MAX_TEXTURE_SIZE);
|
|
364
|
+
}
|
|
349
365
|
const pwfSize = pwfWidth * textureHeight;
|
|
350
366
|
const pwfTable = new Uint8ClampedArray(pwfSize);
|
|
351
367
|
const newOpacityTexture = vtkOpenGLTexture.newInstance();
|
|
@@ -24,7 +24,7 @@ function vtkOpenGLRenderer(publicAPI, model) {
|
|
|
24
24
|
publicAPI.updateLights();
|
|
25
25
|
publicAPI.prepareNodes();
|
|
26
26
|
publicAPI.addMissingNode(model.renderable.getActiveCamera());
|
|
27
|
-
publicAPI.addMissingNodes(model.renderable.getViewPropsWithNestedProps());
|
|
27
|
+
publicAPI.addMissingNodes(model.renderable.getViewPropsWithNestedProps(), true);
|
|
28
28
|
publicAPI.removeUnusedNodes();
|
|
29
29
|
}
|
|
30
30
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Wrap, Filter } from './Texture/Constants';
|
|
2
2
|
import vtkOpenGLRenderWindow from './RenderWindow';
|
|
3
|
-
import { Nullable } from './../../types';
|
|
3
|
+
import { Extent, Nullable } from './../../types';
|
|
4
4
|
import { VtkDataTypes } from './../../Common/Core/DataArray';
|
|
5
5
|
import { vtkViewNode } from './../SceneGraph/ViewNode';
|
|
6
|
-
import { vtkObject } from './../../interfaces';
|
|
6
|
+
import { vtkObject, vtkRange } from './../../interfaces';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Initial values for creating a new instance of vtkOpenGLTexture.
|
|
@@ -244,7 +244,8 @@ export interface vtkOpenGLTexture extends vtkViewNode {
|
|
|
244
244
|
* @param numComps The number of components in the texture.
|
|
245
245
|
* @param dataType The data type of the texture.
|
|
246
246
|
* @param data The raw data for the texture.
|
|
247
|
-
* @param preferSizeOverAccuracy Whether to prefer texture size over accuracy.
|
|
247
|
+
* @param [preferSizeOverAccuracy=false] Whether to prefer texture size over accuracy. Defaults to false.
|
|
248
|
+
* @param [ranges] The precomputed ranges of the data (optional). Provided to prevent computation of the data ranges.
|
|
248
249
|
* @returns {boolean} True if the texture was successfully created, false otherwise.
|
|
249
250
|
*/
|
|
250
251
|
create2DFilterableFromRaw(
|
|
@@ -253,7 +254,8 @@ export interface vtkOpenGLTexture extends vtkViewNode {
|
|
|
253
254
|
numComps: number,
|
|
254
255
|
dataType: VtkDataTypes,
|
|
255
256
|
data: any,
|
|
256
|
-
preferSizeOverAccuracy
|
|
257
|
+
preferSizeOverAccuracy?: boolean,
|
|
258
|
+
ranges?: vtkRange[]
|
|
257
259
|
): boolean;
|
|
258
260
|
|
|
259
261
|
/**
|
|
@@ -273,12 +275,16 @@ export interface vtkOpenGLTexture extends vtkViewNode {
|
|
|
273
275
|
|
|
274
276
|
/**
|
|
275
277
|
* Creates a 3D texture from raw data.
|
|
278
|
+
*
|
|
279
|
+
* updatedExtents is currently incompatible with webgl1, since there's no extent scaling.
|
|
280
|
+
*
|
|
276
281
|
* @param width The width of the texture.
|
|
277
282
|
* @param height The height of the texture.
|
|
278
283
|
* @param depth The depth of the texture.
|
|
279
284
|
* @param numComps The number of components in the texture.
|
|
280
285
|
* @param dataType The data type of the texture.
|
|
281
286
|
* @param data The raw data for the texture.
|
|
287
|
+
* @param updatedExtents Only update the specified extents (default: [])
|
|
282
288
|
* @returns {boolean} True if the texture was successfully created, false otherwise.
|
|
283
289
|
*/
|
|
284
290
|
create3DFromRaw(
|
|
@@ -287,11 +293,15 @@ export interface vtkOpenGLTexture extends vtkViewNode {
|
|
|
287
293
|
depth: number,
|
|
288
294
|
numComps: number,
|
|
289
295
|
dataType: VtkDataTypes,
|
|
290
|
-
data: any
|
|
296
|
+
data: any,
|
|
297
|
+
updatedExtents?: Extent[]
|
|
291
298
|
): boolean;
|
|
292
299
|
|
|
293
300
|
/**
|
|
294
301
|
* Creates a 3D filterable texture from raw data, with a preference for size over accuracy if necessary.
|
|
302
|
+
*
|
|
303
|
+
* updatedExtents is currently incompatible with webgl1, since there's no extent scaling.
|
|
304
|
+
*
|
|
295
305
|
* @param width The width of the texture.
|
|
296
306
|
* @param height The height of the texture.
|
|
297
307
|
* @param depth The depth of the texture.
|
|
@@ -299,7 +309,11 @@ export interface vtkOpenGLTexture extends vtkViewNode {
|
|
|
299
309
|
* @param dataType The data type of the texture.
|
|
300
310
|
* @param values The raw data for the texture.
|
|
301
311
|
* @param preferSizeOverAccuracy Whether to prefer texture size over accuracy.
|
|
302
|
-
* @
|
|
312
|
+
* @param [ranges] The precomputed ranges of the data (optional). Provided to
|
|
313
|
+
* @param updatedExtents Only update the specified extents (default: [])
|
|
314
|
+
* prevent computation of the data ranges.
|
|
315
|
+
* @returns {boolean} True if the texture was successfully created, false
|
|
316
|
+
* otherwise.
|
|
303
317
|
*/
|
|
304
318
|
create3DFilterableFromRaw(
|
|
305
319
|
width: number,
|
|
@@ -308,16 +322,22 @@ export interface vtkOpenGLTexture extends vtkViewNode {
|
|
|
308
322
|
numComps: number,
|
|
309
323
|
dataType: VtkDataTypes,
|
|
310
324
|
values: any,
|
|
311
|
-
preferSizeOverAccuracy: boolean
|
|
325
|
+
preferSizeOverAccuracy: boolean,
|
|
326
|
+
ranges?: vtkRange[],
|
|
327
|
+
updatedExtents?: Extent[]
|
|
312
328
|
): boolean;
|
|
313
329
|
|
|
314
330
|
/**
|
|
315
331
|
* Creates a 3D filterable texture from a data array, with a preference for size over accuracy if necessary.
|
|
332
|
+
*
|
|
333
|
+
* updatedExtents is currently incompatible with webgl1, since there's no extent scaling.
|
|
334
|
+
*
|
|
316
335
|
* @param width The width of the texture.
|
|
317
336
|
* @param height The height of the texture.
|
|
318
337
|
* @param depth The depth of the texture.
|
|
319
338
|
* @param dataArray The data array to use for the texture.
|
|
320
339
|
* @param preferSizeOverAccuracy Whether to prefer texture size over accuracy.
|
|
340
|
+
* @param updatedExtents Only update the specified extents (default: [])
|
|
321
341
|
* @returns {boolean} True if the texture was successfully created, false otherwise.
|
|
322
342
|
*/
|
|
323
343
|
create3DFilterableFromDataArray(
|
|
@@ -325,7 +345,8 @@ export interface vtkOpenGLTexture extends vtkViewNode {
|
|
|
325
345
|
height: number,
|
|
326
346
|
depth: number,
|
|
327
347
|
dataArray: any,
|
|
328
|
-
preferSizeOverAccuracy: boolean
|
|
348
|
+
preferSizeOverAccuracy: boolean,
|
|
349
|
+
updatedExtents?: Extent[]
|
|
329
350
|
): boolean;
|
|
330
351
|
|
|
331
352
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import DeepEqual from 'fast-deep-equal';
|
|
1
2
|
import Constants from './Texture/Constants.js';
|
|
2
3
|
import HalfFloat from '../../Common/Core/HalfFloat.js';
|
|
3
4
|
import { n as newInstance$1, o as obj, s as set, e as setGet, g as get, i as moveToProtected, a as newTypedArray, c as macro } from '../../macros2.js';
|
|
@@ -30,6 +31,16 @@ const {
|
|
|
30
31
|
function vtkOpenGLTexture(publicAPI, model) {
|
|
31
32
|
// Set our className
|
|
32
33
|
model.classHierarchy.push('vtkOpenGLTexture');
|
|
34
|
+
function getTexParams() {
|
|
35
|
+
return {
|
|
36
|
+
internalFormat: model.internalFormat,
|
|
37
|
+
format: model.format,
|
|
38
|
+
openGLDataType: model.openGLDataType,
|
|
39
|
+
width: model.width,
|
|
40
|
+
height: model.height
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
// Renders myself
|
|
34
45
|
publicAPI.render = function () {
|
|
35
46
|
let renWin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
@@ -148,6 +159,7 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
148
159
|
if (model.context && model.handle) {
|
|
149
160
|
model.context.deleteTexture(model.handle);
|
|
150
161
|
}
|
|
162
|
+
model._prevTexParams = null;
|
|
151
163
|
model.handle = 0;
|
|
152
164
|
model.numberOfDimensions = 0;
|
|
153
165
|
model.target = 0;
|
|
@@ -209,6 +221,7 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
209
221
|
rwin.activateTexture(publicAPI);
|
|
210
222
|
rwin.deactivateTexture(publicAPI);
|
|
211
223
|
model.context.deleteTexture(model.handle);
|
|
224
|
+
model._prevTexParams = null;
|
|
212
225
|
model.handle = 0;
|
|
213
226
|
model.numberOfDimensions = 0;
|
|
214
227
|
model.target = 0;
|
|
@@ -353,6 +366,7 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
353
366
|
|
|
354
367
|
//----------------------------------------------------------------------------
|
|
355
368
|
publicAPI.resetFormatAndType = () => {
|
|
369
|
+
model._prevTexParams = null;
|
|
356
370
|
model.format = 0;
|
|
357
371
|
model.internalFormat = 0;
|
|
358
372
|
model._forceInternalFormat = false;
|
|
@@ -499,6 +513,86 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
499
513
|
}
|
|
500
514
|
};
|
|
501
515
|
|
|
516
|
+
//----------------------------------------------------------------------------
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Gets the extent's size.
|
|
520
|
+
* @param {Extent} extent
|
|
521
|
+
*/
|
|
522
|
+
function getExtentSize(extent) {
|
|
523
|
+
const [xmin, xmax, ymin, ymax, zmin, zmax] = extent;
|
|
524
|
+
return [xmax - xmin + 1, ymax - ymin + 1, zmax - zmin + 1];
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
//----------------------------------------------------------------------------
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Gets the number of pixels in the extent.
|
|
531
|
+
* @param {Extent} extent
|
|
532
|
+
*/
|
|
533
|
+
function getExtentPixelCount(extent) {
|
|
534
|
+
const [sx, sy, sz] = getExtentSize(extent);
|
|
535
|
+
return sx * sy * sz;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
//----------------------------------------------------------------------------
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Reads a flattened extent from the image data and writes to the given output array.
|
|
542
|
+
*
|
|
543
|
+
* Assumes X varies the fastest and Z varies the slowest.
|
|
544
|
+
*
|
|
545
|
+
* @param {*} data
|
|
546
|
+
* @param {*} dataDims
|
|
547
|
+
* @param {Extent} extent
|
|
548
|
+
* @param {TypedArray} outArray
|
|
549
|
+
* @param {number} outOffset
|
|
550
|
+
* @returns
|
|
551
|
+
*/
|
|
552
|
+
function readExtentIntoArray(data, dataDims, extent, outArray, outOffset) {
|
|
553
|
+
const [xmin, xmax, ymin, ymax, zmin, zmax] = extent;
|
|
554
|
+
const [dx, dy] = dataDims;
|
|
555
|
+
const sxy = dx * dy;
|
|
556
|
+
let writeOffset = outOffset;
|
|
557
|
+
for (let zi = zmin; zi <= zmax; zi++) {
|
|
558
|
+
const zOffset = zi * sxy;
|
|
559
|
+
for (let yi = ymin; yi <= ymax; yi++) {
|
|
560
|
+
const zyOffset = zOffset + yi * dx;
|
|
561
|
+
// explicit alternative to data.subarray,
|
|
562
|
+
// due to potential perf issues on v8
|
|
563
|
+
for (let readOffset = zyOffset + xmin, end = zyOffset + xmax; readOffset <= end; readOffset++, writeOffset++) {
|
|
564
|
+
outArray[writeOffset] = data[readOffset];
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
//----------------------------------------------------------------------------
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Reads several image extents into a contiguous pixel array.
|
|
574
|
+
*
|
|
575
|
+
* @param {*} data
|
|
576
|
+
* @param {Extent[]} extent
|
|
577
|
+
* @param {TypedArrayConstructor} typedArrayConstructor optional typed array constructor
|
|
578
|
+
* @returns
|
|
579
|
+
*/
|
|
580
|
+
function readExtents(data, extents) {
|
|
581
|
+
let typedArrayConstructor = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
582
|
+
const constructor = typedArrayConstructor || data.constructor;
|
|
583
|
+
const numPixels = extents.reduce((count, extent) => count + getExtentPixelCount(extent), 0);
|
|
584
|
+
const extentPixels = new constructor(numPixels);
|
|
585
|
+
const dataDims = [model.width, model.height, model.depth];
|
|
586
|
+
let writeOffset = 0;
|
|
587
|
+
extents.forEach(extent => {
|
|
588
|
+
readExtentIntoArray(data, dataDims, extent, extentPixels, writeOffset);
|
|
589
|
+
writeOffset += getExtentPixelCount(extent);
|
|
590
|
+
});
|
|
591
|
+
return extentPixels;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
//----------------------------------------------------------------------------
|
|
595
|
+
|
|
502
596
|
/**
|
|
503
597
|
* Updates the data array to match the required data type for OpenGL.
|
|
504
598
|
*
|
|
@@ -508,23 +602,30 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
508
602
|
* @param {string} dataType - The original data type of the input data.
|
|
509
603
|
* @param {Array} data - The input data array that needs to be updated.
|
|
510
604
|
* @param {boolean} [depth=false] - Indicates whether the data is a 3D array.
|
|
605
|
+
* @param {Array<Extent>} imageExtents only consider these image extents (default: [])
|
|
511
606
|
* @returns {Array} The updated data array that matches the OpenGL data type.
|
|
512
607
|
*/
|
|
513
608
|
publicAPI.updateArrayDataTypeForGL = function (dataType, data) {
|
|
514
609
|
let depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
610
|
+
let imageExtents = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
515
611
|
const pixData = [];
|
|
516
612
|
let pixCount = model.width * model.height * model.components;
|
|
517
613
|
if (depth) {
|
|
518
614
|
pixCount *= model.depth;
|
|
519
615
|
}
|
|
616
|
+
const onlyUpdateExtents = !!imageExtents.length;
|
|
520
617
|
|
|
521
618
|
// if the opengl data type is float
|
|
522
619
|
// then the data array must be float
|
|
523
620
|
if (dataType !== VtkDataTypes.FLOAT && model.openGLDataType === model.context.FLOAT) {
|
|
524
621
|
for (let idx = 0; idx < data.length; idx++) {
|
|
525
622
|
if (data[idx]) {
|
|
526
|
-
|
|
527
|
-
|
|
623
|
+
if (onlyUpdateExtents) {
|
|
624
|
+
pixData.push(readExtents(data[idx], imageExtents, Float32Array));
|
|
625
|
+
} else {
|
|
626
|
+
const dataArrayToCopy = data[idx].length > pixCount ? data[idx].subarray(0, pixCount) : data[idx];
|
|
627
|
+
pixData.push(new Float32Array(dataArrayToCopy));
|
|
628
|
+
}
|
|
528
629
|
} else {
|
|
529
630
|
pixData.push(null);
|
|
530
631
|
}
|
|
@@ -536,8 +637,12 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
536
637
|
if (dataType !== VtkDataTypes.UNSIGNED_CHAR && model.openGLDataType === model.context.UNSIGNED_BYTE) {
|
|
537
638
|
for (let idx = 0; idx < data.length; idx++) {
|
|
538
639
|
if (data[idx]) {
|
|
539
|
-
|
|
540
|
-
|
|
640
|
+
if (onlyUpdateExtents) {
|
|
641
|
+
pixData.push(readExtents(data[idx], imageExtents, Uint8Array));
|
|
642
|
+
} else {
|
|
643
|
+
const dataArrayToCopy = data[idx].length > pixCount ? data[idx].subarray(0, pixCount) : data[idx];
|
|
644
|
+
pixData.push(new Uint8Array(dataArrayToCopy));
|
|
645
|
+
}
|
|
541
646
|
} else {
|
|
542
647
|
pixData.push(null);
|
|
543
648
|
}
|
|
@@ -556,9 +661,10 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
556
661
|
if (halfFloat) {
|
|
557
662
|
for (let idx = 0; idx < data.length; idx++) {
|
|
558
663
|
if (data[idx]) {
|
|
559
|
-
const
|
|
560
|
-
const
|
|
561
|
-
|
|
664
|
+
const src = onlyUpdateExtents ? readExtents(data[idx], imageExtents) : data[idx];
|
|
665
|
+
const newArray = new Uint16Array(onlyUpdateExtents ? src.length : pixCount);
|
|
666
|
+
const newArrayLen = newArray.length;
|
|
667
|
+
for (let i = 0; i < newArrayLen; i++) {
|
|
562
668
|
newArray[i] = toHalf(src[i]);
|
|
563
669
|
}
|
|
564
670
|
pixData.push(newArray);
|
|
@@ -571,7 +677,7 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
571
677
|
// The output has to be filled
|
|
572
678
|
if (pixData.length === 0) {
|
|
573
679
|
for (let i = 0; i < data.length; i++) {
|
|
574
|
-
pixData.push(data[i]);
|
|
680
|
+
pixData.push(onlyUpdateExtents && data[i] ? readExtents(data[i], imageExtents) : data[i]);
|
|
575
681
|
}
|
|
576
682
|
}
|
|
577
683
|
return pixData;
|
|
@@ -986,10 +1092,12 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
986
1092
|
}
|
|
987
1093
|
publicAPI.create2DFilterableFromRaw = function (width, height, numberOfComponents, dataType, values) {
|
|
988
1094
|
let preferSizeOverAccuracy = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
1095
|
+
let ranges = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : undefined;
|
|
989
1096
|
return publicAPI.create2DFilterableFromDataArray(width, height, vtkDataArray.newInstance({
|
|
990
1097
|
numberOfComponents,
|
|
991
1098
|
dataType,
|
|
992
|
-
values
|
|
1099
|
+
values,
|
|
1100
|
+
ranges
|
|
993
1101
|
}), preferSizeOverAccuracy);
|
|
994
1102
|
};
|
|
995
1103
|
publicAPI.create2DFilterableFromDataArray = function (width, height, dataArray) {
|
|
@@ -1054,7 +1162,8 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
1054
1162
|
};
|
|
1055
1163
|
|
|
1056
1164
|
//----------------------------------------------------------------------------
|
|
1057
|
-
publicAPI.create3DFromRaw = (width, height, depth, numComps, dataType, data)
|
|
1165
|
+
publicAPI.create3DFromRaw = function (width, height, depth, numComps, dataType, data) {
|
|
1166
|
+
let updatedExtents = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : [];
|
|
1058
1167
|
let dataTypeToUse = dataType;
|
|
1059
1168
|
let dataToUse = data;
|
|
1060
1169
|
if (!publicAPI.updateVolumeInfoForGL(dataTypeToUse, numComps) && dataToUse) {
|
|
@@ -1096,25 +1205,42 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
1096
1205
|
model._openGLRenderWindow.activateTexture(publicAPI);
|
|
1097
1206
|
publicAPI.createTexture();
|
|
1098
1207
|
publicAPI.bind();
|
|
1208
|
+
const hasUpdatedExtents = updatedExtents.length > 0;
|
|
1209
|
+
|
|
1210
|
+
// It's possible for the texture parameters to change while
|
|
1211
|
+
// streaming, so check for such a change.
|
|
1212
|
+
const rebuildEntireTexture = !hasUpdatedExtents || !DeepEqual(model._prevTexParams, getTexParams());
|
|
1213
|
+
|
|
1099
1214
|
// Create an array of texture with one texture
|
|
1100
1215
|
const dataArray = [dataToUse];
|
|
1101
1216
|
const is3DArray = true;
|
|
1102
|
-
const pixData = publicAPI.updateArrayDataTypeForGL(dataTypeToUse, dataArray, is3DArray);
|
|
1217
|
+
const pixData = publicAPI.updateArrayDataTypeForGL(dataTypeToUse, dataArray, is3DArray, rebuildEntireTexture ? [] : updatedExtents);
|
|
1103
1218
|
const scaledData = scaleTextureToHighestPowerOfTwo(pixData);
|
|
1104
1219
|
|
|
1105
1220
|
// Source texture data from the PBO.
|
|
1106
1221
|
// model.context.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
1107
1222
|
model.context.pixelStorei(model.context.UNPACK_ALIGNMENT, 1);
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1223
|
+
if (rebuildEntireTexture) {
|
|
1224
|
+
if (useTexStorage(dataTypeToUse)) {
|
|
1225
|
+
model.context.texStorage3D(model.target, 1, model.internalFormat, model.width, model.height, model.depth);
|
|
1226
|
+
if (scaledData[0] != null) {
|
|
1227
|
+
model.context.texSubImage3D(model.target, 0, 0, 0, 0, model.width, model.height, model.depth, model.format, model.openGLDataType, scaledData[0]);
|
|
1228
|
+
}
|
|
1229
|
+
} else {
|
|
1230
|
+
model.context.texImage3D(model.target, 0, model.internalFormat, model.width, model.height, model.depth, 0, model.format, model.openGLDataType, scaledData[0]);
|
|
1231
|
+
}
|
|
1232
|
+
model._prevTexParams = getTexParams();
|
|
1233
|
+
} else if (hasUpdatedExtents) {
|
|
1234
|
+
const extentPixels = scaledData[0];
|
|
1235
|
+
let readOffset = 0;
|
|
1236
|
+
for (let i = 0; i < updatedExtents.length; i++) {
|
|
1237
|
+
const extent = updatedExtents[i];
|
|
1238
|
+
const extentSize = getExtentSize(extent);
|
|
1239
|
+
const extentPixelCount = getExtentPixelCount(extent);
|
|
1240
|
+
const textureData = new extentPixels.constructor(extentPixels.buffer, readOffset, extentPixelCount);
|
|
1241
|
+
readOffset += textureData.byteLength;
|
|
1242
|
+
model.context.texSubImage3D(model.target, 0, extent[0], extent[2], extent[4], extentSize[0], extentSize[1], extentSize[2], model.format, model.openGLDataType, textureData);
|
|
1115
1243
|
}
|
|
1116
|
-
} else {
|
|
1117
|
-
model.context.texImage3D(model.target, 0, model.internalFormat, model.width, model.height, model.depth, 0, model.format, model.openGLDataType, scaledData[0]);
|
|
1118
1244
|
}
|
|
1119
1245
|
if (model.generateMipmap) {
|
|
1120
1246
|
model.context.generateMipmap(model.target);
|
|
@@ -1129,17 +1255,21 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
1129
1255
|
// Prefer create3DFilterableFromDataArray to enable caching of min and max values
|
|
1130
1256
|
publicAPI.create3DFilterableFromRaw = function (width, height, depth, numberOfComponents, dataType, values) {
|
|
1131
1257
|
let preferSizeOverAccuracy = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
1258
|
+
let ranges = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : undefined;
|
|
1259
|
+
let updatedExtents = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : [];
|
|
1132
1260
|
return publicAPI.create3DFilterableFromDataArray(width, height, depth, vtkDataArray.newInstance({
|
|
1133
1261
|
numberOfComponents,
|
|
1134
1262
|
dataType,
|
|
1135
|
-
values
|
|
1136
|
-
|
|
1263
|
+
values,
|
|
1264
|
+
ranges
|
|
1265
|
+
}), preferSizeOverAccuracy, updatedExtents);
|
|
1137
1266
|
};
|
|
1138
1267
|
|
|
1139
1268
|
//----------------------------------------------------------------------------
|
|
1140
1269
|
// This method create a 3D texture from dimensions and a DataArray
|
|
1141
1270
|
publicAPI.create3DFilterableFromDataArray = function (width, height, depth, dataArray) {
|
|
1142
1271
|
let preferSizeOverAccuracy = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
1272
|
+
let updatedExtents = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
|
|
1143
1273
|
const {
|
|
1144
1274
|
numComps,
|
|
1145
1275
|
dataType,
|
|
@@ -1174,7 +1304,7 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
1174
1304
|
|
|
1175
1305
|
// WebGL2 path, we have 3d textures etc
|
|
1176
1306
|
if (model._openGLRenderWindow.getWebgl2()) {
|
|
1177
|
-
return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data);
|
|
1307
|
+
return publicAPI.create3DFromRaw(width, height, depth, numComps, dataType, data, updatedExtents);
|
|
1178
1308
|
}
|
|
1179
1309
|
const numPixelsIn = width * height * depth;
|
|
1180
1310
|
const scaleOffsetsCopy = structuredClone(scaleOffsets);
|
|
@@ -1343,6 +1473,7 @@ function vtkOpenGLTexture(publicAPI, model) {
|
|
|
1343
1473
|
const DEFAULT_VALUES = {
|
|
1344
1474
|
_openGLRenderWindow: null,
|
|
1345
1475
|
_forceInternalFormat: false,
|
|
1476
|
+
_prevTexParams: null,
|
|
1346
1477
|
context: null,
|
|
1347
1478
|
handle: 0,
|
|
1348
1479
|
sendParametersTime: null,
|