Skip to content

Commit

Permalink
Fixed: Issues disappear when using a zoom (#4189)
Browse files Browse the repository at this point in the history
* Fixed: Issues disappear when using a zoom

* Fixed creating issues for ellipses and rotated shapes

* Updated version & changelog
  • Loading branch information
Boris Sekachev authored Jan 19, 2022
1 parent bc4ff49 commit d3db54d
Show file tree
Hide file tree
Showing 21 changed files with 169 additions and 119 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bug: canvas is busy when start playing, start resizing a shape and do not release the mouse cursor (<https://github.com/openvinotoolkit/cvat/pull/4151>)
- Bug: could not receive frame N. TypeError: Cannot read properties of undefined (reding "filename") (<https://github.com/openvinotoolkit/cvat/pull/4187>)
- Fixed tus upload error over https (<https://github.com/openvinotoolkit/cvat/pull/4154>)
- Issues disappear when rescale a browser (<https://github.com/openvinotoolkit/cvat/pull/4189>)
- Auth token key is not returned when registering without email verification (<https://github.com/openvinotoolkit/cvat/pull/4092>)

### Security
Expand Down
1 change: 1 addition & 0 deletions cvat-canvas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ Standard JS events are used.
- canvas.zoomstart
- canvas.zoomstop
- canvas.zoom
- canvas.reshape
- canvas.fit
- canvas.dragshape => {id: number}
- canvas.roiselected => {points: number[]}
Expand Down
4 changes: 2 additions & 2 deletions cvat-canvas/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cvat-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-canvas",
"version": "2.12.2",
"version": "2.13.0",
"description": "Part of Computer Vision Annotation Tool which presents its canvas library",
"main": "src/canvas.ts",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion cvat-canvas/src/scss/canvas.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ polyline.cvat_shape_drawing_opacity {
}

.cvat_canvas_issue_region {
display: none;
stroke-width: 0;
}

Expand Down
6 changes: 3 additions & 3 deletions cvat-canvas/src/typescript/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2021 Intel Corporation
// Copyright (C) 2019-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -29,7 +29,7 @@ const CanvasVersion = pjson.version;
interface Canvas {
html(): HTMLDivElement;
setup(frameData: any, objectStates: any[], zLayer?: number): void;
setupIssueRegions(issueRegions: Record<number, number[]>): void;
setupIssueRegions(issueRegions: Record<number, { hidden: boolean; points: number[] }>): void;
activate(clientID: number | null, attributeID?: number): void;
rotate(rotationAngle: number): void;
focus(clientID: number, padding?: number): void;
Expand Down Expand Up @@ -77,7 +77,7 @@ class CanvasImpl implements Canvas {
this.model.setup(frameData, objectStates, zLayer);
}

public setupIssueRegions(issueRegions: Record<number, number[]>): void {
public setupIssueRegions(issueRegions: Record<number, { hidden: boolean; points: number[] }>): void {
this.model.setupIssueRegions(issueRegions);
}

Expand Down
6 changes: 3 additions & 3 deletions cvat-canvas/src/typescript/canvasController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2020 Intel Corporation
// Copyright (C) 2019-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -19,7 +19,7 @@ import {

export interface CanvasController {
readonly objects: any[];
readonly issueRegions: Record<number, number[]>;
readonly issueRegions: Record<number, { hidden: boolean; points: number[] }>;
readonly zLayer: number | null;
readonly focusData: FocusData;
readonly activeElement: ActiveElement;
Expand Down Expand Up @@ -123,7 +123,7 @@ export class CanvasControllerImpl implements CanvasController {
return this.model.zLayer;
}

public get issueRegions(): Record<number, number[]> {
public get issueRegions(): Record<number, { hidden: boolean; points: number[] }> {
return this.model.issueRegions;
}

Expand Down
13 changes: 7 additions & 6 deletions cvat-canvas/src/typescript/canvasModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019-2021 Intel Corporation
// Copyright (C) 2019-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -172,7 +172,7 @@ export enum Mode {
export interface CanvasModel {
readonly imageBitmap: boolean;
readonly image: Image | null;
readonly issueRegions: Record<number, number[]>;
readonly issueRegions: Record<number, { hidden: boolean; points: number[] }>;
readonly objects: any[];
readonly zLayer: number | null;
readonly gridSize: Size;
Expand All @@ -193,7 +193,7 @@ export interface CanvasModel {
move(topOffset: number, leftOffset: number): void;

setup(frameData: any, objectStates: any[], zLayer: number): void;
setupIssueRegions(issueRegions: Record<number, number[]>): void;
setupIssueRegions(issueRegions: Record<number, { hidden: boolean; points: number[] }>): void;
activate(clientID: number | null, attributeID: number | null): void;
rotate(rotationAngle: number): void;
focus(clientID: number, padding: number): void;
Expand Down Expand Up @@ -234,7 +234,7 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel {
gridSize: Size;
left: number;
objects: any[];
issueRegions: Record<number, number[]>;
issueRegions: Record<number, { hidden: boolean; points: number[] }>;
scale: number;
top: number;
zLayer: number | null;
Expand Down Expand Up @@ -353,6 +353,7 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel {

this.notify(UpdateReasons.FITTED_CANVAS);
this.notify(UpdateReasons.OBJECTS_UPDATED);
this.notify(UpdateReasons.ISSUE_REGIONS_UPDATED);
}

public bitmap(enabled: boolean): void {
Expand Down Expand Up @@ -445,7 +446,7 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel {
});
}

public setupIssueRegions(issueRegions: Record<number, number[]>): void {
public setupIssueRegions(issueRegions: Record<number, { hidden: boolean; points: number[] }>): void {
this.data.issueRegions = issueRegions;
this.notify(UpdateReasons.ISSUE_REGIONS_UPDATED);
}
Expand Down Expand Up @@ -756,7 +757,7 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel {
return this.data.image;
}

public get issueRegions(): Record<number, number[]> {
public get issueRegions(): Record<number, { hidden: boolean; points: number[] }> {
return { ...this.data.issueRegions };
}

Expand Down
15 changes: 13 additions & 2 deletions cvat-canvas/src/typescript/canvasView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
}
}

private setupIssueRegions(issueRegions: Record<number, number[]>): void {
private setupIssueRegions(issueRegions: Record<number, { hidden: boolean; points: number[] }>): void {
for (const issueRegion of Object.keys(this.drawnIssueRegions)) {
if (!(issueRegion in issueRegions) || !+issueRegion) {
this.drawnIssueRegions[+issueRegion].remove();
Expand All @@ -616,7 +616,7 @@ export class CanvasViewImpl implements CanvasView, Listener {

for (const issueRegion of Object.keys(issueRegions)) {
if (issueRegion in this.drawnIssueRegions) continue;
const points = this.translateToCanvas(issueRegions[+issueRegion]);
const points = this.translateToCanvas(issueRegions[+issueRegion].points);
if (points.length === 2) {
this.drawnIssueRegions[+issueRegion] = this.adoptedContent
.circle((consts.BASE_POINT_SIZE * 3 * 2) / this.geometry.scale)
Expand Down Expand Up @@ -656,6 +656,10 @@ export class CanvasViewImpl implements CanvasView, Listener {
'stroke-width': `${consts.BASE_STROKE_WIDTH / this.geometry.scale}`,
});
}

if (issueRegions[+issueRegion].hidden) {
this.drawnIssueRegions[+issueRegion].style({ display: 'none' });
}
}
}

Expand Down Expand Up @@ -1263,8 +1267,15 @@ export class CanvasViewImpl implements CanvasView, Listener {
} else if (reason === UpdateReasons.FITTED_CANVAS) {
// Canvas geometry is going to be changed. Old object positions aren't valid any more
this.setupObjects([]);
this.setupIssueRegions({});
this.moveCanvas();
this.resizeCanvas();
this.canvas.dispatchEvent(
new CustomEvent('canvas.reshape', {
bubbles: false,
cancelable: true,
}),
);
} else if ([UpdateReasons.IMAGE_ZOOMED, UpdateReasons.IMAGE_FITTED].includes(reason)) {
this.moveCanvas();
this.transformCanvas();
Expand Down
4 changes: 2 additions & 2 deletions cvat-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cvat-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.33.2",
"version": "1.33.3",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2021 Intel Corporation
// Copyright (C) 2021-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -10,6 +10,7 @@ import { MenuInfo } from 'rc-menu/lib/interface';

import ObjectItemContainer from 'containers/annotation-page/standard-workspace/objects-side-bar/object-item';
import { Workspace } from 'reducers/interfaces';
import { rotatePoint } from 'utils/math';
import consts from 'consts';

interface Props {
Expand Down Expand Up @@ -106,7 +107,29 @@ export default function CanvasContextMenu(props: Props): JSX.Element | null {
);
if (param.key === ReviewContextMenuKeys.OPEN_ISSUE) {
if (state) {
onStartIssue(state.points);
let { points } = state;
if (['ellipse', 'rectangle'].includes(state.shapeType)) {
const [cx, cy] = state.shapeType === 'ellipse' ? state.points : [
(state.points[0] + state.points[2]) / 2,
(state.points[1] + state.points[3]) / 2,
];
const [rx, ry] = [state.points[2] - cx, cy - state.points[3]];
points = state.shapeType === 'ellipse' ? [
state.points[0] - rx,
state.points[1] - ry,
state.points[0] + rx,
state.points[1] + ry,
] : state.points;

points = [
[points[0], points[1]],
[points[2], points[1]],
[points[2], points[3]],
[points[0], points[3]],
].map(([x, y]: number[]) => rotatePoint(x, y, state.rotation, cx, cy)).flat();
}

onStartIssue(points);
}
} else if (param.key === ReviewContextMenuKeys.QUICK_ISSUE_POSITION) {
if (state) {
Expand Down
24 changes: 0 additions & 24 deletions cvat-ui/src/components/annotation-page/canvas/canvas-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ interface Props {
activatedStateID: number | null;
activatedAttributeID: number | null;
annotations: any[];
frameIssues: any[] | null;
frameData: any;
frameAngle: number;
frameFetching: boolean;
Expand Down Expand Up @@ -136,7 +135,6 @@ export default class CanvasWrapperComponent extends React.PureComponent<Props> {
});

this.initialSetup();
this.updateIssueRegions();
this.updateCanvas();
}

Expand All @@ -148,7 +146,6 @@ export default class CanvasWrapperComponent extends React.PureComponent<Props> {
outlined,
outlineColor,
showBitmap,
frameIssues,
frameData,
frameAngle,
annotations,
Expand Down Expand Up @@ -256,10 +253,6 @@ export default class CanvasWrapperComponent extends React.PureComponent<Props> {
}
}

if (prevProps.frameIssues !== frameIssues) {
this.updateIssueRegions();
}

if (
prevProps.annotations !== annotations ||
prevProps.frameData !== frameData ||
Expand Down Expand Up @@ -684,23 +677,6 @@ export default class CanvasWrapperComponent extends React.PureComponent<Props> {
}
}

private updateIssueRegions(): void {
const { frameIssues } = this.props;
const { canvasInstance } = this.props as { canvasInstance: Canvas };
if (frameIssues === null) {
canvasInstance.setupIssueRegions({});
} else {
const regions = frameIssues.reduce((acc: Record<number, number[]>, issue: any): Record<
number,
number[]
> => {
acc[issue.id] = issue.position;
return acc;
}, {});
canvasInstance.setupIssueRegions(regions);
}
}

private updateCanvas(): void {
const {
curZLayer, annotations, frameData, canvasInstance,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020-2021 Intel Corporation
// Copyright (C) 2020-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -16,7 +16,7 @@ interface Props {
selectIssuePosition(enabled: boolean): void;
}

function ResizeControl(props: Props): JSX.Element {
function CreateIssueControl(props: Props): JSX.Element {
const { activeControl, canvasInstance, selectIssuePosition } = props;

return (
Expand All @@ -43,4 +43,4 @@ function ResizeControl(props: Props): JSX.Element {
);
}

export default React.memo(ResizeControl);
export default React.memo(CreateIssueControl);
Loading

0 comments on commit d3db54d

Please sign in to comment.