@kitware/vtk.js 27.5.0 → 28.0.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.
Files changed (46) hide show
  1. package/BREAKING_CHANGES.md +4 -0
  2. package/Common/DataModel/Line.d.ts +24 -2
  3. package/Common/DataModel/Line.js +17 -1
  4. package/Common/DataModel/PolyLine.d.ts +36 -2
  5. package/Common/DataModel/PolyLine.js +80 -10
  6. package/Common/Transform/Transform.d.ts +177 -0
  7. package/Common/Transform/Transform.js +81 -3
  8. package/Proxy/Core/View2DProxy.js +22 -12
  9. package/Rendering/Core/AbstractMapper3D.d.ts +1 -3
  10. package/Rendering/Core/AbstractMapper3D.js +21 -45
  11. package/Rendering/Core/ImageCPRMapper.d.ts +380 -0
  12. package/Rendering/Core/ImageCPRMapper.js +361 -0
  13. package/Rendering/Core/ImageProperty/Constants.js +2 -2
  14. package/Rendering/Core/ImageProperty.js +2 -2
  15. package/Rendering/OpenGL/ImageCPRMapper.js +919 -0
  16. package/Rendering/OpenGL/ImageResliceMapper.js +2 -2
  17. package/Rendering/OpenGL/Profiles/All.js +1 -0
  18. package/Rendering/OpenGL/Profiles/Volume.js +1 -0
  19. package/Rendering/OpenGL/glsl/vtkVolumeFS.glsl.js +1 -1
  20. package/Rendering/Profiles/All.js +1 -0
  21. package/Rendering/Profiles/Volume.js +1 -0
  22. package/Widgets/Core/WidgetManager.js +1 -1
  23. package/Widgets/Manipulators/AbstractManipulator.d.ts +2 -2
  24. package/Widgets/Manipulators/CPRManipulator.js +138 -0
  25. package/Widgets/Manipulators/LineManipulator.js +3 -1
  26. package/Widgets/Manipulators/PlaneManipulator.js +3 -1
  27. package/Widgets/Manipulators/TrackballManipulator.js +3 -1
  28. package/Widgets/Widgets3D/AngleWidget/behavior.js +5 -2
  29. package/Widgets/Widgets3D/DistanceWidget/behavior.js +5 -2
  30. package/Widgets/Widgets3D/ImageCroppingWidget/behavior.js +3 -3
  31. package/Widgets/Widgets3D/ImplicitPlaneWidget.js +3 -1
  32. package/Widgets/Widgets3D/LabelWidget/behavior.js +5 -2
  33. package/Widgets/Widgets3D/LineWidget/behavior.js +4 -2
  34. package/Widgets/Widgets3D/PaintWidget/behavior.js +2 -1
  35. package/Widgets/Widgets3D/PolyLineWidget/behavior.js +2 -1
  36. package/Widgets/Widgets3D/ResliceCursorWidget/Constants.js +2 -1
  37. package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +72 -34
  38. package/Widgets/Widgets3D/ResliceCursorWidget/cprBehavior.js +92 -0
  39. package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +64 -18
  40. package/Widgets/Widgets3D/ResliceCursorWidget/state.js +30 -16
  41. package/Widgets/Widgets3D/ResliceCursorWidget.js +43 -20
  42. package/Widgets/Widgets3D/ShapeWidget/behavior.js +4 -2
  43. package/Widgets/Widgets3D/SphereWidget/behavior.js +1 -1
  44. package/Widgets/Widgets3D/SplineWidget/behavior.js +3 -1
  45. package/index.d.ts +2 -0
  46. package/package.json +1 -1
@@ -1,76 +1,52 @@
1
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
1
3
  import macro from '../../macros.js';
2
4
  import vtkAbstractMapper from './AbstractMapper.js';
3
- import { u as uninitializeBounds } from '../../Common/Core/Math/index.js';
5
+ import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
4
6
 
7
+ 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; }
8
+
9
+ 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; }
5
10
  // vtkAbstractMapper methods
