in pathology/viewer/src/stores/image-viewer-page.store.ts [513:619]
private dicomModelToSideNavLayers(
dicomAnnotationModel: DicomModel,
slideInfo: SlideInfo): Array<SideNavLayer | SideNavLayer[]> {
const dicomAnnotation: DicomAnnotation =
this.dicomAnnotationsService.dicomModelToAnnotations(
dicomAnnotationModel, slideInfo);
const annotationGroups = dicomAnnotation.annotationGroupSequence;
const errorGroup = annotationGroups.find(a => a.error);
if (errorGroup) {
this.dialogService.error(errorGroup.error!);
}
const annotationSideNavLayer: Array<SideNavLayer | SideNavLayer[]> =
annotationGroups.filter(annotationGroup => !annotationGroup.error)
.map((annotationGroup, index) => {
const annotatorId = this.dicomAnnotationsService
.getAnnotatorIdByDicomAnnotationInstance(
dicomAnnotationModel);
// Common properties for all SideNavLayer objects
const commonProps = {
names: annotationGroup.annotationGroupLabel,
notes: annotationGroup.annotationGroupDescription,
annotatorId,
index,
};
switch (annotationGroup.graphicType) {
case 'POLYLINE':
return {
...commonProps,
feature: new Feature(new LineString(
annotationGroup.pointCoordinatesData)),
} as SideNavLayer;
case 'RECTANGLE':
const rectangles: Coordinate[][] = [];
for (let i = 0;
i < annotationGroup.pointCoordinatesData.length;
i += 4) {
const rectangle =
annotationGroup.pointCoordinatesData.slice(i, i + 4);
rectangles.push(rectangle);
}
const rectangleSideNavs = rectangles.map((rectangle) => {
const [topLeft, topRight, bottomRight, bottomLeft] =
rectangle;
const coordinates = [
topLeft, topRight, bottomRight, bottomLeft, topLeft
]; // Close the polygon
return {
...{
...commonProps,
feature: new Feature(
new Polygon([coordinates])),
}
} as SideNavLayer;
});
return rectangleSideNavs;
case 'ELLIPSE':
const ellipses: Coordinate[][] = [];
for (let i = 0;
i < annotationGroup.pointCoordinatesData.length;
i += 4) {
const ellipse =
annotationGroup.pointCoordinatesData.slice(i, i + 4);
ellipses.push(ellipse);
}
const elliipseSideNavs =
ellipses.map((ellipsesCoordinates) => {
const ellipseFeature =
this.computeEllipseFeature(ellipsesCoordinates);
return {
...commonProps,
feature: ellipseFeature,
} as SideNavLayer;
});
return elliipseSideNavs;
case 'POLYGON':
return {
...commonProps,
feature: new Feature(new Polygon(
[annotationGroup.pointCoordinatesData])),
} as SideNavLayer;
case 'POINT':
return annotationGroup.pointCoordinatesData.map(
(pointCoordinate, pointCoordinateIndex) => ({
...commonProps,
feature: new Feature(
new Point(pointCoordinate)),
index:
pointCoordinateIndex, // Use
// pointCoordinateIndex
// for POINTs
})) as SideNavLayer[];
default:
break; // Handle unknown graphic types
}
return undefined; // Return undefined for invalid or unsupported
// cases
})
.filter((entry): entry is SideNavLayer | SideNavLayer[] => !!entry);
return annotationSideNavLayer.flat();
}