Skip to content

Commit

Permalink
fix(pointcloud-line): Fix write and read lineTool's data on wrong way
Browse files Browse the repository at this point in the history
  • Loading branch information
lijingchi committed May 9, 2023
1 parent bd2c00c commit 4efb5dc
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 56 deletions.
10 changes: 2 additions & 8 deletions packages/lb-annotation/src/core/pointCloud/annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class PointCloudAnnotation implements IPointCloudAnnotationOperation {
} else {
toolList = toolName as EToolName[];
}

toolList.forEach((tool, i) => {
let toolInstance;
if (tool === EToolName.PointCloudPolygon) {
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 2 additions & 11 deletions packages/lb-annotation/src/core/toolOperation/LineToolOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ class LineToolOperation extends BasicToolOperation {
public drawLines = () => {
try {
const lineList = _.cloneDeep(this.attributeFilteredLines);

if (this.isHidden) {
return;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,6 +85,7 @@ export const PointCloudContext = React.createContext<IPointCloudContext>({
pointCloudSphereList: [],
displayPointCloudList: [],
displaySphereList: [],
displayLineList: [],
polygonList: [],
lineList: [],
selectedID: '',
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -270,6 +276,7 @@ export const PointCloudProvider: React.FC<{}> = ({ children }) => {
pointCloudSphereList,
displayPointCloudList,
displaySphereList,
displayLineList,
selectedIDs,
setPointCloudResult,
setSelectedIDs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -173,7 +172,6 @@ const PointCloudTopView: React.FC<IProps> = ({
const { hideAttributes } = ptCtx;

const { addPolygon, deletePolygon } = usePolygon();
const { addLine, deleteLine } = useLine();
const { deletePointCloudSphere } = useSphere();
const { deletePointCloudBox, changeValidByID } = useSingleBox();
const [zAxisLimit, setZAxisLimit] = useState<number>(10);
Expand Down Expand Up @@ -211,28 +209,11 @@ const PointCloudTopView: React.FC<IProps> = ({
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)
Expand Down Expand Up @@ -349,6 +330,7 @@ const PointCloudTopView: React.FC<IProps> = ({
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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useHistory = () => {
newBoxParams?: IPointCloudBox;
newPolygon?: IPolygonData;
newLine?: ILine;
newSphereParams?: IPointCloudSphere,
newSphereParams?: IPointCloudSphere;
}) => {
const historyRecord = {
pointCloudBoxList,
Expand All @@ -56,7 +56,7 @@ export const useHistory = () => {
}

if (newSphereParams) {
historyRecord.pointCloudSphereList = pointCloudSphereList.concat(newSphereParams)
historyRecord.pointCloudSphereList = pointCloudSphereList.concat(newSphereParams);
}

history.pushHistory(historyRecord);
Expand Down Expand Up @@ -90,7 +90,7 @@ export const useHistory = () => {
}

if (params.pointCloudSphereList) {
historyRecord.pointCloudSphereList = params.pointCloudSphereList
historyRecord.pointCloudSphereList = params.pointCloudSphereList;
}

history.pushHistory(historyRecord);
Expand Down Expand Up @@ -193,16 +193,20 @@ 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);
});

addPointCloudList.forEach((v) => {
mainViewInstance?.generateSphere(v);
});
setPointCloudSphereList(newPointCloudSphereList)
setPointCloudSphereList(newPointCloudSphereList);
}

if (newPolygonList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 4efb5dc

Please sign in to comment.