@kitware/vtk.js 33.0.0-beta.2 → 33.0.0-beta.3
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 +4 -0
- package/Common/Core/DataArray.js +3 -0
- package/Common/Core/Math/index.js +1 -1
- package/Common/Core/Math.js +1 -1
- package/Common/Core/URLExtract.js +2 -6
- package/Common/DataModel/Line.js +1 -0
- package/Common/DataModel/PolyLine.js +4 -0
- package/Filters/Core/ThresholdPoints.d.ts +72 -0
- package/Filters/Core/ThresholdPoints.js +219 -0
- package/Filters/General/ContourTriangulator/helper.js +1 -1
- package/IO/Core/DataAccessHelper/JSZipDataAccessHelper.js +1 -1
- package/IO/Geometry/DracoReader.d.ts +4 -4
- package/IO/Geometry/DracoReader.js +154 -105
- package/IO/Geometry/GLTFImporter/Animations.js +239 -0
- package/IO/Geometry/GLTFImporter/Constants.js +87 -0
- package/IO/Geometry/GLTFImporter/Decoder.js +69 -0
- package/IO/Geometry/GLTFImporter/Extensions.js +110 -0
- package/IO/Geometry/GLTFImporter/ORMTexture.worker.js +42 -0
- package/IO/Geometry/GLTFImporter/Parser.js +359 -0
- package/IO/Geometry/GLTFImporter/Reader.js +518 -0
- package/IO/Geometry/GLTFImporter/Utils.js +165 -0
- package/IO/Geometry/GLTFImporter.d.ts +266 -0
- package/IO/Geometry/GLTFImporter.js +245 -0
- package/IO/Geometry/IFCImporter.d.ts +163 -0
- package/IO/Geometry/IFCImporter.js +270 -0
- package/IO/Geometry/STLReader.d.ts +14 -0
- package/IO/Geometry/STLReader.js +57 -1
- package/IO/Geometry.js +5 -1
- package/IO/Image/HDRReader/Utils.js +1 -1
- package/IO/Image/HDRReader.js +1 -1
- package/IO/Image/TGAReader/Constants.js +28 -0
- package/IO/Image/TGAReader.d.ts +121 -0
- package/IO/Image/TGAReader.js +418 -0
- package/IO/Image/TIFFReader.d.ts +133 -0
- package/IO/Image/TIFFReader.js +144 -0
- package/IO/Image.js +5 -1
- package/IO/XML/XMLPolyDataWriter.js +1 -0
- package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +1 -1
- package/Interaction/Style/InteractorStyleTrackballCamera.js +1 -1
- package/Rendering/Core/Glyph3DMapper.d.ts +45 -29
- package/Rendering/Core/ImageCPRMapper.js +1 -1
- package/Rendering/Core/ImageProperty.d.ts +22 -0
- package/Rendering/Core/PointPicker.js +10 -1
- package/Rendering/Core/Prop3D.js +1 -1
- package/Rendering/Core/RenderWindowInteractor.d.ts +1 -1
- package/Rendering/Core/RenderWindowInteractor.js +1 -1
- package/Rendering/Misc/CanvasView.js +4 -2
- package/Rendering/Misc/RemoteView.d.ts +9 -3
- package/Rendering/Misc/RemoteView.js +7 -3
- package/Rendering/Misc/SynchronizableRenderWindow/ObjectManager.d.ts +1 -1
- package/Rendering/OpenGL/ImageMapper.js +14 -7
- package/Rendering/OpenGL/Texture/supportsNorm16Linear.js +97 -0
- package/Rendering/OpenGL/Texture.js +18 -11
- package/Widgets/Widgets3D/AngleWidget/behavior.js +2 -0
- package/Widgets/Widgets3D/InteractiveOrientationWidget.js +1 -1
- package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +17 -0
- package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +1 -0
- package/Widgets/Widgets3D/ShapeWidget/behavior.js +3 -0
- package/_virtual/rollup-plugin-worker-loader__module_Sources/IO/Geometry/GLTFImporter/ORMTexture.worker.js +296 -0
- package/index.d.ts +5 -0
- package/package.json +12 -10
|
@@ -0,0 +1,418 @@
|
|
|
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 };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { vtkAlgorithm, vtkObject } from './../../interfaces';
|
|
2
|
+
import HtmlDataAccessHelper from './../Core/DataAccessHelper/HtmlDataAccessHelper';
|
|
3
|
+
import HttpDataAccessHelper from './../Core/DataAccessHelper/HttpDataAccessHelper';
|
|
4
|
+
import JSZipDataAccessHelper from './../Core/DataAccessHelper/JSZipDataAccessHelper';
|
|
5
|
+
import LiteHttpDataAccessHelper from './../Core/DataAccessHelper/LiteHttpDataAccessHelper';
|
|
6
|
+
|
|
7
|
+
interface ITIFFReaderOptions {
|
|
8
|
+
compression?: string;
|
|
9
|
+
progressCallback?: any;
|
|
10
|
+
flipY?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export interface ITIFFReaderInitialValues {}
|
|
17
|
+
|
|
18
|
+
type vtkTIFFReaderBase = vtkObject &
|
|
19
|
+
Omit<
|
|
20
|
+
vtkAlgorithm,
|
|
21
|
+
| 'getInputData'
|
|
22
|
+
| 'setInputData'
|
|
23
|
+
| 'setInputConnection'
|
|
24
|
+
| 'getInputConnection'
|
|
25
|
+
| 'addInputConnection'
|
|
26
|
+
| 'addInputData'
|
|
27
|
+
>;
|
|
28
|
+
|
|
29
|
+
export interface vtkTIFFReader extends vtkTIFFReaderBase {
|
|
30
|
+
/**
|
|
31
|
+
* Get the base url.
|
|
32
|
+
*/
|
|
33
|
+
getBaseURL(): string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get if the image is flipped vertically.
|
|
37
|
+
*/
|
|
38
|
+
getFlipY(): boolean;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get the dataAccess helper.
|
|
42
|
+
*/
|
|
43
|
+
getDataAccessHelper():
|
|
44
|
+
| HtmlDataAccessHelper
|
|
45
|
+
| HttpDataAccessHelper
|
|
46
|
+
| JSZipDataAccessHelper
|
|
47
|
+
| LiteHttpDataAccessHelper;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Get the url of the object to load.
|
|
51
|
+
*/
|
|
52
|
+
getUrl(): string;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Load the object data.
|
|
56
|
+
* @param {ITIFFReaderOptions} [options]
|
|
57
|
+
*/
|
|
58
|
+
loadData(options?: ITIFFReaderOptions): Promise<any>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Parse data.
|
|
62
|
+
* @param {ArrayBuffer} content The content to parse.
|
|
63
|
+
*/
|
|
64
|
+
parse(content: ArrayBuffer): void;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Parse data as ArrayBuffer.
|
|
68
|
+
* @param {ArrayBuffer} content The content to parse.
|
|
69
|
+
*/
|
|
70
|
+
parseAsArrayBuffer(content: ArrayBuffer): void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @param inData
|
|
75
|
+
* @param outData
|
|
76
|
+
*/
|
|
77
|
+
requestData(inData: any, outData: any): void;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Flip the image vertically.
|
|
81
|
+
* @param {String} flipY If true, flip the image vertically.
|
|
82
|
+
*/
|
|
83
|
+
setFlipY(flipY: boolean): boolean;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @param dataAccessHelper
|
|
88
|
+
*/
|
|
89
|
+
setDataAccessHelper(
|
|
90
|
+
dataAccessHelper:
|
|
91
|
+
| HtmlDataAccessHelper
|
|
92
|
+
| HttpDataAccessHelper
|
|
93
|
+
| JSZipDataAccessHelper
|
|
94
|
+
| LiteHttpDataAccessHelper
|
|
95
|
+
): boolean;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Set the url of the object to load.
|
|
99
|
+
* @param {String} url the url of the object to load.
|
|
100
|
+
* @param {ITIFFReaderOptions} [option] The PLY reader options.
|
|
101
|
+
*/
|
|
102
|
+
setUrl(url: string, option?: ITIFFReaderOptions): Promise<string | any>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Method used to decorate a given object (publicAPI+model) with vtkTIFFReader characteristics.
|
|
107
|
+
*
|
|
108
|
+
* @param publicAPI object on which methods will be bounds (public)
|
|
109
|
+
* @param model object on which data structure will be bounds (protected)
|
|
110
|
+
* @param {ITIFFReaderInitialValues} [initialValues] (default: {})
|
|
111
|
+
*/
|
|
112
|
+
export function extend(
|
|
113
|
+
publicAPI: object,
|
|
114
|
+
model: object,
|
|
115
|
+
initialValues?: ITIFFReaderInitialValues
|
|
116
|
+
): void;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Method used to create a new instance of vtkTIFFReader
|
|
120
|
+
* @param {ITIFFReaderInitialValues} [initialValues] for pre-setting some of its content
|
|
121
|
+
*/
|
|
122
|
+
export function newInstance(
|
|
123
|
+
initialValues?: ITIFFReaderInitialValues
|
|
124
|
+
): vtkTIFFReader;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* vtkTIFFReader is a source object that reads TIFF files.
|
|
128
|
+
*/
|
|
129
|
+
export declare const vtkTIFFReader: {
|
|
130
|
+
newInstance: typeof newInstance;
|
|
131
|
+
extend: typeof extend;
|
|
132
|
+
};
|
|
133
|
+
export default vtkTIFFReader;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { m as macro } from '../../macros2.js';
|
|
2
|
+
import '../Core/DataAccessHelper/LiteHttpDataAccessHelper.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 UTIF from 'utif';
|
|
7
|
+
|
|
8
|
+
// ----------------------------------------------------------------------------
|
|
9
|
+
// vtkTIFFReader methods
|
|
10
|
+
// ----------------------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
function vtkTIFFReader(publicAPI, model) {
|
|
13
|
+
// Set our className
|
|
14
|
+
model.classHierarchy.push('vtkTIFFReader');
|
|
15
|
+
|
|
16
|
+
// Create default dataAccessHelper if not available
|
|
17
|
+
if (!model.dataAccessHelper) {
|
|
18
|
+
model.dataAccessHelper = DataAccessHelper.get('http');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Internal method to fetch Array
|
|
22
|
+
function fetchData(url) {
|
|
23
|
+
const {
|
|
24
|
+
compression,
|
|
25
|
+
progressCallback
|
|
26
|
+
} = model;
|
|
27
|
+
return model.dataAccessHelper.fetchBinary(url, {
|
|
28
|
+
compression,
|
|
29
|
+
progressCallback
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Set DataSet url
|
|
34
|
+
publicAPI.setUrl = function (url) {
|
|
35
|
+
let option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
36
|
+
binary: true
|
|
37
|
+
};
|
|
38
|
+
model.url = url;
|
|
39
|
+
|
|
40
|
+
// Remove the file in the URL
|
|
41
|
+
const path = url.split('/');
|
|
42
|
+
path.pop();
|
|
43
|
+
model.baseURL = path.join('/');
|
|
44
|
+
model.compression = option.compression;
|
|
45
|
+
|
|
46
|
+
// Fetch metadata
|
|
47
|
+
return publicAPI.loadData({
|
|
48
|
+
progressCallback: option.progressCallback
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Fetch the actual data arrays
|
|
53
|
+
publicAPI.loadData = function () {
|
|
54
|
+
const promise = fetchData(model.url);
|
|
55
|
+
promise.then(publicAPI.parse);
|
|
56
|
+
return promise;
|
|
57
|
+
};
|
|
58
|
+
publicAPI.parse = content => {
|
|
59
|
+
publicAPI.parseAsArrayBuffer(content);
|
|
60
|
+
};
|
|
61
|
+
publicAPI.parseAsArrayBuffer = content => {
|
|
62
|
+
if (!content) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Read Header
|
|
67
|
+
const ifds = UTIF.decode(content);
|
|
68
|
+
UTIF.decodeImage(content, ifds[0]);
|
|
69
|
+
const data = UTIF.toRGBA8(ifds[0]);
|
|
70
|
+
const width = ifds[0].width;
|
|
71
|
+
const height = ifds[0].height;
|
|
72
|
+
const output = new Uint8Array(data.length);
|
|
73
|
+
if (model.flipY) {
|
|
74
|
+
for (let y = 0; y < height; y++) {
|
|
75
|
+
for (let x = 0; x < width; x++) {
|
|
76
|
+
const srcIndex = (y * width + x) * 4;
|
|
77
|
+
const destIndex = ((height - y - 1) * width + x) * 4;
|
|
78
|
+
output[destIndex] = data[srcIndex]; // R
|
|
79
|
+
output[destIndex + 1] = data[srcIndex + 1]; // G
|
|
80
|
+
output[destIndex + 2] = data[srcIndex + 2]; // B
|
|
81
|
+
output[destIndex + 3] = data[srcIndex + 3]; // A
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const dataExtent = [0, width - 1, 0, height - 1];
|
|
87
|
+
const dataSpacing = [1, 1, 1];
|
|
88
|
+
const imageData = vtkImageData.newInstance();
|
|
89
|
+
imageData.setDimensions(width, height, 1);
|
|
90
|
+
imageData.setExtent(dataExtent);
|
|
91
|
+
imageData.setSpacing(dataSpacing);
|
|
92
|
+
const dataArray = vtkDataArray.newInstance({
|
|
93
|
+
name: 'TIFFImage',
|
|
94
|
+
numberOfComponents: 4,
|
|
95
|
+
values: output
|
|
96
|
+
});
|
|
97
|
+
imageData.getPointData().setScalars(dataArray);
|
|
98
|
+
model.output[0] = imageData;
|
|
99
|
+
};
|
|
100
|
+
publicAPI.requestData = (inData, outData) => {
|
|
101
|
+
publicAPI.parse(model.parseData);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ----------------------------------------------------------------------------
|
|
106
|
+
// Object factory
|
|
107
|
+
// ----------------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
const DEFAULT_VALUES = {
|
|
110
|
+
flipY: true,
|
|
111
|
+
compression: null,
|
|
112
|
+
progressCallback: null
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// ----------------------------------------------------------------------------
|
|
116
|
+
|
|
117
|
+
function extend(publicAPI, model) {
|
|
118
|
+
let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
119
|
+
Object.assign(model, DEFAULT_VALUES, initialValues);
|
|
120
|
+
|
|
121
|
+
// Make this a VTK object
|
|
122
|
+
macro.obj(publicAPI, model);
|
|
123
|
+
|
|
124
|
+
// Also make it an algorithm with one input and one output
|
|
125
|
+
macro.algo(publicAPI, model, 0, 1);
|
|
126
|
+
macro.get(publicAPI, model, ['url', 'baseURL']);
|
|
127
|
+
macro.setGet(publicAPI, model, ['dataAccessHelper', 'flipY']);
|
|
128
|
+
|
|
129
|
+
// Object specific methods
|
|
130
|
+
vtkTIFFReader(publicAPI, model);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ----------------------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
const newInstance = macro.newInstance(extend, 'vtkTIFFReader');
|
|
136
|
+
|
|
137
|
+
// ----------------------------------------------------------------------------
|
|
138
|
+
|
|
139
|
+
var vtkTIFFReader$1 = {
|
|
140
|
+
newInstance,
|
|
141
|
+
extend
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export { vtkTIFFReader$1 as default, extend, newInstance };
|
package/IO/Image.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import vtkHDRReader from './Image/HDRReader.js';
|
|
2
|
+
import vtkTGAReader from './Image/TGAReader.js';
|
|
3
|
+
import vtkTIFFReader from './Image/TIFFReader.js';
|
|
2
4
|
|
|
3
5
|
var index = {
|
|
4
|
-
vtkHDRReader
|
|
6
|
+
vtkHDRReader,
|
|
7
|
+
vtkTGAReader,
|
|
8
|
+
vtkTIFFReader
|
|
5
9
|
};
|
|
6
10
|
|
|
7
11
|
export { index as default };
|