6
11
  // ----------------------------------------------------------------------------
7
12
 
8
13
  function vtkAbstractMapper3D(publicAPI, model) {
9
14
  publicAPI.getBounds = function () {
10
- return 0;
11
- };
12
-
13
- publicAPI.getBounds = function (bounds) {
14
- publicAPI.getBounds();
15
-
16
- for (var i = 0; i < 6; i++) {
17
- bounds[i] = model.bounds[i];
18
- }
15
+ macro.vtkErrorMacro("vtkAbstractMapper3D.getBounds - NOT IMPLEMENTED");
19
16
  };
20
17
 
21
18
  publicAPI.getCenter = function () {
22
- publicAPI.getBounds();
19
+ var _model$center;
23
20
 
24
- for (var i = 0; i < 3; i++) {
25
- model.center[i] = (model.bounds[2 * i + 1] + model.bounds[2 * i]) / 2.0;
26
- }
27
-
28
- return model.center.slice();
21
+ var bounds = publicAPI.getBounds();
22
+ model.center = vtkBoundingBox.isValid(bounds) ? vtkBoundingBox.getCenter(bounds) : null;
23
+ return (_model$center = model.center) === null || _model$center === void 0 ? void 0 : _model$center.slice();
29
24
  };
30
25
 
31
26
  publicAPI.getLength = function () {
32
- var diff = 0.0;
33
- var l = 0.0;
34
- publicAPI.getBounds();
35
-
36
- for (var i = 0; i < 3; i++) {
37
- diff = model.bounds[2 * i + 1] - model.bounds[2 * i];
38
- l += diff * diff;
39
- }
40
-
41
- return Math.sqrt(l);
27
+ var bounds = publicAPI.getBounds();
28
+ return vtkBoundingBox.getDiagonalLength(bounds);
42
29
  };
43
30
  } // ----------------------------------------------------------------------------
44
31
  // Object factory
45
32
  // ----------------------------------------------------------------------------
46
33
 
47
34
 
