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

0% Statements 0/13
0% Branches 0/6
0% Functions 0/4
0% Lines 0/13

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                                                                                                                                               
import { triggerSegmentationRepresentationModified } from '../triggerSegmentationEvents';
import { getSegmentationRepresentations } from '../../../stateManagement/segmentation/segmentationState';
import { ToolGroupSpecificRepresentation } from '../../../types/SegmentationStateTypes';
 
/**
 * 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;
}
 
export { setSegmentationVisibility, getSegmentationVisibility };