All files / packages/tools/src/tools/segmentation/strategies/compositions threshold.ts

0% Statements 0/11
0% Branches 0/13
0% Functions 0/2
0% Lines 0/11

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                                                                           
import { vec3 } from 'gl-matrix';
import type { Types } from '@cornerstonejs/core';
import type { InitializedOperationData } from '../BrushStrategy';
import StrategyCallbacks from '../../../../enums/StrategyCallbacks';
 
/**
 * Adds an isWithinThreshold to the operation data that checks that the
 * image value is within threshold[0]...threshold[1]
 * No-op if threshold not defined.
 */
export default {
  [StrategyCallbacks.CreateIsInThreshold]: (
    operationData: InitializedOperationData
  ) => {
    const { imageVoxelManager, strategySpecificConfiguration, segmentIndex } =
      operationData;
    if (!strategySpecificConfiguration || !segmentIndex) {
      return;
    }
    return (index) => {
      const { THRESHOLD, THRESHOLD_INSIDE_CIRCLE } =
        strategySpecificConfiguration;
 
      const voxelValue = imageVoxelManager.getAtIndex(index);
      const gray = Array.isArray(voxelValue)
        ? vec3.length(voxelValue as Types.Point3)
        : voxelValue;
      // Prefer the generic version of the THRESHOLD configuration, but fallback
      // to the older THRESHOLD_INSIDE_CIRCLE version.
      const { threshold } = THRESHOLD || THRESHOLD_INSIDE_CIRCLE || {};
      if (!threshold?.length) {
        return true;
      }
      return threshold[0] <= gray && gray <= threshold[1];
    };
  },
};