All files / tools/src/types SegmentationStateTypes.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

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                                                                                                                                                                                                                                                                                                     
import type { Enums as coreEnums, Types } from '@cornerstonejs/core';
import type * as Enums from '../enums';
import type { ContourSegmentationData } from './ContourTypes';
import type { LabelmapSegmentationData } from './LabelmapTypes';
import type { SurfaceSegmentationData } from './SurfaceTypes';
import type vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
import type vtkPiecewiseFunction from '@kitware/vtk.js/Common/DataModel/PiecewiseFunction';
 
export type RepresentationsData = {
  [Enums.SegmentationRepresentations.Labelmap]?: LabelmapSegmentationData;
  [Enums.SegmentationRepresentations.Contour]?: ContourSegmentationData;
  [Enums.SegmentationRepresentations.Surface]?: SurfaceSegmentationData;
};
 
export type RepresentationData =
  | LabelmapSegmentationData
  | ContourSegmentationData
  | SurfaceSegmentationData;
 
export type Segment = {
  /** segment index */
  segmentIndex: number;
  /** segment label */
  label: string;
  /** is segment locked for editing */
  locked: boolean;
  /** cached stats for the segment, e.g., pt suv mean, max etc. */
  cachedStats: { [key: string]: unknown };
  /** is segment active for editing, at the same time only one segment can be active for editing */
  active: boolean;
};
 
/**
 * Global Segmentation Data which is used for the segmentation
 */
export type Segmentation = {
  /** segmentation id  */
  segmentationId: string;
  /** segmentation label */
  label: string;
  segments: {
    [segmentIndex: number]: Segment;
  };
  /**
   * Representations of the segmentation. Each segmentation "can" be viewed
   * in various representations. For instance, if a DICOM SEG is loaded, the main
   * representation is the labelmap. However, for DICOM RT the main representation
   * is contours, and other representations can be derived from the contour (currently
   * only labelmap representation is supported)
   */
  representationData: RepresentationsData;
  /**
   * Segmentation level stats, Note each segment can have its own stats
   * This is used for caching stats for the segmentation level
   */
  cachedStats: { [key: string]: unknown };
};
 
export type LabelmapRenderingConfig = {
  cfun: vtkColorTransferFunction;
  ofun: vtkPiecewiseFunction;
  colorLUTIndex: number;
  // segmentation blend mode if desired
  blendMode?: coreEnums.BlendModes;
};
 
export type ContourRenderingConfig = {};
 
export type SurfaceRenderingConfig = {};
 
export type RenderingConfig =
  | LabelmapRenderingConfig
  | ContourRenderingConfig
  | SurfaceRenderingConfig;
 
type BaseSegmentationRepresentation = {
  colorLUTIndex: number;
  // identifier for the segmentation representation
  segmentationId: string;
  type: Enums.SegmentationRepresentations;
  // settings
  visible: boolean;
  active: boolean;
  segments: {
    [segmentIndex: number]: {
      visible: boolean;
    };
  };
};
 
export type LabelmapRepresentation = BaseSegmentationRepresentation & {
  config: LabelmapRenderingConfig;
};
 
export type ContourRepresentation = BaseSegmentationRepresentation & {
  config: ContourRenderingConfig;
};
 
export type SurfaceRepresentation = BaseSegmentationRepresentation & {
  config: SurfaceRenderingConfig;
};
 
export type SegmentationRepresentation =
  | LabelmapRepresentation
  | ContourRepresentation
  | SurfaceRepresentation;
 
export type SegmentationState = {
  /** Array of colorLUT for segmentation to render */
  colorLUT: Types.ColorLUT[];
  /** segmentations */
  segmentations: Segmentation[];
  /** viewports association with segmentation representations */
  viewportSegRepresentations: {
    [viewportId: string]: Array<SegmentationRepresentation>;
  };
};
 
export type SegmentationPublicInput = {
  segmentationId: string;
  representation: {
    type: Enums.SegmentationRepresentations;
    data?: RepresentationData;
  };
  config?: {
    segments?: {
      [segmentIndex: number]: Partial<Segment>;
    };
    label?: string;
    // segmentation level stats
    cachedStats?: { [key: string]: unknown };
  };
};
 
/**
 * Represents the input structure for adding a segmentation to a viewport.
 */
export type RepresentationPublicInput = {
  /** The unique identifier for the segmentation. */
  segmentationId: string;
  type?: Enums.SegmentationRepresentations;
  config?: {
    colorLUTOrIndex?: Types.ColorLUT | number;
    blendMode?: coreEnums.BlendModes;
  };
};