Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute annotation mode encapsulation #216

Merged
merged 1 commit into from
Dec 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 58 additions & 23 deletions cvat/apps/engine/static/engine/js/attributeAnnotationMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,11 @@ class AAMModel extends Listener {
if (this._activeAAM && this._active) {
let label = this._active.label;
let attrId = +this._attrIdByIdx(label, this._attrNumberByLabel[label].current);
let attrInfo = window.cvat.labelsInfo.attrInfo(attrId);

let [xtl, ytl, xbr, ybr] = this._bbRect(this._currentShapes[this._activeIdx].interpolation.position);
this._focus(xtl - this._margin, xbr + this._margin, ytl - this._margin, ybr + this._margin);

this._active.activeAAM = {
shape: true,
attribute: attrId,
};

this.notify();

if (attrInfo.type === 'text' || attrInfo.type === 'number') {
this._active.aamAttributeFocus();
}
this._active.activeAttribute = attrId;
}
else {
this.notify();
Expand All @@ -140,10 +130,7 @@ class AAMModel extends Listener {

_deactivate() {
if (this._activeAAM && this._active) {
this._active.activeAAM = {
shape: false,
attribute: null
};
this._active.activeAttribute = null;
}
}

Expand All @@ -153,7 +140,6 @@ class AAMModel extends Listener {
this._shapeCollection.resetActive();
this._activeAAM = true;
this._updateCollection();
this.notify();
this._activate();
}
}
Expand Down Expand Up @@ -238,26 +224,22 @@ class AAMModel extends Listener {
if (!this._activeAAM || !this._active) {
return;
}

let label = this._active.label;
let frame = window.cvat.player.frames.current;
let attrId = this._attrIdByIdx(label, this._attrNumberByLabel[label].current);
let attrInfo = window.cvat.labelsInfo.attrInfo(attrId);

if (key >= attrInfo.values.length) {
if (attrInfo.type === 'checkbox' && key < 2) {
this._active.updateAttribute(frame, attrId, !attrInfo.values[0]);
}
return;
}

if (attrInfo.values[0] === AAMUndefinedKeyword) {
if (key >= attrInfo.values.length - 1) {
return;
}
key ++;
}

this._active.updateAttribute(frame, attrId, attrInfo.values[key]);
}

Expand All @@ -284,6 +266,10 @@ class AAMModel extends Listener {
return this._activeAAM;
}

get active() {
return this._active;
}

set margin(value) {
this._margin = value;
}
Expand Down Expand Up @@ -333,7 +319,6 @@ class AAMController {
else {
return;
}

this._model.setupAttributeValue(key);
}.bind(this));

Expand Down Expand Up @@ -361,6 +346,7 @@ class AAMView {
this._aamCounter = $('#aamCounter');
this._aamHelpContainer = $('#aamHelpContainer');
this._zoomMargin = $('#aamZoomMargin');
this._frameContent = SVG.adopt($('#frameContent')[0]);
this._controller = aamController;

this._zoomMargin.on('change', (e) => {
Expand All @@ -370,7 +356,58 @@ class AAMView {
aamModel.subscribe(this);
}

_setupAAMView(active, type, pos) {
let oldRect = $('#outsideRect');
let oldMask = $('#outsideMask');

if (active) {
if (oldRect.length) {
oldRect.remove();
oldMask.remove();
}

let size = window.cvat.translate.box.actualToCanvas({
x: 0,
y: 0,
width: window.cvat.player.geometry.frameWidth,
height: window.cvat.player.geometry.frameHeight
});

let excludeField = this._frameContent.rect(size.width, size.height).move(size.x, size.y).fill('#666');
let includeField = null;

if (type === 'box') {
pos = window.cvat.translate.box.actualToCanvas(pos);
includeField = this._frameContent.rect(pos.xbr - pos.xtl, pos.ybr - pos.ytl).move(pos.xtl, pos.ytl);
}
else {
pos.points = window.cvat.translate.points.actualToCanvas(pos.points);
includeField = this._frameContent.polygon(pos.points);
}

this._frameContent.mask().add(excludeField).add(includeField).fill('black').attr('id', 'outsideMask');
this._frameContent.rect(size.width, size.height).move(size.x, size.y).attr({
mask: 'url(#outsideMask)',
id: 'outsideRect'
});

let content = $(this._frameContent.node);
let texts = content.find('.shapeText');
for (let text of texts) {
content.append(text);
}
}
else {
oldRect.remove();
oldMask.remove();
}
}

onAAMUpdate(aam) {
this._setupAAMView(aam.active ? true : false,
aam.active ? aam.active.type.split('_')[1] : '',
aam.active ? aam.active.interpolate(window.cvat.player.frames.current).position : 0);

if (aam.activeAAM) {
if (this._aamMenu.hasClass('hidden')) {
this._trackManagement.addClass('hidden');
Expand All @@ -392,7 +429,5 @@ class AAMView {
this._trackManagement.removeClass('hidden');
}
}
// blur on change text attribute to other or on exit from aam
blurAllElements();
}
}
41 changes: 19 additions & 22 deletions cvat/apps/engine/static/engine/js/shapeCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class ShapeCollectionModel extends Listener {
this._groupIdx = 0;
this._frame = null;
this._activeShape = null;
this._activeAAMShape = null;
this._lastPos = {
x: 0,
y: 0,
Expand Down Expand Up @@ -95,14 +94,10 @@ class ShapeCollectionModel extends Listener {
this._z_order.min = 0;

if (this._activeShape) {
this._activeShape.active = false;
}

if (this._activeAAMShape) {
this._activeAAMShape.activeAAM = {
shape: false,
attribute: null
};
if (this._activeShape.activeAttribute != null) {
this._activeShape.activeAttribute = null;
}
this.resetActive();
}

this._currentShapes = [];
Expand Down Expand Up @@ -498,16 +493,14 @@ class ShapeCollectionModel extends Listener {

// If frame was not changed and collection already interpolated (for example after pause() call)
if (frame === this._frame && this._currentShapes.length) return;

if (this._activeShape) {
this._activeShape.active = false;
this._activeShape = null;
}
if (this._activeAAMShape) {
this._activeAAMShape.activeAAM = {
shape: false,
attribute: null,
};
if (this._activeShape.activeAttribute != null) {
this._activeShape.activeAttribute = null;
}
this.resetActive();
}

this._frame = frame;
this._interpolate();
if (!window.cvat.mode) {
Expand All @@ -522,12 +515,15 @@ class ShapeCollectionModel extends Listener {

onShapeUpdate(model) {
switch (model.updateReason) {
case 'activeAAM':
if (model.activeAAM.shape) {
this._activeAAMShape = model;
case 'activeAttribute':
if (model.activeAttribute != null) {
if (this._activeShape && this._activeShape != model) {
this.resetActive();
}
this._activeShape = model;
}
else if (this._activeAAMShape === model) {
this._activeAAMShape = null;
else if (this._activeShape) {
this.resetActive();
}
break;
case 'activation': {
Expand Down Expand Up @@ -1583,4 +1579,5 @@ class ShapeCollectionView {
}
}
}

}
Loading