dwv 0.31.0-beta.0 → 0.31.0-beta.1
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 +655 -124
- 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.1 2022-03-17 17:17:41 */
|
|
2
2
|
// Inspired from umdjs
|
|
3
3
|
// See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
|
|
4
4
|
(function (root, factory) {
|
|
@@ -627,9 +627,9 @@ dwv.App = function () {
|
|
|
627
627
|
// initialise or add view
|
|
628
628
|
if (layerGroup.getViewLayersByDataIndex(dataIndex).length === 0) {
|
|
629
629
|
if (layerGroup.getNumberOfLayers() === 0) {
|
|
630
|
-
initialiseBaseLayers(dataIndex, config
|
|
630
|
+
initialiseBaseLayers(dataIndex, config);
|
|
631
631
|
} else {
|
|
632
|
-
addViewLayer(dataIndex, config
|
|
632
|
+
addViewLayer(dataIndex, config);
|
|
633
633
|
}
|
|
634
634
|
}
|
|
635
635
|
// draw
|
|
@@ -1210,25 +1210,12 @@ dwv.App = function () {
|
|
|
1210
1210
|
* To be called once the DICOM data has been loaded.
|
|
1211
1211
|
*
|
|
1212
1212
|
* @param {number} dataIndex The data index.
|
|
1213
|
-
* @param {
|
|
1213
|
+
* @param {object} dataViewConfig The data view config.
|
|
1214
1214
|
* @private
|
|
1215
1215
|
*/
|
|
1216
|
-
function initialiseBaseLayers(dataIndex,
|
|
1217
|
-
var data = dataController.get(dataIndex);
|
|
1218
|
-
if (!data) {
|
|
1219
|
-
throw new Error('Cannot initialise layers with data id: ' + dataIndex);
|
|
1220
|
-
}
|
|
1221
|
-
var layerGroup = stage.getLayerGroupWithElementId(layerGroupElementId);
|
|
1222
|
-
if (!layerGroup) {
|
|
1223
|
-
throw new Error('Cannot initialise layers with group id: ' +
|
|
1224
|
-
layerGroupElementId);
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1216
|
+
function initialiseBaseLayers(dataIndex, dataViewConfig) {
|
|
1227
1217
|
// add layers
|
|
1228
|
-
addViewLayer(dataIndex,
|
|
1229
|
-
|
|
1230
|
-
// update style
|
|
1231
|
-
//style.setBaseScale(layerGroup.getBaseScale());
|
|
1218
|
+
addViewLayer(dataIndex, dataViewConfig);
|
|
1232
1219
|
|
|
1233
1220
|
// initialise the toolbox
|
|
1234
1221
|
if (toolboxController) {
|
|
@@ -1270,17 +1257,17 @@ dwv.App = function () {
|
|
|
1270
1257
|
* Add a view layer.
|
|
1271
1258
|
*
|
|
1272
1259
|
* @param {number} dataIndex The data index.
|
|
1273
|
-
* @param {
|
|
1260
|
+
* @param {object} dataViewConfig The data view config.
|
|
1274
1261
|
*/
|
|
1275
|
-
function addViewLayer(dataIndex,
|
|
1262
|
+
function addViewLayer(dataIndex, dataViewConfig) {
|
|
1276
1263
|
var data = dataController.get(dataIndex);
|
|
1277
1264
|
if (!data) {
|
|
1278
|
-
throw new Error('Cannot initialise
|
|
1265
|
+
throw new Error('Cannot initialise layer with data id: ' + dataIndex);
|
|
1279
1266
|
}
|
|
1280
|
-
var layerGroup = stage.getLayerGroupWithElementId(
|
|
1267
|
+
var layerGroup = stage.getLayerGroupWithElementId(dataViewConfig.divId);
|
|
1281
1268
|
if (!layerGroup) {
|
|
1282
|
-
throw new Error('Cannot initialise
|
|
1283
|
-
|
|
1269
|
+
throw new Error('Cannot initialise layer with group id: ' +
|
|
1270
|
+
dataViewConfig.divId);
|
|
1284
1271
|
}
|
|
1285
1272
|
var imageGeometry = data.image.getGeometry();
|
|
1286
1273
|
|
|
@@ -1298,11 +1285,34 @@ dwv.App = function () {
|
|
|
1298
1285
|
);
|
|
1299
1286
|
view.setOrientation(viewOrientation);
|
|
1300
1287
|
|
|
1301
|
-
//
|
|
1288
|
+
// make pixel of value 0 transparent for segmentation
|
|
1289
|
+
// (assuming RGB data)
|
|
1290
|
+
if (data.image.getMeta().Modality === 'SEG') {
|
|
1291
|
+
view.setAlphaFunction(function (value) {
|
|
1292
|
+
if (value[0] === 0 &&
|
|
1293
|
+
value[1] === 0 &&
|
|
1294
|
+
value[2] === 0) {
|
|
1295
|
+
return 1;
|
|
1296
|
+
} else {
|
|
1297
|
+
return 0xff;
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// colour map
|
|
1303
|
+
if (typeof dataViewConfig.colourMap !== 'undefined') {
|
|
1304
|
+
view.setColourMap(dataViewConfig.colourMap);
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
// opacity
|
|
1302
1308
|
var opacity = 1;
|
|
1303
|
-
|
|
1304
|
-
|
|
1309
|
+
// do we have more than one layer
|
|
1310
|
+
if (layerGroup.getNumberOfLayers() !== 0) {
|
|
1305
1311
|
opacity = 0.5;
|
|
1312
|
+
// set color map if non was provided
|
|
1313
|
+
if (typeof dataViewConfig.colourMap === 'undefined') {
|
|
1314
|
+
view.setColourMap(dwv.image.lut.rainbow);
|
|
1315
|
+
}
|
|
1306
1316
|
}
|
|
1307
1317
|
|
|
1308
1318
|
// view layer
|
|
@@ -1316,11 +1326,14 @@ dwv.App = function () {
|
|
|
1316
1326
|
// compensate origin difference
|
|
1317
1327
|
var diff = null;
|
|
1318
1328
|
if (dataIndex !== 0) {
|
|
1329
|
+
// offset from the top, use first origin
|
|
1319
1330
|
var data0 = dataController.get(0);
|
|
1320
|
-
var origin0 = data0.image.getGeometry().
|
|
1321
|
-
var origin1 = imageGeometry.
|
|
1331
|
+
var origin0 = data0.image.getGeometry().getOrigins()[0];
|
|
1332
|
+
var origin1 = imageGeometry.getOrigins()[0];
|
|
1322
1333
|
diff = origin0.minus(origin1);
|
|
1323
|
-
|
|
1334
|
+
// TODO: check why -z...
|
|
1335
|
+
viewLayer.setBaseOffset(new dwv.math.Vector3D(
|
|
1336
|
+
diff.getX(), diff.getY(), -1 * diff.getZ()));
|
|
1324
1337
|
}
|
|
1325
1338
|
|
|
1326
1339
|
// listen to image changes
|
|
@@ -2744,9 +2757,11 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2744
2757
|
* Generate display image data to be given to a canvas.
|
|
2745
2758
|
*
|
|
2746
2759
|
* @param {Array} array The array to fill in.
|
|
2760
|
+
* @param {dwv.math.Point} position Optional position at which to generate,
|
|
2761
|
+
* otherwise generates at current position.
|
|
2747
2762
|
*/
|
|
2748
|
-
this.generateImageData = function (array) {
|
|
2749
|
-
view.generateImageData(array);
|
|
2763
|
+
this.generateImageData = function (array, position) {
|
|
2764
|
+
view.generateImageData(array, position);
|
|
2750
2765
|
};
|
|
2751
2766
|
|
|
2752
2767
|
/**
|
|
@@ -4353,6 +4368,26 @@ dwv.dicom.DicomElementsWrapper.prototype.getFromName = function (name) {
|
|
|
4353
4368
|
return value;
|
|
4354
4369
|
};
|
|
4355
4370
|
|
|
4371
|
+
/**
|
|
4372
|
+
* Extract a size from dicom elements.
|
|
4373
|
+
*
|
|
4374
|
+
* @returns {object} The size.
|
|
4375
|
+
*/
|
|
4376
|
+
dwv.dicom.DicomElementsWrapper.prototype.getImageSize = function () {
|
|
4377
|
+
// rows
|
|
4378
|
+
var rows = this.getFromKey('x00280010');
|
|
4379
|
+
if (!rows) {
|
|
4380
|
+
throw new Error('Missing or empty DICOM image number of rows');
|
|
4381
|
+
}
|
|
4382
|
+
// columns
|
|
4383
|
+
var columns = this.getFromKey('x00280011');
|
|
4384
|
+
if (!columns) {
|
|
4385
|
+
throw new Error('Missing or empty DICOM image number of columns');
|
|
4386
|
+
}
|
|
4387
|
+
return new dwv.image.Size([columns, rows, 1]);
|
|
4388
|
+
};
|
|
4389
|
+
|
|
4390
|
+
|
|
4356
4391
|
/**
|
|
4357
4392
|
* Get the pixel spacing from the different spacing tags.
|
|
4358
4393
|
*
|
|
@@ -4468,7 +4503,7 @@ dwv.dicom = dwv.dicom || {};
|
|
|
4468
4503
|
* @returns {string} The version of the library.
|
|
4469
4504
|
*/
|
|
4470
4505
|
dwv.getVersion = function () {
|
|
4471
|
-
return '0.31.0-beta.
|
|
4506
|
+
return '0.31.0-beta.1';
|
|
4472
4507
|
};
|
|
4473
4508
|
|
|
4474
4509
|
/**
|
|
@@ -13050,6 +13085,14 @@ dwv.gui.ViewLayer = function (containerDiv) {
|
|
|
13050
13085
|
*/
|
|
13051
13086
|
var context = null;
|
|
13052
13087
|
|
|
13088
|
+
/**
|
|
13089
|
+
* Flag to know if the context has been cleared.
|
|
13090
|
+
*
|
|
13091
|
+
* @private
|
|
13092
|
+
* @type {boolean}
|
|
13093
|
+
*/
|
|
13094
|
+
var isContextClear = true;
|
|
13095
|
+
|
|
13053
13096
|
/**
|
|
13054
13097
|
* The image data array.
|
|
13055
13098
|
*
|
|
@@ -13398,14 +13441,8 @@ dwv.gui.ViewLayer = function (containerDiv) {
|
|
|
13398
13441
|
// context opacity
|
|
13399
13442
|
context.globalAlpha = opacity;
|
|
13400
13443
|
|
|
13401
|
-
// clear
|
|
13402
|
-
|
|
13403
|
-
context.save();
|
|
13404
|
-
// use the identity matrix while clearing the canvas
|
|
13405
|
-
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
13406
|
-
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
13407
|
-
// restore the transform
|
|
13408
|
-
context.restore();
|
|
13444
|
+
// clear context
|
|
13445
|
+
this.clear();
|
|
13409
13446
|
|
|
13410
13447
|
// draw the cached canvas on the context
|
|
13411
13448
|
// transform takes as input a, b, c, d, e, f to create
|
|
@@ -13427,6 +13464,9 @@ dwv.gui.ViewLayer = function (containerDiv) {
|
|
|
13427
13464
|
// draw image
|
|
13428
13465
|
context.drawImage(offscreenCanvas, 0, 0);
|
|
13429
13466
|
|
|
13467
|
+
// set clear flag
|
|
13468
|
+
isContextClear = false;
|
|
13469
|
+
|
|
13430
13470
|
/**
|
|
13431
13471
|
* Render end event.
|
|
13432
13472
|
*
|
|
@@ -13621,6 +13661,11 @@ dwv.gui.ViewLayer = function (containerDiv) {
|
|
|
13621
13661
|
function onPositionChange(event) {
|
|
13622
13662
|
if (typeof event.skipGenerate === 'undefined' ||
|
|
13623
13663
|
event.skipGenerate === false) {
|
|
13664
|
+
// clear for non valid events
|
|
13665
|
+
if (typeof event.valid !== 'undefined' && !event.valid) {
|
|
13666
|
+
self.clear();
|
|
13667
|
+
return;
|
|
13668
|
+
}
|
|
13624
13669
|
// 3D dimensions
|
|
13625
13670
|
var dims3D = [0, 1, 2];
|
|
13626
13671
|
// remove scroll index
|
|
@@ -13663,12 +13708,22 @@ dwv.gui.ViewLayer = function (containerDiv) {
|
|
|
13663
13708
|
};
|
|
13664
13709
|
|
|
13665
13710
|
/**
|
|
13666
|
-
* Clear the context
|
|
13711
|
+
* Clear the context.
|
|
13667
13712
|
*/
|
|
13668
13713
|
this.clear = function () {
|
|
13669
|
-
|
|
13670
|
-
|
|
13671
|
-
|
|
13714
|
+
if (!isContextClear) {
|
|
13715
|
+
// clear the context: reset the transform first
|
|
13716
|
+
// store the current transformation matrix
|
|
13717
|
+
context.save();
|
|
13718
|
+
// use the identity matrix while clearing the canvas
|
|
13719
|
+
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
13720
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
13721
|
+
// restore the transform
|
|
13722
|
+
context.restore();
|
|
13723
|
+
|
|
13724
|
+
// update clear flag
|
|
13725
|
+
isContextClear = true;
|
|
13726
|
+
}
|
|
13672
13727
|
};
|
|
13673
13728
|
|
|
13674
13729
|
/**
|
|
@@ -14130,11 +14185,20 @@ dwv.image.DicomBufferToView = function () {
|
|
|
14130
14185
|
* @param {string} origin The data origin.
|
|
14131
14186
|
*/
|
|
14132
14187
|
function generateImage(index, origin) {
|
|
14188
|
+
var dicomElements = dicomParserStore[index].getDicomElements();
|
|
14189
|
+
|
|
14190
|
+
var modality = dwv.dicom.cleanString(dicomElements.getFromKey('x00080060'));
|
|
14191
|
+
var factory;
|
|
14192
|
+
if (modality && modality === 'SEG') {
|
|
14193
|
+
factory = new dwv.image.MaskFactory();
|
|
14194
|
+
} else {
|
|
14195
|
+
factory = new dwv.image.ImageFactory();
|
|
14196
|
+
}
|
|
14197
|
+
|
|
14133
14198
|
// create the image
|
|
14134
14199
|
try {
|
|
14135
|
-
var
|
|
14136
|
-
|
|
14137
|
-
dicomParserStore[index].getDicomElements(),
|
|
14200
|
+
var image = factory.create(
|
|
14201
|
+
dicomElements,
|
|
14138
14202
|
finalBufferStore[index],
|
|
14139
14203
|
options.numberOfFiles);
|
|
14140
14204
|
// call onloaditem
|
|
@@ -16858,10 +16922,10 @@ dwv.image.rangeRegions = function (
|
|
|
16858
16922
|
* @param {boolean} isPlanar A flag to know if the data is planar
|
|
16859
16923
|
* (RRRR...GGGG...BBBB...) or not (RGBRGBRGBRGB...), defaults to false.
|
|
16860
16924
|
* @returns {object} A 3 components iterator folowing the iterator and iterable
|
|
16861
|
-
* protocol,
|
|
16862
|
-
* third component.
|
|
16925
|
+
* protocol, the value is an array of size 3 with each component.
|
|
16863
16926
|
*/
|
|
16864
|
-
dwv.image.
|
|
16927
|
+
dwv.image.simpleRange3d = function (
|
|
16928
|
+
dataAccessor, start, end, increment, isPlanar) {
|
|
16865
16929
|
if (typeof increment === 'undefined') {
|
|
16866
16930
|
increment = 1;
|
|
16867
16931
|
}
|
|
@@ -16903,6 +16967,84 @@ dwv.image.range3d = function (dataAccessor, start, end, increment, isPlanar) {
|
|
|
16903
16967
|
};
|
|
16904
16968
|
};
|
|
16905
16969
|
|
|
16970
|
+
/**
|
|
16971
|
+
* Get an iterator for a given range for a 3 components data.
|
|
16972
|
+
*
|
|
16973
|
+
* Using 'maxIter' and not an 'end' index since it fails in some edge cases
|
|
16974
|
+
* (for ex coronal2, ie zxy)
|
|
16975
|
+
*
|
|
16976
|
+
* @param {Function} dataAccessor Function to access data.
|
|
16977
|
+
* @param {number} start Zero-based index at which to start the iteration.
|
|
16978
|
+
* @param {number} maxIter The maximum number of iterations.
|
|
16979
|
+
* @param {number} increment Increment between indicies.
|
|
16980
|
+
* @param {number} blockMaxIter Number of applied increment after which
|
|
16981
|
+
* blockIncrement is applied.
|
|
16982
|
+
* @param {number} blockIncrement Increment after blockMaxIter is reached,
|
|
16983
|
+
* the value is from block start to the next block start.
|
|
16984
|
+
* @param {boolean} reverse1 If true, loop from end to start.
|
|
16985
|
+
* WARN: don't forget to set the value of start as the last index!
|
|
16986
|
+
* @param {boolean} reverse2 If true, loop from block end to block start.
|
|
16987
|
+
* @param {boolean} isPlanar A flag to know if the data is planar
|
|
16988
|
+
* (RRRR...GGGG...BBBB...) or not (RGBRGBRGBRGB...), defaults to false.
|
|
16989
|
+
* @returns {object} An iterator folowing the iterator and iterable protocol.
|
|
16990
|
+
*/
|
|
16991
|
+
dwv.image.range3d = function (dataAccessor, start, maxIter, increment,
|
|
16992
|
+
blockMaxIter, blockIncrement, reverse1, reverse2, isPlanar) {
|
|
16993
|
+
var iters = [];
|
|
16994
|
+
if (isPlanar) {
|
|
16995
|
+
iters.push(dwv.image.range(
|
|
16996
|
+
dataAccessor, start, maxIter, increment,
|
|
16997
|
+
blockMaxIter, blockIncrement, reverse1, reverse2
|
|
16998
|
+
));
|
|
16999
|
+
iters.push(dwv.image.range(
|
|
17000
|
+
dataAccessor, start + maxIter * increment, maxIter, increment,
|
|
17001
|
+
blockMaxIter, blockIncrement, reverse1, reverse2
|
|
17002
|
+
));
|
|
17003
|
+
iters.push(dwv.image.range(
|
|
17004
|
+
dataAccessor, start + 2 * maxIter * increment, maxIter, increment,
|
|
17005
|
+
blockMaxIter, blockIncrement, reverse1, reverse2
|
|
17006
|
+
));
|
|
17007
|
+
} else {
|
|
17008
|
+
increment *= 3;
|
|
17009
|
+
blockIncrement *= 3;
|
|
17010
|
+
iters.push(dwv.image.range(
|
|
17011
|
+
dataAccessor, start, maxIter, increment,
|
|
17012
|
+
blockMaxIter, blockIncrement, reverse1, reverse2
|
|
17013
|
+
));
|
|
17014
|
+
iters.push(dwv.image.range(
|
|
17015
|
+
dataAccessor, start + 1, maxIter, increment,
|
|
17016
|
+
blockMaxIter, blockIncrement, reverse1, reverse2
|
|
17017
|
+
));
|
|
17018
|
+
iters.push(dwv.image.range(
|
|
17019
|
+
dataAccessor, start + 2, maxIter, increment,
|
|
17020
|
+
blockMaxIter, blockIncrement, reverse1, reverse2
|
|
17021
|
+
));
|
|
17022
|
+
}
|
|
17023
|
+
|
|
17024
|
+
// result
|
|
17025
|
+
return {
|
|
17026
|
+
next: function () {
|
|
17027
|
+
var r0 = iters[0].next();
|
|
17028
|
+
var r1 = iters[1].next();
|
|
17029
|
+
var r2 = iters[2].next();
|
|
17030
|
+
if (!r0.done) {
|
|
17031
|
+
return {
|
|
17032
|
+
value: [
|
|
17033
|
+
r0.value,
|
|
17034
|
+
r1.value,
|
|
17035
|
+
r2.value
|
|
17036
|
+
],
|
|
17037
|
+
done: false
|
|
17038
|
+
};
|
|
17039
|
+
}
|
|
17040
|
+
return {
|
|
17041
|
+
done: true,
|
|
17042
|
+
index: r2.index
|
|
17043
|
+
};
|
|
17044
|
+
}
|
|
17045
|
+
};
|
|
17046
|
+
};
|
|
17047
|
+
|
|
16906
17048
|
/**
|
|
16907
17049
|
* Get a list of values for a given iterator.
|
|
16908
17050
|
*
|
|
@@ -16964,70 +17106,82 @@ dwv.image.getSliceIterator = function (
|
|
|
16964
17106
|
var nslices = size.get(2);
|
|
16965
17107
|
var sliceSize = size.getDimSize(2);
|
|
16966
17108
|
|
|
17109
|
+
var ncomp = image.getNumberOfComponents();
|
|
17110
|
+
var isPlanar = image.getPlanarConfiguration() === 1;
|
|
17111
|
+
var getRange = function (
|
|
17112
|
+
dataAccessor, start, maxIter, increment,
|
|
17113
|
+
blockMaxIter, blockIncrement, reverse1, reverse2) {
|
|
17114
|
+
if (ncomp === 1) {
|
|
17115
|
+
return dwv.image.range(dataAccessor, start, maxIter, increment,
|
|
17116
|
+
blockMaxIter, blockIncrement, reverse1, reverse2);
|
|
17117
|
+
} else if (ncomp === 3) {
|
|
17118
|
+
return dwv.image.range3d(dataAccessor, 3 * start, maxIter, increment,
|
|
17119
|
+
blockMaxIter, blockIncrement, reverse1, reverse2, isPlanar);
|
|
17120
|
+
}
|
|
17121
|
+
};
|
|
17122
|
+
|
|
16967
17123
|
var range = null;
|
|
16968
|
-
if (
|
|
16969
|
-
|
|
16970
|
-
|
|
16971
|
-
|
|
16972
|
-
|
|
16973
|
-
|
|
16974
|
-
|
|
16975
|
-
|
|
16976
|
-
|
|
16977
|
-
|
|
16978
|
-
|
|
16979
|
-
|
|
16980
|
-
|
|
16981
|
-
|
|
16982
|
-
|
|
16983
|
-
|
|
16984
|
-
|
|
16985
|
-
|
|
16986
|
-
|
|
16987
|
-
|
|
16988
|
-
|
|
16989
|
-
|
|
16990
|
-
|
|
16991
|
-
|
|
16992
|
-
|
|
16993
|
-
|
|
16994
|
-
|
|
16995
|
-
|
|
16996
|
-
start, maxIter, ncols, nrows, sliceSize, reverse1, reverse2);
|
|
16997
|
-
} else {
|
|
16998
|
-
// zyx
|
|
16999
|
-
range = dwv.image.range(dataAccessor,
|
|
17000
|
-
start, maxIter, sliceSize, nslices, ncols, reverse1, reverse2);
|
|
17001
|
-
}
|
|
17002
|
-
} else if (dirMax2.index === 1) {
|
|
17003
|
-
// coronal
|
|
17004
|
-
maxIter = nslices * ncols;
|
|
17005
|
-
if (dirMax0.index === 0) {
|
|
17006
|
-
// xzy
|
|
17007
|
-
range = dwv.image.range(dataAccessor,
|
|
17008
|
-
start, maxIter, 1, ncols, sliceSize, reverse1, reverse2);
|
|
17009
|
-
} else {
|
|
17010
|
-
// zxy
|
|
17011
|
-
range = dwv.image.range(dataAccessor,
|
|
17012
|
-
start, maxIter, sliceSize, nslices, 1, reverse1, reverse2);
|
|
17013
|
-
}
|
|
17124
|
+
if (viewOrientation && typeof viewOrientation !== 'undefined') {
|
|
17125
|
+
var dirMax0 = viewOrientation.getColAbsMax(0);
|
|
17126
|
+
var dirMax2 = viewOrientation.getColAbsMax(2);
|
|
17127
|
+
|
|
17128
|
+
// default reverse
|
|
17129
|
+
var reverse1 = false;
|
|
17130
|
+
var reverse2 = false;
|
|
17131
|
+
|
|
17132
|
+
var maxIter = null;
|
|
17133
|
+
if (dirMax2.index === 2) {
|
|
17134
|
+
// axial
|
|
17135
|
+
maxIter = ncols * nrows;
|
|
17136
|
+
if (dirMax0.index === 0) {
|
|
17137
|
+
// xyz
|
|
17138
|
+
range = getRange(dataAccessor,
|
|
17139
|
+
start, maxIter, 1, ncols, ncols, reverse1, reverse2);
|
|
17140
|
+
} else {
|
|
17141
|
+
// yxz
|
|
17142
|
+
range = getRange(dataAccessor,
|
|
17143
|
+
start, maxIter, ncols, nrows, 1, reverse1, reverse2);
|
|
17144
|
+
}
|
|
17145
|
+
} else if (dirMax2.index === 0) {
|
|
17146
|
+
// sagittal
|
|
17147
|
+
maxIter = nslices * nrows;
|
|
17148
|
+
if (dirMax0.index === 1) {
|
|
17149
|
+
// yzx
|
|
17150
|
+
range = getRange(dataAccessor,
|
|
17151
|
+
start, maxIter, ncols, nrows, sliceSize, reverse1, reverse2);
|
|
17014
17152
|
} else {
|
|
17015
|
-
|
|
17153
|
+
// zyx
|
|
17154
|
+
range = getRange(dataAccessor,
|
|
17155
|
+
start, maxIter, sliceSize, nslices, ncols, reverse1, reverse2);
|
|
17156
|
+
}
|
|
17157
|
+
} else if (dirMax2.index === 1) {
|
|
17158
|
+
// coronal
|
|
17159
|
+
maxIter = nslices * ncols;
|
|
17160
|
+
if (dirMax0.index === 0) {
|
|
17161
|
+
// xzy
|
|
17162
|
+
range = getRange(dataAccessor,
|
|
17163
|
+
start, maxIter, 1, ncols, sliceSize, reverse1, reverse2);
|
|
17164
|
+
} else {
|
|
17165
|
+
// zxy
|
|
17166
|
+
range = getRange(dataAccessor,
|
|
17167
|
+
start, maxIter, sliceSize, nslices, 1, reverse1, reverse2);
|
|
17016
17168
|
}
|
|
17017
17169
|
} else {
|
|
17018
|
-
|
|
17019
|
-
range = dwv.image.simpleRange(dataAccessor, start, start + sliceSize);
|
|
17170
|
+
throw new Error('Unknown direction: ' + dirMax2.index);
|
|
17020
17171
|
}
|
|
17021
|
-
} else if (image.getNumberOfComponents() === 3) {
|
|
17022
|
-
// 3 times bigger...
|
|
17023
|
-
start *= 3;
|
|
17024
|
-
sliceSize *= 3;
|
|
17025
|
-
var isPlanar = image.getPlanarConfiguration() === 1;
|
|
17026
|
-
range = dwv.image.range3d(
|
|
17027
|
-
dataAccessor, start, start + sliceSize, 1, isPlanar);
|
|
17028
17172
|
} else {
|
|
17029
|
-
|
|
17030
|
-
image.
|
|
17173
|
+
if (image.getNumberOfComponents() === 1) {
|
|
17174
|
+
range = dwv.image.simpleRange(dataAccessor, start, start + sliceSize);
|
|
17175
|
+
} else if (image.getNumberOfComponents() === 3) {
|
|
17176
|
+
// 3 times bigger...
|
|
17177
|
+
start *= 3;
|
|
17178
|
+
sliceSize *= 3;
|
|
17179
|
+
range = dwv.image.simpleRange3d(
|
|
17180
|
+
dataAccessor, start, start + sliceSize, 1, isPlanar);
|
|
17181
|
+
} else {
|
|
17182
|
+
throw new Error('Unsupported number of components: ' +
|
|
17183
|
+
image.getNumberOfComponents());
|
|
17184
|
+
}
|
|
17031
17185
|
}
|
|
17032
17186
|
|
|
17033
17187
|
return range;
|
|
@@ -17409,6 +17563,358 @@ dwv.image.lut.test = {
|
|
|
17409
17563
|
var dwv = dwv || {};
|
|
17410
17564
|
dwv.image = dwv.image || {};
|
|
17411
17565
|
|
|
17566
|
+
/**
|
|
17567
|
+
* Mask {@link dwv.image.Image} factory.
|
|
17568
|
+
*
|
|
17569
|
+
* @class
|
|
17570
|
+
*/
|
|
17571
|
+
dwv.image.MaskFactory = function () {};
|
|
17572
|
+
|
|
17573
|
+
/**
|
|
17574
|
+
* Get an {@link dwv.image.Image} object from the read DICOM file.
|
|
17575
|
+
*
|
|
17576
|
+
* @param {object} dicomElements The DICOM tags.
|
|
17577
|
+
* @param {Array} pixelBuffer The pixel buffer.
|
|
17578
|
+
* @returns {dwv.image.Image} A new Image.
|
|
17579
|
+
*/
|
|
17580
|
+
dwv.image.MaskFactory.prototype.create = function (
|
|
17581
|
+
dicomElements, pixelBuffer) {
|
|
17582
|
+
// columns
|
|
17583
|
+
var columns = dicomElements.getFromKey('x00280011');
|
|
17584
|
+
if (!columns) {
|
|
17585
|
+
throw new Error('Missing or empty DICOM image number of columns');
|
|
17586
|
+
}
|
|
17587
|
+
// rows
|
|
17588
|
+
var rows = dicomElements.getFromKey('x00280010');
|
|
17589
|
+
if (!rows) {
|
|
17590
|
+
throw new Error('Missing or empty DICOM image number of rows');
|
|
17591
|
+
}
|
|
17592
|
+
var sliceSize = columns * rows;
|
|
17593
|
+
|
|
17594
|
+
// frames
|
|
17595
|
+
var frames = dicomElements.getFromKey('x00280008');
|
|
17596
|
+
if (!frames) {
|
|
17597
|
+
frames = 1;
|
|
17598
|
+
} else {
|
|
17599
|
+
frames = parseInt(frames, 10);
|
|
17600
|
+
}
|
|
17601
|
+
|
|
17602
|
+
if (frames !== pixelBuffer.length / sliceSize) {
|
|
17603
|
+
throw new Error(
|
|
17604
|
+
'Buffer and numberOfFrames meta are not equal.');
|
|
17605
|
+
}
|
|
17606
|
+
|
|
17607
|
+
// Segmentation Type
|
|
17608
|
+
var segType = dicomElements.getFromKey('x00620001');
|
|
17609
|
+
if (!segType) {
|
|
17610
|
+
throw new Error('Missing or empty DICOM segmentation type');
|
|
17611
|
+
} else {
|
|
17612
|
+
segType = dwv.dicom.cleanString(segType);
|
|
17613
|
+
}
|
|
17614
|
+
if (segType !== 'BINARY') {
|
|
17615
|
+
throw new Error('Unsupported segmentation type: ' + segType);
|
|
17616
|
+
}
|
|
17617
|
+
|
|
17618
|
+
// check if compressed
|
|
17619
|
+
var syntax = dwv.dicom.cleanString(dicomElements.getFromKey('x00020010'));
|
|
17620
|
+
var algoName = dwv.dicom.getSyntaxDecompressionName(syntax);
|
|
17621
|
+
if (algoName !== null) {
|
|
17622
|
+
throw new Error('Unsupported compressed segmentation: ' + algoName);
|
|
17623
|
+
}
|
|
17624
|
+
|
|
17625
|
+
// Segment Sequence
|
|
17626
|
+
var segSequence = dicomElements.getFromKey('x00620002', true);
|
|
17627
|
+
if (!segSequence || typeof segSequence === 'undefined') {
|
|
17628
|
+
throw new Error('Missing or empty segmentation sequence');
|
|
17629
|
+
}
|
|
17630
|
+
var labels = [];
|
|
17631
|
+
var storeAsRGB = false;
|
|
17632
|
+
for (var i = 0; i < segSequence.length; ++i) {
|
|
17633
|
+
// value -> Segment Number
|
|
17634
|
+
// name -> Segment Label
|
|
17635
|
+
var label = {
|
|
17636
|
+
value: segSequence[i].x00620004.value[0],
|
|
17637
|
+
name: dwv.dicom.cleanString(segSequence[i].x00620005.value[0]),
|
|
17638
|
+
algorithmType: dwv.dicom.cleanString(segSequence[i].x00620008.value[0])
|
|
17639
|
+
};
|
|
17640
|
+
// Segment Algorithm Name
|
|
17641
|
+
if (segSequence[i].x00620009) {
|
|
17642
|
+
label.algorithmName =
|
|
17643
|
+
dwv.dicom.cleanString(segSequence[i].x00620009.value[0]);
|
|
17644
|
+
}
|
|
17645
|
+
// Recommended Display CIELab Value
|
|
17646
|
+
if (typeof segSequence[i].x0062000D !== 'undefined') {
|
|
17647
|
+
var cielabElement = segSequence[i].x0062000D.value;
|
|
17648
|
+
var rgb = dwv.utils.cielabToSrgb(dwv.utils.uintLabToLab({
|
|
17649
|
+
l: cielabElement[0],
|
|
17650
|
+
a: cielabElement[1],
|
|
17651
|
+
b: cielabElement[2]
|
|
17652
|
+
}));
|
|
17653
|
+
label.colour = rgb;
|
|
17654
|
+
// create rgb image
|
|
17655
|
+
storeAsRGB = true;
|
|
17656
|
+
}
|
|
17657
|
+
// store
|
|
17658
|
+
labels.push(label);
|
|
17659
|
+
}
|
|
17660
|
+
|
|
17661
|
+
// image size
|
|
17662
|
+
var size = dicomElements.getImageSize();
|
|
17663
|
+
|
|
17664
|
+
var getSpacingFromMeasure = function (measure) {
|
|
17665
|
+
if (typeof measure.x00280030 === 'undefined') {
|
|
17666
|
+
return null;
|
|
17667
|
+
}
|
|
17668
|
+
var pixelSpacing = measure.x00280030;
|
|
17669
|
+
var spacingValues = [
|
|
17670
|
+
parseFloat(pixelSpacing.value[0]),
|
|
17671
|
+
parseFloat(pixelSpacing.value[1])
|
|
17672
|
+
];
|
|
17673
|
+
if (typeof measure.x00180088 !== 'undefined') {
|
|
17674
|
+
var sliceThickness = measure.x00180088;
|
|
17675
|
+
spacingValues.push(parseFloat(sliceThickness.value[0]));
|
|
17676
|
+
}
|
|
17677
|
+
return new dwv.image.Spacing(spacingValues);
|
|
17678
|
+
};
|
|
17679
|
+
|
|
17680
|
+
// Shared Functional Groups Sequence
|
|
17681
|
+
var spacing;
|
|
17682
|
+
var imageOrientationPatient;
|
|
17683
|
+
var sharedFunctionalGroupsSeq = dicomElements.getFromKey('x52009229', true);
|
|
17684
|
+
if (sharedFunctionalGroupsSeq.length !== 0) {
|
|
17685
|
+
// should be only one
|
|
17686
|
+
var funcGroup0 = sharedFunctionalGroupsSeq[0];
|
|
17687
|
+
// Plane Orientation Sequence
|
|
17688
|
+
if (typeof funcGroup0.x00209116 !== 'undefined') {
|
|
17689
|
+
var planeOrientationSeq = funcGroup0.x00209116;
|
|
17690
|
+
if (planeOrientationSeq.value.length !== 0) {
|
|
17691
|
+
// should be only one
|
|
17692
|
+
imageOrientationPatient = planeOrientationSeq.value[0].x00200037.value;
|
|
17693
|
+
} else {
|
|
17694
|
+
dwv.logger.warn(
|
|
17695
|
+
'No shared functional group plane orientation sequence items.');
|
|
17696
|
+
}
|
|
17697
|
+
}
|
|
17698
|
+
// Pixel Measures Sequence
|
|
17699
|
+
if (typeof funcGroup0.x00289110 !== 'undefined') {
|
|
17700
|
+
var pixelMeasuresSeq = funcGroup0.x00289110;
|
|
17701
|
+
if (pixelMeasuresSeq.value.length !== 0) {
|
|
17702
|
+
// should be only one
|
|
17703
|
+
spacing = getSpacingFromMeasure(pixelMeasuresSeq.value[0]);
|
|
17704
|
+
} else {
|
|
17705
|
+
dwv.logger.warn(
|
|
17706
|
+
'No shared functional group pixel measure sequence items.');
|
|
17707
|
+
}
|
|
17708
|
+
}
|
|
17709
|
+
}
|
|
17710
|
+
|
|
17711
|
+
// position patient utility functions
|
|
17712
|
+
var equalPosPat = function (pos1, pos2) {
|
|
17713
|
+
return JSON.stringify(pos1) === JSON.stringify(pos2);
|
|
17714
|
+
};
|
|
17715
|
+
|
|
17716
|
+
var comparePosPat = function (pos1, pos2) {
|
|
17717
|
+
var diff = null;
|
|
17718
|
+
var posLen = pos1.length;
|
|
17719
|
+
var index = posLen;
|
|
17720
|
+
for (var i = 0; i < posLen; ++i) {
|
|
17721
|
+
--index;
|
|
17722
|
+
diff = pos2[index] - pos1[index];
|
|
17723
|
+
if (diff !== 0) {
|
|
17724
|
+
return diff;
|
|
17725
|
+
}
|
|
17726
|
+
}
|
|
17727
|
+
return diff;
|
|
17728
|
+
};
|
|
17729
|
+
|
|
17730
|
+
var includesPosPat = function (arr, val) {
|
|
17731
|
+
return arr.some(function (arrVal) {
|
|
17732
|
+
return equalPosPat(val, arrVal);
|
|
17733
|
+
});
|
|
17734
|
+
};
|
|
17735
|
+
|
|
17736
|
+
var findIndexPosPat = function (arr, val) {
|
|
17737
|
+
return arr.findIndex(function (arrVal) {
|
|
17738
|
+
return equalPosPat(val, arrVal);
|
|
17739
|
+
});
|
|
17740
|
+
};
|
|
17741
|
+
|
|
17742
|
+
var arrayEquals = function (arr0, arr1) {
|
|
17743
|
+
if (arr0 === null || arr1 === null) {
|
|
17744
|
+
return false;
|
|
17745
|
+
}
|
|
17746
|
+
if (arr0.length !== arr1.length) {
|
|
17747
|
+
return false;
|
|
17748
|
+
}
|
|
17749
|
+
return arr0.every(function (element, index) {
|
|
17750
|
+
return element === arr1[index];
|
|
17751
|
+
});
|
|
17752
|
+
};
|
|
17753
|
+
|
|
17754
|
+
// Per-frame Functional Groups Sequence
|
|
17755
|
+
var perFrameFuncGroupSequence = dicomElements.getFromKey('x52009230', true);
|
|
17756
|
+
if (!perFrameFuncGroupSequence ||
|
|
17757
|
+
typeof perFrameFuncGroupSequence === 'undefined') {
|
|
17758
|
+
throw new Error('Missing or empty per frame functional sequence');
|
|
17759
|
+
}
|
|
17760
|
+
if (frames !== perFrameFuncGroupSequence.length) {
|
|
17761
|
+
throw new Error(
|
|
17762
|
+
'perFrameFuncGroupSequence meta and numberOfFrames are not equal.');
|
|
17763
|
+
}
|
|
17764
|
+
// create frame info object from per frame func
|
|
17765
|
+
var frameInfos = [];
|
|
17766
|
+
var posPats = [];
|
|
17767
|
+
for (var j = 0; j < perFrameFuncGroupSequence.length; ++j) {
|
|
17768
|
+
var frameFunc = perFrameFuncGroupSequence[j];
|
|
17769
|
+
// Derivation Image Sequence
|
|
17770
|
+
var referencedSOPInstanceUID;
|
|
17771
|
+
if (typeof frameFunc.x00089124 !== 'undefined') {
|
|
17772
|
+
var derivationImageSq = frameFunc.x00089124.value;
|
|
17773
|
+
// Source Image Sequence
|
|
17774
|
+
if (typeof derivationImageSq[0].x00082112 !== 'undefined') {
|
|
17775
|
+
var sourceImageSq = derivationImageSq[0].x00082112.value;
|
|
17776
|
+
// Referenced SOP Instance UID
|
|
17777
|
+
if (typeof sourceImageSq[0].x00081155 !== 'undefined') {
|
|
17778
|
+
referencedSOPInstanceUID = sourceImageSq[0].x00081155.value[0];
|
|
17779
|
+
}
|
|
17780
|
+
}
|
|
17781
|
+
}
|
|
17782
|
+
// Frame Content Sequence
|
|
17783
|
+
var frameContentSq = frameFunc.x00209111.value;
|
|
17784
|
+
// Dimension Index Value
|
|
17785
|
+
var dimIndex = frameContentSq[0].x00209157.value;
|
|
17786
|
+
// Plane Position Sequence
|
|
17787
|
+
var planePosSq = frameFunc.x00209113.value;
|
|
17788
|
+
// Image Position (Patient)
|
|
17789
|
+
var imagePosPat = planePosSq[0].x00200032.value;
|
|
17790
|
+
for (var p = 0; p < imagePosPat.length; ++p) {
|
|
17791
|
+
imagePosPat[p] = parseFloat(imagePosPat[p], 10);
|
|
17792
|
+
}
|
|
17793
|
+
if (!includesPosPat(posPats, imagePosPat)) {
|
|
17794
|
+
posPats.push(imagePosPat);
|
|
17795
|
+
}
|
|
17796
|
+
frameInfos.push({
|
|
17797
|
+
dimIndex: dimIndex,
|
|
17798
|
+
imagePosPat: imagePosPat,
|
|
17799
|
+
referencedSOPInstanceUID: referencedSOPInstanceUID
|
|
17800
|
+
});
|
|
17801
|
+
// Plane Orientation Sequence
|
|
17802
|
+
if (typeof frameFunc.x00209116 !== 'undefined') {
|
|
17803
|
+
var framePlaneOrientationSeq = frameFunc.x00209116;
|
|
17804
|
+
if (framePlaneOrientationSeq.value.length !== 0) {
|
|
17805
|
+
// should only be one
|
|
17806
|
+
var frameImageOrientation =
|
|
17807
|
+
framePlaneOrientationSeq.value[0].x00200037.value;
|
|
17808
|
+
if (typeof imageOrientationPatient === 'undefined') {
|
|
17809
|
+
imageOrientationPatient = frameImageOrientation;
|
|
17810
|
+
} else {
|
|
17811
|
+
if (!arrayEquals(frameImageOrientation, imageOrientationPatient)) {
|
|
17812
|
+
throw new Error('Unsupported multi orientation dicom seg.');
|
|
17813
|
+
}
|
|
17814
|
+
}
|
|
17815
|
+
}
|
|
17816
|
+
}
|
|
17817
|
+
// Pixel Measures Sequence
|
|
17818
|
+
if (typeof frameFunc.x00289110 !== 'undefined') {
|
|
17819
|
+
var framePixelMeasuresSeq = frameFunc.x00289110;
|
|
17820
|
+
if (framePixelMeasuresSeq.value.length !== 0) {
|
|
17821
|
+
// should only be one
|
|
17822
|
+
var frameSpacing =
|
|
17823
|
+
getSpacingFromMeasure(framePixelMeasuresSeq.value[0]);
|
|
17824
|
+
if (typeof spacing === 'undefined') {
|
|
17825
|
+
spacing = frameSpacing;
|
|
17826
|
+
} else {
|
|
17827
|
+
if (!spacing.equals(frameSpacing)) {
|
|
17828
|
+
throw new Error('Unsupported multi resolution dicom seg.');
|
|
17829
|
+
}
|
|
17830
|
+
}
|
|
17831
|
+
} else {
|
|
17832
|
+
dwv.logger.warn(
|
|
17833
|
+
'No shared functional group pixel measure sequence items.');
|
|
17834
|
+
}
|
|
17835
|
+
}
|
|
17836
|
+
}
|
|
17837
|
+
// sort positions patient
|
|
17838
|
+
posPats.sort(comparePosPat);
|
|
17839
|
+
|
|
17840
|
+
// create output buffer
|
|
17841
|
+
// as many slices as posPats -> gap slices between groups are not represented
|
|
17842
|
+
var numberOfSlices = posPats.length;
|
|
17843
|
+
var mul = storeAsRGB ? 3 : 1;
|
|
17844
|
+
var buffer = new pixelBuffer.constructor(mul * sliceSize * numberOfSlices);
|
|
17845
|
+
buffer.fill(0);
|
|
17846
|
+
// merge frame buffers
|
|
17847
|
+
var sliceOffset = null;
|
|
17848
|
+
var sliceIndex = null;
|
|
17849
|
+
var frameOffset = null;
|
|
17850
|
+
var labelIndex = null;
|
|
17851
|
+
for (var f = 0; f < frameInfos.length; ++f) {
|
|
17852
|
+
// get the slice index from the position in the posPat array
|
|
17853
|
+
sliceIndex = findIndexPosPat(posPats, frameInfos[f].imagePosPat);
|
|
17854
|
+
frameOffset = sliceSize * f;
|
|
17855
|
+
labelIndex = frameInfos[f].dimIndex[0] - 1;
|
|
17856
|
+
sliceOffset = sliceSize * sliceIndex;
|
|
17857
|
+
var pixelValue;
|
|
17858
|
+
if (storeAsRGB) {
|
|
17859
|
+
pixelValue = labels[labelIndex].colour;
|
|
17860
|
+
} else {
|
|
17861
|
+
pixelValue = labels[labelIndex].value;
|
|
17862
|
+
}
|
|
17863
|
+
for (var l = 0; l < sliceSize; ++l) {
|
|
17864
|
+
if (pixelBuffer[frameOffset + l] !== 0) {
|
|
17865
|
+
var offset = mul * (sliceOffset + l);
|
|
17866
|
+
if (storeAsRGB) {
|
|
17867
|
+
buffer[offset] = pixelValue.r;
|
|
17868
|
+
buffer[offset + 1] = pixelValue.g;
|
|
17869
|
+
buffer[offset + 2] = pixelValue.b;
|
|
17870
|
+
} else {
|
|
17871
|
+
buffer[offset] = pixelValue;
|
|
17872
|
+
}
|
|
17873
|
+
}
|
|
17874
|
+
}
|
|
17875
|
+
}
|
|
17876
|
+
|
|
17877
|
+
if (typeof spacing === 'undefined') {
|
|
17878
|
+
throw Error('No spacing found in DICOM seg file.');
|
|
17879
|
+
}
|
|
17880
|
+
|
|
17881
|
+
// geometry
|
|
17882
|
+
var point3DFromArray = function (arr) {
|
|
17883
|
+
return new dwv.math.Point3D(arr[0], arr[1], arr[2]);
|
|
17884
|
+
};
|
|
17885
|
+
var origin = point3DFromArray(posPats[0]);
|
|
17886
|
+
var geometry = new dwv.image.Geometry(origin, size, spacing);
|
|
17887
|
+
var uids = [0];
|
|
17888
|
+
for (var m = 1; m < numberOfSlices; ++m) {
|
|
17889
|
+
// args: origin, volumeNumber, uid, index, increment
|
|
17890
|
+
geometry.appendOrigin(point3DFromArray(posPats[m]), m);
|
|
17891
|
+
uids.push(m);
|
|
17892
|
+
}
|
|
17893
|
+
|
|
17894
|
+
// create image
|
|
17895
|
+
var image = new dwv.image.Image(geometry, buffer, uids);
|
|
17896
|
+
if (storeAsRGB) {
|
|
17897
|
+
image.setPhotometricInterpretation('RGB');
|
|
17898
|
+
}
|
|
17899
|
+
// image meta
|
|
17900
|
+
var meta = {
|
|
17901
|
+
Modality: 'SEG',
|
|
17902
|
+
BitsStored: 8,
|
|
17903
|
+
labels: labels,
|
|
17904
|
+
frameInfos: frameInfos,
|
|
17905
|
+
SeriesInstanceUID: dicomElements.getFromKey('x0020000E'),
|
|
17906
|
+
SOPInstanceUID: dicomElements.getFromKey('x00080018'),
|
|
17907
|
+
ImageOrientationPatient: imageOrientationPatient
|
|
17908
|
+
};
|
|
17909
|
+
image.setMeta(meta);
|
|
17910
|
+
|
|
17911
|
+
return image;
|
|
17912
|
+
};
|
|
17913
|
+
|
|
17914
|
+
// namespaces
|
|
17915
|
+
var dwv = dwv || {};
|
|
17916
|
+
dwv.image = dwv.image || {};
|
|
17917
|
+
|
|
17412
17918
|
/**
|
|
17413
17919
|
* Plane geometry helper.
|
|
17414
17920
|
*
|
|
@@ -18566,16 +19072,28 @@ dwv.image.View = function (image) {
|
|
|
18566
19072
|
silent = false;
|
|
18567
19073
|
}
|
|
18568
19074
|
|
|
18569
|
-
// check if possible
|
|
18570
19075
|
var geometry = image.getGeometry();
|
|
19076
|
+
var posIndex = geometry.worldToIndex(newPosition);
|
|
19077
|
+
|
|
19078
|
+
// check if possible
|
|
18571
19079
|
if (!geometry.isInBounds(newPosition)) {
|
|
19080
|
+
if (!silent) {
|
|
19081
|
+
// fire event with valid: false
|
|
19082
|
+
fireEvent({
|
|
19083
|
+
type: 'positionchange',
|
|
19084
|
+
value: [
|
|
19085
|
+
posIndex.getValues(),
|
|
19086
|
+
newPosition.getValues(),
|
|
19087
|
+
],
|
|
19088
|
+
valid: false
|
|
19089
|
+
});
|
|
19090
|
+
}
|
|
18572
19091
|
return false;
|
|
18573
19092
|
}
|
|
18574
19093
|
|
|
18575
19094
|
var isNew = !currentPosition || !currentPosition.equals(newPosition);
|
|
18576
19095
|
|
|
18577
19096
|
if (isNew) {
|
|
18578
|
-
var posIndex = geometry.worldToIndex(newPosition);
|
|
18579
19097
|
var diffDims = null;
|
|
18580
19098
|
if (currentPosition) {
|
|
18581
19099
|
if (currentPosition.canCompare(newPosition)) {
|
|
@@ -18648,7 +19166,11 @@ dwv.image.View = function (image) {
|
|
|
18648
19166
|
*/
|
|
18649
19167
|
this.setCurrentIndex = function (index, silent) {
|
|
18650
19168
|
var geometry = this.getImage().getGeometry();
|
|
18651
|
-
|
|
19169
|
+
var position = geometry.indexToWorld(index);
|
|
19170
|
+
if (!geometry.isInBounds(position)) {
|
|
19171
|
+
return false;
|
|
19172
|
+
}
|
|
19173
|
+
return this.setCurrentPosition(position, silent);
|
|
18652
19174
|
};
|
|
18653
19175
|
|
|
18654
19176
|
/**
|
|
@@ -18832,14 +19354,19 @@ dwv.image.View.prototype.setWindowLevelMinMax = function () {
|
|
|
18832
19354
|
* Generate display image data to be given to a canvas.
|
|
18833
19355
|
*
|
|
18834
19356
|
* @param {Array} array The array to fill in.
|
|
19357
|
+
* @param {dwv.math.Point} position Optional position at which to generate,
|
|
19358
|
+
* otherwise generates at current position.
|
|
18835
19359
|
*/
|
|
18836
|
-
dwv.image.View.prototype.generateImageData = function (array) {
|
|
19360
|
+
dwv.image.View.prototype.generateImageData = function (array, position) {
|
|
18837
19361
|
// check position
|
|
18838
|
-
if (
|
|
18839
|
-
this.
|
|
19362
|
+
if (typeof position === 'undefined') {
|
|
19363
|
+
if (!this.getCurrentPosition()) {
|
|
19364
|
+
this.setInitialPosition();
|
|
19365
|
+
}
|
|
19366
|
+
position = this.getCurrentIndex();
|
|
18840
19367
|
}
|
|
19368
|
+
|
|
18841
19369
|
var image = this.getImage();
|
|
18842
|
-
var position = this.getCurrentIndex();
|
|
18843
19370
|
var iterator = dwv.image.getSliceIterator(
|
|
18844
19371
|
image, position, false, this.getOrientation());
|
|
18845
19372
|
|
|
@@ -18907,8 +19434,7 @@ dwv.image.View.prototype.incrementIndex = function (dim, silent) {
|
|
|
18907
19434
|
}
|
|
18908
19435
|
var incr = new dwv.math.Index(values);
|
|
18909
19436
|
var newIndex = index.add(incr);
|
|
18910
|
-
|
|
18911
|
-
return this.setCurrentPosition(geometry.indexToWorld(newIndex), silent);
|
|
19437
|
+
return this.setCurrentIndex(newIndex, silent);
|
|
18912
19438
|
};
|
|
18913
19439
|
|
|
18914
19440
|
/**
|
|
@@ -18929,8 +19455,7 @@ dwv.image.View.prototype.decrementIndex = function (dim, silent) {
|
|
|
18929
19455
|
}
|
|
18930
19456
|
var incr = new dwv.math.Index(values);
|
|
18931
19457
|
var newIndex = index.add(incr);
|
|
18932
|
-
|
|
18933
|
-
return this.setCurrentPosition(geometry.indexToWorld(newIndex), silent);
|
|
19458
|
+
return this.setCurrentIndex(newIndex, silent);
|
|
18934
19459
|
};
|
|
18935
19460
|
|
|
18936
19461
|
/**
|
|
@@ -32428,7 +32953,11 @@ dwv.utils.buildMultipart = function (parts, boundary) {
|
|
|
32428
32953
|
var partsSize = 0;
|
|
32429
32954
|
var headers = [];
|
|
32430
32955
|
for (var i = 0; i < parts.length; ++i) {
|
|
32431
|
-
var headerStr = '
|
|
32956
|
+
var headerStr = '';
|
|
32957
|
+
if (i !== 0) {
|
|
32958
|
+
headerStr += lineBreak;
|
|
32959
|
+
}
|
|
32960
|
+
headerStr += '--' + boundary + lineBreak;
|
|
32432
32961
|
var partKeys = Object.keys(parts[i]);
|
|
32433
32962
|
for (var k = 0; k < partKeys.length; ++k) {
|
|
32434
32963
|
var key = partKeys[k];
|
|
@@ -32442,7 +32971,7 @@ dwv.utils.buildMultipart = function (parts, boundary) {
|
|
|
32442
32971
|
partsSize += header.byteLength + parts[i].data.byteLength;
|
|
32443
32972
|
}
|
|
32444
32973
|
// build trailer
|
|
32445
|
-
var trailerStr = '--' + boundary + '--' + lineBreak;
|
|
32974
|
+
var trailerStr = lineBreak + '--' + boundary + '--' + lineBreak;
|
|
32446
32975
|
var trailer = dwv.utils.stringToUint8Array(trailerStr);
|
|
32447
32976
|
|
|
32448
32977
|
// final buffer
|
|
@@ -35315,8 +35844,10 @@ dwv.utils.loadFromQuery = function (query, app, options) {
|
|
|
35315
35844
|
dwv.utils.decodeQuery(query, app.loadURLs, options);
|
|
35316
35845
|
// optional display state
|
|
35317
35846
|
if (typeof query.state !== 'undefined') {
|
|
35847
|
+
// queue after main data load
|
|
35318
35848
|
var onLoadEnd = function (/*event*/) {
|
|
35319
|
-
app.
|
|
35849
|
+
app.removeEventListener('loadend', onLoadEnd);
|
|
35850
|
+
app.loadURLs([query.state]);
|
|
35320
35851
|
};
|
|
35321
35852
|
app.addEventListener('loadend', onLoadEnd);
|
|
35322
35853
|
}
|