dwv 0.31.0-beta.18 → 0.31.0-beta.19

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.18 2022-11-30 11:36:21 */
1
+ /*! dwv 0.31.0-beta.19 2022-12-09 10:21:09 */
2
2
  // Inspired from umdjs
3
3
  // See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
4
4
  (function (root, factory) {
@@ -311,17 +311,6 @@ dwv.App = function () {
311
311
  return stage.getViewLayersByDataIndex(index);
312
312
  };
313
313
 
314
- /**
315
- * Get a layer group by id.
316
- * The layer is available after the first loaded item.
317
- *
318
- * @param {number} groupId The group id.
319
- * @returns {dwv.gui.LayerGroup} The layer group.
320
- */
321
- this.getLayerGroupById = function (groupId) {
322
- return stage.getLayerGroup(groupId);
323
- };
324
-
325
314
  /**
326
315
  * Get a layer group by div id.
327
316
  * The layer is available after the first loaded item.
@@ -1038,7 +1027,7 @@ dwv.App = function () {
1038
1027
  layer = layerGroup.getActiveViewLayer();
1039
1028
  }
1040
1029
  if (layer) {
1041
- toolboxController.bindLayer(layer, layerGroup.getGroupId());
1030
+ toolboxController.bindLayer(layer, layerGroup.getDivId());
1042
1031
  }
1043
1032
  }
1044
1033
 
@@ -1391,7 +1380,7 @@ dwv.App = function () {
1391
1380
  // bind
1392
1381
  stage.bindLayerGroups();
1393
1382
  if (toolboxController) {
1394
- toolboxController.bindLayer(viewLayer, layerGroup.getGroupId());
1383
+ toolboxController.bindLayer(viewLayer, layerGroup.getDivId());
1395
1384
  }
1396
1385
 
1397
1386
  // optional draw layer
@@ -1414,9 +1403,21 @@ dwv.App = function () {
1414
1403
 
1415
1404
  // sync layer groups
1416
1405
  stage.syncLayerGroupScale();
1406
+
1407
+ // extra flip for oriented views...
1408
+ 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();
1416
+ }
1417
+ }
1417
1418
  }
1418
1419
 
1419
- };
1420
+ }; // class dwv.App
1420
1421
 
1421
1422
  // namespaces
1422
1423
  var dwv = dwv || {};
@@ -2496,11 +2497,11 @@ dwv.ctrl.ToolboxController = function (toolList) {
2496
2497
  * Listen to layer interaction events.
2497
2498
  *
2498
2499
  * @param {object} layer The layer to listen to.
2499
- * @param {number} layerGroupId The associated layer group id.
2500
+ * @param {string} layerGroupDivId The associated layer group div id.
2500
2501
  */
2501
- this.bindLayer = function (layer, layerGroupId) {
2502
- if (typeof boundLayers[layerGroupId] !== 'undefined') {
2503
- unbindLayer(boundLayers[layerGroupId]);
2502
+ this.bindLayer = function (layer, layerGroupDivId) {
2503
+ if (typeof boundLayers[layerGroupDivId] !== 'undefined') {
2504
+ unbindLayer(boundLayers[layerGroupDivId]);
2504
2505
  }
2505
2506
  layer.bindInteraction();
2506
2507
  // interaction events
@@ -2510,7 +2511,7 @@ dwv.ctrl.ToolboxController = function (toolList) {
2510
2511
  getOnMouch(layer.getId(), names[i]));
2511
2512
  }
2512
2513
  // update class var
2513
- boundLayers[layerGroupId] = layer;
2514
+ boundLayers[layerGroupDivId] = layer;
2514
2515
  };
2515
2516
 
2516
2517
  /**
@@ -2639,7 +2640,7 @@ dwv.ctrl.ViewController = function (view) {
2639
2640
  // set window/level to first preset
2640
2641
  this.setWindowLevelPresetById(0);
2641
2642
  // default position
2642
- this.setCurrentPosition(this.getPositionFrom2D(0, 0));
2643
+ this.setCurrentPosition(this.getPositionFromPlanePoint(0, 0));
2643
2644
  };
2644
2645
 
2645
2646
  /**
@@ -2707,20 +2708,17 @@ dwv.ctrl.ViewController = function (view) {
2707
2708
  };
2708
2709
 
2709
2710
  /**
2710
- * Get the current oriented position.
2711
+ * Get the current oriented index.
2711
2712
  *
2712
- * @returns {dwv.math.Point} The position.
2713
+ * @returns {dwv.math.Index} The index.
2713
2714
  */
2714
2715
  this.getCurrentOrientedIndex = function () {
2715
2716
  var res = view.getCurrentIndex();
2716
- // values = orientation * orientedValues
2717
- // -> inv(orientation) * values = orientedValues
2718
2717
  if (typeof view.getOrientation() !== 'undefined') {
2719
- var index3D = new dwv.math.Index(
2720
- [res.get(0), res.get(1), res.get(2)]);
2721
- var orientedIndex3D =
2722
- view.getOrientation().getInverse().getAbs().multiplyIndex3D(index3D);
2723
- var values = orientedIndex3D.getValues();
2718
+ // view oriented => image de-oriented
2719
+ var values = planeHelper.getImageDeOrientedVector3D([
2720
+ res.get(0), res.get(1), res.get(2)
2721
+ ]);
2724
2722
  res = new dwv.math.Index(values);
2725
2723
  }
2726
2724
  return res;
@@ -3000,7 +2998,7 @@ dwv.ctrl.ViewController = function (view) {
3000
2998
  * @param {number} y The row position.
3001
2999
  * @returns {dwv.math.Point} The associated position.
3002
3000
  */
3003
- this.getPositionFrom2D = function (x, y) {
3001
+ this.getPositionFromPlanePoint = function (x, y) {
3004
3002
  // keep third direction
3005
3003
  var k = this.getCurrentScrollIndexValue();
3006
3004
  var planePoint = new dwv.math.Point3D(x, y, k);
@@ -3024,25 +3022,6 @@ dwv.ctrl.ViewController = function (view) {
3024
3022
  return view.setCurrentIndex(index, silent);
3025
3023
  };
3026
3024
 
3027
- /**
3028
- * Get a 3D position from a plane 2D position.
3029
- *
3030
- * @param {dwv.math.Point2D} point2D The 2D position as {x,y}.
3031
- * @returns {dwv.math.Point} The 3D point.
3032
- */
3033
- this.getPositionFromPlanePoint = function (point2D) {
3034
- // keep third direction
3035
- var k = this.getCurrentScrollIndexValue();
3036
- var planePoint = new dwv.math.Point3D(point2D.x, point2D.y, k);
3037
- // de-orient
3038
- var point = planeHelper.getImageOrientedVector3D(planePoint);
3039
- // ~indexToWorld to not loose precision
3040
- var geometry = view.getImage().getGeometry();
3041
- var point3D = geometry.pointToWorld(point);
3042
- // merge with current position to keep extra dimensions
3043
- return this.getCurrentPosition().mergeWith3D(point3D);
3044
- };
3045
-
3046
3025
  /**
3047
3026
  * Get a plane 3D position from a plane 2D position: does not compensate
3048
3027
  * for the image origin. Needed for setting the scale center...
@@ -4657,7 +4636,7 @@ dwv.dicom = dwv.dicom || {};
4657
4636
  * @returns {string} The version of the library.
4658
4637
  */
4659
4638
  dwv.getVersion = function () {
4660
- return '0.31.0-beta.18';
4639
+ return '0.31.0-beta.19';
4661
4640
  };
4662
4641
 
4663
4642
  /**
@@ -12913,7 +12892,7 @@ dwv.gui.DrawLayer = function (containerDiv) {
12913
12892
  * @param {dwv.math.Point3D} center The scale center.
12914
12893
  */
12915
12894
  this.setScale = function (newScale, center) {
12916
- var orientedNewScale = planeHelper.getTargetOrientedXYZ(newScale);
12895
+ var orientedNewScale = planeHelper.getTargetOrientedPositiveXYZ(newScale);
12917
12896
  var finalNewScale = {
12918
12897
  x: fitScale.x * orientedNewScale.x,
12919
12898
  y: fitScale.y * orientedNewScale.y
@@ -13385,33 +13364,30 @@ var dwv = dwv || {};
13385
13364
  dwv.gui = dwv.gui || {};
13386
13365
 
13387
13366
  /**
13388
- * Get the layer group div id.
13367
+ * Get the layer div id.
13389
13368
  *
13390
- * @param {number} groupId The layer group id.
13369
+ * @param {string} groupDivId The layer group div id.
13391
13370
  * @param {number} layerId The lyaer id.
13392
13371
  * @returns {string} A string id.
13393
13372
  */
13394
- dwv.gui.getLayerGroupDivId = function (groupId, layerId) {
13395
- return 'layer-' + groupId + '-' + layerId;
13373
+ dwv.gui.getLayerDivId = function (groupDivId, layerId) {
13374
+ return groupDivId + '-layer-' + layerId;
13396
13375
  };
13397
13376
 
13398
13377
  /**
13399
13378
  * Get the layer details from a div id.
13400
13379
  *
13401
- * @param {string} idString The layer group id.
13402
- * @returns {object} The layer details as {groupId, layerId}.
13380
+ * @param {string} idString The layer div id.
13381
+ * @returns {object} The layer details as {groupDivId, layerId}.
13403
13382
  */
13404
13383
  dwv.gui.getLayerDetailsFromLayerDivId = function (idString) {
13405
- var posHyphen = idString.lastIndexOf('-');
13406
- var groupId = null;
13407
- var layerId = null;
13408
- if (posHyphen !== -1) {
13409
- groupId = parseInt(idString.substring(6, posHyphen), 10);
13410
- layerId = parseInt(idString.substring(posHyphen + 1), 10);
13384
+ var split = idString.split('-layer-');
13385
+ if (split.length !== 2) {
13386
+ dwv.logger.warn('Not the expected layer div id format...');
13411
13387
  }
13412
13388
  return {
13413
- groupId: groupId,
13414
- layerId: layerId
13389
+ groupDivId: split[0],
13390
+ layerId: split[1]
13415
13391
  };
13416
13392
  };
13417
13393
 
@@ -13420,8 +13396,8 @@ dwv.gui.getLayerDetailsFromLayerDivId = function (idString) {
13420
13396
  *
13421
13397
  * @param {object} event The event to get the layer div id from. Expecting
13422
13398
  * an event origininating from a canvas inside a layer HTML div
13423
- * with the 'layer' class and id generated with `dwv.gui.getLayerGroupDivId`.
13424
- * @returns {object} The layer details as {groupId, layerId}.
13399
+ * with the 'layer' class and id generated with `dwv.gui.getLayerDivId`.
13400
+ * @returns {object} The layer details as {groupDivId, layerId}.
13425
13401
  */
13426
13402
  dwv.gui.getLayerDetailsFromEvent = function (event) {
13427
13403
  var res = null;
@@ -13519,10 +13495,9 @@ dwv.gui.getScaledOffset = function (offset, scale, newScale, center) {
13519
13495
  * no need yet for a planePos to displayPos...
13520
13496
  *
13521
13497
  * @param {object} containerDiv The associated HTML div.
13522
- * @param {number} groupId The group id.
13523
13498
  * @class
13524
13499
  */
13525
- dwv.gui.LayerGroup = function (containerDiv, groupId) {
13500
+ dwv.gui.LayerGroup = function (containerDiv) {
13526
13501
 
13527
13502
  // closure to self
13528
13503
  var self = this;
@@ -13612,15 +13587,6 @@ dwv.gui.LayerGroup = function (containerDiv, groupId) {
13612
13587
  return containerDiv.id;
13613
13588
  };
13614
13589
 
13615
- /**
13616
- * Get the layer group id.
13617
- *
13618
- * @returns {number} The id.
13619
- */
13620
- this.getGroupId = function () {
13621
- return groupId;
13622
- };
13623
-
13624
13590
  /**
13625
13591
  * Get the layer scale.
13626
13592
  *
@@ -13872,7 +13838,7 @@ dwv.gui.LayerGroup = function (containerDiv, groupId) {
13872
13838
  */
13873
13839
  function getNextLayerDiv() {
13874
13840
  var div = document.createElement('div');
13875
- div.id = dwv.gui.getLayerGroupDivId(groupId, layers.length);
13841
+ div.id = dwv.gui.getLayerDivId(self.getDivId(), layers.length);
13876
13842
  div.className = 'layer';
13877
13843
  div.style.pointerEvents = 'none';
13878
13844
  return div;
@@ -14393,7 +14359,7 @@ dwv.gui.Stage = function () {
14393
14359
  */
14394
14360
  this.addLayerGroup = function (htmlElement) {
14395
14361
  activeLayerGroupIndex = layerGroups.length;
14396
- var layerGroup = new dwv.gui.LayerGroup(htmlElement, activeLayerGroupIndex);
14362
+ var layerGroup = new dwv.gui.LayerGroup(htmlElement);
14397
14363
  // add to storage
14398
14364
  var isBound = callbackStore && callbackStore.length !== 0;
14399
14365
  if (isBound) {
@@ -15175,6 +15141,16 @@ dwv.gui.ViewLayer = function (containerDiv) {
15175
15141
  fireEvent(event);
15176
15142
  };
15177
15143
 
15144
+ this.flipY = function () {
15145
+ offset.y += canvas.height / scale.y;
15146
+ scale.y *= -1;
15147
+ };
15148
+
15149
+ this.flipX = function () {
15150
+ offset.x += canvas.width / scale.x;
15151
+ scale.x *= -1;
15152
+ };
15153
+
15178
15154
  /**
15179
15155
  * Set the layer scale.
15180
15156
  *
@@ -15183,7 +15159,7 @@ dwv.gui.ViewLayer = function (containerDiv) {
15183
15159
  */
15184
15160
  this.setScale = function (newScale, center) {
15185
15161
  var helper = viewController.getPlaneHelper();
15186
- var orientedNewScale = helper.getTargetOrientedXYZ(newScale);
15162
+ var orientedNewScale = helper.getTargetOrientedPositiveXYZ(newScale);
15187
15163
  var finalNewScale = {
15188
15164
  x: fitScale.x * orientedNewScale.x,
15189
15165
  y: fitScale.y * orientedNewScale.y
@@ -15318,6 +15294,14 @@ dwv.gui.ViewLayer = function (containerDiv) {
15318
15294
  };
15319
15295
  };
15320
15296
 
15297
+ this.planePosToDisplay = function (x, y) {
15298
+ //console.log('[vl] off', offset, baseOffset);
15299
+ return {
15300
+ x: (x - offset.x + baseOffset.x) * scale.x,
15301
+ y: (y - offset.y + baseOffset.y) * scale.y
15302
+ };
15303
+ };
15304
+
15321
15305
  /**
15322
15306
  * Get a main plane position from a display position.
15323
15307
  *
@@ -17064,7 +17048,7 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17064
17048
  * @returns {dwv.math.Point3D} The object origin.
17065
17049
  */
17066
17050
  this.getOrigin = function () {
17067
- return origins[origins.length - 1];
17051
+ return origins[0];
17068
17052
  };
17069
17053
  /**
17070
17054
  * Get the object origins.
@@ -17103,7 +17087,7 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17103
17087
  this.getSize = function (viewOrientation) {
17104
17088
  var res = size;
17105
17089
  if (viewOrientation && typeof viewOrientation !== 'undefined') {
17106
- var values = dwv.math.getOrientedArray3D(
17090
+ var values = dwv.image.getPositiveOrientedArray3D(
17107
17091
  [
17108
17092
  size.get(0),
17109
17093
  size.get(1),
@@ -17148,7 +17132,7 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17148
17132
  }
17149
17133
  var res = spacing;
17150
17134
  if (viewOrientation && typeof viewOrientation !== 'undefined') {
17151
- var orientedValues = dwv.math.getOrientedArray3D(
17135
+ var orientedValues = dwv.image.getPositiveOrientedArray3D(
17152
17136
  [
17153
17137
  spacing.get(0),
17154
17138
  spacing.get(1),
@@ -17225,13 +17209,8 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17225
17209
  // -> >0 => vectors are codirectional
17226
17210
  // -> <0 => vectors are opposite
17227
17211
  var dotProd = normal.dotProduct(pointDir);
17228
- var test = dotProd < 0;
17229
- // TODO: check why coronal behaves differently...
17230
- if (orientation.getThirdColMajorDirection() === 1) {
17231
- test = dotProd > 0;
17232
- }
17233
17212
  // oposite vectors get higher index
17234
- var sliceIndex = test ? closestSliceIndex + 1 : closestSliceIndex;
17213
+ var sliceIndex = dotProd > 0 ? closestSliceIndex + 1 : closestSliceIndex;
17235
17214
  return sliceIndex;
17236
17215
  };
17237
17216
 
@@ -17327,17 +17306,6 @@ dwv.image.Geometry.prototype.isIndexInBounds = function (index, dirs) {
17327
17306
  return this.getSize().isInBounds(index, dirs);
17328
17307
  };
17329
17308
 
17330
- /**
17331
- * Flip the K index.
17332
- *
17333
- * @param {dwv.image.Size} size The image size.
17334
- * @param {number} k The index.
17335
- * @returns {number} The flipped index.
17336
- */
17337
- function flipK(size, k) {
17338
- return (size.get(2) - 1) - k;
17339
- }
17340
-
17341
17309
  /**
17342
17310
  * Convert an index into world coordinates.
17343
17311
  *
@@ -17345,15 +17313,13 @@ function flipK(size, k) {
17345
17313
  * @returns {dwv.math.Point} The corresponding point.
17346
17314
  */
17347
17315
  dwv.image.Geometry.prototype.indexToWorld = function (index) {
17348
- // flip K index (because of the slice order given by getSliceIndex)
17349
- var k = flipK(this.getSize(), index.get(2));
17350
17316
  // apply spacing
17351
17317
  // (spacing is oriented, apply before orientation)
17352
17318
  var spacing = this.getSpacing();
17353
17319
  var orientedPoint3D = new dwv.math.Point3D(
17354
17320
  index.get(0) * spacing.get(0),
17355
17321
  index.get(1) * spacing.get(1),
17356
- k * spacing.get(2)
17322
+ index.get(2) * spacing.get(2)
17357
17323
  );
17358
17324
  // de-orient
17359
17325
  var point3D = this.getOrientation().multiplyPoint3D(orientedPoint3D);
@@ -17374,15 +17340,13 @@ dwv.image.Geometry.prototype.indexToWorld = function (index) {
17374
17340
  * @returns {dwv.math.Point3D} The corresponding world 3D point.
17375
17341
  */
17376
17342
  dwv.image.Geometry.prototype.pointToWorld = function (point) {
17377
- // flip K index (because of the slice order given by getSliceIndex)
17378
- var k = flipK(this.getSize(), point.getZ());
17379
17343
  // apply spacing
17380
17344
  // (spacing is oriented, apply before orientation)
17381
17345
  var spacing = this.getSpacing();
17382
17346
  var orientedPoint3D = new dwv.math.Point3D(
17383
17347
  point.getX() * spacing.get(0),
17384
17348
  point.getY() * spacing.get(1),
17385
- k * spacing.get(2)
17349
+ point.getZ() * spacing.get(2)
17386
17350
  );
17387
17351
  // de-orient
17388
17352
  var point3D = this.getOrientation().multiplyPoint3D(orientedPoint3D);
@@ -17420,16 +17384,50 @@ dwv.image.Geometry.prototype.worldToIndex = function (point) {
17420
17384
  var spacing = this.getSpacing();
17421
17385
  values[0] = Math.round(orientedPoint3D.getX() / spacing.get(0));
17422
17386
  values[1] = Math.round(orientedPoint3D.getY() / spacing.get(1));
17423
- // flip K index (because of the slice order given by getSliceIndex)
17424
- var k = Math.round(orientedPoint3D.getZ() / spacing.get(2));
17425
- // abs to fix #1163
17426
- // TODO: find out why k can sometimes be negative...
17427
- values[2] = flipK(this.getSize(), k);
17387
+ values[2] = Math.round(orientedPoint3D.getZ() / spacing.get(2));
17428
17388
 
17429
17389
  // return index
17430
17390
  return new dwv.math.Index(values);
17431
17391
  };
17432
17392
 
17393
+
17394
+ /**
17395
+ * Get the oriented values of an input 3D array.
17396
+ *
17397
+ * @param {Array} array3D The 3D array.
17398
+ * @param {dwv.math.Matrix33} orientation The orientation 3D matrix.
17399
+ * @returns {Array} The values reordered according to the orientation.
17400
+ */
17401
+ dwv.image.getPositiveOrientedArray3D = function (array3D, orientation) {
17402
+ // values = orientation * orientedValues
17403
+ // -> 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;
17411
+ };
17412
+
17413
+ /**
17414
+ * Get the raw values of an oriented input 3D array.
17415
+ *
17416
+ * @param {Array} array3D The 3D array.
17417
+ * @param {dwv.math.Matrix33} orientation The orientation 3D matrix.
17418
+ * @returns {Array} The values reordered to compensate the orientation.
17419
+ */
17420
+ dwv.image.getPositiveDeOrientedArray3D = function (array3D, orientation) {
17421
+ // 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;
17429
+ };
17430
+
17433
17431
  /**
17434
17432
  * Get the slice spacing from the difference in the Z directions
17435
17433
  * of input origins.
@@ -20712,6 +20710,8 @@ dwv.image.PlaneHelper = function (spacing, imageOrientation, viewOrientation) {
20712
20710
 
20713
20711
  /**
20714
20712
  * Orient an input vector from target to image space.
20713
+ * WARN: returns absolute values...
20714
+ * TODO: check why abs is needed...
20715
20715
  *
20716
20716
  * @param {dwv.math.Vector3D} planeVector The input vector.
20717
20717
  * @returns {dwv.math.Vector3D} The orienteded vector.
@@ -20719,21 +20719,61 @@ dwv.image.PlaneHelper = function (spacing, imageOrientation, viewOrientation) {
20719
20719
  this.getImageOrientedVector3D = function (planeVector) {
20720
20720
  var vector = planeVector;
20721
20721
  if (typeof viewOrientation !== 'undefined') {
20722
- // abs? otherwise negative index...
20723
- // vector = viewOrientation * planePoint
20724
- vector = viewOrientation.getAbs().multiplyVector3D(planeVector);
20722
+ // image oriented => view de-oriented
20723
+ var values = dwv.image.getPositiveDeOrientedArray3D(
20724
+ [
20725
+ planeVector.getX(),
20726
+ planeVector.getY(),
20727
+ planeVector.getZ()
20728
+ ],
20729
+ viewOrientation);
20730
+ vector = new dwv.math.Vector3D(
20731
+ values[0],
20732
+ values[1],
20733
+ values[2]
20734
+ );
20725
20735
  }
20726
20736
  return vector;
20727
20737
  };
20728
20738
 
20739
+ /**
20740
+ * De-orient an input vector from image to target space.
20741
+ * WARN: returns absolute values...
20742
+ * TODO: check why abs is needed...
20743
+ *
20744
+ * @param {dwv.math.Vector3D} vector The input vector.
20745
+ * @returns {dwv.math.Vector3D} The de-orienteded vector.
20746
+ */
20747
+ this.getImageDeOrientedVector3D = function (vector) {
20748
+ var planeVector = vector;
20749
+ if (typeof viewOrientation !== 'undefined') {
20750
+ // image de-oriented => view oriented
20751
+ var orientedValues = dwv.image.getPositiveOrientedArray3D(
20752
+ [
20753
+ vector.getX(),
20754
+ vector.getY(),
20755
+ vector.getZ()
20756
+ ],
20757
+ viewOrientation);
20758
+ planeVector = new dwv.math.Vector3D(
20759
+ orientedValues[0],
20760
+ orientedValues[1],
20761
+ orientedValues[2]
20762
+ );
20763
+ }
20764
+ return planeVector;
20765
+ };
20766
+
20729
20767
  /**
20730
20768
  * Reorder values to follow target orientation.
20769
+ * WARN: returns absolute values...
20770
+ * TODO: check why abs is needed...
20731
20771
  *
20732
20772
  * @param {object} values Values as {x,y,z}.
20733
20773
  * @returns {object} Reoriented values as {x,y,z}.
20734
20774
  */
20735
- this.getTargetOrientedXYZ = function (values) {
20736
- var orientedValues = dwv.math.getOrientedArray3D(
20775
+ this.getTargetOrientedPositiveXYZ = function (values) {
20776
+ var orientedValues = dwv.image.getPositiveOrientedArray3D(
20737
20777
  [
20738
20778
  values.x,
20739
20779
  values.y,
@@ -27339,32 +27379,6 @@ dwv.math.getMatrixFromName = function (name) {
27339
27379
  return matrix;
27340
27380
  };
27341
27381
 
27342
- /**
27343
- * Get the oriented values of an input 3D array.
27344
- *
27345
- * @param {Array} array3D The 3D array.
27346
- * @param {dwv.math.Matrix33} orientation The orientation 3D matrix.
27347
- * @returns {Array} The values reordered according to the orientation.
27348
- */
27349
- dwv.math.getOrientedArray3D = function (array3D, orientation) {
27350
- // values = orientation * orientedValues
27351
- // -> inv(orientation) * values = orientedValues
27352
- return orientation.getInverse().getAbs().multiplyArray3D(array3D);
27353
- };
27354
-
27355
- /**
27356
- * Get the raw values of an oriented input 3D array.
27357
- *
27358
- * @param {Array} array3D The 3D array.
27359
- * @param {dwv.math.Matrix33} orientation The orientation 3D matrix.
27360
- * @returns {Array} The values reordered to compensate the orientation.
27361
- */
27362
- dwv.math.getDeOrientedArray3D = function (array3D, orientation) {
27363
- // values = orientation * orientedValues
27364
- // -> inv(orientation) * values = orientedValues
27365
- return orientation.getAbs().multiplyArray3D(array3D);
27366
- };
27367
-
27368
27382
  // namespaces
27369
27383
  var dwv = dwv || {};
27370
27384
  dwv.math = dwv.math || {};
@@ -29868,7 +29882,7 @@ dwv.tool.Draw = function (app) {
29868
29882
  }
29869
29883
 
29870
29884
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
29871
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
29885
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
29872
29886
  var drawLayer = layerGroup.getActiveDrawLayer();
29873
29887
 
29874
29888
  // determine if the click happened in an existing shape
@@ -29925,7 +29939,7 @@ dwv.tool.Draw = function (app) {
29925
29939
  }
29926
29940
 
29927
29941
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
29928
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
29942
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
29929
29943
  var viewLayer = layerGroup.getActiveViewLayer();
29930
29944
  var pos = viewLayer.displayToPlanePos(event._x, event._y);
29931
29945
 
@@ -29969,7 +29983,7 @@ dwv.tool.Draw = function (app) {
29969
29983
  if (points.length === currentFactory.getNPoints()) {
29970
29984
  // store points
29971
29985
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
29972
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
29986
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
29973
29987
  onFinalPoints(points, layerGroup);
29974
29988
  // reset flag
29975
29989
  started = false;
@@ -30003,7 +30017,7 @@ dwv.tool.Draw = function (app) {
30003
30017
 
30004
30018
  // store points
30005
30019
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
30006
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
30020
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
30007
30021
  onFinalPoints(points, layerGroup);
30008
30022
  // reset flag
30009
30023
  started = false;
@@ -30039,7 +30053,7 @@ dwv.tool.Draw = function (app) {
30039
30053
  }
30040
30054
 
30041
30055
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
30042
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
30056
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
30043
30057
  var viewLayer = layerGroup.getActiveViewLayer();
30044
30058
  var pos = viewLayer.displayToPlanePos(event._x, event._y);
30045
30059
 
@@ -31419,7 +31433,7 @@ dwv.tool.ShapeEditor = function (app) {
31419
31433
  // drag move listener
31420
31434
  anchor.on('dragmove.edit', function (evt) {
31421
31435
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(evt.evt);
31422
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
31436
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
31423
31437
  var drawLayer = layerGroup.getActiveDrawLayer();
31424
31438
  // validate the anchor position
31425
31439
  dwv.tool.validateAnchorPosition(drawLayer.getBaseSize(), this);
@@ -32584,7 +32598,7 @@ dwv.tool.Floodfill = function (app) {
32584
32598
  */
32585
32599
  var getCoord = function (event) {
32586
32600
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
32587
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
32601
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
32588
32602
  var viewLayer = layerGroup.getActiveViewLayer();
32589
32603
  var index = viewLayer.displayToPlaneIndex(event._x, event._y);
32590
32604
  return {
@@ -32772,7 +32786,7 @@ dwv.tool.Floodfill = function (app) {
32772
32786
  */
32773
32787
  this.mousedown = function (event) {
32774
32788
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
32775
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
32789
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
32776
32790
  var viewLayer = layerGroup.getActiveViewLayer();
32777
32791
  var drawLayer = layerGroup.getActiveDrawLayer();
32778
32792
 
@@ -32819,7 +32833,7 @@ dwv.tool.Floodfill = function (app) {
32819
32833
  self.started = false;
32820
32834
  if (extender) {
32821
32835
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
32822
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
32836
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
32823
32837
  self.extend(layerGroup);
32824
32838
  }
32825
32839
  };
@@ -33283,7 +33297,7 @@ dwv.tool.Livewire = function (app) {
33283
33297
  */
33284
33298
  this.mousedown = function (event) {
33285
33299
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
33286
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
33300
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
33287
33301
  var viewLayer = layerGroup.getActiveViewLayer();
33288
33302
  var imageSize = viewLayer.getViewController().getImageSize();
33289
33303
  var index = viewLayer.displayToPlaneIndex(event._x, event._y);
@@ -33344,7 +33358,7 @@ dwv.tool.Livewire = function (app) {
33344
33358
  return;
33345
33359
  }
33346
33360
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
33347
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
33361
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
33348
33362
  var viewLayer = layerGroup.getActiveViewLayer();
33349
33363
  var index = viewLayer.displayToPlaneIndex(event._x, event._y);
33350
33364
 
@@ -33634,7 +33648,7 @@ dwv.tool.Opacity = function (app) {
33634
33648
  // do not trigger for small moves
33635
33649
  if (xMove) {
33636
33650
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
33637
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
33651
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
33638
33652
  var viewLayer = layerGroup.getActiveViewLayer();
33639
33653
  var op = viewLayer.getOpacity();
33640
33654
  viewLayer.setOpacity(op + (diffX / 200));
@@ -34946,7 +34960,7 @@ dwv.tool = dwv.tool || {};
34946
34960
  * document.body.appendChild(range);
34947
34961
  * // update app on slider change
34948
34962
  * range.oninput = function () {
34949
- * var lg = app.getLayerGroupById(0);
34963
+ * var lg = app.getLayerGroupByDivId('layerGroup0');
34950
34964
  * var vc = lg.getActiveViewLayer().getViewController();
34951
34965
  * var index = vc.getCurrentIndex();
34952
34966
  * var values = index.getValues();
@@ -34961,7 +34975,7 @@ dwv.tool = dwv.tool || {};
34961
34975
  * });
34962
34976
  * // update slider on slice change (for ex via mouse wheel)
34963
34977
  * app.addEventListener('positionchange', function () {
34964
- * var lg = app.getLayerGroupById(0);
34978
+ * var lg = app.getLayerGroupByDivId('layerGroup0');
34965
34979
  * var vc = lg.getActiveViewLayer().getViewController();
34966
34980
  * range.value = vc.getCurrentIndex().get(2);
34967
34981
  * });
@@ -35014,7 +35028,7 @@ dwv.tool.Scroll = function (app) {
35014
35028
 
35015
35029
  // stop viewer if playing
35016
35030
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35017
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35031
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35018
35032
  var viewLayer = layerGroup.getActiveViewLayer();
35019
35033
  var viewController = viewLayer.getViewController();
35020
35034
  if (viewController.isPlaying()) {
@@ -35028,7 +35042,8 @@ dwv.tool.Scroll = function (app) {
35028
35042
 
35029
35043
  // update controller position
35030
35044
  var planePos = viewLayer.displayToPlanePos(event._x, event._y);
35031
- var position = viewController.getPositionFrom2D(planePos.x, planePos.y);
35045
+ var position = viewController.getPositionFromPlanePoint(
35046
+ planePos.x, planePos.y);
35032
35047
  viewController.setCurrentPosition(position);
35033
35048
  };
35034
35049
 
@@ -35047,7 +35062,7 @@ dwv.tool.Scroll = function (app) {
35047
35062
  }
35048
35063
 
35049
35064
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35050
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35065
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35051
35066
  var viewLayer = layerGroup.getActiveViewLayer();
35052
35067
  var viewController = viewLayer.getViewController();
35053
35068
 
@@ -35180,7 +35195,7 @@ dwv.tool.Scroll = function (app) {
35180
35195
  }
35181
35196
 
35182
35197
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35183
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35198
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35184
35199
  var viewController =
35185
35200
  layerGroup.getActiveViewLayer().getViewController();
35186
35201
  if (up) {
@@ -35207,7 +35222,7 @@ dwv.tool.Scroll = function (app) {
35207
35222
  */
35208
35223
  this.dblclick = function (event) {
35209
35224
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35210
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35225
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35211
35226
  var viewController =
35212
35227
  layerGroup.getActiveViewLayer().getViewController();
35213
35228
  viewController.play();
@@ -35225,11 +35240,12 @@ dwv.tool.Scroll = function (app) {
35225
35240
 
35226
35241
  // get image value at position
35227
35242
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35228
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35243
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35229
35244
  var viewLayer = layerGroup.getActiveViewLayer();
35230
35245
  var viewController = viewLayer.getViewController();
35231
35246
  var planePos = viewLayer.displayToPlanePos(event._x, event._y);
35232
- var position = viewController.getPositionFrom2D(planePos.x, planePos.y);
35247
+ var position = viewController.getPositionFromPlanePoint(
35248
+ planePos.x, planePos.y);
35233
35249
  var value = viewController.getRescaledImageValue(position);
35234
35250
 
35235
35251
  // create
@@ -35515,7 +35531,7 @@ dwv.tool.WindowLevel = function (app) {
35515
35531
  }
35516
35532
 
35517
35533
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35518
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35534
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35519
35535
  var viewController =
35520
35536
  layerGroup.getActiveViewLayer().getViewController();
35521
35537
 
@@ -35605,7 +35621,7 @@ dwv.tool.WindowLevel = function (app) {
35605
35621
  */
35606
35622
  this.dblclick = function (event) {
35607
35623
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35608
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35624
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35609
35625
  var viewLayer = layerGroup.getActiveViewLayer();
35610
35626
  var index = viewLayer.displayToPlaneIndex(event._x, event._y);
35611
35627
  var viewController = viewLayer.getViewController();
@@ -35737,7 +35753,7 @@ dwv.tool.ZoomAndPan = function (app) {
35737
35753
  var ty = event._y - self.y0;
35738
35754
  // apply translation
35739
35755
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35740
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35756
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35741
35757
  var viewLayer = layerGroup.getActiveViewLayer();
35742
35758
  var viewController = viewLayer.getViewController();
35743
35759
  var planeOffset = viewLayer.displayToPlaneScale(tx, ty);
@@ -35768,7 +35784,7 @@ dwv.tool.ZoomAndPan = function (app) {
35768
35784
  var lineRatio = newLine.getLength() / self.line0.getLength();
35769
35785
 
35770
35786
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35771
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35787
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35772
35788
  var viewLayer = layerGroup.getActiveViewLayer();
35773
35789
  var viewController = viewLayer.getViewController();
35774
35790
 
@@ -35869,7 +35885,7 @@ dwv.tool.ZoomAndPan = function (app) {
35869
35885
  var step = -event.deltaY / 500;
35870
35886
 
35871
35887
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35872
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35888
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35873
35889
  var viewLayer = layerGroup.getActiveViewLayer();
35874
35890
  var viewController = viewLayer.getViewController();
35875
35891
  var planePos = viewLayer.displayToMainPlanePos(event._x, event._y);