@kitware/vtk.js 28.7.0 → 28.8.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.
@@ -1,5 +1,5 @@
1
- import { quat } from 'gl-matrix';
2
- import { Vector2, Vector3 } from './../../types';
1
+ import { quat, vec3 } from 'gl-matrix';
2
+ import { Nullable, Vector2, Vector3 } from './../../types';
3
3
  import vtkCell, { ICellInitialValues } from './Cell';
4
4
  import { IIntersectWithLine } from './Line';
5
5
 
@@ -67,6 +67,31 @@ export interface vtkPolyLine extends vtkCell {
67
67
  * @param distance The distance from the first point of the polyline
68
68
  */
69
69
  findPointIdAtDistanceFromFirstPoint(distance: number): number;
70
+
71
+ /**
72
+ * An array of quaternions used to orient the polyline at each of its point
73
+ * The length of the array has to be the same size as the number of points
74
+ * Defaults to null.
75
+ */
76
+ getOrientations(): Nullable<quat[]>;
77
+
78
+ /**
79
+ * @see getOrientations
80
+ * @param orientations
81
+ */
82
+ setOrientations(orientations: Nullable<quat[]>): boolean;
83
+
84
+ /**
85
+ * The function used in getDistancesToFirstPoint and in findPointIdAtDistanceFromFirstPoint
86
+ * Defaults to vec3.dist of gl-matrix
87
+ */
88
+ getDistanceFunction(): (a: vec3, b: vec3) => number;
89
+
90
+ /**
91
+ * @see getDistanceFunction
92
+ * @param f
93
+ */
94
+ setDistanceFunction(f: (a: vec3, b: vec3) => number): boolean;
70
95
  }
71
96
 
72
97
  /**
@@ -58,7 +58,9 @@ function vtkPolyLine(publicAPI, model) {
58
58
  };
59
59
 
60
60
  publicAPI.getDistancesToFirstPoint = function () {
61
- if (model.distancesTime.getMTime() < model.points.getMTime()) {
61
+ var dTime = model.distancesTime.getMTime();
62
+
63
+ if (dTime < model.points.getMTime() || dTime < publicAPI.getMTime()) {
62
64
  var numPoints = publicAPI.getNumberOfPoints();
63
65
 
64
66
  if (!model.distances) {
@@ -76,7 +78,7 @@ function vtkPolyLine(publicAPI, model) {
76
78
 
77
79
  for (var i = 1; i < numPoints; ++i) {
78
80
  model.points.getPoint(i, currentPoint);
79
- totalDistance += vec3.dist(previousPoint, currentPoint);
81
+ totalDistance += model.distanceFunction(previousPoint, currentPoint);
80
82
  model.distances[i] = totalDistance;
81
83
  vec3.copy(previousPoint, currentPoint);
82
84
  }
@@ -121,15 +123,16 @@ function vtkPolyLine(publicAPI, model) {
121
123
 
122
124
 
123
125
  var DEFAULT_VALUES = {
124
- orientations: null // an array of quat or null
125
-
126
+ orientations: null,
127
+ // an array of quat or null
128
+ distanceFunction: vec3.dist
126
129
  }; // ----------------------------------------------------------------------------
127
130
 
128
131
  function extend(publicAPI, model) {
129
132
  var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
130
133
  Object.assign(model, DEFAULT_VALUES, initialValues);
131
134
  vtkCell.extend(publicAPI, model, initialValues);
132
- macro.setGet(publicAPI, model, ['orientations']);
135
+ macro.setGet(publicAPI, model, ['orientations', 'distanceFunction']);
133
136
  model.distancesTime = {};
134
137
  macro.obj(model.distancesTime, {
135
138
  mtime: 0
@@ -62,6 +62,21 @@ export interface vtkImageCPRMapper extends vtkAbstractMapper3D {
62
62
  */
63
63
  setUseUniformOrientation(useUniformOrientation: boolean): boolean;
64
64
 
