Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | 1x 1x 1x 1x 1x 1x 1x 1x 16x 16x 16x 16x 1x 1x 21x 21x 21x 21x 1x 32x 32x 32x 1x 13x 13x 13x 13x 13x 13x 13x 12x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x | import { Enums, utilities } from '@cornerstonejs/core';
const { CalibrationTypes } = Enums;
const PIXEL_UNITS = 'px';
const SUPPORTED_REGION_DATA_TYPES = [
1, // Tissue
];
const SUPPORTED_LENGTH_VARIANT = [
'3,3', // x: cm & y:cm
];
const SUPPORTED_PROBE_VARIANT = [
'4,3', // x: seconds & y : cm
];
const UNIT_MAPPING = {
3: 'cm',
4: 'seconds',
};
const EPS = 1e-3;
/**
* Extracts the length units and the type of calibration for those units
* into the response. The length units will typically be either mm or px
* while the calibration type can be any of a number of different calibration types.
*
* Volumetric images have no calibration type, so are just the raw mm.
*
* TODO: Handle region calibration
*
* @param handles - used to detect if the spacing information is different
* between various points (eg angled ERMF or US Region).
* Currently unused, but needed for correct US Region handling
* @param image - to extract the calibration from
* image.calibration - calibration value to extract units form
* @returns String containing the units and type of calibration
*/
const getCalibratedLengthUnits = (handles, image): string => {
const { calibration, hasPixelSpacing } = image;
// Anachronistic - moving to using calibration consistently, but not completed yet
const units = hasPixelSpacing ? 'mm' : PIXEL_UNITS;
Eif (
!calibration ||
(!calibration.type && !calibration.sequenceOfUltrasoundRegions)
) {
return units;
}
if (calibration.type === CalibrationTypes.UNCALIBRATED) {
return PIXEL_UNITS;
}
if (calibration.sequenceOfUltrasoundRegions) {
return 'US Region';
}
return `${units} ${calibration.type}`;
};
const SQUARE = '\xb2';
/**
* Extracts the area units, including the squared sign plus calibration type.
*/
const getCalibratedAreaUnits = (handles, image): string => {
const { calibration, hasPixelSpacing } = image;
const units = (hasPixelSpacing ? 'mm' : PIXEL_UNITS) + SQUARE;
Eif (!calibration || !calibration.type) {
return units;
}
if (calibration.sequenceOfUltrasoundRegions) {
return 'US Region';
}
return `${units} ${calibration.type}`;
};
/**
* Gets the scale divisor for converting from internal spacing to
* image spacing for calibrated images.
*/
const getCalibratedScale = (image, handles = []) => {
Iif (image.calibration?.sequenceOfUltrasoundRegions) {
// image.spacing / image.us.space
} else Iif (image.calibration?.scale) {
return image.calibration.scale;
} else {
return 1;
}
};
/**
* Extracts the calibrated length units, area units, and the scale
* for converting from internal spacing to image spacing.
*
* @param handles - to detect if spacing information is different between points
* @param image - to extract the calibration from
* @returns Object containing the units, area units, and scale
*/
const getCalibratedLengthUnitsAndScale = (image, handles) => {
const [imageIndex1, imageIndex2] = handles;
const { calibration, hasPixelSpacing } = image;
let units = hasPixelSpacing ? 'mm' : PIXEL_UNITS;
const areaUnits = units + SQUARE;
let scale = 1;
let calibrationType = '';
if (
!calibration ||
(!calibration.type && !calibration.sequenceOfUltrasoundRegions)
) {
return { units, areaUnits, scale };
}
Iif (calibration.type === CalibrationTypes.UNCALIBRATED) {
return { units: PIXEL_UNITS, areaUnits: PIXEL_UNITS + SQUARE, scale };
}
Iif (calibration.sequenceOfUltrasoundRegions) {
let regions = calibration.sequenceOfUltrasoundRegions.filter(
(region) =>
imageIndex1[0] >= region.regionLocationMinX0 &&
imageIndex1[0] <= region.regionLocationMaxX1 &&
imageIndex1[1] >= region.regionLocationMinY0 &&
imageIndex1[1] <= region.regionLocationMaxY1 &&
imageIndex2[0] >= region.regionLocationMinX0 &&
imageIndex2[0] <= region.regionLocationMaxX1 &&
imageIndex2[1] >= region.regionLocationMinY0 &&
imageIndex2[1] <= region.regionLocationMaxY1
);
// If we are not in a region at all we should show the underlying calibration
// which might be the mm spacing for the image
if (!regions?.length) {
return { units, areaUnits, scale };
}
// if we are in a region then it is the question of whether we support it
// or not. If we do not support it we should show px
regions = regions.filter(
(region) =>
SUPPORTED_REGION_DATA_TYPES.includes(region.regionDataType) &&
SUPPORTED_LENGTH_VARIANT.includes(
`${region.physicalUnitsXDirection},${region.physicalUnitsYDirection}`
)
);
if (!regions.length) {
return { units: PIXEL_UNITS, areaUnits: PIXEL_UNITS + SQUARE, scale };
}
// Todo: expand on this logic
const region = regions[0];
const physicalDeltaX = Math.abs(region.physicalDeltaX);
const physicalDeltaY = Math.abs(region.physicalDeltaY);
// if we are in a supported region then we should check if the
// physicalDeltaX and physicalDeltaY are the same. If they are not
// then we should show px again, but if they are the same then we should
// show the units
const isSamePhysicalDelta = utilities.isEqual(
physicalDeltaX,
physicalDeltaY,
EPS
);
if (isSamePhysicalDelta) {
scale = 1 / (physicalDeltaX * physicalDeltaY * 100);
calibrationType = 'US Region';
units = 'mm';
} else {
return { units: PIXEL_UNITS, areaUnits: PIXEL_UNITS + SQUARE, scale };
}
} else Eif (calibration.scale) {
scale = calibration.scale;
}
// everything except REGION/Uncalibratted
const types = [
CalibrationTypes.ERMF,
CalibrationTypes.USER,
CalibrationTypes.ERROR,
CalibrationTypes.PROJECTION,
];
Eif (types.includes(calibration?.type)) {
calibrationType = calibration.type;
}
return {
units: units + (calibrationType ? ` ${calibrationType}` : ''),
areaUnits: areaUnits + (calibrationType ? ` ${calibrationType}` : ''),
scale,
};
};
const getCalibratedProbeUnitsAndValue = (image, handles) => {
const [imageIndex] = handles;
const { calibration } = image;
let units = ['raw'];
let values = [null];
let calibrationType = '';
if (
!calibration ||
(!calibration.type && !calibration.sequenceOfUltrasoundRegions)
) {
return { units, values };
// Todo: add support for other scenarios
}
if (calibration.sequenceOfUltrasoundRegions) {
// for Probe tool
const supportedRegionsMetadata =
calibration.sequenceOfUltrasoundRegions.filter(
(region) =>
SUPPORTED_REGION_DATA_TYPES.includes(region.regionDataType) &&
SUPPORTED_PROBE_VARIANT.includes(
`${region.physicalUnitsXDirection},${region.physicalUnitsYDirection}`
)
);
if (!supportedRegionsMetadata?.length) {
return { units, values };
}
const region = supportedRegionsMetadata.find(
(region) =>
imageIndex[0] >= region.regionLocationMinX0 &&
imageIndex[0] <= region.regionLocationMaxX1 &&
imageIndex[1] >= region.regionLocationMinY0 &&
imageIndex[1] <= region.regionLocationMaxY1
);
if (!region) {
return { units, values };
}
// Todo: I think this is a ok assumption for now that if the referencePixelX0 and referencePixelY0
// are not defined, then we can assume 0 for them
const { referencePixelX0 = 0, referencePixelY0 = 0 } = region;
const { physicalDeltaX, physicalDeltaY } = region;
const yValue =
(imageIndex[1] - region.regionLocationMinY0 - referencePixelY0) *
physicalDeltaY;
const xValue =
(imageIndex[0] - region.regionLocationMinX0 - referencePixelX0) *
physicalDeltaX;
calibrationType = 'US Region';
values = [xValue, yValue];
units = [
UNIT_MAPPING[region.physicalUnitsXDirection],
UNIT_MAPPING[region.physicalUnitsYDirection],
];
}
return {
units,
values,
calibrationType,
};
};
/** Gets the aspect ratio of the screen display relative to the image
* display in order to square up measurement values.
* That is, suppose the spacing on the image is 1, 0.5 (x,y spacing)
* This is displayed at 1, 1 spacing on screen, then the
* aspect value will be 1/0.5 = 2
*/
const getCalibratedAspect = (image) => image.calibration?.aspect || 1;
export default getCalibratedLengthUnits;
export {
getCalibratedAreaUnits,
getCalibratedLengthUnits,
getCalibratedLengthUnitsAndScale,
getCalibratedScale,
getCalibratedAspect,
getCalibratedProbeUnitsAndValue,
};
|