@kitware/vtk.js 32.6.2 → 33.0.0-beta.2

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.
Files changed (37) hide show
  1. package/BREAKING_CHANGES.md +3 -0
  2. package/IO/Image.js +1 -3
  3. package/Interaction/Manipulators/KeyboardCameraManipulator.d.ts +113 -0
  4. package/Rendering/Core/Actor.d.ts +5 -20
  5. package/Rendering/Core/Actor.js +5 -68
  6. package/Rendering/Core/ImageProperty.d.ts +0 -22
  7. package/Rendering/Core/ImageSlice.d.ts +7 -23
  8. package/Rendering/Core/ImageSlice.js +9 -68
  9. package/Rendering/Core/PointPicker.js +1 -4
  10. package/Rendering/Core/Prop3D.d.ts +39 -2
  11. package/Rendering/Core/Prop3D.js +81 -2
  12. package/Rendering/Core/RenderWindowInteractor.d.ts +1 -1
  13. package/Rendering/Core/Volume.d.ts +5 -20
  14. package/Rendering/Core/Volume.js +2 -70
  15. package/Rendering/Core/VolumeMapper/Constants.d.ts +0 -7
  16. package/Rendering/Core/VolumeMapper/Constants.js +2 -8
  17. package/Rendering/Core/VolumeMapper.d.ts +16 -140
  18. package/Rendering/Core/VolumeMapper.js +17 -52
  19. package/Rendering/Core/VolumeProperty/Constants.d.ts +12 -3
  20. package/Rendering/Core/VolumeProperty/Constants.js +11 -4
  21. package/Rendering/Core/VolumeProperty.d.ts +120 -4
  22. package/Rendering/Core/VolumeProperty.js +49 -4
  23. package/Rendering/OpenGL/ImageCPRMapper.js +27 -19
  24. package/Rendering/OpenGL/ImageMapper.js +34 -41
  25. package/Rendering/OpenGL/ImageResliceMapper.js +261 -172
  26. package/Rendering/OpenGL/PolyDataMapper.js +1 -8
  27. package/Rendering/OpenGL/RenderWindow/resourceSharingHelper.d.ts +3 -3
  28. package/Rendering/OpenGL/RenderWindow/resourceSharingHelper.js +8 -5
  29. package/Rendering/OpenGL/VolumeMapper.js +710 -772
  30. package/Rendering/OpenGL/glsl/vtkVolumeFS.glsl.js +1 -1
  31. package/Rendering/WebGPU/VolumePassFSQ.js +2 -2
  32. package/index.d.ts +1 -1
  33. package/macros2.js +1 -1
  34. package/package.json +1 -1
  35. package/IO/Image/TGAReader/Constants.js +0 -28
  36. package/IO/Image/TGAReader.d.ts +0 -121
  37. package/IO/Image/TGAReader.js +0 -418
