Skip to content

Commit

Permalink
Merge branch 'bs/fixed_deleted_frames' into bs/fixed_tracks_1
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev authored Jan 20, 2025
2 parents 9820164 + e95b59e commit 853ea46
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
16 changes: 7 additions & 9 deletions cvat-core/src/annotations-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export default class Collection {
dimension: DimensionType;
framesInfo: BasicInjection['framesInfo'];
jobType: JobType;
isFrameDeleted: (frame: number) => boolean;
}) {
this.stopFrame = data.stopFrame;

Expand Down Expand Up @@ -101,7 +100,6 @@ export default class Collection {
jobType: data.jobType,
groupColors: {},
nextClientID: () => ++config.globalObjectsCounter,
isFrameDeleted: data.isFrameDeleted,
getMasksOnFrame: (frame: number) => (this.shapes[frame] as MaskShape[])
.filter((object) => object instanceof MaskShape),
};
Expand Down Expand Up @@ -236,7 +234,7 @@ export default class Collection {
}

public get(frame: number, allTracks: boolean, filters: object[]): ObjectState[] {
if (this.injection.isFrameDeleted(frame)) {
if (this.injection.framesInfo.isFrameDeleted(frame)) {
return [];
}

Expand Down Expand Up @@ -929,7 +927,7 @@ export default class Collection {
count -= 1;
}
for (let i = start + 1; lastIsKeyframe ? i < stop : i <= stop; i++) {
if (this.injection.isFrameDeleted(i)) {
if (this.injection.framesInfo.isFrameDeleted(i)) {
count--;
}
}
Expand All @@ -942,7 +940,7 @@ export default class Collection {
const keyframes = Object.keys(track.shapes)
.sort((a, b) => +a - +b)
.map((el) => +el)
.filter((frame) => !this.injection.isFrameDeleted(frame));
.filter((frame) => !this.injection.framesInfo.isFrameDeleted(frame));

let prevKeyframe = keyframes[0];
let visible = false;
Expand Down Expand Up @@ -999,7 +997,7 @@ export default class Collection {
labels[label].total++;
} else if (objectType === 'track') {
scanTrack(object);
} else if (!this.injection.isFrameDeleted(object.frame)) {
} else if (!this.injection.framesInfo.isFrameDeleted(object.frame)) {
const { shapeType } = object as Shape;
labels[label][shapeType].shape++;
labels[label].manually++;
Expand Down Expand Up @@ -1298,7 +1296,7 @@ export default class Collection {
const predicate = sign > 0 ? (frame) => frame <= frameTo : (frame) => frame >= frameTo;
const update = sign > 0 ? (frame) => frame + 1 : (frame) => frame - 1;
for (let frame = frameFrom; predicate(frame); frame = update(frame)) {
if (!allowDeletedFrames && this.injection.isFrameDeleted(frame)) {
if (!allowDeletedFrames && this.injection.framesInfo.isFrameDeleted(frame)) {
continue;
}

Expand Down Expand Up @@ -1365,7 +1363,7 @@ export default class Collection {
if (!annotationsFilters) {
let frame = frameFrom;
while (predicate(frame)) {
if (!allowDeletedFrames && this.injection.isFrameDeleted(frame)) {
if (!allowDeletedFrames && this.injection.framesInfo.isFrameDeleted(frame)) {
frame = update(frame);
continue;
}
Expand All @@ -1380,7 +1378,7 @@ export default class Collection {
const linearSearch = filtersStr.match(/"var":"width"/) || filtersStr.match(/"var":"height"/);

for (let frame = frameFrom; predicate(frame); frame = update(frame)) {
if (!allowDeletedFrames && this.injection.isFrameDeleted(frame)) {
if (!allowDeletedFrames && this.injection.framesInfo.isFrameDeleted(frame)) {
continue;
}

Expand Down
15 changes: 10 additions & 5 deletions cvat-core/src/annotations-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ function computeNewSource(currentSource: Source): Source {
return Source.MANUAL;
}

type FrameInfo = {
width: number;
height: number;
};

export interface BasicInjection {
labels: Record<number, Label>;
groups: { max: number };
framesInfo: Readonly<Record<number, Readonly<{ width: number; height: number; }>>>
framesInfo: Readonly<{
[index: number]: Readonly<FrameInfo>;
isFrameDeleted: (frame: number) => boolean;
}>;
history: AnnotationHistory;
groupColors: Record<number, string>;
parentID?: number;
Expand All @@ -70,7 +78,6 @@ export interface BasicInjection {
jobType: JobType;
nextClientID: () => number;
getMasksOnFrame: (frame: number) => MaskShape[];
isFrameDeleted: (frame: number) => boolean;
}

type AnnotationInjection = BasicInjection & {
Expand Down Expand Up @@ -395,7 +402,6 @@ class Annotation {
}

class Drawn extends Annotation {
protected isFrameDeleted: (frame: number) => boolean;
protected framesInfo: AnnotationInjection['framesInfo'];
protected descriptions: string[];
public hidden: boolean;
Expand All @@ -404,7 +410,6 @@ class Drawn extends Annotation {

constructor(data, clientID: number, color: string, injection: AnnotationInjection) {
super(data, clientID, color, injection);
this.isFrameDeleted = injection.isFrameDeleted;
this.framesInfo = injection.framesInfo;
this.descriptions = data.descriptions || [];
this.hidden = false;
Expand Down Expand Up @@ -957,7 +962,7 @@ export class Track extends Drawn {
let last = Number.MIN_SAFE_INTEGER;

for (const frame of frames) {
if (this.isFrameDeleted(frame)) {
if (this.framesInfo.isFrameDeleted(frame)) {
continue;
}

Expand Down
24 changes: 13 additions & 11 deletions cvat-core/src/annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,19 @@ async function getAnnotationsFromServer(session: Job | Task): Promise<void> {
stopFrame: session instanceof Job ? session.stopFrame : session.size - 1,
labels: session.labels,
dimension: session.dimension,
isFrameDeleted: session instanceof Job ?
(frame: number) => !!getJobFramesMetaSync(session.id).deletedFrames[frame] :
(frame: number) => !!frameMeta.deletedFrames[frame],
framesInfo: frameMeta.frames.reduce((acc, frameInfo, idx) => {
// keep only static information
acc[frameNumbers[idx]] = {
width: frameInfo.width,
height: frameInfo.height,
};
return acc;
}, {}),
framesInfo: {
isFrameDeleted: session instanceof Job ?
(frame: number) => !!getJobFramesMetaSync(session.id).deletedFrames[frame] :
(frame: number) => !!frameMeta.deletedFrames[frame],
...frameMeta.frames.reduce((acc, frameInfo, idx) => {
// keep only static information
acc[frameNumbers[idx]] = {
width: frameInfo.width,
height: frameInfo.height,
};
return acc;
}, {}),
},
history,
});

Expand Down

0 comments on commit 853ea46

Please sign in to comment.