@searpent/react-image-annotate 2.0.5 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/Annotator/examplePhotos.js +6976 -0
  2. package/Annotator/index.js +268 -0
  3. package/Annotator/reducers/combine-reducers.js +14 -0
  4. package/Annotator/reducers/convert-expanding-line-to-polygon.js +73 -0
  5. package/{src/Annotator → Annotator}/reducers/fix-twisted.js +3 -5
  6. package/Annotator/reducers/general-reducer.js +1152 -0
  7. package/Annotator/reducers/get-active-image.js +27 -0
  8. package/Annotator/reducers/get-implied-video-regions.js +180 -0
  9. package/Annotator/reducers/history-handler.js +38 -0
  10. package/Annotator/reducers/image-reducer.js +20 -0
  11. package/Annotator/reducers/video-reducer.js +88 -0
  12. package/ClassSelectionMenu/index.js +135 -0
  13. package/Crosshairs/index.js +53 -0
  14. package/DebugSidebarBox/index.js +20 -0
  15. package/DemoSite/Editor.js +194 -0
  16. package/DemoSite/ErrorBoundaryDialog.js +64 -0
  17. package/DemoSite/index.js +40 -0
  18. package/{src/Editor → Editor}/annotation-plugin/annotation.css +0 -0
  19. package/Editor/annotation-plugin/annotation.js +613 -0
  20. package/Editor/index.js +57 -0
  21. package/{src/Editor → Editor}/tools.js +2 -3
  22. package/FullImageSegmentationAnnotator/index.js +7 -0
  23. package/GroupSelectorSidebarBox/index.js +63 -0
  24. package/HighlightBox/index.js +99 -0
  25. package/HistorySidebarBox/index.js +71 -0
  26. package/ImageCanvas/index.js +429 -0
  27. package/ImageCanvas/region-tools.js +165 -0
  28. package/{src/ImageCanvas → ImageCanvas}/styles.js +12 -8
  29. package/ImageCanvas/use-mouse.js +180 -0
  30. package/ImageCanvas/use-project-box.js +27 -0
  31. package/ImageCanvas/use-wasd-mode.js +62 -0
  32. package/ImageMask/index.js +133 -0
  33. package/ImageMask/load-image.js +25 -0
  34. package/ImageSelectorSidebarBox/index.js +60 -0
  35. package/KeyframeTimeline/get-time-string.js +27 -0
  36. package/KeyframeTimeline/index.js +233 -0
  37. package/KeyframesSelectorSidebarBox/index.js +93 -0
  38. package/LandingPage/index.js +159 -0
  39. package/MainLayout/icon-dictionary.js +104 -0
  40. package/MainLayout/index.js +469 -0
  41. package/{src/MainLayout → MainLayout}/styles.js +6 -7
  42. package/MainLayout/types.js +0 -0
  43. package/MainLayout/use-implied-video-regions.js +13 -0
  44. package/MetadataEditorSidebarBox/index.js +126 -0
  45. package/PageSelector/index.js +69 -0
  46. package/{src/PageSelector → PageSelector}/page-selector.css +18 -0
  47. package/PointDistances/index.js +73 -0
  48. package/PreventScrollToParents/index.js +51 -0
  49. package/RegionLabel/index.js +205 -0
  50. package/{src/RegionLabel → RegionLabel}/styles.js +12 -15
  51. package/RegionSelectAndTransformBoxes/index.js +167 -0
  52. package/RegionSelectorSidebarBox/index.js +248 -0
  53. package/{src/RegionSelectorSidebarBox → RegionSelectorSidebarBox}/styles.js +13 -14
  54. package/RegionShapes/index.js +294 -0
  55. package/RegionTags/index.js +142 -0
  56. package/SettingsDialog/index.js +52 -0
  57. package/SettingsProvider/index.js +58 -0
  58. package/Shortcuts/ShortcutField.js +46 -0
  59. package/Shortcuts/index.js +133 -0
  60. package/ShortcutsManager/index.js +155 -0
  61. package/Sidebar/index.js +69 -0
  62. package/SidebarBoxContainer/index.js +93 -0
  63. package/SmallToolButton/index.js +42 -0
  64. package/TagsSidebarBox/index.js +105 -0
  65. package/TaskDescriptionSidebarBox/index.js +58 -0
  66. package/Theme/index.js +30 -0
  67. package/VideoOrImageCanvasBackground/index.js +151 -0
  68. package/colors.js +14 -0
  69. package/hooks/use-colors.js +101 -0
  70. package/hooks/use-event-callback.js +10 -0
  71. package/hooks/use-exclude-pattern.js +24 -0
  72. package/hooks/use-load-image.js +26 -0
  73. package/hooks/use-window-size.js +46 -0
  74. package/{src/hooks → hooks}/xpattern.js +1 -1
  75. package/index.js +3 -0
  76. package/lib.js +3 -0
  77. package/package.json +1 -1
  78. package/stories.js +5 -0
  79. package/{src/utils → utils}/filter-only-unique.js +1 -1
  80. package/utils/get-from-local-storage.js +7 -0
  81. package/utils/get-hotkey-help-text.js +9 -0
  82. package/utils/get-landmarks-with-transform.js +40 -0
  83. package/utils/photosToImages.js +53 -0
  84. package/utils/regions-to-blocks.js +16 -0
  85. package/utils/set-in-local-storage.js +3 -0
  86. package/.babelrc +0 -6
  87. package/.env +0 -1
  88. package/.flowconfig +0 -2
  89. package/.github/workflows/release-on-master.yml +0 -32
  90. package/.github/workflows/test.yml +0 -16
  91. package/.prettierrc +0 -3
  92. package/.releaserc.js +0 -18
  93. package/.storybook/addons.js +0 -2
  94. package/.storybook/config.js +0 -16
  95. package/LICENSE +0 -21
  96. package/public/favicon.ico +0 -0
  97. package/public/index.html +0 -38
  98. package/src/Annotator/bike-pic.png +0 -0
  99. package/src/Annotator/bike-pic2.png +0 -0
  100. package/src/Annotator/dab-keyframes.story.json +0 -1
  101. package/src/Annotator/examplePhotos.js +0 -7601
  102. package/src/Annotator/index.js +0 -291
  103. package/src/Annotator/index.story.js +0 -807
  104. package/src/Annotator/poses.story.js +0 -150
  105. package/src/Annotator/reducers/combine-reducers.js +0 -7
  106. package/src/Annotator/reducers/convert-expanding-line-to-polygon.js +0 -53
  107. package/src/Annotator/reducers/general-reducer.js +0 -996
  108. package/src/Annotator/reducers/get-active-image.js +0 -21
  109. package/src/Annotator/reducers/get-implied-video-regions.js +0 -115
  110. package/src/Annotator/reducers/history-handler.js +0 -60
  111. package/src/Annotator/reducers/image-reducer.js +0 -23
  112. package/src/Annotator/reducers/video-reducer.js +0 -85
  113. package/src/Annotator/video.story.js +0 -51
  114. package/src/ClassSelectionMenu/index.js +0 -108
  115. package/src/Crosshairs/index.js +0 -64
  116. package/src/DebugSidebarBox/index.js +0 -36
  117. package/src/DemoSite/Editor.js +0 -235
  118. package/src/DemoSite/ErrorBoundaryDialog.js +0 -34
  119. package/src/DemoSite/index.js +0 -41
  120. package/src/DemoSite/index.story.js +0 -10
  121. package/src/DemoSite/simple-segmentation-example.json +0 -572
  122. package/src/Editor/annotation-plugin/annotation.js +0 -515
  123. package/src/Editor/index.js +0 -24
  124. package/src/FullImageSegmentationAnnotator/hard1.story.jpg +0 -0
  125. package/src/FullImageSegmentationAnnotator/hard2.story.jpg +0 -0
  126. package/src/FullImageSegmentationAnnotator/hard3.story.jpg +0 -0
  127. package/src/FullImageSegmentationAnnotator/index.js +0 -7
  128. package/src/FullImageSegmentationAnnotator/index.story.js +0 -177
  129. package/src/FullImageSegmentationAnnotator/orange.story.png +0 -0
  130. package/src/GroupSelectorSidebarBox/index.js +0 -48
  131. package/src/HighlightBox/index.js +0 -143
  132. package/src/HistorySidebarBox/index.js +0 -78
  133. package/src/ImageCanvas/dancing-man.story.jpg +0 -0
  134. package/src/ImageCanvas/index.js +0 -494
  135. package/src/ImageCanvas/index.story.js +0 -314
  136. package/src/ImageCanvas/mouse_mask.story.png +0 -0
  137. package/src/ImageCanvas/region-tools.js +0 -171
  138. package/src/ImageCanvas/seves_desk.story.jpg +0 -0
  139. package/src/ImageCanvas/use-mouse.js +0 -168
  140. package/src/ImageCanvas/use-project-box.js +0 -23
  141. package/src/ImageCanvas/use-wasd-mode.js +0 -50
  142. package/src/ImageMask/index.js +0 -127
  143. package/src/ImageMask/load-image.js +0 -32
  144. package/src/ImageSelectorSidebarBox/index.js +0 -54
  145. package/src/KeyframeTimeline/get-time-string.js +0 -25
  146. package/src/KeyframeTimeline/index.js +0 -223
  147. package/src/KeyframesSelectorSidebarBox/index.js +0 -93
  148. package/src/LandingPage/content.md +0 -57
  149. package/src/LandingPage/github-markdown.css +0 -964
  150. package/src/LandingPage/index.js +0 -147
  151. package/src/MainLayout/icon-dictionary.js +0 -79
  152. package/src/MainLayout/index.js +0 -510
  153. package/src/MainLayout/index.story.js +0 -240
  154. package/src/MainLayout/types.js +0 -164
  155. package/src/MainLayout/use-implied-video-regions.js +0 -17
  156. package/src/MetadataEditorSidebarBox/index.js +0 -98
  157. package/src/PageSelector/index.js +0 -76
  158. package/src/PointDistances/index.js +0 -90
  159. package/src/PreventScrollToParents/index.js +0 -48
  160. package/src/PreventScrollToParents/index.story.js +0 -23
  161. package/src/RegionLabel/index.js +0 -222
  162. package/src/RegionSelectAndTransformBoxes/index.js +0 -234
  163. package/src/RegionSelectorSidebarBox/index.js +0 -216
  164. package/src/RegionShapes/index.js +0 -254
  165. package/src/RegionTags/index.js +0 -134
  166. package/src/SettingsDialog/index.js +0 -58
  167. package/src/SettingsProvider/index.js +0 -48
  168. package/src/Shortcuts/ShortcutField.js +0 -44
  169. package/src/Shortcuts/index.js +0 -129
  170. package/src/ShortcutsManager/index.js +0 -162
  171. package/src/Sidebar/index.js +0 -117
  172. package/src/SidebarBoxContainer/index.js +0 -93
  173. package/src/SmallToolButton/index.js +0 -57
  174. package/src/TagsSidebarBox/index.js +0 -93
  175. package/src/TaskDescriptionSidebarBox/index.js +0 -43
  176. package/src/Theme/index.js +0 -36
  177. package/src/VideoOrImageCanvasBackground/index.js +0 -170
  178. package/src/colors.js +0 -32
  179. package/src/hooks/use-colors.js +0 -74
  180. package/src/hooks/use-event-callback.js +0 -11
  181. package/src/hooks/use-exclude-pattern.js +0 -27
  182. package/src/hooks/use-load-image.js +0 -21
  183. package/src/hooks/use-window-size.js +0 -46
  184. package/src/hooks/xpattern.png +0 -0
  185. package/src/index.js +0 -18
  186. package/src/lib.js +0 -7
  187. package/src/screenshot.png +0 -0
  188. package/src/site.css +0 -5
  189. package/src/stories.js +0 -2
  190. package/src/utils/get-from-local-storage.js +0 -7
  191. package/src/utils/get-hotkey-help-text.js +0 -11
  192. package/src/utils/get-landmarks-with-transform.js +0 -23
  193. package/src/utils/photosToImages.js +0 -40
  194. package/src/utils/regions-to-blocks.js +0 -14
  195. package/src/utils/set-in-local-storage.js +0 -6
