Skip to content

Commit b7cb1a9

Browse files
authored
feat: Merge pull request #85 from UniversalDataTool/feat/modify-allowed-area
Feature: Modify Allowed Area
2 parents 69bd601 + 69a2df5 commit b7cb1a9

File tree

9 files changed

+109
-173
lines changed

9 files changed

+109
-173
lines changed

src/Annotator/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import useEventCallback from "use-event-callback"
2222
import makeImmutable, { without } from "seamless-immutable"
2323

2424
type Props = {
25-
taskDescription: string,
25+
taskDescription?: string,
2626
allowedArea?: { x: number, y: number, w: number, h: number },
2727
regionTagList?: Array<string>,
2828
regionClsList?: Array<string>,
@@ -68,7 +68,7 @@ export const Annotator = ({
6868
imageTagList = [],
6969
imageClsList = [],
7070
keyframes = {},
71-
taskDescription,
71+
taskDescription = "",
7272
fullImageSegmentationMode = false,
7373
RegionEditLabel,
7474
videoSrc,

src/Annotator/index.story.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ import Annotator from "./"
1414

1515
import { testRegions } from "../ImageCanvas/index.story"
1616

17+
const middlewares = [
18+
(store) => (next) => (action) => {
19+
actionAddon(action.type)(action)
20+
return next(action)
21+
},
22+
]
23+
1724
storiesOf("Annotator", module)
1825
.add("Basic", () => (
1926
<Annotator
2027
onExit={actionAddon("onExit")}
21-
middlewares={[
22-
(store) => (next) => (action) => {
23-
actionAddon(action.type)(action)
24-
return next(action)
25-
},
26-
]}
28+
middlewares={middlewares}
2729
labelImages
2830
regionClsList={["Alpha", "Beta", "Charlie", "Delta"]}
2931
regionTagList={["tag1", "tag2", "tag3"]}
@@ -112,12 +114,7 @@ storiesOf("Annotator", module)
112114
.add("Annotator w/o No Region Labels or Image Labels", () => (
113115
<Annotator
114116
onExit={actionAddon("onExit")}
115-
middlewares={[
116-
(store) => (next) => (action) => {
117-
actionAddon(action.type)(action)
118-
return next(action)
119-
},
120-
]}
117+
middlewares={middlewares}
121118
images={[
122119
{
123120
src: exampleImage,
@@ -132,12 +129,7 @@ storiesOf("Annotator", module)
132129
onExit={actionAddon("onExit")}
133130
enabledTools={[]}
134131
showTags={false}
135-
middlewares={[
136-
(store) => (next) => (action) => {
137-
actionAddon(action.type)(action)
138-
return next(action)
139-
},
140-
]}
132+
middlewares={middlewares}
141133
images={[
142134
{
143135
src: exampleImage,
@@ -195,12 +187,7 @@ storiesOf("Annotator", module)
195187
.add("Car Annotation", () => (
196188
<Annotator
197189
onExit={actionAddon("onExit")}
198-
middlewares={[
199-
(store) => (next) => (action) => {
200-
actionAddon(action.type)(action)
201-
return next(action)
202-
},
203-
]}
190+
middlewares={middlewares}
204191
labelImages
205192
regionClsList={["Car", "Sign", "Construction Barrier"]}
206193
regionTagList={["Moving", "Stopped", "Obstacle"]}
@@ -650,18 +637,30 @@ storiesOf("Annotator", module)
650637
.add("CORs Error (Pixel Segmentation)", () => (
651638
<Annotator
652639
onExit={actionAddon("onExit")}
653-
middlewares={[
654-
(store) => (next) => (action) => {
655-
actionAddon(action.type)(action)
656-
return next(action)
640+
middlewares={middlewares}
641+
labelImages
642+
fullImageSegmentationMode
643+
regionClsList={["Alpha", "Beta", "Charlie", "Delta"]}
644+
images={[
645+
{
646+
src: "https://placebear.com/200/300",
647+
name: "Frame 0036",
657648
},
658649
]}
650+
/>
651+
))
652+
.add("Modify Allowed Area", () => (
653+
<Annotator
654+
onExit={actionAddon("onExit")}
655+
middlewares={middlewares}
659656
labelImages
660657
fullImageSegmentationMode
658+
allowedArea={{ x: 0, y: 0.6, w: 0.3, h: 0.3 }}
659+
enabledTools={["modify-allowed-area"]}
661660
regionClsList={["Alpha", "Beta", "Charlie", "Delta"]}
662661
images={[
663662
{
664-
src: "https://placebear.com/200/300",
663+
src: exampleImage,
665664
name: "Frame 0036",
666665
},
667666
]}

src/Annotator/reducers/general-reducer.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const getRandomId = () => Math.random().toString().split(".")[1]
1616
export default (state: MainLayoutState, action: Action) => {
1717
if (
1818
state.allowedArea &&
19+
state.selectedTool !== "modify-allowed-area" &&
1920
["MOUSE_DOWN", "MOUSE_UP", "MOUSE_MOVE"].includes(action.type)
2021
) {
2122
const aa = state.allowedArea
@@ -241,6 +242,17 @@ export default (state: MainLayoutState, action: Action) => {
241242
}
242243
case "MOVE_REGION": {
243244
const { regionId } = state.mode
245+
if (regionId === "$$allowed_area") {
246+
const {
247+
allowedArea: { w, h },
248+
} = state
249+
return setIn(state, ["allowedArea"], {
250+
x: x - w / 2,
251+
y: y - h / 2,
252+
w,
253+
h,
254+
})
255+
}
244256
const regionIndex = getRegionIndex(regionId)
245257
if (regionIndex === null) return state
246258
return setIn(
@@ -255,9 +267,6 @@ export default (state: MainLayoutState, action: Action) => {
255267
freedom: [xFree, yFree],
256268
original: { x: ox, y: oy, w: ow, h: oh },
257269
} = state.mode
258-
const regionIndex = getRegionIndex(regionId)
259-
if (regionIndex === null) return state
260-
const box = activeImage.regions[regionIndex]
261270

262271
const dx = xFree === 0 ? ox : xFree === -1 ? Math.min(ox + ow, x) : ox
263272
const dw =
@@ -282,6 +291,19 @@ export default (state: MainLayoutState, action: Action) => {
282291
state = setIn(state, ["mode", "freedom"], [xFree, yFree * -1])
283292
}
284293

294+
if (regionId === "$$allowed_area") {
295+
return setIn(state, ["allowedArea"], {
296+
x: dx,
297+
w: dw,
298+
y: dy,
299+
h: dh,
300+
})
301+
}
302+
303+
const regionIndex = getRegionIndex(regionId)
304+
if (regionIndex === null) return state
305+
const box = activeImage.regions[regionIndex]
306+
285307
return setIn(state, [...pathToActiveImage, "regions", regionIndex], {
286308
...box,
287309
x: dx,
@@ -699,6 +721,9 @@ export default (state: MainLayoutState, action: Action) => {
699721
} else if (action.selectedTool === "show-mask") {
700722
return setIn(state, ["showMask"], !state.showMask)
701723
}
724+
if (action.selectedTool === "modify-allowed-area" && !state.allowedArea) {
725+
state = setIn(state, ["allowedArea"], { x: 0, y: 0, w: 1, h: 1 })
726+
}
702727
state = setIn(state, ["mode"], null)
703728
return setIn(state, ["selectedTool"], action.selectedTool)
704729
}

src/IconTools/index.js

Lines changed: 0 additions & 134 deletions
This file was deleted.

src/ImageCanvas/index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type Props = {
5757
zoomOnAllowedArea?: boolean,
5858
fullImageSegmentationMode?: boolean,
5959
autoSegmentationOptions?: Object,
60+
modifyingAllowedArea?: boolean,
6061

6162
onChangeRegion: (Region) => any,
6263
onBeginRegionEdit: (Region) => any,
@@ -126,6 +127,7 @@ export const ImageCanvas = ({
126127
onChangeVideoPlaying,
127128
onRegionClassAdded,
128129
zoomOnAllowedArea = true,
130+
modifyingAllowedArea = false,
129131
}: Props) => {
130132
const classes = useStyles()
131133

@@ -325,7 +327,24 @@ export const ImageCanvas = ({
325327
{imageLoaded && !dragging && (
326328
<RegionSelectAndTransformBoxes
327329
key="regionSelectAndTransformBoxes"
328-
regions={regions}
330+
regions={
331+
!modifyingAllowedArea || !allowedArea
332+
? regions
333+
: [
334+
{
335+
type: "box",
336+
id: "$$allowed_area",
337+
cls: "allowed_area",
338+
highlighted: true,
339+
x: allowedArea.x,
340+
y: allowedArea.y,
341+
w: allowedArea.w,
342+
h: allowedArea.h,
343+
visible: true,
344+
color: "#ff0",
345+
},
346+
]
347+
}
329348
mouseEvents={mouseEvents}
330349
projectRegionBox={projectRegionBox}
331350
dragWithPrimary={dragWithPrimary}

src/ImageCanvas/index.story.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,13 @@ storiesOf("ImageCanvas", module)
148148
{...events}
149149
/>
150150
))
151+
.add("Modify Allowed Area", () => (
152+
<ImageCanvas
153+
showTags
154+
regions={[]}
155+
imageSrc={exampleImage}
156+
modifyingAllowedArea
157+
allowedArea={{ x: 0.6, y: 0.6, w: 0.2, h: 0.2 }}
158+
{...events}
159+
/>
160+
))

src/MainLayout/icon-dictionary.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
faHandPaper,
1616
faSearch,
1717
faMask,
18+
faEdit,
1819
} from "@fortawesome/free-solid-svg-icons"
1920
import FullscreenIcon from "@material-ui/icons/Fullscreen"
2021

@@ -63,6 +64,9 @@ export const iconDictionary = {
6364
"show-mask": () => (
6465
<FontAwesomeIcon style={faStyle} size="xs" fixedWidth icon={faMask} />
6566
),
67+
"modify-allowed-area": () => (
68+
<FontAwesomeIcon style={faStyle} size="xs" fixedWidth icon={faEdit} />
69+
),
6670
window: FullscreenIcon,
6771
}
6872

0 commit comments

Comments
 (0)