dwv 0.30.5 → 0.30.6

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,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.30.6](https://github.com/ivmartel/dwv/releases/tag/v0.30.6) - 20/12/2021
4
+
5
+ ### Fixed
6
+
7
+ - Zoom does not stay centred with overlay data [#1066](https://github.com/ivmartel/dwv/issues/1066)
8
+ - Image limit for offset overlap [#1065](https://github.com/ivmartel/dwv/issues/1065)
9
+
10
+ ---
11
+
3
12
  ## [v0.30.5](https://github.com/ivmartel/dwv/releases/tag/v0.30.5) - 16/12/2021
4
13
 
5
14
  ### Fixed
package/dist/dwv.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! dwv 0.30.5 2021-12-16 11:23:07 */
1
+ /*! dwv 0.30.6 2021-12-21 11:22:44 */
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());
@@ -1317,7 +1322,27 @@ dwv.App = function () {
1317
1322
  }
1318
1323
  }
1319
1324
 
1320
- layerGroup.fitToContainer();
1325
+ // fit to the maximum size
1326
+ var maxSize = {x: 0, y: 0};
1327
+ for (var i = 0; i < dataController.length(); ++i) {
1328
+ var dc = dataController.get(i);
1329
+ var geometry = dc.image.getGeometry();
1330
+ var viewOrient = dwv.gui.getViewOrientation(
1331
+ geometry,
1332
+ layerGroup.getTargetOrientation()
1333
+ );
1334
+ var size = geometry.getSize(viewOrient).get2D();
1335
+ var spacing = geometry.getSpacing(viewOrient).get2D();
1336
+ var width = size.x * spacing.x;
1337
+ if (width > maxSize.x) {
1338
+ maxSize.x = width;
1339
+ }
1340
+ var height = size.y * spacing.y;
1341
+ if (height > maxSize.y) {
1342
+ maxSize.y = height;
1343
+ }
1344
+ }
1345
+ layerGroup.fitToContainer(maxSize);
1321
1346
  }
1322
1347
 
1323
1348
  };
@@ -4419,7 +4444,7 @@ dwv.dicom = dwv.dicom || {};
4419
4444
  * @returns {string} The version of the library.
4420
4445
  */
4421
4446
  dwv.getVersion = function () {
4422
- return '0.30.5';
4447
+ return '0.30.6';
4423
4448
  };
4424
4449
 
4425
4450
  /**
@@ -11212,18 +11237,6 @@ dwv.gui.DrawLayer = function (containerDiv) {
11212
11237
  return containerDiv.id;
11213
11238
  };
11214
11239
 
11215
- /**
11216
- * Get the data full size, ie size * spacing.
11217
- *
11218
- * @returns {object} The full size as {x,y}.
11219
- */
11220
- this.getFullSize = function () {
11221
- return {
11222
- x: baseSize.x * baseSpacing.x,
11223
- y: baseSize.y * baseSpacing.y
11224
- };
11225
- };
11226
-
11227
11240
  /**
11228
11241
  * Get the layer base size (without scale).
11229
11242
  *
@@ -11363,19 +11376,17 @@ dwv.gui.DrawLayer = function (containerDiv) {
11363
11376
  * Fit the layer to its parent container.
11364
11377
  *
11365
11378
  * @param {number} fitScale1D The 1D fit scale.
11379
+ * @param {object} fitSize The fit size as {x,y}.
11366
11380
  */
