dwv 0.30.6 → 0.31.0-beta.0
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 +800 -126
- package/dist/dwv.min.js +2 -2
- package/package.json +4 -4
- package/changelog.md +0 -859
package/dist/dwv.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! dwv 0.
|
|
1
|
+
/*! dwv 0.31.0-beta.0 2022-03-11 16:27:12 */
|
|
2
2
|
// Inspired from umdjs
|
|
3
3
|
// See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
|
|
4
4
|
(function (root, factory) {
|
|
@@ -295,7 +295,7 @@ dwv.App = function () {
|
|
|
295
295
|
* - `dataViewConfigs`: data indexed object containing the data view
|
|
296
296
|
* configurations in the form of a list of objects containing:
|
|
297
297
|
* - divId: the HTML div id
|
|
298
|
-
* - orientation: optional 'axial', 'coronal' or 'sagittal'
|
|
298
|
+
* - orientation: optional 'axial', 'coronal' or 'sagittal' orientation
|
|
299
299
|
* string (default undefined keeps the original slice order)
|
|
300
300
|
* - `binders`: array of layerGroup binders
|
|
301
301
|
* - `tools`: tool name indexed object containing individual tool
|
|
@@ -526,20 +526,15 @@ dwv.App = function () {
|
|
|
526
526
|
// load API [end] ---------------------------------------------------------
|
|
527
527
|
|
|
528
528
|
/**
|
|
529
|
-
* Fit the display to the
|
|
529
|
+
* Fit the display to the data of each layer group.
|
|
530
|
+
* To be called once the image is loaded.
|
|
530
531
|
*/
|
|
531
532
|
this.fitToContainer = function () {
|
|
532
|
-
var
|
|
533
|
-
|
|
534
|
-
var
|
|
535
|
-
|
|
536
|
-
var spacing = geometry.getSpacing().get2D();
|
|
537
|
-
var width = size.x * spacing.x;
|
|
538
|
-
var height = size.y * spacing.y;
|
|
539
|
-
layerGroup.fitToContainer({x: width, y: height});
|
|
533
|
+
for (var i = 0; i < stage.getNumberOfLayerGroups(); ++i) {
|
|
534
|
+
var layerGroup = stage.getLayerGroup(i);
|
|
535
|
+
var mazSize = getLayerGroupMaxSize(layerGroup);
|
|
536
|
+
layerGroup.fitToContainer(mazSize);
|
|
540
537
|
layerGroup.draw();
|
|
541
|
-
// update style
|
|
542
|
-
//style.setBaseScale(layerGroup.getBaseScale());
|
|
543
538
|
}
|
|
544
539
|
};
|
|
545
540
|
|
|
@@ -563,7 +558,7 @@ dwv.App = function () {
|
|
|
563
558
|
// check options
|
|
564
559
|
if (options.dataViewConfigs === null ||
|
|
565
560
|
typeof options.dataViewConfigs === 'undefined') {
|
|
566
|
-
throw new Error('No available data
|
|
561
|
+
throw new Error('No available data view configuration');
|
|
567
562
|
}
|
|
568
563
|
var configs = null;
|
|
569
564
|
if (typeof options.dataViewConfigs['*'] !== 'undefined') {
|
|
@@ -718,7 +713,8 @@ dwv.App = function () {
|
|
|
718
713
|
drawings, drawingsDetails, fireEvent, this.addToUndoStack);
|
|
719
714
|
|
|
720
715
|
drawController.activateDrawLayer(
|
|
721
|
-
viewController.
|
|
716
|
+
viewController.getCurrentOrientedIndex(),
|
|
717
|
+
viewController.getScrollIndex());
|
|
722
718
|
};
|
|
723
719
|
/**
|
|
724
720
|
* Update a drawing from its details.
|
|
@@ -1066,7 +1062,8 @@ dwv.App = function () {
|
|
|
1066
1062
|
var eventMetaData = null;
|
|
1067
1063
|
if (event.loadtype === 'image') {
|
|
1068
1064
|
if (isFirstLoadItem && timeId === 0) {
|
|
1069
|
-
dataController.addNew(
|
|
1065
|
+
dataController.addNew(
|
|
1066
|
+
event.loadid, event.data.image, event.data.info);
|
|
1070
1067
|
} else {
|
|
1071
1068
|
dataController.update(
|
|
1072
1069
|
event.loadid, event.data.image, event.data.info,
|
|
@@ -1239,6 +1236,36 @@ dwv.App = function () {
|
|
|
1239
1236
|
}
|
|
1240
1237
|
}
|
|
1241
1238
|
|
|
1239
|
+
/**
|
|
1240
|
+
* Get the data max size for a layer group.
|
|
1241
|
+
*
|
|
1242
|
+
* @todo Filter for data of the layer group.
|
|
1243
|
+
* @param {object} lg The layer group.
|
|
1244
|
+
* @returns {object} The max size as {x,y}.
|
|
1245
|
+
*/
|
|
1246
|
+
function getLayerGroupMaxSize(lg) {
|
|
1247
|
+
var maxSize = {x: 0, y: 0};
|
|
1248
|
+
for (var i = 0; i < dataController.length(); ++i) {
|
|
1249
|
+
var dc = dataController.get(i);
|
|
1250
|
+
var geometry = dc.image.getGeometry();
|
|
1251
|
+
var viewOrient = dwv.gui.getViewOrientation(
|
|
1252
|
+
geometry,
|
|
1253
|
+
lg.getTargetOrientation()
|
|
1254
|
+
);
|
|
1255
|
+
var size = geometry.getSize(viewOrient).get2D();
|
|
1256
|
+
var spacing = geometry.getSpacing(viewOrient).get2D();
|
|
1257
|
+
var width = size.x * spacing.x;
|
|
1258
|
+
if (width > maxSize.x) {
|
|
1259
|
+
maxSize.x = width;
|
|
1260
|
+
}
|
|
1261
|
+
var height = size.y * spacing.y;
|
|
1262
|
+
if (height > maxSize.y) {
|
|
1263
|
+
maxSize.y = height;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return maxSize;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1242
1269
|
/**
|
|
1243
1270
|
* Add a view layer.
|
|
1244
1271
|
*
|
|
@@ -1323,25 +1350,7 @@ dwv.App = function () {
|
|
|
1323
1350
|
}
|
|
1324
1351
|
|
|
1325
1352
|
// fit to the maximum size
|
|
1326
|
-
var maxSize =
|
|
1327
|
-
for (var i = 0; i < dataController.length(); ++i) {
|
|
1328
|
-
var dc = dataController.get(i);
|
|
1329
|
-
var geometry = dc.image.getGeometry();
|
|
1330
|
-
var viewOrient = dwv.gui.getViewOrientation(
|
|
1331
|
-
geometry,
|
|
1332
|
-
layerGroup.getTargetOrientation()
|
|
1333
|
-
);
|
|
1334
|
-
var size = geometry.getSize(viewOrient).get2D();
|
|
1335
|
-
var spacing = geometry.getSpacing(viewOrient).get2D();
|
|
1336
|
-
var width = size.x * spacing.x;
|
|
1337
|
-
if (width > maxSize.x) {
|
|
1338
|
-
maxSize.x = width;
|
|
1339
|
-
}
|
|
1340
|
-
var height = size.y * spacing.y;
|
|
1341
|
-
if (height > maxSize.y) {
|
|
1342
|
-
maxSize.y = height;
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1353
|
+
var maxSize = getLayerGroupMaxSize(layerGroup);
|
|
1345
1354
|
layerGroup.fitToContainer(maxSize);
|
|
1346
1355
|
}
|
|
1347
1356
|
|
|
@@ -1363,9 +1372,9 @@ dwv.ctrl.DataController = function () {
|
|
|
1363
1372
|
* List of {image, meta}.
|
|
1364
1373
|
*
|
|
1365
1374
|
* @private
|
|
1366
|
-
* @type {
|
|
1375
|
+
* @type {object}
|
|
1367
1376
|
*/
|
|
1368
|
-
var data =
|
|
1377
|
+
var data = {};
|
|
1369
1378
|
|
|
1370
1379
|
/**
|
|
1371
1380
|
* Listener handler.
|
|
@@ -1381,7 +1390,7 @@ dwv.ctrl.DataController = function () {
|
|
|
1381
1390
|
* @returns {number} The length.
|
|
1382
1391
|
*/
|
|
1383
1392
|
this.length = function () {
|
|
1384
|
-
return data.length;
|
|
1393
|
+
return Object.keys(data).length;
|
|
1385
1394
|
};
|
|
1386
1395
|
|
|
1387
1396
|
/**
|
|
@@ -1418,15 +1427,19 @@ dwv.ctrl.DataController = function () {
|
|
|
1418
1427
|
/**
|
|
1419
1428
|
* Add a new data.
|
|
1420
1429
|
*
|
|
1430
|
+
* @param {number} index The index of the data.
|
|
1421
1431
|
* @param {dwv.image.Image} image The image.
|
|
1422
1432
|
* @param {object} meta The image meta.
|
|
1423
1433
|
*/
|
|
1424
|
-
this.addNew = function (image, meta) {
|
|
1434
|
+
this.addNew = function (index, image, meta) {
|
|
1435
|
+
if (typeof data[index] !== 'undefined') {
|
|
1436
|
+
throw new Error('Index already used in storage: ' + index);
|
|
1437
|
+
}
|
|
1425
1438
|
// store the new image
|
|
1426
|
-
data
|
|
1439
|
+
data[index] = {
|
|
1427
1440
|
image: image,
|
|
1428
1441
|
meta: getMetaObject(meta)
|
|
1429
|
-
}
|
|
1442
|
+
};
|
|
1430
1443
|
};
|
|
1431
1444
|
|
|
1432
1445
|
/**
|
|
@@ -2224,17 +2237,21 @@ dwv.ctrl.LoadController = function (defaultCharacterSet) {
|
|
|
2224
2237
|
};
|
|
2225
2238
|
loader.onprogress = augmentCallbackEvent(self.onprogress, eventInfo);
|
|
2226
2239
|
loader.onloaditem = function (event) {
|
|
2227
|
-
var isFirstItem = currentLoaders[loadId].isFirstItem;
|
|
2228
2240
|
var eventInfoItem = {
|
|
2229
2241
|
loadtype: loadType,
|
|
2230
|
-
loadid: loadId
|
|
2231
|
-
isfirstitem: isFirstItem
|
|
2242
|
+
loadid: loadId
|
|
2232
2243
|
};
|
|
2244
|
+
if (typeof currentLoaders[loadId] !== 'undefined') {
|
|
2245
|
+
eventInfoItem.isfirstitem = currentLoaders[loadId].isFirstItem;
|
|
2246
|
+
}
|
|
2233
2247
|
if (hasTimepoint) {
|
|
2234
2248
|
eventInfoItem.timepoint = options.timepoint;
|
|
2235
2249
|
}
|
|
2250
|
+
// callback
|
|
2236
2251
|
augmentCallbackEvent(self.onloaditem, eventInfoItem)(event);
|
|
2237
|
-
|
|
2252
|
+
// update loader
|
|
2253
|
+
if (typeof currentLoaders[loadId] !== 'undefined' &&
|
|
2254
|
+
currentLoaders[loadId].isFirstItem) {
|
|
2238
2255
|
currentLoaders[loadId].isFirstItem = false;
|
|
2239
2256
|
}
|
|
2240
2257
|
};
|
|
@@ -2680,12 +2697,17 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2680
2697
|
*
|
|
2681
2698
|
* @returns {dwv.math.Point} The position.
|
|
2682
2699
|
*/
|
|
2683
|
-
this.
|
|
2684
|
-
var res = view.
|
|
2700
|
+
this.getCurrentOrientedIndex = function () {
|
|
2701
|
+
var res = view.getCurrentIndex();
|
|
2685
2702
|
// values = orientation * orientedValues
|
|
2686
2703
|
// -> inv(orientation) * values = orientedValues
|
|
2687
2704
|
if (typeof view.getOrientation() !== 'undefined') {
|
|
2688
|
-
|
|
2705
|
+
var index3D = new dwv.math.Index(
|
|
2706
|
+
[res.get(0), res.get(1), res.get(2)]);
|
|
2707
|
+
var orientedIndex3D =
|
|
2708
|
+
view.getOrientation().getInverse().getAbs().multiplyIndex3D(index3D);
|
|
2709
|
+
var values = orientedIndex3D.getValues();
|
|
2710
|
+
res = new dwv.math.Index(values);
|
|
2689
2711
|
}
|
|
2690
2712
|
return res;
|
|
2691
2713
|
};
|
|
@@ -3487,7 +3509,7 @@ dwv.dicom.DataReader.prototype.readHex = function (byteOffset) {
|
|
|
3487
3509
|
// read and convert to hex string
|
|
3488
3510
|
var str = this.readUint16(byteOffset).toString(16);
|
|
3489
3511
|
// return padded
|
|
3490
|
-
return '0x0000'.
|
|
3512
|
+
return '0x0000'.substring(0, 6 - str.length) + str.toUpperCase();
|
|
3491
3513
|
};
|
|
3492
3514
|
|
|
3493
3515
|
// namespaces
|
|
@@ -3647,7 +3669,7 @@ dwv.dicom.DataWriter = function (buffer, isLittleEndian) {
|
|
|
3647
3669
|
*/
|
|
3648
3670
|
this.writeHex = function (byteOffset, str) {
|
|
3649
3671
|
// remove first two chars and parse
|
|
3650
|
-
var value = parseInt(str.
|
|
3672
|
+
var value = parseInt(str.substring(2), 16);
|
|
3651
3673
|
view.setUint16(byteOffset, value, isLittleEndian);
|
|
3652
3674
|
return byteOffset + Uint16Array.BYTES_PER_ELEMENT;
|
|
3653
3675
|
};
|
|
@@ -4029,15 +4051,17 @@ dwv.dicom.DicomElementsWrapper.prototype.getElementValueAsString = function (
|
|
|
4029
4051
|
dayBeginIndex = 8;
|
|
4030
4052
|
}
|
|
4031
4053
|
var da = new Date(
|
|
4032
|
-
parseInt(daValue.
|
|
4033
|
-
parseInt(daValue.
|
|
4034
|
-
|
|
4054
|
+
parseInt(daValue.substring(0, 4), 10),
|
|
4055
|
+
parseInt(daValue.substring(
|
|
4056
|
+
monthBeginIndex, monthBeginIndex + 2), 10) - 1, // 0-11 range
|
|
4057
|
+
parseInt(daValue.substring(
|
|
4058
|
+
dayBeginIndex, dayBeginIndex + 2), 10));
|
|
4035
4059
|
str = da.toLocaleDateString();
|
|
4036
4060
|
} else if (dicomElement.vr === 'TM' && pretty) {
|
|
4037
4061
|
var tmValue = dicomElement.value[0];
|
|
4038
|
-
var tmHour = tmValue.
|
|
4039
|
-
var tmMinute = tmValue.length >= 4 ? tmValue.
|
|
4040
|
-
var tmSeconds = tmValue.length >= 6 ? tmValue.
|
|
4062
|
+
var tmHour = tmValue.substring(0, 2);
|
|
4063
|
+
var tmMinute = tmValue.length >= 4 ? tmValue.substring(2, 4) : '00';
|
|
4064
|
+
var tmSeconds = tmValue.length >= 6 ? tmValue.substring(4, 6) : '00';
|
|
4041
4065
|
str = tmHour + ':' + tmMinute + ':' + tmSeconds;
|
|
4042
4066
|
} else {
|
|
4043
4067
|
var isOtherVR = false;
|
|
@@ -4067,9 +4091,9 @@ dwv.dicom.DicomElementsWrapper.prototype.getElementValueAsString = function (
|
|
|
4067
4091
|
} else if (isOtherVR) {
|
|
4068
4092
|
var tmp = dicomElement.value[k].toString(16);
|
|
4069
4093
|
if (dicomElement.vr === 'OB') {
|
|
4070
|
-
tmp = '00'.
|
|
4094
|
+
tmp = '00'.substring(0, 2 - tmp.length) + tmp;
|
|
4071
4095
|
} else {
|
|
4072
|
-
tmp = '0000'.
|
|
4096
|
+
tmp = '0000'.substring(0, 4 - tmp.length) + tmp;
|
|
4073
4097
|
}
|
|
4074
4098
|
valueStr += tmp;
|
|
4075
4099
|
} else if (typeof dicomElement.value[k] === 'string') {
|
|
@@ -4140,9 +4164,9 @@ dwv.dicom.DicomElementsWrapper.prototype.getElementAsString = function (
|
|
|
4140
4164
|
|
|
4141
4165
|
// (group,element)
|
|
4142
4166
|
line = '(';
|
|
4143
|
-
line += dicomElement.tag.group.
|
|
4167
|
+
line += dicomElement.tag.group.substring(2).toLowerCase();
|
|
4144
4168
|
line += ',';
|
|
4145
|
-
line += dicomElement.tag.element.
|
|
4169
|
+
line += dicomElement.tag.element.substring(2).toLowerCase();
|
|
4146
4170
|
line += ') ';
|
|
4147
4171
|
// value representation
|
|
4148
4172
|
line += dicomElement.vr;
|
|
@@ -4444,7 +4468,7 @@ dwv.dicom = dwv.dicom || {};
|
|
|
4444
4468
|
* @returns {string} The version of the library.
|
|
4445
4469
|
*/
|
|
4446
4470
|
dwv.getVersion = function () {
|
|
4447
|
-
return '0.
|
|
4471
|
+
return '0.31.0-beta.0';
|
|
4448
4472
|
};
|
|
4449
4473
|
|
|
4450
4474
|
/**
|
|
@@ -4558,7 +4582,7 @@ dwv.dicom.getReverseOrientation = function (ori) {
|
|
|
4558
4582
|
|
|
4559
4583
|
var rori = '';
|
|
4560
4584
|
for (var n = 0; n < ori.length; n++) {
|
|
4561
|
-
var o = ori.
|
|
4585
|
+
var o = ori.substring(n, n + 1);
|
|
4562
4586
|
var r = rlabels[o];
|
|
4563
4587
|
if (r) {
|
|
4564
4588
|
rori += r;
|
|
@@ -4772,7 +4796,7 @@ dwv.dicom.guessTransferSyntax = function (firstDataElement) {
|
|
|
4772
4796
|
group !== oEightGroupLittleEndian) {
|
|
4773
4797
|
throw new Error(
|
|
4774
4798
|
'Not a valid DICOM file (no magic DICM word found' +
|
|
4775
|
-
'and first element not in 0x0008 group)'
|
|
4799
|
+
' and first element not in 0x0008 group)'
|
|
4776
4800
|
);
|
|
4777
4801
|
}
|
|
4778
4802
|
// reasonable assumption: 2 uppercase characters => explicit vr
|
|
@@ -5340,9 +5364,9 @@ dwv.dicom.DicomParser.prototype.interpretElement = function (
|
|
|
5340
5364
|
var stri = raw[i].toString(16);
|
|
5341
5365
|
var stri1 = raw[i + 1].toString(16);
|
|
5342
5366
|
var str = '(';
|
|
5343
|
-
str += '0000'.
|
|
5367
|
+
str += '0000'.substring(0, 4 - stri.length) + stri.toUpperCase();
|
|
5344
5368
|
str += ',';
|
|
5345
|
-
str += '0000'.
|
|
5369
|
+
str += '0000'.substring(0, 4 - stri1.length) + stri1.toUpperCase();
|
|
5346
5370
|
str += ')';
|
|
5347
5371
|
data.push(str);
|
|
5348
5372
|
}
|
|
@@ -5655,19 +5679,21 @@ dwv.dicom.Tag.prototype.equals2 = function (rhs) {
|
|
|
5655
5679
|
/**
|
|
5656
5680
|
* Get the group-element key used to store DICOM elements.
|
|
5657
5681
|
*
|
|
5658
|
-
* @returns {string} The key.
|
|
5682
|
+
* @returns {string} The key as 'x########'.
|
|
5659
5683
|
*/
|
|
5660
5684
|
dwv.dicom.Tag.prototype.getKey = function () {
|
|
5661
|
-
|
|
5685
|
+
// group and element are in the '0x####' form
|
|
5686
|
+
return 'x' + this.getGroup().substring(2) + this.getElement().substring(2);
|
|
5662
5687
|
};
|
|
5663
5688
|
|
|
5664
5689
|
/**
|
|
5665
5690
|
* Get a simplified group-element key.
|
|
5666
5691
|
*
|
|
5667
|
-
* @returns {string} The key.
|
|
5692
|
+
* @returns {string} The key as '########'.
|
|
5668
5693
|
*/
|
|
5669
5694
|
dwv.dicom.Tag.prototype.getKey2 = function () {
|
|
5670
|
-
|
|
5695
|
+
// group and element are in the '0x####' form
|
|
5696
|
+
return this.getGroup().substring(2) + this.getElement().substring(2);
|
|
5671
5697
|
};
|
|
5672
5698
|
|
|
5673
5699
|
/**
|
|
@@ -5676,7 +5702,9 @@ dwv.dicom.Tag.prototype.getKey2 = function () {
|
|
|
5676
5702
|
* @returns {string} The name.
|
|
5677
5703
|
*/
|
|
5678
5704
|
dwv.dicom.Tag.prototype.getGroupName = function () {
|
|
5679
|
-
|
|
5705
|
+
// group is in the '0x####' form
|
|
5706
|
+
// TagGroups include the x
|
|
5707
|
+
return dwv.dicom.TagGroups[this.getGroup().substring(1)];
|
|
5680
5708
|
};
|
|
5681
5709
|
|
|
5682
5710
|
|
|
@@ -5687,7 +5715,7 @@ dwv.dicom.Tag.prototype.getGroupName = function () {
|
|
|
5687
5715
|
* @returns {object} The DICOM tag.
|
|
5688
5716
|
*/
|
|
5689
5717
|
dwv.dicom.getTagFromKey = function (key) {
|
|
5690
|
-
return new dwv.dicom.Tag(key.
|
|
5718
|
+
return new dwv.dicom.Tag(key.substring(1, 5), key.substring(5, 9));
|
|
5691
5719
|
};
|
|
5692
5720
|
|
|
5693
5721
|
/**
|
|
@@ -5711,7 +5739,8 @@ dwv.dicom.Tag.prototype.isWithVR = function () {
|
|
|
5711
5739
|
* ie if its group is an odd number.
|
|
5712
5740
|
*/
|
|
5713
5741
|
dwv.dicom.Tag.prototype.isPrivate = function () {
|
|
5714
|
-
|
|
5742
|
+
// group is in the '0x####' form
|
|
5743
|
+
var groupNumber = parseInt(this.getGroup().substring(2), 10);
|
|
5715
5744
|
return groupNumber % 2 === 1;
|
|
5716
5745
|
};
|
|
5717
5746
|
|
|
@@ -6515,7 +6544,7 @@ dwv.dicom.DicomWriter.prototype.getBuffer = function (dicomElements) {
|
|
|
6515
6544
|
dwv.dicom.checkUnknownVR(element);
|
|
6516
6545
|
|
|
6517
6546
|
// tag group name (remove first 0)
|
|
6518
|
-
groupName = dwv.dicom.TagGroups[element.tag.group.
|
|
6547
|
+
groupName = dwv.dicom.TagGroups[element.tag.group.substring(1)];
|
|
6519
6548
|
|
|
6520
6549
|
// prefix
|
|
6521
6550
|
if (groupName === 'Meta Element') {
|
|
@@ -6795,6 +6824,43 @@ dwv.dicom.setElementValue = function (element, value, isImplicit) {
|
|
|
6795
6824
|
return size;
|
|
6796
6825
|
};
|
|
6797
6826
|
|
|
6827
|
+
/**
|
|
6828
|
+
* Get the DICOM element from a DICOM tags object.
|
|
6829
|
+
*
|
|
6830
|
+
* @param {object} tags The DICOM tags object.
|
|
6831
|
+
* @returns {object} The DICOM elements and the end offset.
|
|
6832
|
+
*/
|
|
6833
|
+
dwv.dicom.getElementsFromJSONTags = function (tags) {
|
|
6834
|
+
// transfer syntax
|
|
6835
|
+
var isImplicit = dwv.dicom.isImplicitTransferSyntax(tags.TransferSyntaxUID);
|
|
6836
|
+
// convert JSON to DICOM element object
|
|
6837
|
+
var keys = Object.keys(tags);
|
|
6838
|
+
var dicomElements = {};
|
|
6839
|
+
var dicomElement;
|
|
6840
|
+
var name;
|
|
6841
|
+
var offset = 128 + 4; // preamble
|
|
6842
|
+
var size;
|
|
6843
|
+
for (var k = 0, len = keys.length; k < len; ++k) {
|
|
6844
|
+
// get the DICOM element definition from its name
|
|
6845
|
+
dicomElement = dwv.dicom.getDicomElement(keys[k]);
|
|
6846
|
+
// set its value
|
|
6847
|
+
size = dwv.dicom.setElementValue(dicomElement, tags[keys[k]], isImplicit);
|
|
6848
|
+
// set offsets
|
|
6849
|
+
offset += dwv.dicom.getDataElementPrefixByteSize(
|
|
6850
|
+
dicomElement.vr, isImplicit);
|
|
6851
|
+
dicomElement.startOffset = offset;
|
|
6852
|
+
offset += size;
|
|
6853
|
+
dicomElement.endOffset = offset;
|
|
6854
|
+
// create the tag group/element key
|
|
6855
|
+
name = new dwv.dicom.Tag(
|
|
6856
|
+
dicomElement.tag.group, dicomElement.tag.element).getKey();
|
|
6857
|
+
// store
|
|
6858
|
+
dicomElements[name] = dicomElement;
|
|
6859
|
+
}
|
|
6860
|
+
// return
|
|
6861
|
+
return {elements: dicomElements, offset: offset};
|
|
6862
|
+
};
|
|
6863
|
+
|
|
6798
6864
|
/*eslint max-len:0*/
|
|
6799
6865
|
// namespaces
|
|
6800
6866
|
var dwv = dwv || {};
|
|
@@ -19591,9 +19657,22 @@ dwv.io.DicomDataLoader.prototype.canLoadFile = function (file) {
|
|
|
19591
19657
|
* - the url has no 'contentType' and no extension or the extension is 'dcm'
|
|
19592
19658
|
*
|
|
19593
19659
|
* @param {string} url The url to check.
|
|
19660
|
+
* @param {object} options Optional url request options.
|
|
19594
19661
|
* @returns {boolean} True if the url can be loaded.
|
|
19595
19662
|
*/
|
|
19596
|
-
dwv.io.DicomDataLoader.prototype.canLoadUrl = function (url) {
|
|
19663
|
+
dwv.io.DicomDataLoader.prototype.canLoadUrl = function (url, options) {
|
|
19664
|
+
// if there are options.requestHeaders, just base check on them
|
|
19665
|
+
if (typeof options !== 'undefined' &&
|
|
19666
|
+
typeof options.requestHeaders !== 'undefined') {
|
|
19667
|
+
// starts with 'application/dicom'
|
|
19668
|
+
var isDicom = function (element) {
|
|
19669
|
+
return element.name === 'Accept' &&
|
|
19670
|
+
dwv.utils.startsWith(element.value, 'application/dicom') &&
|
|
19671
|
+
element.value[18] !== '+';
|
|
19672
|
+
};
|
|
19673
|
+
return typeof options.requestHeaders.find(isDicom) !== 'undefined';
|
|
19674
|
+
}
|
|
19675
|
+
|
|
19597
19676
|
var urlObjext = dwv.utils.getUrlFromUri(url);
|
|
19598
19677
|
// extension
|
|
19599
19678
|
var ext = dwv.utils.getFileExtension(urlObjext.pathname);
|
|
@@ -19602,12 +19681,29 @@ dwv.io.DicomDataLoader.prototype.canLoadUrl = function (url) {
|
|
|
19602
19681
|
// content type (for wado url)
|
|
19603
19682
|
var contentType = urlObjext.searchParams.get('contentType');
|
|
19604
19683
|
var hasContentType = contentType !== null &&
|
|
19605
|
-
|
|
19684
|
+
typeof contentType !== 'undefined';
|
|
19606
19685
|
var hasDicomContentType = (contentType === 'application/dicom');
|
|
19607
19686
|
|
|
19608
19687
|
return hasContentType ? hasDicomContentType : (hasNoExt || hasDcmExt);
|
|
19609
19688
|
};
|
|
19610
19689
|
|
|
19690
|
+
/**
|
|
19691
|
+
* Check if the loader can load the provided memory object.
|
|
19692
|
+
*
|
|
19693
|
+
* @param {object} mem The memory object.
|
|
19694
|
+
* @returns {boolean} True if the object can be loaded.
|
|
19695
|
+
*/
|
|
19696
|
+
dwv.io.DicomDataLoader.prototype.canLoadMemory = function (mem) {
|
|
19697
|
+
if (typeof mem['Content-Type'] !== 'undefined' &&
|
|
19698
|
+
mem['Content-Type'] === 'application/dicom') {
|
|
19699
|
+
return true;
|
|
19700
|
+
}
|
|
19701
|
+
if (typeof mem.filename !== 'undefined') {
|
|
19702
|
+
return this.canLoadFile(mem.filename);
|
|
19703
|
+
}
|
|
19704
|
+
return false;
|
|
19705
|
+
};
|
|
19706
|
+
|
|
19611
19707
|
/**
|
|
19612
19708
|
* Get the file content type needed by the loader.
|
|
19613
19709
|
*
|
|
@@ -20183,14 +20279,45 @@ dwv.io.JSONTextLoader.prototype.canLoadFile = function (file) {
|
|
|
20183
20279
|
* Check if the loader can load the provided url.
|
|
20184
20280
|
*
|
|
20185
20281
|
* @param {string} url The url to check.
|
|
20282
|
+
* @param {object} options Optional url request options.
|
|
20186
20283
|
* @returns {boolean} True if the url can be loaded.
|
|
20187
20284
|
*/
|
|
20188
|
-
dwv.io.JSONTextLoader.prototype.canLoadUrl = function (url) {
|
|
20285
|
+
dwv.io.JSONTextLoader.prototype.canLoadUrl = function (url, options) {
|
|
20286
|
+
// if there are options.requestHeader, just base check on them
|
|
20287
|
+
if (typeof options !== 'undefined' &&
|
|
20288
|
+
typeof options.requestHeaders !== 'undefined') {
|
|
20289
|
+
// starts with 'application/json' or 'application/dicom+json
|
|
20290
|
+
var isJson = function (element) {
|
|
20291
|
+
return element.name === 'Accept' &&
|
|
20292
|
+
dwv.utils.startsWith(element.value, 'application/json') &&
|
|
20293
|
+
dwv.utils.startsWith(element.value, 'application/dicom+json');
|
|
20294
|
+
};
|
|
20295
|
+
return typeof options.requestHeaders.find(isJson) !== 'undefined';
|
|
20296
|
+
}
|
|
20297
|
+
|
|
20189
20298
|
var urlObjext = dwv.utils.getUrlFromUri(url);
|
|
20190
20299
|
var ext = dwv.utils.getFileExtension(urlObjext.pathname);
|
|
20191
20300
|
return (ext === 'json');
|
|
20192
20301
|
};
|
|
20193
20302
|
|
|
20303
|
+
/**
|
|
20304
|
+
* Check if the loader can load the provided memory object.
|
|
20305
|
+
*
|
|
20306
|
+
* @param {object} mem The memory object.
|
|
20307
|
+
* @returns {boolean} True if the object can be loaded.
|
|
20308
|
+
*/
|
|
20309
|
+
dwv.io.JSONTextLoader.prototype.canLoadMemory = function (mem) {
|
|
20310
|
+
if (typeof mem['Content-Type'] !== 'undefined') {
|
|
20311
|
+
if (mem['Content-Type'].includes('json')) {
|
|
20312
|
+
return true;
|
|
20313
|
+
}
|
|
20314
|
+
}
|
|
20315
|
+
if (typeof mem.filename !== 'undefined') {
|
|
20316
|
+
return this.canLoadFile(mem.filename);
|
|
20317
|
+
}
|
|
20318
|
+
return false;
|
|
20319
|
+
};
|
|
20320
|
+
|
|
20194
20321
|
/**
|
|
20195
20322
|
* Get the file content type needed by the loader.
|
|
20196
20323
|
*
|
|
@@ -20453,7 +20580,7 @@ dwv.io.MemoryLoader = function () {
|
|
|
20453
20580
|
var foundLoader = false;
|
|
20454
20581
|
for (var l = 0; l < loaders.length; ++l) {
|
|
20455
20582
|
loader = loaders[l];
|
|
20456
|
-
if (loader.
|
|
20583
|
+
if (loader.canLoadMemory(dataElement)) {
|
|
20457
20584
|
foundLoader = true;
|
|
20458
20585
|
// load options
|
|
20459
20586
|
loader.setOptions({
|
|
@@ -20488,7 +20615,7 @@ dwv.io.MemoryLoader = function () {
|
|
|
20488
20615
|
for (var i = 0; i < data.length; ++i) {
|
|
20489
20616
|
dataElement = data[i];
|
|
20490
20617
|
// check loader
|
|
20491
|
-
if (!loader.
|
|
20618
|
+
if (!loader.canLoadMemory(dataElement)) {
|
|
20492
20619
|
throw new Error('Input data of different type: ' +
|
|
20493
20620
|
dataElement.filename);
|
|
20494
20621
|
}
|
|
@@ -20566,6 +20693,214 @@ dwv.io.MemoryLoader.prototype.onabort = function (_event) {};
|
|
|
20566
20693
|
var dwv = dwv || {};
|
|
20567
20694
|
dwv.io = dwv.io || {};
|
|
20568
20695
|
|
|
20696
|
+
/**
|
|
20697
|
+
* Multipart data loader.
|
|
20698
|
+
*
|
|
20699
|
+
* @class
|
|
20700
|
+
*/
|
|
20701
|
+
dwv.io.MultipartLoader = function () {
|
|
20702
|
+
// closure to self
|
|
20703
|
+
var self = this;
|
|
20704
|
+
|
|
20705
|
+
/**
|
|
20706
|
+
* Loading flag.
|
|
20707
|
+
*
|
|
20708
|
+
* @private
|
|
20709
|
+
* @type {boolean}
|
|
20710
|
+
*/
|
|
20711
|
+
var isLoading = false;
|
|
20712
|
+
|
|
20713
|
+
/**
|
|
20714
|
+
* Set the loader options.
|
|
20715
|
+
*
|
|
20716
|
+
* @param {object} _opt The input options.
|
|
20717
|
+
*/
|
|
20718
|
+
this.setOptions = function (_opt) {
|
|
20719
|
+
// does nothing
|
|
20720
|
+
};
|
|
20721
|
+
|
|
20722
|
+
/**
|
|
20723
|
+
* Is the load ongoing?
|
|
20724
|
+
*
|
|
20725
|
+
* @returns {boolean} True if loading.
|
|
20726
|
+
*/
|
|
20727
|
+
this.isLoading = function () {
|
|
20728
|
+
return isLoading;
|
|
20729
|
+
};
|
|
20730
|
+
|
|
20731
|
+
/**
|
|
20732
|
+
* Load data.
|
|
20733
|
+
*
|
|
20734
|
+
* @param {object} buffer The DICOM buffer.
|
|
20735
|
+
* @param {string} origin The data origin.
|
|
20736
|
+
* @param {number} index The data index.
|
|
20737
|
+
*/
|
|
20738
|
+
this.load = function (buffer, origin, index) {
|
|
20739
|
+
// send start event
|
|
20740
|
+
this.onloadstart({
|
|
20741
|
+
source: origin
|
|
20742
|
+
});
|
|
20743
|
+
// set loading flag
|
|
20744
|
+
isLoading = true;
|
|
20745
|
+
|
|
20746
|
+
var memoryIO = new dwv.io.MemoryLoader();
|
|
20747
|
+
// memoryIO.onloadstart: nothing to do
|
|
20748
|
+
memoryIO.onprogress = function (progress) {
|
|
20749
|
+
// add 50% to take into account the un-Multipartping
|
|
20750
|
+
progress.loaded = 50 + progress.loaded / 2;
|
|
20751
|
+
// set data index
|
|
20752
|
+
progress.index = index;
|
|
20753
|
+
self.onprogress(progress);
|
|
20754
|
+
};
|
|
20755
|
+
memoryIO.onloaditem = self.onloaditem;
|
|
20756
|
+
memoryIO.onload = self.onload;
|
|
20757
|
+
memoryIO.onloadend = function (event) {
|
|
20758
|
+
// reset loading flag
|
|
20759
|
+
isLoading = false;
|
|
20760
|
+
// call listeners
|
|
20761
|
+
self.onloadend(event);
|
|
20762
|
+
};
|
|
20763
|
+
memoryIO.onerror = self.onerror;
|
|
20764
|
+
memoryIO.onabort = self.onabort;
|
|
20765
|
+
// launch
|
|
20766
|
+
memoryIO.load(dwv.utils.parseMultipart(buffer));
|
|
20767
|
+
};
|
|
20768
|
+
|
|
20769
|
+
/**
|
|
20770
|
+
* Abort load: pass to listeners.
|
|
20771
|
+
*/
|
|
20772
|
+
this.abort = function () {
|
|
20773
|
+
// reset loading flag
|
|
20774
|
+
isLoading = false;
|
|
20775
|
+
// call listeners
|
|
20776
|
+
self.onabort({});
|
|
20777
|
+
self.onloadend({});
|
|
20778
|
+
};
|
|
20779
|
+
|
|
20780
|
+
}; // class MultipartLoader
|
|
20781
|
+
|
|
20782
|
+
/**
|
|
20783
|
+
* Check if the loader can load the provided file.
|
|
20784
|
+
*
|
|
20785
|
+
* @param {object} _file The file to check.
|
|
20786
|
+
* @returns {boolean} True if the file can be loaded.
|
|
20787
|
+
*/
|
|
20788
|
+
dwv.io.MultipartLoader.prototype.canLoadFile = function (_file) {
|
|
20789
|
+
return false;
|
|
20790
|
+
};
|
|
20791
|
+
|
|
20792
|
+
/**
|
|
20793
|
+
* Check if the loader can load the provided url.
|
|
20794
|
+
*
|
|
20795
|
+
* @param {string} url The url to check.
|
|
20796
|
+
* @param {object} options The url request options.
|
|
20797
|
+
* @returns {boolean} True if the url can be loaded.
|
|
20798
|
+
*/
|
|
20799
|
+
dwv.io.MultipartLoader.prototype.canLoadUrl = function (url, options) {
|
|
20800
|
+
// if there are options.requestHeaders, just base check on them
|
|
20801
|
+
if (typeof options !== 'undefined' &&
|
|
20802
|
+
typeof options.requestHeaders !== 'undefined') {
|
|
20803
|
+
var isMultipart = function (element) {
|
|
20804
|
+
return element.name === 'Accept' &&
|
|
20805
|
+
dwv.utils.startsWith(element.value, 'multipart/related');
|
|
20806
|
+
};
|
|
20807
|
+
return typeof options.requestHeaders.find(isMultipart) !== 'undefined';
|
|
20808
|
+
}
|
|
20809
|
+
|
|
20810
|
+
return false;
|
|
20811
|
+
};
|
|
20812
|
+
|
|
20813
|
+
/**
|
|
20814
|
+
* Check if the loader can load the provided memory object.
|
|
20815
|
+
*
|
|
20816
|
+
* @param {object} _mem The memory object.
|
|
20817
|
+
* @returns {boolean} True if the url can be loaded.
|
|
20818
|
+
*/
|
|
20819
|
+
dwv.io.MultipartLoader.prototype.canLoadMemory = function (_mem) {
|
|
20820
|
+
return false;
|
|
20821
|
+
};
|
|
20822
|
+
|
|
20823
|
+
/**
|
|
20824
|
+
* Get the file content type needed by the loader.
|
|
20825
|
+
*
|
|
20826
|
+
* @returns {number} One of the 'dwv.io.fileContentTypes'.
|
|
20827
|
+
*/
|
|
20828
|
+
dwv.io.MultipartLoader.prototype.loadFileAs = function () {
|
|
20829
|
+
return dwv.io.fileContentTypes.ArrayBuffer;
|
|
20830
|
+
};
|
|
20831
|
+
|
|
20832
|
+
/**
|
|
20833
|
+
* Get the url content type needed by the loader.
|
|
20834
|
+
*
|
|
20835
|
+
* @returns {number} One of the 'dwv.io.urlContentTypes'.
|
|
20836
|
+
*/
|
|
20837
|
+
dwv.io.MultipartLoader.prototype.loadUrlAs = function () {
|
|
20838
|
+
return dwv.io.urlContentTypes.ArrayBuffer;
|
|
20839
|
+
};
|
|
20840
|
+
|
|
20841
|
+
/**
|
|
20842
|
+
* Handle a load start event.
|
|
20843
|
+
* Default does nothing.
|
|
20844
|
+
*
|
|
20845
|
+
* @param {object} _event The load start event.
|
|
20846
|
+
*/
|
|
20847
|
+
dwv.io.MultipartLoader.prototype.onloadstart = function (_event) {};
|
|
20848
|
+
/**
|
|
20849
|
+
* Handle a load progress event.
|
|
20850
|
+
* Default does nothing.
|
|
20851
|
+
*
|
|
20852
|
+
* @param {object} _event The progress event.
|
|
20853
|
+
*/
|
|
20854
|
+
dwv.io.MultipartLoader.prototype.onprogress = function (_event) {};
|
|
20855
|
+
/**
|
|
20856
|
+
* Handle a load item event.
|
|
20857
|
+
* Default does nothing.
|
|
20858
|
+
*
|
|
20859
|
+
* @param {object} _event The load item event fired
|
|
20860
|
+
* when a file item has been loaded successfully.
|
|
20861
|
+
*/
|
|
20862
|
+
dwv.io.MultipartLoader.prototype.onloaditem = function (_event) {};
|
|
20863
|
+
/**
|
|
20864
|
+
* Handle a load event.
|
|
20865
|
+
* Default does nothing.
|
|
20866
|
+
*
|
|
20867
|
+
* @param {object} _event The load event fired
|
|
20868
|
+
* when a file has been loaded successfully.
|
|
20869
|
+
*/
|
|
20870
|
+
dwv.io.MultipartLoader.prototype.onload = function (_event) {};
|
|
20871
|
+
/**
|
|
20872
|
+
* Handle an load end event.
|
|
20873
|
+
* Default does nothing.
|
|
20874
|
+
*
|
|
20875
|
+
* @param {object} _event The load end event fired
|
|
20876
|
+
* when a file load has completed, successfully or not.
|
|
20877
|
+
*/
|
|
20878
|
+
dwv.io.MultipartLoader.prototype.onloadend = function (_event) {};
|
|
20879
|
+
/**
|
|
20880
|
+
* Handle an error event.
|
|
20881
|
+
* Default does nothing.
|
|
20882
|
+
*
|
|
20883
|
+
* @param {object} _event The error event.
|
|
20884
|
+
*/
|
|
20885
|
+
dwv.io.MultipartLoader.prototype.onerror = function (_event) {};
|
|
20886
|
+
/**
|
|
20887
|
+
* Handle an abort event.
|
|
20888
|
+
* Default does nothing.
|
|
20889
|
+
*
|
|
20890
|
+
* @param {object} _event The abort event.
|
|
20891
|
+
*/
|
|
20892
|
+
dwv.io.MultipartLoader.prototype.onabort = function (_event) {};
|
|
20893
|
+
|
|
20894
|
+
/**
|
|
20895
|
+
* Add to Loader list.
|
|
20896
|
+
*/
|
|
20897
|
+
dwv.io.loaderList = dwv.io.loaderList || [];
|
|
20898
|
+
dwv.io.loaderList.push('MultipartLoader');
|
|
20899
|
+
|
|
20900
|
+
// namespaces
|
|
20901
|
+
var dwv = dwv || {};
|
|
20902
|
+
dwv.io = dwv.io || {};
|
|
20903
|
+
|
|
20569
20904
|
/**
|
|
20570
20905
|
* Raw image loader.
|
|
20571
20906
|
*
|
|
@@ -20692,9 +21027,21 @@ dwv.io.RawImageLoader.prototype.canLoadFile = function (file) {
|
|
|
20692
21027
|
* Check if the loader can load the provided url.
|
|
20693
21028
|
*
|
|
20694
21029
|
* @param {string} url The url to check.
|
|
21030
|
+
* @param {object} options Optional url request options.
|
|
20695
21031
|
* @returns {boolean} True if the url can be loaded.
|
|
20696
21032
|
*/
|
|
20697
|
-
dwv.io.RawImageLoader.prototype.canLoadUrl = function (url) {
|
|
21033
|
+
dwv.io.RawImageLoader.prototype.canLoadUrl = function (url, options) {
|
|
21034
|
+
// if there are options.requestHeaders, just base check on them
|
|
21035
|
+
if (typeof options !== 'undefined' &&
|
|
21036
|
+
typeof options.requestHeaders !== 'undefined') {
|
|
21037
|
+
// starts with 'image/'
|
|
21038
|
+
var isImage = function (element) {
|
|
21039
|
+
return element.name === 'Accept' &&
|
|
21040
|
+
dwv.utils.startsWith(element.value, 'image/');
|
|
21041
|
+
};
|
|
21042
|
+
return typeof options.requestHeaders.find(isImage) !== 'undefined';
|
|
21043
|
+
}
|
|
21044
|
+
|
|
20698
21045
|
var urlObjext = dwv.utils.getUrlFromUri(url);
|
|
20699
21046
|
// extension
|
|
20700
21047
|
var ext = dwv.utils.getFileExtension(urlObjext.pathname);
|
|
@@ -20711,6 +21058,19 @@ dwv.io.RawImageLoader.prototype.canLoadUrl = function (url) {
|
|
|
20711
21058
|
return hasContentType ? hasImageContentType : hasImageExt;
|
|
20712
21059
|
};
|
|
20713
21060
|
|
|
21061
|
+
/**
|
|
21062
|
+
* Check if the loader can load the provided memory object.
|
|
21063
|
+
*
|
|
21064
|
+
* @param {object} mem The memory object.
|
|
21065
|
+
* @returns {boolean} True if the object can be loaded.
|
|
21066
|
+
*/
|
|
21067
|
+
dwv.io.RawImageLoader.prototype.canLoadMemory = function (mem) {
|
|
21068
|
+
if (typeof mem.filename !== 'undefined') {
|
|
21069
|
+
return this.canLoadFile(mem.filename);
|
|
21070
|
+
}
|
|
21071
|
+
return false;
|
|
21072
|
+
};
|
|
21073
|
+
|
|
20714
21074
|
/**
|
|
20715
21075
|
* Get the file content type needed by the loader.
|
|
20716
21076
|
*
|
|
@@ -20896,15 +21256,40 @@ dwv.io.RawVideoLoader.prototype.canLoadFile = function (file) {
|
|
|
20896
21256
|
* Check if the loader can load the provided url.
|
|
20897
21257
|
*
|
|
20898
21258
|
* @param {string} url The url to check.
|
|
21259
|
+
* @param {object} options Optional url request options.
|
|
20899
21260
|
* @returns {boolean} True if the url can be loaded.
|
|
20900
21261
|
*/
|
|
20901
|
-
dwv.io.RawVideoLoader.prototype.canLoadUrl = function (url) {
|
|
21262
|
+
dwv.io.RawVideoLoader.prototype.canLoadUrl = function (url, options) {
|
|
21263
|
+
// if there are options.requestHeaders, just base check on them
|
|
21264
|
+
if (typeof options !== 'undefined' &&
|
|
21265
|
+
typeof options.requestHeaders !== 'undefined') {
|
|
21266
|
+
// starts with 'video/'
|
|
21267
|
+
var isVideo = function (element) {
|
|
21268
|
+
return element.name === 'Accept' &&
|
|
21269
|
+
dwv.utils.startsWith(element.value, 'video/');
|
|
21270
|
+
};
|
|
21271
|
+
return typeof options.requestHeaders.find(isVideo) !== 'undefined';
|
|
21272
|
+
}
|
|
21273
|
+
|
|
20902
21274
|
var urlObjext = dwv.utils.getUrlFromUri(url);
|
|
20903
21275
|
var ext = dwv.utils.getFileExtension(urlObjext.pathname);
|
|
20904
21276
|
return (ext === 'mp4') || (ext === 'ogg') ||
|
|
20905
21277
|
(ext === 'webm');
|
|
20906
21278
|
};
|
|
20907
21279
|
|
|
21280
|
+
/**
|
|
21281
|
+
* Check if the loader can load the provided memory object.
|
|
21282
|
+
*
|
|
21283
|
+
* @param {object} mem The memory object.
|
|
21284
|
+
* @returns {boolean} True if the object can be loaded.
|
|
21285
|
+
*/
|
|
21286
|
+
dwv.io.RawVideoLoader.prototype.canLoadMemory = function (mem) {
|
|
21287
|
+
if (typeof mem.filename !== 'undefined') {
|
|
21288
|
+
return this.canLoadFile(mem.filename);
|
|
21289
|
+
}
|
|
21290
|
+
return false;
|
|
21291
|
+
};
|
|
21292
|
+
|
|
20908
21293
|
/**
|
|
20909
21294
|
* Get the file content type needed by the loader.
|
|
20910
21295
|
*
|
|
@@ -21033,7 +21418,7 @@ dwv.io.State = function () {
|
|
|
21033
21418
|
version: '0.5',
|
|
21034
21419
|
'window-center': viewController.getWindowLevel().center,
|
|
21035
21420
|
'window-width': viewController.getWindowLevel().width,
|
|
21036
|
-
position:
|
|
21421
|
+
position: position.getValues(),
|
|
21037
21422
|
scale: app.getAddedScale(),
|
|
21038
21423
|
offset: app.getOffset(),
|
|
21039
21424
|
drawings: drawLayer.getKonvaLayer().toObject(),
|
|
@@ -21078,9 +21463,7 @@ dwv.io.State = function () {
|
|
|
21078
21463
|
// display
|
|
21079
21464
|
viewController.setWindowLevel(
|
|
21080
21465
|
data['window-center'], data['window-width']);
|
|
21081
|
-
viewController.setCurrentPosition(
|
|
21082
|
-
new dwv.math.Point3D(
|
|
21083
|
-
data.position[0], data.position[1], data.position[2]), true);
|
|
21466
|
+
viewController.setCurrentPosition(new dwv.math.Point(data.position));
|
|
21084
21467
|
// apply saved scale on top of current base one
|
|
21085
21468
|
var baseScale = app.getActiveLayerGroup().getBaseScale();
|
|
21086
21469
|
var scale = null;
|
|
@@ -21370,8 +21753,8 @@ dwv.io.v01Tov02DrawingsAndDetails = function (inputDrawings) {
|
|
|
21370
21753
|
if (drawGroup.name() === 'ruler-group') {
|
|
21371
21754
|
quant = {
|
|
21372
21755
|
length: {
|
|
21373
|
-
value: parseFloat(textExpr.
|
|
21374
|
-
unit: textExpr.
|
|
21756
|
+
value: parseFloat(textExpr.substring(0, txtLen - 2)),
|
|
21757
|
+
unit: textExpr.substring(-2)
|
|
21375
21758
|
}
|
|
21376
21759
|
};
|
|
21377
21760
|
textExpr = '{length}';
|
|
@@ -21379,8 +21762,8 @@ dwv.io.v01Tov02DrawingsAndDetails = function (inputDrawings) {
|
|
|
21379
21762
|
drawGroup.name() === 'rectangle-group') {
|
|
21380
21763
|
quant = {
|
|
21381
21764
|
surface: {
|
|
21382
|
-
value: parseFloat(textExpr.
|
|
21383
|
-
unit: textExpr.
|
|
21765
|
+
value: parseFloat(textExpr.substring(0, txtLen - 3)),
|
|
21766
|
+
unit: textExpr.substring(-3)
|
|
21384
21767
|
}
|
|
21385
21768
|
};
|
|
21386
21769
|
textExpr = '{surface}';
|
|
@@ -21388,8 +21771,8 @@ dwv.io.v01Tov02DrawingsAndDetails = function (inputDrawings) {
|
|
|
21388
21771
|
drawGroup.name() === 'rectangle-group') {
|
|
21389
21772
|
quant = {
|
|
21390
21773
|
angle: {
|
|
21391
|
-
value: parseFloat(textExpr.
|
|
21392
|
-
unit: textExpr.
|
|
21774
|
+
value: parseFloat(textExpr.substring(0, txtLen - 1)),
|
|
21775
|
+
unit: textExpr.substring(-1)
|
|
21393
21776
|
}
|
|
21394
21777
|
};
|
|
21395
21778
|
textExpr = '{angle}';
|
|
@@ -21782,7 +22165,7 @@ dwv.io.UrlsLoader = function () {
|
|
|
21782
22165
|
var foundLoader = false;
|
|
21783
22166
|
for (var l = 0; l < loaders.length; ++l) {
|
|
21784
22167
|
loader = loaders[l];
|
|
21785
|
-
if (loader.canLoadUrl(dataElement)) {
|
|
22168
|
+
if (loader.canLoadUrl(dataElement, options)) {
|
|
21786
22169
|
foundLoader = true;
|
|
21787
22170
|
// load options
|
|
21788
22171
|
loader.setOptions({
|
|
@@ -21850,7 +22233,7 @@ dwv.io.UrlsLoader = function () {
|
|
|
21850
22233
|
dataElement = data[i];
|
|
21851
22234
|
|
|
21852
22235
|
// check loader
|
|
21853
|
-
if (!loader.canLoadUrl(dataElement)) {
|
|
22236
|
+
if (!loader.canLoadUrl(dataElement, options)) {
|
|
21854
22237
|
throw new Error('Input url of different type: ' + dataElement);
|
|
21855
22238
|
}
|
|
21856
22239
|
/**
|
|
@@ -22204,14 +22587,36 @@ dwv.io.ZipLoader.prototype.canLoadFile = function (file) {
|
|
|
22204
22587
|
* Check if the loader can load the provided url.
|
|
22205
22588
|
*
|
|
22206
22589
|
* @param {string} url The url to check.
|
|
22590
|
+
* @param {object} options Optional url request options.
|
|
22207
22591
|
* @returns {boolean} True if the url can be loaded.
|
|
22208
22592
|
*/
|
|
22209
|
-
dwv.io.ZipLoader.prototype.canLoadUrl = function (url) {
|
|
22593
|
+
dwv.io.ZipLoader.prototype.canLoadUrl = function (url, options) {
|
|
22594
|
+
// if there are options.requestHeaders, just base check on them
|
|
22595
|
+
if (typeof options !== 'undefined' &&
|
|
22596
|
+
typeof options.requestHeaders !== 'undefined') {
|
|
22597
|
+
// starts with 'application/zip'
|
|
22598
|
+
var isZip = function (element) {
|
|
22599
|
+
return element.name === 'Accept' &&
|
|
22600
|
+
dwv.utils.startsWith(element.value, 'application/zip');
|
|
22601
|
+
};
|
|
22602
|
+
return typeof options.requestHeaders.find(isZip) !== 'undefined';
|
|
22603
|
+
}
|
|
22604
|
+
|
|
22210
22605
|
var urlObjext = dwv.utils.getUrlFromUri(url);
|
|
22211
22606
|
var ext = dwv.utils.getFileExtension(urlObjext.pathname);
|
|
22212
22607
|
return (ext === 'zip');
|
|
22213
22608
|
};
|
|
22214
22609
|
|
|
22610
|
+
/**
|
|
22611
|
+
* Check if the loader can load the provided memory object.
|
|
22612
|
+
*
|
|
22613
|
+
* @param {object} _mem The memory object.
|
|
22614
|
+
* @returns {boolean} True if the object can be loaded.
|
|
22615
|
+
*/
|
|
22616
|
+
dwv.io.ZipLoader.prototype.canLoadMemory = function (_mem) {
|
|
22617
|
+
return false;
|
|
22618
|
+
};
|
|
22619
|
+
|
|
22215
22620
|
/**
|
|
22216
22621
|
* Get the file content type needed by the loader.
|
|
22217
22622
|
*
|
|
@@ -31707,8 +32112,9 @@ dwv.tool.ZoomAndPan = function (app) {
|
|
|
31707
32112
|
// zoom mode
|
|
31708
32113
|
var zoom = (lineRatio - 1) / 2;
|
|
31709
32114
|
if (Math.abs(zoom) % 0.1 <= 0.05) {
|
|
31710
|
-
var planePos = viewLayer.
|
|
31711
|
-
|
|
32115
|
+
var planePos = viewLayer.displayToMainPlanePos(
|
|
32116
|
+
self.midPoint.getX(), self.midPoint.getY());
|
|
32117
|
+
var center = viewController.getPlanePositionFromPlanePoint(planePos);
|
|
31712
32118
|
layerGroup.addScale(zoom, center);
|
|
31713
32119
|
layerGroup.draw();
|
|
31714
32120
|
}
|
|
@@ -31843,6 +32249,223 @@ dwv.tool.ZoomAndPan.prototype.init = function () {
|
|
|
31843
32249
|
var dwv = dwv || {};
|
|
31844
32250
|
dwv.utils = dwv.utils || {};
|
|
31845
32251
|
|
|
32252
|
+
/**
|
|
32253
|
+
* Convert a Uint8Array to a string.
|
|
32254
|
+
*
|
|
32255
|
+
* @param {Uint8Array} arr The array to convert.
|
|
32256
|
+
* @returns {string} The array as string.
|
|
32257
|
+
*/
|
|
32258
|
+
dwv.utils.uint8ArrayToString = function (arr) {
|
|
32259
|
+
return String.fromCharCode.apply(String, arr);
|
|
32260
|
+
};
|
|
32261
|
+
|
|
32262
|
+
/**
|
|
32263
|
+
* Array find in a subset of the input array.
|
|
32264
|
+
* Equivalent to: arr.slice(start, end).find(callbackFn)
|
|
32265
|
+
*
|
|
32266
|
+
* @param {Array} arr The input array to search.
|
|
32267
|
+
* @param {Function} callbackFn The find function.
|
|
32268
|
+
* @param {number} start The array start index.
|
|
32269
|
+
* @param {number} end The array end index.
|
|
32270
|
+
* @returns {number} The index where the element was found.
|
|
32271
|
+
*/
|
|
32272
|
+
dwv.utils.findInArraySubset = function (arr, callbackFn, start, end) {
|
|
32273
|
+
// check inputs
|
|
32274
|
+
if (typeof start === 'undefined' ||
|
|
32275
|
+
start < 0 ||
|
|
32276
|
+
start >= arr.length
|
|
32277
|
+
) {
|
|
32278
|
+
start = 0;
|
|
32279
|
+
}
|
|
32280
|
+
if (typeof end === 'undefined' ||
|
|
32281
|
+
end <= start ||
|
|
32282
|
+
end > arr.length) {
|
|
32283
|
+
end = arr.length;
|
|
32284
|
+
}
|
|
32285
|
+
// run
|
|
32286
|
+
for (var i = start; i < end; ++i) {
|
|
32287
|
+
if (callbackFn(arr[i], i, arr)) {
|
|
32288
|
+
return i;
|
|
32289
|
+
}
|
|
32290
|
+
}
|
|
32291
|
+
return;
|
|
32292
|
+
};
|
|
32293
|
+
|
|
32294
|
+
/**
|
|
32295
|
+
* Get a find in array callback.
|
|
32296
|
+
*
|
|
32297
|
+
* @param {Array} arr1 The array to find.
|
|
32298
|
+
* @returns {Function} The find callback function.
|
|
32299
|
+
*/
|
|
32300
|
+
dwv.utils.getFindArrayInArrayCallback = function (arr1) {
|
|
32301
|
+
return function (element, index, arr0) {
|
|
32302
|
+
for (var i = 0; i < arr1.length; ++i) {
|
|
32303
|
+
if (arr0[index + i] !== arr1[i]) {
|
|
32304
|
+
return false;
|
|
32305
|
+
}
|
|
32306
|
+
}
|
|
32307
|
+
return true;
|
|
32308
|
+
};
|
|
32309
|
+
};
|
|
32310
|
+
|
|
32311
|
+
/**
|
|
32312
|
+
* Extract each element of a multipart ArrayBuffer.
|
|
32313
|
+
* https://en.wikipedia.org/wiki/MIME#Multipart_messages
|
|
32314
|
+
*
|
|
32315
|
+
* @param {ArrayBuffer} arr The multipart array.
|
|
32316
|
+
* @returns {Array} The multipart parts as an array of object as
|
|
32317
|
+
* {'Content-Type', ..., data} (depending on header tags)
|
|
32318
|
+
*/
|
|
32319
|
+
dwv.utils.parseMultipart = function (arr) {
|
|
32320
|
+
var u8Array = new Uint8Array(arr);
|
|
32321
|
+
|
|
32322
|
+
var parts = [];
|
|
32323
|
+
// check input
|
|
32324
|
+
if (u8Array.length === 0) {
|
|
32325
|
+
return parts;
|
|
32326
|
+
}
|
|
32327
|
+
|
|
32328
|
+
// \r\n\r\n
|
|
32329
|
+
var doubleReturnNew = new Uint8Array([0x0d, 0x0a, 0x0d, 0x0a]);
|
|
32330
|
+
var partHeaderEndCb = dwv.utils.getFindArrayInArrayCallback(doubleReturnNew);
|
|
32331
|
+
|
|
32332
|
+
// look for boundary in first part header
|
|
32333
|
+
var partHeaderEndIndex = dwv.utils.findInArraySubset(
|
|
32334
|
+
u8Array, partHeaderEndCb, 0
|
|
32335
|
+
);
|
|
32336
|
+
if (typeof partHeaderEndIndex === 'undefined') {
|
|
32337
|
+
throw new Error('Can\'t find the end of the first multipart header');
|
|
32338
|
+
}
|
|
32339
|
+
var firstPartHeader = u8Array.slice(0, partHeaderEndIndex);
|
|
32340
|
+
// switch to string to use split
|
|
32341
|
+
var lines = dwv.utils.uint8ArrayToString(firstPartHeader).split('\r\n');
|
|
32342
|
+
// boundary should start with '--'
|
|
32343
|
+
var boundaryStr;
|
|
32344
|
+
for (var i = 0; i < lines.length; ++i) {
|
|
32345
|
+
if (lines[i][0] === '-' && lines[i][1] === '-') {
|
|
32346
|
+
boundaryStr = lines[i];
|
|
32347
|
+
break;
|
|
32348
|
+
}
|
|
32349
|
+
}
|
|
32350
|
+
if (typeof boundaryStr === 'undefined') {
|
|
32351
|
+
throw new Error('Can\'t find the boundary between multi-parts');
|
|
32352
|
+
}
|
|
32353
|
+
var boundary = dwv.utils.stringToUint8Array(boundaryStr);
|
|
32354
|
+
var boundaryCb = dwv.utils.getFindArrayInArrayCallback(boundary);
|
|
32355
|
+
var boundaryLen = boundaryStr.length;
|
|
32356
|
+
|
|
32357
|
+
// skip mime header
|
|
32358
|
+
var nextBoundaryIndex = dwv.utils.findInArraySubset(
|
|
32359
|
+
u8Array, boundaryCb, 0
|
|
32360
|
+
);
|
|
32361
|
+
|
|
32362
|
+
// loop through content
|
|
32363
|
+
while (typeof partHeaderEndIndex !== 'undefined') {
|
|
32364
|
+
var part = {};
|
|
32365
|
+
|
|
32366
|
+
// header
|
|
32367
|
+
var partHeader = u8Array.slice(
|
|
32368
|
+
nextBoundaryIndex + boundaryLen, partHeaderEndIndex);
|
|
32369
|
+
// split into object
|
|
32370
|
+
var partHeaderLines =
|
|
32371
|
+
dwv.utils.uint8ArrayToString(partHeader).split('\r\n');
|
|
32372
|
+
for (var l = 0; l < partHeaderLines.length; ++l) {
|
|
32373
|
+
var line = partHeaderLines[l];
|
|
32374
|
+
var semiColonIndex = line.indexOf(':');
|
|
32375
|
+
if (semiColonIndex !== -1) {
|
|
32376
|
+
var key = line.substring(0, semiColonIndex).trim();
|
|
32377
|
+
var val = line.substring(semiColonIndex + 1).trim();
|
|
32378
|
+
part[key] = val;
|
|
32379
|
+
}
|
|
32380
|
+
}
|
|
32381
|
+
|
|
32382
|
+
// find next boundary
|
|
32383
|
+
nextBoundaryIndex = dwv.utils.findInArraySubset(
|
|
32384
|
+
u8Array, boundaryCb, partHeaderEndIndex
|
|
32385
|
+
);
|
|
32386
|
+
// exit if none
|
|
32387
|
+
if (typeof nextBoundaryIndex === 'undefined') {
|
|
32388
|
+
break;
|
|
32389
|
+
}
|
|
32390
|
+
|
|
32391
|
+
// get part
|
|
32392
|
+
// partHeaderEndIndex plus the size of the '\r\n\r\n' separator
|
|
32393
|
+
var dataBeginIndex = partHeaderEndIndex + 4;
|
|
32394
|
+
// nextBoundaryIndex minus the previous '\r\n'
|
|
32395
|
+
var dataEndIndex = nextBoundaryIndex - 2;
|
|
32396
|
+
if (dataBeginIndex < dataEndIndex) {
|
|
32397
|
+
part.data = u8Array.slice(dataBeginIndex, dataEndIndex).buffer;
|
|
32398
|
+
} else {
|
|
32399
|
+
part.data = new Uint8Array();
|
|
32400
|
+
}
|
|
32401
|
+
|
|
32402
|
+
// store part
|
|
32403
|
+
parts.push(part);
|
|
32404
|
+
|
|
32405
|
+
// find next part header end
|
|
32406
|
+
partHeaderEndIndex = dwv.utils.findInArraySubset(
|
|
32407
|
+
u8Array, partHeaderEndCb,
|
|
32408
|
+
nextBoundaryIndex + boundaryLen
|
|
32409
|
+
);
|
|
32410
|
+
}
|
|
32411
|
+
|
|
32412
|
+
return parts;
|
|
32413
|
+
};
|
|
32414
|
+
|
|
32415
|
+
/**
|
|
32416
|
+
* Build a multipart message.
|
|
32417
|
+
* See: https://en.wikipedia.org/wiki/MIME#Multipart_messages
|
|
32418
|
+
* See: https://hg.orthanc-server.com/orthanc-dicomweb/file/tip/Resources/Samples/JavaScript/stow-rs.js
|
|
32419
|
+
*
|
|
32420
|
+
* @param {Array} parts The message parts as an array of object containing
|
|
32421
|
+
* content headers and messages as the data property (as returned by parse).
|
|
32422
|
+
* @param {string} boundary The message boundary.
|
|
32423
|
+
* @returns {Uint8Array} The full multipart message.
|
|
32424
|
+
*/
|
|
32425
|
+
dwv.utils.buildMultipart = function (parts, boundary) {
|
|
32426
|
+
var lineBreak = '\r\n';
|
|
32427
|
+
// build headers and calculate size
|
|
32428
|
+
var partsSize = 0;
|
|
32429
|
+
var headers = [];
|
|
32430
|
+
for (var i = 0; i < parts.length; ++i) {
|
|
32431
|
+
var headerStr = '--' + boundary + lineBreak;
|
|
32432
|
+
var partKeys = Object.keys(parts[i]);
|
|
32433
|
+
for (var k = 0; k < partKeys.length; ++k) {
|
|
32434
|
+
var key = partKeys[k];
|
|
32435
|
+
if (key !== 'data') {
|
|
32436
|
+
headerStr += key + ': ' + parts[i][key] + lineBreak;
|
|
32437
|
+
}
|
|
32438
|
+
}
|
|
32439
|
+
headerStr += lineBreak;
|
|
32440
|
+
var header = dwv.utils.stringToUint8Array(headerStr);
|
|
32441
|
+
headers.push(header);
|
|
32442
|
+
partsSize += header.byteLength + parts[i].data.byteLength;
|
|
32443
|
+
}
|
|
32444
|
+
// build trailer
|
|
32445
|
+
var trailerStr = '--' + boundary + '--' + lineBreak;
|
|
32446
|
+
var trailer = dwv.utils.stringToUint8Array(trailerStr);
|
|
32447
|
+
|
|
32448
|
+
// final buffer
|
|
32449
|
+
var buffer = new Uint8Array(partsSize + trailer.byteLength);
|
|
32450
|
+
var offset = 0;
|
|
32451
|
+
// concatenate parts
|
|
32452
|
+
for (var j = 0; j < parts.length; ++j) {
|
|
32453
|
+
buffer.set(headers[j], offset);
|
|
32454
|
+
offset += headers[j].byteLength;
|
|
32455
|
+
buffer.set(new Uint8Array(parts[j].data), offset);
|
|
32456
|
+
offset += parts[j].data.byteLength;
|
|
32457
|
+
}
|
|
32458
|
+
// end buffer with trailer
|
|
32459
|
+
buffer.set(trailer, offset);
|
|
32460
|
+
|
|
32461
|
+
// return
|
|
32462
|
+
return buffer;
|
|
32463
|
+
};
|
|
32464
|
+
|
|
32465
|
+
// namespaces
|
|
32466
|
+
var dwv = dwv || {};
|
|
32467
|
+
dwv.utils = dwv.utils || {};
|
|
32468
|
+
|
|
31846
32469
|
// example implementation: dcmtk/dcmiod/libsrc/cielabutil.cc
|
|
31847
32470
|
// https://github.com/DCMTK/dcmtk/blob/DCMTK-3.6.6/dcmiod/libsrc/cielabutil.cc
|
|
31848
32471
|
|
|
@@ -31865,19 +32488,30 @@ dwv.utils.ybrToRgb = function (y, cb, cr) {
|
|
|
31865
32488
|
};
|
|
31866
32489
|
|
|
31867
32490
|
/**
|
|
31868
|
-
* Convert a
|
|
32491
|
+
* Convert a hex color into RGB.
|
|
31869
32492
|
*
|
|
31870
|
-
* @param {string}
|
|
31871
|
-
* @returns {object} RGB
|
|
32493
|
+
* @param {string} hexStr The hex color as '#ab01ef'.
|
|
32494
|
+
* @returns {object} The RGB values as {r,g,b}.
|
|
31872
32495
|
*/
|
|
31873
|
-
dwv.utils.hexToRgb = function (
|
|
32496
|
+
dwv.utils.hexToRgb = function (hexStr) {
|
|
31874
32497
|
return {
|
|
31875
|
-
r: parseInt(
|
|
31876
|
-
g: parseInt(
|
|
31877
|
-
b: parseInt(
|
|
32498
|
+
r: parseInt(hexStr.substring(1, 3), 16),
|
|
32499
|
+
g: parseInt(hexStr.substring(3, 5), 16),
|
|
32500
|
+
b: parseInt(hexStr.substring(5, 7), 16)
|
|
31878
32501
|
};
|
|
31879
32502
|
};
|
|
31880
32503
|
|
|
32504
|
+
/**
|
|
32505
|
+
* Convert RGB to its hex equivalent.
|
|
32506
|
+
*
|
|
32507
|
+
* @param {object} rgb The RGB object as {r,g,b}.
|
|
32508
|
+
* @returns {string} A string representing the hex color as '#ab01ef'.
|
|
32509
|
+
*/
|
|
32510
|
+
dwv.utils.rgbToHex = function (rgb) {
|
|
32511
|
+
return '#' +
|
|
32512
|
+
((1 << 24) + (rgb.r << 16) + (rgb.g << 8) + rgb.b).toString(16).slice(1);
|
|
32513
|
+
};
|
|
32514
|
+
|
|
31881
32515
|
/**
|
|
31882
32516
|
* Get the brightness of a RGB colour: calculates
|
|
31883
32517
|
* the luma (Y) of the YIQ colour space.
|
|
@@ -31952,7 +32586,7 @@ dwv.utils.labToUintLab = function (triplet) {
|
|
|
31952
32586
|
};
|
|
31953
32587
|
|
|
31954
32588
|
/**
|
|
31955
|
-
* CIE Standard Illuminant D65
|
|
32589
|
+
* CIE Standard Illuminant D65, standard 2° observer.
|
|
31956
32590
|
*
|
|
31957
32591
|
* @see https://en.wikipedia.org/wiki/Illuminant_D65
|
|
31958
32592
|
*/
|
|
@@ -32028,7 +32662,7 @@ dwv.utils.ciexyzToCielab = function (triplet) {
|
|
|
32028
32662
|
/**
|
|
32029
32663
|
* Convert CIE XYZ to sRGB.
|
|
32030
32664
|
*
|
|
32031
|
-
* @see https://en.wikipedia.org/wiki/SRGB#
|
|
32665
|
+
* @see https://en.wikipedia.org/wiki/SRGB#From_CIE_XYZ_to_sRGB
|
|
32032
32666
|
* @param {object} triplet CIE XYZ triplet as {x,y,z}.
|
|
32033
32667
|
* @returns {object} sRGB triplet as {r,g,b}.
|
|
32034
32668
|
*/
|
|
@@ -32041,7 +32675,8 @@ dwv.utils.ciexyzToSrgb = function (triplet) {
|
|
|
32041
32675
|
// 0.416666667 = 1 / 2.4
|
|
32042
32676
|
res = 1.055 * Math.pow(x, 0.416666667) - 0.055;
|
|
32043
32677
|
}
|
|
32044
|
-
|
|
32678
|
+
// clip [0,1]
|
|
32679
|
+
return Math.min(1, Math.max(0, res));
|
|
32045
32680
|
};
|
|
32046
32681
|
|
|
32047
32682
|
var x = triplet.x / 100;
|
|
@@ -32058,7 +32693,7 @@ dwv.utils.ciexyzToSrgb = function (triplet) {
|
|
|
32058
32693
|
/**
|
|
32059
32694
|
* Convert sRGB to CIE XYZ.
|
|
32060
32695
|
*
|
|
32061
|
-
* @see https://en.wikipedia.org/wiki/SRGB#
|
|
32696
|
+
* @see https://en.wikipedia.org/wiki/SRGB#From_sRGB_to_CIE_XYZ
|
|
32062
32697
|
* @param {object} triplet sRGB triplet as {r,g,b}.
|
|
32063
32698
|
* @returns {object} CIE XYZ triplet as {x,y,z}.
|
|
32064
32699
|
*/
|
|
@@ -32400,9 +33035,11 @@ dwv.env.check = function () {
|
|
|
32400
33035
|
|
|
32401
33036
|
// check string startsWith
|
|
32402
33037
|
if (!String.prototype.startsWith) {
|
|
32403
|
-
String.prototype
|
|
32404
|
-
|
|
32405
|
-
|
|
33038
|
+
Object.defineProperty(String.prototype, 'startsWith', {
|
|
33039
|
+
value: function (search, rawPos) {
|
|
33040
|
+
return dwv.utils.startsWith(this, search, rawPos);
|
|
33041
|
+
}
|
|
33042
|
+
});
|
|
32406
33043
|
}
|
|
32407
33044
|
};
|
|
32408
33045
|
|
|
@@ -32575,7 +33212,7 @@ dwv.i18nPage = function () {
|
|
|
32575
33212
|
* @returns {string} The path to the locale resource.
|
|
32576
33213
|
*/
|
|
32577
33214
|
dwv.i18nGetLocalePath = function (filename) {
|
|
32578
|
-
var lng = i18next.language.
|
|
33215
|
+
var lng = i18next.language.substring(0, 2);
|
|
32579
33216
|
return dwv.i18nLocalesPath +
|
|
32580
33217
|
'/locales/' + lng + '/' + filename;
|
|
32581
33218
|
};
|
|
@@ -32588,7 +33225,7 @@ dwv.i18nGetLocalePath = function (filename) {
|
|
|
32588
33225
|
* @returns {string} The path to the locale resource.
|
|
32589
33226
|
*/
|
|
32590
33227
|
dwv.i18nGetFallbackLocalePath = function (filename) {
|
|
32591
|
-
var lng = i18next.languages[i18next.languages.length - 1].
|
|
33228
|
+
var lng = i18next.languages[i18next.languages.length - 1].substring(0, 2);
|
|
32592
33229
|
return dwv.i18nLocalesPath +
|
|
32593
33230
|
'/locales/' + lng + '/' + filename;
|
|
32594
33231
|
};
|
|
@@ -33830,19 +34467,37 @@ dwv.utils.capitaliseFirstLetter = function (string) {
|
|
|
33830
34467
|
return res;
|
|
33831
34468
|
};
|
|
33832
34469
|
|
|
34470
|
+
/**
|
|
34471
|
+
* Check if a string starts with the input element.
|
|
34472
|
+
*
|
|
34473
|
+
* @param {string} str The input string.
|
|
34474
|
+
* @param {string} search The searched start.
|
|
34475
|
+
* @param {number} rawPos The position in this string at which to begin
|
|
34476
|
+
* searching for searchString. Defaults to 0.
|
|
34477
|
+
* @returns {boolean} True if the input string starts with the searched string.
|
|
34478
|
+
*/
|
|
34479
|
+
dwv.utils.startsWith = function (str, search, rawPos) {
|
|
34480
|
+
if (typeof str === 'undefined' || str === null ||
|
|
34481
|
+
typeof search === 'undefined' || search === null) {
|
|
34482
|
+
return false;
|
|
34483
|
+
}
|
|
34484
|
+
var pos = rawPos > 0 ? rawPos | 0 : 0;
|
|
34485
|
+
return str.substring(pos, pos + search.length) === search;
|
|
34486
|
+
};
|
|
34487
|
+
|
|
33833
34488
|
/**
|
|
33834
34489
|
* Check if a string ends with the input element.
|
|
33835
34490
|
*
|
|
33836
34491
|
* @param {string} str The input string.
|
|
33837
|
-
* @param {string}
|
|
33838
|
-
* @returns {boolean} True if the input string ends with the
|
|
34492
|
+
* @param {string} search The searched ending.
|
|
34493
|
+
* @returns {boolean} True if the input string ends with the searched string.
|
|
33839
34494
|
*/
|
|
33840
|
-
dwv.utils.endsWith = function (str,
|
|
34495
|
+
dwv.utils.endsWith = function (str, search) {
|
|
33841
34496
|
if (typeof str === 'undefined' || str === null ||
|
|
33842
|
-
|
|
34497
|
+
typeof search === 'undefined' || search === null) {
|
|
33843
34498
|
return false;
|
|
33844
34499
|
}
|
|
33845
|
-
return str.
|
|
34500
|
+
return str.substring(str.length - search.length) === search;
|
|
33846
34501
|
};
|
|
33847
34502
|
|
|
33848
34503
|
/**
|
|
@@ -34024,6 +34679,20 @@ dwv.utils.getFileExtension = function (filePath) {
|
|
|
34024
34679
|
return ext;
|
|
34025
34680
|
};
|
|
34026
34681
|
|
|
34682
|
+
/**
|
|
34683
|
+
* Convert a string to a Uint8Array.
|
|
34684
|
+
*
|
|
34685
|
+
* @param {string} str The string to convert.
|
|
34686
|
+
* @returns {Uint8Array} The Uint8Array.
|
|
34687
|
+
*/
|
|
34688
|
+
dwv.utils.stringToUint8Array = function (str) {
|
|
34689
|
+
var arr = new Uint8Array(str.length);
|
|
34690
|
+
for (var i = 0, leni = str.length; i < leni; i++) {
|
|
34691
|
+
arr[i] = str.charCodeAt(i);
|
|
34692
|
+
}
|
|
34693
|
+
return arr;
|
|
34694
|
+
};
|
|
34695
|
+
|
|
34027
34696
|
// namespaces
|
|
34028
34697
|
var dwv = dwv || {};
|
|
34029
34698
|
dwv.utils = dwv.utils || {};
|
|
@@ -34399,13 +35068,13 @@ dwv.utils.splitUri = function (uri) {
|
|
|
34399
35068
|
var sepIndex = null;
|
|
34400
35069
|
if (uri && (sepIndex = uri.indexOf('?')) !== -1) {
|
|
34401
35070
|
// base: before the '?'
|
|
34402
|
-
result.base = uri.
|
|
35071
|
+
result.base = uri.substring(0, sepIndex);
|
|
34403
35072
|
// query : after the '?' and until possible '#'
|
|
34404
35073
|
var hashIndex = uri.indexOf('#');
|
|
34405
35074
|
if (hashIndex === -1) {
|
|
34406
35075
|
hashIndex = uri.length;
|
|
34407
35076
|
}
|
|
34408
|
-
var query = uri.
|
|
35077
|
+
var query = uri.substring(sepIndex + 1, hashIndex);
|
|
34409
35078
|
// split key/value pairs of the query
|
|
34410
35079
|
result.query = dwv.utils.splitKeyValueString(query);
|
|
34411
35080
|
}
|
|
@@ -34438,16 +35107,19 @@ dwv.utils.getUriQuery = function (uri) {
|
|
|
34438
35107
|
* or encoded URI with base and key value/pairs:
|
|
34439
35108
|
* [dwv root]?input=encodeURIComponent([root]?key0=value0&key1=value1)
|
|
34440
35109
|
*
|
|
34441
|
-
*
|
|
34442
|
-
*
|
|
35110
|
+
* @param {string} query The query part to the input URI.
|
|
35111
|
+
* @param {Function} callback The function to call with the decoded file urls.
|
|
35112
|
+
* @param {object} options Optional url request options.
|
|
34443
35113
|
*/
|
|
34444
|
-
dwv.utils.decodeQuery = function (query, callback) {
|
|
35114
|
+
dwv.utils.decodeQuery = function (query, callback, options) {
|
|
34445
35115
|
// manifest
|
|
34446
35116
|
if (query.type && query.type === 'manifest') {
|
|
34447
35117
|
dwv.utils.decodeManifestQuery(query, callback);
|
|
34448
35118
|
} else {
|
|
34449
35119
|
// default case: encoded URI with base and key/value pairs
|
|
34450
|
-
callback(
|
|
35120
|
+
callback(
|
|
35121
|
+
dwv.utils.decodeKeyValueUri(query.input, query.dwvReplaceMode),
|
|
35122
|
+
options);
|
|
34451
35123
|
}
|
|
34452
35124
|
};
|
|
34453
35125
|
|
|
@@ -34620,12 +35292,13 @@ dwv.utils.decodeManifest = function (manifest, nslices) {
|
|
|
34620
35292
|
*
|
|
34621
35293
|
* @param {string} uri The input uri, for example: 'window.location.href'.
|
|
34622
35294
|
* @param {dwv.App} app The associated app that handles the load.
|
|
35295
|
+
* @param {object} options Optional url request options.
|
|
34623
35296
|
*/
|
|
34624
|
-
dwv.utils.loadFromUri = function (uri, app) {
|
|
35297
|
+
dwv.utils.loadFromUri = function (uri, app, options) {
|
|
34625
35298
|
var query = dwv.utils.getUriQuery(uri);
|
|
34626
35299
|
// check query
|
|
34627
35300
|
if (query && typeof query.input !== 'undefined') {
|
|
34628
|
-
dwv.utils.loadFromQuery(query, app);
|
|
35301
|
+
dwv.utils.loadFromQuery(query, app, options);
|
|
34629
35302
|
}
|
|
34630
35303
|
// no else to allow for empty uris
|
|
34631
35304
|
};
|
|
@@ -34635,10 +35308,11 @@ dwv.utils.loadFromUri = function (uri, app) {
|
|
|
34635
35308
|
*
|
|
34636
35309
|
* @param {object} query A query derived from an uri.
|
|
34637
35310
|
* @param {object} app The associated app that handles the load.
|
|
35311
|
+
* @param {object} options Optional url request options.
|
|
34638
35312
|
*/
|
|
34639
|
-
dwv.utils.loadFromQuery = function (query, app) {
|
|
35313
|
+
dwv.utils.loadFromQuery = function (query, app, options) {
|
|
34640
35314
|
// load base
|
|
34641
|
-
dwv.utils.decodeQuery(query, app.loadURLs);
|
|
35315
|
+
dwv.utils.decodeQuery(query, app.loadURLs, options);
|
|
34642
35316
|
// optional display state
|
|
34643
35317
|
if (typeof query.state !== 'undefined') {
|
|
34644
35318
|
var onLoadEnd = function (/*event*/) {
|