Skip to content

Commit 44e860b

Browse files
author
hackermd
committed
Fix handling of concatenations and tiled full
1 parent 2d30e29 commit 44e860b

File tree

3 files changed

+52
-42
lines changed

3 files changed

+52
-42
lines changed

build/dicom-microscopy-viewer.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49406,7 +49406,6 @@
4940649406

4940749407
const studyInstanceUID = metadata['0020000D']['Value'][0];
4940849408
const seriesInstanceUID = metadata['0020000E']['Value'][0];
49409-
const sopInstanceUID = metadata['00080018']['Value'][0];
4941049409
const rows = metadata['00280010']['Value'][0];
4941149410
const columns = metadata['00280011']['Value'][0];
4941249411
const totalPixelMatrixColumns = metadata['00480006']['Value'][0];
@@ -49433,20 +49432,26 @@
4943349432

4943449433
let tilesPerRow = Math.ceil(totalPixelMatrixColumns / columns);
4943549434
const frameMapping = {};
49435+
// We may update the SOPInstanceUID when reassembling concatentations
49436+
let sopInstanceUID = metadata['00080018']['Value'][0];
49437+
let sopInstanceUIDOfConcatenationSource = null;
49438+
let frameOffsetNumber = 0;
49439+
if ('00209161' in metadata) {
49440+
sopInstanceUIDOfConcatenationSource = metadata['00209161']['Value'][0];
49441+
frameOffsetNumber = Number(metadata['00209228']['Value'][0]);
49442+
}
4943649443
if (dimensionOrganizationType === 'TILED_FULL') {
49437-
let frameOffsetNumber = 0;
49438-
if ('00209161' in metadata) {
49439-
frameOffsetNumber = Number(metadata['00209228']['Value'][0]);
49440-
}
4944149444
let offset = frameOffsetNumber + 1;
4944249445
let limit = frameOffsetNumber + numberOfFrames;
4944349446
for (let j = offset; j <= limit; j++) {
49444-
let rowIndex = Math.ceil(j / tilesPerRow);
49445-
let rowFraction = 1 - (rowIndex - (j / tilesPerRow));
49446-
let colIndex = Math.ceil(totalPixelMatrixColumns * rowFraction / columns);
49447+
let rowFraction = j / tilesPerRow;
49448+
let rowIndex = Math.ceil(rowFraction);
49449+
let colIndex = j - (rowIndex * tilesPerRow) + tilesPerRow;
49450+
// let colFraction = 1 - (rowIndex - rowFraction);
49451+
// let colIndex = Math.ceil((totalPixelMatrixColumns * colFraction) / columns);
4944749452
let index = rowIndex + '-' + colIndex;
4944849453
let frameNumber = j - offset + 1;
49449-
frameMapping[index] = frameNumber;
49454+
frameMapping[index] = `${sopInstanceUID}/frames/${frameNumber}`;
4945049455
}
4945149456
} else {
4945249457
const perFrameFunctionalGroupsSequence = metadata['52009230']['Value'];
@@ -49458,10 +49463,14 @@
4945849463
let colIndex = Math.ceil(columnPositionInTotalPixelMatrix / rows);
4945949464
let index = rowIndex + '-' + colIndex;
4946049465
let frameNumber = j + 1;
49461-
frameMapping[index] = frameNumber;
49466+
frameMapping[index] = `${sopInstanceUID}/frames/${frameNumber}`;
4946249467
}
4946349468
}
4946449469

