Skip to content

Commit d86aba4

Browse files
committed
checkpoint, refactoring regions
1 parent 79f3c9c commit d86aba4

File tree

13 files changed

+314
-93
lines changed

13 files changed

+314
-93
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ yarn-error.log*
2424
storybook-static
2525

2626
dist
27+
28+
secret.*
29+
secret.story.*
30+
*.secret.*

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"babel-preset-react-app": "^7.0.0",
7373
"gh-pages": "^2.0.1",
7474
"prettier": "^2.0.5",
75+
"raw.macro": "^0.3.0",
7576
"react-github-btn": "^1.1.1",
7677
"react-scripts": "^2.1.8"
7778
},

src/Annotator/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Props = {
4141
videoSrc?: string,
4242
keyframes?: Object,
4343
videoName?: string,
44+
fullImageSegmentationMode?: boolean,
4445
}
4546

4647
export const Annotator = ({
@@ -50,15 +51,21 @@ export const Annotator = ({
5051
showPointDistances,
5152
pointDistancePrecision,
5253
showTags = true,
53-
enabledTools = ["select", "create-point", "create-box", "create-polygon"],
54+
enabledTools = [
55+
"select",
56+
"create-point",
57+
"create-box",
58+
"create-polygon",
59+
"create-expanding-line",
60+
],
5461
selectedTool = "select",
5562
regionTagList = [],
5663
regionClsList = [],
5764
imageTagList = [],
5865
imageClsList = [],
5966
keyframes = {},
6067
taskDescription,
61-
fullImageSegmentationMode,
68+
fullImageSegmentationMode = false,
6269
RegionEditLabel,
6370
videoSrc,
6471
videoTime = 0,

src/Annotator/reducers/general-reducer.js

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,37 @@ export default (state: MainLayoutState, action: Action) => {
291291
if (!activeImage) return state
292292
const { x, y } = action
293293

294-
let newRegion
295294
if (state.allowedArea) {
295+
// TODO clamp x/y instead of giving up
296+
// TODO or image bounds
296297
const aa = state.allowedArea
297298
if (x < aa.x || x > aa.x + aa.w || y < aa.y || y > aa.y + aa.h) {
298299
return state
299300
}
300301
}
301302

303+
if (state.mode) {
304+
switch (state.mode.mode) {
305+
case "DRAW_POLYGON": {
306+
const [polygon, regionIndex] = getRegion(state.mode.regionId)
307+
if (!polygon) break
308+
return setIn(
309+
state,
310+
[...pathToActiveImage, "regions", regionIndex],
311+
{ ...polygon, points: polygon.points.concat([[x, y]]) }
312+
)
313+
}
314+
case "DRAW_EXPANDING_LINE": {
315+
const [expandingLine, regionIndex] = getRegion(state.mode.regionId)
316+
if (!expandingLine) break
317+
return state
318+
}
319+
default:
320+
break
321+
}
322+
}
323+
324+
let newRegion
302325
let defaultRegionCls = undefined,
303326
defaultRegionColor = "#ff0000"
304327
if (activeImage && (activeImage.regions || []).length > 0) {
@@ -369,24 +392,26 @@ export default (state: MainLayoutState, action: Action) => {
369392
})
370393
break
371394
}
372-
default:
373-
break
374-
}
375-
376-
if (state.mode) {
377-
switch (state.mode.mode) {
378-
case "DRAW_POLYGON": {
379-
const [polygon, regionIndex] = getRegion(state.mode.regionId)
380-
if (!polygon) break
381-
return setIn(
382-
state,
383-
[...pathToActiveImage, "regions", regionIndex],
384-
{ ...polygon, points: polygon.points.concat([[x, y]]) }
385-
)
395+
case "create-expanding-line": {
396+
state = saveToHistory(state, "Create Expanding Line")
397+
newRegion = {
398+
type: "expanding-line",
399+
unfinished: true,
400+
points: [{ x, y, angle: null, width: null }],
401+
open: true,
402+
highlighted: true,
403+
color: defaultRegionColor,
404+
defaultRegionCls: defaultRegionCls,
405+
id: getRandomId(),
386406
}
387-
default:
388-
break
407+
state = setIn(state, ["mode"], {
408+
mode: "DRAW_EXPANDING_LINE",
409+
regionId: newRegion.id,
410+
})
411+
break
389412
}
413+
default:
414+
break
390415
}
391416

392417
const regions = [...(getIn(state, pathToActiveImage).regions || [])]

src/FullImageSegmentationAnnotator/index.story.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import hard3 from "./hard3.story.jpg"
1111

1212
import FullImageSegmentationAnnotator from "./"
1313

14-
storiesOf("FullImageSegmentationAnnotator", module)
14+
storiesOf("FullImageSegmentationAnnotator.Basic", module)
1515
.add("Orange 2 Class", () => (
1616
<div style={{ width: "100vw", height: "100vh" }}>
1717
<FullImageSegmentationAnnotator

src/HighlightBox/index.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ export const HighlightBox = ({
5656
pbox: { x: number, y: number, w: number, h: number },
5757
}) => {
5858
const classes = useStyles()
59+
60+
const styleCoords =
61+
r.type === "point"
62+
? {
63+
left: pbox.x + pbox.w / 2 - 30,
64+
top: pbox.y + pbox.h / 2 - 30,
65+
width: 60,
66+
height: 60,
67+
}
68+
: {
69+
left: pbox.x - 5,
70+
top: pbox.y - 5,
71+
width: pbox.w + 10,
72+
height: pbox.h + 10,
73+
}
74+
75+
const pathD =
76+
r.type === "point"
77+
? `M5,5 L${styleCoords.width - 5} 5L${styleCoords.width - 5} ${
78+
styleCoords.height - 5
79+
}L5 ${styleCoords.height - 5}Z`
80+
: `M5,5 L${pbox.w + 5},5 L${pbox.w + 5},${pbox.h + 5} L5,${pbox.h + 5} Z`
81+
5982
return (
6083
<svg
6184
key={r.id}
@@ -97,17 +120,10 @@ export const HighlightBox = ({
97120
: undefined,
98121
}),
99122
position: "absolute",
100-
left: pbox.x - 5,
101-
top: pbox.y - 5,
102-
width: pbox.w + 10,
103-
height: pbox.h + 10,
123+
...styleCoords,
104124
}}
105125
>
106-
<path
107-
d={`M5,5 L${pbox.w + 5},5 L${pbox.w + 5},${pbox.h + 5} L5,${
108-
pbox.h + 5
109-
} Z`}
110-
/>
126+
<path d={pathD} />
111127
</svg>
112128
)
113129
}

src/IconTools/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
faArrowsAlt,
77
faMousePointer,
88
faExpandArrowsAlt,
9+
faGripLines,
910
faTag,
1011
faPaintBrush,
1112
faCrosshairs,
@@ -37,7 +38,13 @@ type Props = {
3738
onClickTool: (string) => any,
3839
}
3940

40-
const defaultTools = ["select", "create-point", "create-box", "create-polygon"]
41+
const defaultTools = [
42+
"select",
43+
"create-point",
44+
"create-box",
45+
"create-polygon",
46+
"create-expanding-line",
47+
]
4148

4249
export const IconTools = ({
4350
showTags,
@@ -103,6 +110,11 @@ export const IconTools = ({
103110
name="Add Polygon"
104111
icon={<FontAwesomeIcon size="xs" fixedWidth icon={faDrawPolygon} />}
105112
/>
113+
<SmallToolButton
114+
id="create-expanding-line"
115+
name="Add Expanding Line"
116+
icon={<FontAwesomeIcon size="xs" fixedWidth icon={faGripLines} />}
117+
/>
106118
{/* <SmallToolButton
107119
id="create-pixel"
108120
name="Add Pixel Region"

src/ImageCanvas/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ImageMask from "../ImageMask"
1919
import RegionSelectAndTransformBoxes from "../RegionSelectAndTransformBoxes"
2020
import VideoOrImageCanvasBackground from "../VideoOrImageCanvasBackground"
2121
import useEventCallback from "use-event-callback"
22+
import RegionShapes from "../RegionShapes"
2223

2324
const useStyles = makeStyles(styles)
2425

@@ -490,7 +491,16 @@ export const ImageCanvas = ({
490491
classPoints={classPoints}
491492
/>
492493
)}
493-
<canvas className={classes.canvas} ref={canvasEl} />
494+
<canvas
495+
style={{ opacity: 0.25 }}
496+
className={classes.canvas}
497+
ref={canvasEl}
498+
/>
499+
<RegionShapes
500+
mat={mat}
501+
imagePosition={imagePosition}
502+
regions={regions}
503+
/>
494504
<VideoOrImageCanvasBackground
495505
videoPlaying={videoPlaying}
496506
imagePosition={imagePosition}

src/ImageCanvas/use-mouse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default ({
3333
// NOTE: We're mutating mat here
3434
mat.translate(mx, my).scaleU(scale)
3535
if (mat.a > 2) mat.scaleU(2 / mat.a)
36-
if (mat.a < 0.1) mat.scaleU(0.1 / mat.a)
36+
if (mat.a < 0.05) mat.scaleU(0.05 / mat.a)
3737
mat.translate(-mx, -my)
3838

3939
changeMat(mat.clone())
@@ -127,7 +127,7 @@ export default ({
127127
(zoomEnd.x - zoomStart.x) / iw,
128128
(zoomEnd.y - zoomStart.y) / ih
129129
)
130-
if (scale < 0.1) scale = 0.1
130+
if (scale < 0.05) scale = 0.05
131131
if (scale > 10) scale = 10
132132

133133
const newMat = getDefaultMat()

0 commit comments

Comments
 (0)