All files / packages/tools/src/stateManagement/segmentation/polySeg/Contour/utils extractContourData.ts

0% Statements 0/13
0% Branches 0/8
0% Functions 0/1
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                                                                             
import { PolyDataClipCacheType } from '../../../helpers/clipAndCacheSurfacesForViewport';
import { RawContourData } from '../contourComputationStrategies';
 
/**
 * Extracts contour data from the given polyDataCache.
 * @param polyDataCache - The polyData cache containing intersection information.
 * @param segmentIndexMap - Optional map for mapping surface IDs to segment indices.
 * @returns A map of segment indices to an array of contour results.
 */
export function extractContourData(
  polyDataCache: PolyDataClipCacheType,
  segmentIndexMap?: Map<string, number>
) {
  const rawResults = new Map() as RawContourData;
 
  for (const [cacheId, intersectionInfo] of polyDataCache) {
    // Todo; fix this
    const surfaceId = cacheId.split('_')[1];
 
    for (const [_, result] of intersectionInfo) {
      if (!result) {
        continue;
      }
      const segmentIndex = Number(surfaceId) || segmentIndexMap?.get(surfaceId);
 
      if (!segmentIndex) {
        continue;
      }
 
      if (!rawResults.has(segmentIndex)) {
        rawResults.set(segmentIndex, []);
      }
 
      rawResults.get(segmentIndex).push(result);
    }
  }
  return rawResults;
}