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 | import { cache } from '@cornerstonejs/core';
import * as csTools from '@cornerstonejs/tools';
function getRoiStats(displaySet, annotations) {
const { imageIds } = displaySet;
const ptVolumeInfo = cache.getVolumeContainingImageId(imageIds[0]);
Iif (!ptVolumeInfo) {
throw new Error('No volume found for display set');
}
const { volume } = ptVolumeInfo;
const { voxelManager } = volume;
// Todo: add support for other strategies
const { fn, baseValue } = _getStrategyFn('max');
let value = baseValue;
const boundsIJK = csTools.utilities.rectangleROITool.getBoundsIJKFromRectangleAnnotations(
annotations,
volume
);
// Use the voxelManager's forEach method to iterate over the bounds
voxelManager.forEach(
({ value: voxelValue }) => {
value = fn(voxelValue, value);
},
{
boundsIJK,
}
);
return value;
}
function getThresholdValues(
annotationUIDs,
ptDisplaySet,
config
): { ptLower: number; ptUpper: number; ctLower: number; ctUpper: number } {
Iif (config.strategy === 'range') {
return {
ptLower: Number(config.ptLower),
ptUpper: Number(config.ptUpper),
ctLower: Number(config.ctLower),
ctUpper: Number(config.ctUpper),
};
}
const { weight } = config;
const annotations = annotationUIDs.map(annotationUID =>
csTools.annotation.state.getAnnotation(annotationUID)
);
const ptValue = getRoiStats(ptDisplaySet, annotations);
return {
ctLower: -Infinity,
ctUpper: +Infinity,
ptLower: weight * ptValue,
ptUpper: +Infinity,
};
}
function _getStrategyFn(statistic): {
fn: (a: number, b: number) => number;
baseValue: number;
} {
const baseValue = -Infinity;
const fn = (number, maxValue) => {
Iif (number > maxValue) {
maxValue = number;
}
return maxValue;
};
return { fn, baseValue };
}
export default getThresholdValues;
|