Skip to content

Commit

Permalink
Merge pull request #460 from Kitware/fix/save-labelmaps-from-remote-d…
Browse files Browse the repository at this point in the history
…atasets

fix(PaintTool): only apply girder keys on upload
  • Loading branch information
floryst authored Nov 3, 2022
2 parents 7d6f01b + 6745e93 commit be4ff6f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/components/tools/PaintTool/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default {
computed: {
...mapState('widgets', {
imageToLabelmaps: (state) => state.imageToLabelmaps,
labelmapToImage: (state) => state.labelmapToImage,
labelmapStates: (state) => state.labelmapStates,
}),
labelmaps() {
Expand All @@ -99,6 +100,11 @@ export default {
activeLabelmapProxy() {
return this.$proxyManager.getProxyById(this.activeLabelmapId);
},
activeLabelmapParentImageProxy() {
return this.$proxyManager.getProxyById(
this.labelmapToImage[this.activeLabelmapId]
);
},
activeLabelmapState() {
return this.labelmapStates[this.activeLabelmapId];
},
Expand Down Expand Up @@ -248,6 +254,9 @@ export default {
labelmapState,
});
},
deleteLabelmapInternal(dispatch, labelmapId) {
return dispatch('widgets/deleteLabelmap', labelmapId);
},
}),
setRadius(r) {
this.radius = Math.max(1, Math.round(r));
Expand All @@ -264,7 +273,10 @@ export default {
}
},
deleteLabelmap() {
this.$proxyManager.deleteProxy(this.activeLabelmapProxy);
if (this.activeLabelmapProxy) {
this.deleteLabelmapInternal(this.activeLabelmapProxy.getProxyId());
this.$proxyManager.deleteProxy(this.activeLabelmapProxy);
}
},
filterImageData(source) {
return (
Expand Down Expand Up @@ -307,13 +319,6 @@ export default {
const baseImageName = this.targetImageProxy.getName();
lmProxy.setName(`Labelmap ${labelmapNum} ${baseImageName}`);

if (this.targetImageProxy.getKey('girderProvenance')) {
lmProxy.setKey(
'girderProvenance',
this.targetImageProxy.getKey('girderProvenance')
);
}

const labelMap = createLabelMapFromImage(backgroundImage);
labelMap.setLabelColor(lmState.selectedLabel, fromHex(this.palette[0]));

Expand Down Expand Up @@ -538,12 +543,19 @@ export default {
this.widgetId = -1;
},
upload() {
const proxy = this.activeLabelmapProxy;
if (proxy) {
setTimeout(() => {
setTimeout(() => {
const proxy = this.activeLabelmapProxy;
const parentImageProxy = this.activeLabelmapParentImageProxy;
if (proxy && parentImageProxy) {
if (parentImageProxy.getKey('girderProvenance')) {
proxy.setKey(
'girderProvenance',
parentImageProxy.getKey('girderProvenance')
);
}
this.$root.$emit('girder_upload_proxy', this.activeLabelmapId);
}, 10);
}
}
}, 10);
},
},
};
19 changes: 19 additions & 0 deletions src/store/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default ({ proxyManager }) => ({

// paint
imageToLabelmaps: {}, // image id -> [labelmap ids]
labelmapToImage: {}, // labelmap id -> parent image id
labelmapStates: {}, // labelmap id -> { selectedLabel, lastColorIndex }

// crop
Expand All @@ -33,8 +34,19 @@ export default ({ proxyManager }) => ({
if (!(imageId in state.imageToLabelmaps)) {
Vue.set(state.imageToLabelmaps, imageId, []);
}
Vue.set(state.labelmapToImage, labelmapId, imageId);
state.imageToLabelmaps[imageId].push(labelmapId);
},
deleteLabelmap(state, labelmapId) {
if (labelmapId in state.labelmapToImage) {
const imageId = state.labelmapToImage[labelmapId];
Vue.delete(state.labelmapToImage, labelmapId);
state.imageToLabelmaps[imageId].splice(
state.imageToLabelmaps[imageId].indexOf(labelmapId),
1
);
}
},
setLabelmapState(state, { labelmapId, labelmapState }) {
Vue.set(state.labelmapStates, labelmapId, labelmapState);
},
Expand Down Expand Up @@ -72,10 +84,17 @@ export default ({ proxyManager }) => ({
idMapping
);
});

const newLabelmapToImage = {};
Object.entries(state.labelmapToImage).forEach(([lmId, imageId]) => {
newLabelmapToImage[idMapping[lmId]] = idMapping[imageId];
});
state.labelmapToImage = newLabelmapToImage;
},
},
actions: {
addLabelmapToImage: wrapMutationAsAction('addLabelmapToImage'),
deleteLabelmap: wrapMutationAsAction('deleteLabelmap'),
setLabelmapState: wrapMutationAsAction('setLabelmapState'),
addMeasurementTool: wrapMutationAsAction('addMeasurementTool'),
removeMeasurementTool: wrapMutationAsAction('removeMeasurementTool'),
Expand Down

0 comments on commit be4ff6f

Please sign in to comment.