48
- var DEFAULT_VALUES = {
49
- bounds: [1, -1, 1, -1, 1, -1],
50
- center: [0, 0, 0],
51
- viewSpecificProperties: null
35
+ var defaultValues = function defaultValues(initialValues) {
36
+ return _objectSpread({
37
+ bounds: _toConsumableArray(vtkBoundingBox.INIT_BOUNDS),
38
+ center: [0, 0, 0],
39
+ viewSpecificProperties: {}
40
+ }, initialValues);
52
41
  }; // ----------------------------------------------------------------------------
53
42
 
43
+
54
44
  function extend(publicAPI, model) {
55
45
  var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
56
- Object.assign(model, DEFAULT_VALUES, initialValues); // Inheritance
46
+ Object.assign(model, defaultValues(initialValues)); // Inheritance
57
47
 
58
48
  vtkAbstractMapper.extend(publicAPI, model, initialValues);
59
-
60
- if (!model.bounds) {
61
- uninitializeBounds(model.bounds);
62
- }
63
-
64
- if (!model.center) {
65
- model.center = [0.0, 0.0, 0.0];
66
- }
67
-
68
49
  macro.setGet(publicAPI, model, ['viewSpecificProperties']);
69
-
70
- if (!model.viewSpecificProperties) {
71
- model.viewSpecificProperties = {};
72
- }
73
-
74
50
  vtkAbstractMapper3D(publicAPI, model);
75
51
  } // ----------------------------------------------------------------------------
76
52
 
@@ -0,0 +1,380 @@
1
+ import { mat3, mat4, quat, vec3 } from "gl-matrix";
2
+ import { Nullable } from './../../types';
3
+ import { vtkOutputPort } from './../../interfaces';
4
+ import vtkAbstractMapper3D, { IAbstractMapper3DInitialValues } from './AbstractMapper3D';
5
+ import vtkDataArray from './../../Common/Core/DataArray';
6
+ import vtkImageData from './../../Common/DataModel/ImageData';
7
+ import vtkPolyData from './../../Common/DataModel/PolyData';
8
+ import vtkPolyLine from './../../Common/DataModel/PolyLine';
9
+
10
+ interface ICoincidentTopology {
11
+ factor: number;
12
+ offset: number;
13
+ }
14
+
15
+ type TOrientation = mat4 | mat3 | quat | vec3;
16
+
17
+ export interface IImageCPRMapperInitialValues extends IAbstractMapper3DInitialValues{
18
+ width: number;
19
+ uniformOrientation: TOrientation; // Don't use vec3 if possible
20
+ useUniformOrientation: boolean;
21
+ preferSizeOverAccuracy: boolean; // Whether to use halfFloat representation of float, when it is inaccurate
22
+ orientationArrayName: Nullable<string>;
23
+ tangentDirection: vec3;
24
+ bitangentDirection: vec3;
25
+ normalDirection: vec3;
26
+ }
27
+
28
+ export interface vtkImageCPRMapper extends vtkAbstractMapper3D {
29
+ /**
30
+ * @returns the width of the image in model coordinates of the input volume
31
+ */
32
+ getWidth(): number;
33
+
34
+ /**
35
+ * @see getWidth
36
+ * @param width
37
+ */
38
+ setWidth(width: number): boolean;
39
+
40
+ /**
41
+ * Use @see getUseUniformOrientation to use the uniform orientation instead of the orientation specified by the centerline
42
+ * @returns the uniform orientation of the centerline
43
+ */
44
+ getUniformOrientation(): TOrientation;
45
+
46
+ /**
47
+ * @see getUniformOrientation
48
+ * @param orientation
49
+ */
50
+ setUniformOrientation(orientation: TOrientation): boolean;
51
+
52
+ /**
53
+ * This flag specifies wether the mapper should use the uniformOrientation ( @see getUniformOrientation ) or the orientation specified in centerline at centerline input ( @see setCenterlineData )
54
+ * Defaults to false.
55
+ * @returns the useUniformOrientation flag
56
+ */
57
+ getUseUniformOrientation(): boolean;
58
+
59
+ /**
60
+ * @see getUseUniformOrientation
61
+ * @param useUniformOrientation
62
+ */
63
+ setUseUniformOrientation(useUniformOrientation: boolean): boolean;
64
+
65
+ /**
66
+ * This flag indicates wether the GPU should use half float or not
67
+ * When true, will use half float
68
+ * When false, may use half float if there is no loss of accuracy (see in Texture: checkUseHalfFloat)
69
+ * Defaults to false.
70
+ * @returns the preferSizeOverAccuracy flag
71
+ */
72
+ getPreferSizeOverAccuracy(): boolean;
73
+
74
+ /**
75
+ * @see getPreferSizeOverAccuracy
76
+ * @param preferSizeOverAccuracy
77
+ */
78
+ setPreferSizeOverAccuracy(preferSizeOverAccuracy: boolean): boolean;
79
+
80
+ /**
81
+ * OrientationArrayName specifies the name of the data array which gives an orientation for each point of the centerline
82
+ * The data array has to be in the PointData attribute of the centerline input
83
+ * If null, look for the orientation data array in: "Orientation", "Direction", Vectors, Tensors, Normals
84
+ * The data array should be an array of mat4, mat3, quat or vec3 but using vec3 makes the CPRInteractor unusable
85
+ * Default to null.
86
+ */
87
+ getOrientationArrayName(): Nullable<string>;
88
+
89
+ /**
90
+ * @see getOrientationArrayName
91
+ * @param arrayName
92
+ */
93
+ setOrientationArrayName(arrayName: Nullable<string>): boolean;
94
+
95
+ /**
96
+ * For each point on the oriented centerline, the tangent direction is the direction in which the mapper will sample
97
+ * Let O (a mat3) be the orientation at a point on a centerline, and N (a vec3) the tangent direction
98
+ * Then the mapper will sample along O * N
99
+ * Default value: [1, 0, 0]
100
+ */
101
+ getTangentDirection(): vec3;
102
+
103
+ /**
104
+ * @see getTangentDirection
105
+ * @param tangent
106
+ */
107
+ setTangentDirection(tangent: vec3): boolean;
108
+
109
+ /**
110
+ * For each point on the oriented centerline, the bitangent direction forms with the normal and the tangent direction a new basis
111
+ * Default value: [0, 1, 0]
112
+ */
113
+ getBitangentDirection(): vec3;
114
+
115
+ /**
116
+ * @see getBitangentDirection
117
+ * @param bitangent
118
+ */
119
+ setBitangentDirection(bitangent: vec3): boolean;
120
+
121
+ /**
122
+ * For each point on the oriented centerline, the normal direction is the direction along the centerline
123
+ * Default value: [0, 0, 1]
124
+ */
125
+ getNormalDirection(): vec3;
126
+
127
+ /**
128
+ * @see getNormalDirection
129
+ * @param normal
130
+ */
131
+ setNormalDirection(normal: vec3): boolean;
132
+
133
+ /**
134
+ * The direction matrix is the matrix composed of tangent, bitangent and normal directions
135
+ * It is used to orient the camera or the actor
136
+ */
137
+ getDirectionMatrix(): mat3;
138
+
139
+ /**
140
+ * @see getDirectionMatrix
141
+ * @param mat
142
+ */
143
+ setDirectionMatrix(mat: mat3): boolean;
144
+
145
+ /**
146
+ * Find the data array to use for orientation in the input polydata ( @see getOrientationArrayName )
147
+ */
148
+ getOrientationDataArray(): Nullable<vtkDataArray>;
149
+
150
+ /**
151
+ * Recompute the oriented centerline from the input polydata if needed and return the result
152
+ * If there is no polydata as input, return the last oriented centerline
153
+ * It means that if no polydata is given as input and the centerline is set using @see setOrientedCenterline , the given centerline will be used
154
+ */
155
+ getOrientedCenterline(): vtkPolyLine;
156
+
157
+ /**
158
+ * Set the internal oriented centerline
159
+ * WARNING: this centerline will be overwritten if the polydata centerline is specified (input 1 @see setCenterlineData )
160
+ * @param centerline An oriented centerline
161
+ */
162
+ setOrientedCenterline(centerline: vtkPolyLine): boolean;
163
+
164
+ /**
165
+ * @returns The total height of the image in model coordinates.
166
+ */
167
+ getHeight(): number;
168
+
169
+ /**
170
+ * @param distance Distance from the beginning of the centerline, following the centerline, in model coordinates
171
+ * @returns The position and orientation which is at the given distance from the beginning of the centerline.
172
+ * If the distance is negative or greater than the length of the centerline, position and orientation are not defined.
173
+ * If the centerline is not oriented, orientation is not defined.
174
+ */
175
+ getCenterlinePositionAndOrientation(distance: number): { position?: vec3, orientation?: quat };
176
+
177
+ /**
178
+ * @returns A flat array of vec3 representing the direction at each point of the centerline
179
+ * It is computed from the orientations of the centerline and tangentDirection
180
+ * Uses caching to avoid recomputing at each frame
181
+ */
182
+ getCenterlineTangentDirections(): Float32Array;
183
+
184
+ /**
185
+ * @returns The direction to sample, in model space, computed using uniform orientation and tangent direction
186
+ */
187
+ getUniformDirection(): vec3;
188
+
189
+ /**
190
+ * @returns A boolean indicating if the mapper is ready to render
191
+ */
192
+ preRenderCheck(): boolean;
193
+
194
+ /**
195
+ * Set the polydata used as a centerline
196
+ * You can also use `publicAPI.setInputData(centerlineData, 1);`
197
+ * Use all the segments of all the polylines (the centerline can be in multiple pieces)
198
+ * The polydata can contain a PointData DataArray to specify the direction in which the mapper should sample for each point of the centerline ( @see getDirectionArrayName @see getDirectionArrayOffset )
199
+ * If no such point data is specified, a uniform direction can be used instead ( @see getUniformDirection @see getUseUniformOrientation )
200
+ * The points of the centerline are in model coordinates of the volume used as input ( @see setImageDataData ) and not index coordinates (see MCTC matrix of the OpenGL ImageCPRMapper)
201
+ * Use `imageData.getWorldToIndex();` or `imageData.getIndexToWorld();` to go from model coordinates to index coordinates or the other way around
202
+ * @param centerlineData A polydata containing one or multiple polyline(s) and optionnally a PointData DataArray for direction
203
+ */
204
+ setCenterlineData(centerlineData: vtkPolyData): void;
205
+
206
+ /**
207
+ * Same as setCenterlineData except it uses an output port instead of a polydata
208
+ * You can also use `publicAPI.setInputConnection(centerlineConnection, 1);`
209
+ * @see setCenterlineData
210
+ * @param centerlineConnection
211
+ */
212
+ setCenterlineConnection(centerlineConnection: vtkOutputPort): void;
213
+
214
+ /**
215
+ * Set the volume which should be sampled by the mapper
216
+ * You can also use `publicAPI.setInputData(imageData, 0);`
217
+ * The model coordinates of this imageData are used by this mapper when specifying points, vectors or width (see MCTC matrix of the OpenGL ImageCPRMapper)
218
+ * You can use `imageData.getWorldToIndex();` or `imageData.getIndexToWorld();` to go from this model coordinates to index coordinates or the other way around
219
+ * @param imageData
220
+ */
221
+ setImageData(imageData: vtkImageData): void;
222
+
223
+ /**
224
+ * Set the connection for the volume
225
+ * You can also use `publicAPI.setInputConnection(imageData, 0);`
226
+ * @see setImageData
227
+ * @param imageData
228
+ */
229
+ setImageConnection(imageData: vtkOutputPort): void;
230
+
231
+ /**
232
+ *
233
+ */
234
+ getResolveCoincidentTopology(): ICoincidentTopology
235
+
236
+ /**
237
+ *
238
+ */
239
+ getResolveCoincidentTopologyAsString(): ICoincidentTopology
240
+
241
+ /**
242
+ *
243
+ */
244
+ getResolveCoincidentTopologyLineOffsetParameters(): ICoincidentTopology
245
+
246
+ /**
247
+ *
248
+ */
249
+ getResolveCoincidentTopologyPointOffsetParameters(): ICoincidentTopology
250
+
251
+ /**
252
+ *
253
+ */
254
+ getResolveCoincidentTopologyPolygonOffsetFaces(): ICoincidentTopology
255
+
256
+ /**
257
+ *
258
+ */
259
+ getResolveCoincidentTopologyPolygonOffsetParameters(): ICoincidentTopology;
260
+
261
+ /**
262
+ *
263
+ * @param {Number} factor
264
+ * @param {Number} offset
265
+ */
266
+ setRelativeCoincidentTopologyLineOffsetParameters(factor: number, offset: number): boolean;
267
+
268
+ /**
269
+ *
270
+ * @param {Number} factor
271
+ * @param {Number} offset
272
+ */
273
+ setRelativeCoincidentTopologyPointOffsetParameters(factor: number, offset: number): boolean;
274
+
275
+ /**
276
+ *
277
+ * @param {Number} factor
278
+ * @param {Number} offset
279
+ */
280
+ setRelativeCoincidentTopologyPolygonOffsetParameters(factor: number, offset: number): boolean;
281
+
282
+ /**
283
+ *
284
+ * @param resolveCoincidentTopology
285
+ * @default false
286
+ */
287
+ setResolveCoincidentTopology(resolveCoincidentTopology: boolean): boolean;
288
+
289
+ /**
290
+ *
291
+ * @param {Number} factor
292
+ * @param {Number} offset
293
+ */
294
+ setResolveCoincidentTopologyLineOffsetParameters(factor: number, offset: number): boolean;
295
+
296
+ /**
297
+ *
298
+ * @param {Number} factor
299
+ * @param {Number} offset
300
+ */
301
+ setResolveCoincidentTopologyPointOffsetParameters(factor: number, offset: number): boolean;
302
+
303
+ /**
304
+ *
305
+ * @param value
306
+ */
307
+ setResolveCoincidentTopologyPolygonOffsetFaces(value: number): boolean;
308
+
309
+ /**
310
+ *
311
+ * @param {Number} factor
312
+ * @param {Number} offset
313
+ */
314
+ setResolveCoincidentTopologyPolygonOffsetParameters(factor: number, offset: number): boolean;
315
+
316
+ /**
317
+ *
318
+ */
319
+ setResolveCoincidentTopologyToDefault(): boolean;
320
+
321
+ /**
322
+ *
323
+ */
324
+ setResolveCoincidentTopologyToOff(): boolean;
325
+
326
+ /**
327
+ *
328
+ */
329
+ setResolveCoincidentTopologyToPolygonOffset(): boolean;
330
+ }
331
+
332
+ /**
333
+ * Method used to decorate a given object (publicAPI+model) with vtkImageCPRMapper characteristics.
334
+ *
335
+ * @param publicAPI object on which methods will be bounds (public)
336
+ * @param model object on which data structure will be bounds (protected)
337
+ * @param {IImageCPRMapperInitialValues} [initialValues] (default: {})
338
+ */
339
+ export function extend(publicAPI: object, model: object, initialValues?: IImageCPRMapperInitialValues): void;
340
+
341
+ /**
342
+ * Method used to create a new instance of vtkImageCPRMapper
343
+ * @param {IImageCPRMapperInitialValues} [initialValues] for pre-setting some of its content
344
+ */
345
+ export function newInstance(initialValues?: IImageCPRMapperInitialValues): vtkImageCPRMapper;
346
+
347
+ /**
348
+ * CPR in vtkImageCPRMapper stands for Curved Planar Reformation. This mapper
349
+ * can be used to visualize tubular structures such as blood vessels.
350
+ *
351
+ * This specialised mapper takes as input a vtkImageData representing a volume
352
+ * ( @see setImageData ) and a vtkPolyData representing a centerline
353
+ * ( @see setCenterlineData ). The mapper also need to have an orientation per
354
+ * point or for all points. This can be specified using a uniform orientation
355
+ * ( @see getUniformOrientation @see getUseUniformOrientation ) or a point
356
+ * data array ( @see getOrientationArrayName ). Every point, vector or length
357
+ * specified to the mapper (centerline points, orientation, width...) use model
358
+ * coordinates of the volume used as input ( @see setImageData ).
359
+ *
360
+ * For each segment of the centerline the mapper creates a quad of the
361
+ * specified width ( @see getWidth ) and of height equal to the length of the
362
+ * segment. The position and the orientation of the centerline are
363
+ * interpolated along the y-axis of the quad. The position is linearly
364
+ * interpolated (lerp) and the orientation is interpolated using
365
+ * spherical linear interpolation (slerp). For a point (x, y) on the quad,
366
+ * the value of y gives the interpolated position P and interpolated
367
+ * orientation O which combined with tangentDirection gives D
368
+ * ( @see getTangentDirection ). The value of x between -0.5 and 0.5 then gives
369
+ * the position to sample in the volume: P + x*D.
370
+ *
371
+ * By computing the right centerline positions and orientations, one
372
+ * can simulate Stretched CPR and Straightened CPR.
373
+ *
374
+ * This class resolves coincident topology with the same methods as vtkMapper.
375
+ */
376
+ export declare const vtkImageCPRMapper: {
377
+ newInstance: typeof newInstance;
378
+ extend: typeof extend;
379
+ }
380
+ export default vtkImageCPRMapper;