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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | 34x 34x 34x 144x 144x 34x 144x 144x 144x 144x 77x 77x 77x 77x 144x 144x 144x 34x 10x 10x 57x 57x 34x | import { create } from 'zustand'; import { devtools } from 'zustand/middleware'; import { SegmentationPresentation, SegmentationPresentationItem } from '../types/Presentation'; import { JOIN_STR } from './presentationUtils'; import { getViewportOrientationFromImageOrientationPatient } from '../utils/getViewportOrientationFromImageOrientationPatient'; const PRESENTATION_TYPE_ID = 'segmentationPresentationId'; const DEBUG_STORE = false; /** * The keys are the presentationId. */ type SegmentationPresentationStore = { /** * Type identifier for the store. */ type: string; /** * Stores segmentation presentations indexed by their presentation ID. */ segmentationPresentationStore: Record<string, SegmentationPresentation>; /** * Sets the segmentation presentation for a given segmentation ID. * * @param presentationId - The presentation ID. * @param value - The `SegmentationPresentation` to associate with the ID. */ setSegmentationPresentation: (presentationId: string, value: SegmentationPresentation) => void; /** * Clears all segmentation presentations from the store. */ clearSegmentationPresentationStore: () => void; /** * Retrieves the presentation ID based on the provided parameters. * * @param id - The ID to check. * @param options - Configuration options. * @param options.viewport - The current viewport. * @param options.viewports - All available viewports. * @param options.isUpdatingSameViewport - Indicates if the same viewport is being updated. * @param options.servicesManager - The services manager instance. * @returns The segmentation presentation ID or undefined. */ getPresentationId: ( id: string, options: { viewport: AppTypes.ViewportGrid.Viewport; viewports: AppTypes.ViewportGrid.Viewports; isUpdatingSameViewport: boolean; servicesManager: AppTypes.ServicesManager; } ) => string | undefined; /** * Adds a new segmentation presentation state. * * @param presentationId - The presentation ID. * @param segmentationPresentation - The `SegmentationPresentation` to add. * @param servicesManager - The services manager instance. */ addSegmentationPresentationItem: ( presentationId: string, segmentationPresentationItem: SegmentationPresentationItem ) => void; /** * Gets the current segmentation presentation ID. * * @param params - Parameters for retrieving the segmentation presentation ID. * @param params.viewport - The current viewport. * @param params.servicesManager - The services manager instance. * @returns The current segmentation presentation ID. */ getSegmentationPresentationId: ({ viewport, servicesManager, }: { viewport: AppTypes.ViewportGrid.Viewport; servicesManager: AppTypes.ServicesManager; }) => string; }; /** * Generates a segmentation presentation ID based on the viewport configuration. * * @param id - The ID to check. * @param options - Configuration options. * @param options.viewport - The current viewport. * @param options.viewports - All available viewports. * @param options.isUpdatingSameViewport - Indicates if the same viewport is being updated. * @param options.servicesManager - The services manager instance. * @returns The segmentation presentation ID or undefined. */ const getPresentationId = ( id: string, { viewport, viewports, isUpdatingSameViewport, servicesManager, }: { viewport: AppTypes.ViewportGrid.Viewport; viewports: AppTypes.ViewportGrid.Viewports; isUpdatingSameViewport: boolean; servicesManager: AppTypes.ServicesManager; } ): string | undefined => { Iif (id !== PRESENTATION_TYPE_ID) { return; } return _getSegmentationPresentationId({ viewport, servicesManager }); }; /** * Helper function to generate the segmentation presentation ID. * * @param params - Parameters for generating the segmentation presentation ID. * @param params.viewport - The current viewport. * @param params.servicesManager - The services manager instance. * @returns The segmentation presentation ID or undefined. */ const _getSegmentationPresentationId = ({ viewport, servicesManager, }: { viewport: AppTypes.ViewportGrid.Viewport; servicesManager: AppTypes.ServicesManager; }) => { Iif (!viewport?.viewportOptions || !viewport.displaySetInstanceUIDs?.length) { return; } const { displaySetInstanceUIDs, viewportOptions } = viewport; let orientation = viewportOptions.orientation; if (!orientation) { // Calculate orientation from the viewport sample image const displaySet = servicesManager.services.displaySetService.getDisplaySetByUID( displaySetInstanceUIDs[0] ); const sampleImage = displaySet.images?.[0]; const imageOrientationPatient = sampleImage?.ImageOrientationPatient; orientation = getViewportOrientationFromImageOrientationPatient(imageOrientationPatient); } const segmentationPresentationArr = []; segmentationPresentationArr.push(...displaySetInstanceUIDs); // Uncomment if unique indexing is needed // addUniqueIndex( // segmentationPresentationArr, // 'segmentationPresentationId', // viewports, // isUpdatingSameViewport // ); return segmentationPresentationArr.join(JOIN_STR); }; /** * Creates the Segmentation Presentation store. * * @param set - The zustand set function. * @returns The Segmentation Presentation store state and actions. */ const createSegmentationPresentationStore = set => ({ type: PRESENTATION_TYPE_ID, segmentationPresentationStore: {}, /** * Clears all segmentation presentations from the store. */ clearSegmentationPresentationStore: () => set({ segmentationPresentationStore: {} }, false, 'clearSegmentationPresentationStore'), /** * Adds a new segmentation presentation item to the store. * * segmentationPresentationItem: { * segmentationId: string; * type: SegmentationRepresentations; * hydrated: boolean | null; * config?: unknown; * } */ addSegmentationPresentationItem: ( presentationId: string, segmentationPresentationItem: SegmentationPresentationItem ) => set( state => ({ segmentationPresentationStore: { ...state.segmentationPresentationStore, [presentationId]: [ ...(state.segmentationPresentationStore[presentationId] || []), segmentationPresentationItem, ], }, }), false, 'addSegmentationPresentationItem' ), /** * Sets the segmentation presentation for a given presentation ID. A segmentation * presentation is an array of SegmentationPresentationItem. * * segmentationPresentationItem: { * segmentationId: string; * type: SegmentationRepresentations; * hydrated: boolean | null; * config?: unknown; * } * * segmentationPresentation: SegmentationPresentationItem[] */ setSegmentationPresentation: (presentationId: string, values: SegmentationPresentation) => set( state => ({ segmentationPresentationStore: { ...state.segmentationPresentationStore, [presentationId]: values, }, }), false, 'setSegmentationPresentation' ), /** * Retrieves the presentation ID based on the provided parameters. */ getPresentationId, /** * Retrieves the current segmentation presentation ID. */ getSegmentationPresentationId: _getSegmentationPresentationId, }); /** * Zustand store for managing segmentation presentations. * Applies devtools middleware when DEBUG_STORE is enabled. */ export const useSegmentationPresentationStore = create<SegmentationPresentationStore>()( DEBUG_STORE ? devtools(createSegmentationPresentationStore, { name: 'Segmentation Presentation Store' }) : createSegmentationPresentationStore ); |