65
+ /**
66
+ * A point used to offset each line of pixel in the rendering
67
+ * The line of pixel is offseted such as the center of the line is as close as possible to the center point
68
+ * This can be used in combination with @see getUseUniformOrientation and a custom distance function for @see getOrientedCenterline to visualize a CPR in projected mode or stretched mode
69
+ * Defaults to null.
70
+ * @returns the center point
71
+ */
72
+ getCenterPoint(): Nullable<vec3>;
73
+
74
+ /**
75
+ * @see getCenterPoint
76
+ * @param point
77
+ */
78
+ setCenterPoint(point: Nullable<vec3>): boolean;
79
+
65
80
  /**
66
81
  * This flag indicates wether the GPU should use half float or not
67
82
  * When true, will use half float
@@ -191,6 +206,17 @@ export interface vtkImageCPRMapper extends vtkAbstractMapper3D {
191
206
  */
192
207
  preRenderCheck(): boolean;
193
208
 
209
+ /**
210
+ * Configure the mapper and the centerline to be in straightened CPR mode
211
+ */
212
+ useStraightenedMode(): void;
213
+
214
+ /**
215
+ * Configure the mapper and the centerline to be in strectched CPR mode
216
+ * @param centerPoint The center point, optional, default to the first point of the centerline or [0, 0, 0]
217
+ */
218
+ useStretchedMode(centerPoint?: Nullable<vec3>): void;
219
+
194
220
  /**
195
221
  * Set the polydata used as a centerline
196
222
  * You can also use `publicAPI.setInputData(centerlineData, 1);`
@@ -346,7 +372,10 @@ export function newInstance(initialValues?: IImageCPRMapperInitialValues): vtkIm
346
372
 
347
373
  /**
348
374
  * CPR in vtkImageCPRMapper stands for Curved Planar Reformation. This mapper
349
- * can be used to visualize tubular structures such as blood vessels.
375
+ * can be used to visualize tubular structures such as blood vessels. It can be
376
+ * used in projected mode, stretched mode or straightened mode depending on the
377
+ * settings @see getUseUniformOrientation , @see getCenterPoint and the distance
378
+ * function of @see getOrientedCenterline .
350
379
  *
351
380
  * This specialised mapper takes as input a vtkImageData representing a volume
352
381
  * ( @see setImageData ) and a vtkPolyData representing a centerline
@@ -293,6 +293,36 @@ function vtkImageCPRMapper(publicAPI, model) {
293
293
  return true;
294
294
  };
295
295
 
296
+ publicAPI.useStraightenedMode = function () {
297
+ publicAPI.setCenterPoint(null);
298
+ publicAPI.setUseUniformOrientation(false);
299
+ publicAPI.getOrientedCenterline().setDistanceFunction(vec3.dist);
300
+ };
301
+
302
+ publicAPI.useStretchedMode = function (centerPoint) {
303
+ var centerline = publicAPI.getOrientedCenterline(); // Set center point
304
+
305
+ if (!centerPoint) {
306
+ // Get the first point of the centerline if there is one
307
+ var centerlinePoints = centerline.getPoints();
308
+ var newCenterPoint = centerlinePoints.getNumberOfTuples() > 0 ? centerlinePoints.getPoint(0) : [0, 0, 0];
309
+ publicAPI.setCenterPoint(newCenterPoint);
310
+ } else {
311
+ publicAPI.setCenterPoint(centerPoint);
312
+ } // Enable uniform orientation
313
+
314
+
315
+ publicAPI.setUseUniformOrientation(true); // Change distance function
316
+
317
+ centerline.setDistanceFunction(function (a, b) {
318
+ var direction = publicAPI.getUniformDirection();
319
+ var vec = vec3.subtract([], a, b);
320
+ var d2 = vec3.squaredLength(vec);
321
+ var x = vec3.dot(direction, vec);
322
+ return Math.sqrt(d2 - x * x);
323
+ });
324
+ };
325
+
296
326
  publicAPI.setCenterlineData = function (centerlineData) {
297
327
  return publicAPI.setInputData(centerlineData, 1);
298
328
  };
@@ -326,6 +356,7 @@ var DEFAULT_VALUES = {
326
356
  width: 10,
327
357
  uniformOrientation: [0, 0, 0, 1],
328
358
  useUniformOrientation: false,
359
+ centerPoint: null,
329
360
  preferSizeOverAccuracy: false,
330
361
  orientationArrayName: null,
331
362
  tangentDirection: [1, 0, 0],
@@ -345,7 +376,7 @@ function extend(publicAPI, model) {
345
376
  mtime: 0
346
377
  }); // Setters and getters
347
378
 
348
- macro.setGet(publicAPI, model, ['width', 'uniformOrientation', 'useUniformOrientation', 'preferSizeOverAccuracy', 'orientationArrayName', 'tangentDirection', 'bitangentDirection', 'normalDirection']);
379
+ macro.setGet(publicAPI, model, ['width', 'uniformOrientation', 'useUniformOrientation', 'centerPoint', 'preferSizeOverAccuracy', 'orientationArrayName', 'tangentDirection', 'bitangentDirection', 'normalDirection']);
349
380
  CoincidentTopologyHelper.implementCoincidentTopologyMethods(publicAPI, model); // Object methods
350
381
 
351
382
  vtkImageCPRMapper(publicAPI, model);
@@ -449,14 +449,20 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
449
449
  publicAPI.getNeedToRebuildShaders = function (cellBO, ren, actor) {
450
450
  // has something changed that would require us to recreate the shader?
451
451
  // candidates are
452
+ // presence of centerPoint
453
+ // value of useUniformOrientation
452
454
  // property modified (representation interpolation and lighting)
453
455
  // input modified
454
456
  // light complexity changed
455
457
  // render pass shader replacement changed
456
458
  var tNumComp = model.volumeTexture.getComponents();
457
459
  var iComp = actor.getProperty().getIndependentComponents();
460
+ var useCenterPoint = !!model.renderable.getCenterPoint();
461
+ var useUniformOrientation = model.renderable.getUseUniformOrientation();
458
462
 
459
- if (model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || cellBO.getProgram() === 0 || model.lastTextureComponents !== tNumComp || model.lastIndependentComponents !== iComp) {
463
+ if (cellBO.getProgram() === 0 || model.lastUseCenterPoint !== useCenterPoint || model.lastUseUniformOrientation !== useUniformOrientation || model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || model.lastTextureComponents !== tNumComp || model.lastIndependentComponents !== iComp) {
464
+ model.lastUseCenterPoint = useCenterPoint;
465
+ model.lastUseUniformOrientation = useUniformOrientation;
460
466
  model.lastHaveSeenDepthRequest = model.haveSeenDepthRequest;
461
467
  model.lastTextureComponents = tNumComp;
462
468
  model.lastIndependentComponents = iComp;
@@ -521,6 +527,12 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
521
527
  tcoordFSDec.push('in vec3 centerlineTopDirVSOutput;', 'in vec3 centerlineBotDirVSOutput;', 'in float centerlineAngleVSOutput;');
522
528
  }
523
529
 
530
+ var centerPoint = model.renderable.getCenterPoint();
531
+
532
+ if (centerPoint) {
533
+ tcoordFSDec.push('uniform vec3 globalCenterPoint;');
534
+ }
535
+
524
536
  if (iComps) {
525
537
  for (var comp = 1; comp < tNumComp; comp++) {
526
538
  tcoordFSDec = tcoordFSDec.concat([// color shift and scale
@@ -566,7 +578,13 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
566
578
  tcoordFSImpl.push('vec3 interpolatedCenterlineDir;', 'if (centerlineAngleVSOutput < 0.0) {', ' // Lerp', ' interpolatedCenterlineDir = quadOffsetVSOutput.y * centerlineTopDirVSOutput + (1.0 - quadOffsetVSOutput.y) * centerlineBotDirVSOutput;', '} else {', ' // Slerp', ' float topInterpolationAngle = quadOffsetVSOutput.y * centerlineAngleVSOutput;', ' float botInterpolationAngle = centerlineAngleVSOutput - topInterpolationAngle;', ' interpolatedCenterlineDir = sin(topInterpolationAngle) * centerlineTopDirVSOutput + sin(botInterpolationAngle) * centerlineBotDirVSOutput;', '}', '// Slerp should give a normalized vector but when sin(angle) is small, rounding error occurs', '// Normalize for both lerp and slerp', 'interpolatedCenterlineDir = normalize(interpolatedCenterlineDir);');
567
579
  }
568
580
 
569
- tcoordFSImpl.push('vec3 volumePosMC = centerlinePosVSOutput + quadOffsetVSOutput.x * interpolatedCenterlineDir;', 'vec3 volumePosTC = (MCTCMatrix * vec4(volumePosMC, 1.0)).xyz;', 'if (any(lessThan(volumePosTC, vec3(0.0))) || any(greaterThan(volumePosTC, vec3(1.0))))', '{', ' // set the background color and exit', ' gl_FragData[0] = backgroundColor;', ' return;', '}', 'vec4 tvalue = texture(volumeTexture, volumePosTC);');
581
+ if (centerPoint) {
582
+ tcoordFSImpl.push('float baseOffset = dot(interpolatedCenterlineDir, globalCenterPoint - centerlinePosVSOutput);', 'float horizontalOffset = quadOffsetVSOutput.x + baseOffset;');
583
+ } else {
584
+ tcoordFSImpl.push('float horizontalOffset = quadOffsetVSOutput.x;');
585
+ }
586
+
587
+ tcoordFSImpl.push('vec3 volumePosMC = centerlinePosVSOutput + horizontalOffset * interpolatedCenterlineDir;', 'vec3 volumePosTC = (MCTCMatrix * vec4(volumePosMC, 1.0)).xyz;', 'if (any(lessThan(volumePosTC, vec3(0.0))) || any(greaterThan(volumePosTC, vec3(1.0))))', '{', ' // set the background color and exit', ' gl_FragData[0] = backgroundColor;', ' return;', '}', 'vec4 tvalue = texture(volumeTexture, volumePosTC);');
570
588
 
571
589
  if (iComps) {
572
590
  var rgba = ['r', 'g', 'b', 'a'];
@@ -685,6 +703,11 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
685
703
  if (cellBO.getProgram().isUniformUsed('centerlineDirection')) {
686
704
  var uniformDirection = model.renderable.getUniformDirection();
687
705
  cellBO.getProgram().setUniform3fArray('centerlineDirection', uniformDirection);
706
+ }
707
+
708
+ if (cellBO.getProgram().isUniformUsed('globalCenterPoint')) {
709
+ var centerPoint = model.renderable.getCenterPoint();
710
+ cellBO.getProgram().setUniform3fArray('globalCenterPoint', centerPoint);
688
711
  } // Model coordinates to image space
689
712
  // getWorldToIndex is badly named and is in fact modelToIndex
690
713
  // MCIC -> Model coordinates to index coordinates
@@ -365,6 +365,10 @@ function widgetBehavior(publicAPI, model) {
365
365
  var _manipulator$handleEv3 = manipulator.handleEvent(calldata, model._apiSpecificRenderWindow),
366
366
  worldCoords = _manipulator$handleEv3.worldCoords;
367
367
 
368
+ if (!worldCoords || !worldCoords.length) {
369
+ return;
370
+ }
371
+
368
372
  var center = model.widgetState.getCenter();
369
373
  var currentVectorToOrigin = [0, 0, 0];
370
374
  subtract(worldCoords, center, currentVectorToOrigin);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "28.7.0",
3
+ "version": "28.8.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",