dwv 0.31.0-beta.19 → 0.31.0-beta.20

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/dist/dwv.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! dwv 0.31.0-beta.19 2022-12-09 10:21:09 */
1
+ /*! dwv 0.31.0-beta.20 2022-12-19 10:41:20 */
2
2
  // Inspired from umdjs
3
3
  // See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
4
4
  (function (root, factory) {
@@ -965,6 +965,13 @@ dwv.App = function () {
965
965
  undoStack.redo();
966
966
  } else if (event.keyCode === 90) { // crtl-z
967
967
  undoStack.undo();
968
+ } else if (event.code === 'Space') { // crtl-space
969
+ event.preventDefault();
970
+ for (var i = 0; i < stage.getNumberOfLayerGroups(); ++i) {
971
+ stage.getLayerGroup(i).setShowCrosshair(
972
+ !stage.getLayerGroup(i).getShowCrosshair()
973
+ );
974
+ }
968
975
  }
969
976
  }
970
977
  };
@@ -1353,11 +1360,13 @@ dwv.App = function () {
1353
1360
  view.setColourMap(dataViewConfig.colourMap);
1354
1361
  }
1355
1362
 
1363
+ var isBaseLayer = layerGroup.getNumberOfLayers() === 0;
1364
+
1356
1365
  // opacity
1357
1366
  var opacity = 1;
1358
1367
  // do we have more than one layer
1359
1368
  // (the layer has not been added to the layer group yet)
