From 4efb5dc792ea8933e753ab77396c7fc7ca3b9cd5 Mon Sep 17 00:00:00 2001 From: lijingchi Date: Mon, 8 May 2023 21:06:00 +0800 Subject: [PATCH] fix(pointcloud-line): Fix write and read lineTool's data on wrong way --- .../src/core/pointCloud/annotation.ts | 10 ++----- .../core/toolOperation/LineToolOperation.ts | 13 ++-------- .../toolOperation/pointCloud2dOperation.ts | 2 +- .../pointCloudView/PointCloudContext.tsx | 9 ++++++- .../pointCloudView/PointCloudTopView.tsx | 26 +++---------------- .../pointCloudView/hooks/useHistory.ts | 16 +++++++----- .../hooks/usePointCloudViews.ts | 14 +++++----- 7 files changed, 34 insertions(+), 56 deletions(-) diff --git a/packages/lb-annotation/src/core/pointCloud/annotation.ts b/packages/lb-annotation/src/core/pointCloud/annotation.ts index 12eaa720b..b42a46f2c 100644 --- a/packages/lb-annotation/src/core/pointCloud/annotation.ts +++ b/packages/lb-annotation/src/core/pointCloud/annotation.ts @@ -101,6 +101,7 @@ export class PointCloudAnnotation implements IPointCloudAnnotationOperation { } else { toolList = toolName as EToolName[]; } + toolList.forEach((tool, i) => { let toolInstance; if (tool === EToolName.PointCloudPolygon) { @@ -198,14 +199,7 @@ export class PointCloudAnnotation implements IPointCloudAnnotationOperation { } public updateLineList = (lineList: ILine[]) => { - const list = lineList.map((v: ILine) => ({ - ...v, - pointList: v?.pointList?.map((point: IPoint) => - PointCloudUtils.transferWorld2Canvas(point, this.toolInstance.size), - ), - })); - - this.toolScheduler.updateDataByToolName(EToolName.Line, list); + this.toolScheduler.updateDataByToolName(EToolName.Line, lineList ?? []); }; public addLineListOnTopView(result: string) { diff --git a/packages/lb-annotation/src/core/toolOperation/LineToolOperation.ts b/packages/lb-annotation/src/core/toolOperation/LineToolOperation.ts index 71b757995..0b7348efa 100644 --- a/packages/lb-annotation/src/core/toolOperation/LineToolOperation.ts +++ b/packages/lb-annotation/src/core/toolOperation/LineToolOperation.ts @@ -681,7 +681,6 @@ class LineToolOperation extends BasicToolOperation { public drawLines = () => { try { const lineList = _.cloneDeep(this.attributeFilteredLines); - if (this.isHidden) { return; } @@ -1459,14 +1458,6 @@ class LineToolOperation extends BasicToolOperation { reset(); return; } - // /** 非创建状态,记录当前被修改的线条 */ - // if (this.isMousedown && !this.isCreate) { - // const lineChanged = this.lineHasChanged(); - // if (lineChanged) { - // this.updateLines(); - // this.history?.pushHistory(this.lineList); - // } - // } if (e.which === 1) { this.onLeftClick(e); @@ -1518,7 +1509,7 @@ class LineToolOperation extends BasicToolOperation { const newLine = this.createLineData(); selectedID = newLine.id; this.setLineList([...this.lineList, newLine]); - this.emit('lineCreated', newLine, this.zoom, this.currentPos); + // this.emit('lineCreated', newLine, this.zoom, this.currentPos); this.history?.pushHistory(this.lineList); } } @@ -1530,7 +1521,7 @@ class LineToolOperation extends BasicToolOperation { } this.actionsHistory?.empty(); - this.emit('dataUpdated', this.lineList); + this.emit('dataUpdated', this.lineList, this.selectedIDs); this.render(); } diff --git a/packages/lb-annotation/src/core/toolOperation/pointCloud2dOperation.ts b/packages/lb-annotation/src/core/toolOperation/pointCloud2dOperation.ts index e2a6276ee..4ac23f093 100644 --- a/packages/lb-annotation/src/core/toolOperation/pointCloud2dOperation.ts +++ b/packages/lb-annotation/src/core/toolOperation/pointCloud2dOperation.ts @@ -7,6 +7,7 @@ */ import { IPointCloudConfig, toolStyleConverter, UpdatePolygonByDragList, INVALID_COLOR } from '@labelbee/lb-utils'; +import _ from 'lodash'; import { EDragTarget, ESortDirection } from '@/constant/annotation'; import { EPolygonPattern } from '@/constant/tool'; import { IPolygonData, IPolygonPoint } from '@/types/tool/polygon'; @@ -15,7 +16,6 @@ import CommonToolUtils from '@/utils/tool/CommonToolUtils'; import DrawUtils from '@/utils/tool/DrawUtils'; import PolygonUtils from '@/utils/tool/PolygonUtils'; import { polygonConfig } from '@/constant/defaultConfig'; -import _ from 'lodash'; import PolygonOperation, { IPolygonOperationProps } from './polygonOperation'; import { BasicToolOperation } from './basicToolOperation'; diff --git a/packages/lb-components/src/components/pointCloudView/PointCloudContext.tsx b/packages/lb-components/src/components/pointCloudView/PointCloudContext.tsx index 0dd2d1131..dc84a7d04 100644 --- a/packages/lb-components/src/components/pointCloudView/PointCloudContext.tsx +++ b/packages/lb-components/src/components/pointCloudView/PointCloudContext.tsx @@ -32,6 +32,7 @@ export interface IPointCloudContext extends IPointCloudContextInstances { pointCloudSphereList: IPointCloudSphereList; displayPointCloudList: IPointCloudBoxList; displaySphereList: IPointCloudSphereList; + displayLineList: ILine[]; selectedIDs: string[]; setSelectedIDs: (ids?: string[] | string) => void; valid: boolean; @@ -84,6 +85,7 @@ export const PointCloudContext = React.createContext({ pointCloudSphereList: [], displayPointCloudList: [], displaySphereList: [], + displayLineList: [], polygonList: [], lineList: [], selectedID: '', @@ -213,6 +215,10 @@ export const PointCloudProvider: React.FC<{}> = ({ children }) => { (i) => !hideAttributes.includes(i.attribute), ); + const displayLineList = lineList.filter( + (i) => i.attribute && !hideAttributes.includes(i.attribute), + ); + const toggleAttributesVisible = (tAttribute: string) => { if (hideAttributes.includes(tAttribute)) { setHideAttributes(hideAttributes.filter((attribute) => attribute !== tAttribute)); @@ -226,7 +232,7 @@ export const PointCloudProvider: React.FC<{}> = ({ children }) => { _displayPointCloudList: IPointCloudBoxList = displayPointCloudList, _polygonList: IPolygonData[] = polygonList, _displaySphereList: IPointCloudSphereList = displaySphereList, - _lineList: ILine[] = lineList, + _lineList: ILine[] = displayLineList, ) => { pointCloudBoxList.forEach((v) => { mainViewInstance?.removeObjectByName(v.id); @@ -270,6 +276,7 @@ export const PointCloudProvider: React.FC<{}> = ({ children }) => { pointCloudSphereList, displayPointCloudList, displaySphereList, + displayLineList, selectedIDs, setPointCloudResult, setSelectedIDs, diff --git a/packages/lb-components/src/components/pointCloudView/PointCloudTopView.tsx b/packages/lb-components/src/components/pointCloudView/PointCloudTopView.tsx index 95285c6b5..82f949a08 100644 --- a/packages/lb-components/src/components/pointCloudView/PointCloudTopView.tsx +++ b/packages/lb-components/src/components/pointCloudView/PointCloudTopView.tsx @@ -22,7 +22,6 @@ import { useSingleBox } from './hooks/useSingleBox'; import { PointCloudContainer } from './PointCloudLayout'; import { BoxInfos, PointCloudValidity } from './PointCloudInfos'; import { usePolygon } from './hooks/usePolygon'; -import { useLine } from './hooks/useLine'; import { useSphere } from './hooks/useSphere'; import { useZoom } from './hooks/useZoom'; import { Slider } from 'antd'; @@ -173,7 +172,6 @@ const PointCloudTopView: React.FC = ({ const { hideAttributes } = ptCtx; const { addPolygon, deletePolygon } = usePolygon(); - const { addLine, deleteLine } = useLine(); const { deletePointCloudSphere } = useSphere(); const { deletePointCloudBox, changeValidByID } = useSingleBox(); const [zAxisLimit, setZAxisLimit] = useState(10); @@ -211,28 +209,11 @@ const PointCloudTopView: React.FC = ({ const { toolInstance: TopView2dOperation } = ptCtx.topViewInstance; // line register - TopView2dOperation.singleOn('lineCreated', (line: ILine, zoom: number) => { - const newLine = { - ...line, - pointList: line.pointList!.map((v) => PointCloudUtils.transferCanvas2World(v, size)), - }; - - addLine(newLine); - ptCtx.setSelectedIDs(hideAttributes.includes(line.attribute!) ? '' : line.id); - return; - }); - - TopView2dOperation.singleOn('lineDeleted', (selectedID: string) => { - deletePointCloudBox(selectedID); - deleteLine(selectedID); + TopView2dOperation.singleOn('dataUpdated', (updateLine: ILine[], selectedIDs: string[]) => { + ptCtx.setSelectedIDs(selectedIDs); + ptCtx.setLineList(updateLine); }); - TopView2dOperation.singleOn('lineSelected', (selectedID: string) => { - ptCtx.setSelectedIDs([selectedID]); - }); - TopView2dOperation.singleOn('updateLineByDrag', (updateLine: ILine) => { - pointCloudViews.topViewUpdateLine?.(updateLine, size); - }); // point tool events TopView2dOperation.singleOn('pointCreated', (point: IPointUnit, zoom: number) => { // addPoint(point) @@ -349,6 +330,7 @@ const PointCloudTopView: React.FC = ({ ptCtx.topViewInstance.initSize(size); ptCtx.topViewInstance.updatePolygonList(ptCtx.displayPointCloudList, ptCtx.polygonList); ptCtx.topViewInstance.updatePointList(ptCtx.displaySphereList); + ptCtx.topViewInstance.updateLineList(ptCtx.displayLineList); const { topViewInstance: { pointCloudInstance: pointCloud, toolInstance }, diff --git a/packages/lb-components/src/components/pointCloudView/hooks/useHistory.ts b/packages/lb-components/src/components/pointCloudView/hooks/useHistory.ts index 099fcd877..72404a45b 100644 --- a/packages/lb-components/src/components/pointCloudView/hooks/useHistory.ts +++ b/packages/lb-components/src/components/pointCloudView/hooks/useHistory.ts @@ -35,7 +35,7 @@ export const useHistory = () => { newBoxParams?: IPointCloudBox; newPolygon?: IPolygonData; newLine?: ILine; - newSphereParams?: IPointCloudSphere, + newSphereParams?: IPointCloudSphere; }) => { const historyRecord = { pointCloudBoxList, @@ -56,7 +56,7 @@ export const useHistory = () => { } if (newSphereParams) { - historyRecord.pointCloudSphereList = pointCloudSphereList.concat(newSphereParams) + historyRecord.pointCloudSphereList = pointCloudSphereList.concat(newSphereParams); } history.pushHistory(historyRecord); @@ -90,7 +90,7 @@ export const useHistory = () => { } if (params.pointCloudSphereList) { - historyRecord.pointCloudSphereList = params.pointCloudSphereList + historyRecord.pointCloudSphereList = params.pointCloudSphereList; } history.pushHistory(historyRecord); @@ -193,8 +193,12 @@ export const useHistory = () => { setSelectedIDs(); } - let deletedPointCloudList = pointCloudSphereList.filter((v) => newPointCloudSphereList.every((d) => d.id !== v.id)) - let addPointCloudList = newPointCloudSphereList.filter((v) => pointCloudSphereList.every((d) => d.id !== v.id)) + let deletedPointCloudList = pointCloudSphereList.filter((v) => + newPointCloudSphereList.every((d) => d.id !== v.id), + ); + let addPointCloudList = newPointCloudSphereList.filter((v) => + pointCloudSphereList.every((d) => d.id !== v.id), + ); deletedPointCloudList.forEach((v) => { mainViewInstance?.removeObjectByName(v.id); }); @@ -202,7 +206,7 @@ export const useHistory = () => { addPointCloudList.forEach((v) => { mainViewInstance?.generateSphere(v); }); - setPointCloudSphereList(newPointCloudSphereList) + setPointCloudSphereList(newPointCloudSphereList); } if (newPolygonList) { diff --git a/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts index 3274fdb9e..e402b2836 100644 --- a/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts +++ b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts @@ -605,12 +605,8 @@ export const usePointCloudViews = () => { pointCloudSphereList, hideAttributes, } = ptCtx; - const { - addHistory, - initHistory, - pushHistoryUnderUpdatePolygon, - pushHistoryUnderUpdateLine, - } = useHistory(); + const { addHistory, initHistory, pushHistoryUnderUpdatePolygon, pushHistoryUnderUpdateLine } = + useHistory(); const { selectedPolygon } = usePolygon(); const { updateSelectedBox, updateSelectedBoxes, getPointCloudByID } = useSingleBox(); @@ -1149,7 +1145,11 @@ export const usePointCloudViews = () => { ptCtx.setPointCloudSphereList([]); ptCtx.setLineList([]); } - initHistory({ pointCloudBoxList: boxParamsList, polygonList, pointCloudSphereList: sphereParamsList }); + initHistory({ + pointCloudBoxList: boxParamsList, + polygonList, + pointCloudSphereList: sphereParamsList, + }); mainViewInstance.updateTopCamera();