Skip to content

Commit

Permalink
Merged develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev committed Feb 27, 2020
2 parents f29f272 + d6e7216 commit 2ea117d
Show file tree
Hide file tree
Showing 23 changed files with 792 additions and 195 deletions.
4 changes: 3 additions & 1 deletion cvat-core/src/annotations-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
groups: this.groups,
frameMeta: this.frameMeta,
history: this.history,
groupColors: {},
};
}

Expand All @@ -139,7 +140,8 @@

for (const tag of data.tags) {
const clientID = ++this.count;
const tagModel = new Tag(tag, clientID, this.injection);
const color = colors[clientID % colors.length];
const tagModel = new Tag(tag, clientID, color, this.injection);
this.tags[tagModel.frame] = this.tags[tagModel.frame] || [];
this.tags[tagModel.frame].push(tagModel);
this.objects[clientID] = tagModel;
Expand Down
155 changes: 84 additions & 71 deletions cvat-core/src/annotations-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require:false
*/


(() => {
const ObjectState = require('./object-state');
const {
Expand Down Expand Up @@ -136,21 +137,42 @@
}

class Annotation {
constructor(data, clientID, injection) {
constructor(data, clientID, color, injection) {
this.taskLabels = injection.labels;
this.history = injection.history;
this.groupColors = injection.groupColors;
this.clientID = clientID;
this.serverID = data.id;
this.group = data.group;
this.label = this.taskLabels[data.label_id];
this.frame = data.frame;
this.removed = false;
this.lock = false;
this.color = color;
this.updated = Date.now();
this.attributes = data.attributes.reduce((attributeAccumulator, attr) => {
attributeAccumulator[attr.spec_id] = attr.value;
return attributeAccumulator;
}, {});
this.groupObject = Object.defineProperties({}, {
color: {
get: () => {
if (this.group) {
return this.groupColors[this.group]
|| colors[this.group % colors.length];
}
return defaultGroupColor;
},
set: (newColor) => {
if (this.group && typeof (newColor) === 'string' && /^#[0-9A-F]{6}$/i.test(newColor)) {
this.groupColors[this.group] = newColor;
}
},
},
id: {
get: () => this.group,
},
});
this.appendDefaultAttributes(this.label);

injection.groups.max = Math.max(injection.groups.max, this.group);
Expand Down Expand Up @@ -229,65 +251,6 @@
}, [this.clientID]);
}

appendDefaultAttributes(label) {
const labelAttributes = label.attributes;
for (const attribute of labelAttributes) {
if (!(attribute.id in this.attributes)) {
this.attributes[attribute.id] = attribute.defaultValue;
}
}
}

updateTimestamp(updated) {
const anyChanges = updated.label || updated.attributes || updated.points
|| updated.outside || updated.occluded || updated.keyframe
|| updated.zOrder;

if (anyChanges) {
this.updated = Date.now();
}
}

delete(force) {
if (!this.lock || force) {
this.removed = true;

this.history.do(HistoryActions.REMOVED_OBJECT, () => {
this.removed = false;
}, () => {
this.removed = true;
}, [this.clientID]);
}

return this.removed;
}
}

class Drawn extends Annotation {
constructor(data, clientID, color, injection) {
super(data, clientID, injection);

this.frameMeta = injection.frameMeta;
this.hidden = false;
this.pinned = true;

this.color = color;
this.shapeType = null;
}

_savePinned(pinned) {
const undoPinned = this.pinned;
const redoPinned = pinned;

this.history.do(HistoryActions.CHANGED_PINNED, () => {
this.pinned = undoPinned;
}, () => {
this.pinned = redoPinned;
}, [this.clientID]);

this.pinned = pinned;
}

_validateStateBeforeSave(frame, data, updated) {
let fittedPoints = [];

Expand Down Expand Up @@ -381,6 +344,62 @@
return fittedPoints;
}

appendDefaultAttributes(label) {
const labelAttributes = label.attributes;
for (const attribute of labelAttributes) {
if (!(attribute.id in this.attributes)) {
this.attributes[attribute.id] = attribute.defaultValue;
}
}
}

updateTimestamp(updated) {
const anyChanges = updated.label || updated.attributes || updated.points
|| updated.outside || updated.occluded || updated.keyframe
|| updated.zOrder;

if (anyChanges) {
this.updated = Date.now();
}
}

delete(force) {
if (!this.lock || force) {
this.removed = true;

this.history.do(HistoryActions.REMOVED_OBJECT, () => {
this.removed = false;
}, () => {
this.removed = true;
}, [this.clientID]);
}

return this.removed;
}
}

class Drawn extends Annotation {
constructor(data, clientID, color, injection) {
super(data, clientID, color, injection);
this.frameMeta = injection.frameMeta;
this.hidden = false;
this.pinned = true;
this.shapeType = null;
}

_savePinned(pinned) {
const undoPinned = this.pinned;
const redoPinned = pinned;

this.history.do(HistoryActions.CHANGED_PINNED, () => {
this.pinned = undoPinned;
}, () => {
this.pinned = redoPinned;
}, [this.clientID]);

this.pinned = pinned;
}

save() {
throw new ScriptingError(
'Is not implemented',
Expand Down Expand Up @@ -450,10 +469,7 @@
points: [...this.points],
attributes: { ...this.attributes },
label: this.label,
group: {
color: this.group ? colors[this.group % colors.length] : defaultGroupColor,
id: this.group,
},
group: this.groupObject,
color: this.color,
hidden: this.hidden,
updated: this.updated,
Expand Down Expand Up @@ -641,10 +657,7 @@
return {
...this.getPosition(frame, prev, next),
attributes: this.getAttributes(frame),
group: {
color: this.group ? colors[this.group % colors.length] : defaultGroupColor,
id: this.group,
},
group: this.groupObject,
objectType: ObjectType.TRACK,
shapeType: this.shapeType,
clientID: this.clientID,
Expand Down Expand Up @@ -1081,8 +1094,8 @@
}

class Tag extends Annotation {
constructor(data, clientID, injection) {
super(data, clientID, injection);
constructor(data, clientID, color, injection) {
super(data, clientID, color, injection);
}

// Method is used to export data to the server
Expand Down Expand Up @@ -1119,7 +1132,7 @@
lock: this.lock,
attributes: { ...this.attributes },
label: this.label,
group: this.group,
group: this.groupObject,
updated: this.updated,
frame,
};
Expand Down
16 changes: 8 additions & 8 deletions cvat-core/src/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@
return result;
},

async hasUnsavedChanges() {
const result = await PluginRegistry
.apiWrapper.call(this, prototype.annotations.hasUnsavedChanges);
return result;
},

async merge(objectStates) {
const result = await PluginRegistry
.apiWrapper.call(this, prototype.annotations.merge, objectStates);
Expand All @@ -107,6 +101,12 @@
.apiWrapper.call(this, prototype.annotations.exportDataset, format);
return result;
},

hasUnsavedChanges() {
const result = prototype.annotations
.hasUnsavedChanges.implementation.call(this);
return result;
},
},
writable: true,
}),
Expand Down Expand Up @@ -381,14 +381,14 @@
* @async
*/
/**
* Indicate if there are any changes in
* Method indicates if there are any changes in
* annotations which haven't been saved on a server
* </br><b> This function cannot be wrapped with a plugin </b>
* @method hasUnsavedChanges
* @memberof Session.annotations
* @returns {boolean}
* @throws {module:API.cvat.exceptions.PluginError}
* @instance
* @async
*/
/**
* Export as a dataset.
Expand Down
Loading

0 comments on commit 2ea117d

Please sign in to comment.