dwv 0.31.0-beta.1 → 0.31.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dwv.js +443 -221
- package/dist/dwv.min.js +2 -2
- package/package.json +3 -3
- package/readme.md +9 -21
package/dist/dwv.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! dwv 0.31.0-beta.
|
|
1
|
+
/*! dwv 0.31.0-beta.4 2022-04-21 16:49:31 */
|
|
2
2
|
// Inspired from umdjs
|
|
3
3
|
// See https://github.com/umdjs/umd/blob/master/templates/returnExports.js
|
|
4
4
|
(function (root, factory) {
|
|
@@ -560,10 +560,10 @@ dwv.App = function () {
|
|
|
560
560
|
typeof options.dataViewConfigs === 'undefined') {
|
|
561
561
|
throw new Error('No available data view configuration');
|
|
562
562
|
}
|
|
563
|
-
var configs =
|
|
563
|
+
var configs = [];
|
|
564
564
|
if (typeof options.dataViewConfigs['*'] !== 'undefined') {
|
|
565
565
|
configs = options.dataViewConfigs['*'];
|
|
566
|
-
} else {
|
|
566
|
+
} else if (typeof options.dataViewConfigs[dataIndex] !== 'undefined') {
|
|
567
567
|
configs = options.dataViewConfigs[dataIndex];
|
|
568
568
|
}
|
|
569
569
|
return configs;
|
|
@@ -603,8 +603,11 @@ dwv.App = function () {
|
|
|
603
603
|
}
|
|
604
604
|
// loop on all configs
|
|
605
605
|
var viewConfigs = getViewConfigs(dataIndex);
|
|
606
|
-
if
|
|
607
|
-
|
|
606
|
+
// nothing to do if no view config
|
|
607
|
+
if (viewConfigs.length === 0) {
|
|
608
|
+
dwv.logger.info('Not rendering data: ' + dataIndex +
|
|
609
|
+
' (no data view config)');
|
|
610
|
+
return;
|
|
608
611
|
}
|
|
609
612
|
for (var i = 0; i < viewConfigs.length; ++i) {
|
|
610
613
|
var config = viewConfigs[i];
|
|
@@ -1096,6 +1099,7 @@ dwv.App = function () {
|
|
|
1096
1099
|
|
|
1097
1100
|
// render if first and flag allows
|
|
1098
1101
|
if (event.loadtype === 'image' &&
|
|
1102
|
+
getViewConfigs(event.loadid).length !== 0 &&
|
|
1099
1103
|
isFirstLoadItem && options.viewOnFirstLoadItem) {
|
|
1100
1104
|
self.render(event.loadid);
|
|
1101
1105
|
}
|
|
@@ -1226,18 +1230,19 @@ dwv.App = function () {
|
|
|
1226
1230
|
/**
|
|
1227
1231
|
* Get the data max size for a layer group.
|
|
1228
1232
|
*
|
|
1229
|
-
* @
|
|
1230
|
-
* @param {object} lg The layer group.
|
|
1233
|
+
* @param {object} layerGroup The layer group.
|
|
1231
1234
|
* @returns {object} The max size as {x,y}.
|
|
1232
1235
|
*/
|
|
1233
|
-
function getLayerGroupMaxSize(
|
|
1236
|
+
function getLayerGroupMaxSize(layerGroup) {
|
|
1234
1237
|
var maxSize = {x: 0, y: 0};
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
+
// loop through layer group data
|
|
1239
|
+
var indices = layerGroup.getViewDataIndices();
|
|
1240
|
+
for (var i = 0; i < indices.length; ++i) {
|
|
1241
|
+
var data = dataController.get(indices[i]);
|
|
1242
|
+
var geometry = data.image.getGeometry();
|
|
1238
1243
|
var viewOrient = dwv.gui.getViewOrientation(
|
|
1239
1244
|
geometry,
|
|
1240
|
-
|
|
1245
|
+
layerGroup.getTargetOrientation()
|
|
1241
1246
|
);
|
|
1242
1247
|
var size = geometry.getSize(viewOrient).get2D();
|
|
1243
1248
|
var spacing = geometry.getSpacing(viewOrient).get2D();
|
|
@@ -1307,6 +1312,7 @@ dwv.App = function () {
|
|
|
1307
1312
|
// opacity
|
|
1308
1313
|
var opacity = 1;
|
|
1309
1314
|
// do we have more than one layer
|
|
1315
|
+
// (the layer has not been added to the layer group yet)
|
|
1310
1316
|
if (layerGroup.getNumberOfLayers() !== 0) {
|
|
1311
1317
|
opacity = 0.5;
|
|
1312
1318
|
// set color map if non was provided
|
|
@@ -1323,19 +1329,6 @@ dwv.App = function () {
|
|
|
1323
1329
|
viewLayer.initialise(size2D, spacing2D, dataIndex);
|
|
1324
1330
|
viewLayer.setOpacity(opacity);
|
|
1325
1331
|
|
|
1326
|
-
// compensate origin difference
|
|
1327
|
-
var diff = null;
|
|
1328
|
-
if (dataIndex !== 0) {
|
|
1329
|
-
// offset from the top, use first origin
|
|
1330
|
-
var data0 = dataController.get(0);
|
|
1331
|
-
var origin0 = data0.image.getGeometry().getOrigins()[0];
|
|
1332
|
-
var origin1 = imageGeometry.getOrigins()[0];
|
|
1333
|
-
diff = origin0.minus(origin1);
|
|
1334
|
-
// TODO: check why -z...
|
|
1335
|
-
viewLayer.setBaseOffset(new dwv.math.Vector3D(
|
|
1336
|
-
diff.getX(), diff.getY(), -1 * diff.getZ()));
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
1332
|
// listen to image changes
|
|
1340
1333
|
dataController.addEventListener('imagechange', viewLayer.onimagechange);
|
|
1341
1334
|
|
|
@@ -1355,11 +1348,6 @@ dwv.App = function () {
|
|
|
1355
1348
|
vc.getCurrentPosition().getValues()
|
|
1356
1349
|
];
|
|
1357
1350
|
layerGroup.updateLayersToPositionChange({value: value});
|
|
1358
|
-
|
|
1359
|
-
// compensate origin difference
|
|
1360
|
-
if (dataIndex !== 0) {
|
|
1361
|
-
dl.setBaseOffset(diff);
|
|
1362
|
-
}
|
|
1363
1351
|
}
|
|
1364
1352
|
|
|
1365
1353
|
// fit to the maximum size
|
|
@@ -2616,9 +2604,15 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2616
2604
|
// third dimension player ID (created by setInterval)
|
|
2617
2605
|
var playerID = null;
|
|
2618
2606
|
|
|
2607
|
+
// check view
|
|
2608
|
+
if (typeof view.getImage() === 'undefined') {
|
|
2609
|
+
throw new Error('View does not have an image, cannot setup controller');
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2619
2612
|
// setup the plane helper
|
|
2620
2613
|
var planeHelper = new dwv.image.PlaneHelper(
|
|
2621
|
-
view.getImage().getGeometry().
|
|
2614
|
+
view.getImage().getGeometry().getRealSpacing(),
|
|
2615
|
+
view.getImage().getGeometry().getOrientation(),
|
|
2622
2616
|
view.getOrientation()
|
|
2623
2617
|
);
|
|
2624
2618
|
|
|
@@ -2743,6 +2737,10 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2743
2737
|
return view.getCurrentIndex().get(view.getScrollIndex());
|
|
2744
2738
|
};
|
|
2745
2739
|
|
|
2740
|
+
this.getOrigin = function (position) {
|
|
2741
|
+
return view.getOrigin(position);
|
|
2742
|
+
};
|
|
2743
|
+
|
|
2746
2744
|
/**
|
|
2747
2745
|
* Get the current scroll position value.
|
|
2748
2746
|
*
|
|
@@ -2891,6 +2889,10 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2891
2889
|
return view.getImage().getGeometry().getSize();
|
|
2892
2890
|
};
|
|
2893
2891
|
|
|
2892
|
+
this.canSetPosition = function (position) {
|
|
2893
|
+
return view.canSetPosition(position);
|
|
2894
|
+
};
|
|
2895
|
+
|
|
2894
2896
|
/**
|
|
2895
2897
|
* Set the current position.
|
|
2896
2898
|
*
|
|
@@ -2910,8 +2912,18 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2910
2912
|
* @returns {boolean} False if not in bounds.
|
|
2911
2913
|
*/
|
|
2912
2914
|
this.setCurrentPosition2D = function (x, y) {
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
+
// keep third direction
|
|
2916
|
+
var k = this.getCurrentScrollIndexValue();
|
|
2917
|
+
var planePoint = new dwv.math.Point3D(x, y, k);
|
|
2918
|
+
// de-orient
|
|
2919
|
+
var point = planeHelper.getImageOrientedVector3D(planePoint);
|
|
2920
|
+
// ~indexToWorld to not loose precision
|
|
2921
|
+
var geometry = view.getImage().getGeometry();
|
|
2922
|
+
var point3D = geometry.pointToWorld(point);
|
|
2923
|
+
// merge with current position to keep extra dimensions
|
|
2924
|
+
var position = this.getCurrentPosition().mergeWith3D(point3D);
|
|
2925
|
+
|
|
2926
|
+
return view.setCurrentPosition(position);
|
|
2915
2927
|
};
|
|
2916
2928
|
|
|
2917
2929
|
/**
|
|
@@ -2925,25 +2937,6 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2925
2937
|
return view.setCurrentIndex(index, silent);
|
|
2926
2938
|
};
|
|
2927
2939
|
|
|
2928
|
-
/**
|
|
2929
|
-
* Get a 3D position from a plane 2D position.
|
|
2930
|
-
*
|
|
2931
|
-
* @param {dwv.math.Point2D} point2D The 2D position as {x,y}.
|
|
2932
|
-
* @returns {dwv.math.Point} The 3D point.
|
|
2933
|
-
*/
|
|
2934
|
-
this.getPositionFromPlanePoint = function (point2D) {
|
|
2935
|
-
// keep third direction
|
|
2936
|
-
var k = this.getCurrentScrollIndexValue();
|
|
2937
|
-
var planePoint = new dwv.math.Point3D(point2D.x, point2D.y, k);
|
|
2938
|
-
// de-orient
|
|
2939
|
-
var point = planeHelper.getDeOrientedVector3D(planePoint);
|
|
2940
|
-
// ~indexToWorld to not loose precision
|
|
2941
|
-
var geometry = view.getImage().getGeometry();
|
|
2942
|
-
var point3D = geometry.pointToWorld(point);
|
|
2943
|
-
// merge with current position to keep extra dimensions
|
|
2944
|
-
return this.getCurrentPosition().mergeWith3D(point3D);
|
|
2945
|
-
};
|
|
2946
|
-
|
|
2947
2940
|
/**
|
|
2948
2941
|
* Get a plane 3D position from a plane 2D position: does not compensate
|
|
2949
2942
|
* for the image origin. Needed for setting the scale center...
|
|
@@ -2959,7 +2952,7 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2959
2952
|
var point = planeHelper.getDeOrientedVector3D(planePoint);
|
|
2960
2953
|
// ~indexToWorld to not loose precision
|
|
2961
2954
|
var geometry = view.getImage().getGeometry();
|
|
2962
|
-
var spacing = geometry.
|
|
2955
|
+
var spacing = geometry.getRealSpacing();
|
|
2963
2956
|
return new dwv.math.Point3D(
|
|
2964
2957
|
point.getX() * spacing.get(0),
|
|
2965
2958
|
point.getY() * spacing.get(1),
|
|
@@ -4503,7 +4496,7 @@ dwv.dicom = dwv.dicom || {};
|
|
|
4503
4496
|
* @returns {string} The version of the library.
|
|
4504
4497
|
*/
|
|
4505
4498
|
dwv.getVersion = function () {
|
|
4506
|
-
return '0.31.0-beta.
|
|
4499
|
+
return '0.31.0-beta.4';
|
|
4507
4500
|
};
|
|
4508
4501
|
|
|
4509
4502
|
/**
|
|
@@ -5970,11 +5963,15 @@ dwv.dicom = dwv.dicom || {};
|
|
|
5970
5963
|
* @returns {string} The dwv UID prefix.
|
|
5971
5964
|
*/
|
|
5972
5965
|
dwv.dicom.getDwvUIDPrefix = function () {
|
|
5973
|
-
return '1.2.826.0.1.3680043.9.7278.1
|
|
5966
|
+
return '1.2.826.0.1.3680043.9.7278.1';
|
|
5974
5967
|
};
|
|
5975
5968
|
|
|
5969
|
+
// local generated uid counter
|
|
5970
|
+
var _uidCount = 0;
|
|
5971
|
+
|
|
5976
5972
|
/**
|
|
5977
5973
|
* Get a UID for a DICOM tag.
|
|
5974
|
+
* Note: Use https://github.com/uuidjs/uuid?
|
|
5978
5975
|
*
|
|
5979
5976
|
* @see http://dicom.nema.org/dicom/2013/output/chtml/part05/chapter_9.html
|
|
5980
5977
|
* @see http://dicomiseasy.blogspot.com/2011/12/chapter-4-dicom-objects-in-chapter-3.html
|
|
@@ -5983,17 +5980,34 @@ dwv.dicom.getDwvUIDPrefix = function () {
|
|
|
5983
5980
|
* @returns {string} The corresponding UID.
|
|
5984
5981
|
*/
|
|
5985
5982
|
dwv.dicom.getUID = function (tagName) {
|
|
5986
|
-
var
|
|
5983
|
+
var prefix = dwv.dicom.getDwvUIDPrefix() + '.';
|
|
5984
|
+
var uid = '';
|
|
5987
5985
|
if (tagName === 'ImplementationClassUID') {
|
|
5988
|
-
uid
|
|
5989
|
-
} else if (tagName === 'SOPInstanceUID') {
|
|
5990
|
-
for (var i = 0; i < tagName.length; ++i) {
|
|
5991
|
-
uid += tagName.charCodeAt(i);
|
|
5992
|
-
}
|
|
5993
|
-
// add date (only numbers)
|
|
5994
|
-
uid += '.' + (new Date()).toISOString().replace(/\D/g, '');
|
|
5986
|
+
uid = prefix + dwv.getVersion();
|
|
5995
5987
|
} else {
|
|
5996
|
-
|
|
5988
|
+
// date (only numbers), do not keep milliseconds
|
|
5989
|
+
var date = (new Date()).toISOString().replace(/\D/g, '');
|
|
5990
|
+
var datePart = '.' + date.substring(0, 14);
|
|
5991
|
+
// count
|
|
5992
|
+
_uidCount += 1;
|
|
5993
|
+
var countPart = '.' + _uidCount;
|
|
5994
|
+
|
|
5995
|
+
// uid = prefix . tag . date . count
|
|
5996
|
+
uid = prefix;
|
|
5997
|
+
|
|
5998
|
+
// limit tag part to not exceed 64 length
|
|
5999
|
+
var nonTagLength = prefix.length + countPart.length + datePart.length;
|
|
6000
|
+
var leni = Math.min(tagName.length, 64 - nonTagLength);
|
|
6001
|
+
if (leni > 1) {
|
|
6002
|
+
var tagNumber = '';
|
|
6003
|
+
for (var i = 0; i < leni; ++i) {
|
|
6004
|
+
tagNumber += tagName.charCodeAt(i);
|
|
6005
|
+
}
|
|
6006
|
+
uid += tagNumber.substring(0, leni);
|
|
6007
|
+
}
|
|
6008
|
+
|
|
6009
|
+
// finish
|
|
6010
|
+
uid += datePart + countPart;
|
|
5997
6011
|
}
|
|
5998
6012
|
return uid;
|
|
5999
6013
|
};
|
|
@@ -6015,10 +6029,24 @@ dwv.dicom.isEven = function (number) {
|
|
|
6015
6029
|
* @returns {boolean} True if the VR is a non string one.
|
|
6016
6030
|
*/
|
|
6017
6031
|
dwv.dicom.isNonStringVr = function (vr) {
|
|
6018
|
-
return vr === 'UN' ||
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
6032
|
+
return vr === 'UN' ||
|
|
6033
|
+
vr === 'SQ' ||
|
|
6034
|
+
vr === 'AT' ||
|
|
6035
|
+
dwv.dicom.isTypedArrayVr(vr);
|
|
6036
|
+
};
|
|
6037
|
+
|
|
6038
|
+
/**
|
|
6039
|
+
* Is the input VR a VR that stores data in a typed array.
|
|
6040
|
+
*
|
|
6041
|
+
* @param {string} vr The element VR.
|
|
6042
|
+
* @returns {boolean} True if the VR is a typed array one.
|
|
6043
|
+
*/
|
|
6044
|
+
dwv.dicom.isTypedArrayVr = function (vr) {
|
|
6045
|
+
return vr === 'OB' || vr === 'OW' ||
|
|
6046
|
+
vr === 'OF' || vr === 'OD' ||
|
|
6047
|
+
vr === 'US' || vr === 'SS' ||
|
|
6048
|
+
vr === 'UL' || vr === 'SL' ||
|
|
6049
|
+
vr === 'FL' || vr === 'FD';
|
|
6022
6050
|
};
|
|
6023
6051
|
|
|
6024
6052
|
/**
|
|
@@ -6815,43 +6843,55 @@ dwv.dicom.setElementValue = function (element, value, isImplicit) {
|
|
|
6815
6843
|
// set the value and calculate size
|
|
6816
6844
|
size = 0;
|
|
6817
6845
|
var paddedValue = dwv.dicom.padElementValue(element, value);
|
|
6818
|
-
if (
|
|
6846
|
+
if (element.vr === 'AT') {
|
|
6819
6847
|
element.value = paddedValue;
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6848
|
+
size = 4;
|
|
6849
|
+
} else if (dwv.dicom.isTypedArrayVr(element.vr)) {
|
|
6850
|
+
// convert non array (number) value to array
|
|
6851
|
+
if (typeof value.length === 'undefined') {
|
|
6852
|
+
element.value = [paddedValue];
|
|
6853
|
+
} else {
|
|
6854
|
+
element.value = paddedValue;
|
|
6855
|
+
}
|
|
6856
|
+
size = element.value.length;
|
|
6857
|
+
|
|
6858
|
+
// convert size to bytes
|
|
6859
|
+
if (element.vr === 'US' || element.vr === 'OW') {
|
|
6860
|
+
size *= Uint16Array.BYTES_PER_ELEMENT;
|
|
6861
|
+
} else if (element.vr === 'SS') {
|
|
6862
|
+
size *= Int16Array.BYTES_PER_ELEMENT;
|
|
6863
|
+
} else if (element.vr === 'UL') {
|
|
6864
|
+
size *= Uint32Array.BYTES_PER_ELEMENT;
|
|
6865
|
+
} else if (element.vr === 'SL') {
|
|
6866
|
+
size *= Int32Array.BYTES_PER_ELEMENT;
|
|
6867
|
+
} else if (element.vr === 'FL') {
|
|
6868
|
+
size *= Float32Array.BYTES_PER_ELEMENT;
|
|
6869
|
+
} else if (element.vr === 'FD') {
|
|
6870
|
+
size *= Float64Array.BYTES_PER_ELEMENT;
|
|
6827
6871
|
}
|
|
6828
6872
|
} else {
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6873
|
+
if (value instanceof Array) {
|
|
6874
|
+
element.value = paddedValue;
|
|
6875
|
+
for (var k = 0; k < paddedValue.length; ++k) {
|
|
6876
|
+
// separator
|
|
6877
|
+
if (k !== 0) {
|
|
6878
|
+
size += 1;
|
|
6879
|
+
}
|
|
6880
|
+
// value
|
|
6881
|
+
size += paddedValue[k].toString().length;
|
|
6882
|
+
}
|
|
6833
6883
|
} else {
|
|
6834
|
-
|
|
6835
|
-
|
|
6884
|
+
element.value = [paddedValue];
|
|
6885
|
+
if (typeof paddedValue !== 'undefined' &&
|
|
6886
|
+
typeof paddedValue.length !== 'undefined') {
|
|
6887
|
+
size = paddedValue.length;
|
|
6888
|
+
} else {
|
|
6889
|
+
// numbers
|
|
6890
|
+
size = 1;
|
|
6891
|
+
}
|
|
6836
6892
|
}
|
|
6837
6893
|
}
|
|
6838
6894
|
|
|
6839
|
-
// convert size to bytes
|
|
6840
|
-
if (element.vr === 'US' || element.vr === 'OW') {
|
|
6841
|
-
size *= Uint16Array.BYTES_PER_ELEMENT;
|
|
6842
|
-
} else if (element.vr === 'SS') {
|
|
6843
|
-
size *= Int16Array.BYTES_PER_ELEMENT;
|
|
6844
|
-
} else if (element.vr === 'UL') {
|
|
6845
|
-
size *= Uint32Array.BYTES_PER_ELEMENT;
|
|
6846
|
-
} else if (element.vr === 'SL') {
|
|
6847
|
-
size *= Int32Array.BYTES_PER_ELEMENT;
|
|
6848
|
-
} else if (element.vr === 'FL') {
|
|
6849
|
-
size *= Float32Array.BYTES_PER_ELEMENT;
|
|
6850
|
-
} else if (element.vr === 'FD') {
|
|
6851
|
-
size *= Float64Array.BYTES_PER_ELEMENT;
|
|
6852
|
-
} else {
|
|
6853
|
-
size *= Uint8Array.BYTES_PER_ELEMENT;
|
|
6854
|
-
}
|
|
6855
6895
|
element.vl = size;
|
|
6856
6896
|
}
|
|
6857
6897
|
|
|
@@ -11395,21 +11435,31 @@ dwv.gui.DrawLayer = function (containerDiv) {
|
|
|
11395
11435
|
};
|
|
11396
11436
|
|
|
11397
11437
|
/**
|
|
11398
|
-
* Set the base layer offset.
|
|
11438
|
+
* Set the base layer offset. Updates the layer offset.
|
|
11399
11439
|
*
|
|
11400
|
-
* @param {
|
|
11440
|
+
* @param {dwv.math.Vector3D} scrollOffset The scroll offset vector.
|
|
11441
|
+
* @param {dwv.math.Vector3D} planeOffset The plane offset vector.
|
|
11442
|
+
* @returns {boolean} True if the offset was updated.
|
|
11401
11443
|
*/
|
|
11402
|
-
this.setBaseOffset = function (
|
|
11403
|
-
|
|
11404
|
-
|
|
11405
|
-
|
|
11406
|
-
|
|
11407
|
-
|
|
11408
|
-
// reset offset
|
|
11409
|
-
konvaStage.offset({
|
|
11410
|
-
x: baseOffset.x,
|
|
11411
|
-
y: baseOffset.y
|
|
11444
|
+
this.setBaseOffset = function (scrollOffset, planeOffset) {
|
|
11445
|
+
var scrollIndex = planeHelper.getNativeScrollIndex();
|
|
11446
|
+
var newOffset = planeHelper.getPlaneOffsetFromOffset3D({
|
|
11447
|
+
x: scrollIndex === 0 ? scrollOffset.getX() : planeOffset.getX(),
|
|
11448
|
+
y: scrollIndex === 1 ? scrollOffset.getY() : planeOffset.getY(),
|
|
11449
|
+
z: scrollIndex === 2 ? scrollOffset.getZ() : planeOffset.getZ(),
|
|
11412
11450
|
});
|
|
11451
|
+
var needsUpdate = baseOffset.x !== newOffset.x ||
|
|
11452
|
+
baseOffset.y !== newOffset.y;
|
|
11453
|
+
// reset offset if needed
|
|
11454
|
+
if (needsUpdate) {
|
|
11455
|
+
var offset = konvaStage.offset();
|
|
11456
|
+
konvaStage.offset({
|
|
11457
|
+
x: offset.x - baseOffset.x + newOffset.x,
|
|
11458
|
+
y: offset.y - baseOffset.y + newOffset.y
|
|
11459
|
+
});
|
|
11460
|
+
baseOffset = newOffset;
|
|
11461
|
+
}
|
|
11462
|
+
return needsUpdate;
|
|
11413
11463
|
};
|
|
11414
11464
|
|
|
11415
11465
|
/**
|
|
@@ -11525,10 +11575,13 @@ dwv.gui.DrawLayer = function (containerDiv) {
|
|
|
11525
11575
|
*
|
|
11526
11576
|
* @param {dwv.math.Point} position The new position.
|
|
11527
11577
|
* @param {dwv.math.Index} index The new index.
|
|
11578
|
+
* @returns {boolean} True if the position was updated.
|
|
11528
11579
|
*/
|
|
11529
11580
|
this.setCurrentPosition = function (position, index) {
|
|
11530
11581
|
this.getDrawController().activateDrawLayer(
|
|
11531
11582
|
index, planeHelper.getScrollIndex());
|
|
11583
|
+
// TODO: add check
|
|
11584
|
+
return true;
|
|
11532
11585
|
};
|
|
11533
11586
|
|
|
11534
11587
|
/**
|
|
@@ -12032,6 +12085,21 @@ dwv.gui.LayerGroup = function (containerDiv, groupId) {
|
|
|
12032
12085
|
return res;
|
|
12033
12086
|
};
|
|
12034
12087
|
|
|
12088
|
+
/**
|
|
12089
|
+
* Get the view layers data indices.
|
|
12090
|
+
*
|
|
12091
|
+
* @returns {Array} The list of indices.
|
|
12092
|
+
*/
|
|
12093
|
+
this.getViewDataIndices = function () {
|
|
12094
|
+
var res = [];
|
|
12095
|
+
for (var i = 0; i < layers.length; ++i) {
|
|
12096
|
+
if (layers[i] instanceof dwv.gui.ViewLayer) {
|
|
12097
|
+
res.push(layers[i].getDataIndex());
|
|
12098
|
+
}
|
|
12099
|
+
}
|
|
12100
|
+
return res;
|
|
12101
|
+
};
|
|
12102
|
+
|
|
12035
12103
|
/**
|
|
12036
12104
|
* Get the active draw layer.
|
|
12037
12105
|
*
|
|
@@ -12215,10 +12283,56 @@ dwv.gui.LayerGroup = function (containerDiv, groupId) {
|
|
|
12215
12283
|
|
|
12216
12284
|
var index = new dwv.math.Index(event.value[0]);
|
|
12217
12285
|
var position = new dwv.math.Point(event.value[1]);
|
|
12286
|
+
// origin of the first view layer
|
|
12287
|
+
var baseOrigin0 = null;
|
|
12288
|
+
var baseOrigin = null;
|
|
12218
12289
|
// update position for all layers except the source one
|
|
12219
12290
|
for (var i = 0; i < layers.length; ++i) {
|
|
12291
|
+
|
|
12292
|
+
// update base offset (does not trigger redraw)
|
|
12293
|
+
// TODO check draw layers update
|
|
12294
|
+
var hasSetOffset = false;
|
|
12295
|
+
if (layers[i] instanceof dwv.gui.ViewLayer) {
|
|
12296
|
+
var vc = layers[i].getViewController();
|
|
12297
|
+
var origin0 = vc.getOrigin();
|
|
12298
|
+
var origin = vc.getOrigin(position);
|
|
12299
|
+
if (!baseOrigin) {
|
|
12300
|
+
baseOrigin0 = origin0;
|
|
12301
|
+
baseOrigin = origin;
|
|
12302
|
+
} else {
|
|
12303
|
+
if (vc.canSetPosition(position)) {
|
|
12304
|
+
if (typeof origin0 === 'undefined') {
|
|
12305
|
+
console.log('no origin0', layers[i].getId());
|
|
12306
|
+
}
|
|
12307
|
+
if (typeof origin === 'undefined') {
|
|
12308
|
+
console.log('no origin', layers[i].getId());
|
|
12309
|
+
}
|
|
12310
|
+
|
|
12311
|
+
// TODO: compensate for possible different orientation
|
|
12312
|
+
// TODO: check why -z...
|
|
12313
|
+
|
|
12314
|
+
var scrollDiff = baseOrigin0.minus(origin0);
|
|
12315
|
+
var scrollOffset = new dwv.math.Vector3D(
|
|
12316
|
+
scrollDiff.getX(), scrollDiff.getY(), -1 * scrollDiff.getZ());
|
|
12317
|
+
|
|
12318
|
+
var planeDiff = baseOrigin.minus(origin);
|
|
12319
|
+
var planeOffset = new dwv.math.Vector3D(
|
|
12320
|
+
planeDiff.getX(), planeDiff.getY(), -1 * planeDiff.getZ());
|
|
12321
|
+
|
|
12322
|
+
hasSetOffset = layers[i].setBaseOffset(scrollOffset, planeOffset);
|
|
12323
|
+
}
|
|
12324
|
+
}
|
|
12325
|
+
}
|
|
12326
|
+
|
|
12327
|
+
// update position (triggers redraw)
|
|
12328
|
+
var hasSetPos = false;
|
|
12220
12329
|
if (layers[i].getId() !== event.srclayerid) {
|
|
12221
|
-
layers[i].setCurrentPosition(position, index);
|
|
12330
|
+
hasSetPos = layers[i].setCurrentPosition(position, index);
|
|
12331
|
+
}
|
|
12332
|
+
|
|
12333
|
+
// force redraw if needed
|
|
12334
|
+
if (!hasSetPos && hasSetOffset) {
|
|
12335
|
+
layers[i].draw();
|
|
12222
12336
|
}
|
|
12223
12337
|
}
|
|
12224
12338
|
|
|
@@ -13306,19 +13420,31 @@ dwv.gui.ViewLayer = function (containerDiv) {
|
|
|
13306
13420
|
};
|
|
13307
13421
|
|
|
13308
13422
|
/**
|
|
13309
|
-
* Set the base layer offset.
|
|
13423
|
+
* Set the base layer offset. Updates the layer offset.
|
|
13310
13424
|
*
|
|
13311
|
-
* @param {
|
|
13425
|
+
* @param {dwv.math.Vector3D} scrollOffset The scroll offset vector.
|
|
13426
|
+
* @param {dwv.math.Vector3D} planeOffset The plane offset vector.
|
|
13427
|
+
* @returns {boolean} True if the offset was updated.
|
|
13312
13428
|
*/
|
|
13313
|
-
this.setBaseOffset = function (
|
|
13429
|
+
this.setBaseOffset = function (scrollOffset, planeOffset) {
|
|
13314
13430
|
var helper = viewController.getPlaneHelper();
|
|
13315
|
-
|
|
13316
|
-
|
|
13317
|
-
|
|
13318
|
-
|
|
13431
|
+
var scrollIndex = helper.getNativeScrollIndex();
|
|
13432
|
+
var newOffset = helper.getPlaneOffsetFromOffset3D({
|
|
13433
|
+
x: scrollIndex === 0 ? scrollOffset.getX() : planeOffset.getX(),
|
|
13434
|
+
y: scrollIndex === 1 ? scrollOffset.getY() : planeOffset.getY(),
|
|
13435
|
+
z: scrollIndex === 2 ? scrollOffset.getZ() : planeOffset.getZ(),
|
|
13319
13436
|
});
|
|
13320
|
-
|
|
13321
|
-
|
|
13437
|
+
var needsUpdate = baseOffset.x !== newOffset.x ||
|
|
13438
|
+
baseOffset.y !== newOffset.y;
|
|
13439
|
+
// reset offset if needed
|
|
13440
|
+
if (needsUpdate) {
|
|
13441
|
+
offset = {
|
|
13442
|
+
x: offset.x - baseOffset.x + newOffset.x,
|
|
13443
|
+
y: offset.y - baseOffset.y + newOffset.y
|
|
13444
|
+
};
|
|
13445
|
+
baseOffset = newOffset;
|
|
13446
|
+
}
|
|
13447
|
+
return needsUpdate;
|
|
13322
13448
|
};
|
|
13323
13449
|
|
|
13324
13450
|
/**
|
|
@@ -13702,9 +13828,10 @@ dwv.gui.ViewLayer = function (containerDiv) {
|
|
|
13702
13828
|
*
|
|
13703
13829
|
* @param {dwv.math.Point} position The new position.
|
|
13704
13830
|
* @param {dwv.math.Index} _index The new index.
|
|
13831
|
+
* @returns {boolean} True if the position was updated.
|
|
13705
13832
|
*/
|
|
13706
13833
|
this.setCurrentPosition = function (position, _index) {
|
|
13707
|
-
viewController.setCurrentPosition(position);
|
|
13834
|
+
return viewController.setCurrentPosition(position);
|
|
13708
13835
|
};
|
|
13709
13836
|
|
|
13710
13837
|
/**
|
|
@@ -15065,7 +15192,7 @@ dwv.image.Geometry = function (origin, size, spacing, orientation) {
|
|
|
15065
15192
|
|
|
15066
15193
|
/**
|
|
15067
15194
|
* Get the object spacing.
|
|
15068
|
-
* Warning: the
|
|
15195
|
+
* Warning: the spacing comes as stored in DICOM, meaning that it could
|
|
15069
15196
|
* be oriented.
|
|
15070
15197
|
*
|
|
15071
15198
|
* @param {dwv.math.Matrix33} viewOrientation The view orientation (optional)
|
|
@@ -15093,6 +15220,15 @@ dwv.image.Geometry = function (origin, size, spacing, orientation) {
|
|
|
15093
15220
|
return res;
|
|
15094
15221
|
};
|
|
15095
15222
|
|
|
15223
|
+
/**
|
|
15224
|
+
* Get the image spacing in real world.
|
|
15225
|
+
*
|
|
15226
|
+
* @returns {dwv.image.Spacing} The object spacing.
|
|
15227
|
+
*/
|
|
15228
|
+
this.getRealSpacing = function () {
|
|
15229
|
+
return this.getSpacing(orientation.getInverse().asOneAndZeros());
|
|
15230
|
+
};
|
|
15231
|
+
|
|
15096
15232
|
/**
|
|
15097
15233
|
* Get the object orientation.
|
|
15098
15234
|
*
|
|
@@ -15214,8 +15350,16 @@ dwv.image.Geometry.prototype.equals = function (rhs) {
|
|
|
15214
15350
|
* @returns {boolean} True if the given coordinates are within bounds.
|
|
15215
15351
|
*/
|
|
15216
15352
|
dwv.image.Geometry.prototype.isInBounds = function (point) {
|
|
15217
|
-
|
|
15218
|
-
|
|
15353
|
+
return this.isIndexInBounds(this.worldToIndex(point));
|
|
15354
|
+
};
|
|
15355
|
+
|
|
15356
|
+
/**
|
|
15357
|
+
* Check that a index is within bounds.
|
|
15358
|
+
*
|
|
15359
|
+
* @param {dwv.math.Index} index The index to check.
|
|
15360
|
+
* @returns {boolean} True if the given coordinates are within bounds.
|
|
15361
|
+
*/
|
|
15362
|
+
dwv.image.Geometry.prototype.isIndexInBounds = function (index) {
|
|
15219
15363
|
return this.getSize().isInBounds(index);
|
|
15220
15364
|
};
|
|
15221
15365
|
|
|
@@ -15296,6 +15440,7 @@ dwv.image.Geometry.prototype.pointToWorld = function (point) {
|
|
|
15296
15440
|
dwv.image.Geometry.prototype.worldToIndex = function (point) {
|
|
15297
15441
|
// compensate for origin
|
|
15298
15442
|
// (origin is not oriented, compensate before orientation)
|
|
15443
|
+
// TODO: use slice origin...
|
|
15299
15444
|
var origin = this.getOrigin();
|
|
15300
15445
|
var point3D = new dwv.math.Point3D(
|
|
15301
15446
|
point.get(0) - origin.getX(),
|
|
@@ -17920,9 +18065,17 @@ dwv.image = dwv.image || {};
|
|
|
17920
18065
|
*
|
|
17921
18066
|
* @class
|
|
17922
18067
|
* @param {dwv.image.Spacing} spacing The spacing.
|
|
17923
|
-
* @param {dwv.math.Matrix}
|
|
18068
|
+
* @param {dwv.math.Matrix} imageOrientation The image oientation.
|
|
18069
|
+
* @param {dwv.math.Matrix} viewOrientation The view orientation.
|
|
17924
18070
|
*/
|
|
17925
|
-
dwv.image.PlaneHelper = function (spacing,
|
|
18071
|
+
dwv.image.PlaneHelper = function (spacing, imageOrientation, viewOrientation) {
|
|
18072
|
+
|
|
18073
|
+
// [Img] -- Oi --> [Real] <-- Ot -- [Target]
|
|
18074
|
+
// Pi = (Oi)-1 * Ot * Pt = Ov * Pt
|
|
18075
|
+
// Ov = (Oi)-1 * Ot
|
|
18076
|
+
// Ot = Oi * Ov
|
|
18077
|
+
var targetOrientation =
|
|
18078
|
+
imageOrientation.asOneAndZeros().multiply(viewOrientation);
|
|
17926
18079
|
|
|
17927
18080
|
/**
|
|
17928
18081
|
* Get a 3D offset from a plane one.
|
|
@@ -17943,7 +18096,7 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
17943
18096
|
/**
|
|
17944
18097
|
* Get a plane offset from a 3D one.
|
|
17945
18098
|
*
|
|
17946
|
-
* @param {
|
|
18099
|
+
* @param {object} offset3D The 3D offset as {x,y,z}.
|
|
17947
18100
|
* @returns {object} The plane offset as {x,y}.
|
|
17948
18101
|
*/
|
|
17949
18102
|
this.getPlaneOffsetFromOffset3D = function (offset3D) {
|
|
@@ -17992,10 +18145,8 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
17992
18145
|
*/
|
|
17993
18146
|
this.getOrientedVector3D = function (vector) {
|
|
17994
18147
|
var planeVector = vector;
|
|
17995
|
-
if (typeof
|
|
17996
|
-
|
|
17997
|
-
// vector = orientation * planeVector
|
|
17998
|
-
planeVector = orientation.getInverse().getAbs().multiplyVector3D(vector);
|
|
18148
|
+
if (typeof targetOrientation !== 'undefined') {
|
|
18149
|
+
planeVector = targetOrientation.getInverse().multiplyVector3D(vector);
|
|
17999
18150
|
}
|
|
18000
18151
|
return planeVector;
|
|
18001
18152
|
};
|
|
@@ -18008,10 +18159,10 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18008
18159
|
*/
|
|
18009
18160
|
this.getOrientedIndex = function (index) {
|
|
18010
18161
|
var planeIndex = index;
|
|
18011
|
-
if (typeof
|
|
18162
|
+
if (typeof viewOrientation !== 'undefined') {
|
|
18012
18163
|
// abs? otherwise negative index...
|
|
18013
|
-
// vector =
|
|
18014
|
-
planeIndex =
|
|
18164
|
+
// vector = viewOrientation * planeVector
|
|
18165
|
+
planeIndex = viewOrientation.getInverse().getAbs().multiplyIndex3D(index);
|
|
18015
18166
|
}
|
|
18016
18167
|
return planeIndex;
|
|
18017
18168
|
};
|
|
@@ -18024,11 +18175,11 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18024
18175
|
*/
|
|
18025
18176
|
this.getOrientedPoint = function (point) {
|
|
18026
18177
|
var planePoint = point;
|
|
18027
|
-
if (typeof
|
|
18178
|
+
if (typeof viewOrientation !== 'undefined') {
|
|
18028
18179
|
// abs? otherwise negative index...
|
|
18029
|
-
// vector =
|
|
18180
|
+
// vector = viewOrientation * planeVector
|
|
18030
18181
|
var point3D =
|
|
18031
|
-
|
|
18182
|
+
viewOrientation.getInverse().getAbs().multiplyPoint3D(point.get3D());
|
|
18032
18183
|
planePoint = point.mergeWith3D(point3D);
|
|
18033
18184
|
}
|
|
18034
18185
|
return planePoint;
|
|
@@ -18042,16 +18193,30 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18042
18193
|
*/
|
|
18043
18194
|
this.getDeOrientedVector3D = function (planeVector) {
|
|
18044
18195
|
var vector = planeVector;
|
|
18045
|
-
if (typeof
|
|
18196
|
+
if (typeof targetOrientation !== 'undefined') {
|
|
18197
|
+
vector = targetOrientation.multiplyVector3D(planeVector);
|
|
18198
|
+
}
|
|
18199
|
+
return vector;
|
|
18200
|
+
};
|
|
18201
|
+
|
|
18202
|
+
/**
|
|
18203
|
+
* Get the image oriented values for an input vector.
|
|
18204
|
+
*
|
|
18205
|
+
* @param {dwv.math.Vector3D} planeVector The input vector.
|
|
18206
|
+
* @returns {dwv.math.Vector3D} The de-orienteded vector.
|
|
18207
|
+
*/
|
|
18208
|
+
this.getImageOrientedVector3D = function (planeVector) {
|
|
18209
|
+
var vector = planeVector;
|
|
18210
|
+
if (typeof viewOrientation !== 'undefined') {
|
|
18046
18211
|
// abs? otherwise negative index...
|
|
18047
|
-
// vector =
|
|
18048
|
-
vector =
|
|
18212
|
+
// vector = viewOrientation * planePoint
|
|
18213
|
+
vector = viewOrientation.getAbs().multiplyVector3D(planeVector);
|
|
18049
18214
|
}
|
|
18050
18215
|
return vector;
|
|
18051
18216
|
};
|
|
18052
18217
|
|
|
18053
18218
|
/**
|
|
18054
|
-
* Reorder values to follow orientation.
|
|
18219
|
+
* Reorder values to follow view orientation.
|
|
18055
18220
|
*
|
|
18056
18221
|
* @param {object} values Values as {x,y,z}.
|
|
18057
18222
|
* @returns {object} Reoriented values as {x,y,z}.
|
|
@@ -18063,7 +18228,7 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18063
18228
|
values.y,
|
|
18064
18229
|
values.z
|
|
18065
18230
|
],
|
|
18066
|
-
|
|
18231
|
+
viewOrientation);
|
|
18067
18232
|
return {
|
|
18068
18233
|
x: orientedValues[0],
|
|
18069
18234
|
y: orientedValues[1],
|
|
@@ -18072,7 +18237,7 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18072
18237
|
};
|
|
18073
18238
|
|
|
18074
18239
|
/**
|
|
18075
|
-
* Reorder values to compensate for orientation.
|
|
18240
|
+
* Reorder values to compensate for view orientation.
|
|
18076
18241
|
*
|
|
18077
18242
|
* @param {object} values Values as {x,y,z}.
|
|
18078
18243
|
* @returns {object} 'Deoriented' values as {x,y,z}.
|
|
@@ -18084,7 +18249,7 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18084
18249
|
values.y,
|
|
18085
18250
|
values.z
|
|
18086
18251
|
],
|
|
18087
|
-
|
|
18252
|
+
viewOrientation
|
|
18088
18253
|
);
|
|
18089
18254
|
return {
|
|
18090
18255
|
x: deOrientedValues[0],
|
|
@@ -18094,14 +18259,29 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18094
18259
|
};
|
|
18095
18260
|
|
|
18096
18261
|
/**
|
|
18097
|
-
* Get the scroll dimension index.
|
|
18262
|
+
* Get the (view) scroll dimension index.
|
|
18098
18263
|
*
|
|
18099
18264
|
* @returns {number} The index.
|
|
18100
18265
|
*/
|
|
18101
18266
|
this.getScrollIndex = function () {
|
|
18102
18267
|
var index = null;
|
|
18103
|
-
if (typeof
|
|
18104
|
-
index =
|
|
18268
|
+
if (typeof viewOrientation !== 'undefined') {
|
|
18269
|
+
index = viewOrientation.getThirdColMajorDirection();
|
|
18270
|
+
} else {
|
|
18271
|
+
index = 2;
|
|
18272
|
+
}
|
|
18273
|
+
return index;
|
|
18274
|
+
};
|
|
18275
|
+
|
|
18276
|
+
/**
|
|
18277
|
+
* Get the native (image) scroll dimension index.
|
|
18278
|
+
*
|
|
18279
|
+
* @returns {number} The index.
|
|
18280
|
+
*/
|
|
18281
|
+
this.getNativeScrollIndex = function () {
|
|
18282
|
+
var index = null;
|
|
18283
|
+
if (typeof imageOrientation !== 'undefined') {
|
|
18284
|
+
index = imageOrientation.getThirdColMajorDirection();
|
|
18105
18285
|
} else {
|
|
18106
18286
|
index = 2;
|
|
18107
18287
|
}
|
|
@@ -18669,12 +18849,12 @@ dwv.image.View = function (image) {
|
|
|
18669
18849
|
// to add the extra dimension
|
|
18670
18850
|
image.addEventListener('appendframe', function () {
|
|
18671
18851
|
// update current position if first appendFrame
|
|
18672
|
-
var
|
|
18673
|
-
if (
|
|
18852
|
+
var index = self.getCurrentIndex();
|
|
18853
|
+
if (index.length() === 3) {
|
|
18674
18854
|
// add dimension
|
|
18675
|
-
var values =
|
|
18855
|
+
var values = index.getValues();
|
|
18676
18856
|
values.push(0);
|
|
18677
|
-
self.
|
|
18857
|
+
self.setCurrentIndex(new dwv.math.Index(values));
|
|
18678
18858
|
}
|
|
18679
18859
|
});
|
|
18680
18860
|
|
|
@@ -18722,9 +18902,9 @@ dwv.image.View = function (image) {
|
|
|
18722
18902
|
* Current position as a Point3D.
|
|
18723
18903
|
*
|
|
18724
18904
|
* @private
|
|
18725
|
-
* @type {
|
|
18905
|
+
* @type {dwv.math.Index}
|
|
18726
18906
|
*/
|
|
18727
|
-
var
|
|
18907
|
+
var currentIndex = null;
|
|
18728
18908
|
/**
|
|
18729
18909
|
* View orientation. Undefined will use the original slice ordering.
|
|
18730
18910
|
*
|
|
@@ -18777,20 +18957,20 @@ dwv.image.View = function (image) {
|
|
|
18777
18957
|
};
|
|
18778
18958
|
|
|
18779
18959
|
/**
|
|
18780
|
-
*
|
|
18960
|
+
* Initialise the view: set initial index.
|
|
18781
18961
|
*/
|
|
18782
|
-
this.
|
|
18783
|
-
|
|
18962
|
+
this.init = function () {
|
|
18963
|
+
this.setInitialIndex();
|
|
18964
|
+
};
|
|
18784
18965
|
|
|
18966
|
+
/**
|
|
18967
|
+
* Set the initial index to 0.
|
|
18968
|
+
*/
|
|
18969
|
+
this.setInitialIndex = function () {
|
|
18785
18970
|
var geometry = image.getGeometry();
|
|
18786
18971
|
var values = new Array(geometry.getSize().length());
|
|
18787
18972
|
values.fill(0);
|
|
18788
|
-
|
|
18789
|
-
|
|
18790
|
-
this.setCurrentPosition(
|
|
18791
|
-
geometry.indexToWorld(index),
|
|
18792
|
-
silent
|
|
18793
|
-
);
|
|
18973
|
+
this.setCurrentIndex(new dwv.math.Index(values), true);
|
|
18794
18974
|
};
|
|
18795
18975
|
|
|
18796
18976
|
/**
|
|
@@ -18859,10 +19039,9 @@ dwv.image.View = function (image) {
|
|
|
18859
19039
|
*/
|
|
18860
19040
|
this.getCurrentWindowLut = function (rsi) {
|
|
18861
19041
|
// check position
|
|
18862
|
-
if (!this.
|
|
18863
|
-
this.
|
|
19042
|
+
if (!this.getCurrentIndex()) {
|
|
19043
|
+
this.setInitialIndex();
|
|
18864
19044
|
}
|
|
18865
|
-
var currentIndex = this.getCurrentIndex();
|
|
18866
19045
|
// use current rsi if not provided
|
|
18867
19046
|
if (typeof rsi === 'undefined') {
|
|
18868
19047
|
rsi = image.getRescaleSlopeAndIntercept(currentIndex);
|
|
@@ -19045,7 +19224,8 @@ dwv.image.View = function (image) {
|
|
|
19045
19224
|
* @returns {dwv.math.Point} The current position.
|
|
19046
19225
|
*/
|
|
19047
19226
|
this.getCurrentPosition = function () {
|
|
19048
|
-
|
|
19227
|
+
var geometry = this.getImage().getGeometry();
|
|
19228
|
+
return geometry.indexToWorld(currentIndex);
|
|
19049
19229
|
};
|
|
19050
19230
|
|
|
19051
19231
|
/**
|
|
@@ -19054,72 +19234,107 @@ dwv.image.View = function (image) {
|
|
|
19054
19234
|
* @returns {dwv.math.Index} The current index.
|
|
19055
19235
|
*/
|
|
19056
19236
|
this.getCurrentIndex = function () {
|
|
19057
|
-
|
|
19058
|
-
|
|
19237
|
+
return currentIndex;
|
|
19238
|
+
};
|
|
19239
|
+
|
|
19240
|
+
this.canSetPosition = function (position) {
|
|
19241
|
+
var geometry = image.getGeometry();
|
|
19242
|
+
var index = geometry.worldToIndex(position);
|
|
19243
|
+
return geometry.isIndexInBounds(index);
|
|
19244
|
+
};
|
|
19245
|
+
|
|
19246
|
+
this.getOrigin = function (position) {
|
|
19247
|
+
var geometry = image.getGeometry();
|
|
19248
|
+
var originIndex = 0;
|
|
19249
|
+
if (typeof position !== 'undefined') {
|
|
19250
|
+
var index = geometry.worldToIndex(position);
|
|
19251
|
+
// index is reoriented, 2 is scroll index
|
|
19252
|
+
originIndex = index.get(2);
|
|
19253
|
+
}
|
|
19254
|
+
return geometry.getOrigins()[originIndex];
|
|
19059
19255
|
};
|
|
19060
19256
|
|
|
19061
19257
|
/**
|
|
19062
19258
|
* Set the current position.
|
|
19063
19259
|
*
|
|
19064
|
-
* @param {dwv.math.Point}
|
|
19260
|
+
* @param {dwv.math.Point} position The new position.
|
|
19065
19261
|
* @param {boolean} silent Flag to fire event or not.
|
|
19066
19262
|
* @returns {boolean} False if not in bounds
|
|
19067
19263
|
* @fires dwv.image.View#positionchange
|
|
19068
19264
|
*/
|
|
19069
|
-
this.setCurrentPosition = function (
|
|
19070
|
-
//
|
|
19071
|
-
if (typeof silent === 'undefined') {
|
|
19072
|
-
silent = false;
|
|
19073
|
-
}
|
|
19074
|
-
|
|
19265
|
+
this.setCurrentPosition = function (position, silent) {
|
|
19266
|
+
// send invalid event if not in bounds
|
|
19075
19267
|
var geometry = image.getGeometry();
|
|
19076
|
-
var
|
|
19077
|
-
|
|
19078
|
-
// check if possible
|
|
19079
|
-
if (!geometry.isInBounds(newPosition)) {
|
|
19268
|
+
var index = geometry.worldToIndex(position);
|
|
19269
|
+
if (!geometry.isIndexInBounds(index)) {
|
|
19080
19270
|
if (!silent) {
|
|
19081
19271
|
// fire event with valid: false
|
|
19082
19272
|
fireEvent({
|
|
19083
19273
|
type: 'positionchange',
|
|
19084
19274
|
value: [
|
|
19085
|
-
|
|
19086
|
-
|
|
19275
|
+
index.getValues(),
|
|
19276
|
+
position.getValues(),
|
|
19087
19277
|
],
|
|
19088
19278
|
valid: false
|
|
19089
19279
|
});
|
|
19090
19280
|
}
|
|
19091
19281
|
return false;
|
|
19092
19282
|
}
|
|
19283
|
+
return this.setCurrentIndex(index, silent);
|
|
19284
|
+
};
|
|
19093
19285
|
|
|
19094
|
-
|
|
19286
|
+
/**
|
|
19287
|
+
* Set the current index.
|
|
19288
|
+
*
|
|
19289
|
+
* @param {dwv.math.Index} index The new index.
|
|
19290
|
+
* @param {boolean} silent Flag to fire event or not.
|
|
19291
|
+
* @returns {boolean} False if not in bounds
|
|
19292
|
+
* @fires dwv.image.View#positionchange
|
|
19293
|
+
*/
|
|
19294
|
+
this.setCurrentIndex = function (index, silent) {
|
|
19295
|
+
// check input
|
|
19296
|
+
if (typeof silent === 'undefined') {
|
|
19297
|
+
silent = false;
|
|
19298
|
+
}
|
|
19299
|
+
|
|
19300
|
+
var geometry = image.getGeometry();
|
|
19301
|
+
var position = geometry.indexToWorld(index);
|
|
19302
|
+
|
|
19303
|
+
// check if possible
|
|
19304
|
+
if (!geometry.isIndexInBounds(index)) {
|
|
19305
|
+
// do no send invalid positionchange event: avoid empty repaint
|
|
19306
|
+
return false;
|
|
19307
|
+
}
|
|
19308
|
+
|
|
19309
|
+
var isNew = !currentIndex || !currentIndex.equals(index);
|
|
19095
19310
|
|
|
19096
19311
|
if (isNew) {
|
|
19097
19312
|
var diffDims = null;
|
|
19098
|
-
if (
|
|
19099
|
-
if (
|
|
19100
|
-
diffDims =
|
|
19313
|
+
if (currentIndex) {
|
|
19314
|
+
if (currentIndex.canCompare(index)) {
|
|
19315
|
+
diffDims = currentIndex.compare(index);
|
|
19101
19316
|
} else {
|
|
19102
19317
|
diffDims = [];
|
|
19103
|
-
var minLen = Math.min(
|
|
19318
|
+
var minLen = Math.min(currentIndex.length(), index.length());
|
|
19104
19319
|
for (var i = 0; i < minLen; ++i) {
|
|
19105
|
-
if (
|
|
19320
|
+
if (currentIndex.get(i) !== index.get(i)) {
|
|
19106
19321
|
diffDims.push(i);
|
|
19107
19322
|
}
|
|
19108
19323
|
}
|
|
19109
|
-
var maxLen = Math.max(
|
|
19324
|
+
var maxLen = Math.max(currentIndex.length(), index.length());
|
|
19110
19325
|
for (var j = minLen; j < maxLen; ++j) {
|
|
19111
19326
|
diffDims.push(j);
|
|
19112
19327
|
}
|
|
19113
19328
|
}
|
|
19114
19329
|
} else {
|
|
19115
19330
|
diffDims = [];
|
|
19116
|
-
for (var k = 0; k <
|
|
19331
|
+
for (var k = 0; k < index.length(); ++k) {
|
|
19117
19332
|
diffDims.push(k);
|
|
19118
19333
|
}
|
|
19119
19334
|
}
|
|
19120
19335
|
|
|
19121
19336
|
// assign
|
|
19122
|
-
|
|
19337
|
+
currentIndex = index;
|
|
19123
19338
|
|
|
19124
19339
|
if (!silent) {
|
|
19125
19340
|
/**
|
|
@@ -19133,46 +19348,32 @@ dwv.image.View = function (image) {
|
|
|
19133
19348
|
var posEvent = {
|
|
19134
19349
|
type: 'positionchange',
|
|
19135
19350
|
value: [
|
|
19136
|
-
|
|
19137
|
-
|
|
19351
|
+
index.getValues(),
|
|
19352
|
+
position.getValues(),
|
|
19138
19353
|
],
|
|
19139
19354
|
diffDims: diffDims,
|
|
19140
19355
|
data: {
|
|
19141
|
-
imageUid: image.getImageUid(
|
|
19356
|
+
imageUid: image.getImageUid(index)
|
|
19142
19357
|
}
|
|
19143
19358
|
};
|
|
19144
19359
|
|
|
19145
19360
|
// add value if possible
|
|
19146
19361
|
if (image.canQuantify()) {
|
|
19147
|
-
var pixValue = image.getRescaledValueAtIndex(
|
|
19362
|
+
var pixValue = image.getRescaledValueAtIndex(index);
|
|
19148
19363
|
posEvent.value.push(pixValue);
|
|
19149
19364
|
}
|
|
19150
19365
|
|
|
19151
19366
|
// fire
|
|
19152
19367
|
fireEvent(posEvent);
|
|
19153
19368
|
}
|
|
19369
|
+
} else {
|
|
19370
|
+
return false;
|
|
19154
19371
|
}
|
|
19155
19372
|
|
|
19156
19373
|
// all good
|
|
19157
19374
|
return true;
|
|
19158
19375
|
};
|
|
19159
19376
|
|
|
19160
|
-
/**
|
|
19161
|
-
* Set the current index.
|
|
19162
|
-
*
|
|
19163
|
-
* @param {dwv.math.Index} index The index.
|
|
19164
|
-
* @param {boolean} silent If true, does not fire a positionchange event.
|
|
19165
|
-
* @returns {boolean} False if not in bounds.
|
|
19166
|
-
*/
|
|
19167
|
-
this.setCurrentIndex = function (index, silent) {
|
|
19168
|
-
var geometry = this.getImage().getGeometry();
|
|
19169
|
-
var position = geometry.indexToWorld(index);
|
|
19170
|
-
if (!geometry.isInBounds(position)) {
|
|
19171
|
-
return false;
|
|
19172
|
-
}
|
|
19173
|
-
return this.setCurrentPosition(position, silent);
|
|
19174
|
-
};
|
|
19175
|
-
|
|
19176
19377
|
/**
|
|
19177
19378
|
* Set the view window/level.
|
|
19178
19379
|
*
|
|
@@ -19354,21 +19555,21 @@ dwv.image.View.prototype.setWindowLevelMinMax = function () {
|
|
|
19354
19555
|
* Generate display image data to be given to a canvas.
|
|
19355
19556
|
*
|
|
19356
19557
|
* @param {Array} array The array to fill in.
|
|
19357
|
-
* @param {dwv.math.
|
|
19358
|
-
* otherwise generates at current
|
|
19558
|
+
* @param {dwv.math.Index} index Optional index at which to generate,
|
|
19559
|
+
* otherwise generates at current index.
|
|
19359
19560
|
*/
|
|
19360
|
-
dwv.image.View.prototype.generateImageData = function (array,
|
|
19361
|
-
// check
|
|
19362
|
-
if (typeof
|
|
19363
|
-
if (!this.
|
|
19364
|
-
this.
|
|
19561
|
+
dwv.image.View.prototype.generateImageData = function (array, index) {
|
|
19562
|
+
// check index
|
|
19563
|
+
if (typeof index === 'undefined') {
|
|
19564
|
+
if (!this.getCurrentIndex()) {
|
|
19565
|
+
this.setInitialIndex();
|
|
19365
19566
|
}
|
|
19366
|
-
|
|
19567
|
+
index = this.getCurrentIndex();
|
|
19367
19568
|
}
|
|
19368
19569
|
|
|
19369
19570
|
var image = this.getImage();
|
|
19370
19571
|
var iterator = dwv.image.getSliceIterator(
|
|
19371
|
-
image,
|
|
19572
|
+
image, index, false, this.getOrientation());
|
|
19372
19573
|
|
|
19373
19574
|
var photoInterpretation = image.getPhotometricInterpretation();
|
|
19374
19575
|
switch (photoInterpretation) {
|
|
@@ -19561,8 +19762,8 @@ dwv.image.ViewFactory.prototype.create = function (dicomElements, image) {
|
|
|
19561
19762
|
// store
|
|
19562
19763
|
view.setWindowPresets(windowPresets);
|
|
19563
19764
|
|
|
19564
|
-
//
|
|
19565
|
-
view.
|
|
19765
|
+
// initialise the view
|
|
19766
|
+
view.init();
|
|
19566
19767
|
|
|
19567
19768
|
return view;
|
|
19568
19769
|
};
|
|
@@ -23774,6 +23975,27 @@ dwv.math.Index.prototype.equals = function (rhs) {
|
|
|
23774
23975
|
return true;
|
|
23775
23976
|
};
|
|
23776
23977
|
|
|
23978
|
+
/**
|
|
23979
|
+
* Compare indices and return different dimensions.
|
|
23980
|
+
*
|
|
23981
|
+
* @param {dwv.math.Index} rhs The index to compare to.
|
|
23982
|
+
* @returns {Array} The list of different dimensions.
|
|
23983
|
+
*/
|
|
23984
|
+
dwv.math.Index.prototype.compare = function (rhs) {
|
|
23985
|
+
// check if can compare
|
|
23986
|
+
if (!this.canCompare(rhs)) {
|
|
23987
|
+
return null;
|
|
23988
|
+
}
|
|
23989
|
+
// check values
|
|
23990
|
+
var diffDims = [];
|
|
23991
|
+
for (var i = 0, leni = this.length(); i < leni; ++i) {
|
|
23992
|
+
if (this.get(i) !== rhs.get(i)) {
|
|
23993
|
+
diffDims.push(i);
|
|
23994
|
+
}
|
|
23995
|
+
}
|
|
23996
|
+
return diffDims;
|
|
23997
|
+
};
|
|
23998
|
+
|
|
23777
23999
|
/**
|
|
23778
24000
|
* Add another index to this one.
|
|
23779
24001
|
*
|