Implemented propagate backward (#5355)

<!-- Raised an issue to propose your change
(https://github.com/cvat-ai/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the
[CONTRIBUTION](https://github.com/cvat-ai/cvat/blob/develop/CONTRIBUTING.md)
guide. -->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
Resolved #2998

<img width="428" alt="image"
src="https://user-images.githubusercontent.com/40690378/203806586-1367477b-cfff-46f1-947b-d0292cd6f02e.png">


### How has this been tested?
<!-- Please describe in detail how you tested your changes.
Include details of your testing environment, and the tests you ran to
see how your change affects other areas of the code, etc. -->

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable by a reason then ~~explicitly
strikethrough~~ the whole
line. If you don't do that github will show an incorrect process for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- [x] I have added a description of my changes into
[CHANGELOG](https://github.com/cvat-ai/cvat/blob/develop/CHANGELOG.md)
file
- [ ] I have updated the [documentation](
https://github.com/cvat-ai/cvat/blob/develop/README.md#documentation)
accordingly
- [x] I have added tests to cover my changes
- [x] I have linked related issues ([read github docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [x] I have increased versions of npm packages if it is necessary
([cvat-canvas](https://github.com/cvat-ai/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/cvat-ai/cvat/tree/develop/cvat-core#versioning),
[cvat-data](https://github.com/cvat-ai/cvat/tree/develop/cvat-data#versioning)
and
[cvat-ui](https://github.com/cvat-ai/cvat/tree/develop/cvat-ui#versioning))

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/cvat-ai/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.
main
Boris Sekachev 3 years ago committed by GitHub
parent 2ecd8c7b0c
commit 460df331e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,6 +20,7 @@ from online detectors & interactors) (<https://github.com/opencv/cvat/pull/4543>
- Added Webhooks (<https://github.com/opencv/cvat/pull/4863>)
- Authentication with social accounts google & github (<https://github.com/opencv/cvat/pull/5147>, <https://github.com/opencv/cvat/pull/5181>, <https://github.com/opencv/cvat/pull/5295>)
- REST API tests to export job datasets & annotations and validate their structure (<https://github.com/opencv/cvat/pull/5160>)
- Propagation backward on UI (<https://github.com/opencv/cvat/pull/5355>)
### Changed
- `api/docs`, `api/swagger`, `api/schema`, `server/about` endpoints now allow unauthorized access (<https://github.com/opencv/cvat/pull/4928>, <https://github.com/opencv/cvat/pull/4935>)

@ -1,6 +1,6 @@
{
"name": "cvat-ui",
"version": "1.44.1",
"version": "1.44.2",
"description": "CVAT single-page application",
"main": "src/index.tsx",
"scripts": {

@ -160,10 +160,9 @@ export enum AnnotationActionTypes {
REMOVE_OBJECT = 'REMOVE_OBJECT',
REMOVE_OBJECT_SUCCESS = 'REMOVE_OBJECT_SUCCESS',
REMOVE_OBJECT_FAILED = 'REMOVE_OBJECT_FAILED',
PROPAGATE_OBJECT = 'PROPAGATE_OBJECT',
PROPAGATE_OBJECT_SUCCESS = 'PROPAGATE_OBJECT_SUCCESS',
PROPAGATE_OBJECT_FAILED = 'PROPAGATE_OBJECT_FAILED',
CHANGE_PROPAGATE_FRAMES = 'CHANGE_PROPAGATE_FRAMES',
SWITCH_PROPAGATE_VISIBILITY = 'SWITCH_PROPAGATE_VISIBILITY',
SWITCH_SHOWING_STATISTICS = 'SWITCH_SHOWING_STATISTICS',
SWITCH_SHOWING_FILTERS = 'SWITCH_SHOWING_FILTERS',
COLLECT_STATISTICS = 'COLLECT_STATISTICS',
@ -404,9 +403,32 @@ export function showFilters(visible: boolean): AnyAction {
};
}
export function propagateObjectAsync(sessionInstance: any, objectState: any, from: number, to: number): ThunkAction {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
export function switchPropagateVisibility(visible: boolean): AnyAction {
return {
type: AnnotationActionTypes.SWITCH_PROPAGATE_VISIBILITY,
payload: { visible },
};
}
export function propagateObjectAsync(from: number, to: number): ThunkAction {
return async (dispatch: ActionCreator<Dispatch>, getState): Promise<void> => {
const state = getState();
const {
job: {
instance: sessionInstance,
},
annotations: {
activatedStateID,
states: objectStates,
},
} = state.annotation;
try {
const objectState = objectStates.find((_state: any) => _state.clientID === activatedStateID);
if (!objectState) {
throw new Error('There is not an activated object state to be propagated');
}
const getCopyFromState = (_objectState: any): any => ({
attributes: _objectState.attributes,
points: _objectState.shapeType === 'skeleton' ? null : _objectState.points,
@ -423,9 +445,10 @@ export function propagateObjectAsync(sessionInstance: any, objectState: any, fro
});
const copy = getCopyFromState(objectState);
await sessionInstance.logger.log(LogType.propagateObject, { count: to - from + 1 });
await sessionInstance.logger.log(LogType.propagateObject, { count: Math.abs(to - from) });
const states = [];
for (let frame = from; frame <= to; frame++) {
const sign = Math.sign(to - from);
for (let frame = from + sign; sign > 0 ? frame <= to : frame >= to; frame += sign) {
copy.frame = frame;
copy.elements.forEach((element: any) => { element.frame = frame; });
const newState = new cvat.classes.ObjectState(copy);
@ -437,40 +460,17 @@ export function propagateObjectAsync(sessionInstance: any, objectState: any, fro
dispatch({
type: AnnotationActionTypes.PROPAGATE_OBJECT_SUCCESS,
payload: {
objectState,
history,
},
payload: { history },
});
} catch (error) {
dispatch({
type: AnnotationActionTypes.PROPAGATE_OBJECT_FAILED,
payload: {
error,
},
payload: { error },
});
}
};
}
export function propagateObject(objectState: any | null): AnyAction {
return {
type: AnnotationActionTypes.PROPAGATE_OBJECT,
payload: {
objectState,
},
};
}
export function changePropagateFrames(frames: number): AnyAction {
return {
type: AnnotationActionTypes.CHANGE_PROPAGATE_FRAMES,
payload: {
frames,
},
};
}
export function removeObjectAsync(sessionInstance: any, objectState: any, force: boolean): ThunkAction {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
try {
@ -661,6 +661,13 @@ export function getPredictionsAsync(): ThunkAction {
};
}
export function confirmCanvasReady(): AnyAction {
return {
type: AnnotationActionTypes.CONFIRM_CANVAS_READY,
payload: {},
};
}
export function changeFrameAsync(
toFrame: number,
fillBuffer?: boolean,
@ -670,6 +677,14 @@ export function changeFrameAsync(
return async (dispatch: ActionCreator<Dispatch>, getState: () => CombinedState): Promise<void> => {
const state: CombinedState = getState();
const { instance: job } = state.annotation.job;
const {
propagate: {
visible: propagateVisible,
},
statistics: {
visible: statisticsVisible,
},
} = state.annotation;
const { filters, frame, showAllInterpolationTracks } = receiveAnnotationsParameters();
try {
@ -677,9 +692,9 @@ export function changeFrameAsync(
throw Error(`Required frame ${toFrame} is out of the current job`);
}
const abortAction = (): AnyAction => {
const abortAction = (): void => {
const currentState = getState();
return ({
dispatch({
type: AnnotationActionTypes.CHANGE_FRAME_SUCCESS,
payload: {
number: currentState.annotation.player.frame.number,
@ -694,6 +709,8 @@ export function changeFrameAsync(
curZ: currentState.annotation.annotations.zLayer.cur,
},
});
dispatch(confirmCanvasReady());
};
dispatch({
@ -702,17 +719,17 @@ export function changeFrameAsync(
});
if (toFrame === frame && !forceUpdate) {
dispatch(abortAction());
abortAction();
return;
}
const data = await job.frames.get(toFrame, fillBuffer, frameStep);
const states = await job.annotations.get(toFrame, showAllInterpolationTracks, filters);
if (!isAbleToChangeFrame()) {
if (!isAbleToChangeFrame() || statisticsVisible || propagateVisible) {
// while doing async actions above, canvas can become used by a user in another way
// so, we need an additional check and if it is used, we do not update state
dispatch(abortAction());
abortAction();
return;
}
@ -933,13 +950,6 @@ export function resetCanvas(): AnyAction {
};
}
export function confirmCanvasReady(): AnyAction {
return {
type: AnnotationActionTypes.CONFIRM_CANVAS_READY,
payload: {},
};
}
export function closeJob(): ThunkAction {
return async (dispatch: ActionCreator<Dispatch>): Promise<void> => {
const { jobInstance } = receiveAnnotationsParameters();

@ -1,82 +1,155 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT
import React from 'react';
import React, { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import Modal from 'antd/lib/modal';
import InputNumber from 'antd/lib/input-number';
import Text from 'antd/lib/typography/Text';
import Radio, { RadioChangeEvent } from 'antd/lib/radio';
import { Row, Col } from 'antd/lib/grid';
import Slider from 'antd/lib/slider';
import { clamp } from 'utils/math';
import { ArrowLeftOutlined, ArrowRightOutlined } from '@ant-design/icons';
import { propagateObjectAsync, switchPropagateVisibility } from 'actions/annotation-actions';
import { CombinedState } from 'reducers';
interface Props {
visible: boolean;
propagateFrames: number;
propagateUpToFrame: number;
stopFrame: number;
frameNumber: number;
propagateObject(): void;
cancel(): void;
changePropagateFrames(value: number): void;
changeUpToFrame(value: number): void;
export enum PropagateDirection {
FORWARD = 'forward',
BACKWARD = 'backward',
}
export default function PropagateConfirmComponent(props: Props): JSX.Element {
const {
visible,
propagateFrames,
propagateUpToFrame,
stopFrame,
frameNumber,
propagateObject,
changePropagateFrames,
changeUpToFrame,
cancel,
} = props;
function PropagateConfirmComponent(): JSX.Element {
const dispatch = useDispatch();
const visible = useSelector((state: CombinedState) => state.annotation.propagate.visible);
const frameNumber = useSelector((state: CombinedState) => state.annotation.player.frame.number);
const startFrame = useSelector((state: CombinedState) => state.annotation.job.instance.startFrame);
const stopFrame = useSelector((state: CombinedState) => state.annotation.job.instance.stopFrame);
const [targetFrame, setTargetFrame] = useState<number>(frameNumber);
const propagateFrames = Math.abs(targetFrame - frameNumber);
const propagateDirection = targetFrame >= frameNumber ? PropagateDirection.FORWARD : PropagateDirection.BACKWARD;
const minPropagateFrames = 1;
useEffect(() => {
const propagateForwardAvailable = stopFrame - frameNumber >= 1;
const propagateBackwardAvailable = frameNumber - startFrame >= 1;
if (propagateForwardAvailable) {
setTargetFrame(stopFrame);
} else if (propagateBackwardAvailable) {
setTargetFrame(startFrame);
}
}, [visible]);
const updateTargetFrame = (direction: PropagateDirection, _propagateFrames: number): void => {
if (direction === PropagateDirection.FORWARD) {
setTargetFrame(clamp(frameNumber + _propagateFrames, startFrame, stopFrame));
} else {
setTargetFrame(clamp(frameNumber - _propagateFrames, startFrame, stopFrame));
}
};
return (
<Modal
okType='primary'
okText='Yes'
cancelText='Cancel'
onOk={propagateObject}
onCancel={cancel}
onOk={() => {
dispatch(propagateObjectAsync(frameNumber, targetFrame))
.then(() => dispatch(switchPropagateVisibility(false)));
}}
onCancel={() => dispatch(switchPropagateVisibility(false))}
title='Confirm propagation'
visible={visible}
destroyOnClose
okButtonProps={{ disabled: !propagateFrames }}
>
<div className='cvat-propagate-confirm'>
<Text>Do you want to make a copy of the object on</Text>
<InputNumber
className='cvat-propagate-confirm-object-on-frames'
size='small'
min={minPropagateFrames}
value={propagateFrames}
onChange={(value: number | undefined | string) => {
if (typeof value !== 'undefined') {
changePropagateFrames(
Math.floor(clamp(+value, minPropagateFrames, Number.MAX_SAFE_INTEGER)),
);
}
}}
/>
{propagateFrames > 1 ? <Text> frames </Text> : <Text> frame </Text>}
<Text>up to the </Text>
<InputNumber
className='cvat-propagate-confirm-object-up-to-frame'
size='small'
value={propagateUpToFrame}
min={frameNumber + 1}
max={stopFrame}
onChange={(value: number | undefined | string) => {
if (typeof value !== 'undefined') {
changeUpToFrame(Math.floor(clamp(+value, frameNumber + 1, stopFrame)));
}
}}
/>
<Text>frame</Text>
<Row>
<Col>
<Text>Please, specify a direction</Text>
</Col>
<Col offset={1}>
<Radio.Group
size='small'
value={propagateDirection}
onChange={(e: RadioChangeEvent) => updateTargetFrame(e.target.value, propagateFrames)}
>
<Radio.Button disabled={frameNumber === startFrame} value={PropagateDirection.BACKWARD}>
<ArrowLeftOutlined />
</Radio.Button>
<Radio.Button disabled={frameNumber === stopFrame} value={PropagateDirection.FORWARD}>
<ArrowRightOutlined />
</Radio.Button>
</Radio.Group>
</Col>
</Row>
<Row>
<Col>How many copies do you want to create?</Col>
<Col offset={1}>
<InputNumber
className='cvat-propagate-confirm-object-on-frames'
size='small'
min={0}
value={propagateFrames}
onChange={(value: number) => {
if (typeof value !== 'undefined') {
updateTargetFrame(propagateDirection, +value);
}
}}
/>
</Col>
</Row>
<hr />
<Row className='cvat-propagate-up-to-wrapper'>
<Col span={24}>
<Text>Or specify a range where copies will be created </Text>
</Col>
<Col className='cvat-propagate-slider-wrapper' span={12} offset={1}>
<Slider
range
min={startFrame}
max={stopFrame}
marks={frameNumber !== targetFrame ? {
[frameNumber]: 'FROM',
[targetFrame]: 'TO',
} : undefined}
onChange={([value1, value2]: [number, number]) => {
const value = value1 === frameNumber || value1 === targetFrame ? value2 : value1;
if (value < frameNumber) {
setTargetFrame(clamp(value, startFrame, frameNumber));
} else {
setTargetFrame(clamp(value, frameNumber, stopFrame));
}
}}
value={[frameNumber, targetFrame] as [number, number]}
/>
</Col>
<Col span={4}>
<InputNumber
size='small'
className='cvat-propagate-confirm-up-to-input'
min={startFrame}
max={stopFrame}
value={targetFrame}
onChange={(value: number) => {
if (typeof value !== 'undefined') {
if (value > frameNumber) {
setTargetFrame(clamp(+value, frameNumber, stopFrame));
} else if (value < frameNumber) {
setTargetFrame(clamp(+value, startFrame, frameNumber));
} else {
setTargetFrame(frameNumber);
}
}
}}
/>
</Col>
</Row>
</div>
</Modal>
);
}
export default React.memo(PropagateConfirmComponent);

@ -1,4 +1,5 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporations
//
// SPDX-License-Identifier: MIT
@ -8,13 +9,13 @@ import Layout from 'antd/lib/layout';
import CanvasWrapperContainer from 'containers/annotation-page/canvas/canvas-wrapper';
import ControlsSideBarContainer from 'containers/annotation-page/standard-workspace/controls-side-bar/controls-side-bar';
import PropagateConfirmContainer from 'containers/annotation-page/standard-workspace/propagate-confirm';
import CanvasContextMenuContainer from 'containers/annotation-page/canvas/canvas-context-menu';
import ObjectsListContainer from 'containers/annotation-page/standard-workspace/objects-side-bar/objects-list';
import ObjectSideBarComponent from 'components/annotation-page/standard-workspace/objects-side-bar/objects-side-bar';
import CanvasPointContextMenuComponent from 'components/annotation-page/canvas/canvas-point-context-menu';
import IssueAggregatorComponent from 'components/annotation-page/review/issues-aggregator';
import RemoveConfirmComponent from 'components/annotation-page/standard-workspace/remove-confirm';
import PropagateConfirmComponent from 'components/annotation-page/standard-workspace/propagate-confirm';
export default function StandardWorkspaceComponent(): JSX.Element {
return (
@ -22,7 +23,7 @@ export default function StandardWorkspaceComponent(): JSX.Element {
<ControlsSideBarContainer />
<CanvasWrapperContainer />
<ObjectSideBarComponent objectsList={<ObjectsListContainer />} />
<PropagateConfirmContainer />
<PropagateConfirmComponent />
<CanvasContextMenuContainer />
<CanvasPointContextMenuComponent />
<IssueAggregatorComponent />

@ -1,4 +1,5 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT
@ -333,9 +334,23 @@
}
.cvat-propagate-confirm {
> .ant-input-number {
width: 70px;
margin: 0 5px;
> .ant-row {
align-items: flex-start;
margin-bottom: $grid-unit-size * 2;
}
.ant-input-number {
margin-left: $grid-unit-size;
margin-right: $grid-unit-size;
width: $grid-unit-size * 7;
}
.cvat-propagate-slider-wrapper {
height: $grid-unit-size;
}
.cvat-propagate-up-to-wrapper > div:first-child {
margin-bottom: $grid-unit-size;
}
}

@ -10,10 +10,10 @@ import CanvasWrapperContainer from 'containers/annotation-page/canvas/canvas-wra
import ControlsSideBarContainer from 'containers/annotation-page/standard3D-workspace/controls-side-bar/controls-side-bar';
import ObjectSideBarComponent from 'components/annotation-page/standard-workspace/objects-side-bar/objects-side-bar';
import ObjectsListContainer from 'containers/annotation-page/standard-workspace/objects-side-bar/objects-list';
import PropagateConfirmContainer from 'containers/annotation-page/standard-workspace/propagate-confirm';
import CanvasContextMenuContainer from 'containers/annotation-page/canvas/canvas-context-menu';
import CanvasPointContextMenuComponent from 'components/annotation-page/canvas/canvas-point-context-menu';
import RemoveConfirmComponent from 'components/annotation-page/standard-workspace/remove-confirm';
import PropagateConfirmComponent from 'components/annotation-page/standard-workspace/propagate-confirm';
export default function StandardWorkspace3DComponent(): JSX.Element {
return (
@ -21,7 +21,7 @@ export default function StandardWorkspace3DComponent(): JSX.Element {
<ControlsSideBarContainer />
<CanvasWrapperContainer />
<ObjectSideBarComponent objectsList={<ObjectsListContainer />} />
<PropagateConfirmContainer />
<PropagateConfirmComponent />
<CanvasContextMenuContainer />
<CanvasPointContextMenuComponent />
<RemoveConfirmComponent />

@ -14,7 +14,7 @@ import {
pasteShapeAsync,
copyShape as copyShapeAction,
activateObject as activateObjectAction,
propagateObject as propagateObjectAction,
switchPropagateVisibility as switchPropagateVisibilityAction,
removeObject as removeObjectAction,
} from 'actions/annotation-actions';
import {
@ -56,7 +56,7 @@ interface DispatchToProps {
activateObject: (activatedStateID: number | null, activatedElementID: number | null) => void;
removeObject: (objectState: any) => void;
copyShape: (objectState: any) => void;
propagateObject: (objectState: any) => void;
switchPropagateVisibility: (visible: boolean) => void;
changeGroupColor(group: number, color: string): void;
}
@ -118,8 +118,8 @@ function mapDispatchToProps(dispatch: any): DispatchToProps {
dispatch(copyShapeAction(objectState));
dispatch(pasteShapeAsync());
},
propagateObject(objectState: any): void {
dispatch(propagateObjectAction(objectState));
switchPropagateVisibility(visible: boolean): void {
dispatch(switchPropagateVisibilityAction(visible));
},
changeGroupColor(group: number, color: string): void {
dispatch(changeGroupColorAsync(group, color));
@ -137,9 +137,9 @@ class ObjectItemContainer extends React.PureComponent<Props> {
};
private propagate = (): void => {
const { objectState, readonly, propagateObject } = this.props;
const { switchPropagateVisibility, readonly } = this.props;
if (!readonly) {
propagateObject(objectState);
switchPropagateVisibility(true);
}
};

@ -16,7 +16,7 @@ import {
collapseObjectItems,
changeGroupColorAsync,
copyShape as copyShapeAction,
propagateObject as propagateObjectAction,
switchPropagateVisibility as switchPropagateVisibilityAction,
removeObject as removeObjectAction,
} from 'actions/annotation-actions';
import isAbleToChangeFrame from 'utils/is-able-to-change-frame';
@ -53,7 +53,7 @@ interface DispatchToProps {
collapseStates(states: any[], value: boolean): void;
removeObject: (objectState: any, force: boolean) => void;
copyShape: (objectState: any) => void;
propagateObject: (objectState: any) => void;
switchPropagateVisibility: (visible: boolean) => void;
changeFrame(frame: number): void;
changeGroupColor(group: number, color: string): void;
}
@ -135,8 +135,8 @@ function mapDispatchToProps(dispatch: any): DispatchToProps {
copyShape(objectState: ObjectState): void {
dispatch(copyShapeAction(objectState));
},
propagateObject(objectState: ObjectState): void {
dispatch(propagateObjectAction(objectState));
switchPropagateVisibility(visible: boolean): void {
dispatch(switchPropagateVisibilityAction(visible));
},
changeFrame(frame: number): void {
dispatch(changeFrameAsync(frame));
@ -280,7 +280,7 @@ class ObjectsListContainer extends React.PureComponent<Props, State> {
changeGroupColor,
removeObject,
copyShape,
propagateObject,
switchPropagateVisibility,
changeFrame,
} = this.props;
const { objectStates, sortedStatesID, statesOrdering } = this.state;
@ -448,7 +448,7 @@ class ObjectsListContainer extends React.PureComponent<Props, State> {
preventDefault(event);
const state = activatedState();
if (state && !readonly) {
propagateObject(state);
switchPropagateVisibility(true);
}
},
NEXT_KEY_FRAME: (event: KeyboardEvent | undefined) => {

@ -1,114 +0,0 @@
// Copyright (C) 2020-2022 Intel Corporation
//
// SPDX-License-Identifier: MIT
import React from 'react';
import { connect } from 'react-redux';
import {
propagateObject as propagateObjectAction,
changePropagateFrames as changePropagateFramesAction,
propagateObjectAsync,
} from 'actions/annotation-actions';
import { CombinedState } from 'reducers';
import PropagateConfirmComponent from 'components/annotation-page/standard-workspace/propagate-confirm';
interface StateToProps {
objectState: any | null;
frameNumber: number;
stopFrame: number;
propagateFrames: number;
jobInstance: any;
}
interface DispatchToProps {
cancel(): void;
propagateObject(sessionInstance: any, objectState: any, from: number, to: number): void;
changePropagateFrames(frames: number): void;
}
function mapStateToProps(state: CombinedState): StateToProps {
const {
annotation: {
propagate: { objectState, frames: propagateFrames },
job: {
instance: { stopFrame },
instance: jobInstance,
},
player: {
frame: { number: frameNumber },
},
},
} = state;
return {
objectState,
frameNumber,
stopFrame,
propagateFrames,
jobInstance,
};
}
function mapDispatchToProps(dispatch: any): DispatchToProps {
return {
propagateObject(sessionInstance: any, objectState: any, from: number, to: number): void {
dispatch(propagateObjectAsync(sessionInstance, objectState, from, to));
},
changePropagateFrames(frames: number): void {
dispatch(changePropagateFramesAction(frames));
},
cancel(): void {
dispatch(propagateObjectAction(null));
},
};
}
type Props = StateToProps & DispatchToProps;
class PropagateConfirmContainer extends React.PureComponent<Props> {
private propagateObject = (): void => {
const {
propagateObject, objectState, propagateFrames, frameNumber, stopFrame, jobInstance,
} = this.props;
const propagateUpToFrame = Math.min(frameNumber + propagateFrames, stopFrame);
propagateObject(jobInstance, objectState, frameNumber + 1, propagateUpToFrame);
};
private changePropagateFrames = (value: number): void => {
const { changePropagateFrames } = this.props;
changePropagateFrames(value);
};
private changeUpToFrame = (value: number): void => {
const { stopFrame, frameNumber, changePropagateFrames } = this.props;
const propagateFrames = Math.max(0, Math.min(stopFrame, value)) - frameNumber;
changePropagateFrames(propagateFrames);
};
public render(): JSX.Element {
const {
frameNumber, stopFrame, propagateFrames, cancel, objectState,
} = this.props;
const propagateUpToFrame = Math.min(frameNumber + propagateFrames, stopFrame);
return (
<PropagateConfirmComponent
visible={objectState !== null}
propagateUpToFrame={propagateUpToFrame}
stopFrame={stopFrame}
frameNumber={frameNumber}
propagateFrames={propagateUpToFrame - frameNumber}
propagateObject={this.propagateObject}
changePropagateFrames={this.changePropagateFrames}
changeUpToFrame={this.changeUpToFrame}
cancel={cancel}
/>
);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(PropagateConfirmContainer);

@ -108,10 +108,6 @@ const defaultState: AnnotationState = {
cur: 0,
},
},
propagate: {
objectState: null,
frames: 50,
},
remove: {
objectState: null,
force: false,
@ -121,6 +117,9 @@ const defaultState: AnnotationState = {
collecting: false,
data: null,
},
propagate: {
visible: false,
},
colors: [],
sidebarCollapsed: false,
appearanceCollapsed: false,
@ -830,16 +829,6 @@ export default (state = defaultState, action: AnyAction): AnnotationState => {
},
};
}
case AnnotationActionTypes.PROPAGATE_OBJECT: {
const { objectState } = action.payload;
return {
...state,
propagate: {
...state.propagate,
objectState,
},
};
}
case AnnotationActionTypes.PROPAGATE_OBJECT_SUCCESS: {
const { history } = action.payload;
return {
@ -848,20 +837,14 @@ export default (state = defaultState, action: AnyAction): AnnotationState => {
...state.annotations,
history,
},
propagate: {
...state.propagate,
objectState: null,
},
};
}
case AnnotationActionTypes.CHANGE_PROPAGATE_FRAMES: {
const { frames } = action.payload;
case AnnotationActionTypes.SWITCH_PROPAGATE_VISIBILITY: {
const { visible } = action.payload;
return {
...state,
propagate: {
...state.propagate,
frames,
visible,
},
};
}

@ -720,10 +720,6 @@ export interface AnnotationState {
cur: number;
};
};
propagate: {
objectState: any | null;
frames: number;
};
remove: {
objectState: any;
force: boolean;
@ -733,6 +729,9 @@ export interface AnnotationState {
visible: boolean;
data: any;
};
propagate: {
visible: boolean;
};
colors: any[];
filtersPanelVisible: boolean;
sidebarCollapsed: boolean;

@ -1,4 +1,5 @@
// Copyright (C) 2021-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT
@ -17,8 +18,6 @@ context('Object propagate.', () => {
secondX: 350,
secondY: 450,
};
const propagateOnOneFrame = 1;
const propagateOnTwoFrames = 2;
function startPropagation() {
cy.get('#cvat-objects-sidebar-state-item-1').find('[aria-label="more"]').trigger('mouseover');
@ -27,61 +26,88 @@ context('Object propagate.', () => {
});
}
function setupUpToFrame(value) {
cy.get('.cvat-propagate-confirm-up-to-input')
.find('input')
.clear()
.type(value)
.blur()
.should('have.value', value);
}
function setupPropagateFrames(value) {
cy.get('.cvat-propagate-confirm-object-on-frames') // Change value in the "copy of the object on frame" field
.find('input')
.clear()
.type(value)
.blur()
.should('have.value', value);
}
before(() => {
cy.openTaskJob(taskName);
});
beforeEach(() => {
cy.removeAnnotations();
cy.goCheckFrameNumber(0);
cy.createCuboid(createCuboidShape2Points);
});
describe(`Testing case "${caseId}"`, () => {
it('On the 1st frame propagate object on 1 frame.', () => {
const FROM_FRAME = 0;
const PROPAGATE_FRAMES = 1;
startPropagation();
cy.get('.cvat-propagate-confirm-object-on-frames') // Change value in the "copy of the object on frame" field
.find('input')
.clear()
.should('have.value', 1);
cy.get('.cvat-propagate-confirm-object-up-to-frame') // Value of "up to the frame" field should be same
setupPropagateFrames(PROPAGATE_FRAMES);
cy.get('.cvat-propagate-confirm-up-to-input') // Value of "up to the frame" field should be same
.find('input')
.should('have.attr', 'value', propagateOnOneFrame);
.should('have.attr', 'value', FROM_FRAME + PROPAGATE_FRAMES);
cy.contains('button', 'Yes').click();
});
it('On the 1st and 2nd frames, the number of objects is equal to 1. On the 3rd frame is 0.', () => {
cy.get('.cvat_canvas_shape_cuboid').then(($cuboidCountFirstFrame) => {
cy.goCheckFrameNumber(1); // Go to 2nd frame
cy.get('.cvat_canvas_shape_cuboid').then(($cuboidCountSecondFrame) => {
expect($cuboidCountFirstFrame.length).to.be.equal($cuboidCountSecondFrame.length);
});
});
cy.goCheckFrameNumber(2); // Go to 3rd frame
for (let i = FROM_FRAME; i <= FROM_FRAME + PROPAGATE_FRAMES; i++) {
cy.goCheckFrameNumber(i);
cy.get('.cvat_canvas_shape_cuboid').should('have.length', 1);
}
cy.goCheckFrameNumber(FROM_FRAME + PROPAGATE_FRAMES + 1);
cy.get('.cvat_canvas_shape_cuboid').should('not.exist');
cy.get('.cvat-player-first-button').click();
});
it('From the 1st frame propagate again on 2 frames.', () => {
const FROM_FRAME = 0;
const PROPAGATE_FRAMES = 2;
startPropagation();
cy.get('.cvat-propagate-confirm-object-up-to-frame') // Change value in the "up to the frame" field
.find('input')
.clear()
.type(propagateOnTwoFrames)
.should('have.attr', 'value', propagateOnTwoFrames);
setupUpToFrame(FROM_FRAME + PROPAGATE_FRAMES);
cy.get('.cvat-propagate-confirm-object-on-frames') // Value of "copy of the object on frames" field should be same
.find('input')
.should('have.attr', 'value', propagateOnTwoFrames);
.should('have.attr', 'value', FROM_FRAME + PROPAGATE_FRAMES);
cy.contains('button', 'Yes').click();
for (let i = FROM_FRAME; i <= FROM_FRAME + PROPAGATE_FRAMES; i++) {
cy.goCheckFrameNumber(i);
cy.get('.cvat_canvas_shape_cuboid').should('have.length', 1);
}
cy.goCheckFrameNumber(FROM_FRAME + PROPAGATE_FRAMES + 1);
cy.get('.cvat_canvas_shape_cuboid').should('not.exist');
});
it('On the 1st and 3rd frames the number of objects is equal to 1. On the 2nd frame equal to 2. On the 4th frame equal to 0', () => {
cy.get('.cvat_canvas_shape_cuboid').then(($cuboidCountFirstFrame) => {
cy.goCheckFrameNumber(2); // Go to 3rd frame
cy.get('.cvat_canvas_shape_cuboid').then(($cuboidCountThirdFrame) => {
expect($cuboidCountFirstFrame.length).to.be.equal($cuboidCountThirdFrame.length);
});
});
cy.goCheckFrameNumber(1); // Go to 2nd frame
cy.get('.cvat_canvas_shape_cuboid').then(($cuboidCountSecondFrame) => {
expect($cuboidCountSecondFrame.length).to.be.equal(2);
});
cy.goCheckFrameNumber(3); // Go to 4th frame
it('Testing propagate backward', () => {
cy.removeAnnotations();
const FROM_FRAME = 4;
const UP_TO_FRAME = 1;
cy.goCheckFrameNumber(FROM_FRAME);
cy.createCuboid(createCuboidShape2Points);
startPropagation();
setupUpToFrame(UP_TO_FRAME);
cy.contains('button', 'Yes').click();
for (let i = FROM_FRAME - 1; i >= UP_TO_FRAME; i--) {
cy.goCheckFrameNumber(i);
cy.get('.cvat_canvas_shape_cuboid').should('have.length', 1);
}
cy.goCheckFrameNumber(UP_TO_FRAME - 1);
cy.get('.cvat_canvas_shape_cuboid').should('not.exist');
});
});

@ -14,11 +14,11 @@ context('Rotate all images feature.', () => {
}
function imageRotate(direction = 'anticlockwise', deg) {
cy.get('.cvat-rotate-canvas-control').trigger('mouseover');
cy.get('.cvat-rotate-canvas-control').trigger('mouseover').should('be.visible');
if (direction === 'clockwise') {
cy.get('.cvat-rotate-canvas-controls-right').click();
cy.get('.cvat-rotate-canvas-controls-right').should('be.visible').click();
} else {
cy.get('.cvat-rotate-canvas-controls-left').click();
cy.get('.cvat-rotate-canvas-controls-left').should('be.visible').click();
}
checkDegRotate(deg);
}

@ -1,4 +1,5 @@
// Copyright (C) 2020-2022 Intel Corporation
// Copyright (C) 2022 CVAT.ai Corporation
//
// SPDX-License-Identifier: MIT
@ -11,7 +12,7 @@ context('Check propagation work from the latest frame', () => {
const createRectangleShape2Points = {
points: 'By 2 Points',
type: 'Shape',
labelName: labelName,
labelName,
firstX: 250,
firstY: 350,
secondX: 350,
@ -35,7 +36,9 @@ context('Check propagation work from the latest frame', () => {
it('Try to propagate', () => {
cy.get('#cvat_canvas_shape_1').trigger('mousemove');
cy.get('body').type('{ctrl}b');
cy.get('.ant-modal-content').find('.ant-btn-primary').click();
cy.get('.cvat-propagate-confirm-up-to-input').type(advancedConfigurationParams.segmentSize - 1);
cy.get('.ant-modal-content').find('.ant-btn-primary').should('be.disabled');
cy.get('.ant-modal-content').find('.ant-btn-default').click();
cy.get('.ant-notification-notice').should('not.exist');
});
});

@ -171,7 +171,7 @@ context('Manipulations with masks', { scrollBehavior: false }, () => {
cy.get('.cvat-object-item-menu').within(() => {
cy.contains('button', 'Propagate').click();
});
cy.get('.cvat-propagate-confirm-object-up-to-frame').find('input')
cy.get('.cvat-propagate-confirm-up-to-input').find('input')
.should('have.attr', 'value', serverFiles.length - 1);
cy.contains('button', 'Yes').click();
for (let i = 1; i < serverFiles.length; i++) {

@ -62,7 +62,9 @@ Cypress.Commands.add('activateOrganization', (organizationShortName) => {
.find('[role="menuitem"]')
.filter(':contains("Organization")')
.trigger('mouseover');
cy.contains('.cvat-header-menu-organization-item', organizationShortName).click();
cy.contains('.cvat-header-menu-organization-item', organizationShortName)
.should('be.visible')
.click();
cy.get('.cvat-header-menu-user-dropdown').should('be.visible');
cy.get('.cvat-header-menu-user-dropdown-organization')
.should('exist')

Loading…
Cancel
Save