Skip to content

Commit 80334a3

Browse files
committed
Remove annotationToolContext dependency
1 parent 0b2fef1 commit 80334a3

File tree

13 files changed

+45
-80
lines changed

13 files changed

+45
-80
lines changed

web_ui/src/pages/annotator/annotation/labels/annotation-actions.component.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Annotation } from '../../../../core/annotations/annotation.interface';
99
import { isAnomalyDomain, isClassificationDomain } from '../../../../core/projects/domains';
1010
import { ANIMATION_PARAMETERS } from '../../../../shared/animation-parameters/animation-parameters';
1111
import { hasEqualId } from '../../../../shared/utils';
12-
import { AnnotationToolContext } from '../../core/annotation-tool-context.interface';
12+
import { useAnnotationScene } from '../../providers/annotation-scene-provider/annotation-scene-provider.component';
1313
import { useROI } from '../../providers/region-of-interest-provider/region-of-interest-provider.component';
1414
import { getGlobalAnnotations } from '../../providers/task-chain-provider/utils';
1515
import { useTask } from '../../providers/task-provider/task-provider.component';
@@ -18,21 +18,20 @@ import classes from './labels.module.scss';
1818

1919
interface LabelActionsProps {
2020
annotation: Annotation;
21-
annotationToolContext: AnnotationToolContext;
2221
setEditLabels: (editLabels: boolean) => void;
2322
}
2423

