fix(key): b
This commit is contained in:
@@ -1627,6 +1627,8 @@ const LabelPage = ({
|
|||||||
objectId: selectedContext.objectId,
|
objectId: selectedContext.objectId,
|
||||||
})
|
})
|
||||||
usePaperStore.getState().setPaperMode("polygon")
|
usePaperStore.getState().setPaperMode("polygon")
|
||||||
|
const started = usePaperStore.getState().beginContinuePolygonDraft()
|
||||||
|
if (!started) return
|
||||||
notifications.show({
|
notifications.show({
|
||||||
color: "green",
|
color: "green",
|
||||||
message: "已进入继续标注模式",
|
message: "已进入继续标注模式",
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import { getShowContextMenuPosition, usePaperStore } from "../usePaperStore"
|
|||||||
import { renderGroupPath } from "../useRenderGroupPath"
|
import { renderGroupPath } from "../useRenderGroupPath"
|
||||||
import { useRightToolsStore } from "../useRightToolsStore"
|
import { useRightToolsStore } from "../useRightToolsStore"
|
||||||
import { useTopToolsStore } from "../useTopToolsStore"
|
import { useTopToolsStore } from "../useTopToolsStore"
|
||||||
import { labelTypeMap } from "../utils/constants"
|
|
||||||
import { safeClone } from "../utils/clone"
|
import { safeClone } from "../utils/clone"
|
||||||
|
import { labelTypeMap } from "../utils/constants"
|
||||||
import RightGroupEditModal from "./RightGroupEditModal"
|
import RightGroupEditModal from "./RightGroupEditModal"
|
||||||
|
|
||||||
interface RightGroupToolsComponentProps {
|
interface RightGroupToolsComponentProps {
|
||||||
@@ -56,9 +56,25 @@ const RightGroupTools: React.FC<RightGroupToolsComponentProps> = (props) => {
|
|||||||
const { activeImage } = useBottomToolsStore()
|
const { activeImage } = useBottomToolsStore()
|
||||||
const { groupStatus, updateGroupStatus, selectedPath, updateSelectedPath } =
|
const { groupStatus, updateGroupStatus, selectedPath, updateSelectedPath } =
|
||||||
useObjectStore()
|
useObjectStore()
|
||||||
|
const continuePolygonTarget = usePaperStore(
|
||||||
|
(state) => state.continuePolygonTarget
|
||||||
|
)
|
||||||
const { getItemById, getItemsById } = usePaperStore()
|
const { getItemById, getItemsById } = usePaperStore()
|
||||||
const { shift: pressShift } = useKeyEventStore()
|
const { shift: pressShift } = useKeyEventStore()
|
||||||
const [isGroupCollapsed, setIsGroupCollapsed] = useState<boolean>(true)
|
const [isGroupCollapsed, setIsGroupCollapsed] = useState<boolean>(true)
|
||||||
|
const continueObjectId =
|
||||||
|
continuePolygonTarget?.imageId === activeImage
|
||||||
|
? continuePolygonTarget.objectId
|
||||||
|
: null
|
||||||
|
|
||||||
|
const getGroupChildren = useCallback(
|
||||||
|
(groupId: number) => {
|
||||||
|
const groupChildren = pathGroupMap.get(activeImage)?.get(groupId) || []
|
||||||
|
if (continueObjectId === null) return groupChildren
|
||||||
|
return groupChildren.filter((childId) => childId !== continueObjectId)
|
||||||
|
},
|
||||||
|
[activeImage, continueObjectId, pathGroupMap]
|
||||||
|
)
|
||||||
|
|
||||||
const handleSelect = useCallback(
|
const handleSelect = useCallback(
|
||||||
(id: number) => {
|
(id: number) => {
|
||||||
@@ -322,8 +338,10 @@ const RightGroupTools: React.FC<RightGroupToolsComponentProps> = (props) => {
|
|||||||
<ScrollArea style={{ flex: 1 }} px="md">
|
<ScrollArea style={{ flex: 1 }} px="md">
|
||||||
<Stack gap="xs" pb="md">
|
<Stack gap="xs" pb="md">
|
||||||
{pathGroupMap.get(activeImage) &&
|
{pathGroupMap.get(activeImage) &&
|
||||||
Array.from(pathGroupMap.get(activeImage)!.keys())?.map(
|
Array.from(pathGroupMap.get(activeImage)!.keys())
|
||||||
(groupId) => {
|
.filter((groupId) => getGroupChildren(groupId).length)
|
||||||
|
.map((groupId) => {
|
||||||
|
const groupChildren = getGroupChildren(groupId)
|
||||||
const isOpen =
|
const isOpen =
|
||||||
!groupStatus[activeImage + groupId]?.["COLLAPSE"]
|
!groupStatus[activeImage + groupId]?.["COLLAPSE"]
|
||||||
return (
|
return (
|
||||||
@@ -376,10 +394,7 @@ const RightGroupTools: React.FC<RightGroupToolsComponentProps> = (props) => {
|
|||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
<Group gap="xs">
|
<Group gap="xs">
|
||||||
<Text size="sm">
|
<Text size="sm">{groupChildren.length}</Text>
|
||||||
{pathGroupMap.get(activeImage)?.get(groupId)
|
|
||||||
?.length || 0}
|
|
||||||
</Text>
|
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
variant="subtle"
|
variant="subtle"
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -401,10 +416,7 @@ const RightGroupTools: React.FC<RightGroupToolsComponentProps> = (props) => {
|
|||||||
</Paper>
|
</Paper>
|
||||||
<Collapse in={isOpen}>
|
<Collapse in={isOpen}>
|
||||||
<Stack gap="xs" mt="xs" pl="xs">
|
<Stack gap="xs" mt="xs" pl="xs">
|
||||||
{pathGroupMap
|
{groupChildren.map((child) => {
|
||||||
.get(activeImage)
|
|
||||||
?.get(groupId)
|
|
||||||
?.map((child) => {
|
|
||||||
const isSelected =
|
const isSelected =
|
||||||
selectedPath[activeImage]?.includes(child)
|
selectedPath[activeImage]?.includes(child)
|
||||||
return (
|
return (
|
||||||
@@ -444,8 +456,7 @@ const RightGroupTools: React.FC<RightGroupToolsComponentProps> = (props) => {
|
|||||||
</Collapse>
|
</Collapse>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
})}
|
||||||
)}
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ import { getShowContextMenuPosition, usePaperStore } from "../usePaperStore"
|
|||||||
import { usePaperSupportStore } from "../usePaperSupportStore"
|
import { usePaperSupportStore } from "../usePaperSupportStore"
|
||||||
import { useTopToolsStore } from "../useTopToolsStore"
|
import { useTopToolsStore } from "../useTopToolsStore"
|
||||||
import { getSubAttrStatus } from "../util"
|
import { getSubAttrStatus } from "../util"
|
||||||
import { toggleObjectHideByShortcut } from "../utils/objectVisibility"
|
|
||||||
import { labelTypeMap } from "../utils/constants"
|
import { labelTypeMap } from "../utils/constants"
|
||||||
|
import { toggleObjectHideByShortcut } from "../utils/objectVisibility"
|
||||||
|
|
||||||
interface RightObjectToolsComponentProps {
|
interface RightObjectToolsComponentProps {
|
||||||
labelState: LabelState
|
labelState: LabelState
|
||||||
@@ -143,7 +143,27 @@ const RightObjectTools: React.FC<RightObjectToolsComponentProps> = (props) => {
|
|||||||
|
|
||||||
const { shift: pressShift } = useKeyEventStore()
|
const { shift: pressShift } = useKeyEventStore()
|
||||||
|
|
||||||
|
const continuePolygonTarget = usePaperStore(
|
||||||
|
(state) => state.continuePolygonTarget
|
||||||
|
)
|
||||||
const { getItemById, getItemsById } = usePaperStore()
|
const { getItemById, getItemsById } = usePaperStore()
|
||||||
|
const continueObjectId =
|
||||||
|
continuePolygonTarget?.imageId === activeImage
|
||||||
|
? continuePolygonTarget.objectId
|
||||||
|
: null
|
||||||
|
|
||||||
|
const getOperationChildren = useCallback(
|
||||||
|
(imageId: string, operationId: string) => {
|
||||||
|
const operationChildren = storeLabel.get(imageId)?.get(operationId) || []
|
||||||
|
if (continueObjectId === null || imageId !== activeImage) {
|
||||||
|
return operationChildren
|
||||||
|
}
|
||||||
|
return operationChildren.filter(
|
||||||
|
([objectId]) => objectId !== continueObjectId
|
||||||
|
)
|
||||||
|
},
|
||||||
|
[activeImage, continueObjectId, storeLabel]
|
||||||
|
)
|
||||||
|
|
||||||
// 切换选中对象时,清除所有其他对象的当前选中状态
|
// 切换选中对象时,清除所有其他对象的当前选中状态
|
||||||
const clearSelectedItems = () => {
|
const clearSelectedItems = () => {
|
||||||
@@ -381,14 +401,11 @@ const RightObjectTools: React.FC<RightObjectToolsComponentProps> = (props) => {
|
|||||||
(operationId: string, hide: boolean) => {
|
(operationId: string, hide: boolean) => {
|
||||||
updateOperationStatus(activeImage + operationId, "HIDE", hide)
|
updateOperationStatus(activeImage + operationId, "HIDE", hide)
|
||||||
|
|
||||||
storeLabel
|
getOperationChildren(activeImage, operationId).map((child) => {
|
||||||
.get(activeImage)
|
|
||||||
?.get(operationId)
|
|
||||||
?.map((child) => {
|
|
||||||
toggleObjectHideByShortcut(activeImage, operationId, child[0], hide)
|
toggleObjectHideByShortcut(activeImage, operationId, child[0], hide)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[activeImage, storeLabel, updateOperationStatus]
|
[activeImage, getOperationChildren, updateOperationStatus]
|
||||||
)
|
)
|
||||||
|
|
||||||
const objectHide = useCallback(
|
const objectHide = useCallback(
|
||||||
@@ -398,14 +415,16 @@ const RightObjectTools: React.FC<RightObjectToolsComponentProps> = (props) => {
|
|||||||
[activeImage]
|
[activeImage]
|
||||||
)
|
)
|
||||||
|
|
||||||
const activeImageOperations = labelState.get(activeImage) || []
|
const activeImageOperations = (labelState.get(activeImage) || []).filter(
|
||||||
|
(operationId) => getOperationChildren(activeImage, operationId).length
|
||||||
|
)
|
||||||
|
|
||||||
const isObjectHidden = (imageId: string, objectId: number) => {
|
const isObjectHidden = (imageId: string, objectId: number) => {
|
||||||
return pathStatus[imageId + objectId]?.["HIDE"] ?? false
|
return pathStatus[imageId + objectId]?.["HIDE"] ?? false
|
||||||
}
|
}
|
||||||
|
|
||||||
const isOperationHidden = (imageId: string, operationId: string) => {
|
const isOperationHidden = (imageId: string, operationId: string) => {
|
||||||
const operationChildren = storeLabel.get(imageId)?.get(operationId) || []
|
const operationChildren = getOperationChildren(imageId, operationId)
|
||||||
return (
|
return (
|
||||||
operationChildren.length > 0 &&
|
operationChildren.length > 0 &&
|
||||||
operationChildren.every(([objectId]) => isObjectHidden(imageId, objectId))
|
operationChildren.every(([objectId]) => isObjectHidden(imageId, objectId))
|
||||||
@@ -414,9 +433,7 @@ const RightObjectTools: React.FC<RightObjectToolsComponentProps> = (props) => {
|
|||||||
|
|
||||||
const totalObjectCount = activeImageOperations.reduce(
|
const totalObjectCount = activeImageOperations.reduce(
|
||||||
(count, operationId) => {
|
(count, operationId) => {
|
||||||
return (
|
return count + getOperationChildren(activeImage, operationId).length
|
||||||
count + (storeLabel.get(activeImage)?.get(operationId)?.length || 0)
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
0
|
0
|
||||||
)
|
)
|
||||||
@@ -424,8 +441,7 @@ const RightObjectTools: React.FC<RightObjectToolsComponentProps> = (props) => {
|
|||||||
const areAllObjectsHidden =
|
const areAllObjectsHidden =
|
||||||
totalObjectCount > 0 &&
|
totalObjectCount > 0 &&
|
||||||
activeImageOperations.every((operationId) => {
|
activeImageOperations.every((operationId) => {
|
||||||
const operationChildren =
|
const operationChildren = getOperationChildren(activeImage, operationId)
|
||||||
storeLabel.get(activeImage)?.get(operationId) || []
|
|
||||||
return operationChildren.every(([objectId]) =>
|
return operationChildren.every(([objectId]) =>
|
||||||
isObjectHidden(activeImage, objectId)
|
isObjectHidden(activeImage, objectId)
|
||||||
)
|
)
|
||||||
@@ -451,6 +467,9 @@ const RightObjectTools: React.FC<RightObjectToolsComponentProps> = (props) => {
|
|||||||
.get(activeImage)
|
.get(activeImage)
|
||||||
?.get(operationId)
|
?.get(operationId)
|
||||||
?.some((child) => {
|
?.some((child) => {
|
||||||
|
if (continueObjectId !== null && child[0] === continueObjectId) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return getSubAttrStatus(
|
return getSubAttrStatus(
|
||||||
getOperationSchema(operationId),
|
getOperationSchema(operationId),
|
||||||
child[2]?.sub_attributes
|
child[2]?.sub_attributes
|
||||||
@@ -458,7 +477,7 @@ const RightObjectTools: React.FC<RightObjectToolsComponentProps> = (props) => {
|
|||||||
})
|
})
|
||||||
return bool
|
return bool
|
||||||
},
|
},
|
||||||
[activeImage, getOperationSchema, storeLabel]
|
[activeImage, continueObjectId, getOperationSchema, storeLabel]
|
||||||
)
|
)
|
||||||
|
|
||||||
// 搜索标注对象id
|
// 搜索标注对象id
|
||||||
@@ -468,7 +487,8 @@ const RightObjectTools: React.FC<RightObjectToolsComponentProps> = (props) => {
|
|||||||
const id = Number(searchId)
|
const id = Number(searchId)
|
||||||
const labelObjMap = storeLabel.get(activeImage)
|
const labelObjMap = storeLabel.get(activeImage)
|
||||||
Array.from(labelObjMap!.entries()).forEach(([operationId, objList]) => {
|
Array.from(labelObjMap!.entries()).forEach(([operationId, objList]) => {
|
||||||
objList.forEach((obj) => {
|
false && objList
|
||||||
|
getOperationChildren(activeImage, operationId).forEach((obj) => {
|
||||||
if (id === obj[0]) {
|
if (id === obj[0]) {
|
||||||
handleSelect(id, operationId)
|
handleSelect(id, operationId)
|
||||||
}
|
}
|
||||||
@@ -483,7 +503,7 @@ const RightObjectTools: React.FC<RightObjectToolsComponentProps> = (props) => {
|
|||||||
if (e.key === "Enter") {
|
if (e.key === "Enter") {
|
||||||
Array.from(storeLabel.entries()).forEach(([imgId, objectMap]) => {
|
Array.from(storeLabel.entries()).forEach(([imgId, objectMap]) => {
|
||||||
if (objectMap.get(currentOperationId)) {
|
if (objectMap.get(currentOperationId)) {
|
||||||
const list = objectMap.get(currentOperationId)
|
const list = getOperationChildren(imgId, currentOperationId)
|
||||||
list!.forEach((item) => {
|
list!.forEach((item) => {
|
||||||
const { sub_attributes } = item[2]
|
const { sub_attributes } = item[2]
|
||||||
// 如果没有子属性搜索值,则把对象HIDE设为false
|
// 如果没有子属性搜索值,则把对象HIDE设为false
|
||||||
@@ -616,8 +636,10 @@ const RightObjectTools: React.FC<RightObjectToolsComponentProps> = (props) => {
|
|||||||
const isHide = isOperationHidden(activeImage, operationId)
|
const isHide = isOperationHidden(activeImage, operationId)
|
||||||
const hasSubAttrError = getOperationSubAttrStatus(operationId)
|
const hasSubAttrError = getOperationSubAttrStatus(operationId)
|
||||||
const operationLabel = operationSchema?.label_class
|
const operationLabel = operationSchema?.label_class
|
||||||
const operationChildren =
|
const operationChildren = getOperationChildren(
|
||||||
storeLabel.get(activeImage)?.get(operationId) || []
|
activeImage,
|
||||||
|
operationId
|
||||||
|
)
|
||||||
const objectCount = operationChildren.length
|
const objectCount = operationChildren.length
|
||||||
const visibleChildren = operationChildren.filter((child) => {
|
const visibleChildren = operationChildren.filter((child) => {
|
||||||
const { comment } = child[2]
|
const { comment } = child[2]
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import { persist, PersistStorage, StorageValue } from "zustand/middleware"
|
|||||||
import { Comment } from "./api/label/typing"
|
import { Comment } from "./api/label/typing"
|
||||||
import { safeClone } from "./utils/clone"
|
import { safeClone } from "./utils/clone"
|
||||||
|
|
||||||
type LabelData = Map<string, Map<string, [number, any[], any, any[]][]>>
|
export type LabelData = Map<string, Map<string, [number, any[], any, any[]][]>>
|
||||||
type LabelPathTuple = [number, any[], any, any[]]
|
export type LabelPathTuple = [number, any[], any, any[]]
|
||||||
type LabelTime = {
|
type LabelTime = {
|
||||||
label: number
|
label: number
|
||||||
review1: number
|
review1: number
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { Comment } from "./api/label/typing"
|
|||||||
import { Project } from "./api/project/typing"
|
import { Project } from "./api/project/typing"
|
||||||
import {
|
import {
|
||||||
initialDetail,
|
initialDetail,
|
||||||
|
type LabelPathTuple,
|
||||||
useKeyEventStore,
|
useKeyEventStore,
|
||||||
useLabelStore,
|
useLabelStore,
|
||||||
useObjectStore,
|
useObjectStore,
|
||||||
@@ -180,6 +181,7 @@ interface PaperState {
|
|||||||
getItemById: (id: number) => paper.Path | null
|
getItemById: (id: number) => paper.Path | null
|
||||||
getItemsById: (id: number) => Array<paper.Path | paper.CompoundPath>
|
getItemsById: (id: number) => Array<paper.Path | paper.CompoundPath>
|
||||||
setContinuePolygonTarget: (target: ContinuePolygonTarget | null) => void
|
setContinuePolygonTarget: (target: ContinuePolygonTarget | null) => void
|
||||||
|
beginContinuePolygonDraft: () => boolean
|
||||||
setLoadingData: (flag: boolean) => void
|
setLoadingData: (flag: boolean) => void
|
||||||
resizeGhostRequestToken: number
|
resizeGhostRequestToken: number
|
||||||
requestResizeGhost: () => void
|
requestResizeGhost: () => void
|
||||||
@@ -844,6 +846,7 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
continuePolygonTarget: null,
|
continuePolygonTarget: null,
|
||||||
currentMousePosition: [0, 0],
|
currentMousePosition: [0, 0],
|
||||||
loadingData: false,
|
loadingData: false,
|
||||||
|
beginContinuePolygonDraft: () => false,
|
||||||
init: (
|
init: (
|
||||||
initEl: HTMLCanvasElement,
|
initEl: HTMLCanvasElement,
|
||||||
initScope: paper.PaperScope,
|
initScope: paper.PaperScope,
|
||||||
@@ -3158,6 +3161,11 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
let continueSourceItems: Array<paper.Path | paper.CompoundPath> = []
|
let continueSourceItems: Array<paper.Path | paper.CompoundPath> = []
|
||||||
let continueTargetContourIndex: number | null = null
|
let continueTargetContourIndex: number | null = null
|
||||||
let continueTargetContext: ContinuePolygonTarget | null = null
|
let continueTargetContext: ContinuePolygonTarget | null = null
|
||||||
|
let continueTargetSnapshot: LabelPathTuple | null = null
|
||||||
|
let continueDraftHints = new Map<
|
||||||
|
string,
|
||||||
|
{ contourIndex: number; points: paper.Point[] }
|
||||||
|
>()
|
||||||
|
|
||||||
const handleCircles = (path: paper.Path | paper.CompoundPath | null) => {
|
const handleCircles = (path: paper.Path | paper.CompoundPath | null) => {
|
||||||
// 更新选中的点
|
// 更新选中的点
|
||||||
@@ -3243,6 +3251,146 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getContinueCandidatePaths = (objectId: number) => {
|
||||||
|
const flattenedPaths: paper.Path[] = []
|
||||||
|
const visitedPaths = new Set<paper.Path>()
|
||||||
|
|
||||||
|
usePaperStore
|
||||||
|
.getState()
|
||||||
|
.getItemsById(objectId)
|
||||||
|
.filter((item) => item.data?.type === "polygon")
|
||||||
|
.forEach((item) => {
|
||||||
|
if (item instanceof paper.CompoundPath) {
|
||||||
|
;(item.children as paper.Path[]).forEach((child) => {
|
||||||
|
if (visitedPaths.has(child)) return
|
||||||
|
visitedPaths.add(child)
|
||||||
|
flattenedPaths.push(child)
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (item instanceof paper.Path && !visitedPaths.has(item)) {
|
||||||
|
visitedPaths.add(item)
|
||||||
|
flattenedPaths.push(item)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const candidatePaths = flattenedPaths.filter(
|
||||||
|
(path) => path.segments?.length > 3
|
||||||
|
)
|
||||||
|
if (!candidatePaths.length) return [] as paper.Path[]
|
||||||
|
|
||||||
|
const preferredPaths = candidatePaths.filter(
|
||||||
|
(path) => !path.data?.isHollowPolygon
|
||||||
|
)
|
||||||
|
return preferredPaths.length ? preferredPaths : candidatePaths
|
||||||
|
}
|
||||||
|
|
||||||
|
const clonePaperPoints = (pathPoints: paper.Point[]) => {
|
||||||
|
return pathPoints.map((point) => new paper.Point(point))
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeDuplicatedClosingPoint = (pathPoints: paper.Point[]) => {
|
||||||
|
if (pathPoints.length <= 1) return pathPoints
|
||||||
|
const firstPoint = pathPoints[0]
|
||||||
|
const lastPoint = pathPoints[pathPoints.length - 1]
|
||||||
|
if (
|
||||||
|
Math.abs(firstPoint.x - lastPoint.x) < 0.000001 &&
|
||||||
|
Math.abs(firstPoint.y - lastPoint.y) < 0.000001
|
||||||
|
) {
|
||||||
|
pathPoints.pop()
|
||||||
|
}
|
||||||
|
return pathPoints
|
||||||
|
}
|
||||||
|
|
||||||
|
const getContinueContourPoints = (segments: any[] | undefined) => {
|
||||||
|
return removeDuplicatedClosingPoint(
|
||||||
|
(segments || [])
|
||||||
|
.map((segment) => getPointFromSegment(segment))
|
||||||
|
.filter((point): point is paper.Point => point !== null)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const getContinueDraftHintKey = (target: ContinuePolygonTarget) => {
|
||||||
|
return `${target.imageId}::${target.operationId}::${target.objectId}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizeComparableContour = (pathPoints: paper.Point[]) => {
|
||||||
|
return removeDuplicatedClosingPoint(clonePaperPoints(pathPoints)).map(
|
||||||
|
(point) => [point.x, point.y] as [number, number]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSameComparablePoint = (
|
||||||
|
pointA: [number, number],
|
||||||
|
pointB: [number, number]
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
Math.abs(pointA[0] - pointB[0]) < 0.000001 &&
|
||||||
|
Math.abs(pointA[1] - pointB[1]) < 0.000001
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSameContourOrder = (
|
||||||
|
contourA: [number, number][],
|
||||||
|
contourB: [number, number][]
|
||||||
|
) => {
|
||||||
|
if (contourA.length !== contourB.length) return false
|
||||||
|
if (!contourA.length) return false
|
||||||
|
for (let offset = 0; offset < contourB.length; offset += 1) {
|
||||||
|
let matched = true
|
||||||
|
for (let index = 0; index < contourA.length; index += 1) {
|
||||||
|
if (
|
||||||
|
!isSameComparablePoint(
|
||||||
|
contourA[index],
|
||||||
|
contourB[(index + offset) % contourB.length]
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
matched = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (matched) return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSameContour = (pathA: paper.Point[], pathB: paper.Point[]) => {
|
||||||
|
const contourA = normalizeComparableContour(pathA)
|
||||||
|
const contourB = normalizeComparableContour(pathB)
|
||||||
|
if (contourA.length !== contourB.length || !contourA.length) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
isSameContourOrder(contourA, contourB) ||
|
||||||
|
isSameContourOrder(contourA, [...contourB].reverse())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const findMatchingContinueContourIndex = (
|
||||||
|
candidatePoints: paper.Point[],
|
||||||
|
contours: any[]
|
||||||
|
) => {
|
||||||
|
for (let index = contours.length - 1; index >= 0; index -= 1) {
|
||||||
|
const contourPoints = getContinueContourPoints(contours[index])
|
||||||
|
if (isSameContour(candidatePoints, contourPoints)) {
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
const setContinueDraftHint = (
|
||||||
|
target: ContinuePolygonTarget,
|
||||||
|
contourIndex: number,
|
||||||
|
contourPoints: paper.Point[]
|
||||||
|
) => {
|
||||||
|
if (contourIndex < 0 || !contourPoints.length) return
|
||||||
|
continueDraftHints.set(getContinueDraftHintKey(target), {
|
||||||
|
contourIndex,
|
||||||
|
points: removeDuplicatedClosingPoint(clonePaperPoints(contourPoints)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const clearContinueSourceItems = (restoreVisible: boolean) => {
|
const clearContinueSourceItems = (restoreVisible: boolean) => {
|
||||||
continueSourceItems.forEach((item) => {
|
continueSourceItems.forEach((item) => {
|
||||||
if (restoreVisible) {
|
if (restoreVisible) {
|
||||||
@@ -3258,18 +3406,26 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
clearContinueSourceItems(restoreVisible)
|
clearContinueSourceItems(restoreVisible)
|
||||||
continueTargetContourIndex = null
|
continueTargetContourIndex = null
|
||||||
continueTargetContext = null
|
continueTargetContext = null
|
||||||
|
continueTargetSnapshot = null
|
||||||
usePaperStore.getState().setContinuePolygonTarget(null)
|
usePaperStore.getState().setContinuePolygonTarget(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasContinuePolygonDraft = () => {
|
||||||
|
return !!(
|
||||||
|
continueTargetContext ||
|
||||||
|
continueTargetSnapshot ||
|
||||||
|
usePaperStore.getState().continuePolygonTarget
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const startContinuePolygonDraft = () => {
|
const startContinuePolygonDraft = () => {
|
||||||
const target = usePaperStore.getState().continuePolygonTarget
|
const target = usePaperStore.getState().continuePolygonTarget
|
||||||
if (!target) return false
|
if (!target) return false
|
||||||
|
|
||||||
const imageLabel = useLabelStore.getState().label.get(target.imageId)
|
const imageLabel = useLabelStore.getState().label.get(target.imageId)
|
||||||
const operationPaths = imageLabel?.get(target.operationId) || []
|
const operationPaths = imageLabel?.get(target.operationId) || []
|
||||||
const targetTuple = operationPaths.find(
|
const targetTuple =
|
||||||
(path) => path[0] === target.objectId
|
operationPaths.find((path) => path[0] === target.objectId) || null
|
||||||
)
|
|
||||||
if (!targetTuple) {
|
if (!targetTuple) {
|
||||||
notifications.show({
|
notifications.show({
|
||||||
color: "yellow",
|
color: "yellow",
|
||||||
@@ -3280,14 +3436,71 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const nextPoints = safeClone(targetTuple[1] || [])
|
const nextPoints = safeClone(targetTuple[1] || [])
|
||||||
|
const continuePaths = getContinueCandidatePaths(target.objectId)
|
||||||
|
const continuePath = continuePaths[continuePaths.length - 1]
|
||||||
|
const continuePathPoints = continuePath?.segments?.length
|
||||||
|
? removeDuplicatedClosingPoint(
|
||||||
|
continuePath.segments.map(
|
||||||
|
(segment) => new paper.Point(segment.point)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
: []
|
||||||
|
const continueHint = continueDraftHints.get(
|
||||||
|
getContinueDraftHintKey(target)
|
||||||
|
)
|
||||||
|
|
||||||
let contourIndex = -1
|
let contourIndex = -1
|
||||||
for (let i = nextPoints.length - 1; i >= 0; i -= 1) {
|
if (
|
||||||
if (nextPoints[i]?.length > 3) {
|
continueHint &&
|
||||||
|
continueHint.contourIndex >= 0 &&
|
||||||
|
continueHint.contourIndex < nextPoints.length
|
||||||
|
) {
|
||||||
|
contourIndex = continueHint.contourIndex
|
||||||
|
} else if (continuePathPoints.length) {
|
||||||
|
contourIndex = findMatchingContinueContourIndex(
|
||||||
|
continuePathPoints,
|
||||||
|
nextPoints
|
||||||
|
)
|
||||||
|
}
|
||||||
|
for (
|
||||||
|
let i = nextPoints.length - 1;
|
||||||
|
contourIndex === -1 && i >= 0;
|
||||||
|
i -= 1
|
||||||
|
) {
|
||||||
|
if (nextPoints[i]?.length > 2) {
|
||||||
contourIndex = i
|
contourIndex = i
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (contourIndex === -1) {
|
if (contourIndex === -1 && nextPoints.length) {
|
||||||
|
contourIndex = nextPoints.length - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
let sourceContourPoints = continueHint?.points?.length
|
||||||
|
? clonePaperPoints(continueHint.points)
|
||||||
|
: []
|
||||||
|
|
||||||
|
if (
|
||||||
|
sourceContourPoints.length &&
|
||||||
|
continuePathPoints.length &&
|
||||||
|
!isSameContour(sourceContourPoints, continuePathPoints)
|
||||||
|
) {
|
||||||
|
sourceContourPoints = []
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sourceContourPoints.length && continuePathPoints.length) {
|
||||||
|
sourceContourPoints = clonePaperPoints(continuePathPoints)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sourceContourPoints.length && contourIndex >= 0) {
|
||||||
|
sourceContourPoints = getContinueContourPoints(nextPoints[contourIndex])
|
||||||
|
}
|
||||||
|
|
||||||
|
const contourPoints = sourceContourPoints
|
||||||
|
.slice(0, -1)
|
||||||
|
.map((point) => new paper.Point(point))
|
||||||
|
|
||||||
|
if (!sourceContourPoints.length) {
|
||||||
notifications.show({
|
notifications.show({
|
||||||
color: "yellow",
|
color: "yellow",
|
||||||
message: "当前对象没有可继续标注的区域",
|
message: "当前对象没有可继续标注的区域",
|
||||||
@@ -3296,17 +3509,10 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const contourSegments = safeClone(nextPoints[contourIndex] || [])
|
if (contourPoints.length < 2) {
|
||||||
const continueSegments = contourSegments.slice().reverse()
|
|
||||||
continueSegments.pop()
|
|
||||||
const contourPoints = continueSegments
|
|
||||||
.map((segment: any) => getPointFromSegment(segment))
|
|
||||||
.filter((point: paper.Point | null): point is paper.Point => !!point)
|
|
||||||
|
|
||||||
if (contourPoints.length < 3) {
|
|
||||||
notifications.show({
|
notifications.show({
|
||||||
color: "yellow",
|
color: "yellow",
|
||||||
message: "当前区域至少保留3个节点,无法继续撤回",
|
message: "当前区域至少保留2个节点,无法继续撤回",
|
||||||
})
|
})
|
||||||
clearContinuePolygonContext(true)
|
clearContinuePolygonContext(true)
|
||||||
return false
|
return false
|
||||||
@@ -3321,8 +3527,19 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
item.visible = false
|
item.visible = false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
useOtherToolsStore.getState().setShowContextMenu({
|
||||||
|
showContextMenu: false,
|
||||||
|
position: { top: 0, left: 0 },
|
||||||
|
imageId: target.imageId,
|
||||||
|
operationId: target.operationId,
|
||||||
|
id: target.objectId,
|
||||||
|
})
|
||||||
|
usePaperSupportStore.getState().clearAll()
|
||||||
|
useObjectStore.getState().updateSelectedPath(target.imageId, "ADD")
|
||||||
|
|
||||||
continueTargetContourIndex = contourIndex
|
continueTargetContourIndex = contourIndex
|
||||||
continueTargetContext = target
|
continueTargetContext = target
|
||||||
|
continueTargetSnapshot = safeClone(targetTuple) as LabelPathTuple
|
||||||
points = contourPoints
|
points = contourPoints
|
||||||
draftId = target.objectId
|
draftId = target.objectId
|
||||||
polygon?.remove()
|
polygon?.remove()
|
||||||
@@ -3351,14 +3568,8 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
const saveContinuePolygonDraft = (draftPath: paper.Path) => {
|
const saveContinuePolygonDraft = (draftPath: paper.Path) => {
|
||||||
const target =
|
const target =
|
||||||
continueTargetContext || usePaperStore.getState().continuePolygonTarget
|
continueTargetContext || usePaperStore.getState().continuePolygonTarget
|
||||||
if (!target) return false
|
const targetTuple = continueTargetSnapshot
|
||||||
|
if (!target || !targetTuple) return false
|
||||||
const imageLabel = useLabelStore.getState().label.get(target.imageId)
|
|
||||||
const operationPaths = imageLabel?.get(target.operationId) || []
|
|
||||||
const targetTuple = operationPaths.find(
|
|
||||||
(path) => path[0] === target.objectId
|
|
||||||
)
|
|
||||||
if (!targetTuple) return false
|
|
||||||
|
|
||||||
const pathData = JSON.parse(draftPath.exportJSON({ precision: 20 }))
|
const pathData = JSON.parse(draftPath.exportJSON({ precision: 20 }))
|
||||||
const nextContour = pathData?.[1]?.segments
|
const nextContour = pathData?.[1]?.segments
|
||||||
@@ -3382,6 +3593,7 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
safeClone(targetTuple[2] || initialDetail),
|
safeClone(targetTuple[2] || initialDetail),
|
||||||
safeClone(targetTuple[3] || []),
|
safeClone(targetTuple[3] || []),
|
||||||
])
|
])
|
||||||
|
setContinueDraftHint(target, contourIndex, clonePaperPoints(points))
|
||||||
useObjectStore
|
useObjectStore
|
||||||
.getState()
|
.getState()
|
||||||
.updateSelectedPath(target.imageId, "ADD", target.objectId)
|
.updateSelectedPath(target.imageId, "ADD", target.objectId)
|
||||||
@@ -3673,6 +3885,7 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
|
|
||||||
const points: any[] = []
|
const points: any[] = []
|
||||||
const hollowPoints: any[] = []
|
const hollowPoints: any[] = []
|
||||||
|
let lastOuterContourPoints: paper.Point[] = []
|
||||||
const nextPaths =
|
const nextPaths =
|
||||||
nextPolygon instanceof paper.CompoundPath
|
nextPolygon instanceof paper.CompoundPath
|
||||||
? (nextPolygon.children as paper.Path[])
|
? (nextPolygon.children as paper.Path[])
|
||||||
@@ -3700,6 +3913,7 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
hollowPoints.push(segments)
|
hollowPoints.push(segments)
|
||||||
} else {
|
} else {
|
||||||
points.push(segments)
|
points.push(segments)
|
||||||
|
lastOuterContourPoints = getContinueContourPoints(segments)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -3728,6 +3942,15 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
prevDetail,
|
prevDetail,
|
||||||
hollowPoints,
|
hollowPoints,
|
||||||
])
|
])
|
||||||
|
setContinueDraftHint(
|
||||||
|
{
|
||||||
|
imageId: activeImage,
|
||||||
|
operationId,
|
||||||
|
objectId: selectedId,
|
||||||
|
},
|
||||||
|
points.length - 1,
|
||||||
|
lastOuterContourPoints
|
||||||
|
)
|
||||||
useObjectStore
|
useObjectStore
|
||||||
.getState()
|
.getState()
|
||||||
.updateSelectedPath(activeImage, "ADD", selectedId)
|
.updateSelectedPath(activeImage, "ADD", selectedId)
|
||||||
@@ -3797,6 +4020,7 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
|
|
||||||
const points: any[] = []
|
const points: any[] = []
|
||||||
const hollowPoints: any[] = []
|
const hollowPoints: any[] = []
|
||||||
|
let lastOuterContourPoints: paper.Point[] = []
|
||||||
const nextPaths =
|
const nextPaths =
|
||||||
nextPolygon instanceof paper.CompoundPath
|
nextPolygon instanceof paper.CompoundPath
|
||||||
? (nextPolygon.children as paper.Path[])
|
? (nextPolygon.children as paper.Path[])
|
||||||
@@ -3824,6 +4048,7 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
hollowPoints.push(segments)
|
hollowPoints.push(segments)
|
||||||
} else {
|
} else {
|
||||||
points.push(segments)
|
points.push(segments)
|
||||||
|
lastOuterContourPoints = getContinueContourPoints(segments)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -3852,6 +4077,15 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
prevDetail,
|
prevDetail,
|
||||||
hollowPoints,
|
hollowPoints,
|
||||||
])
|
])
|
||||||
|
setContinueDraftHint(
|
||||||
|
{
|
||||||
|
imageId: activeImage,
|
||||||
|
operationId,
|
||||||
|
objectId: selectedId,
|
||||||
|
},
|
||||||
|
points.length - 1,
|
||||||
|
lastOuterContourPoints
|
||||||
|
)
|
||||||
useObjectStore
|
useObjectStore
|
||||||
.getState()
|
.getState()
|
||||||
.updateSelectedPath(activeImage, "ADD", selectedId)
|
.updateSelectedPath(activeImage, "ADD", selectedId)
|
||||||
@@ -3874,6 +4108,9 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
if (polygon || points.length) {
|
if (polygon || points.length) {
|
||||||
hidePaperContextMenu()
|
hidePaperContextMenu()
|
||||||
undoPolygonPoint()
|
undoPolygonPoint()
|
||||||
|
if (!points.length && hasContinuePolygonDraft()) {
|
||||||
|
clearContinuePolygonContext(true)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!trySelectPaperObjectByPoint(e.point)) {
|
if (!trySelectPaperObjectByPoint(e.point)) {
|
||||||
@@ -3889,11 +4126,7 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
usePaperSupportStore.getState().clearAll()
|
usePaperSupportStore.getState().clearAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!polygon && !points.length && hasContinuePolygonDraft()) {
|
||||||
!polygon &&
|
|
||||||
!points.length &&
|
|
||||||
usePaperStore.getState().continuePolygonTarget
|
|
||||||
) {
|
|
||||||
if (!startContinuePolygonDraft()) return
|
if (!startContinuePolygonDraft()) return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3917,7 +4150,7 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
// 初始化 compoundPolygon
|
// 初始化 compoundPolygon
|
||||||
compoundPolygon = new paper.Path()
|
compoundPolygon = new paper.Path()
|
||||||
|
|
||||||
if (usePaperStore.getState().continuePolygonTarget) {
|
if (hasContinuePolygonDraft()) {
|
||||||
;(polygon as paper.Path).closePath()
|
;(polygon as paper.Path).closePath()
|
||||||
const continueSaved = saveContinuePolygonDraft(
|
const continueSaved = saveContinuePolygonDraft(
|
||||||
polygon as paper.Path
|
polygon as paper.Path
|
||||||
@@ -4089,11 +4322,15 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
if (polygon.children && polygon.children.length) {
|
if (polygon.children && polygon.children.length) {
|
||||||
let points: any[] = []
|
let points: any[] = []
|
||||||
let hollowPoints: any[] = []
|
let hollowPoints: any[] = []
|
||||||
|
let lastOuterContourPoints: paper.Point[] = []
|
||||||
;(polygon.children as paper.Path[]).forEach((path) => {
|
;(polygon.children as paper.Path[]).forEach((path) => {
|
||||||
let pathData = JSON.parse(path.exportJSON({ precision: 20 }))
|
let pathData = JSON.parse(path.exportJSON({ precision: 20 }))
|
||||||
// 在镂空或分割的区域中 路径方向是false
|
// 在镂空或分割的区域中 路径方向是false
|
||||||
if (path.clockwise) {
|
if (path.clockwise) {
|
||||||
points.push(pathData[1]?.segments)
|
points.push(pathData[1]?.segments)
|
||||||
|
lastOuterContourPoints = getContinueContourPoints(
|
||||||
|
pathData[1]?.segments
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
hollowPoints.push(pathData[1]?.segments)
|
hollowPoints.push(pathData[1]?.segments)
|
||||||
}
|
}
|
||||||
@@ -4129,6 +4366,17 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
hollowPoints,
|
hollowPoints,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
if (points.length) {
|
||||||
|
setContinueDraftHint(
|
||||||
|
{
|
||||||
|
imageId: useBottomToolsStore.getState().activeImage,
|
||||||
|
operationId: useTopToolsStore.getState().activeOperation,
|
||||||
|
objectId: polygon.data.id,
|
||||||
|
},
|
||||||
|
points.length - 1,
|
||||||
|
lastOuterContourPoints
|
||||||
|
)
|
||||||
|
}
|
||||||
if (!useTopToolsStore.getState().pressA)
|
if (!useTopToolsStore.getState().pressA)
|
||||||
useRightToolsStore.getState().pushPathId(polygon.data.id)
|
useRightToolsStore.getState().pushPathId(polygon.data.id)
|
||||||
}
|
}
|
||||||
@@ -4163,6 +4411,15 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
[],
|
[],
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
setContinueDraftHint(
|
||||||
|
{
|
||||||
|
imageId: useBottomToolsStore.getState().activeImage,
|
||||||
|
operationId: useTopToolsStore.getState().activeOperation,
|
||||||
|
objectId: polygon.data.id,
|
||||||
|
},
|
||||||
|
0,
|
||||||
|
clonePaperPoints(points)
|
||||||
|
)
|
||||||
useRightToolsStore.getState().pushPathId(polygon.data.id)
|
useRightToolsStore.getState().pushPathId(polygon.data.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4393,11 +4650,7 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
}
|
}
|
||||||
polygonTool.onKeyDown = (e: paper.KeyEvent) => {
|
polygonTool.onKeyDown = (e: paper.KeyEvent) => {
|
||||||
if (e.key === "escape" || e.key === "alt") {
|
if (e.key === "escape" || e.key === "alt") {
|
||||||
if (
|
if (polygon || points.length || hasContinuePolygonDraft()) {
|
||||||
polygon ||
|
|
||||||
points.length ||
|
|
||||||
usePaperStore.getState().continuePolygonTarget
|
|
||||||
) {
|
|
||||||
resetPolygonDraft()
|
resetPolygonDraft()
|
||||||
clearContinuePolygonContext(true)
|
clearContinuePolygonContext(true)
|
||||||
usePaperSupportStore.getState().handleBufferPaths(null)
|
usePaperSupportStore.getState().handleBufferPaths(null)
|
||||||
@@ -4417,6 +4670,7 @@ export const usePaperStore = create<PaperState>((set) => ({
|
|||||||
set((state: PaperState) => ({
|
set((state: PaperState) => ({
|
||||||
...state,
|
...state,
|
||||||
polygonTool: polygonTool,
|
polygonTool: polygonTool,
|
||||||
|
beginContinuePolygonDraft: () => startContinuePolygonDraft(),
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
addRectangle: (
|
addRectangle: (
|
||||||
|
|||||||
Reference in New Issue
Block a user