dwv 0.31.0-beta.3 → 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 +282 -129
- 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.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
|
}
|
|
@@ -1325,20 +1329,6 @@ dwv.App = function () {
|
|
|
1325
1329
|
viewLayer.initialise(size2D, spacing2D, dataIndex);
|
|
1326
1330
|
viewLayer.setOpacity(opacity);
|
|
1327
1331
|
|
|
1328
|
-
// compensate origin difference
|
|
1329
|
-
var diff = null;
|
|
1330
|
-
if (layerGroup.getNumberOfLayers() !== 1) {
|
|
1331
|
-
var firstDataIndex = layerGroup.getViewDataIndices()[0];
|
|
1332
|
-
var data0 = dataController.get(firstDataIndex);
|
|
1333
|
-
// offset from the top, use first origin
|
|
1334
|
-
var origin0 = data0.image.getGeometry().getOrigins()[0];
|
|
1335
|
-
var origin1 = imageGeometry.getOrigins()[0];
|
|
1336
|
-
diff = origin0.minus(origin1);
|
|
1337
|
-
// TODO: check why -z...
|
|
1338
|
-
viewLayer.setBaseOffset(new dwv.math.Vector3D(
|
|
1339
|
-
diff.getX(), diff.getY(), -1 * diff.getZ()));
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
1332
|
// listen to image changes
|
|
1343
1333
|
dataController.addEventListener('imagechange', viewLayer.onimagechange);
|
|
1344
1334
|
|
|
@@ -1358,11 +1348,6 @@ dwv.App = function () {
|
|
|
1358
1348
|
vc.getCurrentPosition().getValues()
|
|
1359
1349
|
];
|
|
1360
1350
|
layerGroup.updateLayersToPositionChange({value: value});
|
|
1361
|
-
|
|
1362
|
-
// compensate origin difference if needed
|
|
1363
|
-
if (diff) {
|
|
1364
|
-
dl.setBaseOffset(diff);
|
|
1365
|
-
}
|
|
1366
1351
|
}
|
|
1367
1352
|
|
|
1368
1353
|
// fit to the maximum size
|
|
@@ -2619,9 +2604,15 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2619
2604
|
// third dimension player ID (created by setInterval)
|
|
2620
2605
|
var playerID = null;
|
|
2621
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
|
+
|
|
2622
2612
|
// setup the plane helper
|
|
2623
2613
|
var planeHelper = new dwv.image.PlaneHelper(
|
|
2624
|
-
view.getImage().getGeometry().
|
|
2614
|
+
view.getImage().getGeometry().getRealSpacing(),
|
|
2615
|
+
view.getImage().getGeometry().getOrientation(),
|
|
2625
2616
|
view.getOrientation()
|
|
2626
2617
|
);
|
|
2627
2618
|
|
|
@@ -2746,6 +2737,10 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2746
2737
|
return view.getCurrentIndex().get(view.getScrollIndex());
|
|
2747
2738
|
};
|
|
2748
2739
|
|
|
2740
|
+
this.getOrigin = function (position) {
|
|
2741
|
+
return view.getOrigin(position);
|
|
2742
|
+
};
|
|
2743
|
+
|
|
2749
2744
|
/**
|
|
2750
2745
|
* Get the current scroll position value.
|
|
2751
2746
|
*
|
|
@@ -2894,6 +2889,10 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2894
2889
|
return view.getImage().getGeometry().getSize();
|
|
2895
2890
|
};
|
|
2896
2891
|
|
|
2892
|
+
this.canSetPosition = function (position) {
|
|
2893
|
+
return view.canSetPosition(position);
|
|
2894
|
+
};
|
|
2895
|
+
|
|
2897
2896
|
/**
|
|
2898
2897
|
* Set the current position.
|
|
2899
2898
|
*
|
|
@@ -2913,8 +2912,18 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2913
2912
|
* @returns {boolean} False if not in bounds.
|
|
2914
2913
|
*/
|
|
2915
2914
|
this.setCurrentPosition2D = function (x, y) {
|
|
2916
|
-
|
|
2917
|
-
|
|
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);
|
|
2918
2927
|
};
|
|
2919
2928
|
|
|
2920
2929
|
/**
|
|
@@ -2928,25 +2937,6 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2928
2937
|
return view.setCurrentIndex(index, silent);
|
|
2929
2938
|
};
|
|
2930
2939
|
|
|
2931
|
-
/**
|
|
2932
|
-
* Get a 3D position from a plane 2D position.
|
|
2933
|
-
*
|
|
2934
|
-
* @param {dwv.math.Point2D} point2D The 2D position as {x,y}.
|
|
2935
|
-
* @returns {dwv.math.Point} The 3D point.
|
|
2936
|
-
*/
|
|
2937
|
-
this.getPositionFromPlanePoint = function (point2D) {
|
|
2938
|
-
// keep third direction
|
|
2939
|
-
var k = this.getCurrentScrollIndexValue();
|
|
2940
|
-
var planePoint = new dwv.math.Point3D(point2D.x, point2D.y, k);
|
|
2941
|
-
// de-orient
|
|
2942
|
-
var point = planeHelper.getDeOrientedVector3D(planePoint);
|
|
2943
|
-
// ~indexToWorld to not loose precision
|
|
2944
|
-
var geometry = view.getImage().getGeometry();
|
|
2945
|
-
var point3D = geometry.pointToWorld(point);
|
|
2946
|
-
// merge with current position to keep extra dimensions
|
|
2947
|
-
return this.getCurrentPosition().mergeWith3D(point3D);
|
|
2948
|
-
};
|
|
2949
|
-
|
|
2950
2940
|
/**
|
|
2951
2941
|
* Get a plane 3D position from a plane 2D position: does not compensate
|
|
2952
2942
|
* for the image origin. Needed for setting the scale center...
|
|
@@ -2962,7 +2952,7 @@ dwv.ctrl.ViewController = function (view) {
|
|
|
2962
2952
|
var point = planeHelper.getDeOrientedVector3D(planePoint);
|
|
2963
2953
|
// ~indexToWorld to not loose precision
|
|
2964
2954
|
var geometry = view.getImage().getGeometry();
|
|
2965
|
-
var spacing = geometry.
|
|
2955
|
+
var spacing = geometry.getRealSpacing();
|
|
2966
2956
|
return new dwv.math.Point3D(
|
|
2967
2957
|
point.getX() * spacing.get(0),
|
|
2968
2958
|
point.getY() * spacing.get(1),
|
|
@@ -4506,7 +4496,7 @@ dwv.dicom = dwv.dicom || {};
|
|
|
4506
4496
|
* @returns {string} The version of the library.
|
|
4507
4497
|
*/
|
|
4508
4498
|
dwv.getVersion = function () {
|
|
4509
|
-
return '0.31.0-beta.
|
|
4499
|
+
return '0.31.0-beta.4';
|
|
4510
4500
|
};
|
|
4511
4501
|
|
|
4512
4502
|
/**
|
|
@@ -6039,10 +6029,24 @@ dwv.dicom.isEven = function (number) {
|
|
|
6039
6029
|
* @returns {boolean} True if the VR is a non string one.
|
|
6040
6030
|
*/
|
|
6041
6031
|
dwv.dicom.isNonStringVr = function (vr) {
|
|
6042
|
-
return vr === 'UN' ||
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
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';
|
|
6046
6050
|
};
|
|
6047
6051
|
|
|
6048
6052
|
/**
|
|
@@ -6839,43 +6843,55 @@ dwv.dicom.setElementValue = function (element, value, isImplicit) {
|
|
|
6839
6843
|
// set the value and calculate size
|
|
6840
6844
|
size = 0;
|
|
6841
6845
|
var paddedValue = dwv.dicom.padElementValue(element, value);
|
|
6842
|
-
if (
|
|
6846
|
+
if (element.vr === 'AT') {
|
|
6843
6847
|
element.value = paddedValue;
|
|
6844
|
-
|
|
6845
|
-
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
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;
|
|
6851
6871
|
}
|
|
6852
6872
|
} else {
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
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
|
+
}
|
|
6857
6883
|
} else {
|
|
6858
|
-
|
|
6859
|
-
|
|
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
|
+
}
|
|
6860
6892
|
}
|
|
6861
6893
|
}
|
|
6862
6894
|
|
|
6863
|
-
// convert size to bytes
|
|
6864
|
-
if (element.vr === 'US' || element.vr === 'OW') {
|
|
6865
|
-
size *= Uint16Array.BYTES_PER_ELEMENT;
|
|
6866
|
-
} else if (element.vr === 'SS') {
|
|
6867
|
-
size *= Int16Array.BYTES_PER_ELEMENT;
|
|
6868
|
-
} else if (element.vr === 'UL') {
|
|
6869
|
-
size *= Uint32Array.BYTES_PER_ELEMENT;
|
|
6870
|
-
} else if (element.vr === 'SL') {
|
|
6871
|
-
size *= Int32Array.BYTES_PER_ELEMENT;
|
|
6872
|
-
} else if (element.vr === 'FL') {
|
|
6873
|
-
size *= Float32Array.BYTES_PER_ELEMENT;
|
|
6874
|
-
} else if (element.vr === 'FD') {
|
|
6875
|
-
size *= Float64Array.BYTES_PER_ELEMENT;
|
|
6876
|
-
} else {
|
|
6877
|
-
size *= Uint8Array.BYTES_PER_ELEMENT;
|
|
6878
|
-
}
|
|
6879
6895
|
element.vl = size;
|
|
6880
6896
|
}
|
|
6881
6897
|
|
|
@@ -11419,21 +11435,31 @@ dwv.gui.DrawLayer = function (containerDiv) {
|
|
|
11419
11435
|
};
|
|
11420
11436
|
|
|
11421
11437
|
/**
|
|
11422
|
-
* Set the base layer offset.
|
|
11438
|
+
* Set the base layer offset. Updates the layer offset.
|
|
11423
11439
|
*
|
|
11424
|
-
* @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.
|
|
11425
11443
|
*/
|
|
11426
|
-
this.setBaseOffset = function (
|
|
11427
|
-
|
|
11428
|
-
|
|
11429
|
-
|
|
11430
|
-
|
|
11431
|
-
|
|
11432
|
-
// reset offset
|
|
11433
|
-
konvaStage.offset({
|
|
11434
|
-
x: baseOffset.x,
|
|
11435
|
-
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(),
|
|
11436
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;
|
|
11437
11463
|
};
|
|
11438
11464
|
|
|
11439
11465
|
/**
|
|
@@ -11549,10 +11575,13 @@ dwv.gui.DrawLayer = function (containerDiv) {
|
|
|
11549
11575
|
*
|
|
11550
11576
|
* @param {dwv.math.Point} position The new position.
|
|
11551
11577
|
* @param {dwv.math.Index} index The new index.
|
|
11578
|
+
* @returns {boolean} True if the position was updated.
|
|
11552
11579
|
*/
|
|
11553
11580
|
this.setCurrentPosition = function (position, index) {
|
|
11554
11581
|
this.getDrawController().activateDrawLayer(
|
|
11555
11582
|
index, planeHelper.getScrollIndex());
|
|
11583
|
+
// TODO: add check
|
|
11584
|
+
return true;
|
|
11556
11585
|
};
|
|
11557
11586
|
|
|
11558
11587
|
/**
|
|
@@ -12254,10 +12283,56 @@ dwv.gui.LayerGroup = function (containerDiv, groupId) {
|
|
|
12254
12283
|
|
|
12255
12284
|
var index = new dwv.math.Index(event.value[0]);
|
|
12256
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;
|
|
12257
12289
|
// update position for all layers except the source one
|
|
12258
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;
|
|
12259
12329
|
if (layers[i].getId() !== event.srclayerid) {
|
|
12260
|
-
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();
|
|
12261
12336
|
}
|
|
12262
12337
|
}
|
|
12263
12338
|
|
|
@@ -13345,19 +13420,31 @@ dwv.gui.ViewLayer = function (containerDiv) {
|
|
|
13345
13420
|
};
|
|
13346
13421
|
|
|
13347
13422
|
/**
|
|
13348
|
-
* Set the base layer offset.
|
|
13423
|
+
* Set the base layer offset. Updates the layer offset.
|
|
13349
13424
|
*
|
|
13350
|
-
* @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.
|
|
13351
13428
|
*/
|
|
13352
|
-
this.setBaseOffset = function (
|
|
13429
|
+
this.setBaseOffset = function (scrollOffset, planeOffset) {
|
|
13353
13430
|
var helper = viewController.getPlaneHelper();
|
|
13354
|
-
|
|
13355
|
-
|
|
13356
|
-
|
|
13357
|
-
|
|
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(),
|
|
13358
13436
|
});
|
|
13359
|
-
|
|
13360
|
-
|
|
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;
|
|
13361
13448
|
};
|
|
13362
13449
|
|
|
13363
13450
|
/**
|
|
@@ -13741,9 +13828,10 @@ dwv.gui.ViewLayer = function (containerDiv) {
|
|
|
13741
13828
|
*
|
|
13742
13829
|
* @param {dwv.math.Point} position The new position.
|
|
13743
13830
|
* @param {dwv.math.Index} _index The new index.
|
|
13831
|
+
* @returns {boolean} True if the position was updated.
|
|
13744
13832
|
*/
|
|
13745
13833
|
this.setCurrentPosition = function (position, _index) {
|
|
13746
|
-
viewController.setCurrentPosition(position);
|
|
13834
|
+
return viewController.setCurrentPosition(position);
|
|
13747
13835
|
};
|
|
13748
13836
|
|
|
13749
13837
|
/**
|
|
@@ -15104,7 +15192,7 @@ dwv.image.Geometry = function (origin, size, spacing, orientation) {
|
|
|
15104
15192
|
|
|
15105
15193
|
/**
|
|
15106
15194
|
* Get the object spacing.
|
|
15107
|
-
* Warning: the
|
|
15195
|
+
* Warning: the spacing comes as stored in DICOM, meaning that it could
|
|
15108
15196
|
* be oriented.
|
|
15109
15197
|
*
|
|
15110
15198
|
* @param {dwv.math.Matrix33} viewOrientation The view orientation (optional)
|
|
@@ -15132,6 +15220,15 @@ dwv.image.Geometry = function (origin, size, spacing, orientation) {
|
|
|
15132
15220
|
return res;
|
|
15133
15221
|
};
|
|
15134
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
|
+
|
|
15135
15232
|
/**
|
|
15136
15233
|
* Get the object orientation.
|
|
15137
15234
|
*
|
|
@@ -15343,6 +15440,7 @@ dwv.image.Geometry.prototype.pointToWorld = function (point) {
|
|
|
15343
15440
|
dwv.image.Geometry.prototype.worldToIndex = function (point) {
|
|
15344
15441
|
// compensate for origin
|
|
15345
15442
|
// (origin is not oriented, compensate before orientation)
|
|
15443
|
+
// TODO: use slice origin...
|
|
15346
15444
|
var origin = this.getOrigin();
|
|
15347
15445
|
var point3D = new dwv.math.Point3D(
|
|
15348
15446
|
point.get(0) - origin.getX(),
|
|
@@ -17967,9 +18065,17 @@ dwv.image = dwv.image || {};
|
|
|
17967
18065
|
*
|
|
17968
18066
|
* @class
|
|
17969
18067
|
* @param {dwv.image.Spacing} spacing The spacing.
|
|
17970
|
-
* @param {dwv.math.Matrix}
|
|
18068
|
+
* @param {dwv.math.Matrix} imageOrientation The image oientation.
|
|
18069
|
+
* @param {dwv.math.Matrix} viewOrientation The view orientation.
|
|
17971
18070
|
*/
|
|
17972
|
-
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);
|
|
17973
18079
|
|
|
17974
18080
|
/**
|
|
17975
18081
|
* Get a 3D offset from a plane one.
|
|
@@ -17990,7 +18096,7 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
17990
18096
|
/**
|
|
17991
18097
|
* Get a plane offset from a 3D one.
|
|
17992
18098
|
*
|
|
17993
|
-
* @param {
|
|
18099
|
+
* @param {object} offset3D The 3D offset as {x,y,z}.
|
|
17994
18100
|
* @returns {object} The plane offset as {x,y}.
|
|
17995
18101
|
*/
|
|
17996
18102
|
this.getPlaneOffsetFromOffset3D = function (offset3D) {
|
|
@@ -18039,10 +18145,8 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18039
18145
|
*/
|
|
18040
18146
|
this.getOrientedVector3D = function (vector) {
|
|
18041
18147
|
var planeVector = vector;
|
|
18042
|
-
if (typeof
|
|
18043
|
-
|
|
18044
|
-
// vector = orientation * planeVector
|
|
18045
|
-
planeVector = orientation.getInverse().getAbs().multiplyVector3D(vector);
|
|
18148
|
+
if (typeof targetOrientation !== 'undefined') {
|
|
18149
|
+
planeVector = targetOrientation.getInverse().multiplyVector3D(vector);
|
|
18046
18150
|
}
|
|
18047
18151
|
return planeVector;
|
|
18048
18152
|
};
|
|
@@ -18055,10 +18159,10 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18055
18159
|
*/
|
|
18056
18160
|
this.getOrientedIndex = function (index) {
|
|
18057
18161
|
var planeIndex = index;
|
|
18058
|
-
if (typeof
|
|
18162
|
+
if (typeof viewOrientation !== 'undefined') {
|
|
18059
18163
|
// abs? otherwise negative index...
|
|
18060
|
-
// vector =
|
|
18061
|
-
planeIndex =
|
|
18164
|
+
// vector = viewOrientation * planeVector
|
|
18165
|
+
planeIndex = viewOrientation.getInverse().getAbs().multiplyIndex3D(index);
|
|
18062
18166
|
}
|
|
18063
18167
|
return planeIndex;
|
|
18064
18168
|
};
|
|
@@ -18071,11 +18175,11 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18071
18175
|
*/
|
|
18072
18176
|
this.getOrientedPoint = function (point) {
|
|
18073
18177
|
var planePoint = point;
|
|
18074
|
-
if (typeof
|
|
18178
|
+
if (typeof viewOrientation !== 'undefined') {
|
|
18075
18179
|
// abs? otherwise negative index...
|
|
18076
|
-
// vector =
|
|
18180
|
+
// vector = viewOrientation * planeVector
|
|
18077
18181
|
var point3D =
|
|
18078
|
-
|
|
18182
|
+
viewOrientation.getInverse().getAbs().multiplyPoint3D(point.get3D());
|
|
18079
18183
|
planePoint = point.mergeWith3D(point3D);
|
|
18080
18184
|
}
|
|
18081
18185
|
return planePoint;
|
|
@@ -18089,16 +18193,30 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18089
18193
|
*/
|
|
18090
18194
|
this.getDeOrientedVector3D = function (planeVector) {
|
|
18091
18195
|
var vector = planeVector;
|
|
18092
|
-
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') {
|
|
18093
18211
|
// abs? otherwise negative index...
|
|
18094
|
-
// vector =
|
|
18095
|
-
vector =
|
|
18212
|
+
// vector = viewOrientation * planePoint
|
|
18213
|
+
vector = viewOrientation.getAbs().multiplyVector3D(planeVector);
|
|
18096
18214
|
}
|
|
18097
18215
|
return vector;
|
|
18098
18216
|
};
|
|
18099
18217
|
|
|
18100
18218
|
/**
|
|
18101
|
-
* Reorder values to follow orientation.
|
|
18219
|
+
* Reorder values to follow view orientation.
|
|
18102
18220
|
*
|
|
18103
18221
|
* @param {object} values Values as {x,y,z}.
|
|
18104
18222
|
* @returns {object} Reoriented values as {x,y,z}.
|
|
@@ -18110,7 +18228,7 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18110
18228
|
values.y,
|
|
18111
18229
|
values.z
|
|
18112
18230
|
],
|
|
18113
|
-
|
|
18231
|
+
viewOrientation);
|
|
18114
18232
|
return {
|
|
18115
18233
|
x: orientedValues[0],
|
|
18116
18234
|
y: orientedValues[1],
|
|
@@ -18119,7 +18237,7 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18119
18237
|
};
|
|
18120
18238
|
|
|
18121
18239
|
/**
|
|
18122
|
-
* Reorder values to compensate for orientation.
|
|
18240
|
+
* Reorder values to compensate for view orientation.
|
|
18123
18241
|
*
|
|
18124
18242
|
* @param {object} values Values as {x,y,z}.
|
|
18125
18243
|
* @returns {object} 'Deoriented' values as {x,y,z}.
|
|
@@ -18131,7 +18249,7 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18131
18249
|
values.y,
|
|
18132
18250
|
values.z
|
|
18133
18251
|
],
|
|
18134
|
-
|
|
18252
|
+
viewOrientation
|
|
18135
18253
|
);
|
|
18136
18254
|
return {
|
|
18137
18255
|
x: deOrientedValues[0],
|
|
@@ -18141,14 +18259,29 @@ dwv.image.PlaneHelper = function (spacing, orientation) {
|
|
|
18141
18259
|
};
|
|
18142
18260
|
|
|
18143
18261
|
/**
|
|
18144
|
-
* Get the scroll dimension index.
|
|
18262
|
+
* Get the (view) scroll dimension index.
|
|
18145
18263
|
*
|
|
18146
18264
|
* @returns {number} The index.
|
|
18147
18265
|
*/
|
|
18148
18266
|
this.getScrollIndex = function () {
|
|
18149
18267
|
var index = null;
|
|
18150
|
-
if (typeof
|
|
18151
|
-
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();
|
|
18152
18285
|
} else {
|
|
18153
18286
|
index = 2;
|
|
18154
18287
|
}
|
|
@@ -19104,6 +19237,23 @@ dwv.image.View = function (image) {
|
|
|
19104
19237
|
return currentIndex;
|
|
19105
19238
|
};
|
|
19106
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];
|
|
19255
|
+
};
|
|
19256
|
+
|
|
19107
19257
|
/**
|
|
19108
19258
|
* Set the current position.
|
|
19109
19259
|
*
|
|
@@ -19152,6 +19302,7 @@ dwv.image.View = function (image) {
|
|
|
19152
19302
|
|
|
19153
19303
|
// check if possible
|
|
19154
19304
|
if (!geometry.isIndexInBounds(index)) {
|
|
19305
|
+
// do no send invalid positionchange event: avoid empty repaint
|
|
19155
19306
|
return false;
|
|
19156
19307
|
}
|
|
19157
19308
|
|
|
@@ -19215,6 +19366,8 @@ dwv.image.View = function (image) {
|
|
|
19215
19366
|
// fire
|
|
19216
19367
|
fireEvent(posEvent);
|
|
19217
19368
|
}
|
|
19369
|
+
} else {
|
|
19370
|
+
return false;
|
|
19218
19371
|
}
|
|
19219
19372
|
|
|
19220
19373
|
// all good
|