diff --git a/js/store.js b/js/store.js index 0a47103..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 }); } @@ -157,12 +158,30 @@ 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.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; } +function getMetadata(shape) { + shape = getShape(shape.node.id); + 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) { // 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..125292b 100644 --- a/tags/workarea.tag.html +++ b/tags/workarea.tag.html @@ -86,7 +86,8 @@ 'type': shape.type, 'rbox': shape.rbox(myCanvas), 'points': getPoints(shape), - 'featurePoints': featurePoints + 'featurePoints': featurePoints, + 'metadata': getMetadata(shape) }); } }) @@ -104,11 +105,13 @@ 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); - shape.featurePoints.forEach(point => { + var shapeData = attachShapeToImg(shapeId, shape.type, shape.rbox, shape.points, shape.metadata); + 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]); }); + // feature point labels no longer needed here after attaching feature points + delete shape.featurePointLabels; }); } // Call update to redraw shapes