All files / tools/src/stateManagement/segmentation addSegmentationRepresentationsToViewport.ts

60% Statements 12/20
100% Branches 0/0
83.33% Functions 10/12
60% Lines 12/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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150                      194x 230x                             8x   8x                                                                             90x   90x                               26x   26x 78x   78x                                     4x   4x                                                                          
import { SegmentationRepresentations } from '../../enums';
import type { RepresentationPublicInput } from '../../types/SegmentationStateTypes';
import { internalAddSegmentationRepresentation } from './internalAddSegmentationRepresentation';
 
/**
 * Adds one or more segmentations to a specific viewport.
 */
export function addSegmentationRepresentations(
  viewportId: string,
  segmentationInputArray: RepresentationPublicInput[]
) {
  segmentationInputArray.map((segmentationInput) => {
    return internalAddSegmentationRepresentation(viewportId, segmentationInput);
  });
}
 
/**
 * Adds one or more contour segmentations to a specific viewport.
 *
 * @param viewportId - The identifier of the viewport to add the contour segmentations to.
 * @param contourInputArray - An array of contour segmentation inputs to be added.
 * @returns A promise that resolves to an array of segmentation representation UIDs.
 */
function addContourRepresentationToViewport(
  viewportId: string,
  contourInputArray: RepresentationPublicInput[]
) {
  return addSegmentationRepresentations(
    viewportId,
    contourInputArray.map((input) => ({
      ...input,
      type: SegmentationRepresentations.Contour,
    }))
  );
}
 
/**
 * Adds multiple contour segmentations to multiple viewports.
 *
 * @param viewportInputMap - An object mapping viewport IDs to arrays of contour segmentation inputs.
 * @returns A promise that resolves to an object mapping viewport IDs to arrays of segmentation representation UIDs.
 */
function addContourRepresentationToViewportMap(viewportInputMap: {
  [viewportId: string]: RepresentationPublicInput[];
}) {
  const results = {};
 
  for (const [viewportId, inputArray] of Object.entries(viewportInputMap)) {
    results[viewportId] = addContourRepresentationToViewport(
      viewportId,
      inputArray
    );
  }
 
  return results;
}
 
/**
 * Adds one or more labelmap segmentations to a specific viewport.
 *
 * @param viewportId - The identifier of the viewport to add the labelmap segmentations to.
 * @param labelmapInputArray - An array of labelmap segmentation inputs to be added.
 * @returns A promise that resolves to an array of segmentation representation UIDs.
 */
function addLabelmapRepresentationToViewport(
  viewportId: string,
  labelmapInputArray: RepresentationPublicInput[]
) {
  return addSegmentationRepresentations(
    viewportId,
    labelmapInputArray.map((input) => ({
      ...input,
      type: SegmentationRepresentations.Labelmap,
    }))
  );
}
 
/**
 * Adds multiple labelmap segmentations to multiple viewports.
 *
 * @param viewportInputMap - An object mapping viewport IDs to arrays of labelmap segmentation inputs.
 * @returns A promise that resolves to an object mapping viewport IDs to arrays of segmentation representation UIDs.
 */
function addLabelmapRepresentationToViewportMap(viewportInputMap: {
  [viewportId: string]: RepresentationPublicInput[];
}) {
  const results = {};
 
  for (const [viewportId, inputArray] of Object.entries(viewportInputMap)) {
    results[viewportId] = addLabelmapRepresentationToViewport(
      viewportId,
      inputArray.map((input) => ({
        ...input,
        type: SegmentationRepresentations.Labelmap,
      }))
    );
  }
}
 
/**
 * Adds one or more surface segmentations to a specific viewport.
 *
 * @param viewportId - The identifier of the viewport to add the surface segmentations to.
 * @param surfaceInputArray - An array of surface segmentation inputs to be added.
 * @returns A promise that resolves to an array of segmentation representation UIDs.
 */
function addSurfaceRepresentationToViewport(
  viewportId: string,
  surfaceInputArray: RepresentationPublicInput[]
) {
  return addSegmentationRepresentations(
    viewportId,
    surfaceInputArray.map((input) => ({
      ...input,
      type: SegmentationRepresentations.Surface,
    }))
  );
}
 
/**
 * Adds multiple surface segmentations to multiple viewports.
 *
 * @param viewportInputMap - An object mapping viewport IDs to arrays of surface segmentation inputs.
 * @returns A promise that resolves to an object mapping viewport IDs to arrays of segmentation representation UIDs.
 */
function addSurfaceRepresentationToViewportMap(viewportInputMap: {
  [viewportId: string]: RepresentationPublicInput[];
}) {
  const results = {};
 
  for (const [viewportId, inputArray] of Object.entries(viewportInputMap)) {
    results[viewportId] = addSurfaceRepresentationToViewport(
      viewportId,
      inputArray
    );
  }
 
  return results;
}
 
export {
  addContourRepresentationToViewport,
  addLabelmapRepresentationToViewport,
  addSurfaceRepresentationToViewport,
  // Multi viewport functions
  addContourRepresentationToViewportMap,
  addLabelmapRepresentationToViewportMap,
  addSurfaceRepresentationToViewportMap,
};