@kitware/vtk.js 27.4.6 → 28.0.0
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/BREAKING_CHANGES.md +4 -0
- package/Common/DataModel/Line.d.ts +24 -2
- package/Common/DataModel/Line.js +17 -1
- package/Common/DataModel/PolyLine.d.ts +36 -2
- package/Common/DataModel/PolyLine.js +80 -10
- package/Common/Transform/Transform.d.ts +177 -0
- package/Common/Transform/Transform.js +81 -3
- package/Proxy/Core/View2DProxy.js +22 -12
- package/Rendering/Core/AbstractMapper3D.d.ts +1 -3
- package/Rendering/Core/AbstractMapper3D.js +21 -45
- package/Rendering/Core/ImageCPRMapper.d.ts +380 -0
- package/Rendering/Core/ImageCPRMapper.js +361 -0
- package/Rendering/OpenGL/ImageCPRMapper.js +919 -0
- package/Rendering/OpenGL/Profiles/All.js +1 -0
- package/Rendering/OpenGL/Profiles/Volume.js +1 -0
- package/Rendering/OpenGL/RenderWindow/Constants.js +3 -2
- package/Rendering/OpenGL/RenderWindow.js +38 -45
- package/Rendering/Profiles/All.js +1 -0
- package/Rendering/Profiles/Volume.js +1 -0
- package/Widgets/Core/WidgetManager.js +1 -1
- package/Widgets/Manipulators/AbstractManipulator.d.ts +2 -2
- package/Widgets/Manipulators/CPRManipulator.js +138 -0
- package/Widgets/Manipulators/LineManipulator.js +3 -1
- package/Widgets/Manipulators/PlaneManipulator.js +3 -1
- package/Widgets/Manipulators/TrackballManipulator.js +3 -1
- package/Widgets/Widgets3D/AngleWidget/behavior.js +5 -2
- package/Widgets/Widgets3D/DistanceWidget/behavior.js +5 -2
- package/Widgets/Widgets3D/ImageCroppingWidget/behavior.js +3 -3
- package/Widgets/Widgets3D/ImplicitPlaneWidget.js +3 -1
- package/Widgets/Widgets3D/LabelWidget/behavior.js +5 -2
- package/Widgets/Widgets3D/LineWidget/behavior.js +4 -2
- package/Widgets/Widgets3D/PaintWidget/behavior.js +2 -1
- package/Widgets/Widgets3D/PolyLineWidget/behavior.js +2 -1
- package/Widgets/Widgets3D/ResliceCursorWidget/Constants.js +2 -1
- package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +72 -34
- package/Widgets/Widgets3D/ResliceCursorWidget/cprBehavior.js +92 -0
- package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +64 -18
- package/Widgets/Widgets3D/ResliceCursorWidget/state.js +30 -16
- package/Widgets/Widgets3D/ResliceCursorWidget.js +43 -20
- package/Widgets/Widgets3D/ShapeWidget/behavior.js +4 -2
- package/Widgets/Widgets3D/SphereWidget/behavior.js +1 -1
- package/Widgets/Widgets3D/SplineWidget/behavior.js +3 -1
- package/index.d.ts +2 -0
- package/package.json +3 -2
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import { vec3, mat4, quat } from 'gl-matrix';
|
|
3
|
+
import CoincidentTopologyHelper from './Mapper/CoincidentTopologyHelper.js';
|
|
4
|
+
import vtkAbstractImageMapper from './AbstractImageMapper.js';
|
|
5
|
+
import macro from '../../macros.js';
|
|
6
|
+
import vtkPoints from '../../Common/Core/Points.js';
|
|
7
|
+
import vtkPolyLine from '../../Common/DataModel/PolyLine.js';
|
|
8
|
+
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
10
|
+
|
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
+
var vtkErrorMacro = macro.vtkErrorMacro;
|
|
13
|
+
var staticOffsetAPI = CoincidentTopologyHelper.staticOffsetAPI,
|
|
14
|
+
otherStaticMethods = CoincidentTopologyHelper.otherStaticMethods; // ----------------------------------------------------------------------------
|
|
15
|
+
// vtkImageCPRMapper methods
|
|
16
|
+
// ----------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
function vtkImageCPRMapper(publicAPI, model) {
|
|
19
|
+
// Set our className
|
|
20
|
+
model.classHierarchy.push('vtkImageCPRMapper');
|
|
21
|
+
|
|
22
|
+
var superClass = _objectSpread({}, publicAPI);
|
|
23
|
+
/**
|
|
24
|
+
* Public methods
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
publicAPI.getBounds = function () {
|
|
29
|
+
var imageWidth = publicAPI.getWidth();
|
|
30
|
+
var imageHeight = publicAPI.getHeight();
|
|
31
|
+
return [0, imageWidth, 0, imageHeight, 0, 0];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
publicAPI.getOrientationDataArray = function () {
|
|
35
|
+
var _publicAPI$getInputDa;
|
|
36
|
+
|
|
37
|
+
var pointData = (_publicAPI$getInputDa = publicAPI.getInputData(1)) === null || _publicAPI$getInputDa === void 0 ? void 0 : _publicAPI$getInputDa.getPointData();
|
|
38
|
+
|
|
39
|
+
if (!pointData) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (model.orientationArrayName !== null) {
|
|
44
|
+
return pointData.getArrayByName(model.orientationArrayName) || null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return pointData.getArrayByName('Orientation') || pointData.getArrayByName('Direction') || pointData.getVectors() || pointData.getTensors() || pointData.getNormals() || null;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
publicAPI.getOrientedCenterline = function () {
|
|
51
|
+
var inputPolydata = publicAPI.getInputData(1);
|
|
52
|
+
|
|
53
|
+
if (!inputPolydata) {
|
|
54
|
+
// No polydata: return previous centerline
|
|
55
|
+
// Don't reset centerline as it could have been set using setOrientedCenterline
|
|
56
|
+
return model._orientedCenterline;
|
|
57
|
+
} // Get dependencies of centerline
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
var orientationDataArray = publicAPI.getOrientationDataArray();
|
|
61
|
+
var linesDataArray = inputPolydata.getLines();
|
|
62
|
+
var pointsDataArray = inputPolydata.getPoints();
|
|
63
|
+
|
|
64
|
+
if (!model.useUniformOrientation && !orientationDataArray) {
|
|
65
|
+
vtkErrorMacro('Failed to create oriented centerline from polydata: no orientation');
|
|
66
|
+
|
|
67
|
+
publicAPI._resetOrientedCenterline();
|
|
68
|
+
|
|
69
|
+
return model._orientedCenterline;
|
|
70
|
+
} // If centerline didn't change, don't recompute
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
var centerlineTime = model._orientedCenterline.getMTime();
|
|
74
|
+
|
|
75
|
+
if (centerlineTime >= publicAPI.getMTime() && centerlineTime > linesDataArray.getMTime() && centerlineTime > pointsDataArray.getMTime() && (model.useUniformOrientation || centerlineTime > orientationDataArray.getMTime())) {
|
|
76
|
+
return model._orientedCenterline;
|
|
77
|
+
} // Get points of the centerline
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
var linesData = linesDataArray.getData();
|
|
81
|
+
|
|
82
|
+
if (linesData.length <= 0) {
|
|
83
|
+
// No polyline
|
|
84
|
+
publicAPI._resetOrientedCenterline();
|
|
85
|
+
|
|
86
|
+
return model._orientedCenterline;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var nPoints = linesData[0];
|
|
90
|
+
|
|
91
|
+
if (nPoints <= 1) {
|
|
92
|
+
// Empty centerline
|
|
93
|
+
publicAPI._resetOrientedCenterline();
|
|
94
|
+
|
|
95
|
+
return model._orientedCenterline;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var pointIndices = linesData.subarray(1, 1 + nPoints); // Get orientations of the centerline
|
|
99
|
+
|
|
100
|
+
var orientations = new Array(nPoints); // Function to convert from mat4, mat3, quat or vec3 to quaternion
|
|
101
|
+
|
|
102
|
+
var convert = function convert() {
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
var numComps = model.useUniformOrientation ? model.uniformOrientation.length : orientationDataArray.getNumberOfComponents();
|
|
107
|
+
|
|
108
|
+
switch (numComps) {
|
|
109
|
+
case 16:
|
|
110
|
+
convert = mat4.getRotation;
|
|
111
|
+
break;
|
|
112
|
+
|
|
113
|
+
case 9:
|
|
114
|
+
convert = function convert(outQuat, inMat) {
|
|
115
|
+
quat.fromMat3(outQuat, inMat);
|
|
116
|
+
quat.normalize(outQuat, outQuat);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
break;
|
|
120
|
+
|
|
121
|
+
case 4:
|
|
122
|
+
convert = quat.copy;
|
|
123
|
+
break;
|
|
124
|
+
|
|
125
|
+
case 3:
|
|
126
|
+
convert = function convert(a, b) {
|
|
127
|
+
return quat.rotationTo(a, model.tangentDirection, b);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
break;
|
|
131
|
+
|
|
132
|
+
default:
|
|
133
|
+
vtkErrorMacro('Orientation doesnt match mat4, mat3, quat or vec3');
|
|
134
|
+
|
|
135
|
+
publicAPI._resetOrientedCenterline();
|
|
136
|
+
|
|
137
|
+
return model._orientedCenterline;
|
|
138
|
+
} // Function to get orientation from point index
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
var getOrientation = function getOrientation() {
|
|
142
|
+
return null;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
if (model.useUniformOrientation) {
|
|
146
|
+
var outQuat = new Float64Array(4);
|
|
147
|
+
convert(outQuat, model.uniformOrientation);
|
|
148
|
+
|
|
149
|
+
getOrientation = function getOrientation() {
|
|
150
|
+
return outQuat;
|
|
151
|
+
};
|
|
152
|
+
} else {
|
|
153
|
+
var temp = new Float64Array(16);
|
|
154
|
+
|
|
155
|
+
getOrientation = function getOrientation(i) {
|
|
156
|
+
var outQuat = new Float64Array(4);
|
|
157
|
+
orientationDataArray.getTuple(i, temp);
|
|
158
|
+
convert(outQuat, temp);
|
|
159
|
+
return outQuat;
|
|
160
|
+
};
|
|
161
|
+
} // Fill the orientation array
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
for (var i = 0; i < nPoints; ++i) {
|
|
165
|
+
var pointIdx = pointIndices[i];
|
|
166
|
+
orientations[i] = getOrientation(pointIdx);
|
|
167
|
+
} // Done recomputing
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
model._orientedCenterline.initialize(pointsDataArray, pointIndices);
|
|
171
|
+
|
|
172
|
+
model._orientedCenterline.setOrientations(orientations);
|
|
173
|
+
|
|
174
|
+
return model._orientedCenterline;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
publicAPI.setOrientedCenterline = function (centerline) {
|
|
178
|
+
if (model._orientedCenterline !== centerline) {
|
|
179
|
+
model._orientedCenterline = centerline;
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return false;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
publicAPI._resetOrientedCenterline = function () {
|
|
187
|
+
model._orientedCenterline.initialize(vtkPoints.newInstance());
|
|
188
|
+
|
|
189
|
+
model._orientedCenterline.setOrientations([]);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
publicAPI.getMTime = function () {
|
|
193
|
+
var mTime = superClass.getMTime();
|
|
194
|
+
|
|
195
|
+
if (!model._orientedCenterline) {
|
|
196
|
+
return mTime;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
mTime = Math.max(mTime, model._orientedCenterline.getMTime());
|
|
200
|
+
return mTime;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
publicAPI.getHeight = function () {
|
|
204
|
+
var accHeights = publicAPI.getOrientedCenterline().getDistancesToFirstPoint();
|
|
205
|
+
|
|
206
|
+
if (accHeights.length === 0) {
|
|
207
|
+
return 0;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return accHeights[accHeights.length - 1];
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
publicAPI.getCenterlinePositionAndOrientation = function (distance) {
|
|
214
|
+
var centerline = publicAPI.getOrientedCenterline();
|
|
215
|
+
var subId = centerline.findPointIdAtDistanceFromFirstPoint(distance);
|
|
216
|
+
|
|
217
|
+
if (subId < 0) {
|
|
218
|
+
return {};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
var distances = centerline.getDistancesToFirstPoint();
|
|
222
|
+
var pcoords = [(distance - distances[subId]) / (distances[subId + 1] - distances[subId])];
|
|
223
|
+
var weights = new Array(2);
|
|
224
|
+
var position = new Array(3);
|
|
225
|
+
centerline.evaluateLocation(subId, pcoords, position, weights);
|
|
226
|
+
var orientation = new Array(4);
|
|
227
|
+
|
|
228
|
+
if (!centerline.evaluateOrientation(subId, pcoords, orientation, weights)) {
|
|
229
|
+
// No orientation
|
|
230
|
+
return {
|
|
231
|
+
position: position
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return {
|
|
236
|
+
position: position,
|
|
237
|
+
orientation: orientation
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
publicAPI.getCenterlineTangentDirections = function () {
|
|
242
|
+
var centerline = publicAPI.getOrientedCenterline();
|
|
243
|
+
|
|
244
|
+
var directionsTime = model._centerlineTangentDirectionsTime.getMTime();
|
|
245
|
+
|
|
246
|
+
if (directionsTime < centerline.getMTime()) {
|
|
247
|
+
var orientations = centerline.getOrientations();
|
|
248
|
+
model._centerlineTangentDirections = new Float32Array(3 * orientations.length);
|
|
249
|
+
var localDirection = new Array(3);
|
|
250
|
+
|
|
251
|
+
for (var i = 0; i < orientations.length; ++i) {
|
|
252
|
+
vec3.transformQuat(localDirection, model.tangentDirection, orientations[i]);
|
|
253
|
+
|
|
254
|
+
model._centerlineTangentDirections.set(localDirection, 3 * i);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
model._centerlineTangentDirectionsTime.modified();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return model._centerlineTangentDirections;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
publicAPI.getUniformDirection = function () {
|
|
264
|
+
return vec3.transformQuat(new Array(3), model.tangentDirection, model.uniformOrientation);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
publicAPI.getDirectionMatrix = function () {
|
|
268
|
+
var tangent = model.tangentDirection;
|
|
269
|
+
var bitangent = model.bitangentDirection;
|
|
270
|
+
var normal = model.normalDirection;
|
|
271
|
+
return new Float64Array([tangent[0], tangent[1], tangent[2], bitangent[0], bitangent[1], bitangent[2], normal[0], normal[1], normal[2]]);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
publicAPI.setDirectionMatrix = function (mat) {
|
|
275
|
+
if (mat4.equals(mat, publicAPI.getDirectionMatrix())) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
model.tangentDirection = [mat[0], mat[1], mat[2]];
|
|
280
|
+
model.bitangentDirection = [mat[3], mat[4], mat[5]];
|
|
281
|
+
model.normalDirection = [mat[6], mat[7], mat[8]];
|
|
282
|
+
publicAPI.modified();
|
|
283
|
+
return true;
|
|
284
|
+
}; // Check if the rendering can occur
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
publicAPI.preRenderCheck = function () {
|
|
288
|
+
if (!publicAPI.getInputData(0)) {
|
|
289
|
+
vtkErrorMacro('No image data input');
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return true;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
publicAPI.setCenterlineData = function (centerlineData) {
|
|
297
|
+
return publicAPI.setInputData(centerlineData, 1);
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
publicAPI.setCenterlineConnection = function (centerlineConnection) {
|
|
301
|
+
return publicAPI.setInputConnection(centerlineConnection, 1);
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
publicAPI.setImageData = function (imageData) {
|
|
305
|
+
return publicAPI.setInputData(imageData, 0);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
publicAPI.setImageConnection = function (imageData) {
|
|
309
|
+
return publicAPI.setInputConnection(imageData, 0);
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
publicAPI.getIsOpaque = function () {
|
|
313
|
+
return true;
|
|
314
|
+
}; // One can also call setOrientedCenterline and not provide a polydata centerline to input 1
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
model._orientedCenterline = vtkPolyLine.newInstance();
|
|
318
|
+
|
|
319
|
+
publicAPI._resetOrientedCenterline();
|
|
320
|
+
} // ----------------------------------------------------------------------------
|
|
321
|
+
// Object factory
|
|
322
|
+
// ----------------------------------------------------------------------------
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
var DEFAULT_VALUES = {
|
|
326
|
+
width: 10,
|
|
327
|
+
uniformOrientation: [0, 0, 0, 1],
|
|
328
|
+
useUniformOrientation: false,
|
|
329
|
+
preferSizeOverAccuracy: false,
|
|
330
|
+
orientationArrayName: null,
|
|
331
|
+
tangentDirection: [1, 0, 0],
|
|
332
|
+
bitangentDirection: [0, 1, 0],
|
|
333
|
+
normalDirection: [0, 0, 1]
|
|
334
|
+
}; // ----------------------------------------------------------------------------
|
|
335
|
+
|
|
336
|
+
function extend(publicAPI, model) {
|
|
337
|
+
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
338
|
+
Object.assign(model, DEFAULT_VALUES, initialValues); // Inheritance
|
|
339
|
+
|
|
340
|
+
vtkAbstractImageMapper.extend(publicAPI, model, initialValues); // Two inputs: one for the ImageData and one for the PolyData (centerline)
|
|
341
|
+
|
|
342
|
+
macro.algo(publicAPI, model, 2, 0);
|
|
343
|
+
model._centerlineTangentDirectionsTime = {};
|
|
344
|
+
macro.obj(model._centerlineTangentDirectionsTime, {
|
|
345
|
+
mtime: 0
|
|
346
|
+
}); // Setters and getters
|
|
347
|
+
|
|
348
|
+
macro.setGet(publicAPI, model, ['width', 'uniformOrientation', 'useUniformOrientation', 'preferSizeOverAccuracy', 'orientationArrayName', 'tangentDirection', 'bitangentDirection', 'normalDirection']);
|
|
349
|
+
CoincidentTopologyHelper.implementCoincidentTopologyMethods(publicAPI, model); // Object methods
|
|
350
|
+
|
|
351
|
+
vtkImageCPRMapper(publicAPI, model);
|
|
352
|
+
} // ----------------------------------------------------------------------------
|
|
353
|
+
|
|
354
|
+
var newInstance = macro.newInstance(extend, 'vtkImageCPRMapper'); // ----------------------------------------------------------------------------
|
|
355
|
+
|
|
356
|
+
var index = _objectSpread(_objectSpread({
|
|
357
|
+
newInstance: newInstance,
|
|
358
|
+
extend: extend
|
|
359
|
+
}, staticOffsetAPI), otherStaticMethods);
|
|
360
|
+
|
|
361
|
+
export { index as default, extend, newInstance };
|