Skip to content

Commit

Permalink
Add seriesUid, update data object, fixes #1813
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Nov 29, 2024
1 parent c15351c commit 51fa786
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/image/domReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ import {Geometry} from '../image/geometry';
import {Image} from '../image/image';
import {Point3D} from '../math/point';

/**
* Convert a string into an UID.
*
* @param {string} str The input string.
* @returns {string} The input string converted to numbers

Check failure on line 11 in src/image/domReader.js

View workflow job for this annotation

GitHub Actions / build

Sentences must end with a period
* using parseInt with a 36 radix
* (10 digits from 0 to 9 + 26 digits from a to z)
*/
function toUID(str) {
return parseInt(str, 36).toString();
}

/**
* Create a simple array buffer from an ImageData buffer.
*
Expand Down Expand Up @@ -87,29 +99,40 @@ export function getViewFromDOMImage(domImage, origin, index) {

// image properties
const info = {};
let seriesUID;
if (typeof origin === 'string') {
info['origin'] = {value: origin};
seriesUID = toUID(origin);
} else {
info['fileName'] = {value: origin.name};
seriesUID = toUID(origin.name);
info['fileType'] = {value: origin.type};
info['fileLastModifiedDate'] = {value: origin.lastModified};
}
info['imageWidth'] = {value: width};
info['imageHeight'] = {value: height};

// image identifier (~UID like)
const sliceIndex = index ? index : 0;
info['imageUid'] = {value: sliceIndex};
// series identifier (~UID like)
info['seriesUid'] = {value: seriesUID};

// create view
const imageBuffer = imageDataToBuffer(imageData);
const image = getDefaultImage(
width, height, sliceIndex, imageBuffer, 1, sliceIndex.toString());

// add seriesUID to meta
const meta = image.getMeta();
meta.SeriesInstanceUID = seriesUID;
image.setMeta(meta);

// return
return {
data: {
image: image,
info: info
meta: info
},
source: origin
};
Expand Down Expand Up @@ -140,17 +163,24 @@ export function getViewFromDOMVideo(

// video properties
const info = {};
let seriesUID;
if (typeof origin === 'string') {
info['origin'] = {value: origin};
seriesUID = toUID(origin);
} else {
info['fileName'] = {value: origin.name};
seriesUID = toUID(origin.name);
info['fileType'] = {value: origin.type};
info['fileLastModifiedDate'] = {value: origin.lastModified};
}
info['imageWidth'] = {value: width};
info['imageHeight'] = {value: height};
info['numberOfFrames'] = {value: numberOfFrames};

// image identifier (~UID like)
info['imageUid'] = {value: 0};
// series identifier (~UID like)
info['seriesUid'] = {value: seriesUID};

// draw the image in the canvas in order to get its data
const canvas = document.createElement('canvas');
Expand Down Expand Up @@ -187,11 +217,15 @@ export function getViewFromDOMVideo(
// create view
image = getDefaultImage(
width, height, 1, imgBuffer, numberOfFrames, dataIndex.toString());
// add seriesUID to meta
const meta = image.getMeta();
meta.SeriesInstanceUID = seriesUID;
image.setMeta(meta);
// call callback
onloaditem({
data: {
image: image,
info: info
meta: info
},
source: origin
});
Expand Down

0 comments on commit 51fa786

Please sign in to comment.