@@ -1,216 +0,0 @@
1
- // @flow
2
-
3
- import React, { Fragment, useState, memo } from "react"
4
- import SidebarBoxContainer from "../SidebarBoxContainer"
5
- import { makeStyles } from "@mui/styles"
6
- import { createTheme, ThemeProvider } from "@mui/material/styles"
7
- import { styled } from "@mui/material/styles"
8
- import { grey } from "@mui/material/colors"
9
- import RegionIcon from "@mui/icons-material/PictureInPicture"
10
- import Grid from "@mui/material/Grid"
11
- import ReorderIcon from "@mui/icons-material/SwapVert"
12
- import PieChartIcon from "@mui/icons-material/PieChart"
13
- import TrashIcon from "@mui/icons-material/Delete"
14
- import LockIcon from "@mui/icons-material/Lock"
15
- import UnlockIcon from "@mui/icons-material/LockOpen"
16
- import VisibleIcon from "@mui/icons-material/Visibility"
17
- import VisibleOffIcon from "@mui/icons-material/VisibilityOff"
18
- import styles from "./styles"
19
- import classnames from "classnames"
20
- import isEqual from "lodash/isEqual"
21
-
22
- const theme = createTheme()
23
- const useStyles = makeStyles((theme) => styles)
24
-
25
- const HeaderSep = styled("div")(({ theme }) => ({
26
- borderTop: `1px solid ${grey[200]}`,
27
- marginTop: 2,
28
- marginBottom: 2,
29
- }))
30
-
31
- const Chip = ({ color, text }) => {
32
- const classes = useStyles()
33
- return (
34
- <span className={classes.chip}>
35
- <div className="color" style={{ backgroundColor: color }} />
36
- <div className="text">{text}</div>
37
- </span>
38
- )
39
- }
40
-
41
- const RowLayout = ({
42
- header,
43
- highlighted,
44
- order,
45
- classification,
46
- area,
47
- tags,
48
- trash,
49
- lock,
50
- visible,
51
- onClick,
52
- }) => {
53
- const classes = useStyles()
54
- const [mouseOver, changeMouseOver] = useState(false)
55
- return (
56
- <div
57
- onClick={onClick}
58
- onMouseEnter={() => changeMouseOver(true)}
59
- onMouseLeave={() => changeMouseOver(false)}
60
- className={classnames(classes.row, { header, highlighted })}
61
- >
62
- <Grid container alignItems="center">
63
- <Grid item xs={2}>
64
- <div style={{ textAlign: "right", paddingRight: 10 }}>{order}</div>
65
- </Grid>
66
- <Grid item xs={5}>
67
- {classification}
68
- </Grid>
69
- <Grid item xs={2}>
70
- <div style={{ textAlign: "right", paddingRight: 6 }}>{area}</div>
71
- </Grid>
72
- <Grid item xs={1}>
73
- {trash}
74
- </Grid>
75
- <Grid item xs={1}>
76
- {lock}
77
- </Grid>
78
- <Grid item xs={1}>
79
- {visible}
80
- </Grid>
81
- </Grid>
82
- </div>
83
- )
84
- }
85
-
86
- const RowHeader = () => {
87
- return (
88
- <RowLayout
89
- header
90
- highlighted={false}
91
- order={<ReorderIcon className="icon" />}
92
- classification={<div style={{ paddingLeft: 10 }}>Class</div>}
93
- area={<PieChartIcon className="icon" />}
94
- trash={<TrashIcon className="icon" />}
95
- lock={<LockIcon className="icon" />}
96
- visible={<VisibleIcon className="icon" />}
97
- />
98
- )
99
- }
100
-
101
- const MemoRowHeader = memo(RowHeader)
102
-
103
- const Row = ({
104
- region: r,
105
- highlighted,
106
- onSelectRegion,
107
- onDeleteRegion,
108
- onChangeRegion,
109
- visible,
110
- locked,
111
- color,
112
- cls,
113
- index,
114
- }) => {
115
- return (
116
- <RowLayout
117
- header={false}
118
- highlighted={highlighted}
119
- onClick={() => onSelectRegion(r)}
120
- order={`#${index + 1}`}
121
- classification={<Chip text={cls || ""} color={color || "#ddd"} />}
122
- area=""
123
- trash={<TrashIcon onClick={() => onDeleteRegion(r)} className="icon2" />}
124
- lock={
125
- r.locked ? (
126
- <LockIcon
127
- onClick={() => onChangeRegion({ ...r, locked: false })}
128
- className="icon2"
129
- />
130
- ) : (
131
- <UnlockIcon
132
- onClick={() => onChangeRegion({ ...r, locked: true })}
133
- className="icon2"
134
- />
135
- )
136
- }
137
- visible={
138
- r.visible || r.visible === undefined ? (
139
- <VisibleIcon
140
- onClick={() => onChangeRegion({ ...r, visible: false })}
141
- className="icon2"
142
- />
143
- ) : (
144
- <VisibleOffIcon
145
- onClick={() => onChangeRegion({ ...r, visible: true })}
146
- className="icon2"
147
- />
148
- )
149
- }
150
- />
151
- )
152
- }
153
-
154
- const MemoRow = memo(
155
- Row,
156
- (prevProps, nextProps) =>
157
- prevProps.highlighted === nextProps.highlighted &&
158
- prevProps.visible === nextProps.visible &&
159
- prevProps.locked === nextProps.locked &&
160
- prevProps.id === nextProps.id &&
161
- prevProps.index === nextProps.index &&
162
- prevProps.cls === nextProps.cls &&
163
- prevProps.color === nextProps.color
164
- )
165
-
166
- const emptyArr = []
167
-
168
- export const RegionSelectorSidebarBox = ({
169
- regions = emptyArr,
170
- onDeleteRegion,
171
- onChangeRegion,
172
- onSelectRegion,
173
- }) => {
174
- const classes = useStyles()
175
- return (
176
- <ThemeProvider theme={theme}>
177
- <SidebarBoxContainer
178
- title="Regions"
179
- subTitle=""
180
- icon={<RegionIcon style={{ color: grey[700] }} />}
181
- expandedByDefault
182
- >
183
- <div className={classes.container}>
184
- <MemoRowHeader />
185
- <HeaderSep />
186
- {regions.map((r, i) => (
187
- <MemoRow
188
- key={r.id}
189
- {...r}
190
- region={r}
191
- index={i}
192
- onSelectRegion={onSelectRegion}
193
- onDeleteRegion={onDeleteRegion}
194
- onChangeRegion={onChangeRegion}
195
- />
196
- ))}
197
- </div>
198
- </SidebarBoxContainer>
199
- </ThemeProvider>
200
- )
201
- }
202
-
203
- const mapUsedRegionProperties = (r) => [
204
- r.id,
205
- r.color,
206
- r.locked,
207
- r.visible,
208
- r.highlighted,
209
- ]
210
-
211
- export default memo(RegionSelectorSidebarBox, (prevProps, nextProps) =>
212
- isEqual(
213
- (prevProps.regions || emptyArr).map(mapUsedRegionProperties),
214
- (nextProps.regions || emptyArr).map(mapUsedRegionProperties)
215
- )
216
- )
@@ -1,254 +0,0 @@
1
- // @flow
2
-
3
- import React, { memo } from "react"
4
- import colorAlpha from "color-alpha"
5
- import useColors from '../hooks/use-colors';
6
-
7
-
8
- function clamp(num, min, max) {
9
- return num <= min ? min : num >= max ? max : num
10
- }
11
-
12
- const RegionComponents = {
13
- point: memo(({ region, iw, ih }) => (
14
- <g transform={`translate(${region.x * iw} ${region.y * ih})`}>
15
- <path
16
- d={"M0 8L8 0L0 -8L-8 0Z"}
17
- strokeWidth={2}
18
- stroke={region.color}
19
- fill="transparent"
20
- />
21
- </g>
22
- )),
23
- line: memo(({ region, iw, ih }) => (
24
- <g transform={`translate(${region.x1 * iw} ${region.y1 * ih})`}>
25
- <line
26
- strokeWidth={2}
27
- x1={0}
28
- y1={0}
29
- x2={(region.x2 - region.x1) * iw}
30
- y2={(region.y2 - region.y1) * ih}
31
- stroke={colorAlpha(region.color, 0.75)}
32
- fill={colorAlpha(region.color, 0.25)}
33
- />
34
- </g>
35
- )),
36
- box: memo(({ region, iw, ih }) => {
37
- const { clsColor, groupColor } = useColors();
38
-
39
- if (region.groupId !== undefined) {
40
- return <g transform={`translate(${region.x * iw} ${region.y * ih})`}>
41
- <rect
42
- strokeWidth={(region.groupHighlighted) ? 3 : 0}
43
- x={0}
44
- y={0}
45
- width={Math.max(region.w * iw, 0)}
46
- height={Math.max(region.h * ih, 0)}
47
- stroke={colorAlpha(clsColor(region.cls), 0.85)}
48
- fill={(region.groupHighlighted) ? colorAlpha(groupColor(region.groupId), 0.5) : colorAlpha(groupColor(region.groupId), 0.25)}
49
- />
50
- </g>
51
- } else {
52
- return <g transform={`translate(${region.x * iw} ${region.y * ih})`}>
53
- <rect
54
- strokeWidth={2}
55
- x={0}
56
- y={0}
57
- width={Math.max(region.w * iw, 0)}
58
- height={Math.max(region.h * ih, 0)}
59
- stroke={colorAlpha(clsColor(region.cls), 0.85)}
60
- fill={colorAlpha(clsColor(region.cls), 0.25)}
61
- />
62
- </g>
63
- }
64
- }
65
- ),
66
- polygon: memo(({ region, iw, ih, fullSegmentationMode }) => {
67
- const Component = region.open ? "polyline" : "polygon"
68
- const alphaBase = fullSegmentationMode ? 0.5 : 1
69
- return (
70
- <Component
71
- points={region.points
72
- .map(([x, y]) => [x * iw, y * ih])
73
- .map((a) => a.join(" "))
74
- .join(" ")}
75
- strokeWidth={2}
76
- stroke={colorAlpha(region.color, 0.75)}
77
- fill={colorAlpha(region.color, 0.25)}
78
- />
79
- )
80
- }),
81
- keypoints: ({ region, iw, ih, keypointDefinitions }) => {
82
- const { points, keypointsDefinitionId } = region
83
- if (!keypointDefinitions[keypointsDefinitionId]) {
84
- throw new Error(
85
- `No definition for keypoint configuration "${keypointsDefinitionId}"`
86
- )
87
- }
88
- const { landmarks, connections } =
89
- keypointDefinitions[keypointsDefinitionId]
90
- return (
91
- <g>
92
- {Object.entries(points).map(([keypointId, { x, y }], i) => (
93
- <g key={i} transform={`translate(${x * iw} ${y * ih})`}>
94
- <path
95
- d={"M0 8L8 0L0 -8L-8 0Z"}
96
- strokeWidth={2}
97
- stroke={landmarks[keypointId].color}
98
- fill="transparent"
99
- />
100
- </g>
101
- ))}
102
- {connections.map(([kp1Id, kp2Id]) => {
103
- const kp1 = points[kp1Id]
104
- const kp2 = points[kp2Id]
105
- const midPoint = { x: (kp1.x + kp2.x) / 2, y: (kp1.y + kp2.y) / 2 }
106
-
107
- return (
108
- <g key={`${kp1.x},${kp1.y}.${kp2.x},${kp2.y}`}>
109
- <line
110
- x1={kp1.x * iw}
111
- y1={kp1.y * ih}
112
- x2={midPoint.x * iw}
113
- y2={midPoint.y * ih}
114
- strokeWidth={2}
115
- stroke={landmarks[kp1Id].color}
116
- />
117
- <line
118
- x1={kp2.x * iw}
119
- y1={kp2.y * ih}
120
- x2={midPoint.x * iw}
121
- y2={midPoint.y * ih}
122
- strokeWidth={2}
123
- stroke={landmarks[kp2Id].color}
124
- />
125
- </g>
126
- )
127
- })}
128
- </g>
129
- )
130
- },
131
- "expanding-line": memo(({ region, iw, ih }) => {
132
- let { expandingWidth = 0.005, points } = region
133
- expandingWidth = points.slice(-1)[0].width || expandingWidth
134
- const pointPairs = points.map(({ x, y, angle, width }, i) => {
135
- if (!angle) {
136
- const n = points[clamp(i + 1, 0, points.length - 1)]
137
- const p = points[clamp(i - 1, 0, points.length - 1)]
138
- angle = Math.atan2(p.x - n.x, p.y - n.y) + Math.PI / 2
139
- }
140
- const dx = (Math.sin(angle) * (width || expandingWidth)) / 2
141
- const dy = (Math.cos(angle) * (width || expandingWidth)) / 2
142
- return [
143
- { x: x + dx, y: y + dy },
144
- { x: x - dx, y: y - dy },
145
- ]
146
- })
147
- const firstSection = pointPairs.map(([p1, p2]) => p1)
148
- const secondSection = pointPairs.map(([p1, p2]) => p2).asMutable()
149
- secondSection.reverse()
150
- const lastPoint = points.slice(-1)[0]
151
- return (
152
- <>
153
- <polygon
154
- points={firstSection
155
- .concat(region.candidatePoint ? [region.candidatePoint] : [])
156
- .concat(secondSection)
157
- .map((p) => `${p.x * iw} ${p.y * ih}`)
158
- .join(" ")}
159
- strokeWidth={2}
160
- stroke={colorAlpha(region.color, 0.75)}
161
- fill={colorAlpha(region.color, 0.25)}
162
- />
163
- {points.map(({ x, y, angle }, i) => (
164
- <g
165
- key={i}
166
- transform={`translate(${x * iw} ${y * ih}) rotate(${(-(angle || 0) * 180) / Math.PI
167
- })`}
168
- >
169
- <g>
170
- <rect
171
- x={-5}
172
- y={-5}
173
- width={10}
174
- height={10}
175
- strokeWidth={2}
176
- stroke={colorAlpha(region.color, 0.75)}
177
- fill={colorAlpha(region.color, 0.25)}
178
- />
179
- </g>
180
- </g>
181
- ))}
182
- <rect
183
- x={lastPoint.x * iw - 8}
184
- y={lastPoint.y * ih - 8}
185
- width={16}
186
- height={16}
187
- strokeWidth={4}
188
- stroke={colorAlpha(region.color, 0.5)}
189
- fill={"transparent"}
190
- />
191
- </>
192
- )
193
- }),
194
- pixel: () => null,
195
- }
196
-
197
- export const WrappedRegionList = memo(
198
- ({ regions, keypointDefinitions, iw, ih, fullSegmentationMode }) => {
199
- return regions
200
- .filter((r) => r.visible !== false)
201
- .map((r) => {
202
- const Component = RegionComponents[r.type]
203
- return (
204
- <Component
205
- key={r.regionId}
206
- region={r}
207
- iw={iw}
208
- ih={ih}
209
- keypointDefinitions={keypointDefinitions}
210
- fullSegmentationMode={fullSegmentationMode}
211
- />
212
- )
213
- })
214
- },
215
- (n, p) => n.regions === p.regions && n.iw === p.iw && n.ih === p.ih
216
- )
217
-
218
- export const RegionShapes = ({
219
- mat,
220
- imagePosition,
221
- regions = [],
222
- keypointDefinitions,
223
- fullSegmentationMode,
224
- }) => {
225
- const iw = imagePosition.bottomRight.x - imagePosition.topLeft.x
226
- const ih = imagePosition.bottomRight.y - imagePosition.topLeft.y
227
- if (isNaN(iw) || isNaN(ih)) return null
228
- return (
229
- <svg
230
- width={iw}
231
- height={ih}
232
- style={{
233
- position: "absolute",
234
- zIndex: 2,
235
- left: imagePosition.topLeft.x,
236
- top: imagePosition.topLeft.y,
237
- pointerEvents: "none",
238
- width: iw,
239
- height: ih,
240
- }}
241
- >
242
- <WrappedRegionList
243
- key="wrapped-region-list"
244
- regions={regions}
245
- iw={iw}
246
- ih={ih}
247
- keypointDefinitions={keypointDefinitions}
248
- fullSegmentationMode={fullSegmentationMode}
249
- />
250
- </svg>
251
- )
252
- }
253
-
254
- export default RegionShapes
@@ -1,134 +0,0 @@
1
- // @flow weak
2
-
3
- import React from "react"
4
- import Paper from "@mui/material/Paper"
5
- import DefaultRegionLabel from "../RegionLabel"
6
- import LockIcon from "@mui/icons-material/Lock"
7
-
8
- const copyWithout = (obj, ...args) => {
9
- const newObj = { ...obj }
10
- for (const arg of args) {
11
- delete newObj[arg]
12
- }
13
- return newObj
14
- }
15
-
16
- export const RegionTags = ({
17
- regions,
18
- projectRegionBox,
19
- mouseEvents,
20
- regionClsList,
21
- regionTagList,
22
- onBeginRegionEdit,
23
- onChangeRegion,
24
- onCloseRegionEdit,
25
- onDeleteRegion,
26
- layoutParams,
27
- imageSrc,
28
- RegionEditLabel,
29
- onRegionClassAdded,
30
- allowComments,
31
- hideNotEditingLabel,
32
- allowedGroups
33
- }) => {
34
- const RegionLabel =
35
- RegionEditLabel != null ? RegionEditLabel : DefaultRegionLabel
36
- return regions
37
- .filter((r) => r.visible || r.visible === undefined)
38
- .map((region) => {
39
- const pbox = projectRegionBox(region)
40
- const { iw, ih } = layoutParams.current
41
- let margin = 8
42
- if (region.highlighted && region.type === "box") margin += 6
43
- const labelBoxHeight =
44
- region.editingLabels && !region.locked ? 170 : region.tags ? 60 : 50
45
- const displayOnTop = pbox.y > labelBoxHeight
46
-
47
- const coords = displayOnTop
48
- ? {
49
- left: pbox.x,
50
- top: pbox.y - margin / 2,
51
- }
52
- : { left: pbox.x, top: pbox.y + pbox.h + margin / 2 }
53
- if (region.locked) {
54
- return (
55
- <div
56
- key={region.id}
57
- style={{
58
- position: "absolute",
59
- ...coords,
60
- zIndex: 10 + (region.editingLabels ? 5 : 0),
61
- }}
62
- >
63
- <Paper
64
- style={{
65
- position: "absolute",
66
- left: 0,
67
- ...(displayOnTop ? { bottom: 0 } : { top: 0 }),
68
- zIndex: 10,
69
- backgroundColor: "#fff",
70
- borderRadius: 4,
71
- padding: 2,
72
- paddingBottom: 0,
73
- opacity: 0.5,
74
- pointerEvents: "none",
75
- }}
76
- >
77
- <LockIcon style={{ width: 16, height: 16, color: "#333" }} />
78
- </Paper>
79
- </div>
80
- )
81
- }
82
- return (
83
- <div
84
- key={region.id}
85
- style={{
86
- position: "absolute",
87
- ...coords,
88
- zIndex: 10 + (region.editingLabels ? 5 : 0),
89
- width: 200,
90
- }}
91
- onMouseDown={(e) => e.preventDefault()}
92
- onMouseUp={(e) => e.preventDefault()}
93
- onMouseEnter={(e) => {
94
- if (region.editingLabels) {
95
- mouseEvents.onMouseUp(e)
96
- e.button = 1
97
- mouseEvents.onMouseUp(e)
98
- }
99
- }}
100
- >
101
- <div
102
- style={{
103
- position: "absolute",
104
- zIndex: 20,
105
- left: 0,
106
- ...(displayOnTop ? { bottom: 0 } : { top: 0 }),
107
- }}
108
- {...(!region.editingLabels
109
- ? copyWithout(mouseEvents, "onMouseDown", "onMouseUp")
110
- : {})}
111
- >
112
- <RegionLabel
113
- allowedClasses={regionClsList}
114
- allowedTags={regionTagList}
115
- onOpen={onBeginRegionEdit}
116
- onChange={onChangeRegion}
117
- onClose={onCloseRegionEdit}
118
- onDelete={onDeleteRegion}
119
- editing={region.editingLabels}
120
- region={region}
121
- regions={regions}
122
- imageSrc={imageSrc}
123
- onRegionClassAdded={onRegionClassAdded}
124
- allowComments={allowComments}
125
- hideNotEditingLabel={hideNotEditingLabel}
126
- allowedGroups={allowedGroups}
127
- />
128
- </div>
129
- </div>
130
- )
131
- })
132
- }
133
-
134
- export default RegionTags
@@ -1,58 +0,0 @@
1
- // @flow
2
-
3
- import React from "react"
4
- import Dialog from "@mui/material/Dialog"
5
- import DialogTitle from "@mui/material/DialogTitle"
6
- import DialogContent from "@mui/material/DialogContent"
7
- import DialogActions from "@mui/material/DialogActions"
8
- import Button from "@mui/material/Button"
9
- import Survey from "material-survey/components/Survey"
10
- import { useSettings } from "../SettingsProvider"
11
-
12
- export const SettingsDialog = ({ open, onClose }) => {
13
- const settings = useSettings()
14
- return (
15
- <Dialog open={open || false} onClose={onClose}>
16
- <DialogTitle>Settings</DialogTitle>
17
- <DialogContent style={{ minWidth: 400 }}>
18
- <Survey
19
- variant="flat"
20
- noActions
21
- defaultAnswers={settings}
22
- onQuestionChange={(q, a, answers) => settings.changeSetting(q, a)}
23
- form={{
24
- questions: [
25
- {
26
- type: "boolean",
27
- title: "Show Crosshairs",
28
- name: "showCrosshairs",
29
- },
30
- {
31
- type: "boolean",
32
- title: "Show Highlight Box",
33
- name: "showHighlightBox",
34
- },
35
- {
36
- type: "boolean",
37
- title: "WASD Mode",
38
- name: "wasdMode",
39
- },
40
- {
41
- type: "dropdown",
42
- title: "Video Playback Speed",
43
- name: "videoPlaybackSpeed",
44
- defaultValue: "1x",
45
- choices: ["0.25x", "0.5x", "1x", "2x"],
46
- },
47
- ],
48
- }}
49
- />
50
- </DialogContent>
51
- <DialogActions>
52
- <Button onClick={onClose}>Close</Button>
53
- </DialogActions>
54
- </Dialog>
55
- )
56
- }
57
-
58
- export default SettingsDialog
@@ -1,48 +0,0 @@
1
- // @flow
2
-
3
- import React, { createContext, useContext, useState } from "react"
4
-
5
- const defaultSettings = {
6
- showCrosshairs: false,
7
- showHighlightBox: true,
8
- wasdMode: true,
9
- }
10
-
11
- export const SettingsContext = createContext(defaultSettings)
12
-
13
- const pullSettingsFromLocalStorage = () => {
14
- if (!window || !window.localStorage) return {}
15
- let settings = {}
16
- for (let i = 0; i < window.localStorage.length; i++) {
17
- const key = window.localStorage.key(i)
18
- if (key.startsWith("settings_")) {
19
- try {
20
- settings[key.replace("settings_", "")] = JSON.parse(
21
- window.localStorage.getItem(key)
22
- )
23
- } catch (e) { }
24
- }
25
- }
26
- return settings
27
- }
28
-
29
- export const useSettings = () => useContext(SettingsContext)
30
-
31
- export const SettingsProvider = ({ children, clsColors, groupColors }) => {
32
- const [state, changeState] = useState({
33
- ...() => pullSettingsFromLocalStorage(),
34
- clsColors,
35
- groupColors,
36
- })
37
- const changeSetting = (setting: string, value: any) => {
38
- changeState({ ...state, [setting]: value })
39
- window.localStorage.setItem(`settings_${setting}`, JSON.stringify(value))
40
- }
41
- return (
42
- <SettingsContext.Provider value={{ ...state, changeSetting }}>
43
- {children}
44
- </SettingsContext.Provider>
45
- )
46
- }
47
-
48
- export default SettingsProvider