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

41.66% Statements 5/12
100% Branches 0/0
50% Functions 5/10
41.66% Lines 5/12

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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196                              30x                                                                                                                     33x                           2x                                           2x                                                                                 2x                                                                                        
import SegmentationRepresentations from '../../../enums/SegmentationRepresentations';
import * as SegmentationState from '../../../stateManagement/segmentation/segmentationState';
 
import {
  RepresentationConfig,
  SegmentationRepresentationConfig,
  SegmentSpecificRepresentationConfig,
} from '../../../types/SegmentationStateTypes';
 
/**
 * It returns the global segmentation config.
 * @returns The global segmentation config containing the representations
 * config for each representation type and renderInactiveSegmentations flag.
 */
function getGlobalConfig(): SegmentationRepresentationConfig {
  return SegmentationState.getGlobalConfig();
}
 
/**
 * Set the global segmentation config
 * @param segmentationConfig - SegmentationConfig
 */
function setGlobalConfig(
  segmentationConfig: SegmentationRepresentationConfig
): void {
  SegmentationState.setGlobalConfig(segmentationConfig);
}
 
/**
 * Given a representation type, return the corresponding global representation config
 * @param representationType - The type of representation to query
 * @returns A representation configuration object.
 */
function getGlobalRepresentationConfig(
  representationType: SegmentationRepresentations
): RepresentationConfig['LABELMAP'] {
  const globalConfig = getGlobalConfig();
  return globalConfig.representations[representationType];
}
 
/**
 * Set the global configuration for a given representation type. It fires
 * a SEGMENTATION_MODIFIED event.
 *
 * @triggers SEGMENTATION_MODIFIED
 * @param representationType - The type of representation to set config for
 * @param config - The configuration for the representation.
 */
function setGlobalRepresentationConfig(
  representationType: SegmentationRepresentations,
  config: RepresentationConfig['LABELMAP']
): void {
  const globalConfig = getGlobalConfig();
 
  setGlobalConfig({
    ...globalConfig,
    representations: {
      ...globalConfig.representations,
      [representationType]: {
        ...globalConfig.representations[representationType],
        ...config,
      },
    },
  });
}
 
/**
 * Get the toolGroup specific segmentation config
 * @param toolGroupId - The Id of the tool group
 * @returns A SegmentationConfig object.
 */
function getToolGroupSpecificConfig(
  toolGroupId: string
): SegmentationRepresentationConfig {
  return SegmentationState.getToolGroupSpecificConfig(toolGroupId);
}
 
/**
 * Sets the tool group specific configuration for the segmentation
 * representation. This will apply to all segmentation representations.
 * @param toolGroupId - The tool group id where the segmentation representation belongs to.
 * @param segmentationRepresentationConfig - This is the configuration object that you will use to set the default values for
 * the segmentation representation.
 */
function setToolGroupSpecificConfig(
  toolGroupId: string,
  segmentationRepresentationConfig: SegmentationRepresentationConfig
): void {
  SegmentationState.setToolGroupSpecificConfig(
    toolGroupId,
    segmentationRepresentationConfig
  );
}
 
/**
 * Give the segmentation representation UID, return the corresponding config
 * which is shared by all segments in the segmentation representation. This is
 * an optional level of configuration that can be set by the user, by default
 * it will fallback to the toolGroup specific config, if not set, it will fallback
 * to the global config.
 *
 * @param segmentationRepresentationUID - The uid of the segmentation representation
 * @param config - The configuration for the representation. This is an object
 * only containing the representation type as key and the config as value.
 * @returns - The configuration for the representation.
 */
function getSegmentationRepresentationSpecificConfig(
  toolGroupId: string,
  segmentationRepresentationUID: string
): RepresentationConfig {
  return SegmentationState.getSegmentationRepresentationSpecificConfig(
    toolGroupId,
    segmentationRepresentationUID
  );
}
 
/**
 * Set the segmentation representation specific configuration for the
 * segmentation representation. This will apply to all segments in the
 * segmentation representation and has higher priority than the toolGroup
 * specific config.
 *
 * @param segmentationRepresentationUID - The uid of the segmentation representation
 * @param config - The configuration for the representation. This is an object
 * only containing the representation type as key and the config as value.
 */
function setSegmentationRepresentationSpecificConfig(
  toolGroupId: string,
  segmentationRepresentationUID: string,
  config: RepresentationConfig
): void {
  SegmentationState.setSegmentationRepresentationSpecificConfig(
    toolGroupId,
    segmentationRepresentationUID,
    config
  );
}
 
/**
 * Get the segment specific configuration for the segmentation representation.
 *
 * @param toolGroupId - The tool group id where the segmentation representation belongs to.
 * @param segmentationRepresentationUID  - The uid of the segmentation representation
 * @param segmentIndex - The index of the segment
 * @returns - The configuration for the segment index in the segmentation representation that is shown in the toolGroup's viewport
 */
function getSegmentSpecificConfig(
  toolGroupId: string,
  segmentationRepresentationUID: string,
  segmentIndex: number
): RepresentationConfig {
  return SegmentationState.getSegmentSpecificRepresentationConfig(
    toolGroupId,
    segmentationRepresentationUID,
    segmentIndex
  );
}
 
/**
 * Set the segment specific configuration for the segmentation representation.
 * This configuration, if specified, has higher priority than the segmentation representation specific config,
 * and the toolGroup specific config. The order of priority is: segment specific config > segmentation representation specific config > toolGroup specific config > global config
 * @param toolGroupId - The tool group id where the segmentation representation belongs to.
 * @param segmentationRepresentationUID - The uid of the segmentation representation
 * @param segmentIndex - The index of the segment
 * @param config - The configuration for the representation. This is an object
 */
function setSegmentSpecificConfig(
  toolGroupId: string,
  segmentationRepresentationUID: string,
  config: SegmentSpecificRepresentationConfig
): void {
  SegmentationState.setSegmentSpecificRepresentationConfig(
    toolGroupId,
    segmentationRepresentationUID,
    config
  );
}
 
export {
  // Global
  getGlobalConfig,
  setGlobalConfig,
  getGlobalRepresentationConfig,
  setGlobalRepresentationConfig,
  // ToolGroup Specific
  getToolGroupSpecificConfig,
  setToolGroupSpecificConfig,
  // segmentation representation specific config
  getSegmentationRepresentationSpecificConfig,
  setSegmentationRepresentationSpecificConfig,
  // segment specific config
  getSegmentSpecificConfig,
  setSegmentSpecificConfig,
};