1360
- if (layerGroup.getNumberOfLayers() !== 0) {
1369
+ if (!isBaseLayer) {
1361
1370
  opacity = 0.5;
1362
1371
  // set color map if non was provided
1363
1372
  if (typeof dataViewConfig.colourMap === 'undefined') {
@@ -1371,8 +1380,6 @@ dwv.App = function () {
1371
1380
  var size2D = imageGeometry.getSize(viewOrientation).get2D();
1372
1381
  var spacing2D = imageGeometry.getSpacing(viewOrientation).get2D();
1373
1382
  viewLayer.initialise(size2D, spacing2D, dataIndex, opacity);
1374
- viewLayer.setScale(layerGroup.getScale());
1375
- viewLayer.setOffset(layerGroup.getOffset());
1376
1383
 
1377
1384
  // listen to image changes
1378
1385
  dataController.addEventListener('imagechange', viewLayer.onimagechange);
@@ -1404,17 +1411,48 @@ dwv.App = function () {
1404
1411
  // sync layer groups
1405
1412
  stage.syncLayerGroupScale();
1406
1413
 
1407
- // extra flip for oriented views...
1414
+ // major orientation axis
1415
+ var major = imageGeometry.getOrientation().getThirdColMajorDirection();
1416
+
1417
+ // view layer offset (done before scale)
1418
+ viewLayer.setOffset(layerGroup.getOffset());
1419
+ // extra flip offset for oriented views...
1408
1420
  if (typeof dataViewConfig.orientation !== 'undefined') {
1409
- var major = imageGeometry.getOrientation().getThirdColMajorDirection();
1410
- if (major === 2 && dataViewConfig.orientation !== 'axial') {
1411
- // flip Y for axial aquired data
1412
- viewLayer.flipY();
1413
- } else if (major === 0 && dataViewConfig.orientation !== 'sagittal') {
1414
- // flip Y for sagittal aquired data
1415
- viewLayer.flipX();
1421
+ if (major === 2) {
1422
+ // flip offset Y for axial aquired data
1423
+ if (dataViewConfig.orientation !== 'axial') {
1424
+ viewLayer.addFlipOffsetY();
1425
+ }
1426
+ } else if (major === 0) {
1427
+ // flip offset X for sagittal aquired data
1428
+ if (dataViewConfig.orientation !== 'sagittal') {
1429
+ viewLayer.addFlipOffsetX();
1430
+ }
1416
1431
  }
1417
1432
  }
1433
+
1434
+ // view layer scale
1435
+ // only flip scale for base layers
1436
+ if (isBaseLayer) {
1437
+ if (typeof dataViewConfig.orientation !== 'undefined') {
1438
+ if (major === 0 || major === 2) {
1439
+ // scale flip Z for oriented views...
1440
+ layerGroup.flipScaleZ();
1441
+ } else {
1442
+ viewLayer.setScale(layerGroup.getScale());
1443
+ }
1444
+ } else {
1445
+ if (major === 0) {
1446
+ // scale flip Z for sagittal and undefined target orientation
1447
+ layerGroup.flipScaleZ();
1448
+ } else {
1449
+ viewLayer.setScale(layerGroup.getScale());
1450
+ }
1451
+ }
1452
+ } else {
1453
+ viewLayer.setScale(layerGroup.getScale());
1454
+ }
1455
+
1418
1456
  }
1419
1457
 
1420
1458
  }; // class dwv.App
@@ -2716,10 +2754,12 @@ dwv.ctrl.ViewController = function (view) {
2716
2754
  var res = view.getCurrentIndex();
2717
2755
  if (typeof view.getOrientation() !== 'undefined') {
2718
2756
  // view oriented => image de-oriented
2719
- var values = planeHelper.getImageDeOrientedVector3D([
2720
- res.get(0), res.get(1), res.get(2)
2757
+ var vector = planeHelper.getImageDeOrientedVector3D(
2758
+ new dwv.math.Vector3D(res.get(0), res.get(1), res.get(2))
2759
+ );
2760
+ res = new dwv.math.Index([
2761
+ vector.getX(), vector.getY(), vector.getZ()
2721
2762
  ]);
2722
- res = new dwv.math.Index(values);
2723
2763
  }
2724
2764
  return res;
2725
2765
  };
@@ -3011,6 +3051,25 @@ dwv.ctrl.ViewController = function (view) {
3011
3051
  return this.getCurrentPosition().mergeWith3D(point3D);
3012
3052
  };
3013
3053
 
3054
+ /**
3055
+ * Get a 2D (x,y) position from a position.
3056
+ *
3057
+ * @param {dwv.math.Point3D} point3D The 3D position.
3058
+ * @returns {object} The 2D position.
3059
+ */
3060
+ this.getPlanePositionFromPosition = function (point3D) {
3061
+ // orient
3062
+ var geometry = view.getImage().getGeometry();
3063
+ // ~worldToIndex to not loose precision
3064
+ var point = geometry.worldToPoint(point3D);
3065
+ var planePoint = planeHelper.getImageDeOrientedVector3D(point);
3066
+ // return
3067
+ return {
3068
+ x: planePoint.getX(),
3069
+ y: planePoint.getY(),
3070
+ };
3071
+ };
3072
+
3014
3073
  /**
3015
3074
  * Set the current index.
3016
3075
  *
@@ -4636,7 +4695,7 @@ dwv.dicom = dwv.dicom || {};
4636
4695
  * @returns {string} The version of the library.
4637
4696
  */
4638
4697
  dwv.getVersion = function () {
4639
- return '0.31.0-beta.19';
4698
+ return '0.31.0-beta.20';
4640
4699
  };
4641
4700
 
4642
4701
  /**
@@ -12918,7 +12977,7 @@ dwv.gui.DrawLayer = function (containerDiv) {
12918
12977
  y: center.getY(),
12919
12978
  z: center.getZ()
12920
12979
  });
12921
- // center was obtained with viewLayer.displayToPlanePosNoBase
12980
+ // center was obtained with viewLayer.displayToMainPlanePos
12922
12981
  // compensated for baseOffset
12923
12982
  // TODO: justify...
12924
12983
  worldCenter = {
@@ -13428,7 +13487,8 @@ dwv.gui.getViewOrientation = function (imageOrientation, targetOrientation) {
13428
13487
  viewOrientation =
13429
13488
  imageOrientation.asOneAndZeros().getInverse().multiply(targetOrientation);
13430
13489
  }
13431
- return viewOrientation;
13490
+ // TODO: why abs???
13491
+ return viewOrientation.getAbs();
13432
13492
  };
13433
13493
 
13434
13494
  /**
@@ -13445,7 +13505,16 @@ dwv.gui.getTargetOrientation = function (imageOrientation, viewOrientation) {
13445
13505
  // Pi = (Oi)-1 * Ot * Pt = Ov * Pt
13446
13506
  // -> Ot = Oi * Ov
13447
13507
  // note: asOneAndZeros as in dwv.gui.getViewOrientation...
13448
- return imageOrientation.asOneAndZeros().multiply(viewOrientation);
13508
+ var targetOrientation =
13509
+ imageOrientation.asOneAndZeros().multiply(viewOrientation);
13510
+
13511
+ // TODO: why abs???
13512
+ var simpleImageOrientation = imageOrientation.asOneAndZeros().getAbs();
13513
+ if (simpleImageOrientation.equals(dwv.math.getCoronalMat33().getAbs())) {
13514
+ targetOrientation = targetOrientation.getAbs();
13515
+ }
13516
+
13517
+ return targetOrientation;
13449
13518
  };
13450
13519
 
13451
13520
  /**
@@ -13560,6 +13629,22 @@ dwv.gui.LayerGroup = function (containerDiv) {
13560
13629
  */
13561
13630
  var targetOrientation;
13562
13631
 
13632
+ /**
13633
+ * Flag to activate crosshair or not.
13634
+ *
13635
+ * @type {boolean}
13636
+ * @private
13637
+ */
13638
+ var showCrosshair = false;
13639
+
13640
+ /**
13641
+ * The current position used for the crosshair.
13642
+ *
13643
+ * @type {dwv.math.Point}
13644
+ * @private
13645
+ */
13646
+ var currentPosition;
13647
+
13563
13648
  /**
13564
13649
  * Get the target orientation.
13565
13650
  *
@@ -13578,6 +13663,44 @@ dwv.gui.LayerGroup = function (containerDiv) {
13578
13663
  targetOrientation = orientation;
13579
13664
  };
13580
13665
 
13666
+ /**
13667
+ * Get the showCrosshair flag.
13668
+ *
13669
+ * @returns {boolean} True to display the crosshair.
13670
+ */
13671
+ this.getShowCrosshair = function () {
13672
+ return showCrosshair;
13673
+ };
13674
+
13675
+ /**
13676
+ * Set the showCrosshair flag.
13677
+ *
13678
+ * @param {boolean} flag True to display the crosshair.
13679
+ */
13680
+ this.setShowCrosshair = function (flag) {
13681
+ showCrosshair = flag;
13682
+ if (flag) {
13683
+ // listen to offset and zoom change
13684
+ self.addEventListener('offsetchange', updateCrosshairOnChange);
13685
+ self.addEventListener('zoomchange', updateCrosshairOnChange);
13686
+ // show crosshair div
13687
+ showCrosshairDiv();
13688
+ } else {
13689
+ // listen to offset and zoom change
13690
+ self.removeEventListener('offsetchange', updateCrosshairOnChange);
13691
+ self.removeEventListener('zoomchange', updateCrosshairOnChange);
13692
+ // remove crosshair div
13693
+ removeCrosshairDiv();
13694
+ }
13695
+ };
13696
+
13697
+ /**
13698
+ * Update crosshair on offset or zoom change.
13699
+ */
13700
+ function updateCrosshairOnChange() {
13701
+ showCrosshairDiv();
13702
+ }
13703
+
13581
13704
  /**
13582
13705
  * Get the Id of the container div.
13583
13706
  *
@@ -13861,6 +13984,64 @@ dwv.gui.LayerGroup = function (containerDiv) {
13861
13984
  }
13862
13985
  };
13863
13986
 
13987
+ /**
13988
+ * Show a crosshair at a given position.
13989
+ *
13990
+ * @param {dwv.math.Point} position The position where to show the crosshair.
13991
+ */
13992
+ function showCrosshairDiv(position) {
13993
+ if (typeof position === 'undefined') {
13994
+ position = currentPosition;
13995
+ }
13996
+
13997
+ // remove previous
13998
+ removeCrosshairDiv();
13999
+
14000
+ // use first layer as base for calculating position and
14001
+ // line sizes
14002
+ var layer0 = layers[0];
14003
+ var vc = layer0.getViewController();
14004
+ var p2D = vc.getPlanePositionFromPosition(position);
14005
+ var displayPos = layer0.planePosToDisplay(p2D.x, p2D.y);
14006
+
14007
+ // 10px offset
14008
+ // TODO: find why...
14009
+ var offY = 10;
14010
+
14011
+ var lineH = document.createElement('hr');
14012
+ lineH.id = self.getDivId() + '-scroll-crosshair-horizontal';
14013
+ lineH.className = 'horizontal';
14014
+ lineH.style.width = containerDiv.offsetWidth + 'px';
14015
+ lineH.style.left = '0px';
14016
+ lineH.style.top = (displayPos.y - offY) + 'px';
14017
+
14018
+ var lineV = document.createElement('hr');
14019
+ lineV.id = self.getDivId() + '-scroll-crosshair-vertical';
14020
+ lineV.className = 'vertical';
14021
+ lineV.style.width = containerDiv.offsetHeight + 'px';
14022
+ lineV.style.left = (displayPos.x) + 'px';
14023
+ lineV.style.top = (-offY) + 'px';
14024
+
14025
+ containerDiv.appendChild(lineH);
14026
+ containerDiv.appendChild(lineV);
14027
+ }
14028
+
14029
+ /**
14030
+ * Remove crosshair divs.
14031
+ */
14032
+ function removeCrosshairDiv() {
14033
+ var div = document.getElementById(
14034
+ self.getDivId() + '-scroll-crosshair-horizontal');
14035
+ if (div) {
14036
+ div.remove();
14037
+ }
14038
+ div = document.getElementById(
14039
+ self.getDivId() + '-scroll-crosshair-vertical');
14040
+ if (div) {
14041
+ div.remove();
14042
+ }
14043
+ }
14044
+
13864
14045
  /**
13865
14046
  * Update layers (but not the active view layer) to a position change.
13866
14047
  *
@@ -13878,6 +14059,14 @@ dwv.gui.LayerGroup = function (containerDiv) {
13878
14059
 
13879
14060
  var index = new dwv.math.Index(event.value[0]);
13880
14061
  var position = new dwv.math.Point(event.value[1]);
14062
+
14063
+ // store current position
14064
+ currentPosition = position;
14065
+
14066
+ if (showCrosshair) {
14067
+ showCrosshairDiv(position);
14068
+ }
14069
+
13881
14070
  // origin of the first view layer
13882
14071
  var baseViewLayerOrigin0 = null;
13883
14072
  var baseViewLayerOrigin = null;
@@ -13901,15 +14090,14 @@ dwv.gui.LayerGroup = function (containerDiv) {
13901
14090
  if (vc.canSetPosition(position) &&
13902
14091
  typeof origin !== 'undefined') {
13903
14092
  // TODO: compensate for possible different orientation between views
13904
- // TODO: check why -z...
13905
14093
 
13906
14094
  var scrollDiff = baseViewLayerOrigin0.minus(origin0);
13907
14095
  var scrollOffset = new dwv.math.Vector3D(
13908
- scrollDiff.getX(), scrollDiff.getY(), -1 * scrollDiff.getZ());
14096
+ scrollDiff.getX(), scrollDiff.getY(), scrollDiff.getZ());
13909
14097
 
13910
14098
  var planeDiff = baseViewLayerOrigin.minus(origin);
13911
14099
  var planeOffset = new dwv.math.Vector3D(
13912
- planeDiff.getX(), planeDiff.getY(), -1 * planeDiff.getZ());
14100
+ planeDiff.getX(), planeDiff.getY(), planeDiff.getZ());
13913
14101
 
13914
14102
  hasSetOffset = layers[i].setBaseOffset(scrollOffset, planeOffset);
13915
14103
  }
@@ -14014,6 +14202,14 @@ dwv.gui.LayerGroup = function (containerDiv) {
14014
14202
  return maxSize;
14015
14203
  };
14016
14204
 
14205
+ /**
14206
+ * Flip all layers along the Z axis without offset compensation.
14207
+ */
14208
+ this.flipScaleZ = function () {
14209
+ baseScale.z *= -1;
14210
+ this.setScale(baseScale);
14211
+ };
14212
+
14017
14213
  /**
14018
14214
  * Add scale to the layers. Scale cannot go lower than 0.1.
14019
14215
  *
@@ -14975,6 +15171,14 @@ dwv.gui.ViewLayer = function (containerDiv) {
14975
15171
  */
14976
15172
  var zoomOffset = {x: 0, y: 0};
14977
15173
 
15174
+ /**
15175
+ * The flip offset.
15176
+ *
15177
+ * @private
15178
+ * @type {object}
15179
+ */
15180
+ var flipOffset = {x: 0, y: 0};
15181
+
14978
15182
  /**
14979
15183
  * Data update flag.
14980
15184
  *
@@ -15141,14 +15345,24 @@ dwv.gui.ViewLayer = function (containerDiv) {
15141
15345
  fireEvent(event);
15142
15346
  };
15143
15347
 
15144
- this.flipY = function () {
15145
- offset.y += canvas.height / scale.y;
15146
- scale.y *= -1;
15348
+ /**
15349
+ * Add a flip offset along the layer X axis.
15350
+ */
15351
+ this.addFlipOffsetX = function () {
15352
+ // flip scale is handled by layer group
15353
+ // flip offset
15354
+ flipOffset.x += canvas.width / scale.x;
15355
+ offset.x += flipOffset.x;
15147
15356
  };
15148
15357
 
15149
- this.flipX = function () {
15150
- offset.x += canvas.width / scale.x;
15151
- scale.x *= -1;
15358
+ /**
15359
+ * Add a flip offset along the layer Y axis.
15360
+ */
15361
+ this.addFlipOffsetY = function () {
15362
+ // flip scale is handled by layer group
15363
+ // flip offset
15364
+ flipOffset.y += canvas.height / scale.y;
15365
+ offset.y += flipOffset.y;
15152
15366
  };
15153
15367
 
15154
15368
  /**
@@ -15165,9 +15379,9 @@ dwv.gui.ViewLayer = function (containerDiv) {
15165
15379
  y: fitScale.y * orientedNewScale.y
15166
15380
  };
15167
15381
 
15168
- if (newScale.x === 1 &&
15169
- newScale.y === 1 &&
15170
- newScale.z === 1) {
15382
+ if (Math.abs(newScale.x) === 1 &&
15383
+ Math.abs(newScale.y) === 1 &&
15384
+ Math.abs(newScale.z) === 1) {
15171
15385
  // reset zoom offset for scale=1
15172
15386
  var resetOffset = {
15173
15387
  x: offset.x - zoomOffset.x,
@@ -15183,7 +15397,7 @@ dwv.gui.ViewLayer = function (containerDiv) {
15183
15397
  y: center.getY(),
15184
15398
  z: center.getZ()
15185
15399
  });
15186
- // center was obtained with viewLayer.displayToPlanePosNoBase
15400
+ // center was obtained with viewLayer.displayToMainPlanePos
15187
15401
  // compensated for baseOffset
15188
15402
  // TODO: justify...
15189
15403
  worldCenter = {
@@ -15245,8 +15459,10 @@ dwv.gui.ViewLayer = function (containerDiv) {
15245
15459
  var helper = viewController.getPlaneHelper();
15246
15460
  var planeNewOffset = helper.getPlaneOffsetFromOffset3D(newOffset);
15247
15461
  offset = {
15248
- x: viewOffset.x + baseOffset.x + zoomOffset.x + planeNewOffset.x,
15249
- y: viewOffset.y + baseOffset.y + zoomOffset.y + planeNewOffset.y
15462
+ x: planeNewOffset.x +
15463
+ viewOffset.x + baseOffset.x + zoomOffset.x + flipOffset.x,
15464
+ y: planeNewOffset.y +
15465
+ viewOffset.y + baseOffset.y + zoomOffset.y + flipOffset.y
15250
15466
  };
15251
15467
  };
15252
15468
 
@@ -15295,7 +15511,6 @@ dwv.gui.ViewLayer = function (containerDiv) {
15295
15511
  };
15296
15512
 
15297
15513
  this.planePosToDisplay = function (x, y) {
15298
- //console.log('[vl] off', offset, baseOffset);
15299
15514
  return {
15300
15515
  x: (x - offset.x + baseOffset.x) * scale.x,
15301
15516
  y: (y - offset.y + baseOffset.y) * scale.y
@@ -15457,7 +15672,8 @@ dwv.gui.ViewLayer = function (containerDiv) {
15457
15672
  function setBaseSize(size) {
15458
15673
  // check canvas creation
15459
15674
  if (!dwv.gui.canCreateCanvas(size.x, size.y)) {
15460
- throw new Error('Cannot create canvas ' + size.x + ', ' + size.y);
15675
+ throw new Error('Cannot create canvas with size ' +
15676
+ size.x + ', ' + size.y);
15461
15677
  }
15462
15678
 
15463
15679
  // set local
@@ -17087,13 +17303,14 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17087
17303
  this.getSize = function (viewOrientation) {
17088
17304
  var res = size;
17089
17305
  if (viewOrientation && typeof viewOrientation !== 'undefined') {
17090
- var values = dwv.image.getPositiveOrientedArray3D(
17306
+ var values = dwv.image.getOrientedArray3D(
17091
17307
  [
17092
17308
  size.get(0),
17093
17309
  size.get(1),
17094
17310
  size.get(2)
17095
17311
  ],
17096
17312
  viewOrientation);
17313
+ values = values.map(Math.abs);
17097
17314
  res = new dwv.image.Size(values.concat(size.getValues().slice(3)));
17098
17315
  }
17099
17316
  return res;
@@ -17132,13 +17349,14 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17132
17349
  }
17133
17350
  var res = spacing;
17134
17351
  if (viewOrientation && typeof viewOrientation !== 'undefined') {
17135
- var orientedValues = dwv.image.getPositiveOrientedArray3D(
17352
+ var orientedValues = dwv.image.getOrientedArray3D(
17136
17353
  [
17137
17354
  spacing.get(0),
17138
17355
  spacing.get(1),
17139
17356
  spacing.get(2)
17140
17357
  ],
17141
17358
  viewOrientation);
17359
+ orientedValues = orientedValues.map(Math.abs);
17142
17360
  res = new dwv.image.Spacing(orientedValues);
17143
17361
  }
17144
17362
  return res;
@@ -17390,6 +17608,35 @@ dwv.image.Geometry.prototype.worldToIndex = function (point) {
17390
17608
  return new dwv.math.Index(values);
17391
17609
  };
17392
17610
 
17611
+ /**
17612
+ * Convert world coordinates into an point.
17613
+ *
17614
+ * @param {dwv.math.Point} point The world point to convert.
17615
+ * @returns {dwv.math.Point3D} The corresponding point.
17616
+ */
17617
+ dwv.image.Geometry.prototype.worldToPoint = function (point) {
17618
+ // compensate for origin
17619
+ // (origin is not oriented, compensate before orientation)
17620
+ var origin = this.getOrigin();
17621
+ var point3D = new dwv.math.Point3D(
17622
+ point.get(0) - origin.getX(),
17623
+ point.get(1) - origin.getY(),
17624
+ point.get(2) - origin.getZ()
17625
+ );
17626
+ // orient
17627
+ var orientedPoint3D =
17628
+ this.getOrientation().getInverse().multiplyPoint3D(point3D);
17629
+ // keep >3d values
17630
+ var values = point.getValues();
17631
+ // apply spacing and round
17632
+ var spacing = this.getSpacing();
17633
+ values[0] = orientedPoint3D.getX() / spacing.get(0);
17634
+ values[1] = orientedPoint3D.getY() / spacing.get(1);
17635
+ values[2] = orientedPoint3D.getZ() / spacing.get(2);
17636
+
17637
+ // return index
17638
+ return new dwv.math.Point3D(values[0], values[1], values[2]);
17639
+ };
17393
17640
 
17394
17641
  /**
17395
17642
  * Get the oriented values of an input 3D array.
@@ -17398,16 +17645,10 @@ dwv.image.Geometry.prototype.worldToIndex = function (point) {
17398
17645
  * @param {dwv.math.Matrix33} orientation The orientation 3D matrix.
17399
17646
  * @returns {Array} The values reordered according to the orientation.
17400
17647
  */
17401
- dwv.image.getPositiveOrientedArray3D = function (array3D, orientation) {
17648
+ dwv.image.getOrientedArray3D = function (array3D, orientation) {
17402
17649
  // values = orientation * orientedValues
17403
17650
  // -> inv(orientation) * values = orientedValues
17404
- var res = orientation.getInverse().multiplyArray3D(array3D);
17405
- // abs to avoid negatives
17406
- // TODO: check why abs is needed...
17407
- res = res.map(function (item) {
17408
- return Math.abs(item);
17409
- });
17410
- return res;
17651
+ return orientation.getInverse().multiplyArray3D(array3D);
17411
17652
  };
17412
17653
 
17413
17654
  /**
@@ -17417,15 +17658,9 @@ dwv.image.getPositiveOrientedArray3D = function (array3D, orientation) {
17417
17658
  * @param {dwv.math.Matrix33} orientation The orientation 3D matrix.
17418
17659
  * @returns {Array} The values reordered to compensate the orientation.
17419
17660
  */
17420
- dwv.image.getPositiveDeOrientedArray3D = function (array3D, orientation) {
17661
+ dwv.image.getDeOrientedArray3D = function (array3D, orientation) {
17421
17662
  // values = orientation * orientedValues
17422
- var res = orientation.multiplyArray3D(array3D);
17423
- // abs to avoid negatives
17424
- // TODO: check why abs is needed...
17425
- res = res.map(function (item) {
17426
- return Math.abs(item);
17427
- });
17428
- return res;
17663
+ return orientation.multiplyArray3D(array3D);
17429
17664
  };
17430
17665
 
17431
17666
  /**
@@ -19774,7 +20009,7 @@ dwv.dicom.getComparePosPat = function (orientation) {
19774
20009
  return function (pos1, pos2) {
19775
20010
  var p1 = invOrientation.multiplyArray3D(pos1);
19776
20011
  var p2 = invOrientation.multiplyArray3D(pos2);
19777
- return p2[2] - p1[2];
20012
+ return p1[2] - p2[2];
19778
20013
  };
19779
20014
  };
19780
20015
 
@@ -20720,7 +20955,7 @@ dwv.image.PlaneHelper = function (spacing, imageOrientation, viewOrientation) {
20720
20955
  var vector = planeVector;
20721
20956
  if (typeof viewOrientation !== 'undefined') {
20722
20957
  // image oriented => view de-oriented
20723
- var values = dwv.image.getPositiveDeOrientedArray3D(
20958
+ var values = dwv.image.getDeOrientedArray3D(
20724
20959
  [
20725
20960
  planeVector.getX(),
20726
20961
  planeVector.getY(),
@@ -20748,7 +20983,7 @@ dwv.image.PlaneHelper = function (spacing, imageOrientation, viewOrientation) {
20748
20983
  var planeVector = vector;
20749
20984
  if (typeof viewOrientation !== 'undefined') {
20750
20985
  // image de-oriented => view oriented
20751
- var orientedValues = dwv.image.getPositiveOrientedArray3D(
20986
+ var orientedValues = dwv.image.getOrientedArray3D(
20752
20987
  [
20753
20988
  vector.getX(),
20754
20989
  vector.getY(),
@@ -20773,7 +21008,7 @@ dwv.image.PlaneHelper = function (spacing, imageOrientation, viewOrientation) {
20773
21008
  * @returns {object} Reoriented values as {x,y,z}.
20774
21009
  */
20775
21010
  this.getTargetOrientedPositiveXYZ = function (values) {
20776
- var orientedValues = dwv.image.getPositiveOrientedArray3D(
21011
+ var orientedValues = dwv.image.getOrientedArray3D(
20777
21012
  [
20778
21013
  values.x,
20779
21014
  values.y,
@@ -27341,7 +27576,7 @@ dwv.math.getCoronalMat33 = function () {
27341
27576
  return new dwv.math.Matrix33([
27342
27577
  1, 0, 0,
27343
27578
  0, 0, 1,
27344
- 0, 1, 0
27579
+ 0, -1, 0
27345
27580
  ]);
27346
27581
  /* eslint-enable array-element-newline */
27347
27582
  };
@@ -27354,9 +27589,9 @@ dwv.math.getCoronalMat33 = function () {
27354
27589
  dwv.math.getSagittalMat33 = function () {
27355
27590
  /* eslint-disable array-element-newline */
27356
27591
  return new dwv.math.Matrix33([
27357
- 0, 0, 1,
27592
+ 0, 0, -1,
27358
27593
  1, 0, 0,
27359
- 0, 1, 0
27594
+ 0, -1, 0
27360
27595
  ]);
27361
27596
  /* eslint-enable array-element-newline */
27362
27597
  };