dwv 0.31.0-beta.17 → 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.17 2022-11-17 16:14:43 */
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.
@@ -374,7 +363,8 @@ dwv.App = function () {
374
363
  * string (default undefined keeps the original slice order)
375
364
  * - `binders`: array of layerGroup binders
376
365
  * - `tools`: tool name indexed object containing individual tool
377
- * configurations
366
+ * configurations in the form of a list of objects containing:
367
+ * - options: array of tool options
378
368
  * - `viewOnFirstLoadItem`: boolean flag to trigger the first data render
379
369
  * after the first loaded data or not
380
370
  * - `defaultCharacterSet`: the default chraracter set string used for DICOM
@@ -433,18 +423,16 @@ dwv.App = function () {
433
423
  toolList[toolName] = new dwv.tool[toolName](this);
434
424
  // register listeners
435
425
  if (typeof toolList[toolName].addEventListener !== 'undefined') {
436
- if (typeof toolParams.events !== 'undefined') {
437
- for (var j = 0; j < toolParams.events.length; ++j) {
438
- var eventName = toolParams.events[j];
439
- toolList[toolName].addEventListener(eventName, fireEvent);
440
- }
426
+ var names = toolList[toolName].getEventNames();
427
+ for (var j = 0; j < names.length; ++j) {
428
+ toolList[toolName].addEventListener(names[j], fireEvent);
441
429
  }
442
430
  }
443
431
  // tool options
444
432
  if (typeof toolParams.options !== 'undefined') {
445
433
  var type = 'raw';
446
- if (typeof toolParams.type !== 'undefined') {
447
- type = toolParams.type;
434
+ if (typeof toolList[toolName].getOptionsType !== 'undefined') {
435
+ type = toolList[toolName].getOptionsType();
448
436
  }
449
437
  var toolOptions = toolParams.options;
450
438
  if (type === 'instance' ||
@@ -1026,21 +1014,10 @@ dwv.App = function () {
1026
1014
  * @param {string} tool The tool.
1027
1015
  */
1028
1016
  this.setTool = function (tool) {
1029
- // bind tool to layer: not really important which layer since
1030
- // tools are responsible for finding the event source layer
1031
- // but there needs to be at least one binding...
1017
+ // bind tool to active layer
1032
1018
  for (var i = 0; i < stage.getNumberOfLayerGroups(); ++i) {
1033
1019
  var layerGroup = stage.getLayerGroup(i);
1034
- // unbind previous layer
1035
- var vl = layerGroup.getActiveViewLayer();
1036
- if (vl) {
1037
- toolboxController.unbindLayer(vl);
1038
- }
1039
- var dl = layerGroup.getActiveDrawLayer();
1040
- if (dl) {
1041
- toolboxController.unbindLayer(dl);
1042
- }
1043
- // bind new layer
1020
+ // draw or view layer
1044
1021
  var layer = null;
1045
1022
  if (tool === 'Draw' ||
1046
1023
  tool === 'Livewire' ||
@@ -1050,7 +1027,7 @@ dwv.App = function () {
1050
1027
  layer = layerGroup.getActiveViewLayer();
1051
1028
  }
1052
1029
  if (layer) {
1053
- toolboxController.bindLayer(layer);
1030
+ toolboxController.bindLayer(layer, layerGroup.getDivId());
1054
1031
  }
1055
1032
  }
1056
1033
 
@@ -1402,6 +1379,9 @@ dwv.App = function () {
1402
1379
 
1403
1380
  // bind
1404
1381
  stage.bindLayerGroups();
1382
+ if (toolboxController) {
1383
+ toolboxController.bindLayer(viewLayer, layerGroup.getDivId());
1384
+ }
1405
1385
 
1406
1386
  // optional draw layer
1407
1387
  if (toolboxController && toolboxController.hasTool('Draw')) {
@@ -1423,9 +1403,21 @@ dwv.App = function () {
1423
1403
 
1424
1404
  // sync layer groups
1425
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
+ }
1426
1418
  }
1427
1419
 
1428
- };
1420
+ }; // class dwv.App
1429
1421
 
1430
1422
  // namespaces
1431
1423
  var dwv = dwv || {};
@@ -2412,6 +2404,14 @@ dwv.ctrl.ToolboxController = function (toolList) {
2412
2404
  */
2413
2405
  var callbackStore = [];
2414
2406
 
2407
+ /**
2408
+ * Current layers bound to tool.
2409
+ *
2410
+ * @type {object}
2411
+ * @private
2412
+ */
2413
+ var boundLayers = {};
2414
+
2415
2415
  /**
2416
2416
  * Initialise.
2417
2417
  */
@@ -2497,8 +2497,12 @@ dwv.ctrl.ToolboxController = function (toolList) {
2497
2497
  * Listen to layer interaction events.
2498
2498
  *
2499
2499
  * @param {object} layer The layer to listen to.
2500
+ * @param {string} layerGroupDivId The associated layer group div id.
2500
2501
  */
2501
- this.bindLayer = function (layer) {
2502
+ this.bindLayer = function (layer, layerGroupDivId) {
2503
+ if (typeof boundLayers[layerGroupDivId] !== 'undefined') {
2504
+ unbindLayer(boundLayers[layerGroupDivId]);
2505
+ }
2502
2506
  layer.bindInteraction();
2503
2507
  // interaction events
2504
2508
  var names = dwv.gui.interactionEventNames;
@@ -2506,6 +2510,8 @@ dwv.ctrl.ToolboxController = function (toolList) {
2506
2510
  layer.addEventListener(names[i],
2507
2511
  getOnMouch(layer.getId(), names[i]));
2508
2512
  }
2513
+ // update class var
2514
+ boundLayers[layerGroupDivId] = layer;
2509
2515
  };
2510
2516
 
2511
2517
  /**
@@ -2513,7 +2519,7 @@ dwv.ctrl.ToolboxController = function (toolList) {
2513
2519
  *
2514
2520
  * @param {object} layer The layer to stop listening to.
2515
2521
  */
2516
- this.unbindLayer = function (layer) {
2522
+ function unbindLayer(layer) {
2517
2523
  layer.unbindInteraction();
2518
2524
  // interaction events
2519
2525
  var names = dwv.gui.interactionEventNames;
@@ -2521,7 +2527,7 @@ dwv.ctrl.ToolboxController = function (toolList) {
2521
2527
  layer.removeEventListener(names[i],
2522
2528
  getOnMouch(layer.getId(), names[i]));
2523
2529
  }
2524
- };
2530
+ }
2525
2531
 
2526
2532
  /**
2527
2533
  * Mou(se) and (T)ouch event handler. This function just determines
@@ -2634,7 +2640,7 @@ dwv.ctrl.ViewController = function (view) {
2634
2640
  // set window/level to first preset
2635
2641
  this.setWindowLevelPresetById(0);
2636
2642
  // default position
2637
- this.setCurrentPosition2D(0, 0);
2643
+ this.setCurrentPosition(this.getPositionFromPlanePoint(0, 0));
2638
2644
  };
2639
2645
 
2640
2646
  /**
@@ -2702,20 +2708,17 @@ dwv.ctrl.ViewController = function (view) {
2702
2708
  };
2703
2709
 
2704
2710
  /**
2705
- * Get the current oriented position.
2711
+ * Get the current oriented index.
2706
2712
  *
2707
- * @returns {dwv.math.Point} The position.
2713
+ * @returns {dwv.math.Index} The index.
2708
2714
  */
2709
2715
  this.getCurrentOrientedIndex = function () {
2710
2716
  var res = view.getCurrentIndex();
2711
- // values = orientation * orientedValues
2712
- // -> inv(orientation) * values = orientedValues
2713
2717
  if (typeof view.getOrientation() !== 'undefined') {
2714
- var index3D = new dwv.math.Index(
2715
- [res.get(0), res.get(1), res.get(2)]);
2716
- var orientedIndex3D =
2717
- view.getOrientation().getInverse().getAbs().multiplyIndex3D(index3D);
2718
- 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
+ ]);
2719
2722
  res = new dwv.math.Index(values);
2720
2723
  }
2721
2724
  return res;
@@ -2783,6 +2786,36 @@ dwv.ctrl.ViewController = function (view) {
2783
2786
  return [spacing.get(0), spacing.get(1)];
2784
2787
  };
2785
2788
 
2789
+ /**
2790
+ * Get the image rescaled value at the input position.
2791
+ *
2792
+ * @param {dwv.math.Point} position the input position.
2793
+ * @returns {number|undefined} The image value or undefined if out of bounds
2794
+ * or no quantifiable (for ex RGB).
2795
+ */
2796
+ this.getRescaledImageValue = function (position) {
2797
+ var image = view.getImage();
2798
+ if (!image.canQuantify()) {
2799
+ return;
2800
+ }
2801
+ var geometry = image.getGeometry();
2802
+ var index = geometry.worldToIndex(position);
2803
+ var value;
2804
+ if (geometry.isIndexInBounds(index)) {
2805
+ value = image.getRescaledValueAtIndex(index);
2806
+ }
2807
+ return value;
2808
+ };
2809
+
2810
+ /**
2811
+ * Get the image pixel unit.
2812
+ *
2813
+ * @returns {string} The unit
2814
+ */
2815
+ this.getPixelUnit = function () {
2816
+ return view.getImage().getMeta().pixelUnit;
2817
+ };
2818
+
2786
2819
  /**
2787
2820
  * Get some values from the associated image in a region.
2788
2821
  *
@@ -2959,13 +2992,13 @@ dwv.ctrl.ViewController = function (view) {
2959
2992
  };
2960
2993
 
2961
2994
  /**
2962
- * Set the current 2D (x,y) position.
2995
+ * Get a position from a 2D (x,y) position.
2963
2996
  *
2964
2997
  * @param {number} x The column position.
2965
2998
  * @param {number} y The row position.
2966
- * @returns {boolean} False if not in bounds.
2999
+ * @returns {dwv.math.Point} The associated position.
2967
3000
  */
2968
- this.setCurrentPosition2D = function (x, y) {
3001
+ this.getPositionFromPlanePoint = function (x, y) {
2969
3002
  // keep third direction
2970
3003
  var k = this.getCurrentScrollIndexValue();
2971
3004
  var planePoint = new dwv.math.Point3D(x, y, k);
@@ -2975,9 +3008,7 @@ dwv.ctrl.ViewController = function (view) {
2975
3008
  var geometry = view.getImage().getGeometry();
2976
3009
  var point3D = geometry.pointToWorld(point);
2977
3010
  // merge with current position to keep extra dimensions
2978
- var position = this.getCurrentPosition().mergeWith3D(point3D);
2979
-
2980
- return view.setCurrentPosition(position);
3011
+ return this.getCurrentPosition().mergeWith3D(point3D);
2981
3012
  };
2982
3013
 
2983
3014
  /**
@@ -2991,25 +3022,6 @@ dwv.ctrl.ViewController = function (view) {
2991
3022
  return view.setCurrentIndex(index, silent);
2992
3023
  };
2993
3024
 
2994
- /**
2995
- * Get a 3D position from a plane 2D position.
2996
- *
2997
- * @param {dwv.math.Point2D} point2D The 2D position as {x,y}.
2998
- * @returns {dwv.math.Point} The 3D point.
2999
- */
3000
- this.getPositionFromPlanePoint = function (point2D) {
3001
- // keep third direction
3002
- var k = this.getCurrentScrollIndexValue();
3003
- var planePoint = new dwv.math.Point3D(point2D.x, point2D.y, k);
3004
- // de-orient
3005
- var point = planeHelper.getImageOrientedVector3D(planePoint);
3006
- // ~indexToWorld to not loose precision
3007
- var geometry = view.getImage().getGeometry();
3008
- var point3D = geometry.pointToWorld(point);
3009
- // merge with current position to keep extra dimensions
3010
- return this.getCurrentPosition().mergeWith3D(point3D);
3011
- };
3012
-
3013
3025
  /**
3014
3026
  * Get a plane 3D position from a plane 2D position: does not compensate
3015
3027
  * for the image origin. Needed for setting the scale center...
@@ -4526,6 +4538,28 @@ dwv.dicom.DicomElementsWrapper.prototype.getTime = function () {
4526
4538
  return undefined;
4527
4539
  };
4528
4540
 
4541
+ /**
4542
+ * Get the pixel data unit.
4543
+ *
4544
+ * @returns {string|null} The unit value if available.
4545
+ */
4546
+ dwv.dicom.DicomElementsWrapper.prototype.getPixelUnit = function () {
4547
+ // RescaleType
4548
+ var unit = this.getFromKey('x00281054');
4549
+ if (!unit) {
4550
+ // Units (for PET)
4551
+ unit = this.getFromKey('x00541001');
4552
+ }
4553
+ // default rescale type for CT
4554
+ if (!unit) {
4555
+ var modality = this.getFromKey('x00080060');
4556
+ if (modality === 'CT') {
4557
+ unit = 'HU';
4558
+ }
4559
+ }
4560
+ return unit;
4561
+ };
4562
+
4529
4563
  /**
4530
4564
  * Get the file list from a DICOMDIR
4531
4565
  *
@@ -4602,7 +4636,7 @@ dwv.dicom = dwv.dicom || {};
4602
4636
  * @returns {string} The version of the library.
4603
4637
  */
4604
4638
  dwv.getVersion = function () {
4605
- return '0.31.0-beta.17';
4639
+ return '0.31.0-beta.19';
4606
4640
  };
4607
4641
 
4608
4642
  /**
@@ -12858,7 +12892,7 @@ dwv.gui.DrawLayer = function (containerDiv) {
12858
12892
  * @param {dwv.math.Point3D} center The scale center.
12859
12893
  */
12860
12894
  this.setScale = function (newScale, center) {
12861
- var orientedNewScale = planeHelper.getTargetOrientedXYZ(newScale);
12895
+ var orientedNewScale = planeHelper.getTargetOrientedPositiveXYZ(newScale);
12862
12896
  var finalNewScale = {
12863
12897
  x: fitScale.x * orientedNewScale.x,
12864
12898
  y: fitScale.y * orientedNewScale.y
@@ -13330,33 +13364,30 @@ var dwv = dwv || {};
13330
13364
  dwv.gui = dwv.gui || {};
13331
13365
 
13332
13366
  /**
13333
- * Get the layer group div id.
13367
+ * Get the layer div id.
13334
13368
  *
13335
- * @param {number} groupId The layer group id.
13369
+ * @param {string} groupDivId The layer group div id.
13336
13370
  * @param {number} layerId The lyaer id.
13337
13371
  * @returns {string} A string id.
13338
13372
  */
13339
- dwv.gui.getLayerGroupDivId = function (groupId, layerId) {
13340
- return 'layer-' + groupId + '-' + layerId;
13373
+ dwv.gui.getLayerDivId = function (groupDivId, layerId) {
13374
+ return groupDivId + '-layer-' + layerId;
13341
13375
  };
13342
13376
 
13343
13377
  /**
13344
13378
  * Get the layer details from a div id.
13345
13379
  *
13346
- * @param {string} idString The layer group id.
13347
- * @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}.
13348
13382
  */
13349
13383
  dwv.gui.getLayerDetailsFromLayerDivId = function (idString) {
13350
- var posHyphen = idString.lastIndexOf('-');
13351
- var groupId = null;
13352
- var layerId = null;
13353
- if (posHyphen !== -1) {
13354
- groupId = parseInt(idString.substring(6, posHyphen), 10);
13355
- 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...');
13356
13387
  }
13357
13388
  return {
13358
- groupId: groupId,
13359
- layerId: layerId
13389
+ groupDivId: split[0],
13390
+ layerId: split[1]
13360
13391
  };
13361
13392
  };
13362
13393
 
@@ -13365,8 +13396,8 @@ dwv.gui.getLayerDetailsFromLayerDivId = function (idString) {
13365
13396
  *
13366
13397
  * @param {object} event The event to get the layer div id from. Expecting
13367
13398
  * an event origininating from a canvas inside a layer HTML div
13368
- * with the 'layer' class and id generated with `dwv.gui.getLayerGroupDivId`.
13369
- * @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}.
13370
13401
  */
13371
13402
  dwv.gui.getLayerDetailsFromEvent = function (event) {
13372
13403
  var res = null;
@@ -13464,10 +13495,9 @@ dwv.gui.getScaledOffset = function (offset, scale, newScale, center) {
13464
13495
  * no need yet for a planePos to displayPos...
13465
13496
  *
13466
13497
  * @param {object} containerDiv The associated HTML div.
13467
- * @param {number} groupId The group id.
13468
13498
  * @class
13469
13499
  */
13470
- dwv.gui.LayerGroup = function (containerDiv, groupId) {
13500
+ dwv.gui.LayerGroup = function (containerDiv) {
13471
13501
 
13472
13502
  // closure to self
13473
13503
  var self = this;
@@ -13557,15 +13587,6 @@ dwv.gui.LayerGroup = function (containerDiv, groupId) {
13557
13587
  return containerDiv.id;
13558
13588
  };
13559
13589
 
13560
- /**
13561
- * Get the layer group id.
13562
- *
13563
- * @returns {number} The id.
13564
- */
13565
- this.getGroupId = function () {
13566
- return groupId;
13567
- };
13568
-
13569
13590
  /**
13570
13591
  * Get the layer scale.
13571
13592
  *
@@ -13817,7 +13838,7 @@ dwv.gui.LayerGroup = function (containerDiv, groupId) {
13817
13838
  */
13818
13839
  function getNextLayerDiv() {
13819
13840
  var div = document.createElement('div');
13820
- div.id = dwv.gui.getLayerGroupDivId(groupId, layers.length);
13841
+ div.id = dwv.gui.getLayerDivId(self.getDivId(), layers.length);
13821
13842
  div.className = 'layer';
13822
13843
  div.style.pointerEvents = 'none';
13823
13844
  return div;
@@ -14338,7 +14359,7 @@ dwv.gui.Stage = function () {
14338
14359
  */
14339
14360
  this.addLayerGroup = function (htmlElement) {
14340
14361
  activeLayerGroupIndex = layerGroups.length;
14341
- var layerGroup = new dwv.gui.LayerGroup(htmlElement, activeLayerGroupIndex);
14362
+ var layerGroup = new dwv.gui.LayerGroup(htmlElement);
14342
14363
  // add to storage
14343
14364
  var isBound = callbackStore && callbackStore.length !== 0;
14344
14365
  if (isBound) {
@@ -15120,6 +15141,16 @@ dwv.gui.ViewLayer = function (containerDiv) {
15120
15141
  fireEvent(event);
15121
15142
  };
15122
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
+
15123
15154
  /**
15124
15155
  * Set the layer scale.
15125
15156
  *
@@ -15128,7 +15159,7 @@ dwv.gui.ViewLayer = function (containerDiv) {
15128
15159
  */
15129
15160
  this.setScale = function (newScale, center) {
15130
15161
  var helper = viewController.getPlaneHelper();
15131
- var orientedNewScale = helper.getTargetOrientedXYZ(newScale);
15162
+ var orientedNewScale = helper.getTargetOrientedPositiveXYZ(newScale);
15132
15163
  var finalNewScale = {
15133
15164
  x: fitScale.x * orientedNewScale.x,
15134
15165
  y: fitScale.y * orientedNewScale.y
@@ -15263,6 +15294,14 @@ dwv.gui.ViewLayer = function (containerDiv) {
15263
15294
  };
15264
15295
  };
15265
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
+
15266
15305
  /**
15267
15306
  * Get a main plane position from a display position.
15268
15307
  *
@@ -17009,7 +17048,7 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17009
17048
  * @returns {dwv.math.Point3D} The object origin.
17010
17049
  */
17011
17050
  this.getOrigin = function () {
17012
- return origins[origins.length - 1];
17051
+ return origins[0];
17013
17052
  };
17014
17053
  /**
17015
17054
  * Get the object origins.
@@ -17048,7 +17087,7 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17048
17087
  this.getSize = function (viewOrientation) {
17049
17088
  var res = size;
17050
17089
  if (viewOrientation && typeof viewOrientation !== 'undefined') {
17051
- var values = dwv.math.getOrientedArray3D(
17090
+ var values = dwv.image.getPositiveOrientedArray3D(
17052
17091
  [
17053
17092
  size.get(0),
17054
17093
  size.get(1),
@@ -17093,7 +17132,7 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17093
17132
  }
17094
17133
  var res = spacing;
17095
17134
  if (viewOrientation && typeof viewOrientation !== 'undefined') {
17096
- var orientedValues = dwv.math.getOrientedArray3D(
17135
+ var orientedValues = dwv.image.getPositiveOrientedArray3D(
17097
17136
  [
17098
17137
  spacing.get(0),
17099
17138
  spacing.get(1),
@@ -17170,13 +17209,8 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17170
17209
  // -> >0 => vectors are codirectional
17171
17210
  // -> <0 => vectors are opposite
17172
17211
  var dotProd = normal.dotProduct(pointDir);
17173
- var test = dotProd < 0;
17174
- // TODO: check why coronal behaves differently...
17175
- if (orientation.getThirdColMajorDirection() === 1) {
17176
- test = dotProd > 0;
17177
- }
17178
17212
  // oposite vectors get higher index
17179
- var sliceIndex = test ? closestSliceIndex + 1 : closestSliceIndex;
17213
+ var sliceIndex = dotProd > 0 ? closestSliceIndex + 1 : closestSliceIndex;
17180
17214
  return sliceIndex;
17181
17215
  };
17182
17216
 
@@ -17272,17 +17306,6 @@ dwv.image.Geometry.prototype.isIndexInBounds = function (index, dirs) {
17272
17306
  return this.getSize().isInBounds(index, dirs);
17273
17307
  };
17274
17308
 
17275
- /**
17276
- * Flip the K index.
17277
- *
17278
- * @param {dwv.image.Size} size The image size.
17279
- * @param {number} k The index.
17280
- * @returns {number} The flipped index.
17281
- */
17282
- function flipK(size, k) {
17283
- return (size.get(2) - 1) - k;
17284
- }
17285
-
17286
17309
  /**
17287
17310
  * Convert an index into world coordinates.
17288
17311
  *
@@ -17290,15 +17313,13 @@ function flipK(size, k) {
17290
17313
  * @returns {dwv.math.Point} The corresponding point.
17291
17314
  */
17292
17315
  dwv.image.Geometry.prototype.indexToWorld = function (index) {
17293
- // flip K index (because of the slice order given by getSliceIndex)
17294
- var k = flipK(this.getSize(), index.get(2));
17295
17316
  // apply spacing
17296
17317
  // (spacing is oriented, apply before orientation)
17297
17318
  var spacing = this.getSpacing();
17298
17319
  var orientedPoint3D = new dwv.math.Point3D(
17299
17320
  index.get(0) * spacing.get(0),
17300
17321
  index.get(1) * spacing.get(1),
17301
- k * spacing.get(2)
17322
+ index.get(2) * spacing.get(2)
17302
17323
  );
17303
17324
  // de-orient
17304
17325
  var point3D = this.getOrientation().multiplyPoint3D(orientedPoint3D);
@@ -17319,15 +17340,13 @@ dwv.image.Geometry.prototype.indexToWorld = function (index) {
17319
17340
  * @returns {dwv.math.Point3D} The corresponding world 3D point.
17320
17341
  */
17321
17342
  dwv.image.Geometry.prototype.pointToWorld = function (point) {
17322
- // flip K index (because of the slice order given by getSliceIndex)
17323
- var k = flipK(this.getSize(), point.getZ());
17324
17343
  // apply spacing
17325
17344
  // (spacing is oriented, apply before orientation)
17326
17345
  var spacing = this.getSpacing();
17327
17346
  var orientedPoint3D = new dwv.math.Point3D(
17328
17347
  point.getX() * spacing.get(0),
17329
17348
  point.getY() * spacing.get(1),
17330
- k * spacing.get(2)
17349
+ point.getZ() * spacing.get(2)
17331
17350
  );
17332
17351
  // de-orient
17333
17352
  var point3D = this.getOrientation().multiplyPoint3D(orientedPoint3D);
@@ -17365,16 +17384,50 @@ dwv.image.Geometry.prototype.worldToIndex = function (point) {
17365
17384
  var spacing = this.getSpacing();
17366
17385
  values[0] = Math.round(orientedPoint3D.getX() / spacing.get(0));
17367
17386
  values[1] = Math.round(orientedPoint3D.getY() / spacing.get(1));
17368
- // flip K index (because of the slice order given by getSliceIndex)
17369
- var k = Math.round(orientedPoint3D.getZ() / spacing.get(2));
17370
- // abs to fix #1163
17371
- // TODO: find out why k can sometimes be negative...
17372
- values[2] = flipK(this.getSize(), k);
17387
+ values[2] = Math.round(orientedPoint3D.getZ() / spacing.get(2));
17373
17388
 
17374
17389
  // return index
17375
17390
  return new dwv.math.Index(values);
17376
17391
  };
17377
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
+
17378
17431
  /**
17379
17432
  * Get the slice spacing from the difference in the Z directions
17380
17433
  * of input origins.
@@ -18712,6 +18765,11 @@ dwv.image.ImageFactory.prototype.create = function (
18712
18765
  };
18713
18766
  // PixelRepresentation -> is signed
18714
18767
  meta.IsSigned = meta.PixelRepresentation === 1;
18768
+ // local pixel unit
18769
+ var pixelUnit = dicomElements.getPixelUnit();
18770
+ if (pixelUnit) {
18771
+ meta.pixelUnit = pixelUnit;
18772
+ }
18715
18773
  // FrameOfReferenceUID (optional)
18716
18774
  var frameOfReferenceUID = dicomElements.getFromKey('x00200052');
18717
18775
  if (frameOfReferenceUID) {
@@ -20652,6 +20710,8 @@ dwv.image.PlaneHelper = function (spacing, imageOrientation, viewOrientation) {
20652
20710
 
20653
20711
  /**
20654
20712
  * Orient an input vector from target to image space.
20713
+ * WARN: returns absolute values...
20714
+ * TODO: check why abs is needed...
20655
20715
  *
20656
20716
  * @param {dwv.math.Vector3D} planeVector The input vector.
20657
20717
  * @returns {dwv.math.Vector3D} The orienteded vector.
@@ -20659,21 +20719,61 @@ dwv.image.PlaneHelper = function (spacing, imageOrientation, viewOrientation) {
20659
20719
  this.getImageOrientedVector3D = function (planeVector) {
20660
20720
  var vector = planeVector;
20661
20721
  if (typeof viewOrientation !== 'undefined') {
20662
- // abs? otherwise negative index...
20663
- // vector = viewOrientation * planePoint
20664
- 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
+ );
20665
20735
  }
20666
20736
  return vector;
20667
20737
  };
20668
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
+
20669
20767
  /**
20670
20768
  * Reorder values to follow target orientation.
20769
+ * WARN: returns absolute values...
20770
+ * TODO: check why abs is needed...
20671
20771
  *
20672
20772
  * @param {object} values Values as {x,y,z}.
20673
20773
  * @returns {object} Reoriented values as {x,y,z}.
20674
20774
  */
20675
- this.getTargetOrientedXYZ = function (values) {
20676
- var orientedValues = dwv.math.getOrientedArray3D(
20775
+ this.getTargetOrientedPositiveXYZ = function (values) {
20776
+ var orientedValues = dwv.image.getPositiveOrientedArray3D(
20677
20777
  [
20678
20778
  values.x,
20679
20779
  values.y,
@@ -27279,32 +27379,6 @@ dwv.math.getMatrixFromName = function (name) {
27279
27379
  return matrix;
27280
27380
  };
27281
27381
 
27282
- /**
27283
- * Get the oriented values of an input 3D array.
27284
- *
27285
- * @param {Array} array3D The 3D array.
27286
- * @param {dwv.math.Matrix33} orientation The orientation 3D matrix.
27287
- * @returns {Array} The values reordered according to the orientation.
27288
- */
27289
- dwv.math.getOrientedArray3D = function (array3D, orientation) {
27290
- // values = orientation * orientedValues
27291
- // -> inv(orientation) * values = orientedValues
27292
- return orientation.getInverse().getAbs().multiplyArray3D(array3D);
27293
- };
27294
-
27295
- /**
27296
- * Get the raw values of an oriented input 3D array.
27297
- *
27298
- * @param {Array} array3D The 3D array.
27299
- * @param {dwv.math.Matrix33} orientation The orientation 3D matrix.
27300
- * @returns {Array} The values reordered to compensate the orientation.
27301
- */
27302
- dwv.math.getDeOrientedArray3D = function (array3D, orientation) {
27303
- // values = orientation * orientedValues
27304
- // -> inv(orientation) * values = orientedValues
27305
- return orientation.getAbs().multiplyArray3D(array3D);
27306
- };
27307
-
27308
27382
  // namespaces
27309
27383
  var dwv = dwv || {};
27310
27384
  dwv.math = dwv.math || {};
@@ -29808,7 +29882,7 @@ dwv.tool.Draw = function (app) {
29808
29882
  }
29809
29883
 
29810
29884
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
29811
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
29885
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
29812
29886
  var drawLayer = layerGroup.getActiveDrawLayer();
29813
29887
 
29814
29888
  // determine if the click happened in an existing shape
@@ -29865,7 +29939,7 @@ dwv.tool.Draw = function (app) {
29865
29939
  }
29866
29940
 
29867
29941
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
29868
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
29942
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
29869
29943
  var viewLayer = layerGroup.getActiveViewLayer();
29870
29944
  var pos = viewLayer.displayToPlanePos(event._x, event._y);
29871
29945
 
@@ -29909,7 +29983,7 @@ dwv.tool.Draw = function (app) {
29909
29983
  if (points.length === currentFactory.getNPoints()) {
29910
29984
  // store points
29911
29985
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
29912
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
29986
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
29913
29987
  onFinalPoints(points, layerGroup);
29914
29988
  // reset flag
29915
29989
  started = false;
@@ -29943,7 +30017,7 @@ dwv.tool.Draw = function (app) {
29943
30017
 
29944
30018
  // store points
29945
30019
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
29946
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
30020
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
29947
30021
  onFinalPoints(points, layerGroup);
29948
30022
  // reset flag
29949
30023
  started = false;
@@ -29979,7 +30053,7 @@ dwv.tool.Draw = function (app) {
29979
30053
  }
29980
30054
 
29981
30055
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
29982
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
30056
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
29983
30057
  var viewLayer = layerGroup.getActiveViewLayer();
29984
30058
  var pos = viewLayer.displayToPlanePos(event._x, event._y);
29985
30059
 
@@ -30452,6 +30526,16 @@ dwv.tool.Draw = function (app) {
30452
30526
  shapeEditor.setFactoryList(options);
30453
30527
  };
30454
30528
 
30529
+ /**
30530
+ * Get the type of tool options: here 'factory' since the shape
30531
+ * list contains factories to create each possible shape.
30532
+ *
30533
+ * @returns {string} The type.
30534
+ */
30535
+ this.getOptionsType = function () {
30536
+ return 'factory';
30537
+ };
30538
+
30455
30539
  /**
30456
30540
  * Set the tool live features: shape colour and shape name.
30457
30541
  *
@@ -30477,6 +30561,15 @@ dwv.tool.Draw = function (app) {
30477
30561
  // does nothing
30478
30562
  };
30479
30563
 
30564
+ /**
30565
+ * Get the list of event names that this tool can fire.
30566
+ *
30567
+ * @returns {Array} The list of event names.
30568
+ */
30569
+ this.getEventNames = function () {
30570
+ return ['drawcreate', 'drawchange', 'drawmove', 'drawdelete'];
30571
+ };
30572
+
30480
30573
  /**
30481
30574
  * Add an event listener on the app.
30482
30575
  *
@@ -31340,7 +31433,7 @@ dwv.tool.ShapeEditor = function (app) {
31340
31433
  // drag move listener
31341
31434
  anchor.on('dragmove.edit', function (evt) {
31342
31435
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(evt.evt);
31343
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
31436
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
31344
31437
  var drawLayer = layerGroup.getActiveDrawLayer();
31345
31438
  // validate the anchor position
31346
31439
  dwv.tool.validateAnchorPosition(drawLayer.getBaseSize(), this);
@@ -31846,6 +31939,16 @@ dwv.tool.Filter = function (app) {
31846
31939
  }
31847
31940
  };
31848
31941
 
31942
+ /**
31943
+ * Get the type of tool options: here 'instance' since the filter
31944
+ * list contains instances of each possible filter.
31945
+ *
31946
+ * @returns {string} The type.
31947
+ */
31948
+ this.getOptionsType = function () {
31949
+ return 'instance';
31950
+ };
31951
+
31849
31952
  /**
31850
31953
  * Initialise the filter. Called once the image is loaded.
31851
31954
  */
@@ -31866,6 +31969,15 @@ dwv.tool.Filter = function (app) {
31866
31969
  app.onKeydown(event);
31867
31970
  };
31868
31971
 
31972
+ /**
31973
+ * Get the list of event names that this tool can fire.
31974
+ *
31975
+ * @returns {Array} The list of event names.
31976
+ */
31977
+ this.getEventNames = function () {
31978
+ return ['filterrun', 'filterundo'];
31979
+ };
31980
+
31869
31981
  /**
31870
31982
  * Add an event listener to this class.
31871
31983
  *
@@ -32486,7 +32598,7 @@ dwv.tool.Floodfill = function (app) {
32486
32598
  */
32487
32599
  var getCoord = function (event) {
32488
32600
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
32489
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
32601
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
32490
32602
  var viewLayer = layerGroup.getActiveViewLayer();
32491
32603
  var index = viewLayer.displayToPlaneIndex(event._x, event._y);
32492
32604
  return {
@@ -32674,7 +32786,7 @@ dwv.tool.Floodfill = function (app) {
32674
32786
  */
32675
32787
  this.mousedown = function (event) {
32676
32788
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
32677
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
32789
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
32678
32790
  var viewLayer = layerGroup.getActiveViewLayer();
32679
32791
  var drawLayer = layerGroup.getActiveDrawLayer();
32680
32792
 
@@ -32721,7 +32833,7 @@ dwv.tool.Floodfill = function (app) {
32721
32833
  self.started = false;
32722
32834
  if (extender) {
32723
32835
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
32724
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
32836
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
32725
32837
  self.extend(layerGroup);
32726
32838
  }
32727
32839
  };
@@ -32796,6 +32908,15 @@ dwv.tool.Floodfill = function (app) {
32796
32908
  // does nothing
32797
32909
  };
32798
32910
 
32911
+ /**
32912
+ * Get the list of event names that this tool can fire.
32913
+ *
32914
+ * @returns {Array} The list of event names.
32915
+ */
32916
+ this.getEventNames = function () {
32917
+ return ['drawcreate', 'drawchange', 'drawmove', 'drawdelete'];
32918
+ };
32919
+
32799
32920
  /**
32800
32921
  * Add an event listener to this class.
32801
32922
  *
@@ -33176,7 +33297,7 @@ dwv.tool.Livewire = function (app) {
33176
33297
  */
33177
33298
  this.mousedown = function (event) {
33178
33299
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
33179
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
33300
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
33180
33301
  var viewLayer = layerGroup.getActiveViewLayer();
33181
33302
  var imageSize = viewLayer.getViewController().getImageSize();
33182
33303
  var index = viewLayer.displayToPlaneIndex(event._x, event._y);
@@ -33237,7 +33358,7 @@ dwv.tool.Livewire = function (app) {
33237
33358
  return;
33238
33359
  }
33239
33360
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
33240
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
33361
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
33241
33362
  var viewLayer = layerGroup.getActiveViewLayer();
33242
33363
  var index = viewLayer.displayToPlaneIndex(event._x, event._y);
33243
33364
 
@@ -33409,6 +33530,15 @@ dwv.tool.Livewire = function (app) {
33409
33530
  // does nothing
33410
33531
  };
33411
33532
 
33533
+ /**
33534
+ * Get the list of event names that this tool can fire.
33535
+ *
33536
+ * @returns {Array} The list of event names.
33537
+ */
33538
+ this.getEventNames = function () {
33539
+ return ['drawcreate', 'drawchange', 'drawmove', 'drawdelete'];
33540
+ };
33541
+
33412
33542
  /**
33413
33543
  * Add an event listener to this class.
33414
33544
  *
@@ -33464,7 +33594,6 @@ dwv.tool.Livewire.prototype.setFeatures = function (features) {
33464
33594
  }
33465
33595
  };
33466
33596
 
33467
-
33468
33597
  // namespaces
33469
33598
  var dwv = dwv || {};
33470
33599
  dwv.tool = dwv.tool || {};
@@ -33519,7 +33648,7 @@ dwv.tool.Opacity = function (app) {
33519
33648
  // do not trigger for small moves
33520
33649
  if (xMove) {
33521
33650
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
33522
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
33651
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
33523
33652
  var viewLayer = layerGroup.getActiveViewLayer();
33524
33653
  var op = viewLayer.getOpacity();
33525
33654
  viewLayer.setOpacity(op + (diffX / 200));
@@ -34831,7 +34960,7 @@ dwv.tool = dwv.tool || {};
34831
34960
  * document.body.appendChild(range);
34832
34961
  * // update app on slider change
34833
34962
  * range.oninput = function () {
34834
- * var lg = app.getLayerGroupById(0);
34963
+ * var lg = app.getLayerGroupByDivId('layerGroup0');
34835
34964
  * var vc = lg.getActiveViewLayer().getViewController();
34836
34965
  * var index = vc.getCurrentIndex();
34837
34966
  * var values = index.getValues();
@@ -34846,7 +34975,7 @@ dwv.tool = dwv.tool || {};
34846
34975
  * });
34847
34976
  * // update slider on slice change (for ex via mouse wheel)
34848
34977
  * app.addEventListener('positionchange', function () {
34849
- * var lg = app.getLayerGroupById(0);
34978
+ * var lg = app.getLayerGroupByDivId('layerGroup0');
34850
34979
  * var vc = lg.getActiveViewLayer().getViewController();
34851
34980
  * range.value = vc.getCurrentIndex().get(2);
34852
34981
  * });
@@ -34881,15 +35010,25 @@ dwv.tool.Scroll = function (app) {
34881
35010
  */
34882
35011
  var wheelDeltaY = 0;
34883
35012
 
35013
+ /**
35014
+ * Option to show or not a value tooltip on mousemove.
35015
+ *
35016
+ * @type {boolean}
35017
+ */
35018
+ var displayTooltip = false;
35019
+
34884
35020
  /**
34885
35021
  * Handle mouse down event.
34886
35022
  *
34887
35023
  * @param {object} event The mouse down event.
34888
35024
  */
34889
35025
  this.mousedown = function (event) {
35026
+ // optional tooltip
35027
+ removeTooltipDiv();
35028
+
34890
35029
  // stop viewer if playing
34891
35030
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
34892
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35031
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
34893
35032
  var viewLayer = layerGroup.getActiveViewLayer();
34894
35033
  var viewController = viewLayer.getViewController();
34895
35034
  if (viewController.isPlaying()) {
@@ -34903,7 +35042,9 @@ dwv.tool.Scroll = function (app) {
34903
35042
 
34904
35043
  // update controller position
34905
35044
  var planePos = viewLayer.displayToPlanePos(event._x, event._y);
34906
- viewController.setCurrentPosition2D(planePos.x, planePos.y);
35045
+ var position = viewController.getPositionFromPlanePoint(
35046
+ planePos.x, planePos.y);
35047
+ viewController.setCurrentPosition(position);
34907
35048
  };
34908
35049
 
34909
35050
  /**
@@ -34913,11 +35054,15 @@ dwv.tool.Scroll = function (app) {
34913
35054
  */
34914
35055
  this.mousemove = function (event) {
34915
35056
  if (!self.started) {
35057
+ // optional tooltip
35058
+ if (displayTooltip) {
35059
+ showTooltip(event);
35060
+ }
34916
35061
  return;
34917
35062
  }
34918
35063
 
34919
35064
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
34920
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35065
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
34921
35066
  var viewLayer = layerGroup.getActiveViewLayer();
34922
35067
  var viewController = viewLayer.getViewController();
34923
35068
 
@@ -34976,6 +35121,8 @@ dwv.tool.Scroll = function (app) {
34976
35121
  */
34977
35122
  this.mouseout = function (event) {
34978
35123
  self.mouseup(event);
35124
+ // remove possible tooltip div
35125
+ removeTooltipDiv();
34979
35126
  };
34980
35127
 
34981
35128
  /**
@@ -35048,7 +35195,7 @@ dwv.tool.Scroll = function (app) {
35048
35195
  }
35049
35196
 
35050
35197
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35051
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35198
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35052
35199
  var viewController =
35053
35200
  layerGroup.getActiveViewLayer().getViewController();
35054
35201
  if (up) {
@@ -35067,6 +35214,7 @@ dwv.tool.Scroll = function (app) {
35067
35214
  event.context = 'dwv.tool.Scroll';
35068
35215
  app.onKeydown(event);
35069
35216
  };
35217
+
35070
35218
  /**
35071
35219
  * Handle double click.
35072
35220
  *
@@ -35074,19 +35222,81 @@ dwv.tool.Scroll = function (app) {
35074
35222
  */
35075
35223
  this.dblclick = function (event) {
35076
35224
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35077
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35225
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35078
35226
  var viewController =
35079
35227
  layerGroup.getActiveViewLayer().getViewController();
35080
35228
  viewController.play();
35081
35229
  };
35082
35230
 
35231
+ /**
35232
+ * Displays a tooltip in a temparary `span`.
35233
+ * Works with css to hide/show the span only on mouse hover.
35234
+ *
35235
+ * @param {object} event The mouse move event.
35236
+ */
35237
+ function showTooltip(event) {
35238
+ // remove previous div
35239
+ removeTooltipDiv();
35240
+
35241
+ // get image value at position
35242
+ var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35243
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35244
+ var viewLayer = layerGroup.getActiveViewLayer();
35245
+ var viewController = viewLayer.getViewController();
35246
+ var planePos = viewLayer.displayToPlanePos(event._x, event._y);
35247
+ var position = viewController.getPositionFromPlanePoint(
35248
+ planePos.x, planePos.y);
35249
+ var value = viewController.getRescaledImageValue(position);
35250
+
35251
+ // create
35252
+ if (typeof value !== 'undefined') {
35253
+ var span = document.createElement('span');
35254
+ span.id = 'scroll-tooltip';
35255
+ // place span in layer group to avoid upper layer opacity
35256
+ var layerDiv = document.getElementById(viewLayer.getId());
35257
+ layerDiv.parentElement.appendChild(span);
35258
+ // position tooltip
35259
+ span.style.left = (event._x + 10) + 'px';
35260
+ span.style.top = (event._y + 10) + 'px';
35261
+ var text = dwv.utils.precisionRound(value, 3);
35262
+ if (typeof viewController.getPixelUnit() !== 'undefined') {
35263
+ text += ' ' + viewController.getPixelUnit();
35264
+ }
35265
+ span.appendChild(document.createTextNode(text));
35266
+ }
35267
+ }
35268
+
35269
+ /**
35270
+ * Remove the tooltip html div.
35271
+ */
35272
+ function removeTooltipDiv() {
35273
+ var div = document.getElementById('scroll-tooltip');
35274
+ if (div) {
35275
+ div.remove();
35276
+ }
35277
+ }
35278
+
35083
35279
  /**
35084
35280
  * Activate the tool.
35085
35281
  *
35086
35282
  * @param {boolean} _bool The flag to activate or not.
35087
35283
  */
35088
35284
  this.activate = function (_bool) {
35089
- // does nothing
35285
+ // remove tooltip html when deactivating
35286
+ if (!_bool) {
35287
+ removeTooltipDiv();
35288
+ }
35289
+ };
35290
+
35291
+ /**
35292
+ * Set the tool live features: disaply tooltip.
35293
+ *
35294
+ * @param {object} features The list of features.
35295
+ */
35296
+ this.setFeatures = function (features) {
35297
+ if (typeof features.displayTooltip !== 'undefined') {
35298
+ displayTooltip = features.displayTooltip;
35299
+ }
35090
35300
  };
35091
35301
 
35092
35302
  /**
@@ -35321,7 +35531,7 @@ dwv.tool.WindowLevel = function (app) {
35321
35531
  }
35322
35532
 
35323
35533
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35324
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35534
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35325
35535
  var viewController =
35326
35536
  layerGroup.getActiveViewLayer().getViewController();
35327
35537
 
@@ -35411,7 +35621,7 @@ dwv.tool.WindowLevel = function (app) {
35411
35621
  */
35412
35622
  this.dblclick = function (event) {
35413
35623
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35414
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35624
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35415
35625
  var viewLayer = layerGroup.getActiveViewLayer();
35416
35626
  var index = viewLayer.displayToPlaneIndex(event._x, event._y);
35417
35627
  var viewController = viewLayer.getViewController();
@@ -35543,7 +35753,7 @@ dwv.tool.ZoomAndPan = function (app) {
35543
35753
  var ty = event._y - self.y0;
35544
35754
  // apply translation
35545
35755
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35546
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35756
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35547
35757
  var viewLayer = layerGroup.getActiveViewLayer();
35548
35758
  var viewController = viewLayer.getViewController();
35549
35759
  var planeOffset = viewLayer.displayToPlaneScale(tx, ty);
@@ -35574,7 +35784,7 @@ dwv.tool.ZoomAndPan = function (app) {
35574
35784
  var lineRatio = newLine.getLength() / self.line0.getLength();
35575
35785
 
35576
35786
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35577
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35787
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35578
35788
  var viewLayer = layerGroup.getActiveViewLayer();
35579
35789
  var viewController = viewLayer.getViewController();
35580
35790
 
@@ -35675,7 +35885,7 @@ dwv.tool.ZoomAndPan = function (app) {
35675
35885
  var step = -event.deltaY / 500;
35676
35886
 
35677
35887
  var layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
35678
- var layerGroup = app.getLayerGroupById(layerDetails.groupId);
35888
+ var layerGroup = app.getLayerGroupByDivId(layerDetails.groupDivId);
35679
35889
  var viewLayer = layerGroup.getActiveViewLayer();
35680
35890
  var viewController = viewLayer.getViewController();
35681
35891
  var planePos = viewLayer.displayToMainPlanePos(event._x, event._y);
@@ -38283,6 +38493,23 @@ dwv.utils.stringToUint8Array = function (str) {
38283
38493
  return arr;
38284
38494
  };
38285
38495
 
38496
+ /**
38497
+ * Round a float number to a given precision.
38498
+ * Inspired from https://stackoverflow.com/a/49729715/3639892.
38499
+ * Can be a solution to not have trailing zero as when
38500
+ * using toFixed or toPrecision.
38501
+ * '+number.toFixed(precision)' does not pass all the tests...
38502
+ *
38503
+ * @param {number} number The number to round.
38504
+ * @param {number} precision The rounding precision.
38505
+ * @returns {number} The rounded number.
38506
+ */
38507
+ dwv.utils.precisionRound = function (number, precision) {
38508
+ var factor = Math.pow(10, precision);
38509
+ var delta = 0.01 / factor; // fixes precisionRound(1.005, 2)
38510
+ return Math.round(number * factor + delta) / factor;
38511
+ };
38512
+
38286
38513
  // namespaces
38287
38514
  var dwv = dwv || {};
38288
38515
  dwv.utils = dwv.utils || {};