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

63.63% Statements 7/11
25% Branches 2/8
66.66% Functions 2/3
63.63% Lines 7/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 39 40 41 42 43 44 45 46                                        1x   1x 1x   1x               5994x   1x             1x      
import type { InitializedOperationData } from '../BrushStrategy';
import pointInShapeCallback from '../../../../utilities/pointInShapeCallback';
import StrategyCallbacks from '../../../../enums/StrategyCallbacks';
 
/**
 * Creates a fill strategy that uses the isWithinThreshold created by the
 * createIsInThreshold and the bounds specified in the boundsIJK to go over
 * the specified area, checking if in threshold, and if so, filling that area
 * with the new segment by calling the setValue function.
 */
export default {
  [StrategyCallbacks.Fill]: (operationData: InitializedOperationData) => {
    const {
      segmentsLocked,
      segmentationImageData,
      segmentationVoxelManager: segmentationVoxelManager,
      previewVoxelManager: previewVoxelManager,
      imageVoxelManager: imageVoxelManager,
      brushStrategy,
      centerIJK,
    } = operationData;
    const isWithinThreshold =
      brushStrategy.createIsInThreshold?.(operationData);
    const { setValue } = brushStrategy;
 
    const callback = isWithinThreshold
      ? (data) => {
          const { value, index } = data;
          if (segmentsLocked.includes(value) || !isWithinThreshold(index)) {
            return;
          }
          setValue(operationData, data);
        }
      : (data) => setValue(operationData, data);
 
    pointInShapeCallback(
      segmentationImageData as unknown,
      imageVoxelManager?.isInObject || segmentationVoxelManager.isInObject,
      callback,
      segmentationVoxelManager.boundsIJK
    );
 
    previewVoxelManager.addPoint(centerIJK);
  },
};