25-
const useOnRemoveLabels = (annotationToolContext: AnnotationToolContext, annotation: Annotation) => {
24+
const useOnRemoveLabels = (annotation: Annotation) => {
2625
const { selectedTask } = useTask();
2726
const { roi } = useROI();
28-
const { removeAnnotations, removeLabels } = annotationToolContext.scene;
27+
const { annotations, removeAnnotations, removeLabels } = useAnnotationScene();
2928

3029
if (selectedTask === null) {
3130
return () => removeAnnotations([annotation]);
3231
}
3332

3433
if (isClassificationDomain(selectedTask.domain) || isAnomalyDomain(selectedTask.domain)) {
35-
const globalAnnotations = getGlobalAnnotations(annotationToolContext.scene.annotations, roi, selectedTask);
34+
const globalAnnotations = getGlobalAnnotations(annotations, roi, selectedTask);
3635

3736
if (!globalAnnotations.some(hasEqualId(annotation.id))) {
3837
return () => {
@@ -50,12 +49,8 @@ const useOnRemoveLabels = (annotationToolContext: AnnotationToolContext, annotat
5049
};
5150
};
5251

53-
export const AnnotationActions = ({
54-
annotation,
55-
annotationToolContext,
56-
setEditLabels,
57-
}: LabelActionsProps): JSX.Element => {
58-
const onRemoveLabels = useOnRemoveLabels(annotationToolContext, annotation);
52+
export const AnnotationActions = ({ annotation, setEditLabels }: LabelActionsProps): JSX.Element => {
53+
const onRemoveLabels = useOnRemoveLabels(annotation);
5954

6055
const onEditLabels = () => {
6156
setEditLabels(true);

web_ui/src/pages/annotator/annotation/labels/edit-labels.component.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ import { isAnomalyDomain } from '../../../../core/projects/domains';
1010
import { TaskLabelTreeSearchPopover } from '../../../../shared/components/task-label-tree-search/task-label-tree-search-popover.component';
1111
import { hasEqualId, runWhenTruthy } from '../../../../shared/utils';
1212
import { SelectionIndicator } from '../../components/labels/label-search/selection-indicator.component';
13-
import { AnnotationToolContext } from '../../core/annotation-tool-context.interface';
13+
import { useAnnotationScene } from '../../providers/annotation-scene-provider/annotation-scene-provider.component';
1414
import { useROI } from '../../providers/region-of-interest-provider/region-of-interest-provider.component';
1515
import { getGlobalAnnotations } from '../../providers/task-chain-provider/utils';
1616
import { useTask } from '../../providers/task-provider/task-provider.component';
1717

1818
interface EditLabelsProps {
1919
setEditLabels: (editLabels: boolean) => void;
2020
annotation: Annotation;
21-
annotationToolContext: AnnotationToolContext;
2221
}
2322

24-
export const EditLabels = ({ annotation, annotationToolContext, setEditLabels }: EditLabelsProps): JSX.Element => {
23+
export const EditLabels = ({ annotation, setEditLabels }: EditLabelsProps): JSX.Element => {
2524
const { roi } = useROI();
2625
const { tasks, selectedTask } = useTask();
27-
const { addLabel, removeLabels, annotations } = annotationToolContext.scene;
26+
const { addLabel, removeLabels, annotations } = useAnnotationScene();
2827

2928
const isAnomalyTask = selectedTask && isAnomalyDomain(selectedTask?.domain);
3029
const globalAnnotations = getGlobalAnnotations(annotations, roi, selectedTask);

web_ui/src/pages/annotator/annotation/labels/labels.component.tsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { useHover } from 'react-aria';
1111
import { Annotation } from '../../../../core/annotations/annotation.interface';
1212
import { ShapeType } from '../../../../core/annotations/shapetype.enum';
1313
import { isRect } from '../../../../core/annotations/utils';
14-
import { AnnotationToolContext, ToolType } from '../../core/annotation-tool-context.interface';
14+
import { ToolType } from '../../core/annotation-tool-context.interface';
15+
import { useAnnotationToolContext } from '../../providers/annotation-tool-provider/annotation-tool-provider.component';
1516
import { useTask } from '../../providers/task-provider/task-provider.component';
1617
import { AnnotationActions } from './annotation-actions.component';
1718
import { EditLabels } from './edit-labels.component';
@@ -27,7 +28,6 @@ export interface LabelsProps {
2728
showOptions?: boolean;
2829
annotation: Annotation;
2930
areLabelsInteractive?: boolean;
30-
annotationToolContext: AnnotationToolContext;
3131
canEditAnnotationLabel?: boolean;
3232
}
3333

@@ -67,12 +67,12 @@ export const Labels = ({
6767
annotation,
6868
isOverlap = false,
6969
showOptions = true,
70-
annotationToolContext,
7170
areLabelsInteractive = true,
7271
canEditAnnotationLabel = true,
7372
}: LabelsProps): JSX.Element => {
7473
const { selectedTask } = useTask();
7574
const { x: left, y, height } = useLabelPosition(annotation);
75+
const { tool } = useAnnotationToolContext();
7676

7777
const [editLabels, setEditLabels] = useState(false);
7878
const { hoverProps, isHovered } = useHover({ isDisabled: editLabels || !canEditAnnotationLabel });
@@ -84,9 +84,10 @@ export const Labels = ({
8484
return undefined;
8585
}
8686

87-
if (!annotation.isSelected && annotationToolContext.tool === ToolType.SelectTool) {
87+
if (!annotation.isSelected && tool === ToolType.SelectTool) {
8888
return isHovered ? 2 : 1;
8989
}
90+
9091
return undefined;
9192
};
9293

@@ -112,11 +113,7 @@ export const Labels = ({
112113
// Make sure the label search component overlaps labels from other annotations
113114
style={{ ...style, zIndex: 2 }}
114115
>
115-
<EditLabels
116-
annotation={annotation}
117-
setEditLabels={setEditLabels}
118-
annotationToolContext={annotationToolContext}
119-
/>
116+
<EditLabels annotation={annotation} setEditLabels={setEditLabels} />
120117
</div>
121118
</>
122119
);
@@ -167,11 +164,7 @@ export const Labels = ({
167164

168165
<AnimatePresence>
169166
{showOptions && isHovered && (
170-
<AnnotationActions
171-
setEditLabels={setEditLabels}
172-
annotation={annotation}
173-
annotationToolContext={annotationToolContext}
174-
/>
167+
<AnnotationActions setEditLabels={setEditLabels} annotation={annotation} />
175168
)}
176169
</AnimatePresence>
177170
</ul>

web_ui/src/pages/annotator/annotation/labels/shape-label.component.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ interface ShapeLabelProps extends LabelsProps {
99
isOverlap?: boolean;
1010
}
1111

12-
export const ShapeLabel = ({
13-
isOverlap,
14-
annotation,
15-
showOptions,
16-
areLabelsInteractive,
17-
annotationToolContext,
18-
}: ShapeLabelProps) => {
12+
export const ShapeLabel = ({ isOverlap, annotation, showOptions, areLabelsInteractive }: ShapeLabelProps) => {
1913
if (isPoseShape(annotation.shape)) {
2014
return annotation.shape.points.map((point) => (
2115
<ExpandablePointLabel isVisible key={point.label.id} point={point} isOverlap={isOverlap} />
@@ -28,7 +22,6 @@ export const ShapeLabel = ({
2822
showOptions={showOptions}
2923
annotation={annotation}
3024
areLabelsInteractive={areLabelsInteractive}
31-
annotationToolContext={annotationToolContext}
3225
/>
3326
);
3427
};

web_ui/src/pages/annotator/annotation/layers/layers.component.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export const Layers = ({
6464
showOptions={showLabelOptions && isActiveLearningMode}
6565
annotation={annotation}
6666
areLabelsInteractive={props.areLabelsInteractive}
67-
annotationToolContext={props.annotationToolContext}
6867
/>
6968
)}
7069
/>
@@ -86,7 +85,6 @@ export const Layers = ({
8685
annotation={annotation}
8786
isOverlap={!isClassification}
8887
areLabelsInteractive={props.areLabelsInteractive}
89-
annotationToolContext={props.annotationToolContext}
9088
/>
9189
)}
9290
/>

web_ui/src/pages/annotator/annotation/layers/video-layers.component.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export const VideoLayers = ({
7777
showOptions={isActiveLearningMode}
7878
annotation={annotation}
7979
areLabelsInteractive={props.areLabelsInteractive}
80-
annotationToolContext={props.annotationToolContext}
8180
/>
8281
)}
8382
/>
@@ -96,7 +95,6 @@ export const VideoLayers = ({
9695
showOptions={false}
9796
annotation={annotation}
9897
areLabelsInteractive={props.areLabelsInteractive}
99-
annotationToolContext={props.annotationToolContext}
10098
/>
10199
)}
102100
/>

web_ui/src/pages/annotator/annotator-canvas.component.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ export function AnnotatorCanvas({
166166
<Labels
167167
key={annotation.id}
168168
annotation={annotation}
169-
annotationToolContext={annotationToolContext}
170169
canEditAnnotationLabel={canEditAnnotationLabel}
171170
/>
172171
))}

web_ui/src/pages/annotator/components/annotator-preview/preview-canvas-content.component.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { AnnotationsMask } from '../../annotation/annotations-mask.component';
1212
import { ShapeLabel } from '../../annotation/labels/shape-label.component';
1313
import { Layer } from '../../annotation/layers/layer.component';
1414
import { MediaImage } from '../../media-image.component';
15-
import { useAnnotationToolContext } from '../../providers/annotation-tool-provider/annotation-tool-provider.component';
1615
import { useAnnotatorCanvasSettings } from '../../providers/annotator-canvas-settings-provider/annotator-canvas-settings-provider.component';
1716
import {
1817
useExplanationOpacity,
@@ -46,7 +45,6 @@ export const PreviewCanvasContent = ({
4645
const { inputs } = useTaskChain();
4746
const { zoomState } = useZoom();
4847
const { tasks, selectedTask } = useTask();
49-
const annotationToolContext = useAnnotationToolContext();
5048
const { canvasSettingsState } = useAnnotatorCanvasSettings();
5149
const { showOverlapAnnotations } = useExplanationOpacity();
5250
const { isExplanationVisible, selectedExplanation } = usePrediction();
@@ -97,13 +95,7 @@ export const PreviewCanvasContent = ({
9795
selectedTask={selectedTask}
9896
globalAnnotations={getGlobalAnnotations(visibleAnnotations, roi, selectedTask)}
9997
removeBackground={showOverlapAnnotations}
100-
renderLabel={(annotation) => (
101-
<ShapeLabel
102-
showOptions={false}
103-
annotation={annotation}
104-
annotationToolContext={annotationToolContext}
105-
/>
106-
)}
98+
renderLabel={(annotation) => <ShapeLabel showOptions={false} annotation={annotation} />}
10799
/>
108100
)}
109101

@@ -117,13 +109,7 @@ export const PreviewCanvasContent = ({
117109
selectedTask={selectedTask}
118110
globalAnnotations={getGlobalAnnotations(annotations, roi, selectedTask)}
119111
isOverlap={!isClassification}
120-
renderLabel={(annotation) => (
121-
<ShapeLabel
122-
showOptions={false}
123-
annotation={annotation}
124-
annotationToolContext={annotationToolContext}
125-
/>
126-
)}
112+
renderLabel={(annotation) => <ShapeLabel showOptions={false} annotation={annotation} />}
127113
/>
128114
)}
129115
</div>

web_ui/src/pages/annotator/tools/edit-tool/edit-annotation-tool.component.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ToolType } from '../../core/annotation-tool-context.interface';
1313
import { useROI } from '../../providers/region-of-interest-provider/region-of-interest-provider.component';
1414
import { getGlobalAnnotations } from '../../providers/task-chain-provider/utils';
1515
import { useTask } from '../../providers/task-provider/task-provider.component';
16+
import { useZoom } from '../../zoom/zoom-provider.component';
1617
import { SelectingToolType } from '../selecting-tool/selecting-tool.enums';
1718
import { ToolAnnotationContextProps } from '../tools.interface';
1819
import { EditBoundingBox as EditBoundingBoxTool } from './edit-bounding-box/edit-bounding-box.component';
@@ -32,21 +33,28 @@ const EditAnnotationToolFactory = ({
3233
disableTranslation = false,
3334
disablePoints = false,
3435
}: EditAnnotationToolFactoryProps) => {
35-
const { roi } = useROI();
36+
const { roi, image } = useROI();
3637
const { tasks, selectedTask } = useTask();
3738
const task = selectedTask ?? tasks[0];
39+
const { scene } = annotationToolContext;
40+
const {
41+
zoomState: { zoom },
42+
} = useZoom();
3843

39-
const globalAnnotations = getGlobalAnnotations(annotationToolContext.scene.annotations, roi, task);
44+
const globalAnnotations = getGlobalAnnotations(scene.annotations, roi, task);
4045

4146
if (globalAnnotations.some(hasEqualId(annotation.id))) {
42-
return <Labels annotation={annotation} annotationToolContext={annotationToolContext} />;
47+
return <Labels annotation={annotation} />;
4348
}
4449

4550
switch (annotation.shape.shapeType) {
4651
case ShapeType.Rect: {
4752
return (
4853
<EditBoundingBoxTool
49-
annotationToolContext={annotationToolContext}
54+
roi={roi}
55+
image={image}
56+
zoom={zoom}
57+
updateAnnotation={scene.updateAnnotation}
5058
annotation={annotation as Annotation & { shape: { shapeType: ShapeType.Rect } }}
5159
disableTranslation={disableTranslation}
5260
disablePoints={disablePoints}

web_ui/src/pages/annotator/tools/edit-tool/edit-bounding-box/edit-bounding-box.component.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,42 @@
44
import { useEffect, useState } from 'react';
55

66
import { ANCHOR_SIZE, ResizeAnchor } from '@geti/smart-tools';
7+
import { RegionOfInterest } from '@geti/smart-tools/types';
78

89
import { Annotation } from '../../../../../core/annotations/annotation.interface';
910
import { Point } from '../../../../../core/annotations/shapes.interface';
1011
import { ShapeType } from '../../../../../core/annotations/shapetype.enum';
1112
import { Labels } from '../../../annotation/labels/labels.component';
12-
import { AnnotationToolContext } from '../../../core/annotation-tool-context.interface';
13-
import { useROI } from '../../../providers/region-of-interest-provider/region-of-interest-provider.component';
14-
import { useZoom } from '../../../zoom/zoom-provider.component';
1513
import { TranslateShape } from '../translate-shape.component';
1614
import { getBoundingBoxInRoi, getBoundingBoxResizePoints, getClampedBoundingBox } from '../utils';
1715

1816
import classes from './../../../annotator-canvas.module.scss';
1917

2018
interface EditBoundingBoxProps {
21-
annotationToolContext: AnnotationToolContext;
2219
annotation: Annotation & { shape: { shapeType: ShapeType.Rect } };
2320
disableTranslation?: boolean;
2421
disablePoints?: boolean;
22+
roi: RegionOfInterest;
23+
image: ImageData;
24+
zoom: number;
25+
updateAnnotation: (annotation: Annotation) => void;
2526
}
2627

2728
export const EditBoundingBox = ({
28-
annotationToolContext,
2929
annotation,
3030
disablePoints = false,
3131
disableTranslation = false,
32+
roi,
33+
image,
34+
zoom,
35+
updateAnnotation,
3236
}: EditBoundingBoxProps): JSX.Element => {
3337
const [shape, setShape] = useState(annotation.shape);
3438

3539
useEffect(() => setShape(annotation.shape), [annotation.shape]);
3640

37-
const { scene } = annotationToolContext;
38-
const {
39-
zoomState: { zoom },
40-
} = useZoom();
41-
const { roi, image } = useROI();
42-
4341
const onComplete = () => {
44-
scene.updateAnnotation({ ...annotation, shape });
42+
updateAnnotation({ ...annotation, shape });
4543
};
4644

4745
const translate = (point: Point) => {
@@ -75,7 +73,7 @@ export const EditBoundingBox = ({
7573
/>
7674
</svg>
7775

78-
<Labels annotation={{ ...annotation, shape }} annotationToolContext={annotationToolContext} />
76+
<Labels annotation={{ ...annotation, shape }} />
7977

8078
{disablePoints === false ? (
8179
<svg

0 commit comments

Comments
 (0)