11367
- this.fitToContainer = function (fitScale1D) {
11381
+ this.fitToContainer = function (fitScale1D, fitSize) {
11368
11382
  // update fit scale
11369
11383
  fitScale = {
11370
11384
  x: fitScale1D * baseSpacing.x,
11371
11385
  y: fitScale1D * baseSpacing.y
11372
11386
  };
11373
11387
  // update konva
11374
- var fullSize = this.getFullSize();
11375
- var width = Math.floor(fullSize.x * fitScale1D);
11376
- var height = Math.floor(fullSize.y * fitScale1D);
11377
- konvaStage.setWidth(width);
11378
- konvaStage.setHeight(height);
11388
+ konvaStage.setWidth(fitSize.x);
11389
+ konvaStage.setHeight(fitSize.y);
11379
11390
  // reset scale
11380
11391
  this.setScale({x: 1, y: 1, z: 1});
11381
11392
  };
@@ -12123,24 +12134,27 @@ dwv.gui.LayerGroup = function (containerDiv, groupId) {
12123
12134
  /**
12124
12135
  * Fit the display to the size of the container.
12125
12136
  * To be called once the image is loaded.
12137
+ *
12138
+ * @param {object} realSize 2D real size (in mm) to fit provided as {x,y}.
12126
12139
  */
12127
- this.fitToContainer = function () {
12140
+ this.fitToContainer = function (realSize) {
12128
12141
  // check container size
12129
12142
  if (containerDiv.offsetWidth === 0 &&
12130
12143
  containerDiv.offsetHeight === 0) {
12131
12144
  throw new Error('Cannot fit to zero sized container.');
12132
12145
  }
12133
12146
  // find best fit
12134
- var fitScales = [];
12135
- for (var i = 0; i < layers.length; ++i) {
12136
- var fullSize = layers[i].getFullSize();
12137
- fitScales.push(containerDiv.offsetWidth / fullSize.x);
12138
- fitScales.push(containerDiv.offsetHeight / fullSize.y);
12139
- }
12140
- var fitScale = Math.min.apply(null, fitScales);
12147
+ var fitScale = Math.min(
12148
+ containerDiv.offsetWidth / realSize.x,
12149
+ containerDiv.offsetHeight / realSize.y
12150
+ );
12151
+ var fitSize = {
12152
+ x: Math.floor(realSize.x * fitScale),
12153
+ y: Math.floor(realSize.y * fitScale)
12154
+ };
12141
12155
  // apply to layers
12142
12156
  for (var j = 0; j < layers.length; ++j) {
12143
- layers[j].fitToContainer(fitScale);
12157
+ layers[j].fitToContainer(fitScale, fitSize);
12144
12158
  }
12145
12159
  };
12146
12160
 
@@ -13128,18 +13142,6 @@ dwv.gui.ViewLayer = function (containerDiv) {
13128
13142
  return containerDiv.id;
13129
13143
  };
13130
13144
 
13131
- /**
13132
- * Get the data full size, ie size * spacing.
13133
- *
13134
- * @returns {object} The full size as {x,y}.
13135
- */
13136
- this.getFullSize = function () {
13137
- return {
13138
- x: baseSize.x * baseSpacing.x,
13139
- y: baseSize.y * baseSpacing.y
13140
- };
13141
- };
13142
-
13143
13145
  /**
13144
13146
  * Get the layer base size (without scale).
13145
13147
  *
@@ -13239,6 +13241,13 @@ dwv.gui.ViewLayer = function (containerDiv) {
13239
13241
  ]);
13240
13242
  };
13241
13243
 
13244
+ /**
13245
+ * Remove scale from a display position.
13246
+ *
13247
+ * @param {number} x The X position.
13248
+ * @param {number} y The Y position.
13249
+ * @returns {object} The de-scaled position as {x,y}.
13250
+ */
13242
13251
  this.displayToPlaneScale = function (x, y) {
13243
13252
  return {
13244
13253
  x: x / scale.x,
@@ -13246,6 +13255,13 @@ dwv.gui.ViewLayer = function (containerDiv) {
13246
13255
  };
13247
13256
  };
13248
13257
 
13258
+ /**
13259
+ * Get a plane position from a display position.
13260
+ *
13261
+ * @param {number} x The X position.
13262
+ * @param {number} y The Y position.
13263
+ * @returns {object} The plane position as {x,y}.
13264
+ */
13249
13265
  this.displayToPlanePos = function (x, y) {
13250
13266
  var deScaled = this.displayToPlaneScale(x, y);
13251
13267
  return {
@@ -13254,6 +13270,21 @@ dwv.gui.ViewLayer = function (containerDiv) {
13254
13270
  };
13255
13271
  };
13256
13272
 
13273
+ /**
13274
+ * Get a main plane position from a display position.
13275
+ *
13276
+ * @param {number} x The X position.
13277
+ * @param {number} y The Y position.
13278
+ * @returns {object} The main plane position as {x,y}.
13279
+ */
13280
+ this.displayToMainPlanePos = function (x, y) {
13281
+ var planePos = this.displayToPlanePos(x, y);
13282
+ return {
13283
+ x: planePos.x - baseOffset.x,
13284
+ y: planePos.y - baseOffset.y
13285
+ };
13286
+ };
13287
+
13257
13288
  /**
13258
13289
  * Display the layer.
13259
13290
  *
@@ -13358,6 +13389,7 @@ dwv.gui.ViewLayer = function (containerDiv) {
13358
13389
  dataIndex = index;
13359
13390
 
13360
13391
  // create canvas
13392
+ // (canvas size is set in fitToContainer)
13361
13393
  canvas = document.createElement('canvas');
13362
13394
  containerDiv.appendChild(canvas);
13363
13395
 
@@ -13378,9 +13410,6 @@ dwv.gui.ViewLayer = function (containerDiv) {
13378
13410
  throw new Error('Cannot create canvas ' + baseSize.x + ', ' + baseSize.y);
13379
13411
  }
13380
13412
 
13381
- // canvas sizes
13382
- canvas.width = baseSize.x;
13383
- canvas.height = baseSize.y;
13384
13413
  // off screen canvas
13385
13414
  offscreenCanvas = document.createElement('canvas');
13386
13415
  offscreenCanvas.width = baseSize.x;
@@ -13397,17 +13426,17 @@ dwv.gui.ViewLayer = function (containerDiv) {
13397
13426
  * Fit the layer to its parent container.
13398
13427
  *
13399
13428
  * @param {number} fitScale1D The 1D fit scale.
13429
+ * @param {object} fitSize The fit size as {x,y}.
13400
13430
  */
13401
- this.fitToContainer = function (fitScale1D) {
13431
+ this.fitToContainer = function (fitScale1D, fitSize) {
13402
13432
  // update fit scale
13403
13433
  fitScale = {
13404
13434
  x: fitScale1D * baseSpacing.x,
13405
13435
  y: fitScale1D * baseSpacing.y
13406
13436
  };
13407
- // update canvas
13408
- var fullSize = this.getFullSize();
13409
- var width = Math.floor(fullSize.x * fitScale1D);
13410
- var height = Math.floor(fullSize.y * fitScale1D);
13437
+ // new canvas size
13438
+ var width = fitSize.x;
13439
+ var height = fitSize.y;
13411
13440
  if (!dwv.gui.canCreateCanvas(width, height)) {
13412
13441
  throw new Error('Cannot resize canvas ' + width + ', ' + height);
13413
13442
  }
@@ -31756,7 +31785,7 @@ dwv.tool.ZoomAndPan = function (app) {
31756
31785
  var layerGroup = app.getLayerGroupById(layerDetails.groupId);
31757
31786
  var viewLayer = layerGroup.getActiveViewLayer();
31758
31787
  var viewController = viewLayer.getViewController();
31759
- var planePos = viewLayer.displayToPlanePos(event._x, event._y);
31788
+ var planePos = viewLayer.displayToMainPlanePos(event._x, event._y);
31760
31789
  var center = viewController.getPlanePositionFromPlanePoint(planePos);
31761
31790
  layerGroup.addScale(step, center);
31762
31791
  layerGroup.draw();