Skip to content

Commit 25d9397

Browse files
authored
ITEP-68000 - Import keypoint detection - p2 (#489)
1 parent 968f8c0 commit 25d9397

File tree

30 files changed

+395
-133
lines changed

30 files changed

+395
-133
lines changed

web_ui/src/core/datasets/dataset.interface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export interface DatasetImportTask {
8383
keypointStructure?: KeypointStructureDTO;
8484
}
8585

86+
export interface DatasetImportKeypointTask extends DatasetImportTask {
87+
keypointStructure: KeypointStructureDTO;
88+
}
89+
8690
export interface DatasetImportConnection {
8791
from: string;
8892
to: string;

web_ui/src/core/projects/services/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ const isKeypointType = (otherTask: TaskDTO | KeypointTaskDTO): otherTask is Keyp
257257
return domain !== undefined && isKeypointDetection(domain);
258258
};
259259

260-
const getKeypointStructure = (structureDTO: KeypointStructureDTO, labels: Label[]): KeypointStructure => {
260+
export const formatDtoToKeypointStructure = (
261+
structureDTO: KeypointStructureDTO,
262+
labels: Label[]
263+
): KeypointStructure => {
261264
return {
262265
...structureDTO,
263266
positions: structureDTO.positions.map((position) => {
@@ -293,7 +296,7 @@ export const getProjectEntity = (serverProject: ProjectDTO, router = API_URLS):
293296
return isKeypointType(task)
294297
? {
295298
...commonStructure,
296-
keypointStructure: getKeypointStructure(task.keypoint_structure, commonStructure.labels),
299+
keypointStructure: formatDtoToKeypointStructure(task.keypoint_structure, commonStructure.labels),
297300
}
298301
: commonStructure;
299302
})

web_ui/src/pages/annotator/tools/keypoint-tool/secondary-toolbar.component.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { Delete, LineMappingLight, Reject } from '@geti/ui/icons';
77
import { isKeypointAnnotation } from '../../../../core/annotations/services/utils';
88
import { labelFromUser } from '../../../../core/annotations/utils';
99
import { AcceptButton } from '../../../../shared/components/quiet-button/accept-button.component';
10+
import { PointAxis } from '../../../utils';
1011
import { useVisibleAnnotations } from '../../hooks/use-visible-annotations.hook';
1112
import { useZoom } from '../../zoom/zoom-provider.component';
1213
import { ToolAnnotationContextProps } from '../tools.interface';
1314
import { useKeypointState } from './keypoint-state-provider.component';
14-
import { getAnnotationInBoundingBox, getInnerPaddedBoundingBox, mirrorPointsAcrossAxis, PointAxis } from './utils';
15+
import { getAnnotationInBoundingBox, getInnerPaddedBoundingBox, mirrorPointsAcrossAxis } from './utils';
1516

1617
export const SecondaryToolbar = ({ annotationToolContext }: ToolAnnotationContextProps) => {
1718
const { zoomState } = useZoom();

web_ui/src/pages/annotator/tools/keypoint-tool/utils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { KeypointStructure } from '../../../../core/projects/task.interface';
55
import { getMockedKeypointNode } from '../../../../test-utils/mocked-items-factory/mocked-keypoint';
66
import { getMockedLabel } from '../../../../test-utils/mocked-items-factory/mocked-labels';
7+
import { PointAxis } from '../../../utils';
78
import {
89
CursorDirection,
910
getAnnotationInBoundingBox,
@@ -18,7 +19,6 @@ import {
1819
groupByFirstNode,
1920
mirrorPointsAcrossAxis,
2021
PADDING_MULTIPLIER,
21-
PointAxis,
2222
rotatePointsAroundPivot,
2323
} from './utils';
2424

web_ui/src/pages/annotator/tools/keypoint-tool/utils.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,9 @@ import { KeypointNode, Point } from '../../../../core/annotations/shapes.interfa
1313
import { ShapeType } from '../../../../core/annotations/shapetype.enum';
1414
import { KeypointStructure } from '../../../../core/projects/task.interface';
1515
import { isNonEmptyString } from '../../../../shared/utils';
16-
import { KEYPOINT_RADIUS } from '../../../utils';
16+
import { getMaxMinPoint, KEYPOINT_RADIUS, PointAxis } from '../../../utils';
1717
import { createAnnotation } from '../../utils';
1818

19-
export enum PointAxis {
20-
X = 'x',
21-
Y = 'y',
22-
}
23-
2419
export enum CursorDirection {
2520
SouthEast = 'south-east',
2621
SouthWest = 'south-west',
@@ -194,12 +189,6 @@ export const getTemplateWithDirection = (templatePoints: KeypointNode[], cursorD
194189
return templatePoints;
195190
};
196191

197-
const getMaxMinPoint = <T extends Point>(points: T[], pointAxis: PointAxis) => {
198-
const minAxisValue = Math.min(...points.map((point) => point[pointAxis]));
199-
const maxAxisValue = Math.max(...points.map((point) => point[pointAxis]));
200-
return [minAxisValue, maxAxisValue];
201-
};
202-
203192
export const getPoseLocations = (points: KeypointNode[], gap: number): PoseLocations => {
204193
const [minX, maxX] = getMaxMinPoint(points, PointAxis.X);
205194
const [minY, maxY] = getMaxMinPoint(points, PointAxis.Y);

web_ui/src/pages/create-project/components/pose-template/canvas/canvas-template.component.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@ import { KeyMap } from '../../../../../shared/keyboard-events/keyboard.interface
1616
import { getIds, hasDifferentId } from '../../../../../shared/utils';
1717
import { ClosestKeypoint } from '../../../../annotator/tools/edit-tool/edit-keypoint/closest-keypoint.component';
1818
import { useZoom } from '../../../../annotator/zoom/zoom-provider.component';
19-
import { getPointInRoi } from '../../../../utils';
19+
import { EdgeLine, getPointInRoi, TemplateState, TemplateStateWithHistory } from '../../../../utils';
2020
import {
21-
EdgeLine,
2221
getDefaultLabelStructure,
2322
isDifferentLabel,
2423
isEdgeConnectingPoints,
2524
isEqualLabel,
2625
isNotMatchingEdge,
27-
TemplateState,
28-
TemplateStateWithHistory,
2926
updateWithLatestPoints,
3027
} from '../util';
3128
import { DrawingBox } from './drawing-box.component';
@@ -61,6 +58,7 @@ export const CanvasTemplate = ({
6158

6259
const isDrawingGhostLine = !isNil(ghostLine?.from);
6360
const selectedPoint = points.find(({ label }) => isSelected(label.id));
61+
const nextPointName = String(points.length + 1);
6462

6563
const isShiftPress = useIsPressed({
6664
key: KeyMap.Shift,
@@ -110,6 +108,7 @@ export const CanvasTemplate = ({
110108

111109
const handleDeletePoint = (point: KeypointNode) => {
112110
onStateUpdate({
111+
skipHistory: false,
113112
points: points.filter(isDifferentLabel(point)),
114113
edges: edges.filter((currentEdge) => {
115114
return isDifferentLabel(currentEdge.from)(point) && isDifferentLabel(currentEdge.to)(point);
@@ -168,10 +167,10 @@ export const CanvasTemplate = ({
168167
border: '1px solid var(--spectrum-global-color-gray-200)',
169168
}}
170169
>
171-
{isAddPointEnabled && (
170+
{isAddPointEnabled && nextPointName !== null && (
172171
<DrawingBox
173-
totalPoints={points.length + 1}
174172
onAddPoint={handleNewPoint}
173+
nextPointName={nextPointName}
175174
onPointerMove={handleGhostLineEndMoving}
176175
/>
177176
)}

web_ui/src/pages/create-project/components/pose-template/canvas/drawing-box.component.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import { getRelativePoint, leftMouseButtonHandler } from '../../../../utils';
1010
import { getDefaultLabelStructure } from '../util';
1111

1212
interface DrawingBoxProps {
13-
totalPoints: number;
13+
nextPointName: string;
1414
onAddPoint: (point: KeypointNode) => void;
1515
onPointerMove: (point: Point) => void;
1616
}
1717

18-
export const DrawingBox = ({ totalPoints, onAddPoint, onPointerMove }: DrawingBoxProps) => {
18+
export const DrawingBox = ({ nextPointName, onAddPoint, onPointerMove }: DrawingBoxProps) => {
1919
const canvasRef = useRef<SVGRectElement>(null);
2020
const { zoomState } = useZoom();
2121

@@ -29,7 +29,7 @@ export const DrawingBox = ({ totalPoints, onAddPoint, onPointerMove }: DrawingBo
2929
}
3030

3131
onAddPoint({
32-
label: getDefaultLabelStructure(String(totalPoints)),
32+
label: getDefaultLabelStructure(nextPointName),
3333
isVisible: true,
3434
...getRelativePoint(canvasRef.current, { x: event.clientX, y: event.clientY }, zoomState.zoom),
3535
});

web_ui/src/pages/create-project/components/pose-template/canvas/point-edges.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Delete } from '@geti/ui/icons';
66

77
import { KeypointNode, Point } from '../../../../../core/annotations/shapes.interface';
88
import { useSelected } from '../../../../../providers/selected-provider/selected-provider.component';
9-
import { EdgeLine } from '../util';
9+
import { EdgeLine } from '../../../../utils';
1010
import { Edge } from './edge.component';
1111

1212
interface PointEdgesProps {

web_ui/src/pages/create-project/components/pose-template/hooks/use-undo-redo-with-callback.hook.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useEffect, useRef } from 'react';
55

66
import { runWhen } from '../../../../../shared/utils';
77
import useUndoRedoState, { UseUndoRedoState } from '../../../../annotator/tools/undo-redo/use-undo-redo-state';
8-
import { TemplateState } from '../util';
8+
import { TemplateState } from '../../../../utils';
99

1010
export const useUndoRedoWithCallback = (
1111
initialState: TemplateState,

web_ui/src/pages/create-project/components/pose-template/pose-template.component.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ import { RegionOfInterest } from '../../../../core/annotations/annotation.interf
1010
import { TaskMetadata } from '../../../../core/projects/task.interface';
1111
import { SliderAnimation } from '../../../../shared/components/slider-animation/slider-animation.component';
1212
import { isNonEmptyString } from '../../../../shared/utils';
13+
import { TemplateState } from '../../../utils';
1314
import { ProjectMetadata } from '../../new-project-dialog-provider/new-project-dialog-provider.interface';
1415
import { getLabelsNamesErrors } from '../../utils';
1516
import { InfoSection } from '../info-section/info-section.component';
1617
import { TemplateManager } from './template-manager.component';
17-
import { getProjectTypeMetadata, TemplateState } from './util';
18+
import { getProjectTypeMetadata } from './util';
1819

1920
export interface PoseTemplateProps {
2021
metadata: TaskMetadata[];

0 commit comments

Comments
 (0)