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

46.66% Statements 7/15
50% Branches 7/14
100% Functions 1/1
46.66% Lines 7/15

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                                          5994x 5994x 5994x               5994x       5994x                   5994x   5994x      
import type { InitializedOperationData } from '../BrushStrategy';
import StrategyCallbacks from '../../../../enums/StrategyCallbacks';
 
/**
 * Creates a set value function which will apply the specified segmentIndex
 * to the given location.
 * If segmentIndex is null, it will clear the given segment index instead
 * This is all done through the previewVoxelManager so that values can be recorded
 * as changed, and the original values remembered.
 */
export default {
  [StrategyCallbacks.INTERNAL_setValue]: (
    operationData: InitializedOperationData,
    { value, index }
  ) => {
    const {
      segmentsLocked,
      segmentIndex,
      previewVoxelManager: previewVoxelManager,
      previewSegmentIndex,
      segmentationVoxelManager: segmentationVoxelManager,
    } = operationData;
    const existingValue = segmentationVoxelManager.getAtIndex(index);
    Iif (segmentIndex === null) {
      const oldValue = previewVoxelManager.getAtIndex(index);
      if (oldValue !== undefined) {
        previewVoxelManager.setAtIndex(index, oldValue);
      }
      return;
    }
 
    Iif (existingValue === segmentIndex || segmentsLocked.includes(value)) {
      return;
    }
    // Correct for preview data getting into the image area and not accepted/rejected
    Iif (existingValue === previewSegmentIndex) {
      if (previewVoxelManager.getAtIndex(index) === undefined) {
        // Reset the value to ensure preview gets added to the indices
        segmentationVoxelManager.setAtIndex(index, segmentIndex);
      } else {
        return;
      }
    }
 
    // Now, just update the displayed value
    const useSegmentIndex = previewSegmentIndex ?? segmentIndex;
 
    previewVoxelManager.setAtIndex(index, useSegmentIndex);
  },
};