feat: crosshair mpr
This commit is contained in:
parent
c73fdb6a6d
commit
ae02206a60
|
@ -23,7 +23,6 @@
|
||||||
"js-cookie": "3.0.5",
|
"js-cookie": "3.0.5",
|
||||||
"three": "0.156.1",
|
"three": "0.156.1",
|
||||||
"path-to-regexp": "6.2.1",
|
"path-to-regexp": "6.2.1",
|
||||||
"cornerstone-core": "2.6.1",
|
|
||||||
"dicom-parser": "1.8.21",
|
"dicom-parser": "1.8.21",
|
||||||
"@msgpack/msgpack": "3.0.0-beta2",
|
"@msgpack/msgpack": "3.0.0-beta2",
|
||||||
"pako": "2.1.0",
|
"pako": "2.1.0",
|
||||||
|
@ -32,8 +31,9 @@
|
||||||
"@cornerstonejs/core": "1.41.0",
|
"@cornerstonejs/core": "1.41.0",
|
||||||
"dcmjs": "0.30.0",
|
"dcmjs": "0.30.0",
|
||||||
"dicomweb-client": "0.10.3",
|
"dicomweb-client": "0.10.3",
|
||||||
"@cornerstonejs/tools": "3.0.2",
|
"@cornerstonejs/tools": "1.41.0",
|
||||||
"@cornerstonejs/streaming-image-volume-loader": "1.41.0"
|
"@cornerstonejs/streaming-image-volume-loader": "1.41.0",
|
||||||
|
"@cornerstonejs/calculate-suv": "1.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.21.8",
|
"@babel/core": "^7.21.8",
|
||||||
|
|
143
apps/aorta/public/d-apple.json
Normal file
143
apps/aorta/public/d-apple.json
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
[
|
||||||
|
"5.0.37",
|
||||||
|
[
|
||||||
|
"apple a14",
|
||||||
|
"14",
|
||||||
|
"a14 apple",
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
2704,
|
||||||
|
1756,
|
||||||
|
120
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"apple m1",
|
||||||
|
"1",
|
||||||
|
"apple m1",
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
2880,
|
||||||
|
1800,
|
||||||
|
198
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"apple m1 max",
|
||||||
|
"1",
|
||||||
|
"apple m1 max",
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
3456,
|
||||||
|
2234,
|
||||||
|
556
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"apple m1 pro",
|
||||||
|
"1",
|
||||||
|
"apple m1 pro",
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
3024,
|
||||||
|
1964,
|
||||||
|
342
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"apple m1 ultra",
|
||||||
|
"1",
|
||||||
|
"apple m1 ultra",
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
5120,
|
||||||
|
2880,
|
||||||
|
437
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"apple m2",
|
||||||
|
"2",
|
||||||
|
"apple m2",
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
2880,
|
||||||
|
1800,
|
||||||
|
60
|
||||||
|
],
|
||||||
|
[
|
||||||
|
2940,
|
||||||
|
1912,
|
||||||
|
209
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"apple m2 max",
|
||||||
|
"2",
|
||||||
|
"apple m2 max",
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
3456,
|
||||||
|
2234,
|
||||||
|
120
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"apple m2 pro",
|
||||||
|
"2",
|
||||||
|
"apple m2 pro",
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
3024,
|
||||||
|
1964,
|
||||||
|
120
|
||||||
|
],
|
||||||
|
[
|
||||||
|
5120,
|
||||||
|
2880,
|
||||||
|
60
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"apple m2 ultra",
|
||||||
|
"2",
|
||||||
|
"apple m2 ultra",
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
5120,
|
||||||
|
2880,
|
||||||
|
60
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"apple paravirtual device",
|
||||||
|
"",
|
||||||
|
"apple device paravirtual",
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
1024,
|
||||||
|
768,
|
||||||
|
30
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
|
@ -31,5 +31,5 @@ export const proxyMap: TProxyMap = {
|
||||||
target: "http://localhost:5000/",
|
target: "http://localhost:5000/",
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
pathRewrite: { "^/py": "" },
|
pathRewrite: { "^/py": "" },
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,7 @@ interface Configuration extends WebpackConfiguration {
|
||||||
devServer?: WebpackDevServerConfiguration;
|
devServer?: WebpackDevServerConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
const host = "127.0.0.1";
|
const host = "0.0.0.0";
|
||||||
const port = 9000;
|
const port = 9000;
|
||||||
|
|
||||||
// 合并公共配置,并添加开发环境配置
|
// 合并公共配置,并添加开发环境配置
|
||||||
|
|
|
@ -5,6 +5,9 @@ import cornerstoneDICOMImageLoader from "@cornerstonejs/dicom-image-loader";
|
||||||
import { getPixelSpacingInformation } from "./getPixelSpacingInformation";
|
import { getPixelSpacingInformation } from "./getPixelSpacingInformation";
|
||||||
import { convertMultiframeImageIds } from "./convertMultiframeImageIds";
|
import { convertMultiframeImageIds } from "./convertMultiframeImageIds";
|
||||||
import { removeInvalidTags } from "./removeInvalidTags";
|
import { removeInvalidTags } from "./removeInvalidTags";
|
||||||
|
import getPTImageIdInstanceMetadata from "./getPTImageIdInstanceMetadata";
|
||||||
|
import { calculateSUVScalingFactors } from "@cornerstonejs/calculate-suv";
|
||||||
|
import ptScalingMetaDataProvider from "./ptScalingMetaDataProvider";
|
||||||
|
|
||||||
const { DicomMetaDictionary } = dcmjs.data;
|
const { DicomMetaDictionary } = dcmjs.data;
|
||||||
const { calibratedPixelSpacingMetadataProvider } = utilities;
|
const { calibratedPixelSpacingMetadataProvider } = utilities;
|
||||||
|
@ -44,11 +47,22 @@ export const createImageIdsAndCacheMetaData = async (
|
||||||
console.log("modality", modality);
|
console.log("modality", modality);
|
||||||
|
|
||||||
let imageIds = instances.map((instanceMetaData: any) => {
|
let imageIds = instances.map((instanceMetaData: any) => {
|
||||||
const seriesInstanceUID = instanceMetaData[SERIES_INSTANCE_UID].Value[0];
|
const SeriesInstanceUID = instanceMetaData[SERIES_INSTANCE_UID].Value[0];
|
||||||
const sopInstanceUIDToUse =
|
const SOPInstanceUIDToUse =
|
||||||
options.SOPInstanceUID || instanceMetaData[SOP_INSTANCE_UID].Value[0];
|
options.SOPInstanceUID || instanceMetaData[SOP_INSTANCE_UID].Value[0];
|
||||||
|
|
||||||
const imageId = `wadors:${options.wadoRsRoot}/studies/${options.StudyInstanceUID}/series/${seriesInstanceUID}/instances/${sopInstanceUIDToUse}/frames/1`;
|
const prefix = "wadors:";
|
||||||
|
|
||||||
|
const imageId =
|
||||||
|
prefix +
|
||||||
|
options.wadoRsRoot +
|
||||||
|
"/studies/" +
|
||||||
|
options.StudyInstanceUID +
|
||||||
|
"/series/" +
|
||||||
|
SeriesInstanceUID +
|
||||||
|
"/instances/" +
|
||||||
|
SOPInstanceUIDToUse +
|
||||||
|
"/frames/1";
|
||||||
|
|
||||||
cornerstoneDICOMImageLoader.wadors.metaDataManager.add(
|
cornerstoneDICOMImageLoader.wadors.metaDataManager.add(
|
||||||
imageId,
|
imageId,
|
||||||
|
@ -62,6 +76,7 @@ export const createImageIdsAndCacheMetaData = async (
|
||||||
imageIds.forEach((imageId) => {
|
imageIds.forEach((imageId) => {
|
||||||
let instanceMetaData =
|
let instanceMetaData =
|
||||||
cornerstoneDICOMImageLoader.wadors.metaDataManager.get(imageId);
|
cornerstoneDICOMImageLoader.wadors.metaDataManager.get(imageId);
|
||||||
|
|
||||||
instanceMetaData = removeInvalidTags(instanceMetaData);
|
instanceMetaData = removeInvalidTags(instanceMetaData);
|
||||||
|
|
||||||
if (instanceMetaData) {
|
if (instanceMetaData) {
|
||||||
|
@ -81,8 +96,44 @@ export const createImageIdsAndCacheMetaData = async (
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (modality === "PT") {
|
||||||
|
const InstanceMetadataArray: any = [];
|
||||||
|
imageIds.forEach((imageId) => {
|
||||||
|
const instanceMetadata = getPTImageIdInstanceMetadata(imageId);
|
||||||
|
|
||||||
|
// TODO: Temporary fix because static-wado is producing a string, not an array of values
|
||||||
|
// (or maybe dcmjs isn't parsing it correctly?)
|
||||||
|
// It's showing up like 'DECY\\ATTN\\SCAT\\DTIM\\RAN\\RADL\\DCAL\\SLSENS\\NORM'
|
||||||
|
// but calculate-suv expects ['DECY', 'ATTN', ...]
|
||||||
|
if (typeof instanceMetadata.CorrectedImage === "string") {
|
||||||
|
instanceMetadata.CorrectedImage =
|
||||||
|
instanceMetadata.CorrectedImage.split("\\");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (instanceMetadata) {
|
||||||
|
InstanceMetadataArray.push(instanceMetadata);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (InstanceMetadataArray.length) {
|
||||||
|
try {
|
||||||
|
const suvScalingFactors = calculateSUVScalingFactors(
|
||||||
|
InstanceMetadataArray
|
||||||
|
);
|
||||||
|
InstanceMetadataArray.forEach((instanceMetadata, index) => {
|
||||||
|
ptScalingMetaDataProvider.addInstance(
|
||||||
|
imageIds[index],
|
||||||
|
suvScalingFactors[index]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return imageIds;
|
return imageIds;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
throw new Error("PACS 中数据不存在");
|
throw new Error("PACS 中数据不存在");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,211 @@
|
||||||
|
import { metaData } from "@cornerstonejs/core";
|
||||||
|
import type { InstanceMetadata } from "@cornerstonejs/calculate-suv";
|
||||||
|
|
||||||
|
export default function getPTImageIdInstanceMetadata(
|
||||||
|
imageId: string
|
||||||
|
): InstanceMetadata {
|
||||||
|
const petSequenceModule = metaData.get("petIsotopeModule", imageId);
|
||||||
|
const generalSeriesModule = metaData.get("generalSeriesModule", imageId);
|
||||||
|
const patientStudyModule = metaData.get("patientStudyModule", imageId);
|
||||||
|
|
||||||
|
const ptSeriesModule = metaData.get("petSeriesModule", imageId);
|
||||||
|
const ptImageModule = metaData.get("petImageModule", imageId);
|
||||||
|
|
||||||
|
if (!petSequenceModule) {
|
||||||
|
throw new Error("petSequenceModule metadata is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
const radiopharmaceuticalInfo = petSequenceModule.radiopharmaceuticalInfo;
|
||||||
|
|
||||||
|
const { seriesDate, seriesTime, acquisitionDate, acquisitionTime } =
|
||||||
|
generalSeriesModule;
|
||||||
|
const { patientWeight } = patientStudyModule;
|
||||||
|
const { correctedImage, units, decayCorrection } = ptSeriesModule;
|
||||||
|
|
||||||
|
if (
|
||||||
|
seriesDate === undefined ||
|
||||||
|
seriesTime === undefined ||
|
||||||
|
patientWeight === undefined ||
|
||||||
|
acquisitionDate === undefined ||
|
||||||
|
acquisitionTime === undefined ||
|
||||||
|
correctedImage === undefined ||
|
||||||
|
units === undefined ||
|
||||||
|
decayCorrection === undefined ||
|
||||||
|
radiopharmaceuticalInfo.radionuclideTotalDose === undefined ||
|
||||||
|
radiopharmaceuticalInfo.radionuclideHalfLife === undefined ||
|
||||||
|
(radiopharmaceuticalInfo.radiopharmaceuticalStartDateTime === undefined &&
|
||||||
|
seriesDate === undefined &&
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartTime === undefined)
|
||||||
|
//
|
||||||
|
) {
|
||||||
|
throw new Error("required metadata are missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
const instanceMetadata: InstanceMetadata = {
|
||||||
|
CorrectedImage: correctedImage,
|
||||||
|
Units: units,
|
||||||
|
RadionuclideHalfLife: radiopharmaceuticalInfo.radionuclideHalfLife,
|
||||||
|
RadionuclideTotalDose: radiopharmaceuticalInfo.radionuclideTotalDose,
|
||||||
|
DecayCorrection: decayCorrection,
|
||||||
|
PatientWeight: patientWeight,
|
||||||
|
SeriesDate: seriesDate,
|
||||||
|
SeriesTime: seriesTime,
|
||||||
|
AcquisitionDate: acquisitionDate,
|
||||||
|
AcquisitionTime: acquisitionTime,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartDateTime &&
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartDateTime !== undefined &&
|
||||||
|
typeof radiopharmaceuticalInfo.radiopharmaceuticalStartDateTime === "string"
|
||||||
|
) {
|
||||||
|
instanceMetadata.RadiopharmaceuticalStartDateTime =
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartDateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartDateTime &&
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartDateTime !== undefined &&
|
||||||
|
typeof radiopharmaceuticalInfo.radiopharmaceuticalStartDateTime !== "string"
|
||||||
|
) {
|
||||||
|
const dateString = convertInterfaceDateToString(
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartDateTime
|
||||||
|
);
|
||||||
|
instanceMetadata.RadiopharmaceuticalStartDateTime = dateString;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
instanceMetadata.AcquisitionDate &&
|
||||||
|
instanceMetadata.AcquisitionDate !== undefined &&
|
||||||
|
typeof instanceMetadata.AcquisitionDate !== "string"
|
||||||
|
) {
|
||||||
|
const dateString = convertInterfaceDateToString(
|
||||||
|
instanceMetadata.AcquisitionDate
|
||||||
|
);
|
||||||
|
instanceMetadata.AcquisitionDate = dateString;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
instanceMetadata.SeriesDate &&
|
||||||
|
instanceMetadata.SeriesDate !== undefined &&
|
||||||
|
typeof instanceMetadata.SeriesDate !== "string"
|
||||||
|
) {
|
||||||
|
const dateString = convertInterfaceDateToString(
|
||||||
|
instanceMetadata.SeriesDate
|
||||||
|
);
|
||||||
|
instanceMetadata.SeriesDate = dateString;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartTime &&
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartTime !== undefined &&
|
||||||
|
typeof radiopharmaceuticalInfo.radiopharmaceuticalStartTime === "string"
|
||||||
|
) {
|
||||||
|
instanceMetadata.RadiopharmaceuticalStartTime =
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartTime &&
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartTime !== undefined &&
|
||||||
|
typeof radiopharmaceuticalInfo.radiopharmaceuticalStartTime !== "string"
|
||||||
|
) {
|
||||||
|
const timeString = convertInterfaceTimeToString(
|
||||||
|
radiopharmaceuticalInfo.radiopharmaceuticalStartTime
|
||||||
|
);
|
||||||
|
instanceMetadata.RadiopharmaceuticalStartTime = timeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
instanceMetadata.AcquisitionTime &&
|
||||||
|
instanceMetadata.AcquisitionTime !== undefined &&
|
||||||
|
typeof instanceMetadata.AcquisitionTime !== "string"
|
||||||
|
) {
|
||||||
|
const timeString = convertInterfaceTimeToString(
|
||||||
|
instanceMetadata.AcquisitionTime
|
||||||
|
);
|
||||||
|
instanceMetadata.AcquisitionTime = timeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
instanceMetadata.SeriesTime &&
|
||||||
|
instanceMetadata.SeriesTime !== undefined &&
|
||||||
|
typeof instanceMetadata.SeriesTime !== "string"
|
||||||
|
) {
|
||||||
|
const timeString = convertInterfaceTimeToString(
|
||||||
|
instanceMetadata.SeriesTime
|
||||||
|
);
|
||||||
|
instanceMetadata.SeriesTime = timeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
ptImageModule.frameReferenceTime &&
|
||||||
|
ptImageModule.frameReferenceTime !== undefined
|
||||||
|
) {
|
||||||
|
instanceMetadata.FrameReferenceTime = ptImageModule.frameReferenceTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
ptImageModule.actualFrameDuration &&
|
||||||
|
ptImageModule.actualFrameDuration !== undefined
|
||||||
|
) {
|
||||||
|
instanceMetadata.ActualFrameDuration = ptImageModule.actualFrameDuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
patientStudyModule.patientSex &&
|
||||||
|
patientStudyModule.patientSex !== undefined
|
||||||
|
) {
|
||||||
|
instanceMetadata.PatientSex = patientStudyModule.patientSex;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
patientStudyModule.patientSize &&
|
||||||
|
patientStudyModule.patientSize !== undefined
|
||||||
|
) {
|
||||||
|
instanceMetadata.PatientSize = patientStudyModule.patientSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Todo: add private tags
|
||||||
|
// if (
|
||||||
|
// dicomMetaData['70531000'] ||
|
||||||
|
// dicomMetaData['70531000'] !== undefined ||
|
||||||
|
// dicomMetaData['70531009'] ||
|
||||||
|
// dicomMetaData['70531009'] !== undefined
|
||||||
|
// ) {
|
||||||
|
// const philipsPETPrivateGroup: PhilipsPETPrivateGroup = {
|
||||||
|
// SUVScaleFactor: dicomMetaData['70531000'],
|
||||||
|
// ActivityConcentrationScaleFactor: dicomMetaData['70531009'],
|
||||||
|
// };
|
||||||
|
// instanceMetadata.PhilipsPETPrivateGroup = philipsPETPrivateGroup;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (dicomMetaData['0009100d'] && dicomMetaData['0009100d'] !== undefined) {
|
||||||
|
// instanceMetadata.GEPrivatePostInjectionDateTime = dicomMetaData['0009100d'];
|
||||||
|
// }
|
||||||
|
|
||||||
|
return instanceMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertInterfaceTimeToString(time): string {
|
||||||
|
const hours = `${time.hours || "00"}`.padStart(2, "0");
|
||||||
|
const minutes = `${time.minutes || "00"}`.padStart(2, "0");
|
||||||
|
const seconds = `${time.seconds || "00"}`.padStart(2, "0");
|
||||||
|
|
||||||
|
const fractionalSeconds = `${time.fractionalSeconds || "000000"}`.padEnd(
|
||||||
|
6,
|
||||||
|
"0"
|
||||||
|
);
|
||||||
|
|
||||||
|
const timeString = `${hours}${minutes}${seconds}.${fractionalSeconds}`;
|
||||||
|
return timeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertInterfaceDateToString(date): string {
|
||||||
|
const month = `${date.month}`.padStart(2, "0");
|
||||||
|
const day = `${date.day}`.padStart(2, "0");
|
||||||
|
const dateString = `${date.year}${month}${day}`;
|
||||||
|
return dateString;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { getPTImageIdInstanceMetadata };
|
|
@ -2,10 +2,19 @@ import dicomParser from "dicom-parser";
|
||||||
import * as cornerstone from "@cornerstonejs/core";
|
import * as cornerstone from "@cornerstonejs/core";
|
||||||
import cornerstoneDICOMImageLoader from "@cornerstonejs/dicom-image-loader";
|
import cornerstoneDICOMImageLoader from "@cornerstonejs/dicom-image-loader";
|
||||||
|
|
||||||
|
window.cornerstone = cornerstone;
|
||||||
|
|
||||||
export const initCornerstoneDICOMImageLoader = () => {
|
export const initCornerstoneDICOMImageLoader = () => {
|
||||||
const { preferSizeOverAccuracy, useNorm16Texture } =
|
const { preferSizeOverAccuracy, useNorm16Texture } =
|
||||||
cornerstone.getConfiguration().rendering;
|
cornerstone.getConfiguration().rendering;
|
||||||
|
|
||||||
|
cornerstone.setConfiguration({
|
||||||
|
detectGPUConfig: {
|
||||||
|
benchmarksURL: "http://localhost:9000",
|
||||||
|
},
|
||||||
|
rendering: cornerstone.getConfiguration().rendering,
|
||||||
|
});
|
||||||
|
|
||||||
cornerstoneDICOMImageLoader.external.cornerstone = cornerstone;
|
cornerstoneDICOMImageLoader.external.cornerstone = cornerstone;
|
||||||
cornerstoneDICOMImageLoader.external.dicomParser = dicomParser;
|
cornerstoneDICOMImageLoader.external.dicomParser = dicomParser;
|
||||||
cornerstoneDICOMImageLoader.configure({
|
cornerstoneDICOMImageLoader.configure({
|
||||||
|
@ -16,8 +25,14 @@ export const initCornerstoneDICOMImageLoader = () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let maxWebWorkers = 1;
|
||||||
|
|
||||||
|
if (navigator.hardwareConcurrency) {
|
||||||
|
maxWebWorkers = Math.min(navigator.hardwareConcurrency, 7);
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
maxWebWorkers: navigator.hardwareConcurrency ?? 7,
|
maxWebWorkers,
|
||||||
startWebWorkersOnDemand: false,
|
startWebWorkersOnDemand: false,
|
||||||
taskConfiguration: {
|
taskConfiguration: {
|
||||||
decodeTask: {
|
decodeTask: {
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
|
import { useEffect, useRef } from "react";
|
||||||
|
import initDemo from "./util/initDemo.js";
|
||||||
import {
|
import {
|
||||||
Enums,
|
|
||||||
RenderingEngine,
|
RenderingEngine,
|
||||||
|
Types,
|
||||||
|
Enums,
|
||||||
setVolumesForViewports,
|
setVolumesForViewports,
|
||||||
volumeLoader,
|
volumeLoader,
|
||||||
|
getRenderingEngine,
|
||||||
} from "@cornerstonejs/core";
|
} from "@cornerstonejs/core";
|
||||||
import { createImageIdsAndCacheMetaData } from "../CornerstoneDicomLoader/createImageIdsAndCacheMetaData";
|
|
||||||
import { initCornerstone } from "../CornerstoneDicomLoader/init";
|
|
||||||
import { useEffect, useRef } from "react";
|
|
||||||
import * as cornerstoneTools from "@cornerstonejs/tools";
|
import * as cornerstoneTools from "@cornerstonejs/tools";
|
||||||
import { PublicViewportInput } from "@cornerstonejs/core/dist/types/types";
|
import createImageIdsAndCacheMetaData from "./util/createImageIdsAndCacheMetaData";
|
||||||
import { setCtTransferFunctionForVolumeActor } from "./setCtTransferFunctionForVolumeActor";
|
import { PublicViewportInput } from "@cornerstonejs/core/dist/types/types/IViewport.js";
|
||||||
interface CorsshairProps {
|
import setCtTransferFunctionForVolumeActor from "./util/setCtTransferFunctionForVolumeActor";
|
||||||
children?: JSX.Element;
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
ToolGroupManager,
|
ToolGroupManager,
|
||||||
|
@ -21,126 +20,185 @@ const {
|
||||||
StackScrollMouseWheelTool,
|
StackScrollMouseWheelTool,
|
||||||
} = cornerstoneTools;
|
} = cornerstoneTools;
|
||||||
|
|
||||||
const toolGroupId = "MY_TOOLGROUP_ID";
|
const { ViewportType } = Enums;
|
||||||
|
|
||||||
|
interface CrosshairMprProps {
|
||||||
|
children?: JSX.Element;
|
||||||
|
}
|
||||||
|
|
||||||
|
const viewportId1 = "CT_AXIAL";
|
||||||
|
const viewportId2 = "CT_SAGITTAL";
|
||||||
|
const viewportId3 = "CT_CORONAL";
|
||||||
|
const toolGroupId = "group";
|
||||||
|
|
||||||
|
const viewportColors = {
|
||||||
|
[viewportId1]: "rgb(200, 0, 0)",
|
||||||
|
[viewportId2]: "rgb(200, 200, 0)",
|
||||||
|
[viewportId3]: "rgb(0, 200, 0)",
|
||||||
|
};
|
||||||
|
|
||||||
|
const viewportReferenceLineControllable = [
|
||||||
|
viewportId1,
|
||||||
|
viewportId2,
|
||||||
|
viewportId3,
|
||||||
|
];
|
||||||
|
|
||||||
|
const viewportReferenceLineDraggableRotatable = [
|
||||||
|
viewportId1,
|
||||||
|
viewportId2,
|
||||||
|
viewportId3,
|
||||||
|
];
|
||||||
|
|
||||||
|
const viewportReferenceLineSlabThicknessControlsOn = [
|
||||||
|
viewportId1,
|
||||||
|
viewportId2,
|
||||||
|
viewportId3,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Define a unique id for the volume
|
||||||
const volumeName = "CT_VOLUME_ID"; // Id of the volume less loader prefix
|
const volumeName = "CT_VOLUME_ID"; // Id of the volume less loader prefix
|
||||||
const volumeLoaderScheme = "cornerstoneStreamingImageVolume"; // Loader id which defines which volume loader to use
|
const volumeLoaderScheme = "cornerstoneStreamingImageVolume"; // Loader id which defines which volume loader to use
|
||||||
const volumeId = `${volumeLoaderScheme}:${volumeName}`; // VolumeId with loader id + volume id
|
const volumeId = `${volumeLoaderScheme}:${volumeName}`; // VolumeId with loader id + volume id
|
||||||
|
|
||||||
const renderingEngineId = "myRenderingEngine";
|
function getReferenceLineColor(viewportId) {
|
||||||
const viewportA = "CT_AXIAL";
|
return viewportColors[viewportId];
|
||||||
const viewportB = "CT_SAGITTAL";
|
}
|
||||||
const viewportC = "CT_CORONAL";
|
|
||||||
|
|
||||||
const viewportColors = {
|
function getReferenceLineControllable(viewportId) {
|
||||||
[viewportA]: "rgb(200, 0, 0)",
|
const index = viewportReferenceLineControllable.indexOf(viewportId);
|
||||||
[viewportB]: "rgb(200, 200, 0)",
|
return index !== -1;
|
||||||
[viewportC]: "rgb(0, 200, 0)",
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const { ViewportType } = Enums;
|
function getReferenceLineDraggableRotatable(viewportId) {
|
||||||
|
const index = viewportReferenceLineDraggableRotatable.indexOf(viewportId);
|
||||||
|
return index !== -1;
|
||||||
|
}
|
||||||
|
|
||||||
const StudyInstanceUID =
|
function getReferenceLineSlabThicknessControlsOn(viewportId) {
|
||||||
"1.2.840.113564.345049290535.9692.637552042156233117.433089";
|
const index =
|
||||||
const SeriesInstanceUID =
|
viewportReferenceLineSlabThicknessControlsOn.indexOf(viewportId);
|
||||||
"1.3.12.2.1107.5.1.4.76315.30000021042706150001900118311";
|
return index !== -1;
|
||||||
|
}
|
||||||
|
|
||||||
export const Corsshair = (props: CorsshairProps) => {
|
export const CrosshairMpr = (props: CrosshairMprProps) => {
|
||||||
const viewportA = useRef(null);
|
const viewportId1Ref = useRef(null);
|
||||||
const viewportB = useRef(null);
|
const viewportId2Ref = useRef(null);
|
||||||
const viewportC = useRef(null);
|
const viewportId3Ref = useRef(null);
|
||||||
|
|
||||||
|
cornerstoneTools.addTool(StackScrollMouseWheelTool);
|
||||||
|
cornerstoneTools.addTool(CrosshairsTool);
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
await initCornerstone();
|
initDemo();
|
||||||
// Get Cornerstone imageIds and fetch metadata into RAM
|
|
||||||
|
// Get Cornerstone imageIds for the source data and fetch metadata into RAM
|
||||||
const imageIds = await createImageIdsAndCacheMetaData({
|
const imageIds = await createImageIdsAndCacheMetaData({
|
||||||
StudyInstanceUID,
|
StudyInstanceUID:
|
||||||
SeriesInstanceUID,
|
"1.2.840.113564.345049290535.9692.637552042156233117.433089",
|
||||||
|
SeriesInstanceUID:
|
||||||
|
"1.3.12.2.1107.5.1.4.76315.30000021042706150001900118311",
|
||||||
wadoRsRoot: "/dicom-web",
|
wadoRsRoot: "/dicom-web",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Define a volume in memory
|
||||||
const volume = await volumeLoader.createAndCacheVolume(volumeId, {
|
const volume = await volumeLoader.createAndCacheVolume(volumeId, {
|
||||||
imageIds,
|
imageIds,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(volume)
|
|
||||||
|
|
||||||
// Instantiate a rendering engine
|
// Instantiate a rendering engine
|
||||||
// const renderingEngine = new RenderingEngine(renderingEngineId);
|
const renderingEngineId = "myRenderingEngine";
|
||||||
|
const renderingEngine = new RenderingEngine(renderingEngineId);
|
||||||
|
|
||||||
// if (viewportA.current && viewportB.current && viewportC.current) {
|
// Create the viewports
|
||||||
// // Create the viewports
|
const viewportInputArray: PublicViewportInput[] = [
|
||||||
// const viewportInputArray: PublicViewportInput[] = [
|
{
|
||||||
// {
|
viewportId: viewportId1,
|
||||||
// viewportId: viewportA.current,
|
type: ViewportType.ORTHOGRAPHIC,
|
||||||
// type: ViewportType.ORTHOGRAPHIC,
|
element: viewportId1Ref.current!,
|
||||||
// element: viewportA.current,
|
defaultOptions: {
|
||||||
// defaultOptions: {
|
orientation: Enums.OrientationAxis.AXIAL,
|
||||||
// orientation: Enums.OrientationAxis.AXIAL,
|
background: [0, 0, 0],
|
||||||
// background: [0, 0, 0],
|
},
|
||||||
// },
|
},
|
||||||
// },
|
{
|
||||||
// {
|
viewportId: viewportId2,
|
||||||
// viewportId: viewportB.current,
|
type: ViewportType.ORTHOGRAPHIC,
|
||||||
// type: ViewportType.ORTHOGRAPHIC,
|
element: viewportId2Ref.current!,
|
||||||
// element: viewportB.current,
|
defaultOptions: {
|
||||||
// defaultOptions: {
|
orientation: Enums.OrientationAxis.SAGITTAL,
|
||||||
// orientation: Enums.OrientationAxis.SAGITTAL,
|
background: [0, 0, 0],
|
||||||
// background: [0, 0, 0],
|
},
|
||||||
// },
|
},
|
||||||
// },
|
{
|
||||||
// {
|
viewportId: viewportId3,
|
||||||
// viewportId: viewportC.current,
|
type: ViewportType.ORTHOGRAPHIC,
|
||||||
// type: ViewportType.ORTHOGRAPHIC,
|
element: viewportId3Ref.current!,
|
||||||
// element: viewportC.current,
|
defaultOptions: {
|
||||||
// defaultOptions: {
|
orientation: Enums.OrientationAxis.CORONAL,
|
||||||
// orientation: Enums.OrientationAxis.CORONAL,
|
background: [0, 0, 0],
|
||||||
// background: [0, 0, 0],
|
},
|
||||||
// },
|
},
|
||||||
// },
|
];
|
||||||
// ];
|
|
||||||
|
|
||||||
// renderingEngine.setViewports(viewportInputArray);
|
renderingEngine.setViewports(viewportInputArray);
|
||||||
|
|
||||||
// volume.load();
|
// Set the volume to load
|
||||||
|
volume.load();
|
||||||
|
|
||||||
// await setVolumesForViewports(
|
// Set volumes on the viewports
|
||||||
// renderingEngine,
|
await setVolumesForViewports(
|
||||||
// [
|
renderingEngine,
|
||||||
// {
|
[
|
||||||
// volumeId,
|
{
|
||||||
// callback: () => setCtTransferFunctionForVolumeActor,
|
volumeId,
|
||||||
// },
|
callback: setCtTransferFunctionForVolumeActor,
|
||||||
// ],
|
},
|
||||||
// [viewportA.current!, viewportB.current!, viewportC.current!]
|
],
|
||||||
// );
|
[viewportId1, viewportId2, viewportId3]
|
||||||
|
);
|
||||||
|
|
||||||
// // Render the image
|
// Define tool groups to add the segmentation display tool to
|
||||||
// renderingEngine.renderViewports([
|
const toolGroup = ToolGroupManager.createToolGroup(toolGroupId);
|
||||||
// viewportA.current!,
|
|
||||||
// viewportB.current!,
|
|
||||||
// viewportC.current!,
|
|
||||||
// ]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
// For the crosshairs to operate, the viewports must currently be
|
||||||
|
// added ahead of setting the tool active. This will be improved in the future.
|
||||||
|
toolGroup.addViewport(viewportId1, renderingEngineId);
|
||||||
|
toolGroup.addViewport(viewportId2, renderingEngineId);
|
||||||
|
toolGroup.addViewport(viewportId3, renderingEngineId);
|
||||||
|
|
||||||
|
// Manipulation Tools
|
||||||
|
toolGroup.addTool(StackScrollMouseWheelTool.toolName);
|
||||||
|
// Add Crosshairs tool and configure it to link the three viewports
|
||||||
|
// These viewports could use different tool groups. See the PET-CT example
|
||||||
|
// for a more complicated used case.
|
||||||
|
|
||||||
|
toolGroup.addTool(CrosshairsTool.toolName, {
|
||||||
|
getReferenceLineColor,
|
||||||
|
getReferenceLineControllable,
|
||||||
|
getReferenceLineDraggableRotatable,
|
||||||
|
getReferenceLineSlabThicknessControlsOn,
|
||||||
|
});
|
||||||
|
|
||||||
|
toolGroup.setToolActive(CrosshairsTool.toolName, {
|
||||||
|
bindings: [{ mouseButton: 1 }],
|
||||||
|
});
|
||||||
|
// As the Stack Scroll mouse wheel is a tool using the `mouseWheelCallback`
|
||||||
|
// hook instead of mouse buttons, it does not need to assign any mouse button.
|
||||||
|
toolGroup.setToolActive(StackScrollMouseWheelTool.toolName);
|
||||||
|
|
||||||
|
renderingEngine.renderViewports([viewportId1, viewportId2, viewportId3]);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
run();
|
run();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div>
|
||||||
style={{
|
<div style={{ display: "flex", gap: 20 }}>
|
||||||
display: "flex",
|
<div style={{ width: 300, height: 300 }} ref={viewportId1Ref}></div>
|
||||||
justifyContent: "space-evenly",
|
<div style={{ width: 300, height: 300 }} ref={viewportId2Ref}></div>
|
||||||
gap: 20,
|
<div style={{ width: 300, height: 300 }} ref={viewportId3Ref}></div>
|
||||||
height: 300,
|
</div>
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div ref={viewportA}></div>
|
|
||||||
<div ref={viewportB}></div>
|
|
||||||
<div ref={viewportC}></div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
import { metaData } from '@cornerstonejs/core';
|
||||||
|
import cornerstoneDICOMImageLoader from '@cornerstonejs/dicom-image-loader';
|
||||||
|
/**
|
||||||
|
* preloads imageIds metadata in memory
|
||||||
|
**/
|
||||||
|
async function prefetchMetadataInformation(imageIdsToPrefetch) {
|
||||||
|
for (let i = 0; i < imageIdsToPrefetch.length; i++) {
|
||||||
|
await cornerstoneDICOMImageLoader.wadouri.loadImage(imageIdsToPrefetch[i])
|
||||||
|
.promise;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFrameInformation(imageId) {
|
||||||
|
if (imageId.includes('wadors:')) {
|
||||||
|
const frameIndex = imageId.indexOf('/frames/');
|
||||||
|
const imageIdFrameless =
|
||||||
|
frameIndex > 0 ? imageId.slice(0, frameIndex + 8) : imageId;
|
||||||
|
return {
|
||||||
|
frameIndex,
|
||||||
|
imageIdFrameless,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const frameIndex = imageId.indexOf('&frame=');
|
||||||
|
let imageIdFrameless =
|
||||||
|
frameIndex > 0 ? imageId.slice(0, frameIndex + 7) : imageId;
|
||||||
|
if (!imageIdFrameless.includes('&frame=')) {
|
||||||
|
imageIdFrameless = imageIdFrameless + '&frame=';
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
frameIndex,
|
||||||
|
imageIdFrameless,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Receives a list of imageids possibly referring to multiframe dicom images
|
||||||
|
* and returns a list of imageid where each imageid referes to one frame.
|
||||||
|
* For each imageId representing a multiframe image with n frames,
|
||||||
|
* it will create n new imageids, one for each frame, and returns the new list of imageids
|
||||||
|
* If a particular imageid no refer to a mutiframe image data, it will be just copied into the new list
|
||||||
|
* @returns new list of imageids where each imageid represents a frame
|
||||||
|
*/
|
||||||
|
function convertMultiframeImageIds(imageIds) {
|
||||||
|
const newImageIds = [];
|
||||||
|
imageIds.forEach((imageId) => {
|
||||||
|
const { imageIdFrameless } = getFrameInformation(imageId);
|
||||||
|
const instanceMetaData = metaData.get('multiframeModule', imageId);
|
||||||
|
if (
|
||||||
|
instanceMetaData &&
|
||||||
|
instanceMetaData.NumberOfFrames &&
|
||||||
|
instanceMetaData.NumberOfFrames > 1
|
||||||
|
) {
|
||||||
|
const NumberOfFrames = instanceMetaData.NumberOfFrames;
|
||||||
|
for (let i = 0; i < NumberOfFrames; i++) {
|
||||||
|
const newImageId = imageIdFrameless + (i + 1);
|
||||||
|
newImageIds.push(newImageId);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newImageIds.push(imageId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return newImageIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { convertMultiframeImageIds, prefetchMetadataInformation };
|
|
@ -0,0 +1,101 @@
|
||||||
|
import { api } from 'dicomweb-client';
|
||||||
|
import dcmjs from 'dcmjs';
|
||||||
|
import { utilities } from '@cornerstonejs/core';
|
||||||
|
import cornerstoneDICOMImageLoader from '@cornerstonejs/dicom-image-loader';
|
||||||
|
import getPixelSpacingInformation from './getPixelSpacingInformation';
|
||||||
|
import { convertMultiframeImageIds } from './convertMultiframeImageIds';
|
||||||
|
import removeInvalidTags from './removeInvalidTags';
|
||||||
|
|
||||||
|
const { DicomMetaDictionary } = dcmjs.data;
|
||||||
|
const { calibratedPixelSpacingMetadataProvider } = utilities;
|
||||||
|
|
||||||
|
/**
|
||||||
|
/**
|
||||||
|
* Uses dicomweb-client to fetch metadata of a study, cache it in cornerstone,
|
||||||
|
* and return a list of imageIds for the frames.
|
||||||
|
*
|
||||||
|
* Uses the app config to choose which study to fetch, and which
|
||||||
|
* dicom-web server to fetch it from.
|
||||||
|
*
|
||||||
|
* @returns {string[]} An array of imageIds for instances in the study.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default async function createImageIdsAndCacheMetaData({
|
||||||
|
StudyInstanceUID,
|
||||||
|
SeriesInstanceUID,
|
||||||
|
SOPInstanceUID = null,
|
||||||
|
wadoRsRoot,
|
||||||
|
client = null,
|
||||||
|
}) {
|
||||||
|
const SOP_INSTANCE_UID = '00080018';
|
||||||
|
const SERIES_INSTANCE_UID = '0020000E';
|
||||||
|
const MODALITY = '00080060';
|
||||||
|
|
||||||
|
const studySearchOptions = {
|
||||||
|
studyInstanceUID: StudyInstanceUID,
|
||||||
|
seriesInstanceUID: SeriesInstanceUID,
|
||||||
|
};
|
||||||
|
|
||||||
|
client = client || new api.DICOMwebClient({ url: wadoRsRoot });
|
||||||
|
let instances = await client.retrieveSeriesMetadata(studySearchOptions);
|
||||||
|
|
||||||
|
// if sop instance is provided we should filter the instances to only include the one we want
|
||||||
|
if (SOPInstanceUID) {
|
||||||
|
instances = instances.filter((instance) => {
|
||||||
|
return instance[SOP_INSTANCE_UID].Value[0] === SOPInstanceUID;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const modality = instances[0][MODALITY].Value[0];
|
||||||
|
let imageIds = instances.map((instanceMetaData) => {
|
||||||
|
const SeriesInstanceUID = instanceMetaData[SERIES_INSTANCE_UID].Value[0];
|
||||||
|
const SOPInstanceUIDToUse =
|
||||||
|
SOPInstanceUID || instanceMetaData[SOP_INSTANCE_UID].Value[0];
|
||||||
|
|
||||||
|
const prefix = 'wadors:';
|
||||||
|
|
||||||
|
const imageId =
|
||||||
|
prefix +
|
||||||
|
wadoRsRoot +
|
||||||
|
'/studies/' +
|
||||||
|
StudyInstanceUID +
|
||||||
|
'/series/' +
|
||||||
|
SeriesInstanceUID +
|
||||||
|
'/instances/' +
|
||||||
|
SOPInstanceUIDToUse +
|
||||||
|
'/frames/1';
|
||||||
|
|
||||||
|
cornerstoneDICOMImageLoader.wadors.metaDataManager.add(
|
||||||
|
imageId,
|
||||||
|
instanceMetaData
|
||||||
|
);
|
||||||
|
return imageId;
|
||||||
|
});
|
||||||
|
|
||||||
|
// if the image ids represent multiframe information, creates a new list with one image id per frame
|
||||||
|
// if not multiframe data available, just returns the same list given
|
||||||
|
imageIds = convertMultiframeImageIds(imageIds);
|
||||||
|
|
||||||
|
imageIds.forEach((imageId) => {
|
||||||
|
let instanceMetaData =
|
||||||
|
cornerstoneDICOMImageLoader.wadors.metaDataManager.get(imageId);
|
||||||
|
|
||||||
|
// It was using JSON.parse(JSON.stringify(...)) before but it is 8x slower
|
||||||
|
instanceMetaData = removeInvalidTags(instanceMetaData);
|
||||||
|
|
||||||
|
if (instanceMetaData) {
|
||||||
|
// Add calibrated pixel spacing
|
||||||
|
const metadata = DicomMetaDictionary.naturalizeDataset(instanceMetaData);
|
||||||
|
const pixelSpacing = getPixelSpacingInformation(metadata);
|
||||||
|
|
||||||
|
if (pixelSpacing) {
|
||||||
|
calibratedPixelSpacingMetadataProvider.add(imageId, {
|
||||||
|
rowPixelSpacing: parseFloat(pixelSpacing[0]),
|
||||||
|
columnPixelSpacing: parseFloat(pixelSpacing[1]),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return imageIds;
|
||||||
|
}
|
|
@ -0,0 +1,136 @@
|
||||||
|
// See https://github.com/OHIF/Viewers/blob/94a9067fe3d291d30e25a1bda5913511388edea2/platform/core/src/utils/metadataProvider/getPixelSpacingInformation.js
|
||||||
|
|
||||||
|
export default function getPixelSpacingInformation(instance) {
|
||||||
|
// See http://gdcm.sourceforge.net/wiki/index.php/Imager_Pixel_Spacing
|
||||||
|
|
||||||
|
// TODO: Add Ultrasound region spacing
|
||||||
|
// TODO: Add manual calibration
|
||||||
|
|
||||||
|
// TODO: Use ENUMS from dcmjs
|
||||||
|
const projectionRadiographSOPClassUIDs = [
|
||||||
|
'1.2.840.10008.5.1.4.1.1.1', // CR Image Storage
|
||||||
|
'1.2.840.10008.5.1.4.1.1.1.1', // Digital X-Ray Image Storage – for Presentation
|
||||||
|
'1.2.840.10008.5.1.4.1.1.1.1.1', // Digital X-Ray Image Storage – for Processing
|
||||||
|
'1.2.840.10008.5.1.4.1.1.1.2', // Digital Mammography X-Ray Image Storage – for Presentation
|
||||||
|
'1.2.840.10008.5.1.4.1.1.1.2.1', // Digital Mammography X-Ray Image Storage – for Processing
|
||||||
|
'1.2.840.10008.5.1.4.1.1.1.3', // Digital Intra – oral X-Ray Image Storage – for Presentation
|
||||||
|
'1.2.840.10008.5.1.4.1.1.1.3.1', // Digital Intra – oral X-Ray Image Storage – for Processing
|
||||||
|
'1.2.840.10008.5.1.4.1.1.12.1', // X-Ray Angiographic Image Storage
|
||||||
|
'1.2.840.10008.5.1.4.1.1.12.1.1', // Enhanced XA Image Storage
|
||||||
|
'1.2.840.10008.5.1.4.1.1.12.2', // X-Ray Radiofluoroscopic Image Storage
|
||||||
|
'1.2.840.10008.5.1.4.1.1.12.2.1', // Enhanced XRF Image Storage
|
||||||
|
'1.2.840.10008.5.1.4.1.1.12.3', // X-Ray Angiographic Bi-plane Image Storage Retired
|
||||||
|
];
|
||||||
|
|
||||||
|
const {
|
||||||
|
PixelSpacing,
|
||||||
|
ImagerPixelSpacing,
|
||||||
|
SOPClassUID,
|
||||||
|
PixelSpacingCalibrationType,
|
||||||
|
PixelSpacingCalibrationDescription,
|
||||||
|
EstimatedRadiographicMagnificationFactor,
|
||||||
|
SequenceOfUltrasoundRegions,
|
||||||
|
} = instance;
|
||||||
|
|
||||||
|
const isProjection = projectionRadiographSOPClassUIDs.includes(SOPClassUID);
|
||||||
|
|
||||||
|
const TYPES = {
|
||||||
|
NOT_APPLICABLE: 'NOT_APPLICABLE',
|
||||||
|
UNKNOWN: 'UNKNOWN',
|
||||||
|
CALIBRATED: 'CALIBRATED',
|
||||||
|
DETECTOR: 'DETECTOR',
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!isProjection) {
|
||||||
|
return PixelSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isProjection && !ImagerPixelSpacing) {
|
||||||
|
// If only Pixel Spacing is present, and this is a projection radiograph,
|
||||||
|
// PixelSpacing should be used, but the user should be informed that
|
||||||
|
// what it means is unknown
|
||||||
|
return {
|
||||||
|
PixelSpacing,
|
||||||
|
type: TYPES.UNKNOWN,
|
||||||
|
isProjection,
|
||||||
|
};
|
||||||
|
} else if (
|
||||||
|
PixelSpacing &&
|
||||||
|
ImagerPixelSpacing &&
|
||||||
|
PixelSpacing === ImagerPixelSpacing
|
||||||
|
) {
|
||||||
|
// If Imager Pixel Spacing and Pixel Spacing are present and they have the same values,
|
||||||
|
// then the user should be informed that the measurements are at the detector plane
|
||||||
|
return {
|
||||||
|
PixelSpacing,
|
||||||
|
type: TYPES.DETECTOR,
|
||||||
|
isProjection,
|
||||||
|
};
|
||||||
|
} else if (
|
||||||
|
PixelSpacing &&
|
||||||
|
ImagerPixelSpacing &&
|
||||||
|
PixelSpacing !== ImagerPixelSpacing
|
||||||
|
) {
|
||||||
|
// If Imager Pixel Spacing and Pixel Spacing are present and they have different values,
|
||||||
|
// then the user should be informed that these are "calibrated"
|
||||||
|
// (in some unknown manner if Pixel Spacing Calibration Type and/or
|
||||||
|
// Pixel Spacing Calibration Description are absent)
|
||||||
|
return {
|
||||||
|
PixelSpacing,
|
||||||
|
type: TYPES.CALIBRATED,
|
||||||
|
isProjection,
|
||||||
|
PixelSpacingCalibrationType,
|
||||||
|
PixelSpacingCalibrationDescription,
|
||||||
|
};
|
||||||
|
} else if (!PixelSpacing && ImagerPixelSpacing) {
|
||||||
|
let CorrectedImagerPixelSpacing = ImagerPixelSpacing;
|
||||||
|
if (EstimatedRadiographicMagnificationFactor) {
|
||||||
|
// Note that in IHE Mammo profile compliant displays, the value of Imager Pixel Spacing is required to be corrected by
|
||||||
|
// Estimated Radiographic Magnification Factor and the user informed of that.
|
||||||
|
// TODO: should this correction be done before all of this logic?
|
||||||
|
CorrectedImagerPixelSpacing = ImagerPixelSpacing.map(
|
||||||
|
(pixelSpacing) =>
|
||||||
|
pixelSpacing / EstimatedRadiographicMagnificationFactor
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
console.warn(
|
||||||
|
'EstimatedRadiographicMagnificationFactor was not present. Unable to correct ImagerPixelSpacing.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
PixelSpacing: CorrectedImagerPixelSpacing,
|
||||||
|
isProjection,
|
||||||
|
};
|
||||||
|
} else if (
|
||||||
|
SequenceOfUltrasoundRegions &&
|
||||||
|
typeof SequenceOfUltrasoundRegions === 'object'
|
||||||
|
) {
|
||||||
|
const { PhysicalDeltaX, PhysicalDeltaY } = SequenceOfUltrasoundRegions;
|
||||||
|
const USPixelSpacing = [PhysicalDeltaX * 10, PhysicalDeltaY * 10];
|
||||||
|
|
||||||
|
return {
|
||||||
|
PixelSpacing: USPixelSpacing,
|
||||||
|
};
|
||||||
|
} else if (
|
||||||
|
SequenceOfUltrasoundRegions &&
|
||||||
|
Array.isArray(SequenceOfUltrasoundRegions) &&
|
||||||
|
SequenceOfUltrasoundRegions.length > 1
|
||||||
|
) {
|
||||||
|
console.warn(
|
||||||
|
'Sequence of Ultrasound Regions > one entry. This is not yet implemented, all measurements will be shown in pixels.'
|
||||||
|
);
|
||||||
|
} else if (isProjection === false && !ImagerPixelSpacing) {
|
||||||
|
// If only Pixel Spacing is present, and this is not a projection radiograph,
|
||||||
|
// we can stop here
|
||||||
|
return {
|
||||||
|
PixelSpacing,
|
||||||
|
type: TYPES.NOT_APPLICABLE,
|
||||||
|
isProjection,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
console.warn(
|
||||||
|
'Unknown combination of PixelSpacing and ImagerPixelSpacing identified. Unable to determine spacing.'
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
import dicomParser from 'dicom-parser';
|
||||||
|
import * as cornerstone from '@cornerstonejs/core';
|
||||||
|
import * as cornerstoneTools from '@cornerstonejs/tools';
|
||||||
|
import cornerstoneDICOMImageLoader from '@cornerstonejs/dicom-image-loader';
|
||||||
|
|
||||||
|
window.cornerstone = cornerstone;
|
||||||
|
window.cornerstoneTools = cornerstoneTools;
|
||||||
|
const { preferSizeOverAccuracy, useNorm16Texture } =
|
||||||
|
cornerstone.getConfiguration().rendering;
|
||||||
|
|
||||||
|
export default function initCornerstoneDICOMImageLoader() {
|
||||||
|
// TODO: 此处非常的蛇皮
|
||||||
|
cornerstone.setUseSharedArrayBuffer(false)
|
||||||
|
cornerstone.setConfiguration({
|
||||||
|
detectGPUConfig: {
|
||||||
|
benchmarksURL: "http://localhost:9000"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
cornerstoneDICOMImageLoader.external.cornerstone = cornerstone;
|
||||||
|
cornerstoneDICOMImageLoader.external.dicomParser = dicomParser;
|
||||||
|
cornerstoneDICOMImageLoader.configure({
|
||||||
|
useWebWorkers: true,
|
||||||
|
decodeConfig: {
|
||||||
|
convertFloatPixelDataToInt: false,
|
||||||
|
use16BitDataType: preferSizeOverAccuracy || useNorm16Texture,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
let maxWebWorkers = 1;
|
||||||
|
|
||||||
|
if (navigator.hardwareConcurrency) {
|
||||||
|
maxWebWorkers = Math.min(navigator.hardwareConcurrency, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
var config = {
|
||||||
|
maxWebWorkers,
|
||||||
|
startWebWorkersOnDemand: false,
|
||||||
|
taskConfiguration: {
|
||||||
|
decodeTask: {
|
||||||
|
initializeCodecsOnStartup: false,
|
||||||
|
strict: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
cornerstoneDICOMImageLoader.webWorkerManager.initialize(config);
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
import initProviders from './initProviders.js';
|
||||||
|
import initCornerstoneDICOMImageLoader from './initCornerstoneDICOMImageLoader';
|
||||||
|
import initVolumeLoader from './initVolumeLoader';
|
||||||
|
import { init as csRenderInit } from '@cornerstonejs/core';
|
||||||
|
import { init as csToolsInit } from '@cornerstonejs/tools';
|
||||||
|
|
||||||
|
export default async function initDemo() {
|
||||||
|
initProviders();
|
||||||
|
initCornerstoneDICOMImageLoader();
|
||||||
|
initVolumeLoader();
|
||||||
|
await csRenderInit();
|
||||||
|
await csToolsInit();
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
import * as cornerstone from '@cornerstonejs/core';
|
||||||
|
import ptScalingMetaDataProvider from './ptScalingMetaDataProvider';
|
||||||
|
|
||||||
|
const { calibratedPixelSpacingMetadataProvider } = cornerstone.utilities;
|
||||||
|
|
||||||
|
export default function initProviders() {
|
||||||
|
cornerstone.metaData.addProvider(
|
||||||
|
ptScalingMetaDataProvider.get.bind(ptScalingMetaDataProvider),
|
||||||
|
10000
|
||||||
|
);
|
||||||
|
cornerstone.metaData.addProvider(
|
||||||
|
calibratedPixelSpacingMetadataProvider.get.bind(
|
||||||
|
calibratedPixelSpacingMetadataProvider
|
||||||
|
),
|
||||||
|
11000
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { volumeLoader } from '@cornerstonejs/core';
|
||||||
|
import {
|
||||||
|
cornerstoneStreamingImageVolumeLoader,
|
||||||
|
cornerstoneStreamingDynamicImageVolumeLoader,
|
||||||
|
} from '@cornerstonejs/streaming-image-volume-loader';
|
||||||
|
|
||||||
|
export default function initVolumeLoader() {
|
||||||
|
volumeLoader.registerUnknownVolumeLoader(
|
||||||
|
cornerstoneStreamingImageVolumeLoader
|
||||||
|
);
|
||||||
|
volumeLoader.registerVolumeLoader(
|
||||||
|
'cornerstoneStreamingImageVolume',
|
||||||
|
cornerstoneStreamingImageVolumeLoader
|
||||||
|
);
|
||||||
|
volumeLoader.registerVolumeLoader(
|
||||||
|
'cornerstoneStreamingDynamicImageVolume',
|
||||||
|
cornerstoneStreamingDynamicImageVolumeLoader
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { utilities as csUtils } from '@cornerstonejs/core';
|
||||||
|
|
||||||
|
const scalingPerImageId = {};
|
||||||
|
|
||||||
|
function addInstance(imageId, scalingMetaData) {
|
||||||
|
const imageURI = csUtils.imageIdToURI(imageId);
|
||||||
|
scalingPerImageId[imageURI] = scalingMetaData;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get(type, imageId) {
|
||||||
|
if (type === 'scalingModule') {
|
||||||
|
const imageURI = csUtils.imageIdToURI(imageId);
|
||||||
|
return scalingPerImageId[imageURI];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { addInstance, get };
|
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
* Remove invalid tags from a metadata and return a new object.
|
||||||
|
*
|
||||||
|
* At this time it is only removing tags that has `null` or `undefined` values
|
||||||
|
* which is our main goal because that breaks when `naturalizeDataset(...)` is
|
||||||
|
* called.
|
||||||
|
*
|
||||||
|
* Validating the tag id using regex like /^[a-fA-F0-9]{8}$/ make it run
|
||||||
|
* +50% slower and looping through all characteres (split+every+Set or simple
|
||||||
|
* FOR+Set) double the time it takes to run. It is currently taking +12ms/1k
|
||||||
|
* images on average which can change depending on the machine.
|
||||||
|
*
|
||||||
|
* @param srcMetadata - source metadata
|
||||||
|
* @returns new metadata object without invalid tags
|
||||||
|
*/
|
||||||
|
function removeInvalidTags(srcMetadata) {
|
||||||
|
// Object.create(null) make it ~9% faster
|
||||||
|
const dstMetadata = Object.create(null);
|
||||||
|
const tagIds = Object.keys(srcMetadata);
|
||||||
|
let tagValue;
|
||||||
|
|
||||||
|
tagIds.forEach((tagId) => {
|
||||||
|
tagValue = srcMetadata[tagId];
|
||||||
|
|
||||||
|
if (tagValue !== undefined && tagValue !== null) {
|
||||||
|
dstMetadata[tagId] = tagValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return dstMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { removeInvalidTags as default, removeInvalidTags };
|
|
@ -1,20 +1,16 @@
|
||||||
import { VolumeActor } from "@cornerstonejs/core/dist/types/types";
|
|
||||||
|
|
||||||
const windowWidth = 400;
|
const windowWidth = 400;
|
||||||
const windowCenter = 40;
|
const windowCenter = 40;
|
||||||
|
|
||||||
const lower = windowCenter - windowWidth / 2.0;
|
const lower = windowCenter - windowWidth / 2.0;
|
||||||
const upper = windowCenter + windowWidth / 2.0;
|
const upper = windowCenter + windowWidth / 2.0;
|
||||||
|
|
||||||
export const ctVoiRange = { lower, upper };
|
const ctVoiRange = { lower, upper };
|
||||||
|
|
||||||
export const setCtTransferFunctionForVolumeActor = ({
|
export default function setCtTransferFunctionForVolumeActor({ volumeActor }) {
|
||||||
volumeActor,
|
|
||||||
}: {
|
|
||||||
volumeActor: VolumeActor;
|
|
||||||
}) => {
|
|
||||||
volumeActor
|
volumeActor
|
||||||
.getProperty()
|
.getProperty()
|
||||||
.getRGBTransferFunction(0)
|
.getRGBTransferFunction(0)
|
||||||
.setMappingRange(lower, upper);
|
.setMappingRange(lower, upper);
|
||||||
};
|
}
|
||||||
|
|
||||||
|
export { ctVoiRange };
|
|
@ -1,13 +1,13 @@
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import { Enums, RenderingEngine, cache } from "@cornerstonejs/core";
|
import { Enums, RenderingEngine, cache } from "@cornerstonejs/core";
|
||||||
import { initCornerstone } from "../CornerstoneDicomLoader/initCornerstoneDicomImageLoader";
|
import { initCornerstone } from "../CornerstoneDicomLoader/init";
|
||||||
import { createImageIdsAndCacheMetaData } from "../CornerstoneDicomLoader/createImageIdsAndCacheMetaData";
|
import { createImageIdsAndCacheMetaData } from "../CornerstoneDicomLoader/createImageIdsAndCacheMetaData";
|
||||||
import {
|
import {
|
||||||
IStackViewport,
|
IStackViewport,
|
||||||
PublicViewportInput,
|
PublicViewportInput,
|
||||||
} from "@cornerstonejs/core/dist/types/types";
|
} from "@cornerstonejs/core/dist/types/types";
|
||||||
|
|
||||||
interface VolumeViewerProps {
|
interface StackViewerProps {
|
||||||
children?: JSX.Element;
|
children?: JSX.Element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ const StudyInstanceUID =
|
||||||
const SeriesInstanceUID =
|
const SeriesInstanceUID =
|
||||||
"1.3.12.2.1107.5.1.4.76315.30000021042706150001900118311";
|
"1.3.12.2.1107.5.1.4.76315.30000021042706150001900118311";
|
||||||
|
|
||||||
export const VolumeViewer = (props: VolumeViewerProps) => {
|
export const StackViewer = (props: StackViewerProps) => {
|
||||||
const dicomRef = useRef(null);
|
const dicomRef = useRef(null);
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
|
@ -1,7 +1,7 @@
|
||||||
import { Corsshair } from "./Crosshair";
|
import { CrosshairMpr } from "./Crosshair";
|
||||||
import { DiffViewer } from "./DiffViewer";
|
import { DiffViewer } from "./DiffViewer";
|
||||||
import { MprViewer } from "./MprViewer";
|
import { MprViewer } from "./MprViewer";
|
||||||
import { VolumeViewer } from "./VolumeViewer";
|
import { StackViewer } from "./StackViewer";
|
||||||
|
|
||||||
interface RootViewerProps {
|
interface RootViewerProps {
|
||||||
children?: JSX.Element;
|
children?: JSX.Element;
|
||||||
|
@ -10,7 +10,8 @@ interface RootViewerProps {
|
||||||
export const RootViewer = (props: RootViewerProps) => {
|
export const RootViewer = (props: RootViewerProps) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Corsshair />
|
<CrosshairMpr />
|
||||||
|
{/* <StackViewer /> */}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
935
pnpm-lock.yaml
935
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user