Skip to content

Commit

Permalink
Added switcher to maintain poylgon crop behaviour (#2961) (#3021)
Browse files Browse the repository at this point in the history
* Added switcher to maintain poylgon crop behaviour (#2961)

* Updated versions & changelog
  • Loading branch information
Boris Sekachev authored Mar 29, 2021
1 parent 57385fa commit 1f56fd2
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ability of upload manifest for dataset with images (<https://github.com/openvinotoolkit/cvat/pull/2763>)
- Annotations filters UI using react-awesome-query-builder (https://github.com/openvinotoolkit/cvat/issues/1418)
- [ICDAR](https://rrc.cvc.uab.es/?ch=2) format support (<https://github.com/openvinotoolkit/cvat/pull/2866>)
- Added switcher to maintain poylgon crop behaviour (<https://github.com/openvinotoolkit/cvat/pull/3021>)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion 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.3.2",
"version": "2.4.0",
"description": "Part of Computer Vision Annotation Tool which presents its canvas library",
"main": "src/canvas.ts",
"scripts": {
Expand Down
15 changes: 10 additions & 5 deletions cvat-canvas/src/typescript/canvasModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface Configuration {
undefinedAttrValue?: string;
showProjections?: boolean;
forceDisableEditing?: boolean;
intelligentPolygonCrop?: boolean;
}

export interface DrawData {
Expand Down Expand Up @@ -621,25 +622,29 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel {
}

public configure(configuration: Configuration): void {
if (typeof configuration.displayAllText !== 'undefined') {
if (typeof configuration.displayAllText === 'boolean') {
this.data.configuration.displayAllText = configuration.displayAllText;
}

if (typeof configuration.showProjections !== 'undefined') {
if (typeof configuration.showProjections === 'boolean') {
this.data.configuration.showProjections = configuration.showProjections;
}
if (typeof configuration.autoborders !== 'undefined') {
if (typeof configuration.autoborders === 'boolean') {
this.data.configuration.autoborders = configuration.autoborders;
}

if (typeof configuration.undefinedAttrValue !== 'undefined') {
if (typeof configuration.undefinedAttrValue === 'string') {
this.data.configuration.undefinedAttrValue = configuration.undefinedAttrValue;
}

if (typeof configuration.forceDisableEditing !== 'undefined') {
if (typeof configuration.forceDisableEditing === 'boolean') {
this.data.configuration.forceDisableEditing = configuration.forceDisableEditing;
}

if (typeof configuration.intelligentPolygonCrop === 'boolean') {
this.data.configuration.intelligentPolygonCrop = configuration.intelligentPolygonCrop;
}

this.notify(UpdateReasons.CONFIG_UPDATED);
}

Expand Down
10 changes: 8 additions & 2 deletions cvat-canvas/src/typescript/editHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class EditHandlerImpl implements EditHandler {
private editLine: SVG.PolyLine;
private clones: SVG.Polygon[];
private autobordersEnabled: boolean;
private intelligentCutEnabled: boolean;

private setupTrailingPoint(circle: SVG.Circle): void {
const head = this.editedShape.attr('points').split(' ').slice(0, this.editData.pointID).join(' ');
Expand Down Expand Up @@ -259,11 +260,11 @@ export class EditHandlerImpl implements EditHandler {
this.editLine.remove();
this.editLine = null;

if (pointsCriteria && lengthCriteria) {
if (pointsCriteria && lengthCriteria && this.intelligentCutEnabled) {
this.clones.push(this.canvas.polygon(firstPart.join(' ')));
this.selectPolygon(this.clones[0]);
// left indexes1 and
} else if (!pointsCriteria && !lengthCriteria) {
} else if (!pointsCriteria && !lengthCriteria && this.intelligentCutEnabled) {
this.clones.push(this.canvas.polygon(secondPart.join(' ')));
this.selectPolygon(this.clones[0]);
} else {
Expand Down Expand Up @@ -384,6 +385,7 @@ export class EditHandlerImpl implements EditHandler {
) {
this.autoborderHandler = autoborderHandler;
this.autobordersEnabled = false;
this.intelligentCutEnabled = false;
this.onEditDone = onEditDone;
this.canvas = canvas;
this.editData = null;
Expand Down Expand Up @@ -423,6 +425,10 @@ export class EditHandlerImpl implements EditHandler {
}
}
}

if (typeof configuration.intelligentPolygonCrop === 'boolean') {
this.intelligentCutEnabled = configuration.intelligentPolygonCrop;
}
}

public transform(geometry: Geometry): void {
Expand Down
2 changes: 1 addition & 1 deletion 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.16.1",
"version": "1.17.0",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {
Expand Down
12 changes: 11 additions & 1 deletion cvat-ui/src/actions/settings-actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020 Intel Corporation
// Copyright (C) 2020-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand Down Expand Up @@ -27,6 +27,7 @@ export enum SettingsActionTypes {
CHANGE_AUTO_SAVE_INTERVAL = 'CHANGE_AUTO_SAVE_INTERVAL',
CHANGE_AAM_ZOOM_MARGIN = 'CHANGE_AAM_ZOOM_MARGIN',
SWITCH_AUTOMATIC_BORDERING = 'SWITCH_AUTOMATIC_BORDERING',
SWITCH_INTELLIGENT_POLYGON_CROP = 'SWITCH_INTELLIGENT_POLYGON_CROP',
SWITCH_SHOWNIG_INTERPOLATED_TRACKS = 'SWITCH_SHOWNIG_INTERPOLATED_TRACKS',
SWITCH_SHOWING_OBJECTS_TEXT_ALWAYS = 'SWITCH_SHOWING_OBJECTS_TEXT_ALWAYS',
CHANGE_CANVAS_BACKGROUND_COLOR = 'CHANGE_CANVAS_BACKGROUND_COLOR',
Expand Down Expand Up @@ -241,6 +242,15 @@ export function switchAutomaticBordering(automaticBordering: boolean): AnyAction
};
}

export function switchIntelligentPolygonCrop(intelligentPolygonCrop: boolean): AnyAction {
return {
type: SettingsActionTypes.SWITCH_INTELLIGENT_POLYGON_CROP,
payload: {
intelligentPolygonCrop,
},
};
}

export function changeCanvasBackgroundColor(color: string): AnyAction {
return {
type: SettingsActionTypes.CHANGE_CANVAS_BACKGROUND_COLOR,
Expand Down
17 changes: 14 additions & 3 deletions cvat-ui/src/components/annotation-page/canvas/canvas-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
// SPDX-License-Identifier: MIT

import React from 'react';
import GlobalHotKeys, { KeyMap } from 'utils/mousetrap-react';
import Layout from 'antd/lib/layout';
import Slider from 'antd/lib/slider';
import Dropdown from 'antd/lib/dropdown';
import { PlusCircleOutlined, UpOutlined } from '@ant-design/icons';

import GlobalHotKeys, { KeyMap } from 'utils/mousetrap-react';
import {
ColorBy, GridColor, ObjectType, ContextMenuType, Workspace, ShapeType,
} from 'reducers/interfaces';
Expand Down Expand Up @@ -61,6 +61,7 @@ interface Props {
showAllInterpolationTracks: boolean;
workspace: Workspace;
automaticBordering: boolean;
intelligentPolygonCrop: boolean;
keyMap: KeyMap;
canvasBackgroundColor: string;
switchableAutomaticBordering: boolean;
Expand Down Expand Up @@ -98,7 +99,12 @@ interface Props {
export default class CanvasWrapperComponent extends React.PureComponent<Props> {
public componentDidMount(): void {
const {
automaticBordering, showObjectsTextAlways, canvasInstance, workspace,
automaticBordering,
intelligentPolygonCrop,
showObjectsTextAlways,
canvasInstance,
workspace,
showProjections,
} = this.props;

// It's awful approach from the point of view React
Expand All @@ -111,6 +117,8 @@ export default class CanvasWrapperComponent extends React.PureComponent<Props> {
undefinedAttrValue: consts.UNDEFINED_ATTRIBUTE_VALUE,
displayAllText: showObjectsTextAlways,
forceDisableEditing: workspace === Workspace.REVIEW_WORKSPACE,
intelligentPolygonCrop,
showProjections,
});

this.initialSetup();
Expand Down Expand Up @@ -147,6 +155,7 @@ export default class CanvasWrapperComponent extends React.PureComponent<Props> {
showObjectsTextAlways,
showAllInterpolationTracks,
automaticBordering,
intelligentPolygonCrop,
showProjections,
canvasBackgroundColor,
onFetchAnnotation,
Expand All @@ -155,13 +164,15 @@ export default class CanvasWrapperComponent extends React.PureComponent<Props> {
if (
prevProps.showObjectsTextAlways !== showObjectsTextAlways ||
prevProps.automaticBordering !== automaticBordering ||
prevProps.showProjections !== showProjections
prevProps.showProjections !== showProjections ||
prevProps.intelligentPolygonCrop !== intelligentPolygonCrop
) {
canvasInstance.configure({
undefinedAttrValue: consts.UNDEFINED_ATTRIBUTE_VALUE,
displayAllText: showObjectsTextAlways,
autoborders: automaticBordering,
showProjections,
intelligentPolygonCrop,
});
}

Expand Down
1 change: 1 addition & 0 deletions cvat-ui/src/components/header/settings-modal/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

.cvat-workspace-settings-auto-save,
.cvat-workspace-settings-autoborders,
.cvat-workspace-settings-intelligent-polygon-cropping,
.cvat-workspace-settings-show-text-always,
.cvat-workspace-settings-show-interpolated {
margin-bottom: 25px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020 Intel Corporation
// Copyright (C) 2020-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -18,12 +18,14 @@ interface Props {
showAllInterpolationTracks: boolean;
showObjectsTextAlways: boolean;
automaticBordering: boolean;
intelligentPolygonCrop: boolean;
onSwitchAutoSave(enabled: boolean): void;
onChangeAutoSaveInterval(interval: number): void;
onChangeAAMZoomMargin(margin: number): void;
onSwitchShowingInterpolatedTracks(enabled: boolean): void;
onSwitchShowingObjectsTextAlways(enabled: boolean): void;
onSwitchAutomaticBordering(enabled: boolean): void;
onSwitchIntelligentPolygonCrop(enabled: boolean): void;
}

export default function WorkspaceSettingsComponent(props: Props): JSX.Element {
Expand All @@ -34,12 +36,14 @@ export default function WorkspaceSettingsComponent(props: Props): JSX.Element {
showAllInterpolationTracks,
showObjectsTextAlways,
automaticBordering,
intelligentPolygonCrop,
onSwitchAutoSave,
onChangeAutoSaveInterval,
onChangeAAMZoomMargin,
onSwitchShowingInterpolatedTracks,
onSwitchShowingObjectsTextAlways,
onSwitchAutomaticBordering,
onSwitchIntelligentPolygonCrop,
} = props;

const minAutoSaveInterval = 1;
Expand Down Expand Up @@ -111,9 +115,7 @@ export default function WorkspaceSettingsComponent(props: Props): JSX.Element {
</Col>
<Col span={24}>
<Text type='secondary'>
{' '}
Show text for an object on the canvas not only when the object is activated
{' '}
</Text>
</Col>
</Row>
Expand All @@ -131,12 +133,26 @@ export default function WorkspaceSettingsComponent(props: Props): JSX.Element {
</Col>
<Col span={24}>
<Text type='secondary'>
{' '}
Enable automatic bordering for polygons and polylines during drawing/editing
{' '}
</Text>
</Col>
</Row>
<Row className='cvat-workspace-settings-intelligent-polygon-cropping'>
<Col span={24}>
<Checkbox
className='cvat-text-color'
checked={intelligentPolygonCrop}
onChange={(event: CheckboxChangeEvent): void => {
onSwitchIntelligentPolygonCrop(event.target.checked);
}}
>
Intelligent polygon cropping
</Checkbox>
</Col>
<Col span={24}>
<Text type='secondary'>Try to crop polygons automatically when editing</Text>
</Col>
</Row>
<Row className='cvat-workspace-settings-aam-zoom-margin'>
<Col>
<Text className='cvat-text-color'> Attribute annotation mode (AAM) zoom margin </Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//
// SPDX-License-Identifier: MIT

import { KeyMap } from 'utils/mousetrap-react';
import { connect } from 'react-redux';

import { KeyMap } from 'utils/mousetrap-react';
import CanvasWrapperComponent from 'components/annotation-page/canvas/canvas-wrapper';
import {
confirmCanvasReady,
Expand Down Expand Up @@ -159,7 +159,11 @@ function mapStateToProps(state: CombinedState): StateToProps {
resetZoom,
},
workspace: {
aamZoomMargin, showObjectsTextAlways, showAllInterpolationTracks, automaticBordering,
aamZoomMargin,
showObjectsTextAlways,
showAllInterpolationTracks,
automaticBordering,
intelligentPolygonCrop,
},
shapes: {
opacity, colorBy, selectedOpacity, outlined, outlineColor, showBitmap, showProjections,
Expand Down Expand Up @@ -207,6 +211,7 @@ function mapStateToProps(state: CombinedState): StateToProps {
minZLayer,
maxZLayer,
automaticBordering,
intelligentPolygonCrop,
workspace,
keyMap,
canvasBackgroundColor,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2020 Intel Corporation
// Copyright (C) 2020-2021 Intel Corporation
//
// SPDX-License-Identifier: MIT

Expand All @@ -12,6 +12,7 @@ import {
switchShowingInterpolatedTracks,
switchShowingObjectsTextAlways,
switchAutomaticBordering,
switchIntelligentPolygonCrop,
} from 'actions/settings-actions';

import { CombinedState } from 'reducers/interfaces';
Expand All @@ -25,6 +26,7 @@ interface StateToProps {
showAllInterpolationTracks: boolean;
showObjectsTextAlways: boolean;
automaticBordering: boolean;
intelligentPolygonCrop: boolean;
}

interface DispatchToProps {
Expand All @@ -34,6 +36,7 @@ interface DispatchToProps {
onSwitchShowingInterpolatedTracks(enabled: boolean): void;
onSwitchShowingObjectsTextAlways(enabled: boolean): void;
onSwitchAutomaticBordering(enabled: boolean): void;
onSwitchIntelligentPolygonCrop(enabled: boolean): void;
}

function mapStateToProps(state: CombinedState): StateToProps {
Expand All @@ -45,6 +48,7 @@ function mapStateToProps(state: CombinedState): StateToProps {
showAllInterpolationTracks,
showObjectsTextAlways,
automaticBordering,
intelligentPolygonCrop,
} = workspace;

return {
Expand All @@ -54,6 +58,7 @@ function mapStateToProps(state: CombinedState): StateToProps {
showAllInterpolationTracks,
showObjectsTextAlways,
automaticBordering,
intelligentPolygonCrop,
};
}

Expand All @@ -77,6 +82,9 @@ function mapDispatchToProps(dispatch: any): DispatchToProps {
onSwitchAutomaticBordering(enabled: boolean): void {
dispatch(switchAutomaticBordering(enabled));
},
onSwitchIntelligentPolygonCrop(enabled: boolean): void {
dispatch(switchIntelligentPolygonCrop(enabled));
},
};
}

Expand Down
Loading

0 comments on commit 1f56fd2

Please sign in to comment.