dwv 0.31.0-beta.7 → 0.31.0-beta.8
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 +324 -181
- package/dist/dwv.min.js +2 -2
- package/package.json +1 -1
package/dist/dwv.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! dwv 0.31.0-beta.
|
|
1
|
+
/*! dwv 0.31.0-beta.8 2022-07-18 12:43:16 */
|
|
2
2
|
// Inspired from umdjs
|
|
3
3
|
// See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
|
|
4
4
|
(function (root, factory) {
|
|
@@ -448,9 +448,6 @@ dwv.App = function () {
|
|
|
448
448
|
if (typeof options.binders !== 'undefined') {
|
|
449
449
|
stage.setBinders(options.binders);
|
|
450
450
|
}
|
|
451
|
-
|
|
452
|
-
// create layer groups
|
|
453
|
-
createLayerGroups(options.dataViewConfigs);
|
|
454
451
|
};
|
|
455
452
|
|
|
456
453
|
/**
|
|
@@ -516,8 +513,6 @@ dwv.App = function () {
|
|
|
516
513
|
* Load a list of files. Can be image files or a state file.
|
|
517
514
|
*
|
|
518
515
|
* @param {Array} files The list of files to load.
|
|
519
|
-
* @param {object} options The options object, can contain:
|
|
520
|
-
* - timepoint: an object with time information
|
|
521
516
|
* @fires dwv.App#loadstart
|
|
522
517
|
* @fires dwv.App#loadprogress
|
|
523
518
|
* @fires dwv.App#loaditem
|
|
@@ -525,12 +520,12 @@ dwv.App = function () {
|
|
|
525
520
|
* @fires dwv.App#error
|
|
526
521
|
* @fires dwv.App#abort
|
|
527
522
|
*/
|
|
528
|
-
this.loadFiles = function (files
|
|
523
|
+
this.loadFiles = function (files) {
|
|
529
524
|
if (files.length === 0) {
|
|
530
525
|
dwv.logger.warn('Ignoring empty input file list.');
|
|
531
526
|
return;
|
|
532
527
|
}
|
|
533
|
-
loadController.loadFiles(files
|
|
528
|
+
loadController.loadFiles(files);
|
|
534
529
|
};
|
|
535
530
|
|
|
536
531
|
/**
|
|
@@ -697,6 +692,13 @@ dwv.App = function () {
|
|
|
697
692
|
if (typeof dataIndex === 'undefined' || dataIndex === null) {
|
|
698
693
|
throw new Error('Cannot render without data index');
|
|
699
694
|
}
|
|
695
|
+
|
|
696
|
+
// create layer groups if not done yet
|
|
697
|
+
// (create all to allow for ratio sync)
|
|
698
|
+
if (stage.getNumberOfLayerGroups() === 0) {
|
|
699
|
+
createLayerGroups(options.dataViewConfigs);
|
|
700
|
+
}
|
|
701
|
+
|
|
700
702
|
// loop on all configs
|
|
701
703
|
var viewConfigs = getViewConfigs(dataIndex);
|
|
702
704
|
// nothing to do if no view config
|
|
@@ -1144,21 +1146,15 @@ dwv.App = function () {
|
|
|
1144
1146
|
}
|
|
1145
1147
|
|
|
1146
1148
|
var isFirstLoadItem = event.isfirstitem;
|
|
1147
|
-
var isTimepoint = typeof event.timepoint !== 'undefined';
|
|
1148
|
-
var timeId = 0;
|
|
1149
|
-
if (isTimepoint) {
|
|
1150
|
-
timeId = event.timepoint.id;
|
|
1151
|
-
}
|
|
1152
1149
|
|
|
1153
1150
|
var eventMetaData = null;
|
|
1154
1151
|
if (event.loadtype === 'image') {
|
|
1155
|
-
if (isFirstLoadItem
|
|
1152
|
+
if (isFirstLoadItem) {
|
|
1156
1153
|
dataController.addNew(
|
|
1157
1154
|
event.loadid, event.data.image, event.data.info);
|
|
1158
1155
|
} else {
|
|
1159
1156
|
dataController.update(
|
|
1160
|
-
event.loadid, event.data.image, event.data.info
|
|
1161
|
-
timeId);
|
|
1157
|
+
event.loadid, event.data.image, event.data.info);
|
|
1162
1158
|
}
|
|
1163
1159
|
eventMetaData = event.data.info;
|
|
1164
1160
|
} else if (event.loadtype === 'state') {
|
|
@@ -1511,40 +1507,27 @@ dwv.ctrl.DataController = function () {
|
|
|
1511
1507
|
* @param {number} index The index of the data.
|
|
1512
1508
|
* @param {dwv.image.Image} image The image.
|
|
1513
1509
|
* @param {object} meta The image meta.
|
|
1514
|
-
* @param {number} timeId The time ID.
|
|
1515
1510
|
*/
|
|
1516
|
-
this.update = function (index, image, meta
|
|
1511
|
+
this.update = function (index, image, meta) {
|
|
1517
1512
|
var dataToUpdate = data[index];
|
|
1518
1513
|
|
|
1519
|
-
// handle possible timepoint
|
|
1520
|
-
if (typeof timeId !== 'undefined') {
|
|
1521
|
-
var size = dataToUpdate.image.getGeometry().getSize();
|
|
1522
|
-
// append frame for first frame (still 3D) or other frames
|
|
1523
|
-
if ((size.length() === 3 && timeId !== 0) ||
|
|
1524
|
-
(size.length() > 3 && timeId >= size.get(3))) {
|
|
1525
|
-
dataToUpdate.image.appendFrame();
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
1514
|
// add slice to current image
|
|
1530
|
-
dataToUpdate.image.appendSlice(image
|
|
1515
|
+
dataToUpdate.image.appendSlice(image);
|
|
1531
1516
|
|
|
1532
1517
|
// update meta data
|
|
1533
1518
|
// TODO add time support
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
idKey = 'imageUid';
|
|
1541
|
-
}
|
|
1542
|
-
dataToUpdate.meta = dwv.utils.mergeObjects(
|
|
1543
|
-
dataToUpdate.meta,
|
|
1544
|
-
getMetaObject(meta),
|
|
1545
|
-
idKey,
|
|
1546
|
-
'value');
|
|
1519
|
+
var idKey = '';
|
|
1520
|
+
if (typeof meta.x00020010 !== 'undefined') {
|
|
1521
|
+
// dicom case
|
|
1522
|
+
idKey = 'InstanceNumber';
|
|
1523
|
+
} else {
|
|
1524
|
+
idKey = 'imageUid';
|
|
1547
1525
|
}
|
|
1526
|
+
dataToUpdate.meta = dwv.utils.mergeObjects(
|
|
1527
|
+
dataToUpdate.meta,
|
|
1528
|
+
getMetaObject(meta),
|
|
1529
|
+
idKey,
|
|
1530
|
+
'value');
|
|
1548
1531
|
};
|
|
1549
1532
|
|
|
1550
1533
|
/**
|
|
@@ -2138,16 +2121,14 @@ dwv.ctrl.LoadController = function (defaultCharacterSet) {
|
|
|
2138
2121
|
* Load a list of files. Can be image files or a state file.
|
|
2139
2122
|
*
|
|
2140
2123
|
* @param {Array} files The list of files to load.
|
|
2141
|
-
* @param {object} options The options object, can contain:
|
|
2142
|
-
* - timepoint: an object with time information
|
|
2143
2124
|
*/
|
|
2144
|
-
this.loadFiles = function (files
|
|
2125
|
+
this.loadFiles = function (files) {
|
|
2145
2126
|
// has been checked for emptiness.
|
|
2146
2127
|
var ext = files[0].name.split('.').pop().toLowerCase();
|
|
2147
2128
|
if (ext === 'json') {
|
|
2148
|
-
loadStateFile(files[0]
|
|
2129
|
+
loadStateFile(files[0]);
|
|
2149
2130
|
} else {
|
|
2150
|
-
loadImageFiles(files
|
|
2131
|
+
loadImageFiles(files);
|
|
2151
2132
|
}
|
|
2152
2133
|
};
|
|
2153
2134
|
|
|
@@ -2199,16 +2180,14 @@ dwv.ctrl.LoadController = function (defaultCharacterSet) {
|
|
|
2199
2180
|
* Load a list of image files.
|
|
2200
2181
|
*
|
|
2201
2182
|
* @param {Array} files The list of image files to load.
|
|
2202
|
-
* @param {object} options The options object, can contain:
|
|
2203
|
-
* - timepoint: an object with time information
|
|
2204
2183
|
* @private
|
|
2205
2184
|
*/
|
|
2206
|
-
function loadImageFiles(files
|
|
2185
|
+
function loadImageFiles(files) {
|
|
2207
2186
|
// create IO
|
|
2208
2187
|
var fileIO = new dwv.io.FilesLoader();
|
|
2209
2188
|
fileIO.setDefaultCharacterSet(defaultCharacterSet);
|
|
2210
2189
|
// load data
|
|
2211
|
-
loadData(files, fileIO, 'image'
|
|
2190
|
+
loadData(files, fileIO, 'image');
|
|
2212
2191
|
}
|
|
2213
2192
|
|
|
2214
2193
|
/**
|
|
@@ -2232,14 +2211,13 @@ dwv.ctrl.LoadController = function (defaultCharacterSet) {
|
|
|
2232
2211
|
* Load a State file.
|
|
2233
2212
|
*
|
|
2234
2213
|
* @param {string} file The state file to load.
|
|
2235
|
-
* @param {object} options The options object.
|
|
2236
2214
|
* @private
|
|
2237
2215
|
*/
|
|
2238
|
-
function loadStateFile(file
|
|
2216
|
+
function loadStateFile(file) {
|
|
2239
2217
|
// create IO
|
|
2240
2218
|
var fileIO = new dwv.io.FilesLoader();
|
|
2241
2219
|
// load data
|
|
2242
|
-
loadData([file], fileIO, 'state'
|
|
2220
|
+
loadData([file], fileIO, 'state');
|
|
2243
2221
|
}
|
|
2244
2222
|
|
|
2245
2223
|
/**
|
|
@@ -2272,20 +2250,8 @@ dwv.ctrl.LoadController = function (defaultCharacterSet) {
|
|
|
2272
2250
|
loadtype: loadType,
|
|
2273
2251
|
};
|
|
2274
2252
|
|
|
2275
|
-
//
|
|
2276
|
-
var
|
|
2277
|
-
if (typeof options !== 'undefined' &&
|
|
2278
|
-
typeof options.timepoint !== 'undefined') {
|
|
2279
|
-
hasTimepoint = true;
|
|
2280
|
-
}
|
|
2281
|
-
|
|
2282
|
-
var loadId = null;
|
|
2283
|
-
if (hasTimepoint) {
|
|
2284
|
-
loadId = options.timepoint.dataId;
|
|
2285
|
-
eventInfo.timepoint = options.timepoint;
|
|
2286
|
-
} else {
|
|
2287
|
-
loadId = getNextLoadId();
|
|
2288
|
-
}
|
|
2253
|
+
// load id
|
|
2254
|
+
var loadId = getNextLoadId();
|
|
2289
2255
|
eventInfo.loadid = loadId;
|
|
2290
2256
|
|
|
2291
2257
|
// set callbacks
|
|
@@ -2307,9 +2273,6 @@ dwv.ctrl.LoadController = function (defaultCharacterSet) {
|
|
|
2307
2273
|
if (typeof currentLoaders[loadId] !== 'undefined') {
|
|
2308
2274
|
eventInfoItem.isfirstitem = currentLoaders[loadId].isFirstItem;
|
|
2309
2275
|
}
|
|
2310
|
-
if (hasTimepoint) {
|
|
2311
|
-
eventInfoItem.timepoint = options.timepoint;
|
|
2312
|
-
}
|
|
2313
2276
|
// callback
|
|
2314
2277
|
augmentCallbackEvent(self.onloaditem, eventInfoItem)(event);
|
|
2315
2278
|
// update loader
|
|
@@ -4553,6 +4516,16 @@ dwv.dicom.DicomElementsWrapper.prototype.getPixelSpacing = function () {
|
|
|
4553
4516
|
return new dwv.image.Spacing([columnSpacing, rowSpacing, 1]);
|
|
4554
4517
|
};
|
|
4555
4518
|
|
|
4519
|
+
/**
|
|
4520
|
+
* Get the time.
|
|
4521
|
+
*
|
|
4522
|
+
* @returns {number|undefined} The time value if available.
|
|
4523
|
+
*/
|
|
4524
|
+
dwv.dicom.DicomElementsWrapper.prototype.getTime = function () {
|
|
4525
|
+
// default returns undefined
|
|
4526
|
+
return undefined;
|
|
4527
|
+
};
|
|
4528
|
+
|
|
4556
4529
|
/**
|
|
4557
4530
|
* Get the file list from a DICOMDIR
|
|
4558
4531
|
*
|
|
@@ -4629,7 +4602,7 @@ dwv.dicom = dwv.dicom || {};
|
|
|
4629
4602
|
* @returns {string} The version of the library.
|
|
4630
4603
|
*/
|
|
4631
4604
|
dwv.getVersion = function () {
|
|
4632
|
-
return '0.31.0-beta.
|
|
4605
|
+
return '0.31.0-beta.8';
|
|
4633
4606
|
};
|
|
4634
4607
|
|
|
4635
4608
|
/**
|
|
@@ -14112,40 +14085,63 @@ dwv.gui.ViewLayer = function (containerDiv) {
|
|
|
14112
14085
|
* @param {object} fitOffset The fit offset as {x,y}.
|
|
14113
14086
|
*/
|
|
14114
14087
|
this.fitToContainer = function (fitScale1D, fitSize, fitOffset) {
|
|
14115
|
-
|
|
14116
|
-
|
|
14117
|
-
|
|
14118
|
-
if (
|
|
14119
|
-
|
|
14088
|
+
var needsDraw = false;
|
|
14089
|
+
|
|
14090
|
+
// update canvas size if needed (triggers canvas reset)
|
|
14091
|
+
if (canvas.width !== fitSize.x || canvas.height !== fitSize.y) {
|
|
14092
|
+
if (!dwv.gui.canCreateCanvas(fitSize.x, fitSize.y)) {
|
|
14093
|
+
throw new Error('Cannot resize canvas ' + fitSize.x + ', ' + fitSize.y);
|
|
14094
|
+
}
|
|
14095
|
+
// canvas size change triggers canvas reset
|
|
14096
|
+
canvas.width = fitSize.x;
|
|
14097
|
+
canvas.height = fitSize.y;
|
|
14098
|
+
// update draw flag
|
|
14099
|
+
needsDraw = true;
|
|
14120
14100
|
}
|
|
14121
|
-
canvas.width = width;
|
|
14122
|
-
canvas.height = height;
|
|
14123
14101
|
|
|
14124
14102
|
// previous scale without fit
|
|
14125
14103
|
var previousScale = {
|
|
14126
14104
|
x: scale.x / fitScale.x,
|
|
14127
14105
|
y: scale.y / fitScale.y
|
|
14128
14106
|
};
|
|
14129
|
-
//
|
|
14130
|
-
|
|
14107
|
+
// fit scale
|
|
14108
|
+
var newFitScale = {
|
|
14131
14109
|
x: fitScale1D * baseSpacing.x,
|
|
14132
14110
|
y: fitScale1D * baseSpacing.y
|
|
14133
14111
|
};
|
|
14134
|
-
//
|
|
14135
|
-
|
|
14136
|
-
x: previousScale.x *
|
|
14137
|
-
y: previousScale.y *
|
|
14138
|
-
};
|
|
14139
|
-
|
|
14140
|
-
// update offsets
|
|
14141
|
-
viewOffset = {
|
|
14142
|
-
x: fitOffset.x / fitScale.x,
|
|
14143
|
-
y: fitOffset.y / fitScale.y
|
|
14112
|
+
// scale
|
|
14113
|
+
var newScale = {
|
|
14114
|
+
x: previousScale.x * newFitScale.x,
|
|
14115
|
+
y: previousScale.y * newFitScale.y
|
|
14144
14116
|
};
|
|
14145
|
-
|
|
14146
|
-
|
|
14147
|
-
|
|
14117
|
+
// check if different
|
|
14118
|
+
if (previousScale.x !== newScale.x || previousScale.y !== newScale.y) {
|
|
14119
|
+
fitScale = newFitScale;
|
|
14120
|
+
scale = newScale;
|
|
14121
|
+
// update draw flag
|
|
14122
|
+
needsDraw = true;
|
|
14123
|
+
}
|
|
14124
|
+
|
|
14125
|
+
// view offset
|
|
14126
|
+
var newViewOffset = {
|
|
14127
|
+
x: fitOffset.x / newFitScale.x,
|
|
14128
|
+
y: fitOffset.y / newFitScale.y
|
|
14148
14129
|
};
|
|
14130
|
+
// check if different
|
|
14131
|
+
if (viewOffset.x !== newViewOffset.x || viewOffset.y !== newViewOffset.y) {
|
|
14132
|
+
viewOffset = newViewOffset;
|
|
14133
|
+
offset = {
|
|
14134
|
+
x: viewOffset.x + baseOffset.x + zoomOffset.x,
|
|
14135
|
+
y: viewOffset.y + baseOffset.y + zoomOffset.y
|
|
14136
|
+
};
|
|
14137
|
+
// update draw flag
|
|
14138
|
+
needsDraw = true;
|
|
14139
|
+
}
|
|
14140
|
+
|
|
14141
|
+
// draw if needed
|
|
14142
|
+
if (needsDraw) {
|
|
14143
|
+
this.draw();
|
|
14144
|
+
}
|
|
14149
14145
|
};
|
|
14150
14146
|
|
|
14151
14147
|
/**
|
|
@@ -15569,13 +15565,17 @@ dwv.image = dwv.image || {};
|
|
|
15569
15565
|
* @param {dwv.image.Spacing} spacing The object spacing.
|
|
15570
15566
|
* @param {dwv.math.Matrix33} orientation The object orientation (3*3 matrix,
|
|
15571
15567
|
* default to 3*3 identity).
|
|
15568
|
+
* @param {number} time Optional time index.
|
|
15572
15569
|
*/
|
|
15573
|
-
dwv.image.Geometry = function (origin, size, spacing, orientation) {
|
|
15574
|
-
// check input origin
|
|
15575
|
-
if (typeof origin === 'undefined') {
|
|
15576
|
-
origin = new dwv.math.Point3D(0, 0, 0);
|
|
15577
|
-
}
|
|
15570
|
+
dwv.image.Geometry = function (origin, size, spacing, orientation, time) {
|
|
15578
15571
|
var origins = [origin];
|
|
15572
|
+
// local helper object for time points
|
|
15573
|
+
var timeOrigins = {};
|
|
15574
|
+
var initialTime;
|
|
15575
|
+
if (typeof time !== 'undefined') {
|
|
15576
|
+
initialTime = time;
|
|
15577
|
+
timeOrigins[time] = [origin];
|
|
15578
|
+
}
|
|
15579
15579
|
// check input orientation
|
|
15580
15580
|
if (typeof orientation === 'undefined') {
|
|
15581
15581
|
orientation = new dwv.math.getIdentityMat33();
|
|
@@ -15583,6 +15583,67 @@ dwv.image.Geometry = function (origin, size, spacing, orientation) {
|
|
|
15583
15583
|
// flag to know if new origins were added
|
|
15584
15584
|
var newOrigins = false;
|
|
15585
15585
|
|
|
15586
|
+
/**
|
|
15587
|
+
* Get the time value that was passed at construction.
|
|
15588
|
+
*
|
|
15589
|
+
* @returns {number} The time value.
|
|
15590
|
+
*/
|
|
15591
|
+
this.getInitialTime = function () {
|
|
15592
|
+
return initialTime;
|
|
15593
|
+
};
|
|
15594
|
+
|
|
15595
|
+
/**
|
|
15596
|
+
* Get the total number of slices.
|
|
15597
|
+
* Can be different from what is stored in the size object
|
|
15598
|
+
* during a volume with time points creation process.
|
|
15599
|
+
*
|
|
15600
|
+
* @returns {number} The total count.
|
|
15601
|
+
*/
|
|
15602
|
+
this.getCurrentTotalNumberOfSlices = function () {
|
|
15603
|
+
var keys = Object.keys(timeOrigins);
|
|
15604
|
+
if (keys.length === 0) {
|
|
15605
|
+
return origins.length;
|
|
15606
|
+
}
|
|
15607
|
+
var count = 0;
|
|
15608
|
+
for (var i = 0; i < keys.length; ++i) {
|
|
15609
|
+
count += timeOrigins[keys[i]].length;
|
|
15610
|
+
}
|
|
15611
|
+
return count;
|
|
15612
|
+
};
|
|
15613
|
+
|
|
15614
|
+
/**
|
|
15615
|
+
* Check if a time point has associated slices.
|
|
15616
|
+
*
|
|
15617
|
+
* @param {number} time The time point to check.
|
|
15618
|
+
* @returns {boolean} True if slices are present.
|
|
15619
|
+
*/
|
|
15620
|
+
this.hasSlicesAtTime = function (time) {
|
|
15621
|
+
return typeof timeOrigins[time] !== 'undefined';
|
|
15622
|
+
};
|
|
15623
|
+
|
|
15624
|
+
/**
|
|
15625
|
+
* Get the number of slices stored for time points preceding
|
|
15626
|
+
* the input one.
|
|
15627
|
+
*
|
|
15628
|
+
* @param {number} time The time point to check.
|
|
15629
|
+
* @returns {number} The count.
|
|
15630
|
+
*/
|
|
15631
|
+
this.getCurrentNumberOfSlicesBeforeTime = function (time) {
|
|
15632
|
+
var keys = Object.keys(timeOrigins);
|
|
15633
|
+
if (keys.length === 0) {
|
|
15634
|
+
return;
|
|
15635
|
+
}
|
|
15636
|
+
var count = 0;
|
|
15637
|
+
for (var i = 0; i < keys.length; ++i) {
|
|
15638
|
+
var key = keys[i];
|
|
15639
|
+
if (parseInt(key, 10) === time) {
|
|
15640
|
+
break;
|
|
15641
|
+
}
|
|
15642
|
+
count += timeOrigins[key].length;
|
|
15643
|
+
}
|
|
15644
|
+
return count;
|
|
15645
|
+
};
|
|
15646
|
+
|
|
15586
15647
|
/**
|
|
15587
15648
|
* Get the object origin.
|
|
15588
15649
|
* This should be the lowest origin to ease calculations (?).
|
|
@@ -15746,24 +15807,30 @@ dwv.image.Geometry = function (origin, size, spacing, orientation) {
|
|
|
15746
15807
|
* magic...
|
|
15747
15808
|
*
|
|
15748
15809
|
* @param {dwv.math.Point3D} point The point to evaluate.
|
|
15810
|
+
* @param {number} time Optional time index.
|
|
15749
15811
|
* @returns {number} The slice index.
|
|
15750
15812
|
*/
|
|
15751
|
-
this.getSliceIndex = function (point) {
|
|
15813
|
+
this.getSliceIndex = function (point, time) {
|
|
15752
15814
|
// cannot use this.worldToIndex(point).getK() since
|
|
15753
15815
|
// we cannot guaranty consecutive slices...
|
|
15754
15816
|
|
|
15817
|
+
var localOrigins = origins;
|
|
15818
|
+
if (typeof time !== 'undefined') {
|
|
15819
|
+
localOrigins = timeOrigins[time];
|
|
15820
|
+
}
|
|
15821
|
+
|
|
15755
15822
|
// find the closest index
|
|
15756
15823
|
var closestSliceIndex = 0;
|
|
15757
|
-
var minDist = point.getDistance(
|
|
15824
|
+
var minDist = point.getDistance(localOrigins[0]);
|
|
15758
15825
|
var dist = 0;
|
|
15759
|
-
for (var i = 0; i <
|
|
15760
|
-
dist = point.getDistance(
|
|
15826
|
+
for (var i = 0; i < localOrigins.length; ++i) {
|
|
15827
|
+
dist = point.getDistance(localOrigins[i]);
|
|
15761
15828
|
if (dist < minDist) {
|
|
15762
15829
|
minDist = dist;
|
|
15763
15830
|
closestSliceIndex = i;
|
|
15764
15831
|
}
|
|
15765
15832
|
}
|
|
15766
|
-
var closestOrigin =
|
|
15833
|
+
var closestOrigin = localOrigins[closestSliceIndex];
|
|
15767
15834
|
// direction between the input point and the closest origin
|
|
15768
15835
|
var pointDir = point.minus(closestOrigin);
|
|
15769
15836
|
// use third orientation matrix column as base plane vector
|
|
@@ -15791,22 +15858,32 @@ dwv.image.Geometry = function (origin, size, spacing, orientation) {
|
|
|
15791
15858
|
*
|
|
15792
15859
|
* @param {dwv.math.Point3D} origin The origin to append.
|
|
15793
15860
|
* @param {number} index The index at which to append.
|
|
15861
|
+
* @param {number} time Optional time index.
|
|
15794
15862
|
*/
|
|
15795
|
-
this.appendOrigin = function (origin, index) {
|
|
15796
|
-
|
|
15797
|
-
|
|
15798
|
-
|
|
15799
|
-
|
|
15800
|
-
|
|
15801
|
-
|
|
15802
|
-
|
|
15863
|
+
this.appendOrigin = function (origin, index, time) {
|
|
15864
|
+
if (typeof time !== 'undefined') {
|
|
15865
|
+
timeOrigins[time].splice(index, 0, origin);
|
|
15866
|
+
}
|
|
15867
|
+
if (typeof time === 'undefined' || time === initialTime) {
|
|
15868
|
+
newOrigins = true;
|
|
15869
|
+
// add in origin array
|
|
15870
|
+
origins.splice(index, 0, origin);
|
|
15871
|
+
// increment second dimension
|
|
15872
|
+
var values = size.getValues();
|
|
15873
|
+
values[2] += 1;
|
|
15874
|
+
size = new dwv.image.Size(values);
|
|
15875
|
+
}
|
|
15803
15876
|
};
|
|
15804
15877
|
|
|
15805
15878
|
/**
|
|
15806
15879
|
* Append a frame to the geometry.
|
|
15807
15880
|
*
|
|
15881
|
+
* @param {dwv.math.Point3D} origin The origin to append.
|
|
15882
|
+
* @param {number} time Optional time index.
|
|
15808
15883
|
*/
|
|
15809
|
-
this.appendFrame = function () {
|
|
15884
|
+
this.appendFrame = function (origin, time) {
|
|
15885
|
+
// add origin to list
|
|
15886
|
+
timeOrigins[time] = [origin];
|
|
15810
15887
|
// increment third dimension
|
|
15811
15888
|
var sizeValues = size.getValues();
|
|
15812
15889
|
var spacingValues = spacing.getValues();
|
|
@@ -15860,11 +15937,11 @@ dwv.image.Geometry.prototype.isInBounds = function (point) {
|
|
|
15860
15937
|
* Check that a index is within bounds.
|
|
15861
15938
|
*
|
|
15862
15939
|
* @param {dwv.math.Index} index The index to check.
|
|
15863
|
-
* @param {
|
|
15940
|
+
* @param {Array} dirs Optional list of directions to check.
|
|
15864
15941
|
* @returns {boolean} True if the given coordinates are within bounds.
|
|
15865
15942
|
*/
|
|
15866
|
-
dwv.image.Geometry.prototype.isIndexInBounds = function (index,
|
|
15867
|
-
return this.getSize().isInBounds(index,
|
|
15943
|
+
dwv.image.Geometry.prototype.isIndexInBounds = function (index, dirs) {
|
|
15944
|
+
return this.getSize().isInBounds(index, dirs);
|
|
15868
15945
|
};
|
|
15869
15946
|
|
|
15870
15947
|
/**
|
|
@@ -15975,6 +16052,31 @@ var dwv = dwv || {};
|
|
|
15975
16052
|
/** @namespace */
|
|
15976
16053
|
dwv.image = dwv.image || {};
|
|
15977
16054
|
|
|
16055
|
+
/**
|
|
16056
|
+
* Get the slice index of an input slice into a volume geometry.
|
|
16057
|
+
*
|
|
16058
|
+
* @param {dwv.image.Geometry} volumeGeometry The volume geometry.
|
|
16059
|
+
* @param {dwv.image.Geometry} sliceGeometry The slice geometry.
|
|
16060
|
+
* @returns {dwv.math.Index} The index of the slice in the volume geomtry.
|
|
16061
|
+
*/
|
|
16062
|
+
dwv.image.getSliceIndex = function (volumeGeometry, sliceGeometry) {
|
|
16063
|
+
// possible time
|
|
16064
|
+
var timeId = sliceGeometry.getInitialTime();
|
|
16065
|
+
// index values
|
|
16066
|
+
var values = [];
|
|
16067
|
+
// x, y
|
|
16068
|
+
values.push(0);
|
|
16069
|
+
values.push(0);
|
|
16070
|
+
// z
|
|
16071
|
+
values.push(volumeGeometry.getSliceIndex(sliceGeometry.getOrigin(), timeId));
|
|
16072
|
+
// time
|
|
16073
|
+
if (typeof timeId !== 'undefined') {
|
|
16074
|
+
values.push(timeId);
|
|
16075
|
+
}
|
|
16076
|
+
// return index
|
|
16077
|
+
return new dwv.math.Index(values);
|
|
16078
|
+
};
|
|
16079
|
+
|
|
15978
16080
|
/**
|
|
15979
16081
|
* Image class.
|
|
15980
16082
|
* Usable once created, optional are:
|
|
@@ -16373,12 +16475,8 @@ dwv.image.Image = function (geometry, buffer, imageUids) {
|
|
|
16373
16475
|
* Append a slice to the image.
|
|
16374
16476
|
*
|
|
16375
16477
|
* @param {Image} rhs The slice to append.
|
|
16376
|
-
* @param {number} timeId An optional time ID.
|
|
16377
16478
|
*/
|
|
16378
|
-
this.appendSlice = function (rhs
|
|
16379
|
-
if (typeof timeId === 'undefined') {
|
|
16380
|
-
timeId = 0;
|
|
16381
|
-
}
|
|
16479
|
+
this.appendSlice = function (rhs) {
|
|
16382
16480
|
// check input
|
|
16383
16481
|
if (rhs === null) {
|
|
16384
16482
|
throw new Error('Cannot append null slice');
|
|
@@ -16412,6 +16510,26 @@ dwv.image.Image = function (geometry, buffer, imageUids) {
|
|
|
16412
16510
|
}
|
|
16413
16511
|
}
|
|
16414
16512
|
|
|
16513
|
+
// possible time
|
|
16514
|
+
var timeId = rhs.getGeometry().getInitialTime();
|
|
16515
|
+
|
|
16516
|
+
// append frame if needed
|
|
16517
|
+
var isNewFrame = false;
|
|
16518
|
+
if (typeof timeId !== 'undefined' && !geometry.hasSlicesAtTime(timeId)) {
|
|
16519
|
+
// update grometry
|
|
16520
|
+
this.appendFrame(rhs.getGeometry().getOrigin(), timeId);
|
|
16521
|
+
// update size
|
|
16522
|
+
size = geometry.getSize();
|
|
16523
|
+
// update flag
|
|
16524
|
+
isNewFrame = true;
|
|
16525
|
+
}
|
|
16526
|
+
|
|
16527
|
+
// get slice index
|
|
16528
|
+
var index = dwv.image.getSliceIndex(geometry, rhs.getGeometry());
|
|
16529
|
+
|
|
16530
|
+
// set slice index
|
|
16531
|
+
var newSliceIndex = index.get(2);
|
|
16532
|
+
|
|
16415
16533
|
// calculate slice size
|
|
16416
16534
|
var sliceSize = numberOfComponents * size.getDimSize(2);
|
|
16417
16535
|
|
|
@@ -16420,65 +16538,43 @@ dwv.image.Image = function (geometry, buffer, imageUids) {
|
|
|
16420
16538
|
throw new Error('Missing number of files for buffer manipulation.');
|
|
16421
16539
|
}
|
|
16422
16540
|
var fullBufferSize = sliceSize * meta.numberOfFiles;
|
|
16423
|
-
if (size.length() === 4) {
|
|
16424
|
-
fullBufferSize *= size.get(3);
|
|
16425
|
-
}
|
|
16426
16541
|
if (buffer.length !== fullBufferSize) {
|
|
16427
16542
|
realloc(fullBufferSize);
|
|
16428
16543
|
}
|
|
16429
16544
|
|
|
16430
|
-
|
|
16431
|
-
var
|
|
16432
|
-
|
|
16433
|
-
|
|
16434
|
-
|
|
16435
|
-
|
|
16436
|
-
|
|
16437
|
-
var
|
|
16438
|
-
|
|
16439
|
-
|
|
16440
|
-
|
|
16441
|
-
|
|
16442
|
-
|
|
16443
|
-
|
|
16444
|
-
var oldNumberOfSlices = size.get(2);
|
|
16445
|
-
// move content if needed
|
|
16446
|
-
var start = primaryOffset;
|
|
16447
|
-
var end;
|
|
16448
|
-
if (newSliceIndex === 0) {
|
|
16449
|
-
// insert slice before current data
|
|
16450
|
-
end = start + oldNumberOfSlices * sliceSize;
|
|
16451
|
-
buffer.set(
|
|
16452
|
-
buffer.subarray(start, end),
|
|
16453
|
-
primaryOffset + sliceSize
|
|
16454
|
-
);
|
|
16455
|
-
} else if (newSliceIndex < oldNumberOfSlices) {
|
|
16456
|
-
// insert slice in between current data
|
|
16457
|
-
end = start + (oldNumberOfSlices - newSliceIndex) * sliceSize;
|
|
16458
|
-
buffer.set(
|
|
16459
|
-
buffer.subarray(start, end),
|
|
16460
|
-
primaryOffset + sliceSize
|
|
16461
|
-
);
|
|
16462
|
-
}
|
|
16545
|
+
// current number of slices
|
|
16546
|
+
var numberOfSlices = newSliceIndex;
|
|
16547
|
+
if (typeof timeId !== 'undefined') {
|
|
16548
|
+
numberOfSlices += geometry.getCurrentNumberOfSlicesBeforeTime(timeId);
|
|
16549
|
+
}
|
|
16550
|
+
// offset of the input slice
|
|
16551
|
+
var indexOffset = numberOfSlices * sliceSize;
|
|
16552
|
+
var maxOffset = geometry.getCurrentTotalNumberOfSlices() * sliceSize;
|
|
16553
|
+
// move content if needed
|
|
16554
|
+
if (indexOffset < maxOffset) {
|
|
16555
|
+
buffer.set(
|
|
16556
|
+
buffer.subarray(indexOffset, maxOffset),
|
|
16557
|
+
indexOffset + sliceSize
|
|
16558
|
+
);
|
|
16463
16559
|
}
|
|
16464
|
-
|
|
16465
16560
|
// add new slice content
|
|
16466
|
-
buffer.set(rhs.getBuffer(),
|
|
16561
|
+
buffer.set(rhs.getBuffer(), indexOffset);
|
|
16467
16562
|
|
|
16468
16563
|
// update geometry
|
|
16469
|
-
if (
|
|
16470
|
-
geometry.appendOrigin(
|
|
16564
|
+
if (!isNewFrame) {
|
|
16565
|
+
geometry.appendOrigin(
|
|
16566
|
+
rhs.getGeometry().getOrigin(), newSliceIndex, timeId);
|
|
16471
16567
|
}
|
|
16472
16568
|
// update rsi
|
|
16473
16569
|
// (rhs should just have one rsi)
|
|
16474
16570
|
this.setRescaleSlopeAndIntercept(
|
|
16475
|
-
rhs.getRescaleSlopeAndIntercept(),
|
|
16571
|
+
rhs.getRescaleSlopeAndIntercept(), numberOfSlices);
|
|
16476
16572
|
|
|
16477
16573
|
// current number of images
|
|
16478
16574
|
var numberOfImages = imageUids.length;
|
|
16479
16575
|
|
|
16480
16576
|
// insert sop instance UIDs
|
|
16481
|
-
imageUids.splice(
|
|
16577
|
+
imageUids.splice(numberOfSlices, 0, rhs.getImageUid());
|
|
16482
16578
|
|
|
16483
16579
|
// update window presets
|
|
16484
16580
|
if (typeof meta.windowPresets !== 'undefined') {
|
|
@@ -16508,7 +16604,7 @@ dwv.image.Image = function (geometry, buffer, imageUids) {
|
|
|
16508
16604
|
if (typeof windowPreset.perslice !== 'undefined' &&
|
|
16509
16605
|
windowPreset.perslice === true) {
|
|
16510
16606
|
windowPresets[pkey].wl.splice(
|
|
16511
|
-
|
|
16607
|
+
numberOfSlices, 0, rhsPreset.wl[0]);
|
|
16512
16608
|
}
|
|
16513
16609
|
} else {
|
|
16514
16610
|
// if not defined (it should be), store all
|
|
@@ -16547,9 +16643,12 @@ dwv.image.Image = function (geometry, buffer, imageUids) {
|
|
|
16547
16643
|
|
|
16548
16644
|
/**
|
|
16549
16645
|
* Append a frame to the image.
|
|
16646
|
+
*
|
|
16647
|
+
* @param {number} time The frame time value.
|
|
16648
|
+
* @param {dwv.math.Point3D} origin The origin of the frame.
|
|
16550
16649
|
*/
|
|
16551
|
-
this.appendFrame = function () {
|
|
16552
|
-
geometry.appendFrame();
|
|
16650
|
+
this.appendFrame = function (time, origin) {
|
|
16651
|
+
geometry.appendFrame(time, origin);
|
|
16553
16652
|
fireEvent({type: 'appendframe'});
|
|
16554
16653
|
// memory will be updated at the first appendSlice or appendFrameBuffer
|
|
16555
16654
|
};
|
|
@@ -17147,8 +17246,9 @@ dwv.image.ImageFactory.prototype.create = function (
|
|
|
17147
17246
|
// geometry
|
|
17148
17247
|
var origin = new dwv.math.Point3D(
|
|
17149
17248
|
slicePosition[0], slicePosition[1], slicePosition[2]);
|
|
17249
|
+
var time = dicomElements.getTime();
|
|
17150
17250
|
var geometry = new dwv.image.Geometry(
|
|
17151
|
-
origin, size, spacing, orientationMatrix);
|
|
17251
|
+
origin, size, spacing, orientationMatrix, time);
|
|
17152
17252
|
|
|
17153
17253
|
// sop instance UID
|
|
17154
17254
|
var sopInstanceUid = dwv.dicom.cleanString(
|
|
@@ -19074,10 +19174,10 @@ dwv.image.Size.prototype.equals = function (rhs) {
|
|
|
19074
19174
|
* Check that an index is within bounds.
|
|
19075
19175
|
*
|
|
19076
19176
|
* @param {dwv.math.Index} index The index to check.
|
|
19077
|
-
* @param {
|
|
19177
|
+
* @param {Array} dirs Optional list of directions to check.
|
|
19078
19178
|
* @returns {boolean} True if the given coordinates are within bounds.
|
|
19079
19179
|
*/
|
|
19080
|
-
dwv.image.Size.prototype.isInBounds = function (index,
|
|
19180
|
+
dwv.image.Size.prototype.isInBounds = function (index, dirs) {
|
|
19081
19181
|
// check input
|
|
19082
19182
|
if (!index) {
|
|
19083
19183
|
return false;
|
|
@@ -19087,20 +19187,28 @@ dwv.image.Size.prototype.isInBounds = function (index, dir) {
|
|
|
19087
19187
|
if (length !== index.length()) {
|
|
19088
19188
|
return false;
|
|
19089
19189
|
}
|
|
19190
|
+
// create dirs if not there
|
|
19191
|
+
if (typeof dirs === 'undefined') {
|
|
19192
|
+
dirs = [];
|
|
19193
|
+
for (var j = 0; j < length; ++j) {
|
|
19194
|
+
dirs.push(j);
|
|
19195
|
+
}
|
|
19196
|
+
} else {
|
|
19197
|
+
for (var k = 0; k < length; ++k) {
|
|
19198
|
+
if (dirs[k] > length - 1) {
|
|
19199
|
+
throw new Error('Wrong input dir value: ' + dirs[k]);
|
|
19200
|
+
}
|
|
19201
|
+
}
|
|
19202
|
+
}
|
|
19090
19203
|
// check values is 0 <= v < size
|
|
19091
19204
|
var inBound = function (value, size) {
|
|
19092
19205
|
return value >= 0 && value < size;
|
|
19093
19206
|
};
|
|
19094
|
-
|
|
19095
|
-
|
|
19207
|
+
// check
|
|
19208
|
+
for (var i = 0; i < dirs.length; ++i) {
|
|
19209
|
+
if (!inBound(index.get(dirs[i]), this.get(dirs[i]))) {
|
|
19096
19210
|
return false;
|
|
19097
19211
|
}
|
|
19098
|
-
} else {
|
|
19099
|
-
for (var i = 0; i < length; ++i) {
|
|
19100
|
-
if (!inBound(index.get(i), this.get(i))) {
|
|
19101
|
-
return false;
|
|
19102
|
-
}
|
|
19103
|
-
}
|
|
19104
19212
|
}
|
|
19105
19213
|
// seems ok!
|
|
19106
19214
|
return true;
|
|
@@ -19703,7 +19811,11 @@ dwv.image.View = function (image) {
|
|
|
19703
19811
|
this.canSetPosition = function (position) {
|
|
19704
19812
|
var geometry = image.getGeometry();
|
|
19705
19813
|
var index = geometry.worldToIndex(position);
|
|
19706
|
-
|
|
19814
|
+
var dirs = [this.getScrollIndex()];
|
|
19815
|
+
if (index.length() === 4) {
|
|
19816
|
+
dirs.push(3);
|
|
19817
|
+
}
|
|
19818
|
+
return geometry.isIndexInBounds(index, dirs);
|
|
19707
19819
|
};
|
|
19708
19820
|
|
|
19709
19821
|
/**
|
|
@@ -19735,7 +19847,11 @@ dwv.image.View = function (image) {
|
|
|
19735
19847
|
// send invalid event if not in bounds
|
|
19736
19848
|
var geometry = image.getGeometry();
|
|
19737
19849
|
var index = geometry.worldToIndex(position);
|
|
19738
|
-
|
|
19850
|
+
var dirs = [this.getScrollIndex()];
|
|
19851
|
+
if (index.length() === 4) {
|
|
19852
|
+
dirs.push(3);
|
|
19853
|
+
}
|
|
19854
|
+
if (!geometry.isIndexInBounds(index, dirs)) {
|
|
19739
19855
|
if (!silent) {
|
|
19740
19856
|
// fire event with valid: false
|
|
19741
19857
|
fireEvent({
|
|
@@ -19770,7 +19886,11 @@ dwv.image.View = function (image) {
|
|
|
19770
19886
|
var position = geometry.indexToWorld(index);
|
|
19771
19887
|
|
|
19772
19888
|
// check if possible
|
|
19773
|
-
|
|
19889
|
+
var dirs = [this.getScrollIndex()];
|
|
19890
|
+
if (index.length() === 4) {
|
|
19891
|
+
dirs.push(3);
|
|
19892
|
+
}
|
|
19893
|
+
if (!geometry.isIndexInBounds(index, dirs)) {
|
|
19774
19894
|
// do no send invalid positionchange event: avoid empty repaint
|
|
19775
19895
|
return false;
|
|
19776
19896
|
}
|
|
@@ -24422,7 +24542,7 @@ dwv.math.Index = function (values) {
|
|
|
24422
24542
|
* Get the index value at the given array index.
|
|
24423
24543
|
*
|
|
24424
24544
|
* @param {number} i The index to get.
|
|
24425
|
-
* @returns {number} The value.
|
|
24545
|
+
* @returns {number|undefined} The value or undefined if not in range.
|
|
24426
24546
|
*/
|
|
24427
24547
|
this.get = function (i) {
|
|
24428
24548
|
return values[i];
|
|
@@ -32765,6 +32885,13 @@ dwv.tool.Scroll = function (app) {
|
|
|
32765
32885
|
// touch timer ID (created by setTimeout)
|
|
32766
32886
|
var touchTimerID = null;
|
|
32767
32887
|
|
|
32888
|
+
/**
|
|
32889
|
+
* Accumulated wheel event deltaY.
|
|
32890
|
+
*
|
|
32891
|
+
* @type {number}
|
|
32892
|
+
*/
|
|
32893
|
+
var wheelDeltaY = 0;
|
|
32894
|
+
|
|
32768
32895
|
/**
|
|
32769
32896
|
* Handle mouse down event.
|
|
32770
32897
|
*
|
|
@@ -32910,6 +33037,22 @@ dwv.tool.Scroll = function (app) {
|
|
|
32910
33037
|
* @param {object} event The mouse wheel event.
|
|
32911
33038
|
*/
|
|
32912
33039
|
this.wheel = function (event) {
|
|
33040
|
+
// deltaMode (deltaY values on my machine...):
|
|
33041
|
+
// - 0 (DOM_DELTA_PIXEL): chrome, deltaY mouse scroll = 53
|
|
33042
|
+
// - 1 (DOM_DELTA_LINE): firefox, deltaY mouse scroll = 6
|
|
33043
|
+
// - 2 (DOM_DELTA_PAGE): ??
|
|
33044
|
+
// TODO: check scroll event
|
|
33045
|
+
var scrollMin = 52;
|
|
33046
|
+
if (event.deltaMode === 1) {
|
|
33047
|
+
scrollMin = 5.99;
|
|
33048
|
+
}
|
|
33049
|
+
wheelDeltaY += event.deltaY;
|
|
33050
|
+
if (Math.abs(wheelDeltaY) < scrollMin) {
|
|
33051
|
+
return;
|
|
33052
|
+
} else {
|
|
33053
|
+
wheelDeltaY = 0;
|
|
33054
|
+
}
|
|
33055
|
+
|
|
32913
33056
|
var up = false;
|
|
32914
33057
|
if (event.deltaY < 0) {
|
|
32915
33058
|
up = true;
|