Skip to content

Commit

Permalink
Added fixes from PR cvat-ai#1370 of opencv/cvat
Browse files Browse the repository at this point in the history
  • Loading branch information
meyg8600 committed Apr 24, 2020
1 parent 0c91e76 commit 1ef9631
Show file tree
Hide file tree
Showing 13 changed files with 296 additions and 238 deletions.
4 changes: 4 additions & 0 deletions cvat-canvas/src/typescript/canvasModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ export class CanvasModelImpl extends MasterImpl implements CanvasModel {
}

public setup(frameData: any, objectStates: any[]): void {
if ([Mode.EDIT, Mode.DRAG, Mode.RESIZE].includes(this.data.mode)) {
throw Error(`Canvas is busy. Action: ${this.data.mode}`);
}

if (frameData.number === this.data.imageID) {
this.data.objects = objectStates;
this.notify(UpdateReasons.OBJECTS_UPDATED);
Expand Down
8 changes: 5 additions & 3 deletions cvat-canvas/src/typescript/canvasView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
const shape = this.svgShapes[this.activeElement.clientID];

if (trackStart === 0) {
console.log('not tracking');
trackStart = 0
} else if (trackStart === 1) {
// startX = e.clientX
// startY = e.clientY
Expand Down Expand Up @@ -1202,7 +1202,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
(this.svgShapes[clientID] as any).clear();
this.svgShapes[clientID].attr('points', stringified);

if (state.shapeType === 'points') {
if (state.shapeType === 'points' && !state.hidden) {
this.selectize(false, this.svgShapes[clientID]);
this.setupPoints(this.svgShapes[clientID] as SVG.PolyLine, state);
}
Expand Down Expand Up @@ -1350,7 +1350,7 @@ export class CanvasViewImpl implements CanvasView, Listener {
(shape as any).off('resizestart');
(shape as any).off('resizing');
(shape as any).off('resizedone');
(shape as any).resize(false);
(shape as any).resize('stop');

// TODO: Hide text only if it is hidden by settings
const text = this.svgTexts[clientID];
Expand Down Expand Up @@ -1730,6 +1730,8 @@ export class CanvasViewImpl implements CanvasView, Listener {
group.on('click.canvas', (event: MouseEvent): void => {
// Need to redispatch the event on another element
basicPolyline.fire(new MouseEvent('click', event));
// redispatch event to canvas to be able merge points clicking them
this.content.dispatchEvent(new MouseEvent('click', event));
});

group.bbox = basicPolyline.bbox.bind(basicPolyline);
Expand Down
74 changes: 38 additions & 36 deletions cvat-core/src/annotations-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@

let shapeModel = null;
switch (type) {
case 'rectangle':
shapeModel = new RectangleShape(shapeData, clientID, color, injection);
break;
case 'polygon':
shapeModel = new PolygonShape(shapeData, clientID, color, injection);
break;
case 'polyline':
shapeModel = new PolylineShape(shapeData, clientID, color, injection);
break;
case 'points':
shapeModel = new PointsShape(shapeData, clientID, color, injection);
break;
default:
throw new DataError(
`An unexpected type of shape "${type}"`,
);
case 'rectangle':
shapeModel = new RectangleShape(shapeData, clientID, color, injection);
break;
case 'polygon':
shapeModel = new PolygonShape(shapeData, clientID, color, injection);
break;
case 'polyline':
shapeModel = new PolylineShape(shapeData, clientID, color, injection);
break;
case 'points':
shapeModel = new PointsShape(shapeData, clientID, color, injection);
break;
default:
throw new DataError(
`An unexpected type of shape "${type}"`,
);
}

return shapeModel;
Expand All @@ -75,22 +75,22 @@

let trackModel = null;
switch (type) {
case 'rectangle':
trackModel = new RectangleTrack(trackData, clientID, color, injection);
break;
case 'polygon':
trackModel = new PolygonTrack(trackData, clientID, color, injection);
break;
case 'polyline':
trackModel = new PolylineTrack(trackData, clientID, color, injection);
break;
case 'points':
trackModel = new PointsTrack(trackData, clientID, color, injection);
break;
default:
throw new DataError(
`An unexpected type of track "${type}"`,
);
case 'rectangle':
trackModel = new RectangleTrack(trackData, clientID, color, injection);
break;
case 'polygon':
trackModel = new PolygonTrack(trackData, clientID, color, injection);
break;
case 'polyline':
trackModel = new PolylineTrack(trackData, clientID, color, injection);
break;
case 'points':
trackModel = new PointsTrack(trackData, clientID, color, injection);
break;
default:
throw new DataError(
`An unexpected type of track "${type}"`,
);
}

return trackModel;
Expand Down Expand Up @@ -373,7 +373,7 @@
} else {
throw new ArgumentError(
`Trying to merge unknown object type: ${object.constructor.name}. `
+ 'Only shapes and tracks are expected.',
+ 'Only shapes and tracks are expected.',
);
}
}
Expand Down Expand Up @@ -737,7 +737,7 @@
if (!Object.values(ObjectShape).includes(state.shapeType)) {
throw new ArgumentError(
'Object shape must be one of: '
+ `${JSON.stringify(Object.values(ObjectShape))}`,
+ `${JSON.stringify(Object.values(ObjectShape))}`,
);
}

Expand Down Expand Up @@ -773,7 +773,7 @@
} else {
throw new ArgumentError(
'Object type must be one of: '
+ `${JSON.stringify(Object.values(ObjectType))}`,
+ `${JSON.stringify(Object.values(ObjectType))}`,
);
}
}
Expand Down Expand Up @@ -871,16 +871,18 @@
// In particular consider first and last frame as keyframes for all frames
const statesData = [].concat(
(frame in this.shapes ? this.shapes[frame] : [])
.filter((shape) => !shape.removed)
.map((shape) => shape.get(frame)),
(frame in this.tags ? this.tags[frame] : [])
.filter((tag) => !tag.removed)
.map((tag) => tag.get(frame)),
);
const tracks = Object.values(this.tracks)
.filter((track) => (
frame in track.shapes
|| frame === frameFrom
|| frame === frameTo
));
)).filter((track) => !track.removed);
statesData.push(
...tracks.map((track) => track.get(frame))
.filter((state) => !state.outside),
Expand Down
22 changes: 16 additions & 6 deletions cvat-ui/src/components/annotation-page/annotation-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ export default function AnnotationPageComponent(props: Props): JSX.Element {

useEffect(() => {
saveLogs();
return saveLogs;
const root = window.document.getElementById('root');
if (root) {
root.style.minHeight = '768px';
}

return () => {
saveLogs();
if (root) {
root.style.minHeight = '';
}
};
}, []);

if (job === null) {
Expand All @@ -63,15 +73,15 @@ export default function AnnotationPageComponent(props: Props): JSX.Element {
<Layout.Header className='cvat-annotation-header'>
<AnnotationTopBarContainer />
</Layout.Header>
{ workspace === Workspace.STANDARD ? (
{workspace === Workspace.STANDARD ? (
<Layout.Content>
<StandardWorkspaceComponent />
</Layout.Content>
) : (
<Layout.Content>
<AttributeAnnotationWorkspace />
</Layout.Content>
)}
<Layout.Content>
<AttributeAnnotationWorkspace />
</Layout.Content>
)}
<StatisticsModalContainer />
</Layout>
);
Expand Down
2 changes: 1 addition & 1 deletion cvat-ui/src/components/create-task-page/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}

.cvat-create-task-content {
margin-top: 20px;
padding-top: 20px;
width: 100%;
height: auto;
border: 1px solid $border-color-1;
Expand Down
6 changes: 3 additions & 3 deletions cvat-ui/src/components/tasks-page/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
height: 100%;

> div:nth-child(1) {
margin-bottom: 10px;
padding-bottom: 10px;

div > {
span {
Expand All @@ -36,11 +36,11 @@

> div:nth-child(3) {
height: 83%;
margin-top: 10px;
padding-top: 10px;
}

> div:nth-child(4) {
margin-top: 10px;
padding-top: 10px;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import copy from 'copy-to-clipboard';
import { connect } from 'react-redux';

import { LogType } from 'cvat-logger';
import { Canvas, isAbleToChangeFrame } from 'cvat-canvas';
import { ActiveControl, CombinedState, ColorBy } from 'reducers/interfaces';
import {
collapseObjectItems,
Expand All @@ -24,7 +25,6 @@ import {

import ObjectStateItemComponent from 'components/annotation-page/standard-workspace/objects-side-bar/object-item';


interface OwnProps {
clientID: number;
}
Expand All @@ -44,6 +44,7 @@ interface StateToProps {
minZLayer: number;
maxZLayer: number;
normalizedKeyMap: Record<string, string>;
canvasInstance: Canvas;
}

interface DispatchToProps {
Expand Down Expand Up @@ -84,6 +85,7 @@ function mapStateToProps(state: CombinedState, own: OwnProps): StateToProps {
canvas: {
ready,
activeControl,
instance: canvasInstance,
},
colors,
},
Expand Down Expand Up @@ -119,6 +121,7 @@ function mapStateToProps(state: CombinedState, own: OwnProps): StateToProps {
minZLayer,
maxZLayer,
normalizedKeyMap,
canvasInstance,
};
}

Expand Down Expand Up @@ -166,71 +169,47 @@ function mapDispatchToProps(dispatch: any): DispatchToProps {
type Props = StateToProps & DispatchToProps;
class ObjectItemContainer extends React.PureComponent<Props> {
private navigateFirstKeyframe = (): void => {
const {
objectState,
changeFrame,
frameNumber,
} = this.props;
const { objectState, frameNumber } = this.props;

const { first } = objectState.keyframes;
if (first !== frameNumber) {
changeFrame(first);
this.changeFrame(first);
}
};

private navigatePrevKeyframe = (): void => {
const {
objectState,
changeFrame,
frameNumber,
} = this.props;
const { objectState, frameNumber } = this.props;

const { prev } = objectState.keyframes;
if (prev !== null && prev !== frameNumber) {
changeFrame(prev);
this.changeFrame(prev);
}
};

private navigateNextKeyframe = (): void => {
const {
objectState,
changeFrame,
frameNumber,
} = this.props;

const { objectState, frameNumber } = this.props;
const { next } = objectState.keyframes;
if (next !== null && next !== frameNumber) {
changeFrame(next);
this.changeFrame(next);
}
};

private navigateLastKeyframe = (): void => {
const {
objectState,
changeFrame,
frameNumber,
} = this.props;

const { objectState, frameNumber } = this.props;
const { last } = objectState.keyframes;
if (last !== frameNumber) {
changeFrame(last);
this.changeFrame(last);
}
};

private copy = (): void => {
const {
objectState,
copyShape,
} = this.props;
const { objectState, copyShape } = this.props;

copyShape(objectState);
};

private propagate = (): void => {
const {
objectState,
propagateObject,
} = this.props;
const { objectState, propagateObject } = this.props;

propagateObject(objectState);
};
Expand Down Expand Up @@ -422,14 +401,21 @@ class ObjectItemContainer extends React.PureComponent<Props> {
this.commit();
};

private changeFrame(frame: number): void {
const { changeFrame, canvasInstance } = this.props;
if (isAbleToChangeFrame(canvasInstance)) {
changeFrame(frame);
}
}

// EDITED FOR INTEGRATION
private autoSnap = (): void => {
const {
objectState,
jobInstance,
frameNumber,
} = this.props;

let result = jobInstance.annotations.snap(objectState.serverID, frameNumber, objectState.points);
result.then((data: any) => {
objectState.points = data.points;
Expand Down Expand Up @@ -544,7 +530,7 @@ class ObjectItemContainer extends React.PureComponent<Props> {
collapse={this.collapse}
// EDITED FOR INTEGRATION
autoSnap={this.autoSnap}
// EDITED END
// EDITED END
/>
);
}
Expand Down
Loading

0 comments on commit 1ef9631

Please sign in to comment.