Skip to content
Open
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
25 changes: 22 additions & 3 deletions js/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions tags/workarea.tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
'type': shape.type,
'rbox': shape.rbox(myCanvas),
'points': getPoints(shape),
'featurePoints': featurePoints
'featurePoints': featurePoints,
'metadata': getMetadata(shape)
});
}
})
Expand All @@ -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
Expand Down