49470+
if (sopInstanceUIDOfConcatenationSource) {
49471+
sopInstanceUID = sopInstanceUIDOfConcatenationSource;
49472+
}
49473+
4946549474
return({
4946649475
studyInstanceUID,
4946749476
seriesInstanceUID,
@@ -50198,7 +50207,7 @@
5019850207
const type = geometry.getType();
5019950208
if (type === 'Point') {
5020050209
let coordinates = geometry.getCoordinates();
50201-
return _geometryCoordinates2scoordCoordinates(coordinates);
50210+
coordinates = _geometryCoordinates2scoordCoordinates(coordinates);
5020250211
return new Point$1(coordinates);
5020350212
} else if (type === 'Polygon') {
5020450213
/*
@@ -50331,7 +50340,7 @@
5033150340
for (let i = 0; i < metadata.length; i++) {
5033250341
const cols = metadata[i].totalPixelMatrixColumns;
5033350342
const rows = metadata[i].totalPixelMatrixRows;
50334-
const paths = metadata[i].paths;
50343+
const mapping = metadata[i].frameMapping;
5033550344
/*
5033650345
* Instances may be broken down into multiple concatentation parts.
5033750346
* Therefore, we have to re-assemble instance metadata.
@@ -50348,11 +50357,8 @@
5034850357
}
5034950358
}
5035050359
if (alreadyExists) {
50351-
/*
50352-
* Update "paths" with information obtained from current
50353-
* concatentation part.
50354-
*/
50355-
Object.assign(this[_pyramid][index].paths, paths);
50360+
// Update with information obtained from current concatentation part.
50361+
Object.assign(this[_pyramid][index].frameMapping, mapping);
5035650362
} else {
5035750363
this[_pyramid].push(metadata[i]);
5035850364
}
@@ -50367,6 +50373,7 @@
5036750373
return 0;
5036850374
}
5036950375
});
50376+
console.log(this[_pyramid]);
5037050377

5037150378
/*
5037250379
* Collect relevant information from DICOM metadata for each pyramid
@@ -50435,16 +50442,15 @@
5043550442
*/
5043650443
let x = -(tileCoord[2] + 1) + 1;
5043750444
let index = x + "-" + y;
50438-
let frameNumber = pyramid[z].frameMapping[index];
50439-
if (frameNumber === undefined) {
50445+
let path = pyramid[z].frameMapping[index];
50446+
if (path === undefined) {
5044050447
console.warn("tile " + index + " not found at level " + z);
5044150448
return(null);
5044250449
}
5044350450
let url = options.client.baseUrl +
5044450451
"/studies/" + pyramid[z].studyInstanceUID +
5044550452
"/series/" + pyramid[z].seriesInstanceUID +
50446-
'/instances/' + pyramid[z].sopInstanceUID +
50447-
'/frames/' + frameNumber;
50453+
'/instances/' + path;
5044850454
return(url);
5044950455
}
5045050456

src/api.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function _geometry2Scoord(geometry) {
3535
const type = geometry.getType()
3636
if (type === 'Point') {
3737
let coordinates = geometry.getCoordinates();
38-
return _geometryCoordinates2scoordCoordinates(coordinates);
38+
coordinates = _geometryCoordinates2scoordCoordinates(coordinates);
3939
return new Point(coordinates);
4040
} else if (type === 'Polygon') {
4141
/*
@@ -170,7 +170,7 @@ class DICOMMicroscopyViewer {
170170
for (let i = 0; i < metadata.length; i++) {
171171
const cols = metadata[i].totalPixelMatrixColumns;
172172
const rows = metadata[i].totalPixelMatrixRows;
173-
const paths = metadata[i].paths;
173+
const mapping = metadata[i].frameMapping;
174174
/*
175175
* Instances may be broken down into multiple concatentation parts.
176176
* Therefore, we have to re-assemble instance metadata.
@@ -187,11 +187,8 @@ class DICOMMicroscopyViewer {
187187
}
188188
}
189189
if (alreadyExists) {
190-
/*
191-
* Update "paths" with information obtained from current
192-
* concatentation part.
193-
*/
194-
Object.assign(this[_pyramid][index].paths, paths);
190+
// Update with information obtained from current concatentation part.
191+
Object.assign(this[_pyramid][index].frameMapping, mapping);
195192
} else {
196193
this[_pyramid].push(metadata[i]);
197194
}
@@ -206,6 +203,7 @@ class DICOMMicroscopyViewer {
206203
return 0;
207204
}
208205
});
206+
console.log(this[_pyramid])
209207

