Skip to content

Commit 3859bd8

Browse files
committed
fix image segmentation multi-sample support
1 parent b35a666 commit 3859bd8

File tree

1 file changed

+26
-6
lines changed
  • src/components/ImageSegmentation

1 file changed

+26
-6
lines changed

src/components/ImageSegmentation/index.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default ({
2929
iface.labels = iface.availableLabels
3030
}
3131

32-
const [selectedIndex] = useState(0)
32+
const [selectedIndex, changeSelectedIndex] = useState(0)
3333
const [showTags, changeShowTags] = useState(true)
3434
const [selectedTool, changeSelectedTool] = useState("select")
3535

@@ -57,9 +57,9 @@ export default ({
5757
iface.multipleRegions || iface.multipleRegions === undefined
5858

5959
const onExit = useEventCallback((output, nextAction) => {
60-
const regionMat = (output.images || [])
61-
.map((img) => img.regions)
62-
.map((riaRegions) => (riaRegions || []).map(convertFromRIARegionFmt))
60+
const regionMat = (output.images || []).map((img) =>
61+
(img.regions || []).map(convertFromRIARegionFmt)
62+
)
6363

6464
for (let i = 0; i < regionMat.length; i++) {
6565
if (multipleRegions) {
@@ -73,10 +73,30 @@ export default ({
7373
if (containerProps.onExit) containerProps.onExit(nextAction)
7474
})
7575
const onNextImage = useEventCallback((output) => {
76-
onExit(output, "go-to-next")
76+
if (selectedIndex + 1 > samples.length) {
77+
onExit(output, "go-to-next")
78+
} else {
79+
onSaveTaskOutputItem(
80+
selectedIndex,
81+
multipleRegions
82+
? output.regions.map(convertFromRIARegionFmt)
83+
: convertToRIAImageFmt(output.regions[0])
84+
)
85+
changeSelectedIndex(selectedIndex + 1)
86+
}
7787
})
7888
const onPrevImage = useEventCallback((output) => {
79-
onExit(output, "go-to-previous")
89+
if (selectedIndex - 1 < 0) {
90+
onExit(output, "go-to-previous")
91+
} else {
92+
onSaveTaskOutputItem(
93+
selectedIndex,
94+
multipleRegions
95+
? output.regions.map(convertFromRIARegionFmt)
96+
: convertToRIAImageFmt(output.regions[0])
97+
)
98+
changeSelectedIndex(selectedIndex - 1)
99+
}
80100
})
81101

82102
const images = useMemo(

0 commit comments

Comments
 (0)