dwv 0.31.0-beta.16 → 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 +259 -133
- package/dist/dwv.min.js +2 -2
- package/package.json +1 -1
package/dist/dwv.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! dwv 0.31.0-beta.
|
|
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) {
|
|
@@ -4602,7 +4602,7 @@ dwv.dicom = dwv.dicom || {};
|
|
|
4602
4602
|
* @returns {string} The version of the library.
|
|
4603
4603
|
*/
|
|
4604
4604
|
dwv.getVersion = function () {
|
|
4605
|
-
return '0.31.0-beta.
|
|
4605
|
+
return '0.31.0-beta.17';
|
|
4606
4606
|
};
|
|
4607
4607
|
|
|
4608
4608
|
/**
|
|
@@ -4745,6 +4745,27 @@ dwv.dicom.getReverseOrientation = function (ori) {
|
|
|
4745
4745
|
return rori;
|
|
4746
4746
|
};
|
|
4747
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
|
+
|
|
4748
4769
|
/**
|
|
4749
4770
|
* Tell if a given syntax is an implicit one (element with no VR).
|
|
4750
4771
|
*
|
|
@@ -5708,25 +5729,28 @@ dwv.dicom.DicomParser.prototype.parse = function (buffer) {
|
|
|
5708
5729
|
//-------------------------------------------------
|
|
5709
5730
|
// values needed for data interpretation
|
|
5710
5731
|
|
|
5711
|
-
//
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
dataElement
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
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
|
+
}
|
|
5721
5744
|
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
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
|
+
}
|
|
5730
5754
|
}
|
|
5731
5755
|
|
|
5732
5756
|
// default character set
|
|
@@ -6804,8 +6828,6 @@ dwv.dicom.DicomWriter.prototype.getBuffer = function (dicomElements) {
|
|
|
6804
6828
|
var syntax = dwv.dicom.cleanString(dicomElements.x00020010.value[0]);
|
|
6805
6829
|
var isImplicit = dwv.dicom.isImplicitTransferSyntax(syntax);
|
|
6806
6830
|
var isBigEndian = dwv.dicom.isBigEndianTransferSyntax(syntax);
|
|
6807
|
-
// Bits Allocated
|
|
6808
|
-
var bitsAllocated = dicomElements.x00280100.value[0];
|
|
6809
6831
|
// Specific CharacterSet
|
|
6810
6832
|
if (typeof dicomElements.x00080005 !== 'undefined') {
|
|
6811
6833
|
var oldscs = dwv.dicom.cleanString(dicomElements.x00080005.value[0]);
|
|
@@ -6816,6 +6838,11 @@ dwv.dicom.DicomWriter.prototype.getBuffer = function (dicomElements) {
|
|
|
6816
6838
|
dicomElements.x00080005.value = ['ISO_IR 192'];
|
|
6817
6839
|
}
|
|
6818
6840
|
}
|
|
6841
|
+
// Bits Allocated (for image data)
|
|
6842
|
+
var bitsAllocated;
|
|
6843
|
+
if (typeof dicomElements.x00280100 !== 'undefined') {
|
|
6844
|
+
bitsAllocated = dicomElements.x00280100.value[0];
|
|
6845
|
+
}
|
|
6819
6846
|
|
|
6820
6847
|
// calculate buffer size and split elements (meta and non meta)
|
|
6821
6848
|
var totalSize = 128 + 4; // DICM
|
|
@@ -14153,9 +14180,22 @@ dwv.gui.PositionBinder = function () {
|
|
|
14153
14180
|
};
|
|
14154
14181
|
this.getCallback = function (layerGroup) {
|
|
14155
14182
|
return function (event) {
|
|
14156
|
-
var
|
|
14183
|
+
var pointValues = event.value[1];
|
|
14157
14184
|
var vc = layerGroup.getActiveViewLayer().getViewController();
|
|
14158
|
-
|
|
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));
|
|
14159
14199
|
};
|
|
14160
14200
|
};
|
|
14161
14201
|
};
|
|
@@ -16984,11 +17024,13 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
|
|
|
16984
17024
|
* Check if a point is in the origin list.
|
|
16985
17025
|
*
|
|
16986
17026
|
* @param {dwv.math.Point3D} point3D The point to check.
|
|
17027
|
+
* @param {number} tol The comparison tolerance
|
|
17028
|
+
* default to Number.EPSILON.
|
|
16987
17029
|
* @returns {boolean} True if in list.
|
|
16988
17030
|
*/
|
|
16989
|
-
this.includesOrigin = function (point3D) {
|
|
17031
|
+
this.includesOrigin = function (point3D, tol) {
|
|
16990
17032
|
for (var i = 0; i < origins.length; ++i) {
|
|
16991
|
-
if (origins[i].isSimilar(point3D,
|
|
17033
|
+
if (origins[i].isSimilar(point3D, tol)) {
|
|
16992
17034
|
return true;
|
|
16993
17035
|
}
|
|
16994
17036
|
}
|
|
@@ -17019,52 +17061,21 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
|
|
|
17019
17061
|
};
|
|
17020
17062
|
|
|
17021
17063
|
/**
|
|
17022
|
-
*
|
|
17023
|
-
*
|
|
17024
|
-
*
|
|
17025
|
-
* @returns {number} The spacing.
|
|
17064
|
+
* Calculate slice spacing from origins and replace current
|
|
17065
|
+
* if needed.
|
|
17026
17066
|
*/
|
|
17027
|
-
|
|
17028
|
-
|
|
17029
|
-
|
|
17030
|
-
|
|
17031
|
-
|
|
17032
|
-
|
|
17033
|
-
|
|
17034
|
-
|
|
17035
|
-
|
|
17036
|
-
|
|
17037
|
-
var deltas = [];
|
|
17038
|
-
for (var i = 0; i < origins.length - 1; ++i) {
|
|
17039
|
-
var origin1 = invOrientation.multiplyVector3D(origins[i]);
|
|
17040
|
-
var origin2 = invOrientation.multiplyVector3D(origins[i + 1]);
|
|
17041
|
-
var diff = Math.abs(origin1.getZ() - origin2.getZ());
|
|
17042
|
-
if (diff === 0) {
|
|
17043
|
-
throw new Error('Zero slice spacing.' +
|
|
17044
|
-
origin1.toString() + ' ' + origin2.toString());
|
|
17045
|
-
}
|
|
17046
|
-
if (sliceSpacing === null) {
|
|
17047
|
-
sliceSpacing = diff;
|
|
17048
|
-
} else {
|
|
17049
|
-
if (!dwv.math.isSimilar(sliceSpacing, diff, dwv.math.BIG_EPSILON)) {
|
|
17050
|
-
deltas.push(Math.abs(sliceSpacing - diff));
|
|
17051
|
-
}
|
|
17052
|
-
}
|
|
17053
|
-
}
|
|
17054
|
-
// warn if non constant
|
|
17055
|
-
if (deltas.length !== 0) {
|
|
17056
|
-
var sumReducer = function (sum, value) {
|
|
17057
|
-
return sum + value;
|
|
17058
|
-
};
|
|
17059
|
-
var mean = deltas.reduce(sumReducer) / deltas.length;
|
|
17060
|
-
if (mean > 1e-4) {
|
|
17061
|
-
dwv.logger.warn('Varying slice spacing, mean delta: ' +
|
|
17062
|
-
mean.toFixed(3) + ' (' + deltas.length + ' case(s))');
|
|
17063
|
-
}
|
|
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);
|
|
17064
17077
|
}
|
|
17065
|
-
|
|
17066
|
-
return sliceSpacing;
|
|
17067
|
-
};
|
|
17078
|
+
}
|
|
17068
17079
|
|
|
17069
17080
|
/**
|
|
17070
17081
|
* Get the object spacing.
|
|
@@ -17077,9 +17088,7 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
|
|
|
17077
17088
|
this.getSpacing = function (viewOrientation) {
|
|
17078
17089
|
// update slice spacing after appendSlice
|
|
17079
17090
|
if (newOrigins) {
|
|
17080
|
-
|
|
17081
|
-
values[2] = this.getSliceGeometrySpacing();
|
|
17082
|
-
spacing = new dwv.image.Spacing(values);
|
|
17091
|
+
updateSliceSpacing();
|
|
17083
17092
|
newOrigins = false;
|
|
17084
17093
|
}
|
|
17085
17094
|
var res = spacing;
|
|
@@ -17153,13 +17162,13 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
|
|
|
17153
17162
|
var pointDir = point.minus(closestOrigin);
|
|
17154
17163
|
// use third orientation matrix column as base plane vector
|
|
17155
17164
|
var normal = new dwv.math.Vector3D(
|
|
17156
|
-
orientation.get(
|
|
17165
|
+
orientation.get(0, 2), orientation.get(1, 2), orientation.get(2, 2));
|
|
17157
17166
|
// a.dot(b) = ||a|| * ||b|| * cos(theta)
|
|
17158
17167
|
// (https://en.wikipedia.org/wiki/Dot_product#Geometric_definition)
|
|
17159
17168
|
// -> the sign of the dot product depends on the cosinus of
|
|
17160
17169
|
// the angle between the vectors
|
|
17161
17170
|
// -> >0 => vectors are codirectional
|
|
17162
|
-
// -> <0 => vectors are
|
|
17171
|
+
// -> <0 => vectors are opposite
|
|
17163
17172
|
var dotProd = normal.dotProduct(pointDir);
|
|
17164
17173
|
var test = dotProd < 0;
|
|
17165
17174
|
// TODO: check why coronal behaves differently...
|
|
@@ -17225,7 +17234,8 @@ dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
|
|
|
17225
17234
|
dwv.image.Geometry.prototype.toString = function () {
|
|
17226
17235
|
return 'Origin: ' + this.getOrigin() +
|
|
17227
17236
|
', Size: ' + this.getSize() +
|
|
17228
|
-
', Spacing: ' + this.getSpacing()
|
|
17237
|
+
', Spacing: ' + this.getSpacing() +
|
|
17238
|
+
', Orientation: ' + this.getOrientation();
|
|
17229
17239
|
};
|
|
17230
17240
|
|
|
17231
17241
|
/**
|
|
@@ -17365,6 +17375,66 @@ dwv.image.Geometry.prototype.worldToIndex = function (point) {
|
|
|
17365
17375
|
return new dwv.math.Index(values);
|
|
17366
17376
|
};
|
|
17367
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
|
+
|
|
17368
17438
|
// namespaces
|
|
17369
17439
|
var dwv = dwv || {};
|
|
17370
17440
|
/** @namespace */
|
|
@@ -19635,24 +19705,19 @@ dwv.dicom.equalPosPat = function (pos1, pos2) {
|
|
|
19635
19705
|
};
|
|
19636
19706
|
|
|
19637
19707
|
/**
|
|
19638
|
-
*
|
|
19708
|
+
* Get a position patient compare function accroding to an
|
|
19709
|
+
* input orientation.
|
|
19639
19710
|
*
|
|
19640
|
-
* @param {
|
|
19641
|
-
* @
|
|
19642
|
-
* @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.
|
|
19643
19713
|
*/
|
|
19644
|
-
dwv.dicom.
|
|
19645
|
-
var
|
|
19646
|
-
|
|
19647
|
-
|
|
19648
|
-
|
|
19649
|
-
|
|
19650
|
-
|
|
19651
|
-
if (diff !== 0) {
|
|
19652
|
-
return diff;
|
|
19653
|
-
}
|
|
19654
|
-
}
|
|
19655
|
-
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
|
+
};
|
|
19656
19721
|
};
|
|
19657
19722
|
|
|
19658
19723
|
/**
|
|
@@ -19684,7 +19749,7 @@ dwv.dicom.checkTag = function (rootElement, tagDefinition) {
|
|
|
19684
19749
|
if (!Array.isArray(tagDefinition.enum[i])) {
|
|
19685
19750
|
throw new Error('Cannot compare array and non array tag value.');
|
|
19686
19751
|
}
|
|
19687
|
-
if (dwv.utils.
|
|
19752
|
+
if (dwv.utils.arraySortEquals(tagDefinition.enum[i], tagValue)) {
|
|
19688
19753
|
includes = true;
|
|
19689
19754
|
break;
|
|
19690
19755
|
}
|
|
@@ -20058,10 +20123,12 @@ dwv.dicom.getSpacingFromMeasure = function (measure) {
|
|
|
20058
20123
|
parseFloat(pixelSpacing.value[0]),
|
|
20059
20124
|
parseFloat(pixelSpacing.value[1])
|
|
20060
20125
|
];
|
|
20061
|
-
//
|
|
20062
|
-
if (typeof measure.
|
|
20063
|
-
|
|
20064
|
-
|
|
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]));
|
|
20065
20132
|
}
|
|
20066
20133
|
return new dwv.image.Spacing(spacingValues);
|
|
20067
20134
|
};
|
|
@@ -20295,7 +20362,7 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
20295
20362
|
if (typeof imageOrientationPatient === 'undefined') {
|
|
20296
20363
|
imageOrientationPatient = frameInfos[ii].imageOrientationPatient;
|
|
20297
20364
|
} else {
|
|
20298
|
-
if (!dwv.utils.
|
|
20365
|
+
if (!dwv.utils.arraySortEquals(
|
|
20299
20366
|
imageOrientationPatient, frameInfos[ii].imageOrientationPatient)) {
|
|
20300
20367
|
throw new Error('Unsupported multi orientation dicom seg.');
|
|
20301
20368
|
}
|
|
@@ -20312,8 +20379,6 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
20312
20379
|
}
|
|
20313
20380
|
}
|
|
20314
20381
|
}
|
|
20315
|
-
// sort positions patient
|
|
20316
|
-
framePosPats.sort(dwv.dicom.comparePosPat);
|
|
20317
20382
|
|
|
20318
20383
|
// check spacing and orientation
|
|
20319
20384
|
if (typeof spacing === 'undefined') {
|
|
@@ -20323,12 +20388,7 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
20323
20388
|
throw new Error('No imageOrientationPatient found for DICOM SEG');
|
|
20324
20389
|
}
|
|
20325
20390
|
|
|
20326
|
-
|
|
20327
|
-
return new dwv.math.Point3D(arr[0], arr[1], arr[2]);
|
|
20328
|
-
};
|
|
20329
|
-
|
|
20330
|
-
// create geometry
|
|
20331
|
-
var origin = point3DFromArray(framePosPats[0]);
|
|
20391
|
+
// orientation
|
|
20332
20392
|
var rowCosines = new dwv.math.Vector3D(
|
|
20333
20393
|
parseFloat(imageOrientationPatient[0]),
|
|
20334
20394
|
parseFloat(imageOrientationPatient[1]),
|
|
@@ -20344,8 +20404,34 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
20344
20404
|
rowCosines.getY(), colCosines.getY(), normal.getY(),
|
|
20345
20405
|
rowCosines.getZ(), colCosines.getZ(), normal.getZ()
|
|
20346
20406
|
]);
|
|
20347
|
-
|
|
20348
|
-
|
|
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);
|
|
20349
20435
|
|
|
20350
20436
|
// add possibly missing posPats
|
|
20351
20437
|
var posPats = [];
|
|
@@ -20354,23 +20440,36 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
20354
20440
|
for (var g = 1; g < framePosPats.length; ++g) {
|
|
20355
20441
|
++sliceIndex;
|
|
20356
20442
|
var index = new dwv.math.Index([0, 0, sliceIndex]);
|
|
20357
|
-
var point =
|
|
20358
|
-
var
|
|
20443
|
+
var point = tmpGeometry.indexToWorld(index).get3D();
|
|
20444
|
+
var frameOrigin = frameOrigins[g];
|
|
20359
20445
|
// check if more pos pats are needed
|
|
20360
|
-
var dist =
|
|
20446
|
+
var dist = frameOrigin.getDistance(point);
|
|
20361
20447
|
// TODO: good threshold?
|
|
20362
|
-
while (dist >
|
|
20363
|
-
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());
|
|
20364
20451
|
posPats.push([point.getX(), point.getY(), point.getZ()]);
|
|
20365
20452
|
++sliceIndex;
|
|
20366
20453
|
index = new dwv.math.Index([0, 0, sliceIndex]);
|
|
20367
|
-
point =
|
|
20368
|
-
dist =
|
|
20454
|
+
point = tmpGeometry.indexToWorld(index).get3D();
|
|
20455
|
+
dist = frameOrigin.getDistance(point);
|
|
20369
20456
|
}
|
|
20370
20457
|
// add frame pos pat
|
|
20371
20458
|
posPats.push(framePosPats[g]);
|
|
20372
20459
|
}
|
|
20373
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
|
+
|
|
20374
20473
|
var getFindSegmentFunc = function (number) {
|
|
20375
20474
|
return function (item) {
|
|
20376
20475
|
return item.number === number;
|
|
@@ -20378,8 +20477,6 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
20378
20477
|
};
|
|
20379
20478
|
|
|
20380
20479
|
// create output buffer
|
|
20381
|
-
// as many slices as posPats
|
|
20382
|
-
var numberOfSlices = posPats.length;
|
|
20383
20480
|
var mul = storeAsRGB ? 3 : 1;
|
|
20384
20481
|
var buffer = new pixelBuffer.constructor(mul * sliceSize * numberOfSlices);
|
|
20385
20482
|
buffer.fill(0);
|
|
@@ -20410,13 +20507,6 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
20410
20507
|
}
|
|
20411
20508
|
}
|
|
20412
20509
|
|
|
20413
|
-
var uids = [0];
|
|
20414
|
-
for (var m = 1; m < numberOfSlices; ++m) {
|
|
20415
|
-
// args: origin, volumeNumber, uid, index, increment
|
|
20416
|
-
geometry.appendOrigin(point3DFromArray(posPats[m]), m);
|
|
20417
|
-
uids.push(m);
|
|
20418
|
-
}
|
|
20419
|
-
|
|
20420
20510
|
// create image
|
|
20421
20511
|
var image = new dwv.image.Image(geometry, buffer, uids);
|
|
20422
20512
|
if (storeAsRGB) {
|
|
@@ -21260,7 +21350,7 @@ dwv.image.View = function (image) {
|
|
|
21260
21350
|
* Store position and not index to stay geometry independent.
|
|
21261
21351
|
*
|
|
21262
21352
|
* @private
|
|
21263
|
-
* @type {dwv.math.
|
|
21353
|
+
* @type {dwv.math.Point3D}
|
|
21264
21354
|
*/
|
|
21265
21355
|
var currentPosition = null;
|
|
21266
21356
|
/**
|
|
@@ -21758,6 +21848,7 @@ dwv.image.View = function (image) {
|
|
|
21758
21848
|
}
|
|
21759
21849
|
|
|
21760
21850
|
// all good
|
|
21851
|
+
//console.log('[v] set cur index OUT');
|
|
21761
21852
|
return true;
|
|
21762
21853
|
};
|
|
21763
21854
|
|
|
@@ -26806,13 +26897,16 @@ if (typeof Number.EPSILON === 'undefined') {
|
|
|
26806
26897
|
}
|
|
26807
26898
|
// -> ~2e-12
|
|
26808
26899
|
dwv.math.BIG_EPSILON = Number.EPSILON * 1e4;
|
|
26900
|
+
// 'real world', for example when comparing positions
|
|
26901
|
+
dwv.math.REAL_WORLD_EPSILON = 1e-4;
|
|
26809
26902
|
|
|
26810
26903
|
/**
|
|
26811
26904
|
* Check if two numbers are similar.
|
|
26812
26905
|
*
|
|
26813
26906
|
* @param {number} a The first number.
|
|
26814
26907
|
* @param {number} b The second number.
|
|
26815
|
-
* @param {number} tol The comparison tolerance
|
|
26908
|
+
* @param {number} tol The comparison tolerance
|
|
26909
|
+
* default to Number.EPSILON.
|
|
26816
26910
|
* @returns {boolean} True if similar.
|
|
26817
26911
|
*/
|
|
26818
26912
|
dwv.math.isSimilar = function (a, b, tol) {
|
|
@@ -27499,11 +27593,11 @@ dwv.math.Point3D.prototype.minus = function (point3D) {
|
|
|
27499
27593
|
};
|
|
27500
27594
|
|
|
27501
27595
|
/**
|
|
27502
|
-
* Get an array find callback for
|
|
27596
|
+
* Get an array find callback for an equal input point.
|
|
27503
27597
|
*
|
|
27504
27598
|
* @param {dwv.math.Point3D} point The point to compare to.
|
|
27505
|
-
* @returns {Function} A function that compares
|
|
27506
|
-
* 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.
|
|
27507
27601
|
*/
|
|
27508
27602
|
dwv.math.getEqualPoint3DFunction = function (point) {
|
|
27509
27603
|
return function (element) {
|
|
@@ -27511,6 +27605,21 @@ dwv.math.getEqualPoint3DFunction = function (point) {
|
|
|
27511
27605
|
};
|
|
27512
27606
|
};
|
|
27513
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
|
+
|
|
27514
27623
|
/**
|
|
27515
27624
|
* Immutable point.
|
|
27516
27625
|
* Warning: the input array is NOT cloned, modifying it will
|
|
@@ -35627,6 +35736,25 @@ dwv.tool.ZoomAndPan.prototype.init = function () {
|
|
|
35627
35736
|
var dwv = dwv || {};
|
|
35628
35737
|
dwv.utils = dwv.utils || {};
|
|
35629
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
|
+
|
|
35630
35758
|
/**
|
|
35631
35759
|
* Check for array equality.
|
|
35632
35760
|
*
|
|
@@ -35644,10 +35772,8 @@ dwv.utils.arrayEquals = function (arr0, arr1) {
|
|
|
35644
35772
|
if (arr0.length !== arr1.length) {
|
|
35645
35773
|
return false;
|
|
35646
35774
|
}
|
|
35647
|
-
|
|
35648
|
-
|
|
35649
|
-
return arr0sorted.every(function (element, index) {
|
|
35650
|
-
return element === arr1sorted[index];
|
|
35775
|
+
return arr0.every(function (element, index) {
|
|
35776
|
+
return element === arr1[index];
|
|
35651
35777
|
});
|
|
35652
35778
|
};
|
|
35653
35779
|
|