210208
/*
211209
* Collect relevant information from DICOM metadata for each pyramid
@@ -284,16 +282,15 @@ class DICOMMicroscopyViewer {
284282
*/
285283
let x = -(tileCoord[2] + 1) + 1;
286284
let index = x + "-" + y;
287-
let frameNumber = pyramid[z].frameMapping[index];
288-
if (frameNumber === undefined) {
285+
let path = pyramid[z].frameMapping[index];
286+
if (path === undefined) {
289287
console.warn("tile " + index + " not found at level " + z);
290288
return(null);
291289
}
292290
let url = options.client.baseUrl +
293291
"/studies/" + pyramid[z].studyInstanceUID +
294292
"/series/" + pyramid[z].seriesInstanceUID +
295-
'/instances/' + pyramid[z].sopInstanceUID +
296-
'/frames/' + frameNumber;
293+
'/instances/' + path;
297294
return(url);
298295
}
299296

src/metadata.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ function formatImageMetadata(metadata) {
1313

1414
const studyInstanceUID = metadata['0020000D']['Value'][0];
1515
const seriesInstanceUID = metadata['0020000E']['Value'][0];
16-
const sopInstanceUID = metadata['00080018']['Value'][0];
1716
const rows = metadata['00280010']['Value'][0];
1817
const columns = metadata['00280011']['Value'][0];
1918
const totalPixelMatrixColumns = metadata['00480006']['Value'][0];
@@ -41,20 +40,24 @@ function formatImageMetadata(metadata) {
4140
let tilesPerRow = Math.ceil(totalPixelMatrixColumns / columns);
4241
let tilesPerColumn = Math.ceil(totalPixelMatrixRows / rows);
4342
const frameMapping = {};
43+
// We may update the SOPInstanceUID when reassembling concatentations
44+
let sopInstanceUID = metadata['00080018']['Value'][0];
45+
let sopInstanceUIDOfConcatenationSource = null;
46+
let frameOffsetNumber = 0;
47+
if ('00209161' in metadata) {
48+
sopInstanceUIDOfConcatenationSource = metadata['00209161']['Value'][0];
49+
frameOffsetNumber = Number(metadata['00209228']['Value'][0]);
50+
}
4451
if (dimensionOrganizationType === 'TILED_FULL') {
45-
let frameOffsetNumber = 0;
46-
if ('00209161' in metadata) {
47-
frameOffsetNumber = Number(metadata['00209228']['Value'][0]);
48-
}
4952
let offset = frameOffsetNumber + 1;
5053
let limit = frameOffsetNumber + numberOfFrames;
5154
for (let j = offset; j <= limit; j++) {
52-
let rowIndex = Math.ceil(j / tilesPerRow);
53-
let rowFraction = 1 - (rowIndex - (j / tilesPerRow));
54-
let colIndex = Math.ceil(totalPixelMatrixColumns * rowFraction / columns);
55+
let rowFraction = j / tilesPerRow;
56+
let rowIndex = Math.ceil(rowFraction);
57+
let colIndex = j - (rowIndex * tilesPerRow) + tilesPerRow;
5558
let index = rowIndex + '-' + colIndex;
5659
let frameNumber = j - offset + 1;
57-
frameMapping[index] = frameNumber;
60+
frameMapping[index] = `${sopInstanceUID}/frames/${frameNumber}`;
5861
}
5962
} else {
6063
const perFrameFunctionalGroupsSequence = metadata['52009230']['Value'];
@@ -66,10 +69,14 @@ function formatImageMetadata(metadata) {
6669
let colIndex = Math.ceil(columnPositionInTotalPixelMatrix / rows);
6770
let index = rowIndex + '-' + colIndex;
6871
let frameNumber = j + 1;
69-
frameMapping[index] = frameNumber;
72+
frameMapping[index] = `${sopInstanceUID}/frames/${frameNumber}`;
7073
}
7174
}
7275

76+
if (sopInstanceUIDOfConcatenationSource) {
77+
sopInstanceUID = sopInstanceUIDOfConcatenationSource;
78+
}
79+
7380
return({
7481
studyInstanceUID,
7582
seriesInstanceUID,

0 commit comments

Comments
 (0)