fix(measurements): Update the calibration tool to match changes in CS3D (#3505)

This change makes the OHIF side consistent with the CS3D user calibration settings, and will correctly display px and rounding values consistent with the CS3D display.
This commit is contained in:
Bill Wallace authored and GitHub committed 2023-09-15 10:50:23 -04:00
1 parent bd7f9592ea
commit 38af3112ec
8 files changed
+177 -90

No files matched your search

@@ -68,7 +68,7 @@ class MetadataProvider {
if (!instance) {
return;
}
}
return (frameNumber && combineFrameInstance(frameNumber, instance)) || instance;
}
@@ -114,8 +114,20 @@ class MetadataProvider {
return this._getCornerstoneDICOMImageLoaderTag(naturalizedTagOrWADOImageLoaderTag, instance);
}
/**
* Adds a new handler for the given tag. The handler will be provided an
* instance object that it can read values from.
*/
public addHandler(
wadoImageLoaderTag: string,
handler
) {
WADO_IMAGE_LOADER[wadoImageLoaderTag] = handler;
}
_getCornerstoneDICOMImageLoaderTag(wadoImageLoaderTag, instance) {
let metadata;
let metadata = WADO_IMAGE_LOADER[wadoImageLoaderTag]?.(instance);
if (metadata) return metadata;
switch (wadoImageLoaderTag) {
case WADO_IMAGE_LOADER_TAGS.GENERAL_SERIES_MODULE:
@@ -153,45 +165,6 @@ class MetadataProvider {
patientSex: instance.PatientSex,
};
break;
case WADO_IMAGE_LOADER_TAGS.IMAGE_PLANE_MODULE:
const { ImageOrientationPatient } = instance;
// Fallback for DX images.
// TODO: We should use the rest of the results of this function
// to update the UI somehow
const { PixelSpacing } = getPixelSpacingInformation(instance);
let rowPixelSpacing;
let columnPixelSpacing;
let rowCosines;
let columnCosines;
if (PixelSpacing) {
rowPixelSpacing = PixelSpacing[0];
columnPixelSpacing = PixelSpacing[1];
}
if (ImageOrientationPatient) {
rowCosines = ImageOrientationPatient.slice(0, 3);
columnCosines = ImageOrientationPatient.slice(3, 6);
}
metadata = {
frameOfReferenceUID: instance.FrameOfReferenceUID,
rows: toNumber(instance.Rows),
columns: toNumber(instance.Columns),
imageOrientationPatient: toNumber(ImageOrientationPatient),
rowCosines: toNumber(rowCosines || [0, 1, 0]),
columnCosines: toNumber(columnCosines || [0, 0, -1]),
imagePositionPatient: toNumber(instance.ImagePositionPatient || [0, 0, 0]),
sliceThickness: toNumber(instance.SliceThickness),
sliceLocation: toNumber(instance.SliceLocation),
pixelSpacing: toNumber(PixelSpacing || 1),
rowPixelSpacing: toNumber(rowPixelSpacing || 1),
columnPixelSpacing: toNumber(columnPixelSpacing || 1),
};
break;
case WADO_IMAGE_LOADER_TAGS.IMAGE_PIXEL_MODULE:
metadata = {
samplesPerPixel: toNumber(instance.SamplesPerPixel),
@@ -484,11 +457,54 @@ const metadataProvider = new MetadataProvider();
export default metadataProvider;
const WADO_IMAGE_LOADER = {
imagePlaneModule: instance => {
const { ImageOrientationPatient } = instance;
// Fallback for DX images.
// TODO: We should use the rest of the results of this function
// to update the UI somehow
const { PixelSpacing } = getPixelSpacingInformation(instance);
let rowPixelSpacing;
let columnPixelSpacing;
let rowCosines;
let columnCosines;
if (PixelSpacing) {
rowPixelSpacing = PixelSpacing[0];
columnPixelSpacing = PixelSpacing[1];
}
if (ImageOrientationPatient) {
rowCosines = ImageOrientationPatient.slice(0, 3);
columnCosines = ImageOrientationPatient.slice(3, 6);
}
return {
frameOfReferenceUID: instance.FrameOfReferenceUID,
rows: toNumber(instance.Rows),
columns: toNumber(instance.Columns),
imageOrientationPatient: toNumber(ImageOrientationPatient),
rowCosines: toNumber(rowCosines || [0, 1, 0]),
columnCosines: toNumber(columnCosines || [0, 0, -1]),
imagePositionPatient: toNumber(
instance.ImagePositionPatient || [0, 0, 0]
),
sliceThickness: toNumber(instance.SliceThickness),
sliceLocation: toNumber(instance.SliceLocation),
pixelSpacing: toNumber(PixelSpacing || 1),
rowPixelSpacing: rowPixelSpacing ? toNumber(rowPixelSpacing) : null,
columnPixelSpacing: columnPixelSpacing ? toNumber(columnPixelSpacing) : null,
};
},
};
const WADO_IMAGE_LOADER_TAGS = {
// dicomImageLoader specific
GENERAL_SERIES_MODULE: 'generalSeriesModule',
PATIENT_STUDY_MODULE: 'patientStudyModule',
IMAGE_PLANE_MODULE: 'imagePlaneModule',
IMAGE_PIXEL_MODULE: 'imagePixelModule',
VOI_LUT_MODULE: 'voiLutModule',
MODALITY_LUT_MODULE: 'modalityLutModule',
+30 -5
View File
@@ -1,9 +1,34 @@
/**
* @param {string | number} value
* @param {number} decimals
* Truncates decimal points to that there is at least 1+precision significant
* digits.
*
* For example, with the default precision 2 (3 significant digits)
* * Values larger than 100 show no information after the decimal point
* * Values between 10 and 99 show 1 decimal point
* * Values between 1 and 9 show 2 decimal points
*
* @param value - to return a fixed measurement value from
* @param precision - defining how many digits after 1..9 are desired
*/
function _round(value, decimals) {
return Number(value).toFixed(decimals);
function roundNumber(value: string | number, precision = 2): string {
if (value === undefined || value === null || value === '') return 'NaN';
value = Number(value);
if (value < 0.0001) return `${value}`;
const fixedPrecision =
value >= 100
? precision - 2
: value >= 10
? precision - 1
: value >= 1
? precision
: value >= 0.1
? precision + 1
: value >= 0.01
? precision + 2
: value >= 0.001
? precision + 3
: precision + 4;
return value.toFixed(fixedPrecision);
}
export default _round;
export default roundNumber;