@cornerstonejs/core
Version:
Cornerstone3D Core
83 lines (82 loc) • 3.2 kB
JavaScript
import * as metaData from '../metaData.js';
import { MetadataModules, VOILUTFunctionType } from '../enums/index.js';
export function getValidVOILUTFunction(voiLUTFunction) {
if (!Object.values(VOILUTFunctionType).includes(voiLUTFunction)) {
return VOILUTFunctionType.LINEAR;
}
return voiLUTFunction;
}
export function getImagePlaneModule(imageId) {
const imagePlaneModule = metaData.get(MetadataModules.IMAGE_PLANE, imageId);
if (imagePlaneModule.usingDefaultValues !== undefined) {
return imagePlaneModule;
}
if (imagePlaneModule.columnPixelSpacing &&
imagePlaneModule.rowPixelSpacing &&
imagePlaneModule.columnCosines &&
imagePlaneModule.rowCosines &&
imagePlaneModule.imagePositionPatient &&
imagePlaneModule.imageOrientationPatient) {
return imagePlaneModule;
}
const newImagePlaneModule = {
...imagePlaneModule,
usingDefaultValues: true,
};
newImagePlaneModule.columnPixelSpacing ||= 1;
newImagePlaneModule.rowPixelSpacing ||= 1;
newImagePlaneModule.columnCosines ||= [0, 1, 0];
newImagePlaneModule.rowCosines ||= [1, 0, 0];
newImagePlaneModule.imagePositionPatient ||= [0, 0, 0];
newImagePlaneModule.imageOrientationPatient ||= new Float32Array([
1, 0, 0, 0, 1, 0,
]);
return newImagePlaneModule;
}
export function calibrateImagePlaneModule(imageId, imagePlaneModule, currentCalibration) {
const calibration = metaData.get('calibratedPixelSpacing', imageId);
const isUpdated = currentCalibration !== calibration;
const { scale } = calibration || {};
const hasPixelSpacing = scale > 0 || imagePlaneModule.rowPixelSpacing > 0;
imagePlaneModule.calibration = calibration;
if (!isUpdated) {
return { imagePlaneModule, hasPixelSpacing };
}
return {
imagePlaneModule,
hasPixelSpacing,
calibrationEvent: {
scale,
calibration,
},
};
}
export function buildMetadata(image) {
const imageId = image.imageId;
const { pixelRepresentation, bitsAllocated, bitsStored, highBit, photometricInterpretation, samplesPerPixel, } = metaData.get(MetadataModules.IMAGE_PIXEL, imageId);
const { windowWidth, windowCenter, voiLUTFunction } = image;
const { modality } = metaData.get(MetadataModules.GENERAL_SERIES, imageId);
const imageIdScalingFactor = metaData.get(MetadataModules.SCALING, imageId);
const calibration = metaData.get(MetadataModules.CALIBRATION, imageId);
const voiLUTFunctionEnum = getValidVOILUTFunction(voiLUTFunction);
const imagePlaneModule = getImagePlaneModule(imageId);
return {
calibration,
scalingFactor: imageIdScalingFactor,
voiLUTFunction: voiLUTFunctionEnum,
modality,
imagePlaneModule,
imagePixelModule: {
bitsAllocated,
bitsStored,
samplesPerPixel,
highBit,
photometricInterpretation,
pixelRepresentation,
windowWidth: windowWidth,
windowCenter: windowCenter,
modality,
voiLUTFunction: voiLUTFunctionEnum,
},
};
}