dwv 0.31.0-beta.10 → 0.31.0-beta.11
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 +443 -159
- 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.11 2022-08-24 09:19:36 */
|
|
2
2
|
// Inspired from umdjs
|
|
3
3
|
// See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
|
|
4
4
|
(function (root, factory) {
|
|
@@ -80,6 +80,17 @@ var dwv = dwv || {};
|
|
|
80
80
|
*
|
|
81
81
|
* @class
|
|
82
82
|
* @tutorial examples
|
|
83
|
+
* @example
|
|
84
|
+
* // create the dwv app
|
|
85
|
+
* var app = new dwv.App();
|
|
86
|
+
* // initialise
|
|
87
|
+
* app.init({
|
|
88
|
+
* dataViewConfigs: {'*': [{divId: 'layerGroup0'}]}
|
|
89
|
+
* });
|
|
90
|
+
* // load dicom data
|
|
91
|
+
* app.loadURLs([
|
|
92
|
+
* 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm'
|
|
93
|
+
* ]);
|
|
83
94
|
*/
|
|
84
95
|
dwv.App = function () {
|
|
85
96
|
// closure to self
|
|
@@ -357,6 +368,31 @@ dwv.App = function () {
|
|
|
357
368
|
* after the first loaded data or not
|
|
358
369
|
* - `defaultCharacterSet`: the default chraracter set string used for DICOM
|
|
359
370
|
* parsing
|
|
371
|
+
* @example
|
|
372
|
+
* // create the dwv app
|
|
373
|
+
* var app = new dwv.App();
|
|
374
|
+
* // initialise
|
|
375
|
+
* app.init({
|
|
376
|
+
* dataViewConfigs: {'*': [{divId: 'layerGroup0'}]},
|
|
377
|
+
* viewOnFirstLoadItem: false
|
|
378
|
+
* });
|
|
379
|
+
* // render button
|
|
380
|
+
* var button = document.createElement('button');
|
|
381
|
+
* button.id = 'render';
|
|
382
|
+
* button.appendChild(document.createTextNode('render'));
|
|
383
|
+
* document.body.appendChild(button);
|
|
384
|
+
* app.addEventListener('load', function () {
|
|
385
|
+
* var button = document.getElementById('render');
|
|
386
|
+
* button.disabled = false;
|
|
387
|
+
* button.onclick = function () {
|
|
388
|
+
* // render data #0
|
|
389
|
+
* app.render(0);
|
|
390
|
+
* };
|
|
391
|
+
* });
|
|
392
|
+
* // load dicom data
|
|
393
|
+
* app.loadURLs([
|
|
394
|
+
* 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm'
|
|
395
|
+
* ]);
|
|
360
396
|
*/
|
|
361
397
|
this.init = function (opt) {
|
|
362
398
|
// store
|
|
@@ -4533,7 +4569,7 @@ dwv.dicom = dwv.dicom || {};
|
|
|
4533
4569
|
* @returns {string} The version of the library.
|
|
4534
4570
|
*/
|
|
4535
4571
|
dwv.getVersion = function () {
|
|
4536
|
-
return '0.31.0-beta.
|
|
4572
|
+
return '0.31.0-beta.11';
|
|
4537
4573
|
};
|
|
4538
4574
|
|
|
4539
4575
|
/**
|
|
@@ -18256,6 +18292,276 @@ dwv.image.lut.test = {
|
|
|
18256
18292
|
var dwv = dwv || {};
|
|
18257
18293
|
dwv.image = dwv.image || {};
|
|
18258
18294
|
|
|
18295
|
+
/**
|
|
18296
|
+
* Check two position patients for equality.
|
|
18297
|
+
*
|
|
18298
|
+
* @param {*} pos1 The first position patient.
|
|
18299
|
+
* @param {*} pos2 The second position patient.
|
|
18300
|
+
* @returns {boolean} True is equal.
|
|
18301
|
+
*/
|
|
18302
|
+
dwv.dicom.equalPosPat = function (pos1, pos2) {
|
|
18303
|
+
return JSON.stringify(pos1) === JSON.stringify(pos2);
|
|
18304
|
+
};
|
|
18305
|
+
|
|
18306
|
+
/**
|
|
18307
|
+
* Compare two position patients.
|
|
18308
|
+
*
|
|
18309
|
+
* @param {*} pos1 The first position patient.
|
|
18310
|
+
* @param {*} pos2 The second position patient.
|
|
18311
|
+
* @returns {number|null} A number used to sort elements.
|
|
18312
|
+
*/
|
|
18313
|
+
dwv.dicom.comparePosPat = function (pos1, pos2) {
|
|
18314
|
+
var diff = null;
|
|
18315
|
+
var posLen = pos1.length;
|
|
18316
|
+
var index = posLen;
|
|
18317
|
+
for (var i = 0; i < posLen; ++i) {
|
|
18318
|
+
--index;
|
|
18319
|
+
diff = pos2[index] - pos1[index];
|
|
18320
|
+
if (diff !== 0) {
|
|
18321
|
+
return diff;
|
|
18322
|
+
}
|
|
18323
|
+
}
|
|
18324
|
+
return diff;
|
|
18325
|
+
};
|
|
18326
|
+
|
|
18327
|
+
/**
|
|
18328
|
+
* Check the required and supported tags.
|
|
18329
|
+
*
|
|
18330
|
+
* @param {object} rootElement The root dicom element.
|
|
18331
|
+
*/
|
|
18332
|
+
dwv.dicom.checkDicomSeg = function (rootElement) {
|
|
18333
|
+
// Transfer Syntax
|
|
18334
|
+
var syntax = dwv.dicom.cleanString(rootElement.getFromKey('x00020010'));
|
|
18335
|
+
var algoName = dwv.dicom.getSyntaxDecompressionName(syntax);
|
|
18336
|
+
if (algoName !== null) {
|
|
18337
|
+
throw new Error('Unsupported compressed segmentation: ' + algoName);
|
|
18338
|
+
}
|
|
18339
|
+
|
|
18340
|
+
// Segmentation Type (required)
|
|
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);
|
|
18348
|
+
}
|
|
18349
|
+
|
|
18350
|
+
// Dimension Organization Type (optional)
|
|
18351
|
+
var dimOrgType = rootElement.getFromKey('x00209311');
|
|
18352
|
+
if (dimOrgType) {
|
|
18353
|
+
dimOrgType = dwv.dicom.cleanString(dimOrgType);
|
|
18354
|
+
if (dimOrgType !== '3D') {
|
|
18355
|
+
throw new Error('Unsupported dimension organization type: ' + dimOrgType);
|
|
18356
|
+
}
|
|
18357
|
+
}
|
|
18358
|
+
};
|
|
18359
|
+
|
|
18360
|
+
/**
|
|
18361
|
+
* Check the dimension organization from a dicom element.
|
|
18362
|
+
*
|
|
18363
|
+
* @param {object} rootElement The root dicom element.
|
|
18364
|
+
* @returns {object} The dimension organizations and indices.
|
|
18365
|
+
*/
|
|
18366
|
+
dwv.dicom.getDimensionOrganization = function (rootElement) {
|
|
18367
|
+
// Dimension Organization Sequence (required)
|
|
18368
|
+
var orgSq = rootElement.getFromKey('x00209221', true);
|
|
18369
|
+
if (!orgSq || orgSq.length !== 1) {
|
|
18370
|
+
throw new Error('Unsupported dimension organization sequence length');
|
|
18371
|
+
}
|
|
18372
|
+
// Dimension Organization UID
|
|
18373
|
+
var orgs = [dwv.dicom.cleanString(orgSq[0].x00209164.value[0])];
|
|
18374
|
+
|
|
18375
|
+
// Dimension Index Sequence (conditionally required)
|
|
18376
|
+
var indices = [];
|
|
18377
|
+
var indexSq = rootElement.getFromKey('x00209222', true);
|
|
18378
|
+
if (indexSq) {
|
|
18379
|
+
// expecting 2D index
|
|
18380
|
+
if (indexSq.length !== 2) {
|
|
18381
|
+
throw new Error('Unsupported dimension index sequence length');
|
|
18382
|
+
}
|
|
18383
|
+
for (var i = 0; i < indexSq.length; ++i) {
|
|
18384
|
+
// Dimension Organization UID (required)
|
|
18385
|
+
var indexOrg = dwv.dicom.cleanString(indexSq[i].x00209164.value[0]);
|
|
18386
|
+
if (indexOrg !== orgs[0]) {
|
|
18387
|
+
throw new Error(
|
|
18388
|
+
'Dimension Index Sequence contains a unknown Dimension Organization');
|
|
18389
|
+
}
|
|
18390
|
+
// Dimension Index Pointer (required)
|
|
18391
|
+
var indexPointer =
|
|
18392
|
+
dwv.dicom.cleanString(indexSq[i].x00209165.value[0]);
|
|
18393
|
+
|
|
18394
|
+
var index = {
|
|
18395
|
+
organization: indexOrg,
|
|
18396
|
+
pointer: indexPointer
|
|
18397
|
+
};
|
|
18398
|
+
// Dimension Description Label (optional)
|
|
18399
|
+
if (typeof indexSq[i].x00209421 !== 'undefined') {
|
|
18400
|
+
index.label =
|
|
18401
|
+
dwv.dicom.cleanString(indexSq[i].x00209421.value[0]);
|
|
18402
|
+
}
|
|
18403
|
+
// store
|
|
18404
|
+
indices.push(index);
|
|
18405
|
+
}
|
|
18406
|
+
// expecting Image Position at last position
|
|
18407
|
+
if (indices[1].pointer !== '(0020,0032)') {
|
|
18408
|
+
throw new Error('Unsupported non image position as last index');
|
|
18409
|
+
}
|
|
18410
|
+
}
|
|
18411
|
+
|
|
18412
|
+
return {
|
|
18413
|
+
organizations: orgs,
|
|
18414
|
+
indices: indices
|
|
18415
|
+
};
|
|
18416
|
+
};
|
|
18417
|
+
|
|
18418
|
+
/**
|
|
18419
|
+
* Get a segment object from a dicom element.
|
|
18420
|
+
*
|
|
18421
|
+
* @param {object} element The dicom element.
|
|
18422
|
+
* @returns {object} A segment object.
|
|
18423
|
+
*/
|
|
18424
|
+
dwv.dicom.getSegment = function (element) {
|
|
18425
|
+
// number -> SegmentNumber
|
|
18426
|
+
// label -> SegmentLabel
|
|
18427
|
+
// algorithmType -> SegmentAlgorithmType
|
|
18428
|
+
var segment = {
|
|
18429
|
+
number: element.x00620004.value[0],
|
|
18430
|
+
label: dwv.dicom.cleanString(element.x00620005.value[0]),
|
|
18431
|
+
algorithmType: dwv.dicom.cleanString(element.x00620008.value[0])
|
|
18432
|
+
};
|
|
18433
|
+
// algorithmName -> SegmentAlgorithmName
|
|
18434
|
+
if (element.x00620009) {
|
|
18435
|
+
segment.algorithmName =
|
|
18436
|
+
dwv.dicom.cleanString(element.x00620009.value[0]);
|
|
18437
|
+
}
|
|
18438
|
+
// displayValue ->
|
|
18439
|
+
// - RecommendedDisplayGrayscaleValue
|
|
18440
|
+
// - RecommendedDisplayCIELabValue converted to RGB
|
|
18441
|
+
if (typeof element.x0062000C !== 'undefined') {
|
|
18442
|
+
segment.displayValue = element.x006200C.value;
|
|
18443
|
+
} else if (typeof element.x0062000D !== 'undefined') {
|
|
18444
|
+
var cielabElement = element.x0062000D.value;
|
|
18445
|
+
var rgb = dwv.utils.cielabToSrgb(dwv.utils.uintLabToLab({
|
|
18446
|
+
l: cielabElement[0],
|
|
18447
|
+
a: cielabElement[1],
|
|
18448
|
+
b: cielabElement[2]
|
|
18449
|
+
}));
|
|
18450
|
+
segment.displayValue = rgb;
|
|
18451
|
+
}
|
|
18452
|
+
return segment;
|
|
18453
|
+
};
|
|
18454
|
+
|
|
18455
|
+
/**
|
|
18456
|
+
* Get a spacing object from a dicom measure element.
|
|
18457
|
+
*
|
|
18458
|
+
* @param {object} measure The dicom element.
|
|
18459
|
+
* @returns {dwv.image.Spacing} A spacing object.
|
|
18460
|
+
*/
|
|
18461
|
+
dwv.dicom.getSpacingFromMeasure = function (measure) {
|
|
18462
|
+
// Pixel Spacing
|
|
18463
|
+
if (typeof measure.x00280030 === 'undefined') {
|
|
18464
|
+
return null;
|
|
18465
|
+
}
|
|
18466
|
+
var pixelSpacing = measure.x00280030;
|
|
18467
|
+
var spacingValues = [
|
|
18468
|
+
parseFloat(pixelSpacing.value[0]),
|
|
18469
|
+
parseFloat(pixelSpacing.value[1])
|
|
18470
|
+
];
|
|
18471
|
+
// Spacing Between Slices
|
|
18472
|
+
if (typeof measure.x00180088 !== 'undefined') {
|
|
18473
|
+
var sliceThickness = measure.x00180088;
|
|
18474
|
+
spacingValues.push(parseFloat(sliceThickness.value[0]));
|
|
18475
|
+
}
|
|
18476
|
+
return new dwv.image.Spacing(spacingValues);
|
|
18477
|
+
};
|
|
18478
|
+
|
|
18479
|
+
/**
|
|
18480
|
+
* Get a frame information object from a dicom element.
|
|
18481
|
+
*
|
|
18482
|
+
* @param {object} groupItem The dicom element.
|
|
18483
|
+
* @returns {object} A frame information object.
|
|
18484
|
+
*/
|
|
18485
|
+
dwv.dicom.getSegmentFrameInfo = function (groupItem) {
|
|
18486
|
+
// Derivation Image Sequence
|
|
18487
|
+
var derivationImages = [];
|
|
18488
|
+
if (typeof groupItem.x00089124 !== 'undefined') {
|
|
18489
|
+
var derivationImageSq = groupItem.x00089124.value;
|
|
18490
|
+
// Source Image Sequence
|
|
18491
|
+
for (var i = 0; i < derivationImageSq.length; ++i) {
|
|
18492
|
+
var sourceImages = [];
|
|
18493
|
+
if (typeof derivationImageSq[i].x00082112 !== 'undefined') {
|
|
18494
|
+
var sourceImageSq = derivationImageSq[i].x00082112.value;
|
|
18495
|
+
for (var j = 0; j < sourceImageSq.length; ++j) {
|
|
18496
|
+
var sourceImage = {};
|
|
18497
|
+
// Referenced SOP Class UID
|
|
18498
|
+
if (typeof sourceImageSq[j].x00081150 !== 'undefined') {
|
|
18499
|
+
sourceImage.referencedSOPClassUID =
|
|
18500
|
+
sourceImageSq[j].x00081150.value[0];
|
|
18501
|
+
}
|
|
18502
|
+
// Referenced SOP Instance UID
|
|
18503
|
+
if (typeof sourceImageSq[j].x00081155 !== 'undefined') {
|
|
18504
|
+
sourceImage.referencedSOPInstanceUID =
|
|
18505
|
+
sourceImageSq[j].x00081155.value[0];
|
|
18506
|
+
}
|
|
18507
|
+
sourceImages.push(sourceImage);
|
|
18508
|
+
}
|
|
18509
|
+
}
|
|
18510
|
+
derivationImages.push(sourceImages);
|
|
18511
|
+
}
|
|
18512
|
+
}
|
|
18513
|
+
// Frame Content Sequence (required, only one)
|
|
18514
|
+
var frameContentSq = groupItem.x00209111.value;
|
|
18515
|
+
// Dimension Index Value
|
|
18516
|
+
var dimIndex = frameContentSq[0].x00209157.value;
|
|
18517
|
+
// Segment Identification Sequence (required, only one)
|
|
18518
|
+
var segmentIdSq = groupItem.x0062000A.value;
|
|
18519
|
+
// Referenced Segment Number
|
|
18520
|
+
var refSegmentNumber = segmentIdSq[0].x0062000B.value[0];
|
|
18521
|
+
// Plane Position Sequence (required, only one)
|
|
18522
|
+
var planePosSq = groupItem.x00209113.value;
|
|
18523
|
+
// Image Position (Patient) (conditionally required)
|
|
18524
|
+
var imagePosPat = planePosSq[0].x00200032.value;
|
|
18525
|
+
for (var p = 0; p < imagePosPat.length; ++p) {
|
|
18526
|
+
imagePosPat[p] = parseFloat(imagePosPat[p], 10);
|
|
18527
|
+
}
|
|
18528
|
+
var frameInfo = {
|
|
18529
|
+
dimIndex: dimIndex,
|
|
18530
|
+
imagePosPat: imagePosPat,
|
|
18531
|
+
derivationImages: derivationImages,
|
|
18532
|
+
refSegmentNumber: refSegmentNumber
|
|
18533
|
+
};
|
|
18534
|
+
// Plane Orientation Sequence
|
|
18535
|
+
if (typeof groupItem.x00209116 !== 'undefined') {
|
|
18536
|
+
var framePlaneOrientationSeq = groupItem.x00209116;
|
|
18537
|
+
if (framePlaneOrientationSeq.value.length !== 0) {
|
|
18538
|
+
// should only be one Image Orientation (Patient)
|
|
18539
|
+
var frameImageOrientation =
|
|
18540
|
+
framePlaneOrientationSeq.value[0].x00200037.value;
|
|
18541
|
+
if (typeof frameImageOrientation !== 'undefined') {
|
|
18542
|
+
frameInfo.imageOrientationPatient = frameImageOrientation;
|
|
18543
|
+
}
|
|
18544
|
+
}
|
|
18545
|
+
}
|
|
18546
|
+
// Pixel Measures Sequence
|
|
18547
|
+
if (typeof groupItem.x00289110 !== 'undefined') {
|
|
18548
|
+
var framePixelMeasuresSeq = groupItem.x00289110;
|
|
18549
|
+
if (framePixelMeasuresSeq.value.length !== 0) {
|
|
18550
|
+
// should only be one
|
|
18551
|
+
var frameSpacing =
|
|
18552
|
+
dwv.dicom.getSpacingFromMeasure(framePixelMeasuresSeq.value[0]);
|
|
18553
|
+
if (typeof frameSpacing !== 'undefined') {
|
|
18554
|
+
frameInfo.spacing = frameSpacing;
|
|
18555
|
+
}
|
|
18556
|
+
} else {
|
|
18557
|
+
dwv.logger.warn(
|
|
18558
|
+
'No shared functional group pixel measure sequence items.');
|
|
18559
|
+
}
|
|
18560
|
+
}
|
|
18561
|
+
|
|
18562
|
+
return frameInfo;
|
|
18563
|
+
};
|
|
18564
|
+
|
|
18259
18565
|
/**
|
|
18260
18566
|
* Mask {@link dwv.image.Image} factory.
|
|
18261
18567
|
*
|
|
@@ -18272,6 +18578,9 @@ dwv.image.MaskFactory = function () {};
|
|
|
18272
18578
|
*/
|
|
18273
18579
|
dwv.image.MaskFactory.prototype.create = function (
|
|
18274
18580
|
dicomElements, pixelBuffer) {
|
|
18581
|
+
// check required and supported tags
|
|
18582
|
+
dwv.dicom.checkDicomSeg(dicomElements);
|
|
18583
|
+
|
|
18275
18584
|
// columns
|
|
18276
18585
|
var columns = dicomElements.getFromKey('x00280011');
|
|
18277
18586
|
if (!columns) {
|
|
@@ -18294,87 +18603,40 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18294
18603
|
|
|
18295
18604
|
if (frames !== pixelBuffer.length / sliceSize) {
|
|
18296
18605
|
throw new Error(
|
|
18297
|
-
'Buffer and numberOfFrames meta are not equal.'
|
|
18298
|
-
|
|
18299
|
-
|
|
18300
|
-
// Segmentation Type
|
|
18301
|
-
var segType = dicomElements.getFromKey('x00620001');
|
|
18302
|
-
if (!segType) {
|
|
18303
|
-
throw new Error('Missing or empty DICOM segmentation type');
|
|
18304
|
-
} else {
|
|
18305
|
-
segType = dwv.dicom.cleanString(segType);
|
|
18306
|
-
}
|
|
18307
|
-
if (segType !== 'BINARY') {
|
|
18308
|
-
throw new Error('Unsupported segmentation type: ' + segType);
|
|
18606
|
+
'Buffer and numberOfFrames meta are not equal.' +
|
|
18607
|
+
frames + ' ' + pixelBuffer.length / sliceSize);
|
|
18309
18608
|
}
|
|
18310
18609
|
|
|
18311
|
-
//
|
|
18312
|
-
var
|
|
18313
|
-
var algoName = dwv.dicom.getSyntaxDecompressionName(syntax);
|
|
18314
|
-
if (algoName !== null) {
|
|
18315
|
-
throw new Error('Unsupported compressed segmentation: ' + algoName);
|
|
18316
|
-
}
|
|
18610
|
+
// Dimension Organization and Index
|
|
18611
|
+
var dimension = dwv.dicom.getDimensionOrganization(dicomElements);
|
|
18317
18612
|
|
|
18318
18613
|
// Segment Sequence
|
|
18319
18614
|
var segSequence = dicomElements.getFromKey('x00620002', true);
|
|
18320
18615
|
if (!segSequence || typeof segSequence === 'undefined') {
|
|
18321
18616
|
throw new Error('Missing or empty segmentation sequence');
|
|
18322
18617
|
}
|
|
18323
|
-
var
|
|
18618
|
+
var segments = [];
|
|
18324
18619
|
var storeAsRGB = false;
|
|
18325
18620
|
for (var i = 0; i < segSequence.length; ++i) {
|
|
18326
|
-
|
|
18327
|
-
|
|
18328
|
-
|
|
18329
|
-
|
|
18330
|
-
name: dwv.dicom.cleanString(segSequence[i].x00620005.value[0]),
|
|
18331
|
-
algorithmType: dwv.dicom.cleanString(segSequence[i].x00620008.value[0])
|
|
18332
|
-
};
|
|
18333
|
-
// Segment Algorithm Name
|
|
18334
|
-
if (segSequence[i].x00620009) {
|
|
18335
|
-
label.algorithmName =
|
|
18336
|
-
dwv.dicom.cleanString(segSequence[i].x00620009.value[0]);
|
|
18337
|
-
}
|
|
18338
|
-
// Recommended Display CIELab Value
|
|
18339
|
-
if (typeof segSequence[i].x0062000D !== 'undefined') {
|
|
18340
|
-
var cielabElement = segSequence[i].x0062000D.value;
|
|
18341
|
-
var rgb = dwv.utils.cielabToSrgb(dwv.utils.uintLabToLab({
|
|
18342
|
-
l: cielabElement[0],
|
|
18343
|
-
a: cielabElement[1],
|
|
18344
|
-
b: cielabElement[2]
|
|
18345
|
-
}));
|
|
18346
|
-
label.colour = rgb;
|
|
18621
|
+
var segment = dwv.dicom.getSegment(segSequence[i]);
|
|
18622
|
+
if (typeof segment.displayValue.r !== 'undefined' &&
|
|
18623
|
+
typeof segment.displayValue.g !== 'undefined' &&
|
|
18624
|
+
typeof segment.displayValue.b !== 'undefined') {
|
|
18347
18625
|
// create rgb image
|
|
18348
18626
|
storeAsRGB = true;
|
|
18349
18627
|
}
|
|
18350
18628
|
// store
|
|
18351
|
-
|
|
18629
|
+
segments.push(segment);
|
|
18352
18630
|
}
|
|
18353
18631
|
|
|
18354
18632
|
// image size
|
|
18355
18633
|
var size = dicomElements.getImageSize();
|
|
18356
18634
|
|
|
18357
|
-
var getSpacingFromMeasure = function (measure) {
|
|
18358
|
-
if (typeof measure.x00280030 === 'undefined') {
|
|
18359
|
-
return null;
|
|
18360
|
-
}
|
|
18361
|
-
var pixelSpacing = measure.x00280030;
|
|
18362
|
-
var spacingValues = [
|
|
18363
|
-
parseFloat(pixelSpacing.value[0]),
|
|
18364
|
-
parseFloat(pixelSpacing.value[1])
|
|
18365
|
-
];
|
|
18366
|
-
if (typeof measure.x00180088 !== 'undefined') {
|
|
18367
|
-
var sliceThickness = measure.x00180088;
|
|
18368
|
-
spacingValues.push(parseFloat(sliceThickness.value[0]));
|
|
18369
|
-
}
|
|
18370
|
-
return new dwv.image.Spacing(spacingValues);
|
|
18371
|
-
};
|
|
18372
|
-
|
|
18373
18635
|
// Shared Functional Groups Sequence
|
|
18374
18636
|
var spacing;
|
|
18375
18637
|
var imageOrientationPatient;
|
|
18376
18638
|
var sharedFunctionalGroupsSeq = dicomElements.getFromKey('x52009229', true);
|
|
18377
|
-
if (sharedFunctionalGroupsSeq.length !== 0) {
|
|
18639
|
+
if (sharedFunctionalGroupsSeq && sharedFunctionalGroupsSeq.length !== 0) {
|
|
18378
18640
|
// should be only one
|
|
18379
18641
|
var funcGroup0 = sharedFunctionalGroupsSeq[0];
|
|
18380
18642
|
// Plane Orientation Sequence
|
|
@@ -18382,7 +18644,12 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18382
18644
|
var planeOrientationSeq = funcGroup0.x00209116;
|
|
18383
18645
|
if (planeOrientationSeq.value.length !== 0) {
|
|
18384
18646
|
// should be only one
|
|
18385
|
-
|
|
18647
|
+
var orientArray = planeOrientationSeq.value[0].x00200037.value;
|
|
18648
|
+
imageOrientationPatient = orientArray.map(
|
|
18649
|
+
function (x) {
|
|
18650
|
+
return parseFloat(x);
|
|
18651
|
+
}
|
|
18652
|
+
);
|
|
18386
18653
|
} else {
|
|
18387
18654
|
dwv.logger.warn(
|
|
18388
18655
|
'No shared functional group plane orientation sequence items.');
|
|
@@ -18393,7 +18660,7 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18393
18660
|
var pixelMeasuresSeq = funcGroup0.x00289110;
|
|
18394
18661
|
if (pixelMeasuresSeq.value.length !== 0) {
|
|
18395
18662
|
// should be only one
|
|
18396
|
-
spacing = getSpacingFromMeasure(pixelMeasuresSeq.value[0]);
|
|
18663
|
+
spacing = dwv.dicom.getSpacingFromMeasure(pixelMeasuresSeq.value[0]);
|
|
18397
18664
|
} else {
|
|
18398
18665
|
dwv.logger.warn(
|
|
18399
18666
|
'No shared functional group pixel measure sequence items.');
|
|
@@ -18401,34 +18668,15 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18401
18668
|
}
|
|
18402
18669
|
}
|
|
18403
18670
|
|
|
18404
|
-
// position patient utility functions
|
|
18405
|
-
var equalPosPat = function (pos1, pos2) {
|
|
18406
|
-
return JSON.stringify(pos1) === JSON.stringify(pos2);
|
|
18407
|
-
};
|
|
18408
|
-
|
|
18409
|
-
var comparePosPat = function (pos1, pos2) {
|
|
18410
|
-
var diff = null;
|
|
18411
|
-
var posLen = pos1.length;
|
|
18412
|
-
var index = posLen;
|
|
18413
|
-
for (var i = 0; i < posLen; ++i) {
|
|
18414
|
-
--index;
|
|
18415
|
-
diff = pos2[index] - pos1[index];
|
|
18416
|
-
if (diff !== 0) {
|
|
18417
|
-
return diff;
|
|
18418
|
-
}
|
|
18419
|
-
}
|
|
18420
|
-
return diff;
|
|
18421
|
-
};
|
|
18422
|
-
|
|
18423
18671
|
var includesPosPat = function (arr, val) {
|
|
18424
18672
|
return arr.some(function (arrVal) {
|
|
18425
|
-
return equalPosPat(val, arrVal);
|
|
18673
|
+
return dwv.dicom.equalPosPat(val, arrVal);
|
|
18426
18674
|
});
|
|
18427
18675
|
};
|
|
18428
18676
|
|
|
18429
18677
|
var findIndexPosPat = function (arr, val) {
|
|
18430
18678
|
return arr.findIndex(function (arrVal) {
|
|
18431
|
-
return equalPosPat(val, arrVal);
|
|
18679
|
+
return dwv.dicom.equalPosPat(val, arrVal);
|
|
18432
18680
|
});
|
|
18433
18681
|
};
|
|
18434
18682
|
|
|
@@ -18456,79 +18704,49 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18456
18704
|
}
|
|
18457
18705
|
// create frame info object from per frame func
|
|
18458
18706
|
var frameInfos = [];
|
|
18459
|
-
var framePosPats = [];
|
|
18460
18707
|
for (var j = 0; j < perFrameFuncGroupSequence.length; ++j) {
|
|
18461
|
-
|
|
18462
|
-
|
|
18463
|
-
|
|
18464
|
-
|
|
18465
|
-
|
|
18466
|
-
|
|
18467
|
-
|
|
18468
|
-
|
|
18469
|
-
|
|
18470
|
-
|
|
18471
|
-
|
|
18472
|
-
|
|
18473
|
-
|
|
18474
|
-
|
|
18475
|
-
|
|
18476
|
-
|
|
18477
|
-
|
|
18478
|
-
|
|
18479
|
-
// Plane Position Sequence
|
|
18480
|
-
var planePosSq = frameFunc.x00209113.value;
|
|
18481
|
-
// Image Position (Patient)
|
|
18482
|
-
var imagePosPat = planePosSq[0].x00200032.value;
|
|
18483
|
-
for (var p = 0; p < imagePosPat.length; ++p) {
|
|
18484
|
-
imagePosPat[p] = parseFloat(imagePosPat[p], 10);
|
|
18485
|
-
}
|
|
18486
|
-
if (!includesPosPat(framePosPats, imagePosPat)) {
|
|
18487
|
-
framePosPats.push(imagePosPat);
|
|
18488
|
-
}
|
|
18489
|
-
frameInfos.push({
|
|
18490
|
-
dimIndex: dimIndex,
|
|
18491
|
-
imagePosPat: imagePosPat,
|
|
18492
|
-
referencedSOPInstanceUID: referencedSOPInstanceUID
|
|
18493
|
-
});
|
|
18494
|
-
// Plane Orientation Sequence
|
|
18495
|
-
if (typeof frameFunc.x00209116 !== 'undefined') {
|
|
18496
|
-
var framePlaneOrientationSeq = frameFunc.x00209116;
|
|
18497
|
-
if (framePlaneOrientationSeq.value.length !== 0) {
|
|
18498
|
-
// should only be one
|
|
18499
|
-
var frameImageOrientation =
|
|
18500
|
-
framePlaneOrientationSeq.value[0].x00200037.value;
|
|
18501
|
-
if (typeof imageOrientationPatient === 'undefined') {
|
|
18502
|
-
imageOrientationPatient = frameImageOrientation;
|
|
18503
|
-
} else {
|
|
18504
|
-
if (!arrayEquals(frameImageOrientation, imageOrientationPatient)) {
|
|
18505
|
-
throw new Error('Unsupported multi orientation dicom seg.');
|
|
18506
|
-
}
|
|
18708
|
+
frameInfos.push(
|
|
18709
|
+
dwv.dicom.getSegmentFrameInfo(perFrameFuncGroupSequence[j]));
|
|
18710
|
+
}
|
|
18711
|
+
|
|
18712
|
+
// check frame infos
|
|
18713
|
+
var framePosPats = [];
|
|
18714
|
+
for (var ii = 0; ii < frameInfos.length; ++ii) {
|
|
18715
|
+
if (!includesPosPat(framePosPats, frameInfos[ii].imagePosPat)) {
|
|
18716
|
+
framePosPats.push(frameInfos[ii].imagePosPat);
|
|
18717
|
+
}
|
|
18718
|
+
// store orientation if needed, avoid multi
|
|
18719
|
+
if (typeof frameInfos[ii].imageOrientationPatient !== 'undefined') {
|
|
18720
|
+
if (typeof imageOrientationPatient === 'undefined') {
|
|
18721
|
+
imageOrientationPatient = frameInfos[ii].imageOrientationPatient;
|
|
18722
|
+
} else {
|
|
18723
|
+
if (!arrayEquals(
|
|
18724
|
+
imageOrientationPatient, frameInfos[ii].imageOrientationPatient)) {
|
|
18725
|
+
throw new Error('Unsupported multi orientation dicom seg.');
|
|
18507
18726
|
}
|
|
18508
18727
|
}
|
|
18509
18728
|
}
|
|
18510
|
-
//
|
|
18511
|
-
if (typeof
|
|
18512
|
-
|
|
18513
|
-
|
|
18514
|
-
// should only be one
|
|
18515
|
-
var frameSpacing =
|
|
18516
|
-
getSpacingFromMeasure(framePixelMeasuresSeq.value[0]);
|
|
18517
|
-
if (typeof spacing === 'undefined') {
|
|
18518
|
-
spacing = frameSpacing;
|
|
18519
|
-
} else {
|
|
18520
|
-
if (!spacing.equals(frameSpacing)) {
|
|
18521
|
-
throw new Error('Unsupported multi resolution dicom seg.');
|
|
18522
|
-
}
|
|
18523
|
-
}
|
|
18729
|
+
// store spacing if needed, avoid multi
|
|
18730
|
+
if (typeof frameInfos[ii].spacing !== 'undefined') {
|
|
18731
|
+
if (typeof spacing === 'undefined') {
|
|
18732
|
+
spacing = frameInfos[ii].spacing;
|
|
18524
18733
|
} else {
|
|
18525
|
-
|
|
18526
|
-
|
|
18734
|
+
if (!spacing.equals(frameInfos[ii].spacing)) {
|
|
18735
|
+
throw new Error('Unsupported multi resolution dicom seg.');
|
|
18736
|
+
}
|
|
18527
18737
|
}
|
|
18528
18738
|
}
|
|
18529
18739
|
}
|
|
18530
18740
|
// sort positions patient
|
|
18531
|
-
framePosPats.sort(comparePosPat);
|
|
18741
|
+
framePosPats.sort(dwv.dicom.comparePosPat);
|
|
18742
|
+
|
|
18743
|
+
// check spacing and orientation
|
|
18744
|
+
if (typeof spacing === 'undefined') {
|
|
18745
|
+
throw new Error('No spacing found for DICOM SEG');
|
|
18746
|
+
}
|
|
18747
|
+
if (typeof imageOrientationPatient === 'undefined') {
|
|
18748
|
+
throw new Error('No imageOrientationPatient found for DICOM SEG');
|
|
18749
|
+
}
|
|
18532
18750
|
|
|
18533
18751
|
// add missing posPats
|
|
18534
18752
|
var posPats = [];
|
|
@@ -18537,7 +18755,7 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18537
18755
|
posPats.push(framePosPats[g]);
|
|
18538
18756
|
var nextZ = framePosPats[g][2] - sliceSpacing;
|
|
18539
18757
|
var diff = Math.abs(nextZ - framePosPats[g + 1][2]);
|
|
18540
|
-
while (diff
|
|
18758
|
+
while (diff >= sliceSpacing) {
|
|
18541
18759
|
posPats.push([framePosPats[g][0], framePosPats[g][1], nextZ]);
|
|
18542
18760
|
nextZ -= sliceSpacing;
|
|
18543
18761
|
diff = Math.abs(nextZ - framePosPats[g + 1][2]);
|
|
@@ -18545,8 +18763,14 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18545
18763
|
}
|
|
18546
18764
|
posPats.push(framePosPats[framePosPats.length - 1]);
|
|
18547
18765
|
|
|
18766
|
+
var getFindSegmentFunc = function (number) {
|
|
18767
|
+
return function (item) {
|
|
18768
|
+
return item.number === number;
|
|
18769
|
+
};
|
|
18770
|
+
};
|
|
18771
|
+
|
|
18548
18772
|
// create output buffer
|
|
18549
|
-
// as many slices as posPats
|
|
18773
|
+
// as many slices as posPats
|
|
18550
18774
|
var numberOfSlices = posPats.length;
|
|
18551
18775
|
var mul = storeAsRGB ? 3 : 1;
|
|
18552
18776
|
var buffer = new pixelBuffer.constructor(mul * sliceSize * numberOfSlices);
|
|
@@ -18555,19 +18779,16 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18555
18779
|
var sliceOffset = null;
|
|
18556
18780
|
var sliceIndex = null;
|
|
18557
18781
|
var frameOffset = null;
|
|
18558
|
-
var labelIndex = null;
|
|
18559
18782
|
for (var f = 0; f < frameInfos.length; ++f) {
|
|
18560
18783
|
// get the slice index from the position in the posPat array
|
|
18561
18784
|
sliceIndex = findIndexPosPat(posPats, frameInfos[f].imagePosPat);
|
|
18562
18785
|
frameOffset = sliceSize * f;
|
|
18563
|
-
labelIndex = frameInfos[f].dimIndex[0] - 1;
|
|
18564
18786
|
sliceOffset = sliceSize * sliceIndex;
|
|
18565
|
-
|
|
18566
|
-
|
|
18567
|
-
|
|
18568
|
-
|
|
18569
|
-
|
|
18570
|
-
}
|
|
18787
|
+
// get the frame display value
|
|
18788
|
+
var frameSegment = segments.find(
|
|
18789
|
+
getFindSegmentFunc(frameInfos[f].refSegmentNumber)
|
|
18790
|
+
);
|
|
18791
|
+
var pixelValue = frameSegment.displayValue;
|
|
18571
18792
|
for (var l = 0; l < sliceSize; ++l) {
|
|
18572
18793
|
if (pixelBuffer[frameOffset + l] !== 0) {
|
|
18573
18794
|
var offset = mul * (sliceOffset + l);
|
|
@@ -18607,11 +18828,15 @@ dwv.image.MaskFactory.prototype.create = function (
|
|
|
18607
18828
|
// image meta
|
|
18608
18829
|
var meta = {
|
|
18609
18830
|
Modality: 'SEG',
|
|
18831
|
+
SegmentationType: 'BINARY',
|
|
18832
|
+
DimensionOrganizationType: '3D',
|
|
18833
|
+
DimensionOrganizations: dimension.organizations,
|
|
18834
|
+
DimensionIndices: dimension.indices,
|
|
18610
18835
|
BitsStored: 8,
|
|
18611
18836
|
SeriesInstanceUID: dicomElements.getFromKey('x0020000E'),
|
|
18612
18837
|
ImageOrientationPatient: imageOrientationPatient,
|
|
18613
18838
|
custom: {
|
|
18614
|
-
|
|
18839
|
+
segments: segments,
|
|
18615
18840
|
frameInfos: frameInfos
|
|
18616
18841
|
}
|
|
18617
18842
|
};
|
|
@@ -20475,7 +20700,7 @@ dwv.image.validateWindowWidth = function (value) {
|
|
|
20475
20700
|
* WindowLevel class.
|
|
20476
20701
|
* <br>Pseudo-code:
|
|
20477
20702
|
* <pre>
|
|
20478
|
-
* if (x
|
|
20703
|
+
* if (x <= c - 0.5 - (w-1)/2), then y = ymin
|
|
20479
20704
|
* else if (x > c - 0.5 + (w-1)/2), then y = ymax,
|
|
20480
20705
|
* else y = ((x - (c - 0.5)) / (w-1) + 0.5) * (ymax - ymin) + ymin
|
|
20481
20706
|
* </pre>
|
|
@@ -32832,6 +33057,65 @@ dwv.tool = dwv.tool || {};
|
|
|
32832
33057
|
*
|
|
32833
33058
|
* @class
|
|
32834
33059
|
* @param {dwv.App} app The associated application.
|
|
33060
|
+
* @example
|
|
33061
|
+
* // create the dwv app
|
|
33062
|
+
* var app = new dwv.App();
|
|
33063
|
+
* // initialise
|
|
33064
|
+
* app.init({
|
|
33065
|
+
* dataViewConfigs: {'*': [{divId: 'layerGroup0'}]},
|
|
33066
|
+
* tools: {Scroll: {}}
|
|
33067
|
+
* });
|
|
33068
|
+
* // activate tool
|
|
33069
|
+
* app.addEventListener('load', function () {
|
|
33070
|
+
* app.setTool('Scroll');
|
|
33071
|
+
* });
|
|
33072
|
+
* // load dicom data
|
|
33073
|
+
* app.loadURLs([
|
|
33074
|
+
* 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm',
|
|
33075
|
+
* 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323707.dcm',
|
|
33076
|
+
* 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323563.dcm'
|
|
33077
|
+
* ]);
|
|
33078
|
+
* @example <caption>Example with slider</caption>
|
|
33079
|
+
* // create the dwv app
|
|
33080
|
+
* var app = new dwv.App();
|
|
33081
|
+
* // initialise
|
|
33082
|
+
* app.init({
|
|
33083
|
+
* dataViewConfigs: {'*': [{divId: 'layerGroup0'}]},
|
|
33084
|
+
* tools: {Scroll: {}}
|
|
33085
|
+
* });
|
|
33086
|
+
* // create range
|
|
33087
|
+
* var range = document.createElement('input');
|
|
33088
|
+
* range.type = 'range';
|
|
33089
|
+
* range.min = 0;
|
|
33090
|
+
* range.id = 'sliceRange';
|
|
33091
|
+
* document.body.appendChild(range);
|
|
33092
|
+
* // update app on slider change
|
|
33093
|
+
* range.oninput = function () {
|
|
33094
|
+
* var lg = app.getLayerGroupById(0);
|
|
33095
|
+
* var vc = lg.getActiveViewLayer().getViewController();
|
|
33096
|
+
* var index = vc.getCurrentIndex();
|
|
33097
|
+
* var values = index.getValues();
|
|
33098
|
+
* values[2] = this.value;
|
|
33099
|
+
* vc.setCurrentIndex(new dwv.math.Index(values));
|
|
33100
|
+
* }
|
|
33101
|
+
* // activate tool and update range max on load
|
|
33102
|
+
* app.addEventListener('load', function () {
|
|
33103
|
+
* app.setTool('Scroll');
|
|
33104
|
+
* var size = app.getImage(0).getGeometry().getSize();
|
|
33105
|
+
* range.max = size.get(2) - 1;
|
|
33106
|
+
* });
|
|
33107
|
+
* // update slider on slice change (for ex via mouse wheel)
|
|
33108
|
+
* app.addEventListener('positionchange', function () {
|
|
33109
|
+
* var lg = app.getLayerGroupById(0);
|
|
33110
|
+
* var vc = lg.getActiveViewLayer().getViewController();
|
|
33111
|
+
* range.value = vc.getCurrentIndex().get(2);
|
|
33112
|
+
* });
|
|
33113
|
+
* // load dicom data
|
|
33114
|
+
* app.loadURLs([
|
|
33115
|
+
* 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm',
|
|
33116
|
+
* 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323707.dcm',
|
|
33117
|
+
* 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323563.dcm'
|
|
33118
|
+
* ]);
|
|
32835
33119
|
*/
|
|
32836
33120
|
dwv.tool.Scroll = function (app) {
|
|
32837
33121
|
/**
|