dwv 0.31.0-beta.15 → 0.31.0-beta.17

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.15 2022-10-28 12:46:58 */
1
+ /*! dwv 0.31.0-beta.17 2022-11-17 16:14:43 */
2
2
  // Inspired from umdjs
3
3
  // See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
4
4
  (function (root, factory) {
@@ -322,6 +322,17 @@ dwv.App = function () {
322
322
  return stage.getLayerGroup(groupId);
323
323
  };
324
324
 
325
+ /**
326
+ * Get a layer group by div id.
327
+ * The layer is available after the first loaded item.
328
+ *
329
+ * @param {string} divId The div id.
330
+ * @returns {dwv.gui.LayerGroup} The layer group.
331
+ */
332
+ this.getLayerGroupByDivId = function (divId) {
333
+ return stage.getLayerGroupByDivId(divId);
334
+ };
335
+
325
336
  /**
326
337
  * Get the number of layer groups.
327
338
  *
@@ -743,7 +754,7 @@ dwv.App = function () {
743
754
  for (var i = 0; i < viewConfigs.length; ++i) {
744
755
  var config = viewConfigs[i];
745
756
  var layerGroup =
746
- stage.getLayerGroupWithElementId(config.divId);
757
+ stage.getLayerGroupByDivId(config.divId);
747
758
  // layer group must exist
748
759
  if (!layerGroup) {
749
760
  throw new Error('No layer group for ' + config.divId);
@@ -1325,7 +1336,7 @@ dwv.App = function () {
1325
1336
  if (!data) {
1326
1337
  throw new Error('Cannot initialise layer with data id: ' + dataIndex);
1327
1338
  }
1328
- var layerGroup = stage.getLayerGroupWithElementId(dataViewConfig.divId);
1339
+ var layerGroup = stage.getLayerGroupByDivId(dataViewConfig.divId);
1329
1340
  if (!layerGroup) {
1330
1341
  throw new Error('Cannot initialise layer with group id: ' +
1331
1342
  dataViewConfig.divId);
@@ -4591,7 +4602,7 @@ dwv.dicom = dwv.dicom || {};
4591
4602
  * @returns {string} The version of the library.
4592
4603
  */
4593
4604
  dwv.getVersion = function () {
4594
- return '0.31.0-beta.15';
4605
+ return '0.31.0-beta.17';
4595
4606
  };
4596
4607
 
4597
4608
  /**
@@ -4734,6 +4745,27 @@ dwv.dicom.getReverseOrientation = function (ori) {
4734
4745
  return rori;
4735
4746
  };
4736
4747
 
4748
+ /**
4749
+ * Get the name of an image orientation patient.
4750
+ *
4751
+ * @param {Array} orientation The image orientation patient.
4752
+ * @returns {string} The orientation name: axial, coronal or sagittal.
4753
+ */
4754
+ dwv.dicom.getOrientationName = function (orientation) {
4755
+ var axialOrientation = [1, 0, 0, 0, 1, 0];
4756
+ var coronalOrientation = [1, 0, 0, 0, 0, -1];
4757
+ var sagittalOrientation = [0, 1, 0, 0, 0, -1];
4758
+ var name;
4759
+ if (dwv.utils.arrayEquals(orientation, axialOrientation)) {
4760
+ name = 'axial';
4761
+ } else if (dwv.utils.arrayEquals(orientation, coronalOrientation)) {
4762
+ name = 'coronal';
4763
+ } else if (dwv.utils.arrayEquals(orientation, sagittalOrientation)) {
4764
+ name = 'sagittal';
4765
+ }
4766
+ return name;
4767
+ };
4768
+
4737
4769
  /**
4738
4770
  * Tell if a given syntax is an implicit one (element with no VR).
4739
4771
  *
@@ -5697,25 +5729,28 @@ dwv.dicom.DicomParser.prototype.parse = function (buffer) {
5697
5729
  //-------------------------------------------------
5698
5730
  // values needed for data interpretation
5699
5731
 
5700
- // PixelRepresentation 0->unsigned, 1->signed
5701
- var pixelRepresentation = 0;
5702
- dataElement = this.dicomElements.x00280103;
5703
- if (typeof dataElement !== 'undefined') {
5704
- dataElement.value = this.interpretElement(dataElement, dataReader);
5705
- pixelRepresentation = dataElement.value[0];
5706
- } else {
5707
- dwv.logger.warn(
5708
- 'Reading DICOM pixel data with default pixelRepresentation.');
5709
- }
5732
+ // pixel specific
5733
+ if (typeof this.dicomElements.x7FE00010 !== 'undefined') {
5734
+ // PixelRepresentation 0->unsigned, 1->signed
5735
+ var pixelRepresentation = 0;
5736
+ dataElement = this.dicomElements.x00280103;
5737
+ if (typeof dataElement !== 'undefined') {
5738
+ dataElement.value = this.interpretElement(dataElement, dataReader);
5739
+ pixelRepresentation = dataElement.value[0];
5740
+ } else {
5741
+ dwv.logger.warn(
5742
+ 'Reading DICOM pixel data with default pixelRepresentation.');
5743
+ }
5710
5744
 
5711
- // BitsAllocated
5712
- var bitsAllocated = 16;
5713
- dataElement = this.dicomElements.x00280100;
5714
- if (typeof dataElement !== 'undefined') {
5715
- dataElement.value = this.interpretElement(dataElement, dataReader);
5716
- bitsAllocated = dataElement.value[0];
5717
- } else {
5718
- dwv.logger.warn('Reading DICOM pixel data with default bitsAllocated.');
5745
+ // BitsAllocated
5746
+ var bitsAllocated = 16;
5747
+ dataElement = this.dicomElements.x00280100;
5748
+ if (typeof dataElement !== 'undefined') {
5749
+ dataElement.value = this.interpretElement(dataElement, dataReader);
5750
+ bitsAllocated = dataElement.value[0];
5751
+ } else {
5752
+ dwv.logger.warn('Reading DICOM pixel data with default bitsAllocated.');
5753
+ }
5719
5754
  }
5720
5755
 
5721
5756
  // default character set
@@ -6083,16 +6118,18 @@ dwv.dicom.isPixelDataTag = function (tag) {
6083
6118
  * Get a tag from the dictionary using a tag string name.
6084
6119
  *
6085
6120
  * @param {string} tagName The tag string name.
6086
- * @returns {object} The tag object.
6121
+ * @returns {object|null} The tag object or null if not found.
6087
6122
  */
6088
6123
  dwv.dicom.getTagFromDictionary = function (tagName) {
6124
+ if (typeof tagName === 'undefined' || tagName === null) {
6125
+ return null;
6126
+ }
6089
6127
  var group = null;
6090
6128
  var element = null;
6091
6129
  var dict = dwv.dicom.dictionary;
6092
6130
  var keys0 = Object.keys(dict);
6093
6131
  var keys1 = null;
6094
- // label for nested loop break
6095
- outLabel:
6132
+ var foundTag = false;
6096
6133
  // search through dictionary
6097
6134
  for (var k0 = 0, lenK0 = keys0.length; k0 < lenK0; ++k0) {
6098
6135
  group = keys0[k0];
@@ -6100,12 +6137,16 @@ dwv.dicom.getTagFromDictionary = function (tagName) {
6100
6137
  for (var k1 = 0, lenK1 = keys1.length; k1 < lenK1; ++k1) {
6101
6138
  element = keys1[k1];
6102
6139
  if (dict[group][element][2] === tagName) {
6103
- break outLabel;
6140
+ foundTag = true;
6141
+ break;
6104
6142
  }
6105
6143
  }
6144
+ if (foundTag) {
6145
+ break;
6146
+ }
6106
6147
  }
6107
6148
  var tag = null;
6108
- if (group !== null && element !== null) {
6149
+ if (foundTag) {
6109
6150
  tag = new dwv.dicom.Tag(group, element);
6110
6151
  }
6111
6152
  return tag;
@@ -6787,8 +6828,6 @@ dwv.dicom.DicomWriter.prototype.getBuffer = function (dicomElements) {
6787
6828
  var syntax = dwv.dicom.cleanString(dicomElements.x00020010.value[0]);
6788
6829
  var isImplicit = dwv.dicom.isImplicitTransferSyntax(syntax);
6789
6830
  var isBigEndian = dwv.dicom.isBigEndianTransferSyntax(syntax);
6790
- // Bits Allocated
6791
- var bitsAllocated = dicomElements.x00280100.value[0];
6792
6831
  // Specific CharacterSet
6793
6832
  if (typeof dicomElements.x00080005 !== 'undefined') {
6794
6833
  var oldscs = dwv.dicom.cleanString(dicomElements.x00080005.value[0]);
@@ -6799,6 +6838,11 @@ dwv.dicom.DicomWriter.prototype.getBuffer = function (dicomElements) {
6799
6838
  dicomElements.x00080005.value = ['ISO_IR 192'];
6800
6839
  }
6801
6840
  }
6841
+ // Bits Allocated (for image data)
6842
+ var bitsAllocated;
6843
+ if (typeof dicomElements.x00280100 !== 'undefined') {
6844
+ bitsAllocated = dicomElements.x00280100.value[0];
6845
+ }
6802
6846
 
6803
6847
  // calculate buffer size and split elements (meta and non meta)
6804
6848
  var totalSize = 128 + 4; // DICM
@@ -6808,7 +6852,10 @@ dwv.dicom.DicomWriter.prototype.getBuffer = function (dicomElements) {
6808
6852
  var element;
6809
6853
  var groupName;
6810
6854
  var metaLength = 0;
6855
+ // FileMetaInformationGroupLength
6811
6856
  var fmiglTag = dwv.dicom.getFileMetaInformationGroupLengthTag();
6857
+ // FileMetaInformationVersion
6858
+ var fmivTag = new dwv.dicom.Tag('0x0002', '0x0001');
6812
6859
  // ImplementationClassUID
6813
6860
  var icUIDTag = new dwv.dicom.Tag('0x0002', '0x0012');
6814
6861
  // ImplementationVersionName
@@ -6820,6 +6867,7 @@ dwv.dicom.DicomWriter.prototype.getBuffer = function (dicomElements) {
6820
6867
  element = this.getElementToWrite(dicomElements[keys[i]]);
6821
6868
  if (element !== null &&
6822
6869
  !fmiglTag.equals(element.tag) &&
6870
+ !fmivTag.equals(element.tag) &&
6823
6871
  !icUIDTag.equals(element.tag) &&
6824
6872
  !ivnTag.equals(element.tag)) {
6825
6873
  localSize = 0;
@@ -6862,9 +6910,16 @@ dwv.dicom.DicomWriter.prototype.getBuffer = function (dicomElements) {
6862
6910
  }
6863
6911
  }
6864
6912
 
6913
+ // FileMetaInformationVersion
6914
+ var fmiv = dwv.dicom.getDicomElement('FileMetaInformationVersion');
6915
+ var fmivSize = dwv.dicom.getDataElementPrefixByteSize(fmiv.vr, false);
6916
+ fmivSize += this.setElementValue(fmiv, [0, 1], false);
6917
+ metaElements.push(fmiv);
6918
+ metaLength += fmivSize;
6919
+ totalSize += fmivSize;
6865
6920
  // ImplementationClassUID
6866
6921
  var icUID = dwv.dicom.getDicomElement('ImplementationClassUID');
6867
- var icUIDSize = dwv.dicom.getDataElementPrefixByteSize(icUID.vr, isImplicit);
6922
+ var icUIDSize = dwv.dicom.getDataElementPrefixByteSize(icUID.vr, false);
6868
6923
  icUIDSize += this.setElementValue(
6869
6924
  icUID, [dwv.dicom.getUID('ImplementationClassUID')], false);
6870
6925
  metaElements.push(icUID);
@@ -6872,7 +6927,7 @@ dwv.dicom.DicomWriter.prototype.getBuffer = function (dicomElements) {
6872
6927
  totalSize += icUIDSize;
6873
6928
  // ImplementationVersionName
6874
6929
  var ivn = dwv.dicom.getDicomElement('ImplementationVersionName');
6875
- var ivnSize = dwv.dicom.getDataElementPrefixByteSize(ivn.vr, isImplicit);
6930
+ var ivnSize = dwv.dicom.getDataElementPrefixByteSize(ivn.vr, false);
6876
6931
  var ivnValue = 'DWV_' + dwv.getVersion();
6877
6932
  ivnSize += this.setElementValue(ivn, [ivnValue], false);
6878
6933
  metaElements.push(ivn);
@@ -6888,7 +6943,7 @@ dwv.dicom.DicomWriter.prototype.getBuffer = function (dicomElements) {
6888
6943
 
6889
6944
  // create the FileMetaInformationGroupLength element
6890
6945
  var fmigl = dwv.dicom.getDicomElement('FileMetaInformationGroupLength');
6891
- var fmiglSize = dwv.dicom.getDataElementPrefixByteSize(fmigl.vr, isImplicit);
6946
+ var fmiglSize = dwv.dicom.getDataElementPrefixByteSize(fmigl.vr, false);
6892
6947
  fmiglSize += this.setElementValue(
6893
6948
  fmigl, new Uint32Array([metaLength]), false);
6894
6949
  totalSize += fmiglSize;
@@ -7189,6 +7244,9 @@ dwv.dicom.getElementsFromJSONTags = function (jsonTags) {
7189
7244
  for (var k = 0, len = keys.length; k < len; ++k) {
7190
7245
  // get the DICOM element definition from its name
7191
7246
  var tag = dwv.dicom.getTagFromDictionary(keys[k]);
7247
+ if (!tag) {
7248
+ continue;
7249
+ }
7192
7250
  var vr = tag.getVrFromDictionary();
7193
7251
  // tag value
7194
7252
  var value;
@@ -13495,7 +13553,7 @@ dwv.gui.LayerGroup = function (containerDiv, groupId) {
13495
13553
  *
13496
13554
  * @returns {string} The id of the div.
13497
13555
  */
13498
- this.getElementId = function () {
13556
+ this.getDivId = function () {
13499
13557
  return containerDiv.id;
13500
13558
  };
13501
13559
 
@@ -14122,9 +14180,22 @@ dwv.gui.PositionBinder = function () {
14122
14180
  };
14123
14181
  this.getCallback = function (layerGroup) {
14124
14182
  return function (event) {
14125
- var pos = new dwv.math.Point(event.value[1]);
14183
+ var pointValues = event.value[1];
14126
14184
  var vc = layerGroup.getActiveViewLayer().getViewController();
14127
- vc.setCurrentPosition(pos);
14185
+ // handle different number of dimensions
14186
+ var currentPos = vc.getCurrentPosition();
14187
+ var currentDims = currentPos.length();
14188
+ var inputDims = pointValues.length;
14189
+ if (inputDims !== currentDims) {
14190
+ if (inputDims === currentDims - 1) {
14191
+ // add missing dim, for ex: input 3D -> current 4D
14192
+ pointValues.push(currentPos.get(currentDims - 1));
14193
+ } else if (inputDims === currentDims + 1) {
14194
+ // remove extra dim, for ex: input 4D -> current 3D
14195
+ pointValues.pop();
14196
+ }
14197
+ }
14198
+ vc.setCurrentPosition(new dwv.math.Point(pointValues));
14128
14199
  };
14129
14200
  };
14130
14201
  };
@@ -14287,9 +14358,9 @@ dwv.gui.Stage = function () {
14287
14358
  * @param {string} id The element id to find.
14288
14359
  * @returns {dwv.gui.LayerGroup} The layer group.
14289
14360
  */
14290
- this.getLayerGroupWithElementId = function (id) {
14361
+ this.getLayerGroupByDivId = function (id) {
14291
14362
  return layerGroups.find(function (item) {
14292
- return item.getElementId() === id;
14363
+ return item.getDivId() === id;
14293
14364
  });
14294
14365
  };
14295
14366
 
@@ -16953,11 +17024,13 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
16953
17024
  * Check if a point is in the origin list.
16954
17025
  *
16955
17026
  * @param {dwv.math.Point3D} point3D The point to check.
17027
+ * @param {number} tol The comparison tolerance
17028
+ * default to Number.EPSILON.
16956
17029
  * @returns {boolean} True if in list.
16957
17030
  */
16958
- this.includesOrigin = function (point3D) {
17031
+ this.includesOrigin = function (point3D, tol) {
16959
17032
  for (var i = 0; i < origins.length; ++i) {
16960
- if (origins[i].isSimilar(point3D, dwv.math.BIG_EPSILON)) {
17033
+ if (origins[i].isSimilar(point3D, tol)) {
16961
17034
  return true;
16962
17035
  }
16963
17036
  }
@@ -16988,52 +17061,21 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
16988
17061
  };
16989
17062
 
16990
17063
  /**
16991
- * Get the slice spacing from the difference in the Z directions
16992
- * of the origins.
16993
- *
16994
- * @returns {number} The spacing.
17064
+ * Calculate slice spacing from origins and replace current
17065
+ * if needed.
16995
17066
  */
16996
- this.getSliceGeometrySpacing = function () {
16997
- if (origins.length === 1) {
16998
- return 1;
16999
- }
17000
- var sliceSpacing = null;
17001
- // (x, y, z) = orientationMatrix * (i, j, k)
17002
- // -> inv(orientationMatrix) * (x, y, z) = (i, j, k)
17003
- // applied on the patient position, reorders indices
17004
- // so that Z is the slice direction
17005
- var invOrientation = orientation.getInverse();
17006
- var deltas = [];
17007
- for (var i = 0; i < origins.length - 1; ++i) {
17008
- var origin1 = invOrientation.multiplyVector3D(origins[i]);
17009
- var origin2 = invOrientation.multiplyVector3D(origins[i + 1]);
17010
- var diff = Math.abs(origin1.getZ() - origin2.getZ());
17011
- if (diff === 0) {
17012
- throw new Error('Zero slice spacing.' +
17013
- origin1.toString() + ' ' + origin2.toString());
17014
- }
17015
- if (sliceSpacing === null) {
17016
- sliceSpacing = diff;
17017
- } else {
17018
- if (!dwv.math.isSimilar(sliceSpacing, diff, dwv.math.BIG_EPSILON)) {
17019
- deltas.push(Math.abs(sliceSpacing - diff));
17020
- }
17021
- }
17022
- }
17023
- // warn if non constant
17024
- if (deltas.length !== 0) {
17025
- var sumReducer = function (sum, value) {
17026
- return sum + value;
17027
- };
17028
- var mean = deltas.reduce(sumReducer) / deltas.length;
17029
- if (mean > 1e-4) {
17030
- dwv.logger.warn('Varying slice spacing, mean delta: ' +
17031
- mean.toFixed(3) + ' (' + deltas.length + ' case(s))');
17032
- }
17067
+ function updateSliceSpacing() {
17068
+ var geoSliceSpacing = dwv.image.getSliceGeometrySpacing(
17069
+ origins, orientation);
17070
+ // update local if needed
17071
+ if (typeof geoSliceSpacing !== 'undefined' &&
17072
+ spacing.get(2) !== geoSliceSpacing) {
17073
+ dwv.logger.trace('Updating slice spacing.');
17074
+ var values = spacing.getValues();
17075
+ values[2] = geoSliceSpacing;
17076
+ spacing = new dwv.image.Spacing(values);
17033
17077
  }
17034
-
17035
- return sliceSpacing;
17036
- };
17078
+ }
17037
17079
 
17038
17080
  /**
17039
17081
  * Get the object spacing.
@@ -17046,9 +17088,7 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17046
17088
  this.getSpacing = function (viewOrientation) {
17047
17089
  // update slice spacing after appendSlice
17048
17090
  if (newOrigins) {
17049
- var values = spacing.getValues();
17050
- values[2] = this.getSliceGeometrySpacing();
17051
- spacing = new dwv.image.Spacing(values);
17091
+ updateSliceSpacing();
17052
17092
  newOrigins = false;
17053
17093
  }
17054
17094
  var res = spacing;
@@ -17122,13 +17162,13 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17122
17162
  var pointDir = point.minus(closestOrigin);
17123
17163
  // use third orientation matrix column as base plane vector
17124
17164
  var normal = new dwv.math.Vector3D(
17125
- orientation.get(2, 0), orientation.get(2, 1), orientation.get(2, 2));
17165
+ orientation.get(0, 2), orientation.get(1, 2), orientation.get(2, 2));
17126
17166
  // a.dot(b) = ||a|| * ||b|| * cos(theta)
17127
17167
  // (https://en.wikipedia.org/wiki/Dot_product#Geometric_definition)
17128
17168
  // -> the sign of the dot product depends on the cosinus of
17129
17169
  // the angle between the vectors
17130
17170
  // -> >0 => vectors are codirectional
17131
- // -> <0 => vectors are oposite
17171
+ // -> <0 => vectors are opposite
17132
17172
  var dotProd = normal.dotProduct(pointDir);
17133
17173
  var test = dotProd < 0;
17134
17174
  // TODO: check why coronal behaves differently...
@@ -17194,7 +17234,8 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
17194
17234
  dwv.image.Geometry.prototype.toString = function () {
17195
17235
  return 'Origin: ' + this.getOrigin() +
17196
17236
  ', Size: ' + this.getSize() +
17197
- ', Spacing: ' + this.getSpacing();
17237
+ ', Spacing: ' + this.getSpacing() +
17238
+ ', Orientation: ' + this.getOrientation();
17198
17239
  };
17199
17240
 
17200
17241
  /**
@@ -17334,6 +17375,66 @@ dwv.image.Geometry.prototype.worldToIndex = function (point) {
17334
17375
  return new dwv.math.Index(values);
17335
17376
  };
17336
17377
 
17378
+ /**
17379
+ * Get the slice spacing from the difference in the Z directions
17380
+ * of input origins.
17381
+ *
17382
+ * @param {Array} origins An array of dwv.math.Point3D.
17383
+ * @param {dwv.math.Matrix} orientation The oritentation matrix.
17384
+ * @param {boolean} withCheck Flag to activate spacing variation check,
17385
+ * default to true.
17386
+ * @returns {number|undefined} The spacing.
17387
+ */
17388
+ dwv.image.getSliceGeometrySpacing = function (origins, orientation, withCheck) {
17389
+ if (typeof withCheck === 'undefined') {
17390
+ withCheck = true;
17391
+ }
17392
+ // check origins
17393
+ if (origins.length <= 1) {
17394
+ return;
17395
+ }
17396
+ // (x, y, z) = orientationMatrix * (i, j, k)
17397
+ // -> inv(orientationMatrix) * (x, y, z) = (i, j, k)
17398
+ // applied on the patient position, reorders indices
17399
+ // so that Z is the slice direction
17400
+ var invOrientation = orientation.getInverse();
17401
+ var origin1 = invOrientation.multiplyVector3D(origins[0]);
17402
+ var origin2 = invOrientation.multiplyVector3D(origins[1]);
17403
+ var sliceSpacing = Math.abs(origin1.getZ() - origin2.getZ());
17404
+ var deltas = [];
17405
+ for (var i = 0; i < origins.length - 1; ++i) {
17406
+ origin1 = invOrientation.multiplyVector3D(origins[i]);
17407
+ origin2 = invOrientation.multiplyVector3D(origins[i + 1]);
17408
+ var diff = Math.abs(origin1.getZ() - origin2.getZ());
17409
+ if (diff === 0) {
17410
+ throw new Error('Zero slice spacing.' +
17411
+ origin1.toString() + ' ' + origin2.toString());
17412
+ }
17413
+ // keep smallest
17414
+ if (diff < sliceSpacing) {
17415
+ sliceSpacing = diff;
17416
+ }
17417
+ if (withCheck) {
17418
+ if (!dwv.math.isSimilar(sliceSpacing, diff, dwv.math.BIG_EPSILON)) {
17419
+ deltas.push(Math.abs(sliceSpacing - diff));
17420
+ }
17421
+ }
17422
+ }
17423
+ // warn if non constant
17424
+ if (withCheck && deltas.length !== 0) {
17425
+ var sumReducer = function (sum, value) {
17426
+ return sum + value;
17427
+ };
17428
+ var mean = deltas.reduce(sumReducer) / deltas.length;
17429
+ if (mean > 1e-4) {
17430
+ dwv.logger.warn('Varying slice spacing, mean delta: ' +
17431
+ mean.toFixed(3) + ' (' + deltas.length + ' case(s))');
17432
+ }
17433
+ }
17434
+
17435
+ return sliceSpacing;
17436
+ };
17437
+
17337
17438
  // namespaces
17338
17439
  var dwv = dwv || {};
17339
17440
  /** @namespace */
@@ -19604,24 +19705,19 @@ dwv.dicom.equalPosPat = function (pos1, pos2) {
19604
19705
  };
19605
19706
 
19606
19707
  /**
19607
- * Compare two position patients.
19708
+ * Get a position patient compare function accroding to an
19709
+ * input orientation.
19608
19710
  *
19609
- * @param {*} pos1 The first position patient.
19610
- * @param {*} pos2 The second position patient.
19611
- * @returns {number|null} A number used to sort elements.
19711
+ * @param {dwv.math.Matrix33} orientation The orientation matrix.
19712
+ * @returns {Function} The position compare function.
19612
19713
  */
19613
- dwv.dicom.comparePosPat = function (pos1, pos2) {
19614
- var diff = null;
19615
- var posLen = pos1.length;
19616
- var index = posLen;
19617
- for (var i = 0; i < posLen; ++i) {
19618
- --index;
19619
- diff = pos2[index] - pos1[index];
19620
- if (diff !== 0) {
19621
- return diff;
19622
- }
19623
- }
19624
- return diff;
19714
+ dwv.dicom.getComparePosPat = function (orientation) {
19715
+ var invOrientation = orientation.getInverse();
19716
+ return function (pos1, pos2) {
19717
+ var p1 = invOrientation.multiplyArray3D(pos1);
19718
+ var p2 = invOrientation.multiplyArray3D(pos2);
19719
+ return p2[2] - p1[2];
19720
+ };
19625
19721
  };
19626
19722
 
19627
19723
  /**
@@ -19653,7 +19749,7 @@ dwv.dicom.checkTag = function (rootElement, tagDefinition) {
19653
19749
  if (!Array.isArray(tagDefinition.enum[i])) {
19654
19750
  throw new Error('Cannot compare array and non array tag value.');
19655
19751
  }
19656
- if (dwv.utils.arrayEquals(tagDefinition.enum[i], tagValue)) {
19752
+ if (dwv.utils.arraySortEquals(tagDefinition.enum[i], tagValue)) {
19657
19753
  includes = true;
19658
19754
  break;
19659
19755
  }
@@ -19675,21 +19771,21 @@ dwv.dicom.checkTag = function (rootElement, tagDefinition) {
19675
19771
  /**
19676
19772
  * List of DICOM Seg required tags.
19677
19773
  */
19678
- dwv.dicom.requiredSegDicomTags = [
19774
+ dwv.dicom.requiredDicomSegTags = [
19679
19775
  {
19680
- name: 'Transfer Syntax UID',
19776
+ name: 'TransferSyntaxUID',
19681
19777
  tag: 'x00020010',
19682
19778
  type: '1',
19683
19779
  enum: ['1.2.840.10008.1.2.1']
19684
19780
  },
19685
19781
  {
19686
- name: 'Media Storage SOP Class UID',
19782
+ name: 'MediaStorageSOPClassUID',
19687
19783
  tag: 'x00020002',
19688
19784
  type: '1',
19689
19785
  enum: ['1.2.840.10008.5.1.4.1.1.66.4']
19690
19786
  },
19691
19787
  {
19692
- name: 'SOP Class UID',
19788
+ name: 'SOPClassUID',
19693
19789
  tag: 'x00020002',
19694
19790
  type: '1',
19695
19791
  enum: ['1.2.840.10008.5.1.4.1.1.66.4']
@@ -19701,61 +19797,75 @@ dwv.dicom.requiredSegDicomTags = [
19701
19797
  enum: ['SEG']
19702
19798
  },
19703
19799
  {
19704
- name: 'Segmentation Type',
19800
+ name: 'SegmentationType',
19705
19801
  tag: 'x00620001',
19706
19802
  type: '1',
19707
19803
  enum: ['BINARY']
19708
19804
  },
19709
19805
  {
19710
- name: 'Dimension Organization Type',
19806
+ name: 'DimensionOrganizationType',
19711
19807
  tag: 'x00209311',
19712
19808
  type: '3',
19713
19809
  enum: ['3D']
19714
19810
  },
19715
19811
  {
19716
- name: 'Image Type',
19812
+ name: 'ImageType',
19717
19813
  tag: 'x00080008',
19718
19814
  type: '1',
19719
19815
  enum: [['DERIVED', 'PRIMARY']]
19720
19816
  },
19721
19817
  {
19722
- name: 'Samples Per Pixel',
19818
+ name: 'SamplesPerPixel',
19723
19819
  tag: 'x00280002',
19724
19820
  type: '1',
19725
19821
  enum: [1]
19726
19822
  },
19727
19823
  {
19728
- name: 'Photometric Interpretation',
19824
+ name: 'PhotometricInterpretation',
19729
19825
  tag: 'x00280004',
19730
19826
  type: '1',
19731
19827
  enum: ['MONOCHROME2']
19732
19828
  },
19733
19829
  {
19734
- name: 'Pixel Representation',
19830
+ name: 'PixelRepresentation',
19735
19831
  tag: 'x00280103',
19736
19832
  type: '1',
19737
19833
  enum: [0]
19738
19834
  },
19739
19835
  {
19740
- name: 'Bits Allocated',
19836
+ name: 'BitsAllocated',
19741
19837
  tag: 'x00280100',
19742
19838
  type: '1',
19743
19839
  enum: [1]
19744
19840
  },
19745
19841
  {
19746
- name: 'Bits Stored',
19842
+ name: 'BitsStored',
19747
19843
  tag: 'x00280101',
19748
19844
  type: '1',
19749
19845
  enum: [1]
19750
19846
  },
19751
19847
  {
19752
- name: 'High Bit',
19848
+ name: 'HighBit',
19753
19849
  tag: 'x00280102',
19754
19850
  type: '1',
19755
19851
  enum: [0]
19756
19852
  },
19757
19853
  ];
19758
19854
 
19855
+ /**
19856
+ * Get the default DICOM seg tags as an object.
19857
+ *
19858
+ * @returns {object} The default tags.
19859
+ */
19860
+ dwv.dicom.getDefaultDicomSegJson = function () {
19861
+ var tags = {};
19862
+ for (var i = 0; i < dwv.dicom.requiredDicomSegTags.length; ++i) {
19863
+ var reqTag = dwv.dicom.requiredDicomSegTags[i];
19864
+ tags[reqTag.name] = reqTag.enum[0];
19865
+ }
19866
+ return tags;
19867
+ };
19868
+
19759
19869
  /**
19760
19870
  * Check the dimension organization from a dicom element.
19761
19871
  *
@@ -19769,7 +19879,7 @@ dwv.dicom.getDimensionOrganization = function (rootElement) {
19769
19879
  throw new Error('Unsupported dimension organization sequence length');
19770
19880
  }
19771
19881
  // Dimension Organization UID
19772
- var orgs = [dwv.dicom.cleanString(orgSq[0].x00209164.value[0])];
19882
+ var orgUID = dwv.dicom.cleanString(orgSq[0].x00209164.value[0]);
19773
19883
 
19774
19884
  // Dimension Index Sequence (conditionally required)
19775
19885
  var indices = [];
@@ -19779,38 +19889,46 @@ dwv.dicom.getDimensionOrganization = function (rootElement) {
19779
19889
  if (indexSq.length !== 2) {
19780
19890
  throw new Error('Unsupported dimension index sequence length');
19781
19891
  }
19892
+ var indexPointer;
19782
19893
  for (var i = 0; i < indexSq.length; ++i) {
19783
19894
  // Dimension Organization UID (required)
19784
19895
  var indexOrg = dwv.dicom.cleanString(indexSq[i].x00209164.value[0]);
19785
- if (indexOrg !== orgs[0]) {
19896
+ if (indexOrg !== orgUID) {
19786
19897
  throw new Error(
19787
19898
  'Dimension Index Sequence contains a unknown Dimension Organization');
19788
19899
  }
19789
19900
  // Dimension Index Pointer (required)
19790
- var indexPointer =
19791
- dwv.dicom.cleanString(indexSq[i].x00209165.value[0]);
19901
+ indexPointer = dwv.dicom.cleanString(indexSq[i].x00209165.value[0]);
19792
19902
 
19793
19903
  var index = {
19794
- organization: indexOrg,
19795
- pointer: indexPointer
19904
+ DimensionOrganizationUID: indexOrg,
19905
+ DimensionIndexPointer: indexPointer
19796
19906
  };
19797
19907
  // Dimension Description Label (optional)
19798
19908
  if (typeof indexSq[i].x00209421 !== 'undefined') {
19799
- index.label =
19909
+ index.DimensionDescriptionLabel =
19800
19910
  dwv.dicom.cleanString(indexSq[i].x00209421.value[0]);
19801
19911
  }
19802
19912
  // store
19803
19913
  indices.push(index);
19804
19914
  }
19805
19915
  // expecting Image Position at last position
19806
- if (indices[1].pointer !== '(0020,0032)') {
19916
+ if (indexPointer !== '(0020,0032)') {
19807
19917
  throw new Error('Unsupported non image position as last index');
19808
19918
  }
19809
19919
  }
19810
19920
 
19811
19921
  return {
19812
- organizations: orgs,
19813
- indices: indices
19922
+ organizations: {
19923
+ value: [
19924
+ {
19925
+ DimensionOrganizationUID: orgUID
19926
+ }
19927
+ ]
19928
+ },
19929
+ indices: {
19930
+ value: indices
19931
+ }
19814
19932
  };
19815
19933
  };
19816
19934
 
@@ -20005,10 +20123,12 @@ dwv.dicom.getSpacingFromMeasure = function (measure) {
20005
20123
  parseFloat(pixelSpacing.value[0]),
20006
20124
  parseFloat(pixelSpacing.value[1])
20007
20125
  ];
20008
- // Spacing Between Slices
20009
- if (typeof measure.x00180088 !== 'undefined') {
20010
- var sliceThickness = measure.x00180088;
20011
- spacingValues.push(parseFloat(sliceThickness.value[0]));
20126
+ // Slice Thickness
20127
+ if (typeof measure.x00180050 !== 'undefined') {
20128
+ spacingValues.push(parseFloat(measure.x00180050.value[0]));
20129
+ } else if (typeof measure.x00180088 !== 'undefined') {
20130
+ // Spacing Between Slices
20131
+ spacingValues.push(parseFloat(measure.x00180088.value[0]));
20012
20132
  }
20013
20133
  return new dwv.image.Spacing(spacingValues);
20014
20134
  };
@@ -20116,8 +20236,8 @@ dwv.image.MaskFactory = function () {};
20116
20236
  dwv.image.MaskFactory.prototype.create = function (
20117
20237
  dicomElements, pixelBuffer) {
20118
20238
  // check required and supported tags
20119
- for (var d = 0; d < dwv.dicom.requiredSegDicomTags.length; ++d) {
20120
- dwv.dicom.checkTag(dicomElements, dwv.dicom.requiredSegDicomTags[d]);
20239
+ for (var d = 0; d < dwv.dicom.requiredDicomSegTags.length; ++d) {
20240
+ dwv.dicom.checkTag(dicomElements, dwv.dicom.requiredDicomSegTags[d]);
20121
20241
  }
20122
20242
 
20123
20243
  // columns
@@ -20183,12 +20303,7 @@ dwv.image.MaskFactory.prototype.create = function (
20183
20303
  var planeOrientationSeq = funcGroup0.x00209116;
20184
20304
  if (planeOrientationSeq.value.length !== 0) {
20185
20305
  // should be only one
20186
- var orientArray = planeOrientationSeq.value[0].x00200037.value;
20187
- imageOrientationPatient = orientArray.map(
20188
- function (x) {
20189
- return parseFloat(x);
20190
- }
20191
- );
20306
+ imageOrientationPatient = planeOrientationSeq.value[0].x00200037.value;
20192
20307
  } else {
20193
20308
  dwv.logger.warn(
20194
20309
  'No shared functional group plane orientation sequence items.');
@@ -20247,7 +20362,7 @@ dwv.image.MaskFactory.prototype.create = function (
20247
20362
  if (typeof imageOrientationPatient === 'undefined') {
20248
20363
  imageOrientationPatient = frameInfos[ii].imageOrientationPatient;
20249
20364
  } else {
20250
- if (!dwv.utils.arrayEquals(
20365
+ if (!dwv.utils.arraySortEquals(
20251
20366
  imageOrientationPatient, frameInfos[ii].imageOrientationPatient)) {
20252
20367
  throw new Error('Unsupported multi orientation dicom seg.');
20253
20368
  }
@@ -20264,8 +20379,6 @@ dwv.image.MaskFactory.prototype.create = function (
20264
20379
  }
20265
20380
  }
20266
20381
  }
20267
- // sort positions patient
20268
- framePosPats.sort(dwv.dicom.comparePosPat);
20269
20382
 
20270
20383
  // check spacing and orientation
20271
20384
  if (typeof spacing === 'undefined') {
@@ -20275,12 +20388,7 @@ dwv.image.MaskFactory.prototype.create = function (
20275
20388
  throw new Error('No imageOrientationPatient found for DICOM SEG');
20276
20389
  }
20277
20390
 
20278
- var point3DFromArray = function (arr) {
20279
- return new dwv.math.Point3D(arr[0], arr[1], arr[2]);
20280
- };
20281
-
20282
- // create geometry
20283
- var origin = point3DFromArray(framePosPats[0]);
20391
+ // orientation
20284
20392
  var rowCosines = new dwv.math.Vector3D(
20285
20393
  parseFloat(imageOrientationPatient[0]),
20286
20394
  parseFloat(imageOrientationPatient[1]),
@@ -20296,8 +20404,34 @@ dwv.image.MaskFactory.prototype.create = function (
20296
20404
  rowCosines.getY(), colCosines.getY(), normal.getY(),
20297
20405
  rowCosines.getZ(), colCosines.getZ(), normal.getZ()
20298
20406
  ]);
20299
- var geometry = new dwv.image.Geometry(
20300
- origin, size, spacing, orientationMatrix);
20407
+
20408
+ // sort positions patient
20409
+ framePosPats.sort(dwv.dicom.getComparePosPat(orientationMatrix));
20410
+
20411
+ var point3DFromArray = function (arr) {
20412
+ return new dwv.math.Point3D(arr[0], arr[1], arr[2]);
20413
+ };
20414
+
20415
+ // frame origins
20416
+ var frameOrigins = [];
20417
+ for (var n = 0; n < framePosPats.length; ++n) {
20418
+ frameOrigins.push(point3DFromArray(framePosPats[n]));
20419
+ }
20420
+
20421
+ // use calculated spacing
20422
+ var newSpacing = spacing;
20423
+ var geoSliceSpacing = dwv.image.getSliceGeometrySpacing(
20424
+ frameOrigins, orientationMatrix, false);
20425
+ var spacingValues = spacing.getValues();
20426
+ if (typeof geoSliceSpacing !== 'undefined' &&
20427
+ geoSliceSpacing !== spacingValues[2]) {
20428
+ spacingValues[2] = geoSliceSpacing;
20429
+ newSpacing = new dwv.image.Spacing(spacingValues);
20430
+ }
20431
+
20432
+ // tmp geometry with correct spacing but only one slice
20433
+ var tmpGeometry = new dwv.image.Geometry(
20434
+ frameOrigins[0], size, newSpacing, orientationMatrix);
20301
20435
 
20302
20436
  // add possibly missing posPats
20303
20437
  var posPats = [];
@@ -20306,23 +20440,36 @@ dwv.image.MaskFactory.prototype.create = function (
20306
20440
  for (var g = 1; g < framePosPats.length; ++g) {
20307
20441
  ++sliceIndex;
20308
20442
  var index = new dwv.math.Index([0, 0, sliceIndex]);
20309
- var point = geometry.indexToWorld(index).get3D();
20310
- var framePosPat = point3DFromArray(framePosPats[g]);
20443
+ var point = tmpGeometry.indexToWorld(index).get3D();
20444
+ var frameOrigin = frameOrigins[g];
20311
20445
  // check if more pos pats are needed
20312
- var dist = framePosPat.getDistance(point);
20446
+ var dist = frameOrigin.getDistance(point);
20313
20447
  // TODO: good threshold?
20314
- while (dist > 1e-4) {
20315
- dwv.logger.debug('Adding intermediate pos pats for DICOM seg');
20448
+ while (dist > dwv.math.REAL_WORLD_EPSILON) {
20449
+ dwv.logger.debug('Adding intermediate pos pats for DICOM seg at ' +
20450
+ point.toString());
20316
20451
  posPats.push([point.getX(), point.getY(), point.getZ()]);
20317
20452
  ++sliceIndex;
20318
20453
  index = new dwv.math.Index([0, 0, sliceIndex]);
20319
- point = geometry.indexToWorld(index).get3D();
20320
- dist = framePosPat.getDistance(point);
20454
+ point = tmpGeometry.indexToWorld(index).get3D();
20455
+ dist = frameOrigin.getDistance(point);
20321
20456
  }
20322
20457
  // add frame pos pat
20323
20458
  posPats.push(framePosPats[g]);
20324
20459
  }
20325
20460
 
20461
+ // as many slices as posPats
20462
+ var numberOfSlices = posPats.length;
20463
+
20464
+ // final geometry
20465
+ var geometry = new dwv.image.Geometry(
20466
+ frameOrigins[0], size, newSpacing, orientationMatrix);
20467
+ var uids = [0];
20468
+ for (var m = 1; m < numberOfSlices; ++m) {
20469
+ geometry.appendOrigin(point3DFromArray(posPats[m]), m);
20470
+ uids.push(m);
20471
+ }
20472
+
20326
20473
  var getFindSegmentFunc = function (number) {
20327
20474
  return function (item) {
20328
20475
  return item.number === number;
@@ -20330,8 +20477,6 @@ dwv.image.MaskFactory.prototype.create = function (
20330
20477
  };
20331
20478
 
20332
20479
  // create output buffer
20333
- // as many slices as posPats
20334
- var numberOfSlices = posPats.length;
20335
20480
  var mul = storeAsRGB ? 3 : 1;
20336
20481
  var buffer = new pixelBuffer.constructor(mul * sliceSize * numberOfSlices);
20337
20482
  buffer.fill(0);
@@ -20362,45 +20507,58 @@ dwv.image.MaskFactory.prototype.create = function (
20362
20507
  }
20363
20508
  }
20364
20509
 
20365
- var uids = [0];
20366
- for (var m = 1; m < numberOfSlices; ++m) {
20367
- // args: origin, volumeNumber, uid, index, increment
20368
- geometry.appendOrigin(point3DFromArray(posPats[m]), m);
20369
- uids.push(m);
20370
- }
20371
-
20372
20510
  // create image
20373
20511
  var image = new dwv.image.Image(geometry, buffer, uids);
20374
20512
  if (storeAsRGB) {
20375
20513
  image.setPhotometricInterpretation('RGB');
20376
20514
  }
20377
20515
  // meta information
20378
- var meta = {
20379
- Modality: 'SEG',
20380
- SegmentationType: 'BINARY',
20381
- DimensionOrganizationType: '3D',
20382
- DimensionOrganizations: dimension.organizations,
20383
- DimensionIndices: dimension.indices,
20384
- BitsStored: 1,
20385
- PatientName: dwv.dicom.cleanString(dicomElements.getFromKey('x00100010')),
20386
- PatientID: dwv.dicom.cleanString(dicomElements.getFromKey('x00100020')),
20387
- PatientBirthDate: dicomElements.getFromKey('x00100030'),
20388
- PatientSex: dwv.dicom.cleanString(dicomElements.getFromKey('x00100040')),
20389
- StudyInstanceUID: dicomElements.getFromKey('x0020000D'),
20390
- SeriesInstanceUID: dicomElements.getFromKey('x0020000E'),
20391
- SeriesNumber: dicomElements.getFromKey('x00200011'),
20392
- ImageOrientationPatient: imageOrientationPatient,
20393
- custom: {
20394
- segments: segments,
20395
- frameInfos: frameInfos,
20396
- SOPInstanceUID: dicomElements.getFromKey('x00080018')
20397
- }
20398
- };
20516
+ var meta = dwv.dicom.getDefaultDicomSegJson();
20517
+ // Study
20518
+ meta.StudyDate = dicomElements.getFromKey('x00080020');
20519
+ meta.StudyTime = dicomElements.getFromKey('x00080030');
20520
+ meta.StudyInstanceUID = dicomElements.getFromKey('x0020000D');
20521
+ meta.StudyID = dicomElements.getFromKey('x00200010');
20522
+ // Series
20523
+ meta.SeriesInstanceUID = dicomElements.getFromKey('x0020000E');
20524
+ meta.SeriesNumber = dicomElements.getFromKey('x00200011');
20525
+ // ReferringPhysicianName
20526
+ meta.ReferringPhysicianName = dicomElements.getFromKey('x00080090');
20527
+ // patient info
20528
+ meta.PatientName =
20529
+ dwv.dicom.cleanString(dicomElements.getFromKey('x00100010'));
20530
+ meta.PatientID = dwv.dicom.cleanString(dicomElements.getFromKey('x00100020'));
20531
+ meta.PatientBirthDate = dicomElements.getFromKey('x00100030');
20532
+ meta.PatientSex =
20533
+ dwv.dicom.cleanString(dicomElements.getFromKey('x00100040'));
20534
+ // Enhanced General Equipment Module
20535
+ meta.Manufacturer = dicomElements.getFromKey('x00080070');
20536
+ meta.ManufacturerModelName = dicomElements.getFromKey('x00081090');
20537
+ meta.DeviceSerialNumber = dicomElements.getFromKey('x00181000');
20538
+ meta.SoftwareVersions = dicomElements.getFromKey('x00181020');
20539
+ // dicom seg dimension
20540
+ meta.DimensionOrganizationSequence = dimension.organizations;
20541
+ meta.DimensionIndexSequence = dimension.indices;
20542
+ // custom
20543
+ meta.custom = {
20544
+ segments: segments,
20545
+ frameInfos: frameInfos,
20546
+ SOPInstanceUID: dicomElements.getFromKey('x00080018')
20547
+ };
20548
+
20549
+ // number of files: in this case equal to number slices,
20550
+ // used to calculate buffer size
20551
+ meta.numberOfFiles = numberOfSlices;
20399
20552
  // FrameOfReferenceUID (optional)
20400
20553
  var frameOfReferenceUID = dicomElements.getFromKey('x00200052');
20401
20554
  if (frameOfReferenceUID) {
20402
20555
  meta.FrameOfReferenceUID = frameOfReferenceUID;
20403
20556
  }
20557
+ // LossyImageCompression (optional)
20558
+ var lossyImageCompression = dicomElements.getFromKey('x00282110');
20559
+ if (lossyImageCompression) {
20560
+ meta.LossyImageCompression = lossyImageCompression;
20561
+ }
20404
20562
 
20405
20563
  image.setMeta(meta);
20406
20564
 
@@ -21192,7 +21350,7 @@ dwv.image.View = function (image) {
21192
21350
  * Store position and not index to stay geometry independent.
21193
21351
  *
21194
21352
  * @private
21195
- * @type {dwv.math.Index}
21353
+ * @type {dwv.math.Point3D}
21196
21354
  */
21197
21355
  var currentPosition = null;
21198
21356
  /**
@@ -21690,6 +21848,7 @@ dwv.image.View = function (image) {
21690
21848
  }
21691
21849
 
21692
21850
  // all good
21851
+ //console.log('[v] set cur index OUT');
21693
21852
  return true;
21694
21853
  };
21695
21854
 
@@ -26738,13 +26897,16 @@ if (typeof Number.EPSILON === 'undefined') {
26738
26897
  }
26739
26898
  // -> ~2e-12
26740
26899
  dwv.math.BIG_EPSILON = Number.EPSILON * 1e4;
26900
+ // 'real world', for example when comparing positions
26901
+ dwv.math.REAL_WORLD_EPSILON = 1e-4;
26741
26902
 
26742
26903
  /**
26743
26904
  * Check if two numbers are similar.
26744
26905
  *
26745
26906
  * @param {number} a The first number.
26746
26907
  * @param {number} b The second number.
26747
- * @param {number} tol The comparison tolerance.
26908
+ * @param {number} tol The comparison tolerance
26909
+ * default to Number.EPSILON.
26748
26910
  * @returns {boolean} True if similar.
26749
26911
  */
26750
26912
  dwv.math.isSimilar = function (a, b, tol) {
@@ -27431,11 +27593,11 @@ dwv.math.Point3D.prototype.minus = function (point3D) {
27431
27593
  };
27432
27594
 
27433
27595
  /**
27434
- * Get an array find callback for a given point.
27596
+ * Get an array find callback for an equal input point.
27435
27597
  *
27436
27598
  * @param {dwv.math.Point3D} point The point to compare to.
27437
- * @returns {Function} A function that compares its input point to the one
27438
- * given as input to this function.
27599
+ * @returns {Function} A function that compares, using `equals`,
27600
+ * its input point to the one given as input to this function.
27439
27601
  */
27440
27602
  dwv.math.getEqualPoint3DFunction = function (point) {
27441
27603
  return function (element) {
@@ -27443,6 +27605,21 @@ dwv.math.getEqualPoint3DFunction = function (point) {
27443
27605
  };
27444
27606
  };
27445
27607
 
27608
+ /**
27609
+ * Get an array find callback for a similar input point.
27610
+ *
27611
+ * @param {dwv.math.Point3D} point The point to compare to.
27612
+ * @param {number} tol The comparison tolerance
27613
+ * default to Number.EPSILON.
27614
+ * @returns {Function} A function that compares, using `isSimilar`,
27615
+ * its input point to the one given as input to this function.
27616
+ */
27617
+ dwv.math.getSimilarPoint3DFunction = function (point, tol) {
27618
+ return function (element) {
27619
+ return element.isSimilar(point, tol);
27620
+ };
27621
+ };
27622
+
27446
27623
  /**
27447
27624
  * Immutable point.
27448
27625
  * Warning: the input array is NOT cloned, modifying it will
@@ -35559,6 +35736,25 @@ dwv.tool.ZoomAndPan.prototype.init = function () {
35559
35736
  var dwv = dwv || {};
35560
35737
  dwv.utils = dwv.utils || {};
35561
35738
 
35739
+ /**
35740
+ * Check for array equality after sorting.
35741
+ *
35742
+ * @param {Array} arr0 First array.
35743
+ * @param {*} arr1 Second array.
35744
+ * @returns {boolean} True if both array are defined and contain same values.
35745
+ */
35746
+ dwv.utils.arraySortEquals = function (arr0, arr1) {
35747
+ if (arr0 === null ||
35748
+ arr1 === null ||
35749
+ typeof arr0 === 'undefined' ||
35750
+ typeof arr1 === 'undefined') {
35751
+ return false;
35752
+ }
35753
+ var arr0sorted = arr0.slice().sort();
35754
+ var arr1sorted = arr1.slice().sort();
35755
+ return dwv.utils.arrayEquals(arr0sorted, arr1sorted);
35756
+ };
35757
+
35562
35758
  /**
35563
35759
  * Check for array equality.
35564
35760
  *
@@ -35576,10 +35772,8 @@ dwv.utils.arrayEquals = function (arr0, arr1) {
35576
35772
  if (arr0.length !== arr1.length) {
35577
35773
  return false;
35578
35774
  }
35579
- var arr0sorted = arr0.slice().sort();
35580
- var arr1sorted = arr1.slice().sort();
35581
- return arr0sorted.every(function (element, index) {
35582
- return element === arr1sorted[index];
35775
+ return arr0.every(function (element, index) {
35776
+ return element === arr1[index];
35583
35777
  });
35584
35778
  };
35585
35779