@kitware/vtk.js 21.4.0 → 21.4.1
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.
|
@@ -2,9 +2,9 @@ import macro from '../../macros.js';
|
|
|
2
2
|
import vtkImageData from './ImageData.js';
|
|
3
3
|
import vtkDataArray from '../Core/DataArray.js';
|
|
4
4
|
|
|
5
|
-
var vtkErrorMacro = macro.vtkErrorMacro; // see itk.js
|
|
5
|
+
var vtkErrorMacro = macro.vtkErrorMacro; // see itk.js PixelTypes.js
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var ITKJSPixelTypes = {
|
|
8
8
|
Unknown: 0,
|
|
9
9
|
Scalar: 1,
|
|
10
10
|
RGB: 2,
|
|
@@ -21,6 +21,25 @@ var ITKPixelTypes = {
|
|
|
21
21
|
Matrix: 13,
|
|
22
22
|
VariableLengthVector: 14,
|
|
23
23
|
VariableSizeMatrix: 15
|
|
24
|
+
}; // itk-wasm pixel types from https://github.com/InsightSoftwareConsortium/itk-wasm/blob/master/src/core/PixelTypes.ts
|
|
25
|
+
|
|
26
|
+
var ITKWASMPixelTypes = {
|
|
27
|
+
Unknown: 'Unknown',
|
|
28
|
+
Scalar: 'Scalar',
|
|
29
|
+
RGB: 'RGB',
|
|
30
|
+
RGBA: 'RGBA',
|
|
31
|
+
Offset: 'Offset',
|
|
32
|
+
Vector: 'Vector',
|
|
33
|
+
Point: 'Point',
|
|
34
|
+
CovariantVector: 'CovariantVector',
|
|
35
|
+
SymmetricSecondRankTensor: 'SymmetricSecondRankTensor',
|
|
36
|
+
DiffusionTensor3D: 'DiffusionTensor3D',
|
|
37
|
+
Complex: 'Complex',
|
|
38
|
+
FixedArray: 'FixedArray',
|
|
39
|
+
Array: 'Array',
|
|
40
|
+
Matrix: 'Matrix',
|
|
41
|
+
VariableLengthVector: 'VariableLengthVector',
|
|
42
|
+
VariableSizeMatrix: 'VariableSizeMatrix'
|
|
24
43
|
};
|
|
25
44
|
/**
|
|
26
45
|
* Converts an itk.js image to a vtk.js image.
|
|
@@ -35,7 +54,10 @@ function convertItkToVtkImage(itkImage) {
|
|
|
35
54
|
spacing: [1, 1, 1]
|
|
36
55
|
};
|
|
37
56
|
var dimensions = [1, 1, 1];
|
|
38
|
-
var direction = [1, 0, 0, 0, 1, 0, 0, 0, 1];
|
|
57
|
+
var direction = [1, 0, 0, 0, 1, 0, 0, 0, 1]; // Check whether itkImage is an itk.js Image or an itk-wasm Image?
|
|
58
|
+
|
|
59
|
+
var isITKWasm = itkImage.direction.data === undefined;
|
|
60
|
+
var ITKPixelTypes = isITKWasm ? ITKWASMPixelTypes : ITKJSPixelTypes;
|
|
39
61
|
|
|
40
62
|
for (var idx = 0; idx < itkImage.imageType.dimension; ++idx) {
|
|
41
63
|
vtkImage.origin[idx] = itkImage.origin[idx];
|
|
@@ -47,7 +69,11 @@ function convertItkToVtkImage(itkImage) {
|
|
|
47
69
|
// matrix on the vtkImageData is a webGL matrix, which uses a
|
|
48
70
|
// column-major data layout. Transpose the direction matrix from
|
|
49
71
|
// itkImage when instantiating that vtkImageData direction matrix.
|
|
50
|
-
|
|
72
|
+
if (isITKWasm) {
|
|
73
|
+
direction[col + idx * 3] = itkImage.direction[idx + col * itkImage.imageType.dimension];
|
|
74
|
+
} else {
|
|
75
|
+
direction[col + idx * 3] = itkImage.direction.data[idx + col * itkImage.imageType.dimension];
|
|
76
|
+
}
|
|
51
77
|
}
|
|
52
78
|
} // Create VTK Image Data
|
|
53
79
|
|
|
@@ -66,7 +92,7 @@ function convertItkToVtkImage(itkImage) {
|
|
|
66
92
|
imageData.getPointData().setScalars(pointData); // Associate the point data that are 3D vectors / tensors
|
|
67
93
|
// Refer to itk-js/src/PixelTypes.js for numerical values
|
|
68
94
|
|
|
69
|
-
switch (itkImage.imageType.pixelType) {
|
|
95
|
+
switch (ITKPixelTypes[itkImage.imageType.pixelType]) {
|
|
70
96
|
case ITKPixelTypes.Scalar:
|
|
71
97
|
break;
|
|
72
98
|
|
|
@@ -148,7 +174,7 @@ function convertVtkToItkImage(vtkImage) {
|
|
|
148
174
|
var itkImage = {
|
|
149
175
|
imageType: {
|
|
150
176
|
dimension: 3,
|
|
151
|
-
pixelType:
|
|
177
|
+
pixelType: ITKJSPixelTypes.Scalar,
|
|
152
178
|
componentType: '',
|
|
153
179
|
components: 1
|
|
154
180
|
},
|
|
@@ -176,10 +202,10 @@ function convertVtkToItkImage(vtkImage) {
|
|
|
176
202
|
var vtkArray;
|
|
177
203
|
|
|
178
204
|
if (pointData.getTensors() !== null) {
|
|
179
|
-
itkImage.imageType.pixelType =
|
|
205
|
+
itkImage.imageType.pixelType = ITKJSPixelTypes.DiffusionTensor3D;
|
|
180
206
|
vtkArray = pointData.getTensors();
|
|
181
207
|
} else if (pointData.getVectors() != null) {
|
|
182
|
-
itkImage.imageType.pixelType =
|
|
208
|
+
itkImage.imageType.pixelType = ITKJSPixelTypes.Vector;
|
|
183
209
|
vtkArray = pointData.getVectors();
|
|
184
210
|
} else {
|
|
185
211
|
vtkArray = pointData.getScalars();
|