dwv 0.31.0-beta.12 → 0.31.0-beta.13
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 +8 -1009
- 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.13 2022-09-07 12:27:46 */
|
|
2
2
|
// Inspired from umdjs
|
|
3
3
|
// See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
|
|
4
4
|
(function (root, factory) {
|
|
@@ -4569,7 +4569,7 @@ dwv.dicom = dwv.dicom || {};
|
|
|
4569
4569
|
* @returns {string} The version of the library.
|
|
4570
4570
|
*/
|
|
4571
4571
|
dwv.getVersion = function () {
|
|
4572
|
-
return '0.31.0-beta.
|
|
4572
|
+
return '0.31.0-beta.13';
|
|
4573
4573
|
};
|
|
4574
4574
|
|
|
4575
4575
|
/**
|
|
@@ -19065,7 +19065,8 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
19065
19065
|
ImageOrientationPatient: imageOrientationPatient,
|
|
19066
19066
|
custom: {
|
|
19067
19067
|
segments: segments,
|
|
19068
|
-
frameInfos: frameInfos
|
|
19068
|
+
frameInfos: frameInfos,
|
|
19069
|
+
SOPInstanceUID: dicomElements.getFromKey('x00080018')
|
|
19069
19070
|
}
|
|
19070
19071
|
};
|
|
19071
19072
|
image.setMeta(meta);
|
|
@@ -27752,1011 +27753,6 @@ dwv.tool.draw.ArrowFactory.prototype.update = function (
|
|
|
27752
27753
|
klabel.position(textPos);
|
|
27753
27754
|
};
|
|
27754
27755
|
|
|
27755
|
-
// namespaces
|
|
27756
|
-
// import * as DicomWebViewer from 'dwv';
|
|
27757
|
-
// export const dwv = DicomWebViewer || {};
|
|
27758
|
-
|
|
27759
|
-
|
|
27760
|
-
// -----------------------------------------------------------------------------
|
|
27761
|
-
// -----------------------------------------------------------------------------
|
|
27762
|
-
// Save methods
|
|
27763
|
-
// -----------------------------------------------------------------------------
|
|
27764
|
-
// -----------------------------------------------------------------------------
|
|
27765
|
-
|
|
27766
|
-
/**
|
|
27767
|
-
* Pad an input string with a '0' to form a 2 digit one.
|
|
27768
|
-
*
|
|
27769
|
-
* @param {string} str The string to pad.
|
|
27770
|
-
* @returns {string} The padded string.
|
|
27771
|
-
*/
|
|
27772
|
-
function padZeroTwoDigit(str) {
|
|
27773
|
-
return ('0' + str).slice(-2);
|
|
27774
|
-
}
|
|
27775
|
-
|
|
27776
|
-
/**
|
|
27777
|
-
* Get a DICOM formated date.
|
|
27778
|
-
*
|
|
27779
|
-
* @param {Date} date The date to format.
|
|
27780
|
-
* @returns {string} The formated date.
|
|
27781
|
-
*/
|
|
27782
|
-
dwv.dicom.getFormatedDate = function (date) {
|
|
27783
|
-
// YYYYMMDD
|
|
27784
|
-
return date.getFullYear().toString() +
|
|
27785
|
-
padZeroTwoDigit((date.getMonth() + 1).toString()) +
|
|
27786
|
-
padZeroTwoDigit(date.getDate().toString());
|
|
27787
|
-
};
|
|
27788
|
-
|
|
27789
|
-
/**
|
|
27790
|
-
* Get a DICOM formated time.
|
|
27791
|
-
*
|
|
27792
|
-
* @param {Date} date The date to format.
|
|
27793
|
-
* @returns {string} The formated time.
|
|
27794
|
-
*/
|
|
27795
|
-
dwv.dicom.getFormatedTime = function (date) {
|
|
27796
|
-
// HHMMSS
|
|
27797
|
-
return padZeroTwoDigit(date.getHours().toString()) +
|
|
27798
|
-
padZeroTwoDigit(date.getMinutes().toString()) +
|
|
27799
|
-
padZeroTwoDigit(date.getSeconds().toString());
|
|
27800
|
-
};
|
|
27801
|
-
|
|
27802
|
-
/**
|
|
27803
|
-
* Get a dicom element from a code object.
|
|
27804
|
-
*
|
|
27805
|
-
* @param {object} code The code object.
|
|
27806
|
-
* @returns {object} The dicom element.
|
|
27807
|
-
*/
|
|
27808
|
-
dwv.dicom.getCodeElement = function (code) {
|
|
27809
|
-
var codeElement = {
|
|
27810
|
-
CodeMeaning: code.meaning
|
|
27811
|
-
};
|
|
27812
|
-
if (typeof code.value !== 'undefined') {
|
|
27813
|
-
codeElement.CodeValue = code.value;
|
|
27814
|
-
} else if (typeof code.longValue !== 'undefined') {
|
|
27815
|
-
codeElement.LongCodeValue = code.longValue;
|
|
27816
|
-
} else if (typeof code.urnValue !== 'undefined') {
|
|
27817
|
-
codeElement.URNCodeValue = code.longVaurnValuelue;
|
|
27818
|
-
}
|
|
27819
|
-
if (typeof code.schemeDesignator !== 'undefined') {
|
|
27820
|
-
codeElement.CodingSchemeDesignator = code.schemeDesignator;
|
|
27821
|
-
}
|
|
27822
|
-
return codeElement;
|
|
27823
|
-
};
|
|
27824
|
-
|
|
27825
|
-
/**
|
|
27826
|
-
* Get a dicom element from a segment object.
|
|
27827
|
-
*
|
|
27828
|
-
* @param {object} segment The segment object.
|
|
27829
|
-
* @returns {object} The dicom element.
|
|
27830
|
-
*/
|
|
27831
|
-
dwv.dicom.getSegmentElement = function (segment) {
|
|
27832
|
-
var algoType = segment.algorithmType;
|
|
27833
|
-
if (typeof algoType === 'undefined') {
|
|
27834
|
-
algoType = 'MANUAL';
|
|
27835
|
-
}
|
|
27836
|
-
var segmentElement = {
|
|
27837
|
-
SegmentNumber: segment.number,
|
|
27838
|
-
SegmentLabel: segment.label,
|
|
27839
|
-
SegmentAlgorithmType: algoType,
|
|
27840
|
-
SegmentedPropertyCategoryCodeSequence: {
|
|
27841
|
-
item0: dwv.dicom.getCodeElement(segment.propertyCategoryCode)
|
|
27842
|
-
},
|
|
27843
|
-
SegmentedPropertyTypeCodeSequence: {
|
|
27844
|
-
item0: dwv.dicom.getCodeElement(segment.propertyTypeCode)
|
|
27845
|
-
}
|
|
27846
|
-
};
|
|
27847
|
-
// display value
|
|
27848
|
-
if (typeof segment.displayValue.r !== 'undefined' &&
|
|
27849
|
-
typeof segment.displayValue.g !== 'undefined' &&
|
|
27850
|
-
typeof segment.displayValue.b !== 'undefined') {
|
|
27851
|
-
var cieLab = dwv.utils.labToUintLab(
|
|
27852
|
-
dwv.utils.srgbToCielab(segment.displayValue));
|
|
27853
|
-
segmentElement.RecommendedDisplayCIELabValue = new Uint16Array([
|
|
27854
|
-
Math.round(cieLab.l),
|
|
27855
|
-
Math.round(cieLab.a),
|
|
27856
|
-
Math.round(cieLab.b)
|
|
27857
|
-
]);
|
|
27858
|
-
} else {
|
|
27859
|
-
segmentElement.RecommendedDisplayGrayscaleValue = segment.displayValue;
|
|
27860
|
-
}
|
|
27861
|
-
// algo name
|
|
27862
|
-
if (algoType !== 'MANUAL' && typeof segment.algorithmName !== 'undefined') {
|
|
27863
|
-
segmentElement.SegmentAlgorithmName = segment.algorithmName;
|
|
27864
|
-
}
|
|
27865
|
-
return segmentElement;
|
|
27866
|
-
};
|
|
27867
|
-
|
|
27868
|
-
/**
|
|
27869
|
-
* Get a dicom element from a dimension index object.
|
|
27870
|
-
*
|
|
27871
|
-
* @param {object} dimensionIndex The dimension index object.
|
|
27872
|
-
* @returns {object} The dicom element.
|
|
27873
|
-
*/
|
|
27874
|
-
dwv.dicom.getDimensionIndexElement = function (dimensionIndex) {
|
|
27875
|
-
var indexElement = {
|
|
27876
|
-
DimensionOrganizationUID: dimensionIndex.organization,
|
|
27877
|
-
DimensionIndexPointer: [dimensionIndex.pointer]
|
|
27878
|
-
};
|
|
27879
|
-
if (typeof dimensionIndex.label !== 'undefined') {
|
|
27880
|
-
indexElement.DimensionDescriptionLabel = dimensionIndex.label;
|
|
27881
|
-
}
|
|
27882
|
-
return indexElement;
|
|
27883
|
-
};
|
|
27884
|
-
|
|
27885
|
-
/**
|
|
27886
|
-
* Get a dicom element from a frame information object.
|
|
27887
|
-
*
|
|
27888
|
-
* @param {object} frameInfo The frame information object.
|
|
27889
|
-
* @returns {object} The dicom element.
|
|
27890
|
-
*/
|
|
27891
|
-
dwv.dicom.getSegmentFrameInfoElement = function (frameInfo) {
|
|
27892
|
-
return {
|
|
27893
|
-
FrameContentSequence: {
|
|
27894
|
-
item0: {
|
|
27895
|
-
DimensionIndexValues: frameInfo.dimIndex
|
|
27896
|
-
}
|
|
27897
|
-
},
|
|
27898
|
-
PlanePositionSequence: {
|
|
27899
|
-
item0: {
|
|
27900
|
-
ImagePositionPatient: frameInfo.imagePosPat
|
|
27901
|
-
}
|
|
27902
|
-
},
|
|
27903
|
-
SegmentIdentificationSequence: {
|
|
27904
|
-
item0: {
|
|
27905
|
-
ReferencedSegmentNumber: frameInfo.refSegmentNumber.toString()
|
|
27906
|
-
}
|
|
27907
|
-
}
|
|
27908
|
-
};
|
|
27909
|
-
};
|
|
27910
|
-
|
|
27911
|
-
/**
|
|
27912
|
-
* Get a dicom element from a spacing object.
|
|
27913
|
-
*
|
|
27914
|
-
* @param {object} spacing The spacing object.
|
|
27915
|
-
* @returns {object} The dicom element.
|
|
27916
|
-
*/
|
|
27917
|
-
dwv.dicom.getMeasureSequenceElement = function (spacing) {
|
|
27918
|
-
return {
|
|
27919
|
-
item0: {
|
|
27920
|
-
PixelSpacing: [spacing.get(1), spacing.get(0)],
|
|
27921
|
-
SpacingBetweenSlices: spacing.get(2).toString()
|
|
27922
|
-
}
|
|
27923
|
-
};
|
|
27924
|
-
};
|
|
27925
|
-
|
|
27926
|
-
/**
|
|
27927
|
-
* Convert a mask image into a DICOM segmentation object.
|
|
27928
|
-
*
|
|
27929
|
-
* @param {dwv.image.Image} image The mask image.
|
|
27930
|
-
* @param {Array} segments The mask segments.
|
|
27931
|
-
* @returns {object} A list of dicom elements.
|
|
27932
|
-
*/
|
|
27933
|
-
dwv.image.MaskFactory.prototype.toDicom = function (image, segments) {
|
|
27934
|
-
// use image segments if not provided as input
|
|
27935
|
-
if (typeof segments === 'undefined') {
|
|
27936
|
-
segments = image.getMeta().segments;
|
|
27937
|
-
}
|
|
27938
|
-
|
|
27939
|
-
var geometry = image.getGeometry();
|
|
27940
|
-
var size = geometry.getSize();
|
|
27941
|
-
var spacing = geometry.getSpacing();
|
|
27942
|
-
var numberOfComponents = image.getNumberOfComponents();
|
|
27943
|
-
var isRGB = numberOfComponents === 3;
|
|
27944
|
-
var orientationPatient = image.getMeta().ImageOrientationPatient;
|
|
27945
|
-
|
|
27946
|
-
var now = new Date();
|
|
27947
|
-
|
|
27948
|
-
// base tags
|
|
27949
|
-
var tags = {
|
|
27950
|
-
TransferSyntaxUID: '1.2.840.10008.1.2.1',
|
|
27951
|
-
MediaStorageSOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
27952
|
-
SOPClassUID: '1.2.840.10008.5.1.4.1.1.66.4',
|
|
27953
|
-
Modality: 'SEG',
|
|
27954
|
-
SegmentationType: 'BINARY',
|
|
27955
|
-
DimensionOrganizationType: '3D',
|
|
27956
|
-
PhotometricInterpretation: 'MONOCHROME2',
|
|
27957
|
-
ImageType: ['DERIVED', 'PRIMARY'],
|
|
27958
|
-
SamplesPerPixel: 1,
|
|
27959
|
-
PixelRepresentation: 0,
|
|
27960
|
-
BitsAllocated: 1,
|
|
27961
|
-
BitsStored: 1,
|
|
27962
|
-
HighBit: 0,
|
|
27963
|
-
PatientName: image.getMeta().PatientName,
|
|
27964
|
-
PatientID: image.getMeta().PatientID,
|
|
27965
|
-
PatientBirthDate: image.getMeta().PatientBirthDate,
|
|
27966
|
-
PatientSex: image.getMeta().PatientSex,
|
|
27967
|
-
ContentDate: dwv.dicom.getFormatedDate(now),
|
|
27968
|
-
ContentTime: dwv.dicom.getFormatedTime(now),
|
|
27969
|
-
ContentLabel: 'QUIBIM edited prostate segmentation',
|
|
27970
|
-
StudyInstanceUID: image.getMeta().StudyInstanceUID,
|
|
27971
|
-
Rows: size.get(1),
|
|
27972
|
-
Columns: size.get(0)
|
|
27973
|
-
};
|
|
27974
|
-
|
|
27975
|
-
// TODO: update numbers
|
|
27976
|
-
tags.SeriesInstanceUID = image.getMeta().SeriesInstanceUID;
|
|
27977
|
-
tags.SeriesNumber = image.getMeta().SeriesNumber;
|
|
27978
|
-
|
|
27979
|
-
// TODO: get from original file
|
|
27980
|
-
tags.LossyImageCompression = '00';
|
|
27981
|
-
tags.InstanceNumber = 0;
|
|
27982
|
-
|
|
27983
|
-
// use existing dimension organization if present
|
|
27984
|
-
if (typeof image.getMeta().DimensionOrganizations !== 'undefined') {
|
|
27985
|
-
var orgs = image.getMeta().DimensionOrganizations;
|
|
27986
|
-
// should be only one
|
|
27987
|
-
tags.DimensionOrganizationSequence = {
|
|
27988
|
-
item0: {
|
|
27989
|
-
DimensionOrganizationUID: orgs[0]
|
|
27990
|
-
}
|
|
27991
|
-
};
|
|
27992
|
-
}
|
|
27993
|
-
// use existing dimension organization if present
|
|
27994
|
-
if (typeof image.getMeta().DimensionIndices !== 'undefined') {
|
|
27995
|
-
var indices = image.getMeta().DimensionIndices;
|
|
27996
|
-
var indicesTag = {};
|
|
27997
|
-
for (var m = 0; m < indices.length; ++m) {
|
|
27998
|
-
indicesTag['item' + m] = dwv.dicom.getDimensionIndexElement(indices[m]);
|
|
27999
|
-
}
|
|
28000
|
-
tags.DimensionIndexSequence = indicesTag;
|
|
28001
|
-
}
|
|
28002
|
-
|
|
28003
|
-
// segments
|
|
28004
|
-
var segmentsTag = {};
|
|
28005
|
-
for (var l = 0; l < segments.length; ++l) {
|
|
28006
|
-
segmentsTag['item' + l] = dwv.dicom.getSegmentElement(segments[l]);
|
|
28007
|
-
}
|
|
28008
|
-
tags.SegmentSequence = segmentsTag;
|
|
28009
|
-
|
|
28010
|
-
// Shared Functional Groups Sequence
|
|
28011
|
-
tags.SharedFunctionalGroupsSequence = {
|
|
28012
|
-
item0: {
|
|
28013
|
-
PlaneOrientationSequence: {
|
|
28014
|
-
item0: {
|
|
28015
|
-
ImageOrientationPatient: orientationPatient
|
|
28016
|
-
}
|
|
28017
|
-
},
|
|
28018
|
-
PixelMeasuresSequence: dwv.dicom.getMeasureSequenceElement(spacing)
|
|
28019
|
-
}
|
|
28020
|
-
};
|
|
28021
|
-
|
|
28022
|
-
var getPixelValue;
|
|
28023
|
-
var equalValues;
|
|
28024
|
-
if (isRGB) {
|
|
28025
|
-
getPixelValue = function (inputOffset) {
|
|
28026
|
-
return {
|
|
28027
|
-
r: image.getValueAtOffset(inputOffset, 0),
|
|
28028
|
-
g: image.getValueAtOffset(inputOffset + 1, 0),
|
|
28029
|
-
b: image.getValueAtOffset(inputOffset + 2, 0)
|
|
28030
|
-
};
|
|
28031
|
-
};
|
|
28032
|
-
equalValues = function (a, b) {
|
|
28033
|
-
return a.r === b.r &&
|
|
28034
|
-
a.g === b.g &&
|
|
28035
|
-
a.b === b.b;
|
|
28036
|
-
};
|
|
28037
|
-
} else {
|
|
28038
|
-
getPixelValue = function (inputOffset) {
|
|
28039
|
-
return image.getValueAtOffset(inputOffset, 0);
|
|
28040
|
-
};
|
|
28041
|
-
equalValues = function (a, b) {
|
|
28042
|
-
return a === b;
|
|
28043
|
-
};
|
|
28044
|
-
}
|
|
28045
|
-
|
|
28046
|
-
// image buffer to multi frame
|
|
28047
|
-
var sliceSize = size.getDimSize(2);
|
|
28048
|
-
var roiBuffers = {};
|
|
28049
|
-
for (var k = 0; k < size.get(2); ++k) {
|
|
28050
|
-
var sliceOffset = k * sliceSize;
|
|
28051
|
-
// initialise buffers
|
|
28052
|
-
var buffers = {};
|
|
28053
|
-
// search pixels
|
|
28054
|
-
for (var o = 0; o < sliceSize; ++o) {
|
|
28055
|
-
var inputOffset = (sliceOffset + o) * numberOfComponents;
|
|
28056
|
-
var pixelValue = getPixelValue(inputOffset);
|
|
28057
|
-
for (var n2 = 0; n2 < segments.length; ++n2) {
|
|
28058
|
-
var number2 = segments[n2].number - 1;
|
|
28059
|
-
if (equalValues(pixelValue, segments[n2].displayValue)) {
|
|
28060
|
-
if (typeof buffers[number2] === 'undefined') {
|
|
28061
|
-
buffers[number2] = new Uint8Array(sliceSize);
|
|
28062
|
-
}
|
|
28063
|
-
buffers[number2][o] = 1;
|
|
28064
|
-
}
|
|
28065
|
-
}
|
|
28066
|
-
}
|
|
28067
|
-
|
|
28068
|
-
// store slice buffers
|
|
28069
|
-
var keys0 = Object.keys(buffers);
|
|
28070
|
-
for (var k0 = 0; k0 < keys0.length; ++k0) {
|
|
28071
|
-
var key0 = keys0[k0];
|
|
28072
|
-
if (typeof roiBuffers[key0] === 'undefined') {
|
|
28073
|
-
roiBuffers[key0] = {};
|
|
28074
|
-
}
|
|
28075
|
-
// ordering by slice index (follows posPat)
|
|
28076
|
-
roiBuffers[key0][k] = buffers[key0];
|
|
28077
|
-
}
|
|
28078
|
-
}
|
|
28079
|
-
|
|
28080
|
-
var frameInfos = [];
|
|
28081
|
-
|
|
28082
|
-
// flatten buffer array
|
|
28083
|
-
var finalBuffers = [];
|
|
28084
|
-
for (var n4 = 0; n4 < segments.length; ++n4) {
|
|
28085
|
-
var number40 = segments[n4].number;
|
|
28086
|
-
var number4 = number40 - 1;
|
|
28087
|
-
var keys1 = Object.keys(roiBuffers[number4]);
|
|
28088
|
-
// revert slice order
|
|
28089
|
-
for (var k1 = keys1.length - 1; k1 >= 0; --k1) {
|
|
28090
|
-
var key1 = keys1[k1];
|
|
28091
|
-
finalBuffers.push(roiBuffers[number4][key1]);
|
|
28092
|
-
// frame info
|
|
28093
|
-
var posPat = image.getGeometry().getOrigins()[key1];
|
|
28094
|
-
frameInfos.push({
|
|
28095
|
-
dimIndex: [number40, keys1.length - k1],
|
|
28096
|
-
imagePosPat: [posPat.getX(), posPat.getY(), posPat.getZ()],
|
|
28097
|
-
refSegmentNumber: number40
|
|
28098
|
-
});
|
|
28099
|
-
}
|
|
28100
|
-
}
|
|
28101
|
-
|
|
28102
|
-
tags.NumberOfFrames = finalBuffers.length.toString();
|
|
28103
|
-
|
|
28104
|
-
// frame infos
|
|
28105
|
-
var frameInfosTag = {};
|
|
28106
|
-
for (var f = 0; f < frameInfos.length; ++f) {
|
|
28107
|
-
frameInfosTag['item' + f] =
|
|
28108
|
-
dwv.dicom.getSegmentFrameInfoElement(frameInfos[f]);
|
|
28109
|
-
}
|
|
28110
|
-
tags.PerFrameFunctionalGroupsSequence = frameInfosTag;
|
|
28111
|
-
|
|
28112
|
-
// convert JSON to DICOM element object
|
|
28113
|
-
var res = dwv.dicom.getElementsFromJSONTags(tags);
|
|
28114
|
-
var dicomElements = res.elements;
|
|
28115
|
-
|
|
28116
|
-
// pixel value length: divide by 8 to trigger binary write
|
|
28117
|
-
var pixVl = finalBuffers.length * sliceSize / 8;
|
|
28118
|
-
dicomElements.x7FE00010 = {
|
|
28119
|
-
tag: {group: '0x7FE0', element: '0x0010', name: 'x7FE00010'},
|
|
28120
|
-
vr: 'OB',
|
|
28121
|
-
vl: pixVl,
|
|
28122
|
-
value: finalBuffers,
|
|
28123
|
-
startOffset: res.offset,
|
|
28124
|
-
endOffset: res.offset + pixVl
|
|
28125
|
-
};
|
|
28126
|
-
|
|
28127
|
-
return dicomElements;
|
|
28128
|
-
};
|
|
28129
|
-
|
|
28130
|
-
// -----------------------------------------------------------------------------
|
|
28131
|
-
// -----------------------------------------------------------------------------
|
|
28132
|
-
// -----------------------------------------------------------------------------
|
|
28133
|
-
// -----------------------------------------------------------------------------
|
|
28134
|
-
|
|
28135
|
-
// namespaces
|
|
28136
|
-
// var dwv = dwv || {};
|
|
28137
|
-
dwv.tool = dwv.tool || {};
|
|
28138
|
-
|
|
28139
|
-
/**
|
|
28140
|
-
* Get the indices that form a circle.
|
|
28141
|
-
* Can be an ellipse to adapt to view.
|
|
28142
|
-
*
|
|
28143
|
-
* @param {dwv.image.Geometry} geometry The geometry.
|
|
28144
|
-
* @param {dwv.math.Point3D} position The circle center.
|
|
28145
|
-
* @param {Array} radiuses The circle radiuses.
|
|
28146
|
-
* @param {Array} dims The 2 dimensions.
|
|
28147
|
-
* @returns {Array} The indices of the circle.
|
|
28148
|
-
*/
|
|
28149
|
-
dwv.tool.getCircleIndices = function (geometry, position, radiuses, dims) {
|
|
28150
|
-
const centerIndex = geometry.worldToIndex(position);
|
|
28151
|
-
return dwv.math.getEllipseIndices(centerIndex, radiuses, dims);
|
|
28152
|
-
};
|
|
28153
|
-
|
|
28154
|
-
/**
|
|
28155
|
-
* Get the data origins that correspond to input indices.
|
|
28156
|
-
*
|
|
28157
|
-
* @param {dwv.image.Geometry} geometry The geometry.
|
|
28158
|
-
* @param {Array} allOrigins All orign array.
|
|
28159
|
-
* @param {Array} indices An array of dwv.math.Index.
|
|
28160
|
-
* @returns {Array} An array of origins (dwv.math.Point3D).
|
|
28161
|
-
*/
|
|
28162
|
-
dwv.tool.getOriginsFromIndices = function (geometry, allOrigins, indices) {
|
|
28163
|
-
const sorted = indices.sort(dwv.math.getIndexCompareFunction(2)); //NOSONAR
|
|
28164
|
-
|
|
28165
|
-
const origin0 = geometry.indexToWorld(sorted[0]);
|
|
28166
|
-
const origin1 = geometry.indexToWorld(sorted[sorted.length - 1]);
|
|
28167
|
-
|
|
28168
|
-
const getEqualZ = function (point) {
|
|
28169
|
-
return function equalZ(x) {
|
|
28170
|
-
return x.getZ() === point.get(2);
|
|
28171
|
-
};
|
|
28172
|
-
};
|
|
28173
|
-
|
|
28174
|
-
let iStart = allOrigins.findIndex(getEqualZ(origin0));
|
|
28175
|
-
if (iStart === -1) {
|
|
28176
|
-
iStart = 0;
|
|
28177
|
-
}
|
|
28178
|
-
let iEnd = allOrigins.findIndex(getEqualZ(origin1));
|
|
28179
|
-
if (iEnd === -1) {
|
|
28180
|
-
iEnd = allOrigins.length - 1;
|
|
28181
|
-
}
|
|
28182
|
-
|
|
28183
|
-
return allOrigins.slice(iStart, iEnd + 1);
|
|
28184
|
-
};
|
|
28185
|
-
|
|
28186
|
-
/**
|
|
28187
|
-
* Get the data offsets that correspond to input indices.
|
|
28188
|
-
*
|
|
28189
|
-
* @param {dwv.image.Geometry} geometry The geometry.
|
|
28190
|
-
* @param {Array} indices An array of dwv.math.Index.
|
|
28191
|
-
* @returns {Array} An array of offsets.
|
|
28192
|
-
*/
|
|
28193
|
-
dwv.tool.getOffsetsFromIndices = function (geometry, indices) {
|
|
28194
|
-
const imageSize = geometry.getSize();
|
|
28195
|
-
const offsets = [];
|
|
28196
|
-
for (let i = 0; i < indices.length; ++i) {
|
|
28197
|
-
offsets.push(imageSize.indexToOffset(indices[i]));
|
|
28198
|
-
}
|
|
28199
|
-
return offsets;
|
|
28200
|
-
};
|
|
28201
|
-
|
|
28202
|
-
/**
|
|
28203
|
-
* Brush class.
|
|
28204
|
-
*
|
|
28205
|
-
* @class
|
|
28206
|
-
* @param {dwv.App} app The associated application.
|
|
28207
|
-
*/
|
|
28208
|
-
dwv.tool.Brush = function (app) {
|
|
28209
|
-
/**
|
|
28210
|
-
* Closure to self: to be used by event handlers.
|
|
28211
|
-
*
|
|
28212
|
-
* @private
|
|
28213
|
-
* @type {dwv.tool.Brush}
|
|
28214
|
-
*/
|
|
28215
|
-
const self = this;
|
|
28216
|
-
|
|
28217
|
-
/**
|
|
28218
|
-
* Interaction start flag.
|
|
28219
|
-
*
|
|
28220
|
-
* @type {boolean}
|
|
28221
|
-
*/
|
|
28222
|
-
this.started = false;
|
|
28223
|
-
|
|
28224
|
-
let mask = null;
|
|
28225
|
-
let maskId = null;
|
|
28226
|
-
|
|
28227
|
-
let brushSize = 2;
|
|
28228
|
-
let brushMode = 'add';
|
|
28229
|
-
|
|
28230
|
-
let segments = [
|
|
28231
|
-
{
|
|
28232
|
-
number: 1,
|
|
28233
|
-
label: 'Red',
|
|
28234
|
-
algorithmType: 'MANUAL',
|
|
28235
|
-
displayValue: {r: 255, g: 0, b: 0}
|
|
28236
|
-
},
|
|
28237
|
-
{
|
|
28238
|
-
number: 2,
|
|
28239
|
-
label: 'Green',
|
|
28240
|
-
algorithmType: 'MANUAL',
|
|
28241
|
-
displayValue: {r: 0, g: 255, b: 0}
|
|
28242
|
-
},
|
|
28243
|
-
{
|
|
28244
|
-
number: 3,
|
|
28245
|
-
label: 'Blue',
|
|
28246
|
-
algorithmType: 'MANUAL',
|
|
28247
|
-
displayValue: {r: 0, g: 0, b: 255}
|
|
28248
|
-
}
|
|
28249
|
-
];
|
|
28250
|
-
let selectedSegment = 0;
|
|
28251
|
-
// undefined, 'replace' or 'add'
|
|
28252
|
-
let newSegmentBehaviour = 'replace';
|
|
28253
|
-
|
|
28254
|
-
let uid = 0;
|
|
28255
|
-
|
|
28256
|
-
/**
|
|
28257
|
-
* Get a mask slice.
|
|
28258
|
-
*
|
|
28259
|
-
* @param {object} geometry The mask geometry.
|
|
28260
|
-
* @param {dwv.math.Point3D} origin The slice origin.
|
|
28261
|
-
* @param {object} meta The mask meta.
|
|
28262
|
-
* @returns {dwv.image.Image} The slice.
|
|
28263
|
-
*/
|
|
28264
|
-
function createMaskImage(geometry, origin, meta) {
|
|
28265
|
-
// create data
|
|
28266
|
-
const sizeValues = geometry.getSize().getValues();
|
|
28267
|
-
sizeValues[2] = 1;
|
|
28268
|
-
const maskSize = new dwv.image.Size(sizeValues);
|
|
28269
|
-
const maskGeometry = new dwv.image.Geometry(
|
|
28270
|
-
origin,
|
|
28271
|
-
maskSize,
|
|
28272
|
-
geometry.getSpacing(),
|
|
28273
|
-
geometry.getOrientation());
|
|
28274
|
-
const values = new Uint8Array(maskSize.getDimSize(2) * 3);
|
|
28275
|
-
values.fill(0);
|
|
28276
|
-
++uid;
|
|
28277
|
-
const uids = [uid];
|
|
28278
|
-
const maskSlice = new dwv.image.Image(maskGeometry, values, uids);
|
|
28279
|
-
maskSlice.setMeta(meta);
|
|
28280
|
-
maskSlice.setPhotometricInterpretation('RGB');
|
|
28281
|
-
|
|
28282
|
-
return maskSlice;
|
|
28283
|
-
}
|
|
28284
|
-
|
|
28285
|
-
/**
|
|
28286
|
-
* Add slices to mask if needed.
|
|
28287
|
-
*
|
|
28288
|
-
* @param {dwv.image.Geometry} baseGeometry The base geometry.
|
|
28289
|
-
* @param {Array} allOrigins All orign array.
|
|
28290
|
-
* @param {dwv.image.Geometry} maskGeometry The mask geometry.
|
|
28291
|
-
* @param {dwv.math.Point3D} position The circle center.
|
|
28292
|
-
* @param {Array} circleDims The circle dimensions.
|
|
28293
|
-
* @param {Array} radiuses The circle radiuses.
|
|
28294
|
-
* @param {object} sliceMeta The slice meta.
|
|
28295
|
-
* @returns {boolean} True if slices were added.
|
|
28296
|
-
*/
|
|
28297
|
-
function addMaskSlices(
|
|
28298
|
-
baseGeometry, allOrigins,
|
|
28299
|
-
maskGeometry, position, circleDims, radiuses, sliceMeta) {
|
|
28300
|
-
// circle indices in the image geometry
|
|
28301
|
-
const circleIndices =
|
|
28302
|
-
dwv.tool.getCircleIndices(baseGeometry, position, radiuses, circleDims);
|
|
28303
|
-
const origins =
|
|
28304
|
-
dwv.tool.getOriginsFromIndices(baseGeometry, allOrigins, circleIndices);
|
|
28305
|
-
if (origins.length === 0) {
|
|
28306
|
-
throw new Error('No brush origins...');
|
|
28307
|
-
}
|
|
28308
|
-
|
|
28309
|
-
// get origins that need to be added
|
|
28310
|
-
const origins0 = [];
|
|
28311
|
-
const originsBelow = [];
|
|
28312
|
-
let isAbove = true;
|
|
28313
|
-
let hasCommon = false;
|
|
28314
|
-
// origins start from the top of the circle, first ones (if any)
|
|
28315
|
-
// are above mask origins
|
|
28316
|
-
for (let i = 0; i < origins.length; ++i) {
|
|
28317
|
-
if (!maskGeometry.includesOrigin(origins[i])) {
|
|
28318
|
-
if (isAbove) {
|
|
28319
|
-
origins0.push(origins[i]);
|
|
28320
|
-
} else {
|
|
28321
|
-
originsBelow.push(origins[i]);
|
|
28322
|
-
}
|
|
28323
|
-
} else {
|
|
28324
|
-
isAbove = false;
|
|
28325
|
-
hasCommon = true;
|
|
28326
|
-
}
|
|
28327
|
-
}
|
|
28328
|
-
|
|
28329
|
-
// append slices if needed
|
|
28330
|
-
let originsToAdd = [];
|
|
28331
|
-
|
|
28332
|
-
if (hasCommon) {
|
|
28333
|
-
// common slice case
|
|
28334
|
-
// reverse origins0 to go from existing mask to new one
|
|
28335
|
-
originsToAdd = origins0.reverse().concat(originsBelow);
|
|
28336
|
-
} else {
|
|
28337
|
-
// non common slice case: add in between slices
|
|
28338
|
-
const maskOrigins = maskGeometry.getOrigins();
|
|
28339
|
-
const firstMask = maskOrigins[0];
|
|
28340
|
-
const lastMask = maskOrigins[maskOrigins.length - 1];
|
|
28341
|
-
const firstOrigin = origins0[0];
|
|
28342
|
-
const lastOrigin = origins0[origins0.length - 1];
|
|
28343
|
-
const distanceAbove = firstMask.getDistance(lastOrigin);
|
|
28344
|
-
const distanceBelow = lastMask.getDistance(firstOrigin);
|
|
28345
|
-
|
|
28346
|
-
const imageOrigins = app.getImage(0).getGeometry().getOrigins();
|
|
28347
|
-
if (distanceAbove < distanceBelow) {
|
|
28348
|
-
// in between above
|
|
28349
|
-
const i00 = imageOrigins.findIndex(
|
|
28350
|
-
dwv.math.getEqualPoint3DFunction(lastOrigin));
|
|
28351
|
-
const i01 = imageOrigins.findIndex(
|
|
28352
|
-
dwv.math.getEqualPoint3DFunction(firstMask));
|
|
28353
|
-
|
|
28354
|
-
// reverse to go from existing mask to new one
|
|
28355
|
-
originsToAdd = imageOrigins.slice(i00 + 1, i01).reverse().concat(
|
|
28356
|
-
origins0.reverse()); //NOSONAR
|
|
28357
|
-
} else {
|
|
28358
|
-
// in between bellow
|
|
28359
|
-
const i10 = imageOrigins.findIndex(
|
|
28360
|
-
dwv.math.getEqualPoint3DFunction(lastMask));
|
|
28361
|
-
const i11 = imageOrigins.findIndex(
|
|
28362
|
-
dwv.math.getEqualPoint3DFunction(firstOrigin));
|
|
28363
|
-
|
|
28364
|
-
originsToAdd = imageOrigins.slice(i10 + 1, i11).concat(origins0);
|
|
28365
|
-
}
|
|
28366
|
-
}
|
|
28367
|
-
|
|
28368
|
-
// append slices
|
|
28369
|
-
// TODO: add image multi slice append?
|
|
28370
|
-
for (let l = 0; l < originsToAdd.length; ++l) {
|
|
28371
|
-
mask.getMeta().numberOfFiles += 1;
|
|
28372
|
-
mask.appendSlice(
|
|
28373
|
-
createMaskImage(maskGeometry, originsToAdd[l], sliceMeta));
|
|
28374
|
-
}
|
|
28375
|
-
|
|
28376
|
-
return originsToAdd.length !== 0;
|
|
28377
|
-
}
|
|
28378
|
-
|
|
28379
|
-
/**
|
|
28380
|
-
* Paint the mask at the given offsets.
|
|
28381
|
-
*
|
|
28382
|
-
* @param {Array} offsets The mask offsets.
|
|
28383
|
-
*/
|
|
28384
|
-
function paintMaskAtOffsets(offsets) {
|
|
28385
|
-
const buff = mask.getBuffer();
|
|
28386
|
-
const colour = segments[selectedSegment].displayValue;
|
|
28387
|
-
for (let i = 0; i < offsets.length; ++i) {
|
|
28388
|
-
const offset = offsets[i] * 3;
|
|
28389
|
-
buff[offset] = brushMode === 'add' ? colour.r : 0;
|
|
28390
|
-
buff[offset + 1] = brushMode === 'add' ? colour.g : 0;
|
|
28391
|
-
buff[offset + 2] = brushMode === 'add' ? colour.b : 0;
|
|
28392
|
-
}
|
|
28393
|
-
// update segment
|
|
28394
|
-
segments[selectedSegment].algorithmType = 'MANUAL';
|
|
28395
|
-
delete segments[selectedSegment].algorithmName;
|
|
28396
|
-
// update app image
|
|
28397
|
-
app.setImage(maskId, mask);
|
|
28398
|
-
// render
|
|
28399
|
-
app.render(maskId);
|
|
28400
|
-
}
|
|
28401
|
-
|
|
28402
|
-
/**
|
|
28403
|
-
* Get the mask offset for an event.
|
|
28404
|
-
*
|
|
28405
|
-
* @param {object} event The event containing the mask position.
|
|
28406
|
-
* @returns {Array} The array of offset to paint.
|
|
28407
|
-
*/
|
|
28408
|
-
function getMaskOffsets(event) {
|
|
28409
|
-
const layerDetails = dwv.gui.getLayerDetailsFromEvent(event);
|
|
28410
|
-
const layerGroup = app.getLayerGroupById(layerDetails.groupId);
|
|
28411
|
-
|
|
28412
|
-
// reference image related vars
|
|
28413
|
-
const viewLayer = layerGroup.getActiveViewLayer();
|
|
28414
|
-
const planePos = viewLayer.displayToPlanePos(event._x, event._y);
|
|
28415
|
-
const viewController = viewLayer.getViewController();
|
|
28416
|
-
const position = viewController.getPositionFromPlanePoint(planePos);
|
|
28417
|
-
|
|
28418
|
-
const sliceMeta = {
|
|
28419
|
-
Modality: 'SEG',
|
|
28420
|
-
IsSigned: false,
|
|
28421
|
-
numberOfFiles: 1,
|
|
28422
|
-
BitsStored: 1
|
|
28423
|
-
};
|
|
28424
|
-
|
|
28425
|
-
const searchMaskMeta = {
|
|
28426
|
-
Modality: 'SEG'
|
|
28427
|
-
};
|
|
28428
|
-
const isMaskVc = viewController.equalImageMeta(searchMaskMeta);
|
|
28429
|
-
|
|
28430
|
-
// base image geometry
|
|
28431
|
-
const baseImage = app.getImage(0);
|
|
28432
|
-
let baseGeometry = baseImage.getGeometry();
|
|
28433
|
-
|
|
28434
|
-
if (isMaskVc) {
|
|
28435
|
-
// udpate an existing mask
|
|
28436
|
-
mask = app.getImage(event.dataindex);
|
|
28437
|
-
maskId = event.dataindex;
|
|
28438
|
-
baseGeometry = mask.getGeometry();
|
|
28439
|
-
// update segments if needed
|
|
28440
|
-
if (typeof newSegmentBehaviour !== 'undefined') {
|
|
28441
|
-
updateSegments(mask.getMeta().custom.segments);
|
|
28442
|
-
}
|
|
28443
|
-
}
|
|
28444
|
-
|
|
28445
|
-
// create mask if not done yet
|
|
28446
|
-
let maskVl = viewLayer;
|
|
28447
|
-
let maskVc = viewController;
|
|
28448
|
-
if (!mask) {
|
|
28449
|
-
const imgK = baseGeometry.worldToIndex(position).get(2);
|
|
28450
|
-
|
|
28451
|
-
const firstSliceMeta = sliceMeta;
|
|
28452
|
-
firstSliceMeta.SeriesInstanceUID =
|
|
28453
|
-
baseImage.getMeta().SeriesInstanceUID;
|
|
28454
|
-
firstSliceMeta.ImageOrientationPatient =
|
|
28455
|
-
baseImage.getMeta().ImageOrientationPatient;
|
|
28456
|
-
|
|
28457
|
-
mask = createMaskImage(
|
|
28458
|
-
baseGeometry, baseGeometry.getOrigins()[imgK], firstSliceMeta);
|
|
28459
|
-
// fires load events and renders data
|
|
28460
|
-
maskId = app.addNewImage(mask, {});
|
|
28461
|
-
|
|
28462
|
-
// newly create mask case: find the SEG view layer
|
|
28463
|
-
const maskViewLayers = layerGroup.searchViewLayers(searchMaskMeta);
|
|
28464
|
-
if (maskViewLayers.length === 0) {
|
|
28465
|
-
console.warn('No mask view layers');
|
|
28466
|
-
} else if (maskViewLayers.length !== 1) {
|
|
28467
|
-
console.warn('Too many mask view layers', maskViewLayers.length);
|
|
28468
|
-
}
|
|
28469
|
-
maskVl = maskViewLayers[0];
|
|
28470
|
-
maskVc = maskVl.getViewController();
|
|
28471
|
-
}
|
|
28472
|
-
|
|
28473
|
-
sliceMeta.SeriesInstanceUID = mask.getMeta().SeriesInstanceUID;
|
|
28474
|
-
sliceMeta.ImageOrientationPatient =
|
|
28475
|
-
mask.getMeta().ImageOrientationPatient;
|
|
28476
|
-
|
|
28477
|
-
const maskGeometry = mask.getGeometry();
|
|
28478
|
-
|
|
28479
|
-
const scrollIndex = viewController.getScrollIndex();
|
|
28480
|
-
let circleDims;
|
|
28481
|
-
let radiuses;
|
|
28482
|
-
const spacing = baseGeometry.getSpacing(baseGeometry.getOrientation());
|
|
28483
|
-
const r0 = Math.round(brushSize / spacing.get(0));
|
|
28484
|
-
const r1 = Math.round(brushSize / spacing.get(1));
|
|
28485
|
-
const r2 = Math.round(brushSize / spacing.get(2));
|
|
28486
|
-
if (scrollIndex === 0) {
|
|
28487
|
-
circleDims = [1, 2];
|
|
28488
|
-
radiuses = [r1, r2];
|
|
28489
|
-
} else if (scrollIndex === 1) {
|
|
28490
|
-
circleDims = [0, 2];
|
|
28491
|
-
radiuses = [r0, r2];
|
|
28492
|
-
} else if (scrollIndex === 2) {
|
|
28493
|
-
circleDims = [0, 1];
|
|
28494
|
-
radiuses = [r0, r1];
|
|
28495
|
-
}
|
|
28496
|
-
|
|
28497
|
-
const addedSlices = addMaskSlices(
|
|
28498
|
-
baseGeometry, baseImage.getGeometry().getOrigins(),
|
|
28499
|
-
maskGeometry, position, circleDims, radiuses, sliceMeta);
|
|
28500
|
-
|
|
28501
|
-
if (addedSlices) {
|
|
28502
|
-
// update mask position if new slices
|
|
28503
|
-
maskVc.setCurrentPosition(position);
|
|
28504
|
-
}
|
|
28505
|
-
|
|
28506
|
-
// circle indices in the mask geometry
|
|
28507
|
-
const maskPlanePos = maskVl.displayToPlanePos(event._x, event._y);
|
|
28508
|
-
const maskPosition = maskVc.getPositionFromPlanePoint(maskPlanePos);
|
|
28509
|
-
const maskCircleIndices = dwv.tool.getCircleIndices(
|
|
28510
|
-
maskGeometry, maskPosition, radiuses, circleDims);
|
|
28511
|
-
|
|
28512
|
-
return dwv.tool.getOffsetsFromIndices(maskGeometry, maskCircleIndices);
|
|
28513
|
-
}
|
|
28514
|
-
|
|
28515
|
-
/**
|
|
28516
|
-
* Update the internal segment list.
|
|
28517
|
-
*
|
|
28518
|
-
* @param {Array} newSegments The array of new segments.
|
|
28519
|
-
*/
|
|
28520
|
-
function updateSegments(newSegments) {
|
|
28521
|
-
if (newSegmentBehaviour === 'replace') {
|
|
28522
|
-
segments = newSegments;
|
|
28523
|
-
if (selectedSegment >= segments.length) {
|
|
28524
|
-
console.warn('Updating selectedSegment to fit new segments');
|
|
28525
|
-
selectedSegment = 0;
|
|
28526
|
-
}
|
|
28527
|
-
} else if (newSegmentBehaviour === 'add') {
|
|
28528
|
-
const getEqualSegFunc = function (segment) {
|
|
28529
|
-
return function (item) {
|
|
28530
|
-
return dwv.dicom.isEqualSegment(item, segment);
|
|
28531
|
-
};
|
|
28532
|
-
};
|
|
28533
|
-
const getSimilarSegFunc = function (segment) {
|
|
28534
|
-
return function (item) {
|
|
28535
|
-
return dwv.dicom.isSimilarSegment(item, segment);
|
|
28536
|
-
};
|
|
28537
|
-
};
|
|
28538
|
-
for (let i = 0; i < newSegments.length; ++i) {
|
|
28539
|
-
const equalSeg = segments.find(getEqualSegFunc(newSegments[i]));
|
|
28540
|
-
// if no equal, check if the segment can be added
|
|
28541
|
-
if (typeof equalSeg === 'undefined') {
|
|
28542
|
-
const similarSeg =
|
|
28543
|
-
segments.find(getSimilarSegFunc(newSegments[i]));
|
|
28544
|
-
// only accept non similar
|
|
28545
|
-
if (typeof similarSeg === 'undefined') {
|
|
28546
|
-
segments.push(newSegments[i]);
|
|
28547
|
-
} else {
|
|
28548
|
-
console.warn(
|
|
28549
|
-
'Not adding segment since a similar one is already present.');
|
|
28550
|
-
}
|
|
28551
|
-
}
|
|
28552
|
-
}
|
|
28553
|
-
} else {
|
|
28554
|
-
console.warn('Unknown newSegmentBehaviour:' + newSegmentBehaviour);
|
|
28555
|
-
}
|
|
28556
|
-
}
|
|
28557
|
-
|
|
28558
|
-
/**
|
|
28559
|
-
* Save the current mask as a DICOM seg object.
|
|
28560
|
-
*/
|
|
28561
|
-
function saveSeg() {
|
|
28562
|
-
const fac = new dwv.image.MaskFactory();
|
|
28563
|
-
const dicomElements = fac.toDicom(mask, segments);
|
|
28564
|
-
|
|
28565
|
-
// create writer with default rules
|
|
28566
|
-
const writer = new dwv.dicom.DicomWriter();
|
|
28567
|
-
let dicomBuffer = null;
|
|
28568
|
-
try {
|
|
28569
|
-
dicomBuffer = writer.getBuffer(dicomElements);
|
|
28570
|
-
} catch (error) {
|
|
28571
|
-
console.error(error);
|
|
28572
|
-
alert(error.message);
|
|
28573
|
-
}
|
|
28574
|
-
// view as Blob to allow download
|
|
28575
|
-
const blob = new Blob([dicomBuffer], {type: 'application/dicom'});
|
|
28576
|
-
// update generate button
|
|
28577
|
-
const element = document.createElement('a');
|
|
28578
|
-
element.href = window.URL.createObjectURL(blob);
|
|
28579
|
-
element.download = 'seg-save.dcm';
|
|
28580
|
-
// trigger download
|
|
28581
|
-
element.click();
|
|
28582
|
-
URL.revokeObjectURL(element.href);
|
|
28583
|
-
}
|
|
28584
|
-
|
|
28585
|
-
/**
|
|
28586
|
-
* Handle mouse down event.
|
|
28587
|
-
*
|
|
28588
|
-
* @param {object} event The mouse down event.
|
|
28589
|
-
*/
|
|
28590
|
-
this.mousedown = function (event) {
|
|
28591
|
-
// start flag
|
|
28592
|
-
self.started = true;
|
|
28593
|
-
// first position
|
|
28594
|
-
self.x0 = event._x;
|
|
28595
|
-
self.y0 = event._y;
|
|
28596
|
-
|
|
28597
|
-
paintMaskAtOffsets(getMaskOffsets(event));
|
|
28598
|
-
};
|
|
28599
|
-
|
|
28600
|
-
/**
|
|
28601
|
-
* Handle mouse move event.
|
|
28602
|
-
*
|
|
28603
|
-
* @param {object} event The mouse move event.
|
|
28604
|
-
*/
|
|
28605
|
-
this.mousemove = function (event) {
|
|
28606
|
-
if (!self.started) {
|
|
28607
|
-
return;
|
|
28608
|
-
}
|
|
28609
|
-
const diffX = Math.abs(event._x - self.x0);
|
|
28610
|
-
const diffY = Math.abs(event._y - self.y0);
|
|
28611
|
-
if (diffX > brushSize / 2 || diffY > brushSize / 2) {
|
|
28612
|
-
paintMaskAtOffsets(getMaskOffsets(event));
|
|
28613
|
-
self.x0 = event._x;
|
|
28614
|
-
self.y0 = event._y;
|
|
28615
|
-
}
|
|
28616
|
-
};
|
|
28617
|
-
|
|
28618
|
-
/**
|
|
28619
|
-
* Handle mouse up event.
|
|
28620
|
-
*
|
|
28621
|
-
* @param {object} _event The mouse up event.
|
|
28622
|
-
*/
|
|
28623
|
-
this.mouseup = function (_event) {
|
|
28624
|
-
if (self.started) {
|
|
28625
|
-
self.started = false;
|
|
28626
|
-
}
|
|
28627
|
-
};
|
|
28628
|
-
|
|
28629
|
-
/**
|
|
28630
|
-
* Handle mouse out event.
|
|
28631
|
-
*
|
|
28632
|
-
* @param {object} event The mouse out event.
|
|
28633
|
-
*/
|
|
28634
|
-
this.mouseout = function (event) {
|
|
28635
|
-
self.mouseup(event);
|
|
28636
|
-
};
|
|
28637
|
-
|
|
28638
|
-
/**
|
|
28639
|
-
* Handle touch start event.
|
|
28640
|
-
*
|
|
28641
|
-
* @param {object} event The touch start event.
|
|
28642
|
-
*/
|
|
28643
|
-
this.touchstart = function (event) {
|
|
28644
|
-
// call mouse equivalent
|
|
28645
|
-
self.mousedown(event);
|
|
28646
|
-
};
|
|
28647
|
-
|
|
28648
|
-
/**
|
|
28649
|
-
* Handle touch move event.
|
|
28650
|
-
*
|
|
28651
|
-
* @param {object} event The touch move event.
|
|
28652
|
-
*/
|
|
28653
|
-
this.touchmove = function (event) {
|
|
28654
|
-
// call mouse equivalent
|
|
28655
|
-
self.mousemove(event);
|
|
28656
|
-
};
|
|
28657
|
-
|
|
28658
|
-
/**
|
|
28659
|
-
* Handle touch end event.
|
|
28660
|
-
*
|
|
28661
|
-
* @param {object} event The touch end event.
|
|
28662
|
-
*/
|
|
28663
|
-
this.touchend = function (event) {
|
|
28664
|
-
// call mouse equivalent
|
|
28665
|
-
self.mouseup(event);
|
|
28666
|
-
};
|
|
28667
|
-
|
|
28668
|
-
/**
|
|
28669
|
-
* Handle key down event.
|
|
28670
|
-
*
|
|
28671
|
-
* @param {object} event The key down event.
|
|
28672
|
-
*/
|
|
28673
|
-
this.keydown = function (event) {
|
|
28674
|
-
event.context = 'dwv.tool.Brush';
|
|
28675
|
-
app.onKeydown(event);
|
|
28676
|
-
|
|
28677
|
-
if (event.key === '+') {
|
|
28678
|
-
brushSize += 1;
|
|
28679
|
-
console.log('Brush size:', brushSize);
|
|
28680
|
-
} else if (event.key === '-') {
|
|
28681
|
-
brushSize -= 1;
|
|
28682
|
-
console.log('Brush size:', brushSize);
|
|
28683
|
-
} else if (!isNaN(parseInt(event.key, 10))) {
|
|
28684
|
-
let index = parseInt(event.key, 10);
|
|
28685
|
-
if (index < segments.length) {
|
|
28686
|
-
selectedSegment = index;
|
|
28687
|
-
console.log('segment:', segments[selectedSegment].label);
|
|
28688
|
-
} else {
|
|
28689
|
-
console.warn('Selected segment does not exist.');
|
|
28690
|
-
}
|
|
28691
|
-
} else if (event.key === 'a') {
|
|
28692
|
-
brushMode = 'add';
|
|
28693
|
-
console.log('Brush mode', brushMode);
|
|
28694
|
-
} else if (event.key === 'd') {
|
|
28695
|
-
brushMode = 'del';
|
|
28696
|
-
console.log('Brush mode', brushMode);
|
|
28697
|
-
} else if (event.key === 's') {
|
|
28698
|
-
console.log('Saving...');
|
|
28699
|
-
saveSeg();
|
|
28700
|
-
}
|
|
28701
|
-
|
|
28702
|
-
};
|
|
28703
|
-
|
|
28704
|
-
/**
|
|
28705
|
-
* Activate the tool.
|
|
28706
|
-
*
|
|
28707
|
-
* @param {boolean} _bool The flag to activate or not.
|
|
28708
|
-
*/
|
|
28709
|
-
this.activate = function (_bool) {
|
|
28710
|
-
// does nothing
|
|
28711
|
-
};
|
|
28712
|
-
|
|
28713
|
-
/**
|
|
28714
|
-
* Set the tool live features.
|
|
28715
|
-
*
|
|
28716
|
-
* @param {object} features The list of features.
|
|
28717
|
-
*/
|
|
28718
|
-
this.setFeatures = function (features) {
|
|
28719
|
-
if (typeof features.brushSize !== 'undefined') {
|
|
28720
|
-
brushSize = features.brushSize;
|
|
28721
|
-
}
|
|
28722
|
-
if (typeof features.brushMode !== 'undefined') {
|
|
28723
|
-
brushMode = features.brushMode;
|
|
28724
|
-
}
|
|
28725
|
-
if (typeof features.segments !== 'undefined') {
|
|
28726
|
-
segments = features.segments;
|
|
28727
|
-
}
|
|
28728
|
-
if (typeof features.selectedSegment !== 'undefined' &&
|
|
28729
|
-
features.selectedSegment < segments.length) {
|
|
28730
|
-
selectedSegment = features.selectedSegment;
|
|
28731
|
-
}
|
|
28732
|
-
};
|
|
28733
|
-
|
|
28734
|
-
/**
|
|
28735
|
-
* Initialise the tool.
|
|
28736
|
-
*/
|
|
28737
|
-
this.init = function () {
|
|
28738
|
-
// does nothing
|
|
28739
|
-
};
|
|
28740
|
-
|
|
28741
|
-
}; // Brush class
|
|
28742
|
-
|
|
28743
|
-
/**
|
|
28744
|
-
* Help for this tool.
|
|
28745
|
-
*
|
|
28746
|
-
* @returns {object} The help content.
|
|
28747
|
-
*/
|
|
28748
|
-
dwv.tool.Brush.prototype.getHelpKeys = function () {
|
|
28749
|
-
return {
|
|
28750
|
-
title: 'tool.Brush.name',
|
|
28751
|
-
brief: 'tool.Brush.brief',
|
|
28752
|
-
mouse: {
|
|
28753
|
-
mouse_click: 'tool.Brush.mouse_click',
|
|
28754
|
-
},
|
|
28755
|
-
touch: {
|
|
28756
|
-
touch_click: 'tool.Brush.touch_click'
|
|
28757
|
-
}
|
|
28758
|
-
};
|
|
28759
|
-
};
|
|
28760
27756
|
// namespaces
|
|
28761
27757
|
var dwv = dwv || {};
|
|
28762
27758
|
dwv.tool = dwv.tool || {};
|
|
@@ -35237,7 +34233,10 @@ dwv.utils = dwv.utils || {};
|
|
|
35237
34233
|
* @returns {boolean} True if both array are defined and contain same values.
|
|
35238
34234
|
*/
|
|
35239
34235
|
dwv.utils.arrayEquals = function (arr0, arr1) {
|
|
35240
|
-
if (arr0 === null ||
|
|
34236
|
+
if (arr0 === null ||
|
|
34237
|
+
arr1 === null ||
|
|
34238
|
+
typeof arr0 === 'undefined' ||
|
|
34239
|
+
typeof arr1 === 'undefined') {
|
|
35241
34240
|
return false;
|
|
35242
34241
|
}
|
|
35243
34242
|
if (arr0.length !== arr1.length) {
|