dwv 0.31.0-beta.11 → 0.31.0-beta.12
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 +1315 -44
- package/dist/dwv.min.js +2 -2
- package/package.json +2 -2
package/dist/dwv.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! dwv 0.31.0-beta.
|
|
1
|
+
/*! dwv 0.31.0-beta.12 2022-09-07 10:28:58 */
|
|
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.12';
|
|
4573
4573
|
};
|
|
4574
4574
|
|
|
4575
4575
|
/**
|
|
@@ -18325,38 +18325,137 @@ dwv.dicom.comparePosPat = function (pos1, pos2) {
|
|
|
18325
18325
|
};
|
|
18326
18326
|
|
|
18327
18327
|
/**
|
|
18328
|
-
* Check
|
|
18328
|
+
* Check that a DICOM tag definition is present in a parsed element.
|
|
18329
18329
|
*
|
|
18330
18330
|
* @param {object} rootElement The root dicom element.
|
|
18331
|
+
* @param {object} tagDefinition The tag definition as {name, tag, type, enum}.
|
|
18331
18332
|
*/
|
|
18332
|
-
dwv.dicom.
|
|
18333
|
-
|
|
18334
|
-
|
|
18335
|
-
|
|
18336
|
-
|
|
18337
|
-
|
|
18333
|
+
dwv.dicom.checkTag = function (rootElement, tagDefinition) {
|
|
18334
|
+
var tagValue = rootElement.getFromKey(tagDefinition.tag);
|
|
18335
|
+
// check null and undefined
|
|
18336
|
+
if (tagDefinition.type === 1 || tagDefinition.type === 2) {
|
|
18337
|
+
if (tagValue === null || typeof tagValue === 'undefined') {
|
|
18338
|
+
throw new Error('Missing or empty ' + tagDefinition.name);
|
|
18339
|
+
}
|
|
18340
|
+
} else {
|
|
18341
|
+
if (tagValue === null || typeof tagValue === 'undefined') {
|
|
18342
|
+
// non mandatory value, exit
|
|
18343
|
+
return;
|
|
18344
|
+
}
|
|
18338
18345
|
}
|
|
18346
|
+
var includes = false;
|
|
18347
|
+
if (Array.isArray(tagValue)) {
|
|
18348
|
+
// trim
|
|
18349
|
+
tagValue = tagValue.map(function (item) {
|
|
18350
|
+
return dwv.dicom.cleanString(item);
|
|
18351
|
+
});
|
|
18352
|
+
for (var i = 0; i < tagDefinition.enum.length; ++i) {
|
|
18353
|
+
if (!Array.isArray(tagDefinition.enum[i])) {
|
|
18354
|
+
throw new Error('Cannot compare array and non array tag value.');
|
|
18355
|
+
}
|
|
18356
|
+
if (dwv.utils.arrayEquals(tagDefinition.enum[i], tagValue)) {
|
|
18357
|
+
includes = true;
|
|
18358
|
+
break;
|
|
18359
|
+
}
|
|
18360
|
+
}
|
|
18361
|
+
} else {
|
|
18362
|
+
// trim
|
|
18363
|
+
if (typeof tagValue === 'string') {
|
|
18364
|
+
tagValue = dwv.dicom.cleanString(tagValue);
|
|
18365
|
+
}
|
|
18339
18366
|
|
|
18340
|
-
|
|
18341
|
-
var segmentationType = rootElement.getFromKey('x00620001');
|
|
18342
|
-
if (!segmentationType) {
|
|
18343
|
-
throw new Error('Missing or empty DICOM segmentation type');
|
|
18344
|
-
}
|
|
18345
|
-
segmentationType = dwv.dicom.cleanString(segmentationType);
|
|
18346
|
-
if (segmentationType !== 'BINARY') {
|
|
18347
|
-
throw new Error('Unsupported segmentation type: ' + segmentationType);
|
|
18367
|
+
includes = tagDefinition.enum.includes(tagValue);
|
|
18348
18368
|
}
|
|
18349
|
-
|
|
18350
|
-
|
|
18351
|
-
|
|
18352
|
-
if (dimOrgType) {
|
|
18353
|
-
dimOrgType = dwv.dicom.cleanString(dimOrgType);
|
|
18354
|
-
if (dimOrgType !== '3D') {
|
|
18355
|
-
throw new Error('Unsupported dimension organization type: ' + dimOrgType);
|
|
18356
|
-
}
|
|
18369
|
+
if (!includes) {
|
|
18370
|
+
throw new Error(
|
|
18371
|
+
'Unsupported ' + tagDefinition.name + ' value: ' + tagValue);
|
|
18357
18372
|
}
|
|
18358
18373
|
};
|
|
18359
18374
|
|
|
18375
|
+
/**
|
|
18376
|
+
* List of DICOM Seg required tags.
|
|
18377
|
+
*/
|
|
18378
|
+
dwv.dicom.requiredSegDicomTags = [
|
|
18379
|
+
{
|
|
18380
|
+
name: 'Transfer Syntax UID',
|
|
18381
|
+
tag: 'x00020010',
|
|
18382
|
+
type: '1',
|
|
18383
|
+
enum: ['1.2.840.10008.1.2.1']
|
|
18384
|
+
},
|
|
18385
|
+
{
|
|
18386
|
+
name: 'Media Storage SOP Class UID',
|
|
18387
|
+
tag: 'x00020002',
|
|
18388
|
+
type: '1',
|
|
18389
|
+
enum: ['1.2.840.10008.5.1.4.1.1.66.4']
|
|
18390
|
+
},
|
|
18391
|
+
{
|
|
18392
|
+
name: 'SOP Class UID',
|
|
18393
|
+
tag: 'x00020002',
|
|
18394
|
+
type: '1',
|
|
18395
|
+
enum: ['1.2.840.10008.5.1.4.1.1.66.4']
|
|
18396
|
+
},
|
|
18397
|
+
{
|
|
18398
|
+
name: 'Modality',
|
|
18399
|
+
tag: 'x00080060',
|
|
18400
|
+
type: '1',
|
|
18401
|
+
enum: ['SEG']
|
|
18402
|
+
},
|
|
18403
|
+
{
|
|
18404
|
+
name: 'Segmentation Type',
|
|
18405
|
+
tag: 'x00620001',
|
|
18406
|
+
type: '1',
|
|
18407
|
+
enum: ['BINARY']
|
|
18408
|
+
},
|
|
18409
|
+
{
|
|
18410
|
+
name: 'Dimension Organization Type',
|
|
18411
|
+
tag: 'x00209311',
|
|
18412
|
+
type: '3',
|
|
18413
|
+
enum: ['3D']
|
|
18414
|
+
},
|
|
18415
|
+
{
|
|
18416
|
+
name: 'Image Type',
|
|
18417
|
+
tag: 'x00080008',
|
|
18418
|
+
type: '1',
|
|
18419
|
+
enum: [['DERIVED', 'PRIMARY']]
|
|
18420
|
+
},
|
|
18421
|
+
{
|
|
18422
|
+
name: 'Samples Per Pixel',
|
|
18423
|
+
tag: 'x00280002',
|
|
18424
|
+
type: '1',
|
|
18425
|
+
enum: [1]
|
|
18426
|
+
},
|
|
18427
|
+
{
|
|
18428
|
+
name: 'Photometric Interpretation',
|
|
18429
|
+
tag: 'x00280004',
|
|
18430
|
+
type: '1',
|
|
18431
|
+
enum: ['MONOCHROME2']
|
|
18432
|
+
},
|
|
18433
|
+
{
|
|
18434
|
+
name: 'Pixel Representation',
|
|
18435
|
+
tag: 'x00280103',
|
|
18436
|
+
type: '1',
|
|
18437
|
+
enum: [0]
|
|
18438
|
+
},
|
|
18439
|
+
{
|
|
18440
|
+
name: 'Bits Allocated',
|
|
18441
|
+
tag: 'x00280100',
|
|
18442
|
+
type: '1',
|
|
18443
|
+
enum: [1]
|
|
18444
|
+
},
|
|
18445
|
+
{
|
|
18446
|
+
name: 'Bits Stored',
|
|
18447
|
+
tag: 'x00280101',
|
|
18448
|
+
type: '1',
|
|
18449
|
+
enum: [1]
|
|
18450
|
+
},
|
|
18451
|
+
{
|
|
18452
|
+
name: 'High Bit',
|
|
18453
|
+
tag: 'x00280102',
|
|
18454
|
+
type: '1',
|
|
18455
|
+
enum: [0]
|
|
18456
|
+
},
|
|
18457
|
+
];
|
|
18458
|
+
|
|
18360
18459
|
/**
|
|
18361
18460
|
* Check the dimension organization from a dicom element.
|
|
18362
18461
|
*
|
|
@@ -18415,6 +18514,42 @@ dwv.dicom.getDimensionOrganization = function (rootElement) {
|
|
|
18415
18514
|
};
|
|
18416
18515
|
};
|
|
18417
18516
|
|
|
18517
|
+
/**
|
|
18518
|
+
* Get a code object from a dicom element.
|
|
18519
|
+
*
|
|
18520
|
+
* @param {object} element The dicom element.
|
|
18521
|
+
* @returns {object} A code object.
|
|
18522
|
+
*/
|
|
18523
|
+
dwv.dicom.getCode = function (element) {
|
|
18524
|
+
// meaning -> CodeMeaning (type1)
|
|
18525
|
+
var code = {
|
|
18526
|
+
meaning: dwv.dicom.cleanString(element.x00080104.value[0])
|
|
18527
|
+
};
|
|
18528
|
+
// value -> CodeValue (type1C)
|
|
18529
|
+
// longValue -> LongCodeValue (type1C)
|
|
18530
|
+
// urnValue -> URNCodeValue (type1C)
|
|
18531
|
+
if (element.x00080100) {
|
|
18532
|
+
code.value = element.x00080100.value[0];
|
|
18533
|
+
} else if (element.x00080119) {
|
|
18534
|
+
code.longValue = element.x00080119.value[0];
|
|
18535
|
+
} else if (element.x00080120) {
|
|
18536
|
+
code.urnValue = element.x00080120.value[0];
|
|
18537
|
+
} else {
|
|
18538
|
+
throw Error('Invalid code with no value, no long value and no urn value.');
|
|
18539
|
+
}
|
|
18540
|
+
// schemeDesignator -> CodingSchemeDesignator (type1C)
|
|
18541
|
+
if (typeof code.value !== 'undefined' ||
|
|
18542
|
+
typeof code.longValue !== 'undefined') {
|
|
18543
|
+
if (element.x00080102) {
|
|
18544
|
+
code.schemeDesignator = element.x00080102.value[0];
|
|
18545
|
+
} else {
|
|
18546
|
+
throw Error(
|
|
18547
|
+
'No coding sheme designator when code value or long value is present');
|
|
18548
|
+
}
|
|
18549
|
+
}
|
|
18550
|
+
return code;
|
|
18551
|
+
};
|
|
18552
|
+
|
|
18418
18553
|
/**
|
|
18419
18554
|
* Get a segment object from a dicom element.
|
|
18420
18555
|
*
|
|
@@ -18422,19 +18557,25 @@ dwv.dicom.getDimensionOrganization = function (rootElement) {
|
|
|
18422
18557
|
* @returns {object} A segment object.
|
|
18423
18558
|
*/
|
|
18424
18559
|
dwv.dicom.getSegment = function (element) {
|
|
18425
|
-
// number -> SegmentNumber
|
|
18426
|
-
// label -> SegmentLabel
|
|
18427
|
-
// algorithmType -> SegmentAlgorithmType
|
|
18560
|
+
// number -> SegmentNumber (type1)
|
|
18561
|
+
// label -> SegmentLabel (type1)
|
|
18562
|
+
// algorithmType -> SegmentAlgorithmType (type1)
|
|
18428
18563
|
var segment = {
|
|
18429
18564
|
number: element.x00620004.value[0],
|
|
18430
18565
|
label: dwv.dicom.cleanString(element.x00620005.value[0]),
|
|
18431
18566
|
algorithmType: dwv.dicom.cleanString(element.x00620008.value[0])
|
|
18432
18567
|
};
|
|
18433
|
-
// algorithmName -> SegmentAlgorithmName
|
|
18568
|
+
// algorithmName -> SegmentAlgorithmName (type1C)
|
|
18434
18569
|
if (element.x00620009) {
|
|
18435
18570
|
segment.algorithmName =
|
|
18436
18571
|
dwv.dicom.cleanString(element.x00620009.value[0]);
|
|
18437
18572
|
}
|
|
18573
|
+
// // required if type is not MANUAL
|
|
18574
|
+
// if (segment.algorithmType !== 'MANUAL' &&
|
|
18575
|
+
// (typeof segment.algorithmName === 'undefined' ||
|
|
18576
|
+
// segment.algorithmName.length === 0)) {
|
|
18577
|
+
// throw new Error('Empty algorithm name for non MANUAL algorithm type.');
|
|
18578
|
+
// }
|
|
18438
18579
|
// displayValue ->
|
|
18439
18580
|
// - RecommendedDisplayGrayscaleValue
|
|
18440
18581
|
// - RecommendedDisplayCIELabValue converted to RGB
|
|
@@ -18449,9 +18590,100 @@ dwv.dicom.getSegment = function (element) {
|
|
|
18449
18590
|
}));
|
|
18450
18591
|
segment.displayValue = rgb;
|
|
18451
18592
|
}
|
|
18593
|
+
// Segmented Property Category Code Sequence (type1, only one)
|
|
18594
|
+
if (element.x00620003) {
|
|
18595
|
+
segment.propertyCategoryCode =
|
|
18596
|
+
dwv.dicom.getCode(element.x00620003.value[0]);
|
|
18597
|
+
} else {
|
|
18598
|
+
throw Error('Missing Segmented Property Category Code Sequence.');
|
|
18599
|
+
}
|
|
18600
|
+
// Segmented Property Type Code Sequence (type1)
|
|
18601
|
+
if (element.x0062000F) {
|
|
18602
|
+
segment.propertyTypeCode =
|
|
18603
|
+
dwv.dicom.getCode(element.x0062000F.value[0]);
|
|
18604
|
+
} else {
|
|
18605
|
+
throw Error('Missing Segmented Property Type Code Sequence.');
|
|
18606
|
+
}
|
|
18607
|
+
|
|
18452
18608
|
return segment;
|
|
18453
18609
|
};
|
|
18454
18610
|
|
|
18611
|
+
/**
|
|
18612
|
+
* Check if two segment objects are equal.
|
|
18613
|
+
*
|
|
18614
|
+
* @param {object} seg1 The first segment.
|
|
18615
|
+
* @param {object} seg2 The second segment.
|
|
18616
|
+
* @returns {boolean} True if both segment are equal.
|
|
18617
|
+
*/
|
|
18618
|
+
dwv.dicom.isEqualSegment = function (seg1, seg2) {
|
|
18619
|
+
// basics
|
|
18620
|
+
if (typeof seg1 === 'undefined' ||
|
|
18621
|
+
typeof seg2 === 'undefined' ||
|
|
18622
|
+
seg1 === null ||
|
|
18623
|
+
seg2 === null) {
|
|
18624
|
+
return false;
|
|
18625
|
+
}
|
|
18626
|
+
var isEqual = seg1.number === seg2.number &&
|
|
18627
|
+
seg1.label === seg2.label &&
|
|
18628
|
+
seg1.algorithmType === seg2.algorithmType;
|
|
18629
|
+
// rgb
|
|
18630
|
+
if (typeof seg1.displayValue.r !== 'undefined') {
|
|
18631
|
+
if (typeof seg2.displayValue.r === 'undefined') {
|
|
18632
|
+
isEqual = false;
|
|
18633
|
+
} else {
|
|
18634
|
+
isEqual = isEqual &&
|
|
18635
|
+
dwv.utils.isEqualRgb(seg1.displayValue, seg2.displayValue);
|
|
18636
|
+
}
|
|
18637
|
+
} else {
|
|
18638
|
+
isEqual = isEqual &&
|
|
18639
|
+
seg1.displayValue === seg2.displayValue;
|
|
18640
|
+
}
|
|
18641
|
+
// algorithmName
|
|
18642
|
+
if (typeof seg1.algorithmName !== 'undefined') {
|
|
18643
|
+
if (typeof seg2.algorithmName === 'undefined') {
|
|
18644
|
+
isEqual = false;
|
|
18645
|
+
} else {
|
|
18646
|
+
isEqual = isEqual &&
|
|
18647
|
+
seg1.algorithmName === seg2.algorithmName;
|
|
18648
|
+
}
|
|
18649
|
+
}
|
|
18650
|
+
|
|
18651
|
+
return isEqual;
|
|
18652
|
+
};
|
|
18653
|
+
|
|
18654
|
+
/**
|
|
18655
|
+
* Check if two segment objects are similar: either the
|
|
18656
|
+
* number or the displayValue are equal.
|
|
18657
|
+
*
|
|
18658
|
+
* @param {object} seg1 The first segment.
|
|
18659
|
+
* @param {object} seg2 The second segment.
|
|
18660
|
+
* @returns {boolean} True if both segment are similar.
|
|
18661
|
+
*/
|
|
18662
|
+
dwv.dicom.isSimilarSegment = function (seg1, seg2) {
|
|
18663
|
+
// basics
|
|
18664
|
+
if (typeof seg1 === 'undefined' ||
|
|
18665
|
+
typeof seg2 === 'undefined' ||
|
|
18666
|
+
seg1 === null ||
|
|
18667
|
+
seg2 === null) {
|
|
18668
|
+
return false;
|
|
18669
|
+
}
|
|
18670
|
+
var isSimilar = seg1.number === seg2.number;
|
|
18671
|
+
// rgb
|
|
18672
|
+
if (typeof seg1.displayValue.r !== 'undefined') {
|
|
18673
|
+
if (typeof seg2.displayValue.r === 'undefined') {
|
|
18674
|
+
isSimilar = false;
|
|
18675
|
+
} else {
|
|
18676
|
+
isSimilar = isSimilar ||
|
|
18677
|
+
dwv.utils.isEqualRgb(seg1.displayValue, seg2.displayValue);
|
|
18678
|
+
}
|
|
18679
|
+
} else {
|
|
18680
|
+
isSimilar = isSimilar ||
|
|
18681
|
+
seg1.displayValue === seg2.displayValue;
|
|
18682
|
+
}
|
|
18683
|
+
|
|
18684
|
+
return isSimilar;
|
|
18685
|
+
};
|
|
18686
|
+
|
|
18455
18687
|
/**
|
|
18456
18688
|
* Get a spacing object from a dicom measure element.
|
|
18457
18689
|
*
|
|
@@ -18579,7 +18811,9 @@ dwv.image.MaskFactory = function () {};
|
|
|
18579
18811
|
dwv.image.MaskFactory.prototype.create = function (
|
|
18580
18812
|
dicomElements, pixelBuffer) {
|
|
18581
18813
|
// check required and supported tags
|
|
18582
|
-
dwv.dicom.
|
|
18814
|
+
for (var d = 0; d < dwv.dicom.requiredSegDicomTags.length; ++d) {
|
|
18815
|
+
dwv.dicom.checkTag(dicomElements, dwv.dicom.requiredSegDicomTags[d]);
|
|
18816
|
+
}
|
|
18583
18817
|
|
|
18584
18818
|
// columns
|
|
18585
18819
|
var columns = dicomElements.getFromKey('x00280011');
|
|
@@ -18680,18 +18914,6 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18680
18914
|
});
|
|
18681
18915
|
};
|
|
18682
18916
|
|
|
18683
|
-
var arrayEquals = function (arr0, arr1) {
|
|
18684
|
-
if (arr0 === null || arr1 === null) {
|
|
18685
|
-
return false;
|
|
18686
|
-
}
|
|
18687
|
-
if (arr0.length !== arr1.length) {
|
|
18688
|
-
return false;
|
|
18689
|
-
}
|
|
18690
|
-
return arr0.every(function (element, index) {
|
|
18691
|
-
return element === arr1[index];
|
|
18692
|
-
});
|
|
18693
|
-
};
|
|
18694
|
-
|
|
18695
18917
|
// Per-frame Functional Groups Sequence
|
|
18696
18918
|
var perFrameFuncGroupSequence = dicomElements.getFromKey('x52009230', true);
|
|
18697
18919
|
if (!perFrameFuncGroupSequence ||
|
|
@@ -18720,7 +18942,7 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18720
18942
|
if (typeof imageOrientationPatient === 'undefined') {
|
|
18721
18943
|
imageOrientationPatient = frameInfos[ii].imageOrientationPatient;
|
|
18722
18944
|
} else {
|
|
18723
|
-
if (!arrayEquals(
|
|
18945
|
+
if (!dwv.utils.arrayEquals(
|
|
18724
18946
|
imageOrientationPatient, frameInfos[ii].imageOrientationPatient)) {
|
|
18725
18947
|
throw new Error('Unsupported multi orientation dicom seg.');
|
|
18726
18948
|
}
|
|
@@ -18832,8 +19054,14 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18832
19054
|
DimensionOrganizationType: '3D',
|
|
18833
19055
|
DimensionOrganizations: dimension.organizations,
|
|
18834
19056
|
DimensionIndices: dimension.indices,
|
|
18835
|
-
BitsStored:
|
|
19057
|
+
BitsStored: 1,
|
|
19058
|
+
PatientName: dwv.dicom.cleanString(dicomElements.getFromKey('x00100010')),
|
|
19059
|
+
PatientID: dwv.dicom.cleanString(dicomElements.getFromKey('x00100020')),
|
|
19060
|
+
PatientBirthDate: dicomElements.getFromKey('x00100030'),
|
|
19061
|
+
PatientSex: dwv.dicom.cleanString(dicomElements.getFromKey('x00100040')),
|
|
19062
|
+
StudyInstanceUID: dicomElements.getFromKey('x0020000D'),
|
|
18836
19063
|
SeriesInstanceUID: dicomElements.getFromKey('x0020000E'),
|
|
19064
|
+
SeriesNumber: dicomElements.getFromKey('x00200011'),
|
|
18837
19065
|
ImageOrientationPatient: imageOrientationPatient,
|
|
18838
19066
|
custom: {
|
|
18839
19067
|
segments: segments,
|
|
@@ -27524,6 +27752,1011 @@ dwv.tool.draw.ArrowFactory.prototype.update = function (
|
|
|
27524
27752
|
klabel.position(textPos);
|
|
27525
27753
|
};
|
|
27526
27754
|
|
|
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
|
+
};
|
|
27527
28760
|
// namespaces
|
|
27528
28761
|
var dwv = dwv || {};
|
|
27529
28762
|
dwv.tool = dwv.tool || {};
|
|
@@ -33996,6 +35229,27 @@ dwv.tool.ZoomAndPan.prototype.init = function () {
|
|
|
33996
35229
|
var dwv = dwv || {};
|
|
33997
35230
|
dwv.utils = dwv.utils || {};
|
|
33998
35231
|
|
|
35232
|
+
/**
|
|
35233
|
+
* Check for array equality.
|
|
35234
|
+
*
|
|
35235
|
+
* @param {Array} arr0 First array.
|
|
35236
|
+
* @param {*} arr1 Second array.
|
|
35237
|
+
* @returns {boolean} True if both array are defined and contain same values.
|
|
35238
|
+
*/
|
|
35239
|
+
dwv.utils.arrayEquals = function (arr0, arr1) {
|
|
35240
|
+
if (arr0 === null || arr1 === null) {
|
|
35241
|
+
return false;
|
|
35242
|
+
}
|
|
35243
|
+
if (arr0.length !== arr1.length) {
|
|
35244
|
+
return false;
|
|
35245
|
+
}
|
|
35246
|
+
var arr0sorted = arr0.slice().sort();
|
|
35247
|
+
var arr1sorted = arr1.slice().sort();
|
|
35248
|
+
return arr0sorted.every(function (element, index) {
|
|
35249
|
+
return element === arr1sorted[index];
|
|
35250
|
+
});
|
|
35251
|
+
};
|
|
35252
|
+
|
|
33999
35253
|
/**
|
|
34000
35254
|
* Convert a Uint8Array to a string.
|
|
34001
35255
|
*
|
|
@@ -34220,6 +35474,23 @@ dwv.utils = dwv.utils || {};
|
|
|
34220
35474
|
// example implementation: dcmtk/dcmiod/libsrc/cielabutil.cc
|
|
34221
35475
|
// https://github.com/DCMTK/dcmtk/blob/DCMTK-3.6.6/dcmiod/libsrc/cielabutil.cc
|
|
34222
35476
|
|
|
35477
|
+
/**
|
|
35478
|
+
* Check if two rgb objects are equal.
|
|
35479
|
+
*
|
|
35480
|
+
* @param {object} c1 The first colour.
|
|
35481
|
+
* @param {object} c2 The second colour.
|
|
35482
|
+
* @returns {boolean} True if both colour are equal.
|
|
35483
|
+
*/
|
|
35484
|
+
dwv.utils.isEqualRgb = function (c1, c2) {
|
|
35485
|
+
return c1 !== null &&
|
|
35486
|
+
c2 !== null &&
|
|
35487
|
+
typeof c1 !== 'undefined' &&
|
|
35488
|
+
typeof c2 !== 'undefined' &&
|
|
35489
|
+
c1.r === c2.r &&
|
|
35490
|
+
c1.g === c2.g &&
|
|
35491
|
+
c1.b === c2.b;
|
|
35492
|
+
};
|
|
35493
|
+
|
|
34223
35494
|
/**
|
|
34224
35495
|
* Convert YBR to RGB.
|
|
34225
35496
|
*
|