From c49e320b2be60b45b5074d2db5d0c526fd1901b8 Mon Sep 17 00:00:00 2001 From: psmarsh Date: Tue, 6 Nov 2018 20:57:15 -0600 Subject: [PATCH 1/3] copy-pasting shapes copies label and category metadata --- js/store.js | 12 +++++++++++- tags/workarea.tag.html | 6 ++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/js/store.js b/js/store.js index 0a47103..296b2fc 100644 --- a/js/store.js +++ b/js/store.js @@ -157,12 +157,22 @@ function updateShapeDetailInStore(shapeId, bbox, points){ /** * Adds a shape into labelling data and returns a shape object */ -function attachShapeToImg(id, type, bbox, points){ +function attachShapeToImg(id, type, bbox, points, metadata){ var shape = scaleShape(id, type, bbox, points, 1 / imgSelected.size.imageScale); + if (metadata) { + shape.label = metadata.label; + shape.category = metadata.category; + } labellingData[ imgSelected.name ].shapes.push(shape); return shape; } +function getMetadata(shape) { + shape = getShape(shape.node.id); + return {'label': shape.label, + 'category': shape.category}; +} + function addImgToStore(imgname, size) { // If we already have this image data in localstorage, // don't initialize its properties diff --git a/tags/workarea.tag.html b/tags/workarea.tag.html index d395941..1be9998 100644 --- a/tags/workarea.tag.html +++ b/tags/workarea.tag.html @@ -71,6 +71,7 @@ */ copiedElements = []; selectedElements.forEach(shape => { + console.log(getMetadata(shape)); if (shape.hasClass('shape')) { var featurePoints = []; shape.siblings() @@ -86,7 +87,8 @@ 'type': shape.type, 'rbox': shape.rbox(myCanvas), 'points': getPoints(shape), - 'featurePoints': featurePoints + 'featurePoints': featurePoints, + 'metadata': getMetadata(shape) }); } }) @@ -104,7 +106,7 @@ copiedElements.forEach(shape => { // Add shape data and any points into labellingData var shapeId = shape.type + currentImgData.shapeIndex++; - var shapeData = attachShapeToImg(shapeId, shape.type, shape.rbox, shape.points); + var shapeData = attachShapeToImg(shapeId, shape.type, shape.rbox, shape.points, shape.metadata); shape.featurePoints.forEach(point => { var pointId = shapeId + point.type + currentImgData.pointIndex++; attachPointToShape(shapeId, pointId, point.rbox); From 57dd5f11a8553b38850af25bcf7059cf1e0a3c74 Mon Sep 17 00:00:00 2001 From: psmarsh Date: Fri, 9 Nov 2018 22:24:13 -0600 Subject: [PATCH 2/3] copy-paste copies tags, attributes, and feature point labels --- js/store.js | 19 ++++++++++++++----- tags/workarea.tag.html | 6 +++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/js/store.js b/js/store.js index 296b2fc..79e02e1 100644 --- a/js/store.js +++ b/js/store.js @@ -30,13 +30,14 @@ function getShape(shapeId){ return findInArray(labellingData[ imgSelected.name ].shapes, "id", shapeId); } -function attachPointToShape(shapeId, pointid, position){ +function attachPointToShape(shapeId, pointid, position, label){ var shape = getShape(shapeId); var scale = 1 / imgSelected.size.imageScale; + label = label || shape.featurePoints.length; shape.featurePoints.push( { "x": position.cx * scale, "y": position.cy * scale, - "label" : shape.featurePoints.length, + "label" : label, "id" : pointid }); } @@ -160,8 +161,11 @@ function updateShapeDetailInStore(shapeId, bbox, points){ function attachShapeToImg(id, type, bbox, points, metadata){ var shape = scaleShape(id, type, bbox, points, 1 / imgSelected.size.imageScale); if (metadata) { - shape.label = metadata.label; shape.category = metadata.category; + shape.label = metadata.label; + shape.attributes = metadata.attributes; + shape.tags = metadata.tags; + shape.featurePointLabels = metadata.featurePointLabels; } labellingData[ imgSelected.name ].shapes.push(shape); return shape; @@ -169,8 +173,13 @@ function attachShapeToImg(id, type, bbox, points, metadata){ function getMetadata(shape) { shape = getShape(shape.node.id); - return {'label': shape.label, - 'category': shape.category}; + return { + 'category': shape.category, + 'label': shape.label, + 'attributes': shape.attributes.map(attr => Object.assign({}, attr)), + 'tags': shape.tags.slice(), + 'featurePointLabels': shape.featurePoints.map(point => point.label) + }; } function addImgToStore(imgname, size) { diff --git a/tags/workarea.tag.html b/tags/workarea.tag.html index 1be9998..bde7a15 100644 --- a/tags/workarea.tag.html +++ b/tags/workarea.tag.html @@ -71,7 +71,6 @@ */ copiedElements = []; selectedElements.forEach(shape => { - console.log(getMetadata(shape)); if (shape.hasClass('shape')) { var featurePoints = []; shape.siblings() @@ -107,10 +106,11 @@ // Add shape data and any points into labellingData var shapeId = shape.type + currentImgData.shapeIndex++; var shapeData = attachShapeToImg(shapeId, shape.type, shape.rbox, shape.points, shape.metadata); - shape.featurePoints.forEach(point => { + shape.featurePoints.forEach((point, index) => { var pointId = shapeId + point.type + currentImgData.pointIndex++; - attachPointToShape(shapeId, pointId, point.rbox); + attachPointToShape(shapeId, pointId, point.rbox, shapeData.featurePointLabels[index]); }); + delete shape.featurePointLabels; }); } // Call update to redraw shapes From 7833304794c739e45c941d6a16b442596ba90a67 Mon Sep 17 00:00:00 2001 From: Phil <35127144+flurmbo@users.noreply.github.com> Date: Fri, 9 Nov 2018 22:42:47 -0600 Subject: [PATCH 3/3] code commenting --- tags/workarea.tag.html | 1 + 1 file changed, 1 insertion(+) diff --git a/tags/workarea.tag.html b/tags/workarea.tag.html index bde7a15..125292b 100644 --- a/tags/workarea.tag.html +++ b/tags/workarea.tag.html @@ -110,6 +110,7 @@ var pointId = shapeId + point.type + currentImgData.pointIndex++; attachPointToShape(shapeId, pointId, point.rbox, shapeData.featurePointLabels[index]); }); + // feature point labels no longer needed here after attaching feature points delete shape.featurePointLabels; }); }