dwv 0.30.4 → 0.30.8

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/changelog.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.30.8](https://github.com/ivmartel/dwv/releases/tag/v0.30.8) - 03/01/2022
4
+
5
+ ### Fixed
6
+
7
+ - Load state shape does not show on correct slice [#1078](https://github.com/ivmartel/dwv/issues/1078)
8
+ - TypeError: point.get is not a function when loading state [#1077](https://github.com/ivmartel/dwv/issues/1077)
9
+ - Uncaught TypeError: t.getX is not a function when saving state [#1072](https://github.com/ivmartel/dwv/issues/1072)
10
+
11
+ ---
12
+
13
+ ## [v0.30.7](https://github.com/ivmartel/dwv/releases/tag/v0.30.7) - 28/12/2021
14
+
15
+ ### Fixed
16
+
17
+ - Pinch zoom is not working [#1070](https://github.com/ivmartel/dwv/issues/1070)
18
+
19
+ ---
20
+
21
+ ## [v0.30.6](https://github.com/ivmartel/dwv/releases/tag/v0.30.6) - 20/12/2021
22
+
23
+ ### Fixed
24
+
25
+ - Zoom does not stay centred with overlay data [#1066](https://github.com/ivmartel/dwv/issues/1066)
26
+ - Image limit for offset overlap [#1065](https://github.com/ivmartel/dwv/issues/1065)
27
+
28
+ ---
29
+
30
+ ## [v0.30.5](https://github.com/ivmartel/dwv/releases/tag/v0.30.5) - 16/12/2021
31
+
32
+ ### Fixed
33
+
34
+ - Allow to play multi-frame data [#1064](https://github.com/ivmartel/dwv/issues/1064)
35
+ - Allow scroll for multi-frame data [#1063](https://github.com/ivmartel/dwv/issues/1063)
36
+ - Stop worker if no tasks left [#1062](https://github.com/ivmartel/dwv/issues/1062)
37
+
38
+ ---
39
+
3
40
  ## [v0.30.4](https://github.com/ivmartel/dwv/releases/tag/v0.30.4) - 10/12/2021
4
41
 
5
42
  ### Fixed
package/dist/dwv.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! dwv 0.30.4 2021-12-10 19:20:41 */
1
+ /*! dwv 0.30.8 2022-01-04 12:43:27 */
2
2
  // Inspired from umdjs
3
3
  // See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
4
4
  (function (root, factory) {
@@ -531,7 +531,12 @@ dwv.App = function () {
531
531
  this.fitToContainer = function () {
532
532
  var layerGroup = stage.getActiveLayerGroup();
533
533
  if (layerGroup) {
534
- layerGroup.fitToContainer(self.getLastImage().getGeometry());
534
+ var geometry = self.getLastImage().getGeometry();
535
+ var size = geometry.getSize().get2D();
536
+ var spacing = geometry.getSpacing().get2D();
537
+ var width = size.x * spacing.x;
538
+ var height = size.y * spacing.y;
539
+ layerGroup.fitToContainer({x: width, y: height});
535
540
  layerGroup.draw();
536
541
  // update style
537
542
  //style.setBaseScale(layerGroup.getBaseScale());
@@ -713,7 +718,8 @@ dwv.App = function () {
713
718
  drawings, drawingsDetails, fireEvent, this.addToUndoStack);
714
719
 
715
720
  drawController.activateDrawLayer(
716
- viewController.getCurrentOrientedPosition());
721
+ viewController.getCurrentOrientedIndex(),
722
+ viewController.getScrollIndex());
717
723
  };
718
724
  /**
719
725
  * Update a drawing from its details.
@@ -1317,7 +1323,27 @@ dwv.App = function () {
1317
1323
  }
1318
1324
  }
1319
1325
 
1320
- layerGroup.fitToContainer();
1326
+ // fit to the maximum size
1327
+ var maxSize = {x: 0, y: 0};
1328
+ for (var i = 0; i < dataController.length(); ++i) {
1329
+ var dc = dataController.get(i);
1330
+ var geometry = dc.image.getGeometry();
1331
+ var viewOrient = dwv.gui.getViewOrientation(
1332
+ geometry,
1333
+ layerGroup.getTargetOrientation()
1334
+ );
1335
+ var size = geometry.getSize(viewOrient).get2D();
1336
+ var spacing = geometry.getSpacing(viewOrient).get2D();
1337
+ var width = size.x * spacing.x;
1338
+ if (width > maxSize.x) {
1339
+ maxSize.x = width;
1340
+ }
1341
+ var height = size.y * spacing.y;
1342
+ if (height > maxSize.y) {
1343
+ maxSize.y = height;
1344
+ }
1345
+ }
1346
+ layerGroup.fitToContainer(maxSize);
1321
1347
  }
1322
1348
 
1323
1349
  };
@@ -2655,12 +2681,17 @@ dwv.ctrl.ViewController = function (view) {
2655
2681
  *
2656
2682
  * @returns {dwv.math.Point} The position.
2657
2683
  */
2658
- this.getCurrentOrientedPosition = function () {
2659
- var res = view.getCurrentPosition();
2684
+ this.getCurrentOrientedIndex = function () {
2685
+ var res = view.getCurrentIndex();
2660
2686
  // values = orientation * orientedValues
2661
2687
  // -> inv(orientation) * values = orientedValues
2662
2688
  if (typeof view.getOrientation() !== 'undefined') {
2663
- res = view.getOrientation().getInverse().getAbs().multiplyVector3D(res);
2689
+ var index3D = new dwv.math.Index(
2690
+ [res.get(0), res.get(1), res.get(2)]);
2691
+ var orientedIndex3D =
2692
+ view.getOrientation().getInverse().getAbs().multiplyIndex3D(index3D);
2693
+ var values = orientedIndex3D.getValues();
2694
+ res = new dwv.math.Index(values);
2664
2695
  }
2665
2696
  return res;
2666
2697
  };
@@ -2813,7 +2844,8 @@ dwv.ctrl.ViewController = function (view) {
2813
2844
  /**
2814
2845
  * Can the data be scrolled?
2815
2846
  *
2816
- * @returns {boolean} True if the data has a third dimension greater than one.
2847
+ * @returns {boolean} True if the data has either the third dimension
2848
+ * or above greater than one.
2817
2849
  */
2818
2850
  this.canScroll = function () {
2819
2851
  return view.getImage().canScroll(view.getOrientation());
@@ -2959,22 +2991,36 @@ dwv.ctrl.ViewController = function (view) {
2959
2991
  * Scroll play: loop through all slices.
2960
2992
  */
2961
2993
  this.play = function () {
2994
+ // ensure data is scrollable: dim >= 3
2962
2995
  if (!this.canScroll()) {
2963
2996
  return;
2964
2997
  }
2965
2998
  if (playerID === null) {
2999
+ var image = view.getImage();
2966
3000
  var recommendedDisplayFrameRate =
2967
- view.getImage().getMeta().RecommendedDisplayFrameRate;
3001
+ image.getMeta().RecommendedDisplayFrameRate;
2968
3002
  var milliseconds = view.getPlaybackMilliseconds(
2969
3003
  recommendedDisplayFrameRate);
3004
+ var size = image.getGeometry().getSize();
3005
+ var canScroll3D = size.canScroll3D();
2970
3006
 
2971
3007
  playerID = setInterval(function () {
3008
+ var canDoMore = false;
3009
+ if (canScroll3D) {
3010
+ canDoMore = self.incrementScrollIndex();
3011
+ } else {
3012
+ canDoMore = self.incrementIndex(3);
3013
+ }
2972
3014
  // end of scroll, loop back
2973
- if (!self.incrementScrollIndex()) {
3015
+ if (!canDoMore) {
2974
3016
  var pos1 = self.getCurrentIndex();
2975
3017
  var values = pos1.getValues();
2976
3018
  var orientation = view.getOrientation();
2977
- values[orientation.getThirdColMajorDirection()] = 0;
3019
+ if (canScroll3D) {
3020
+ values[orientation.getThirdColMajorDirection()] = 0;
3021
+ } else {
3022
+ values[3] = 0;
3023
+ }
2978
3024
  var index = new dwv.math.Index(values);
2979
3025
  var geometry = view.getImage().getGeometry();
2980
3026
  self.setCurrentPosition(geometry.indexToWorld(index));
@@ -4404,7 +4450,7 @@ dwv.dicom = dwv.dicom || {};
4404
4450
  * @returns {string} The version of the library.
4405
4451
  */
4406
4452
  dwv.getVersion = function () {
4407
- return '0.30.4';
4453
+ return '0.30.8';
4408
4454
  };
4409
4455
 
4410
4456
  /**
@@ -11197,18 +11243,6 @@ dwv.gui.DrawLayer = function (containerDiv) {
11197
11243
  return containerDiv.id;
11198
11244
  };
11199
11245
 
11200
- /**
11201
- * Get the data full size, ie size * spacing.
11202
- *
11203
- * @returns {object} The full size as {x,y}.
11204
- */
11205
- this.getFullSize = function () {
11206
- return {
11207
- x: baseSize.x * baseSpacing.x,
11208
- y: baseSize.y * baseSpacing.y
11209
- };
11210
- };
11211
-
11212
11246
  /**
11213
11247
  * Get the layer base size (without scale).
11214
11248
  *
@@ -11348,19 +11382,17 @@ dwv.gui.DrawLayer = function (containerDiv) {
11348
11382
  * Fit the layer to its parent container.
11349
11383
  *
11350
11384
  * @param {number} fitScale1D The 1D fit scale.
11385
+ * @param {object} fitSize The fit size as {x,y}.
11351
11386
  */
11352
- this.fitToContainer = function (fitScale1D) {
11387
+ this.fitToContainer = function (fitScale1D, fitSize) {
11353
11388
  // update fit scale
11354
11389
  fitScale = {
11355
11390
  x: fitScale1D * baseSpacing.x,
11356
11391
  y: fitScale1D * baseSpacing.y
11357
11392
  };
11358
11393
  // update konva
11359
- var fullSize = this.getFullSize();
11360
- var width = Math.floor(fullSize.x * fitScale1D);
11361
- var height = Math.floor(fullSize.y * fitScale1D);
11362
- konvaStage.setWidth(width);
11363
- konvaStage.setHeight(height);
11394
+ konvaStage.setWidth(fitSize.x);
11395
+ konvaStage.setHeight(fitSize.y);
11364
11396
  // reset scale
11365
11397
  this.setScale({x: 1, y: 1, z: 1});
11366
11398
  };
@@ -12108,24 +12140,27 @@ dwv.gui.LayerGroup = function (containerDiv, groupId) {
12108
12140
  /**
12109
12141
  * Fit the display to the size of the container.
12110
12142
  * To be called once the image is loaded.
12143
+ *
12144
+ * @param {object} realSize 2D real size (in mm) to fit provided as {x,y}.
12111
12145
  */
12112
- this.fitToContainer = function () {
12146
+ this.fitToContainer = function (realSize) {
12113
12147
  // check container size
12114
12148
  if (containerDiv.offsetWidth === 0 &&
12115
12149
  containerDiv.offsetHeight === 0) {
12116
12150
  throw new Error('Cannot fit to zero sized container.');
12117
12151
  }
12118
12152
  // find best fit
12119
- var fitScales = [];
12120
- for (var i = 0; i < layers.length; ++i) {
12121
- var fullSize = layers[i].getFullSize();
12122
- fitScales.push(containerDiv.offsetWidth / fullSize.x);
12123
- fitScales.push(containerDiv.offsetHeight / fullSize.y);
12124
- }
12125
- var fitScale = Math.min.apply(null, fitScales);
12153
+ var fitScale = Math.min(
12154
+ containerDiv.offsetWidth / realSize.x,
12155
+ containerDiv.offsetHeight / realSize.y
12156
+ );
12157
+ var fitSize = {
12158
+ x: Math.floor(realSize.x * fitScale),
12159
+ y: Math.floor(realSize.y * fitScale)
12160
+ };
12126
12161
  // apply to layers
12127
12162
  for (var j = 0; j < layers.length; ++j) {
12128
- layers[j].fitToContainer(fitScale);
12163
+ layers[j].fitToContainer(fitScale, fitSize);
12129
12164
  }
12130
12165
  };
12131
12166
 
@@ -13113,18 +13148,6 @@ dwv.gui.ViewLayer = function (containerDiv) {
13113
13148
  return containerDiv.id;
13114
13149
  };
13115
13150
 
13116
- /**
13117
- * Get the data full size, ie size * spacing.
13118
- *
13119
- * @returns {object} The full size as {x,y}.
13120
- */
13121
- this.getFullSize = function () {
13122
- return {
13123
- x: baseSize.x * baseSpacing.x,
13124
- y: baseSize.y * baseSpacing.y
13125
- };
13126
- };
13127
-
13128
13151
  /**
13129
13152
  * Get the layer base size (without scale).
13130
13153
  *
@@ -13224,6 +13247,13 @@ dwv.gui.ViewLayer = function (containerDiv) {
13224
13247
  ]);
13225
13248
  };
13226
13249
 
13250
+ /**
13251
+ * Remove scale from a display position.
13252
+ *
13253
+ * @param {number} x The X position.
13254
+ * @param {number} y The Y position.
13255
+ * @returns {object} The de-scaled position as {x,y}.
13256
+ */
13227
13257
  this.displayToPlaneScale = function (x, y) {
13228
13258
  return {
13229
13259
  x: x / scale.x,
@@ -13231,6 +13261,13 @@ dwv.gui.ViewLayer = function (containerDiv) {
13231
13261
  };
13232
13262
  };
13233
13263
 
13264
+ /**
13265
+ * Get a plane position from a display position.
13266
+ *
13267
+ * @param {number} x The X position.
13268
+ * @param {number} y The Y position.
13269
+ * @returns {object} The plane position as {x,y}.
13270
+ */
13234
13271
  this.displayToPlanePos = function (x, y) {
13235
13272
  var deScaled = this.displayToPlaneScale(x, y);
13236
13273
  return {
@@ -13239,6 +13276,21 @@ dwv.gui.ViewLayer = function (containerDiv) {
13239
13276
  };
13240
13277
  };
13241
13278
 
13279
+ /**
13280
+ * Get a main plane position from a display position.
13281
+ *
13282
+ * @param {number} x The X position.
13283
+ * @param {number} y The Y position.
13284
+ * @returns {object} The main plane position as {x,y}.
13285
+ */
13286
+ this.displayToMainPlanePos = function (x, y) {
13287
+ var planePos = this.displayToPlanePos(x, y);
13288
+ return {
13289
+ x: planePos.x - baseOffset.x,
13290
+ y: planePos.y - baseOffset.y
13291
+ };
13292
+ };
13293
+
13242
13294
  /**
13243
13295
  * Display the layer.
13244
13296
  *
@@ -13343,6 +13395,7 @@ dwv.gui.ViewLayer = function (containerDiv) {
13343
13395
  dataIndex = index;
13344
13396
 
13345
13397
  // create canvas
13398
+ // (canvas size is set in fitToContainer)
13346
13399
  canvas = document.createElement('canvas');
13347
13400
  containerDiv.appendChild(canvas);
13348
13401
 
@@ -13363,9 +13416,6 @@ dwv.gui.ViewLayer = function (containerDiv) {
13363
13416
  throw new Error('Cannot create canvas ' + baseSize.x + ', ' + baseSize.y);
13364
13417
  }
13365
13418
 
13366
- // canvas sizes
13367
- canvas.width = baseSize.x;
13368
- canvas.height = baseSize.y;
13369
13419
  // off screen canvas
13370
13420
  offscreenCanvas = document.createElement('canvas');
13371
13421
  offscreenCanvas.width = baseSize.x;
@@ -13382,17 +13432,17 @@ dwv.gui.ViewLayer = function (containerDiv) {
13382
13432
  * Fit the layer to its parent container.
13383
13433
  *
13384
13434
  * @param {number} fitScale1D The 1D fit scale.
13435
+ * @param {object} fitSize The fit size as {x,y}.
13385
13436
  */
13386
- this.fitToContainer = function (fitScale1D) {
13437
+ this.fitToContainer = function (fitScale1D, fitSize) {
13387
13438
  // update fit scale
13388
13439
  fitScale = {
13389
13440
  x: fitScale1D * baseSpacing.x,
13390
13441
  y: fitScale1D * baseSpacing.y
13391
13442
  };
13392
- // update canvas
13393
- var fullSize = this.getFullSize();
13394
- var width = Math.floor(fullSize.x * fitScale1D);
13395
- var height = Math.floor(fullSize.y * fitScale1D);
13443
+ // new canvas size
13444
+ var width = fitSize.x;
13445
+ var height = fitSize.y;
13396
13446
  if (!dwv.gui.canCreateCanvas(width, height)) {
13397
13447
  throw new Error('Cannot resize canvas ' + width + ', ' + height);
13398
13448
  }
@@ -17743,13 +17793,12 @@ dwv.image.Size.prototype.moreThanOne = function (dimension) {
17743
17793
  };
17744
17794
 
17745
17795
  /**
17746
- * Check if the third direction of an orientation matrix has a size
17747
- * of more than one.
17796
+ * Check if the associated data is scrollable in 3D.
17748
17797
  *
17749
17798
  * @param {dwv.math.Matrix33} viewOrientation The orientation matrix.
17750
17799
  * @returns {boolean} True if scrollable.
17751
17800
  */
17752
- dwv.image.Size.prototype.canScroll = function (viewOrientation) {
17801
+ dwv.image.Size.prototype.canScroll3D = function (viewOrientation) {
17753
17802
  var dimension = 2;
17754
17803
  if (typeof viewOrientation !== 'undefined') {
17755
17804
  dimension = viewOrientation.getThirdColMajorDirection();
@@ -17757,6 +17806,22 @@ dwv.image.Size.prototype.canScroll = function (viewOrientation) {
17757
17806
  return this.moreThanOne(dimension);
17758
17807
  };
17759
17808
 
17809
+ /**
17810
+ * Check if the associated data is scrollable: either in 3D or
17811
+ * in other directions.
17812
+ *
17813
+ * @param {dwv.math.Matrix33} viewOrientation The orientation matrix.
17814
+ * @returns {boolean} True if scrollable.
17815
+ */
17816
+ dwv.image.Size.prototype.canScroll = function (viewOrientation) {
17817
+ var canScroll = this.canScroll3D(viewOrientation);
17818
+ // check possible other dimensions
17819
+ for (var i = 3; i < this.length(); ++i) {
17820
+ canScroll = canScroll || this.moreThanOne(i);
17821
+ }
17822
+ return canScroll;
17823
+ };
17824
+
17760
17825
  /**
17761
17826
  * Get the size of a given dimension.
17762
17827
  *
@@ -20974,7 +21039,7 @@ dwv.io.State = function () {
20974
21039
  version: '0.5',
20975
21040
  'window-center': viewController.getWindowLevel().center,
20976
21041
  'window-width': viewController.getWindowLevel().width,
20977
- position: [position.getX(), position.getY(), position.getZ()],
21042
+ position: position.getValues(),
20978
21043
  scale: app.getAddedScale(),
20979
21044
  offset: app.getOffset(),
20980
21045
  drawings: drawLayer.getKonvaLayer().toObject(),
@@ -21019,9 +21084,7 @@ dwv.io.State = function () {
21019
21084
  // display
21020
21085
  viewController.setWindowLevel(
21021
21086
  data['window-center'], data['window-width']);
21022
- viewController.setCurrentPosition(
21023
- new dwv.math.Point3D(
21024
- data.position[0], data.position[1], data.position[2]), true);
21087
+ viewController.setCurrentPosition(new dwv.math.Point(data.position));
21025
21088
  // apply saved scale on top of current base one
21026
21089
  var baseScale = app.getActiveLayerGroup().getBaseScale();
21027
21090
  var scale = null;
@@ -31012,9 +31075,9 @@ dwv.tool.Scroll = function (app) {
31012
31075
  if (xMove && imageSize.moreThanOne(3)) {
31013
31076
  // update view controller
31014
31077
  if (diffX > 0) {
31015
- viewController.decrementIndex(3);
31016
- } else {
31017
31078
  viewController.incrementIndex(3);
31079
+ } else {
31080
+ viewController.decrementIndex(3);
31018
31081
  }
31019
31082
  }
31020
31083
 
@@ -31648,8 +31711,9 @@ dwv.tool.ZoomAndPan = function (app) {
31648
31711
  // zoom mode
31649
31712
  var zoom = (lineRatio - 1) / 2;
31650
31713
  if (Math.abs(zoom) % 0.1 <= 0.05) {
31651
- var planePos = viewLayer.displayToPlanePos(event._x, event._y);
31652
- var center = viewController.getPositionFromPlanePoint(planePos);
31714
+ var planePos = viewLayer.displayToMainPlanePos(
31715
+ self.midPoint.getX(), self.midPoint.getY());
31716
+ var center = viewController.getPlanePositionFromPlanePoint(planePos);
31653
31717
  layerGroup.addScale(zoom, center);
31654
31718
  layerGroup.draw();
31655
31719
  }
@@ -31726,7 +31790,7 @@ dwv.tool.ZoomAndPan = function (app) {
31726
31790
  var layerGroup = app.getLayerGroupById(layerDetails.groupId);
31727
31791
  var viewLayer = layerGroup.getActiveViewLayer();
31728
31792
  var viewController = viewLayer.getViewController();
31729
- var planePos = viewLayer.displayToPlanePos(event._x, event._y);
31793
+ var planePos = viewLayer.displayToMainPlanePos(event._x, event._y);
31730
31794
  var center = viewController.getPlanePositionFromPlanePoint(planePos);
31731
31795
  layerGroup.addScale(step, center);
31732
31796
  layerGroup.draw();
@@ -34037,6 +34101,8 @@ dwv.utils.ThreadPool = function (poolSize) {
34037
34101
  // use input thread to run the waiting task
34038
34102
  workerThread.run(workerTask);
34039
34103
  } else {
34104
+ // stop the worker
34105
+ workerThread.stop();
34040
34106
  // no task to run, add to free list
34041
34107
  freeThreads.push(workerThread);
34042
34108
  // remove from running list