@@ -1,418 +0,0 @@
1
- import '../Core/DataAccessHelper/LiteHttpDataAccessHelper.js';
2
- import { m as macro } from '../../macros2.js';
3
- import DataAccessHelper from '../Core/DataAccessHelper.js';
4
- import vtkImageData from '../../Common/DataModel/ImageData.js';
5
- import vtkDataArray from '../../Common/Core/DataArray.js';
6
- import Constants from './TGAReader/Constants.js';
7
-
8
- /* eslint-disable no-bitwise */
9
- const {
10
- vtkErrorMacro
11
- } = macro;
12
-
13
- // ----------------------------------------------------------------------------
14
- // vtkTGAReader methods
15
- // ----------------------------------------------------------------------------
16
-
17
- function vtkTGAReader(publicAPI, model) {
18
- // Set our className
19
- model.classHierarchy.push('vtkTGAReader');
20
-
21
- // Create default dataAccessHelper if not available
22
- if (!model.dataAccessHelper) {
23
- model.dataAccessHelper = DataAccessHelper.get('http');
24
- }
25
-
26
- /**
27
- * Gets the header of a TGA file
28
- * @param data defines the TGA data
29
- * @returns the header
30
- */
31
- function parseHeader(data) {
32
- let offset = 0;
33
- const header = {
34
- idLength: data[offset++],
35
- colormap_type: data[offset++],
36
- imageType: data[offset++],
37
- colormapIndex: data[offset++] | data[offset++] << 8,
38
- colormapLength: data[offset++] | data[offset++] << 8,
39
- colormapSize: data[offset++],
40
- origin: [data[offset++] | data[offset++] << 8, data[offset++] | data[offset++] << 8],
41
- width: data[offset++] | data[offset++] << 8,
42
- height: data[offset++] | data[offset++] << 8,
43
- pixelSize: data[offset++],
44
- flags: data[offset++]
45
- };
46
- return header;
47
- }
48
- const handlers = {
49
- getImageData8bits(header, palettes, pixeData, yStart, yStep, yEnd, xStart, xStep, xEnd) {
50
- const image = pixeData;
51
- const colormap = palettes;
52
- const width = header.width;
53
- const height = header.height;
54
- let color;
55
- let i = 0;
56
- let x;
57
- let y;
58
- const imageData = new Uint8Array(width * height * 4);
59
- for (y = yStart; y !== yEnd; y += yStep) {
60
- for (x = xStart; x !== xEnd; x += xStep, i++) {
61
- color = image[i];
62
- imageData[(x + width * y) * 4 + 3] = 255;
63
- imageData[(x + width * y) * 4 + 2] = colormap[color * 3 + 0];
64
- imageData[(x + width * y) * 4 + 1] = colormap[color * 3 + 1];
65
- imageData[(x + width * y) * 4 + 0] = colormap[color * 3 + 2];
66
- }
67
- }
68
- return imageData;
69
- },
70
- getImageData16bits(header, palettes, pixeData, yStart, yStep, yEnd, xStart, xStep, xEnd) {
71
- const image = pixeData;
72
- const width = header.width;
73
- const height = header.height;
74
- let color;
75
- let i = 0;
76
- let x;
77
- let y;
78
- const imageData = new Uint8Array(width * height * 4);
79
- for (y = yStart; y !== yEnd; y += yStep) {
80
- for (x = xStart; x !== xEnd; x += xStep, i += 2) {
81
- color = image[i + 0] + (image[i + 1] << 8); // Inversed ?
82
- const r = ((color & 0x7c00) >> 10) * 255 / 0x1f | 0;
83
- const g = ((color & 0x03e0) >> 5) * 255 / 0x1f | 0;
84
- const b = (color & 0x001f) * 255 / 0x1f | 0;
85
- imageData[(x + width * y) * 4 + 0] = r;
86
- imageData[(x + width * y) * 4 + 1] = g;
87
- imageData[(x + width * y) * 4 + 2] = b;
88
- imageData[(x + width * y) * 4 + 3] = color & 0x8000 ? 0 : 255;
89
- }
90
- }
91
- return imageData;
92
- },
93
- getImageData24bits(header, palettes, pixeData, yStart, yStep, yEnd, xStart, xStep, xEnd) {
94
- const image = pixeData;
95
- const width = header.width;
96
- const height = header.height;
97
- let i = 0;
98
- let x;
99
- let y;
100
- const imageData = new Uint8Array(width * height * 4);
101
- for (y = yStart; y !== yEnd; y += yStep) {
102
- for (x = xStart; x !== xEnd; x += xStep, i += 3) {
103
- imageData[(x + width * y) * 4 + 3] = 255;
104
- imageData[(x + width * y) * 4 + 2] = image[i + 0];
105
- imageData[(x + width * y) * 4 + 1] = image[i + 1];
106
- imageData[(x + width * y) * 4 + 0] = image[i + 2];
107
- }
108
- }
109
- return imageData;
110
- },
111
- getImageData32bits(header, palettes, pixeData, yStart, yStep, yEnd, xStart, xStep, xEnd) {
112
- const image = pixeData;
113
- const width = header.width;
114
- const height = header.height;
115
- let i = 0;
116
- let x;
117
- let y;
118
- const imageData = new Uint8Array(width * height * 4);
119
- for (y = yStart; y !== yEnd; y += yStep) {
120
- for (x = xStart; x !== xEnd; x += xStep, i += 4) {
121
- imageData[(x + width * y) * 4 + 2] = image[i + 0];
122
- imageData[(x + width * y) * 4 + 1] = image[i + 1];
123
- imageData[(x + width * y) * 4 + 0] = image[i + 2];
124
- imageData[(x + width * y) * 4 + 3] = image[i + 3];
125
- }
126
- }
127
- return imageData;
128
- },
129
- getImageDataGrey8bits(header, palettes, pixeData, yStart, yStep, yEnd, xStart, xStep, xEnd) {
130
- const image = pixeData;
131
- const width = header.width;
132
- const height = header.height;
133
- let color;
134
- let i = 0;
135
- let x;
136
- let y;
137
- const imageData = new Uint8Array(width * height * 4);
138
- for (y = yStart; y !== yEnd; y += yStep) {
139
- for (x = xStart; x !== xEnd; x += xStep, i++) {
140
- color = image[i];
141
- imageData[(x + width * y) * 4 + 0] = color;
142
- imageData[(x + width * y) * 4 + 1] = color;
143
- imageData[(x + width * y) * 4 + 2] = color;
144
- imageData[(x + width * y) * 4 + 3] = 255;
145
- }
146
- }
147
- return imageData;
148
- },
149
- getImageDataGrey16bits(header, palettes, pixeData, yStart, yStep, yEnd, xStart, xStep, xEnd) {
150
- const image = pixeData;
151
- const width = header.width;
152
- const height = header.height;
153
- let i = 0;
154
- let x;
155
- let y;
156
- const imageData = new Uint8Array(width * height * 4);
157
- for (y = yStart; y !== yEnd; y += yStep) {
158
- for (x = xStart; x !== xEnd; x += xStep, i += 2) {
159
- imageData[(x + width * y) * 4 + 0] = image[i + 0];
160
- imageData[(x + width * y) * 4 + 1] = image[i + 0];
161
- imageData[(x + width * y) * 4 + 2] = image[i + 0];
162
- imageData[(x + width * y) * 4 + 3] = image[i + 1];
163
- }
164
- }
165
- return imageData;
166
- }
167
- };
168
-
169
- // Internal method to fetch Array
170
- function fetchData(url) {
171
- const {
172
- compression,
173
- progressCallback
174
- } = model;
175
- return model.dataAccessHelper.fetchBinary(url, {
176
- compression,
177
- progressCallback
178
- });
179
- }
180
-
181
- // Set DataSet url
182
- publicAPI.setUrl = function (url) {
183
- let option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
184
- binary: true
185
- };
186
- model.url = url;
187
-
188
- // Remove the file in the URL
189
- const path = url.split('/');
190
- path.pop();
191
- model.baseURL = path.join('/');
192
- model.compression = option.compression;
193
-
194
- // Fetch metadata
195
- return publicAPI.loadData({
196
- progressCallback: option.progressCallback
197
- });
198
- };
199
-
200
- // Fetch the actual data arrays
201
- publicAPI.loadData = function () {
202
- const promise = fetchData(model.url);
203
- promise.then(publicAPI.parse);
204
- return promise;
205
- };
206
- publicAPI.parse = content => {
207
- publicAPI.parseAsArrayBuffer(content);
208
- };
209
- publicAPI.parseAsArrayBuffer = content => {
210
- if (!content) {
211
- return;
212
- }
213
- const data = new Uint8Array(content);
214
- // Not enough data to contain header ?
215
- if (data.length < 19) {
216
- vtkErrorMacro('Unable to load TGA file - Not enough data to contain header');
217
- return;
218
- }
219
-
220
- // Read Header
221
- let offset = 18;
222
- const header = parseHeader(data);
223
-
224
- // Assume it's a valid Targa file.
225
- if (header.idLength + offset > data.length) {
226
- vtkErrorMacro('Unable to load TGA file - Not enough data');
227
- return;
228
- }
229
-
230
- // Skip not needed data
231
- offset += header.idLength;
232
- let useRle = false;
233
- let usePal = false;
234
- let useGrey = false;
235
-
236
- // Get some informations.
237
- switch (header.imageType) {
238
- case Constants.TYPE_RLE_INDEXED:
239
- useRle = true;
240
- // eslint-disable-next-line no-fallthrough
241
- case Constants.TYPE_INDEXED:
242
- usePal = true;
243
- break;
244
- case Constants.TYPE_RLE_RGB:
245
- useRle = true;
246
- // eslint-disable-next-line no-fallthrough
247
- case Constants.TYPE_RGB:
248
- // use_rgb = true;
249
- break;
250
- case Constants.TYPE_RLE_GREY:
251
- useRle = true;
252
- // eslint-disable-next-line no-fallthrough
253
- case Constants.TYPE_GREY:
254
- useGrey = true;
255
- break;
256
- default:
257
- vtkErrorMacro('TGA file has unknown image type');
258
- return;
259
- }
260
- let pixelData;
261
- const pixelSize = header.pixelSize >> 3;
262
- const pixelTotal = header.width * header.height * pixelSize;
263
-
264
- // Read palettes
265
- let palettes;
266
- if (usePal) {
267
- palettes = data.subarray(offset, offset += header.colormapLength * (header.colormapSize >> 3));
268
- }
269
-
270
- // Read LRE
271
- if (useRle) {
272
- pixelData = new Uint8Array(pixelTotal);
273
- let c;
274
- let count;
275
- let i;
276
- let localOffset = 0;
277
- const pixels = new Uint8Array(pixelSize);
278
- while (offset < pixelTotal && localOffset < pixelTotal) {
279
- c = data[offset++];
280
- count = (c & 0x7f) + 1;
281
-
282
- // RLE pixels
283
- if (c & 0x80) {
284
- // Bind pixel tmp array
285
- for (i = 0; i < pixelSize; ++i) {
286
- pixels[i] = data[offset++];
287
- }
288
-
289
- // Copy pixel array
290
- for (i = 0; i < count; ++i) {
291
- pixelData.set(pixels, localOffset + i * pixelSize);
292
- }
293
- localOffset += pixelSize * count;
294
- }
295
- // Raw pixels
296
- else {
297
- count *= pixelSize;
298
- for (i = 0; i < count; ++i) {
299
- pixelData[localOffset + i] = data[offset++];
300
- }
301
- localOffset += count;
302
- }
303
- }
304
- }
305
- // RAW Pixels
306
- else {
307
- pixelData = data.subarray(offset, offset += usePal ? header.width * header.height : pixelTotal);
308
- }
309
-
310
- // Load to texture
311
- let xStart;
312
- let yStart;
313
- let xStep;
314
- let yStep;
315
- let yEnd;
316
- let xEnd;
317
- switch ((header.flags & Constants.ORIGIN_MASK) >> Constants.ORIGIN_SHIFT) {
318
- case Constants.ORIGIN_UL:
319
- xStart = 0;
320
- xStep = 1;
321
- xEnd = header.width;
322
- yStart = 0;
323
- yStep = 1;
324
- yEnd = header.height;
325
- break;
326
- case Constants.ORIGIN_BL:
327
- xStart = 0;
328
- xStep = 1;
329
- xEnd = header.width;
330
- yStart = 0;
331
- yStep = 1;
332
- yEnd = header.height;
333
- break;
334
- case Constants.ORIGIN_UR:
335
- xStart = header.width - 1;
336
- xStep = -1;
337
- xEnd = -1;
338
- yStart = 0;
339
- yStep = 1;
340
- yEnd = header.height;
341
- break;
342
- case Constants.ORIGIN_BR:
343
- xStart = header.width - 1;
344
- xStep = -1;
345
- xEnd = -1;
346
- yStart = header.height - 1;
347
- yStep = -1;
348
- yEnd = -1;
349
- break;
350
- default:
351
- vtkErrorMacro('TGA file has unknown origin');
352
- return;
353
- }
354
- const func = `getImageData${useGrey ? 'Grey' : ''}${header.pixelSize}bits`;
355
- const output = handlers[func](header, palettes, pixelData, yStart, yStep, yEnd, xStart, xStep, xEnd);
356
- const dataExtent = [0, header.width - 1, 0, header.height - 1];
357
- const dataSpacing = [1, 1, 1];
358
- const imageData = vtkImageData.newInstance();
359
- imageData.setDimensions(header.width, header.height, 1);
360
- imageData.setExtent(dataExtent);
361
- imageData.setSpacing(dataSpacing);
362
- const dataArray = vtkDataArray.newInstance({
363
- name: 'TGAImage',
364
- numberOfComponents: 4,
365
- values: output
366
- });
367
- imageData.getPointData().setScalars(dataArray);
368
- model.output[0] = imageData;
369
- };
370
- publicAPI.requestData = (inData, outData) => {
371
- publicAPI.parse(model.parseData);
372
- };
373
- }
374
-
375
- // ----------------------------------------------------------------------------
376
- // Object factory
377
- // ----------------------------------------------------------------------------
378
-
379
- const DEFAULT_VALUES = {};
380
-
381
- // ----------------------------------------------------------------------------
382
-
383
- function extend(publicAPI, model) {
384
- let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
385
- Object.assign(model, DEFAULT_VALUES, initialValues);
386
-
387
- // Make this a VTK object
388
- macro.obj(publicAPI, model);
389
-
390
- // Also make it an algorithm with one input and one output
391
- macro.algo(publicAPI, model, 0, 1);
392
- macro.get(publicAPI, model, ['url', 'baseURL']);
393
- macro.setGet(publicAPI, model, ['dataAccessHelper']);
394
-
395
- // Object specific methods
396
- vtkTGAReader(publicAPI, model);
397
-
398
- // To support destructuring
399
- if (!model.compression) {
400
- model.compression = null;
401
- }
402
- if (!model.progressCallback) {
403
- model.progressCallback = null;
404
- }
405
- }
406
-
407
- // ----------------------------------------------------------------------------
408
-
409
- const newInstance = macro.newInstance(extend, 'vtkTGAReader');
410
-
411
- // ----------------------------------------------------------------------------
412
-
413
- var vtkTGAReader$1 = {
414
- newInstance,
415
- extend
416
- };
417
-
418
- export { vtkTGAReader$1 as default, extend, newInstance };