-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(annotations): rework annotation manager api and enable multi-man…
…ager setup (#442) * fix the get annotations parameters * remove unnecessary element from remove annotation api * fix tests * fix karma * apply review comments * add feature to add and get annotation manager * initial re-write of the annotation manager * modifty annotation state * add annotations * add annotation * finish * update api * fix tests * useless param * go back to element * go back to element for add annotation * fix tests
- Loading branch information
Showing
59 changed files
with
963 additions
and
804 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/docs/docs/concepts/cornerstone-tools/annotation/annotationManager.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
id: annotationManager | ||
title: Annotation Manager | ||
--- | ||
|
||
The Annotation Manager is a singleton class that manages annotations in Cornerstone Tools. | ||
We use the Annotation Manager to store annotations, retrieve annotations, and save and restore annotations. | ||
|
||
## Default Annotation Manager | ||
The default Annotation Manager, `FrameOfReferenceSpecificAnnotationManager`, stores annotations based on the FrameOfReferenceUID. | ||
This means that annotations are stored separately for each FrameOfReferenceUID. | ||
|
||
Currently in our rendering pipeline, if two VolumeViewports share the same | ||
FrameOfReferenceUID, they will share the same annotations. However, StackViewports | ||
works on the per imageId basis, so annotations are not shared between StackViewports. | ||
|
||
### GroupKey | ||
Annotation groups are identified by a groupKey. The groupKey is a string that is used to identify the group of annotations. | ||
As mentioned above, the default Annotation Manager stores annotations based on the FrameOfReferenceUID, so the groupKey is the `FrameOfReferenceUID`. | ||
|
||
|
||
|
||
## Custom Annotation Manager | ||
|
||
You can create your own custom Annotation Manager by implementing the `IAnnotationManager` interface: | ||
|
||
```ts | ||
interface IAnnotationManager { | ||
getGroupKey: (annotationGroupSelector: any) => string; | ||
getAnnotations: ( | ||
groupKey: string, | ||
toolName?: string | ||
) => Annotations | GroupSpecificAnnotations | undefined; | ||
addAnnotation: (annotation: Annotation, groupKey?: string) => void; | ||
removeAnnotation: (annotationUID: string) => void; | ||
removeAnnotations: (groupKey: string, toolName?: string) => void; | ||
saveAnnotations: ( | ||
groupKey?: string, | ||
toolName?: string | ||
) => AnnotationState | GroupSpecificAnnotations | Annotations; | ||
restoreAnnotations: ( | ||
state: AnnotationState | GroupSpecificAnnotations | Annotations, | ||
groupKey?: string, | ||
toolName?: string | ||
) => void; | ||
getNumberOfAllAnnotations: () => number; | ||
removeAllAnnotations: () => void; | ||
} | ||
``` | ||
|
||
To use the Annotation Manager, you can set it as the default Annotation Manager using | ||
|
||
```js | ||
import { annotation } from '@cornerstonejs/tools'; | ||
import myCustomAnnotationManager from './myCustomAnnotationManager'; | ||
|
||
annotation.state.setAnnotationManager(myCustomAnnotationManager); | ||
``` | ||
|
||
The most important method in a custom Annotation Manager is the `getGroupKey` method. | ||
This method is used to determine the groupKey for a given element. For instance, | ||
if you have a usecase to show two separate annotations (e.g. two different readers) | ||
on two viewports that share the same FrameOfReferenceUID, you can use the `getGroupKey` | ||
method to return a different groupKey for each viewport given the element. (certainly | ||
you don't want to share the same annotations between the two viewports). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.