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

[WIP] Feature request 78 #96

Closed
wants to merge 9 commits into from
Closed
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
121 changes: 58 additions & 63 deletions cvat/apps/engine/static/engine/js/attributeAnnotationMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,33 +116,18 @@ 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();
}
}
else {
this.notify();
this._active.activeAttribute = attrId;
}
this.notify();
}

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

Expand Down Expand Up @@ -232,33 +217,6 @@ class AAMModel extends Listener {
this._activate();
}

setupAttributeValue(key) {
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]);
}

onCollectionUpdate() {
if (this._activeAAM) {
// No need deactivate active view because all listeners already unsubscribed
Expand All @@ -282,6 +240,10 @@ class AAMModel extends Listener {
return this._activeAAM;
}

get active() {
return this._active;
}

set margin(value) {
this._margin = value;
}
Expand Down Expand Up @@ -320,28 +282,12 @@ class AAMController {
e.preventDefault();
}.bind(this));

let selectAttributeHandler = Logger.shortkeyLogDecorator(function(e) {
let key = e.keyCode;
if (key >= 48 && key <= 57) {
key -= 48; // 0 and 9
}
else if (key >= 96 && key <= 105) {
key -= 96; // num 0 and 9
}
else {
return;
}

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

let shortkeys = window.cvat.config.shortkeys;
Mousetrap.bind(shortkeys["switch_aam_mode"].value, switchAAMHandler, 'keydown');
Mousetrap.bind(shortkeys["aam_next_attribute"].value, nextAttributeHandler, 'keydown');
Mousetrap.bind(shortkeys["aam_prev_attribute"].value, prevAttributeHandler, 'keydown');
Mousetrap.bind(shortkeys["aam_next_shape"].value, nextShapeHandler, 'keydown');
Mousetrap.bind(shortkeys["aam_prev_shape"].value, prevShapeHandler, 'keydown');
Mousetrap.bind(shortkeys["select_i_attribute"].value, selectAttributeHandler, 'keydown');
}
}

Expand All @@ -359,6 +305,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 @@ -368,7 +315,57 @@ 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 = {
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') {
includeField = this._frameContent.rect(pos.xbr - pos.xtl, pos.ybr - pos.ytl).move(pos.xtl, pos.ytl);
}
else {
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 @@ -390,7 +387,5 @@ class AAMView {
this._trackManagement.removeClass('hidden');
}
}
// blur on change text attribute to other or on exit from aam
blurAllElements();
}
}
2 changes: 2 additions & 0 deletions cvat/apps/engine/static/engine/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ class PlayerController {
}

zoom(e) {
if (e.ctrlKey) return;

let x = e.originalEvent.pageX - this._leftOffset;
let y = e.originalEvent.pageY - this._topOffset;

Expand Down
138 changes: 116 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 @@ -97,14 +96,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 @@ -482,16 +477,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();
}
Expand All @@ -503,12 +496,24 @@ 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) {
if (this._activeShape.activeAttribute != null) {
this._activeShape.activeAttribute = null;
}
this.resetActive();
}
this._activeShape = model;
}
else if (this._activeAAMShape === model) {
this._activeAAMShape = null;
else if (this._activeShape) {
if (this._activeShape != model) {
throw Error('Unexpected behaviour. Variable _activeShape is obsolete');
}

if (this._activeShape.activeAttribute != null) {
this._activeShape.activeAttribute = null;
}
}
break;
case 'activation': {
Expand Down Expand Up @@ -927,7 +932,74 @@ class ShapeCollectionController {
}
}.bind(this));


let selectObjectHandler = function() {
let active = this._model.activeShape;
if (active) {
let label = active.label;
let attributes = window.cvat.labelsInfo.labelAttributes(label);
let firstKey = Object.keys(attributes)[0];
if (typeof(firstKey) != 'undefined' && this._model.activeShape) {
if (!window.cvat.mode) {
this._model.activeShape.activeAttribute = +firstKey;
}
}
}
}.bind(this);

let unselectObjectHandler = function() {
if (this._model.activeShape) {
if (!window.cvat.mode) {
this._model.activeShape.activeAttribute = null;
}
}
}.bind(this);

let selectAttributeHandler = Logger.shortkeyLogDecorator(function(e) {
let active = this._model.activeShape;
if (active && active.activeAttribute) {
let key = e.keyCode;
if (key >= 48 && key <= 57) {
key -= 48; // 0 and 9
}
else if (key >= 96 && key <= 105) {
key -= 96; // num 0 and 9
}
else {
return;
}

let attrId = active.activeAttribute;
let frame = window.cvat.player.frames.current;
let attrInfo = window.cvat.labelsInfo.attrInfo(attrId);

if (e.ctrlKey) {
key --;
if (key < 0) {
key = 10;
}
e.preventDefault();
}
else {
if (attrInfo.values[0] === AAMUndefinedKeyword) {
if (key >= attrInfo.values.length - 1) {
return;
}
key ++;
}
}

if (key >= attrInfo.values.length) {
if (attrInfo.type === 'checkbox' && key < 2) {
active.updateAttribute(frame, attrId, !attrInfo.values[0]);
}
return;
}
active.updateAttribute(frame, attrId, attrInfo.values[key]);
}
}.bind(this));
let shortkeys = window.cvat.config.shortkeys;

Mousetrap.bind(shortkeys["switch_lock_property"].value, switchLockHandler.bind(this), 'keydown');
Mousetrap.bind(shortkeys["switch_all_lock_property"].value, switchAllLockHandler.bind(this), 'keydown');
Mousetrap.bind(shortkeys["switch_occluded_property"].value, switchOccludedHandler.bind(this), 'keydown');
Expand All @@ -939,11 +1011,32 @@ class ShapeCollectionController {
Mousetrap.bind(shortkeys["change_shape_label"].value, switchLabelHandler.bind(this), 'keydown');
Mousetrap.bind(shortkeys["delete_shape"].value, removeActiveHandler.bind(this), 'keydown');
Mousetrap.bind(shortkeys["change_shape_color"].value, changeShapeColorHandler.bind(this), 'keydown');
Mousetrap.bind(shortkeys["select_object"].value, selectObjectHandler.bind(this), 'keydown');
Mousetrap.bind(shortkeys["select_object"].value, unselectObjectHandler.bind(this), 'keyup');
Mousetrap.bind(shortkeys["select_i_attribute"].value.concat(
shortkeys["select_i_attribute"].value.map((x) => `ctrl+${x}`)), selectAttributeHandler, 'keydown');

if (window.cvat.job.z_order) {
Mousetrap.bind(shortkeys["inc_z"].value, incZHandler.bind(this), 'keydown');
Mousetrap.bind(shortkeys["dec_z"].value, decZHandler.bind(this), 'keydown');
}

$('#frameContent').on('mousewheel', (e) => {
let active = this._model.activeShape;
if (active && active.activeAttribute) {
let label = active.label;
let attributes = Object.keys(window.cvat.labelsInfo.labelAttributes(label));
let idxInArr = attributes.indexOf(active.activeAttribute);

if (e.originalEvent.deltaY < 0) idxInArr--;
else idxInArr++;

if (idxInArr >= attributes.length) idxInArr = 0;
else if (idxInArr < 0) idxInArr = attributes.length - 1;
active.activeAttribute = attributes[idxInArr];
}
e.preventDefault();
});
}
}

Expand Down Expand Up @@ -1555,4 +1648,5 @@ class ShapeCollectionView {
}
}
}

}
Loading