Skip to content

Commit 2d30e29

Browse files
author
hackermd
committed
Fix calculation of resolutions of pyramid levels
1 parent 0a996dc commit 2d30e29

File tree

2 files changed

+60
-24
lines changed

2 files changed

+60
-24
lines changed

build/dicom-microscopy-viewer.js

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50226,12 +50226,50 @@
5022650226
}
5022750227

5022850228

50229+
function _scoord2Geometry(scoord) {
50230+
const type = scoord.graphicType;
50231+
const data = scoord.graphicData;
50232+
if (type === 'POINT') {
50233+
let coordinates = _scoordCoordinates2geometryCoordinates(data);
50234+
return new Point(coordinates);
50235+
} else if (type === 'MULTIPOINT') {
50236+
const points = [];
50237+
for (d in data) {
50238+
let coordinates = _scoordCoordinates2geometryCoordinates(d);
50239+
let p = new Point(coordinates);
50240+
points.push(p);
50241+
}
50242+
return points;
50243+
} else if (type === 'POLYLINE') {
50244+
if (data[0] === data[data.length-1]) {
50245+
let coordinates = [_scoordCoordinates2geometryCoordinates(data)];
50246+
return new Polygon(coordinates);
50247+
} else {
50248+
let coordinates = _scoordCoordinates2geometryCoordinates(data);
50249+
return new LineStringGeometry(coordinates);
50250+
}
50251+
} else if (type === 'CIRCLE') {
50252+
let coordinates = _scoordCoordinates2geometryCoordinates(data);
50253+
let center = coordinates[0];
50254+
let radius = Math.abs(coordinates[1][0] - coordinates[0][0]);
50255+
return new Circle(center, radius);
50256+
} else if (type === 'ELLIPSE') ; else {
50257+
console.error(`unknown graphic type "${type}"`);
50258+
}
50259+
}
50260+
50261+
5022950262
function _geometryCoordinates2scoordCoordinates(coordinates) {
5023050263
// TODO: Transform to coordinates on pyramid base layer???
5023150264
return [coordinates[0] + 1, -coordinates[1]]
5023250265
}
5023350266

5023450267

