All files / packages/tools/src/stateManagement/segmentation/config segmentationVisibility.ts

0% Statements 0/20
0% Branches 0/10
0% Functions 0/5
0% Lines 0/20

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                                                                                                                                                                                                                 
import { triggerSegmentationRepresentationModified } from '../triggerSegmentationEvents';
import { getSegmentationRepresentations } from '../../../stateManagement/segmentation/segmentationState';
import { ToolGroupSpecificRepresentation } from '../../../types/SegmentationStateTypes';
import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
 
/**
 * Set the visibility of a segmentation representation for a given tool group. It fires
 * a SEGMENTATION_REPRESENTATION_MODIFIED event.
 *
 * @triggers SEGMENTATION_REPRESENTATION_MODIFIED
 * @param toolGroupId - The Id of the tool group that contains the segmentation.
 * @param segmentationRepresentationUID - The id of the segmentation representation to modify its visibility.
 * @param visibility - boolean
 */
function setSegmentationVisibility(
  toolGroupId: string,
  segmentationRepresentationUID: string,
  visibility: boolean
): void {
  const toolGroupSegmentationRepresentations =
    getSegmentationRepresentations(toolGroupId);
 
  if (!toolGroupSegmentationRepresentations) {
    return;
  }
 
  toolGroupSegmentationRepresentations.forEach(
    (representation: ToolGroupSpecificRepresentation) => {
      if (
        representation.segmentationRepresentationUID ===
        segmentationRepresentationUID
      ) {
        representation.visibility = visibility;
        triggerSegmentationRepresentationModified(
          toolGroupId,
          representation.segmentationRepresentationUID
        );
      }
    }
  );
}
 
/**
 * Get the visibility of a segmentation data for a given tool group.
 *
 * @param toolGroupId - The Id of the tool group that the segmentation
 * data belongs to.
 * @param segmentationRepresentationUID - The id of the segmentation data to get
 * @returns A boolean value that indicates whether the segmentation data is visible or
 * not on the toolGroup
 */
function getSegmentationVisibility(
  toolGroupId: string,
  segmentationRepresentationUID: string
): boolean | undefined {
  const toolGroupSegRepresentations =
    getSegmentationRepresentations(toolGroupId);
 
  const segmentationData = toolGroupSegRepresentations.find(
    (representation: ToolGroupSpecificRepresentation) =>
      representation.segmentationRepresentationUID ===
      segmentationRepresentationUID
  );
 
  if (!segmentationData) {
    return;
  }
 
  return segmentationData.visibility;
}
 
function setVisibilityForSegmentIndex(
  toolGroupId: string,
  segmentationRepresentationUID: string,
  segmentIndex: number,
  visibility: boolean
): void {
  const segRepresentation =
    SegmentationState.getSegmentationRepresentationByUID(
      toolGroupId,
      segmentationRepresentationUID
    );
 
  if (!segRepresentation) {
    return;
  }
 
  if (visibility) {
    segRepresentation.segmentsHidden.delete(segmentIndex);
  } else {
    segRepresentation.segmentsHidden.add(segmentIndex);
  }
 
  triggerSegmentationRepresentationModified(
    toolGroupId,
    segmentationRepresentationUID
  );
}
 
export {
  setSegmentationVisibility,
  getSegmentationVisibility,
  setVisibilityForSegmentIndex,
};