All files / core/src/RenderingEngine/GenericViewport/Planar buildPlanarActorEntry.ts

0% Statements 0/15
0% Branches 0/25
0% Functions 0/3
0% Lines 0/15

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                                                                                                                                                                                                   
import type { ActorEntry, ActorMapperProxy } from '../../../types';
import type {
  LoadedData,
  ViewportDataReference,
} from '../ViewportArchitectureTypes';
import type { PlanarPayload } from './PlanarViewportTypes';
 
/**
 * Builds an ActorEntry from a planar data payload and the render-path-specific
 * actor/mapper. Clean Next dataset identity lives on dataId and semantic
 * derived-data relationships live on `reference`; actor UID stays internal.
 */
export function buildPlanarActorEntry(
  data: LoadedData<PlanarPayload>,
  source: {
    actor: NonNullable<ActorEntry['actorMapper']>['actor'];
    mapper?: NonNullable<ActorEntry['actorMapper']>['mapper'];
    renderMode: NonNullable<ActorEntry['actorMapper']>['renderMode'];
    uid: string;
    referencedIdFallback?: string;
  }
): ActorEntry {
  const referenceFields = getActorEntryReferenceFields(
    data.reference,
    data.volumeId || source.referencedIdFallback
  );
 
  const actor = source.actor;
  const mapper =
    source.mapper ??
    (typeof (actor as { getMapper?: () => unknown }).getMapper === 'function'
      ? ((actor as { getMapper: () => unknown }).getMapper() as NonNullable<
          ActorEntry['actorMapper']
        >['mapper'])
      : undefined);
 
  return {
    uid: source.uid,
    actor: actor as ActorEntry['actor'],
    actorMapper: {
      actor,
      mapper,
      renderMode: source.renderMode,
    } as ActorMapperProxy,
    ...referenceFields,
  };
}
 
function getActorEntryReferenceFields(
  reference: ViewportDataReference | undefined,
  fallbackReferencedId?: string
): {
  reference?: ViewportDataReference;
  referencedId?: string;
  representationUID?: string;
} {
  if (!reference) {
    return fallbackReferencedId ? { referencedId: fallbackReferencedId } : {};
  }
 
  if (reference.kind === 'segmentation') {
    return {
      reference,
      referencedId:
        reference.labelmapId ??
        reference.representationUID ??
        reference.segmentationId,
      ...(reference.representationUID
        ? { representationUID: reference.representationUID }
        : {}),
    };
  }
 
  return {
    reference,
    referencedId: getReferenceId(reference),
  };
}
 
function getReferenceId(reference: Exclude<ViewportDataReference, undefined>) {
  switch (reference.kind) {
    case 'data':
      return reference.dataId;
    case 'image':
      return reference.imageId;
    case 'volume':
      return reference.volumeId;
    case 'geometry':
      return reference.geometryId;
    case 'segmentation':
      return (
        reference.labelmapId ??
        reference.representationUID ??
        reference.segmentationId
      );
  }
}