50268+
function _scoordCoordinates2geometryCoordinates(coordinates) {
50269+
return [coordinates[0] - 1, -coordinates[1]]
50270+
}
50271+
50272+
5023550273
const _map = Symbol('map');
5023650274
const _features = Symbol('features');
5023750275
const _drawingSource = Symbol('drawingSource');
@@ -50338,11 +50376,13 @@
5033850376
const totalSizes = [];
5033950377
const resolutions = [];
5034050378
const origins = [[0, -1]];
50341-
for (let j = 0; j < this[_pyramid].length; j++) {
50379+
const nLevels = this[_pyramid].length;
50380+
for (let j = 0; j < nLevels; j++) {
5034250381
let columns = this[_pyramid][j].columns;
5034350382
let rows = this[_pyramid][j].rows;
5034450383
let totalPixelMatrixColumns = this[_pyramid][j].totalPixelMatrixColumns;
5034550384
let totalPixelMatrixRows = this[_pyramid][j].totalPixelMatrixRows;
50385+
let pixelSpacing = this[_pyramid][j].pixelSpacing;
5034650386
let colFactor = Math.ceil(totalPixelMatrixColumns / columns);
5034750387
let rowFactor = Math.ceil(totalPixelMatrixRows / rows);
5034850388
tileSizes.push([columns, rows]);
@@ -50352,9 +50392,7 @@
5035250392
* Compute the resolution at each pyramid level, since the zoom
5035350393
* factor may not be the same between adjacent pyramid levels.
5035450394
*/
50355-
let zoomFactorColumns = this[_pyramid][0].totalPixelMatrixColumns / totalPixelMatrixColumns;
50356-
let zoomFactorRows = this[_pyramid][0].totalPixelMatrixRows / totalPixelMatrixRows;
50357-
let zoomFactor = (zoomFactorColumns + zoomFactorRows) / 2;
50395+
let zoomFactor = this[_pyramid][nLevels-1].totalPixelMatrixRows / totalPixelMatrixRows;
5035850396
resolutions.push(zoomFactor);
5035950397

5036050398
/*
@@ -50470,8 +50508,8 @@
5047050508
*/
5047150509
const extent = [
5047250510
0, // min X
50473-
-pyramid[0].totalPixelMatrixRows, // min Y
50474-
pyramid[0].totalPixelMatrixColumns, // max X
50511+
-pyramid[nLevels-1].totalPixelMatrixRows, // min Y
50512+
pyramid[nLevels-1].totalPixelMatrixColumns, // max X
5047550513
-1 // max Y
5047650514
];
5047750515

@@ -50521,9 +50559,9 @@
5052150559
* DICOM pixel spacing has millimeter unit while the projection has
5052250560
* has meter unit.
5052350561
*/
50524-
let spacing = pyramid[0].pixelSpacing[1] / 10**3;
50525-
let metricRes = pixelRes * spacing;
50526-
return(metricRes);
50562+
let spacing = pyramid[nLevels-1].pixelSpacing[0] / 10**3;
50563+
let res = pixelRes * spacing;
50564+
return(res);
5052750565
}
5052850566
});
5052950567
/*
@@ -50875,14 +50913,13 @@
5087550913
}
5087650914

5087750915
addScoord(item) {
50878-
let geometry = _graphic2Geometry(item);
50916+
let geometry = _scoord2Geometry(item);
5087950917
let feature = new Feature({geometry});
50880-
this[_features].push(feature);
5088150918
this[_drawingSource].addFeature(feature);
5088250919
}
5088350920

5088450921
updateScoord(index, item) {
50885-
let geometry = _graphic2Geometry(item);
50922+
let geometry = _scoord2Geometry(item);
5088650923
let feature = new Feature({geometry});
5088750924
this[_features].setAt(index, feature);
5088850925
}

src/api.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,13 @@ class DICOMMicroscopyViewer {
215215
const totalSizes = [];
216216
const resolutions = [];
217217
const origins = [[0, -1]];
218-
for (let j = 0; j < this[_pyramid].length; j++) {
218+
const nLevels = this[_pyramid].length;
219+
for (let j = 0; j < nLevels; j++) {
219220
let columns = this[_pyramid][j].columns;
220221
let rows = this[_pyramid][j].rows;
221222
let totalPixelMatrixColumns = this[_pyramid][j].totalPixelMatrixColumns;
222223
let totalPixelMatrixRows = this[_pyramid][j].totalPixelMatrixRows;
224+
let pixelSpacing = this[_pyramid][j].pixelSpacing;
223225
let colFactor = Math.ceil(totalPixelMatrixColumns / columns);
224226
let rowFactor = Math.ceil(totalPixelMatrixRows / rows);
225227
tileSizes.push([columns, rows]);
@@ -229,9 +231,7 @@ class DICOMMicroscopyViewer {
229231
* Compute the resolution at each pyramid level, since the zoom
230232
* factor may not be the same between adjacent pyramid levels.
231233
*/
232-
let zoomFactorColumns = this[_pyramid][0].totalPixelMatrixColumns / totalPixelMatrixColumns;
233-
let zoomFactorRows = this[_pyramid][0].totalPixelMatrixRows / totalPixelMatrixRows;
234-
let zoomFactor = (zoomFactorColumns + zoomFactorRows) / 2;
234+
let zoomFactor = this[_pyramid][nLevels-1].totalPixelMatrixRows / totalPixelMatrixRows;
235235
resolutions.push(zoomFactor);
236236

237237
/*
@@ -367,8 +367,8 @@ class DICOMMicroscopyViewer {
367367
*/
368368
const extent = [
369369
0, // min X
370-
-pyramid[0].totalPixelMatrixRows, // min Y
371-
pyramid[0].totalPixelMatrixColumns, // max X
370+
-pyramid[nLevels-1].totalPixelMatrixRows, // min Y
371+
pyramid[nLevels-1].totalPixelMatrixColumns, // max X
372372
-1 // max Y
373373
];
374374

@@ -418,9 +418,9 @@ class DICOMMicroscopyViewer {
418418
* DICOM pixel spacing has millimeter unit while the projection has
419419
* has meter unit.
420420
*/
421-
let spacing = pyramid[0].pixelSpacing[1] / 10**3;
422-
let metricRes = pixelRes * spacing;
423-
return(metricRes);
421+
let spacing = pyramid[nLevels-1].pixelSpacing[0] / 10**3;
422+
let res = pixelRes * spacing;
423+
return(res);
424424
}
425425
});
426426
/*
@@ -772,14 +772,13 @@ class DICOMMicroscopyViewer {
772772
}
773773

774774
addScoord(item) {
775-
let geometry = _graphic2Geometry(item);
775+
let geometry = _scoord2Geometry(item);
776776
let feature = new Feature({geometry});
777-
this[_features].push(feature);
778777
this[_drawingSource].addFeature(feature);
779778
}
780779

781780
updateScoord(index, item) {
782-
let geometry = _graphic2Geometry(item);
781+
let geometry = _scoord2Geometry(item);
783782
let feature = new Feature({geometry});
784783
this[_features].setAt(index, feature);
785784
}

0 commit comments

Comments
 (0)