Skip to content

Commit

Permalink
feat(line tool): 逻辑修改
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry-Diasa committed Apr 17, 2023
1 parent 1ced67a commit 8f0bc46
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 143 deletions.
39 changes: 1 addition & 38 deletions packages/lb-annotation/src/constant/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,7 @@ const rectToolConfig = {
isShowOrder: false,
filterData: ['valid', 'invalid'],
attributeConfigurable: true,
attributeList: [
{
key: '类别1',
value: '类别1',
},
{
key: '类别8f',
value: 'class-8f',
},
{
key: '类别My',
value: 'class-My',
},
{
key: '类别cN',
value: 'class-cN',
},
{
key: '类别4H',
value: 'class-4H',
},
{
key: '类别Au',
value: 'class-Au',
},
{
key: '类别FM',
value: 'class-FM',
},
{
key: '类别Nj',
value: 'class-Nj',
},
{
key: '类别CP',
value: 'class-CP',
},
],
attributeList: [],
textConfigurable: true,
textCheckType: 0,
customFormat: '',
Expand Down
1 change: 0 additions & 1 deletion packages/lb-annotation/src/core/pointCloud/annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export class PointCloudAnnotation implements IPointCloudAnnotationOperation {
}

public updatePolygonList = (pointCloudDataList: IPointCloudBox[], extraList?: IPolygonData[]) => {
console.log('pointCloudDataList', pointCloudDataList);
let pointList;
let polygonList = pointCloudDataList.map((v: IPointCloudBox) => {
// line
Expand Down
10 changes: 6 additions & 4 deletions packages/lb-annotation/src/core/pointCloud/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,12 @@ export function pointCloudLidar2image(
},
) {
if (boxParams.length) {
return boxParams.linePointList?.map((line) => ({
type: 'line',
pointList: [line],
}));
return boxParams.linePointList
?.map((line) => ({
type: 'line',
pointList: [line],
}))
.slice(0, boxParams.linePointList.length - 1);
}
const allViewData = PointCloudUtils.getAllViewData(boxParams);
const { P, R, T } = cameraMatrix;
Expand Down
7 changes: 0 additions & 7 deletions packages/lb-annotation/src/core/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ export class ToolScheduler implements IToolSchedulerOperation {
this.size = props.size;
this.imgNode = props.imgNode;
this.config = props.config ?? JSON.stringify(getConfig(HybridToolUtils.getTopToolName(props.toolName))); // 设置默认操作
console.log(
getConfig(HybridToolUtils.getTopToolName(props.toolName)),
1231222111,
HybridToolUtils.getTopToolName(props.toolName),
);
this.style = props.style ?? styleDefaultConfig; // 设置默认操作
}

Expand Down Expand Up @@ -119,7 +114,6 @@ export class ToolScheduler implements IToolSchedulerOperation {
}

public syncPosition(currentPos: ICoordinate, zoom: number, imgInfo: ISize, currentToolInstance: any) {
console.log('syncPosition', 111222);
this.toolOperationList.forEach((toolInstance) => {
if (currentToolInstance === toolInstance) {
return;
Expand Down Expand Up @@ -208,7 +202,6 @@ export class ToolScheduler implements IToolSchedulerOperation {
},
);
toolInstance.on('renderZoom', (zoom: number, currentPos: ICoordinate, imgInfo: ISize) => {
console.log(zoom, currentPos);
if (zoom && currentPos) {
this.syncPosition(currentPos, zoom, imgInfo, toolInstance);
}
Expand Down
41 changes: 13 additions & 28 deletions packages/lb-annotation/src/core/toolOperation/LineToolOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import EKeyCode from '@/constant/keyCode';
import MathUtils from '@/utils/MathUtils';
import { BasicToolOperation, IBasicToolOperationProps } from './basicToolOperation';
import LineToolUtils from '../../utils/tool/LineToolUtils';
import { IPolygonData } from '../../types/tool/polygon';

import {
isInPolygon,
Expand Down Expand Up @@ -138,6 +137,12 @@ class LineToolOperation extends BasicToolOperation {

public selectedID?: string;

public updatedLine: ILine = {
id: '',
valid: false,
order: 0,
};

public toolName: string = 'lineTool';

private lineList: ILine[] = [];
Expand Down Expand Up @@ -831,7 +836,6 @@ class LineToolOperation extends BasicToolOperation {
left: this.activeArea.left + offsetX,
});
}

if (this.activeLine) {
this.activeLine.map((i) => Object.assign(i, { x: i.x + offsetX, y: i.y + offsetY }));
this.updateLines();
Expand Down Expand Up @@ -1006,16 +1010,17 @@ class LineToolOperation extends BasicToolOperation {
public moveSelectedLine(coord: ICoordinate) {
const offsetX = (coord.x - this.prevAxis.x) / this.zoom;
const offsetY = (coord.y - this.prevAxis.y) / this.zoom;

/** 允许目标外 */
if (this.enableOutOfTarget) {
this.lineDragging = true;
this.moveActiveArea(offsetX, offsetY);
this.emit('updateLineByDrag', this.updatedLine);
return;
}

if (this.isDependPolygon) {
this.moveLineInPolygon(offsetX, offsetY);
this.emit('updateLineByDrag', this.updatedLine);
return;
}

Expand All @@ -1028,6 +1033,7 @@ class LineToolOperation extends BasicToolOperation {
rectVerticalRange = [y, y + height];
}
this.moveLineInRectRange(offsetX, offsetY, rectHorizontalRange, rectVerticalRange);
this.emit('updateLineByDrag', this.updatedLine);
}

/**
Expand Down Expand Up @@ -1166,7 +1172,6 @@ class LineToolOperation extends BasicToolOperation {
this.setSelectedLineID(line.id);
this.activeArea = area;
this.updateLineAttributes(line);
this.updateLineBasicInfo(line);
} else if (outsideCancel) {
this.setNoneStatus();
}
Expand All @@ -1187,38 +1192,17 @@ class LineToolOperation extends BasicToolOperation {
this.setSelectedLineID(line.id);
this.activeArea = area;
this.updateLineAttributes(line);
this.updateLineBasicInfo(line);
}

this.render();
}

public updateLineBasicInfo(line: ILine) {
let createPolygon: IPolygonData | undefined;
const basicSourceID = CommonToolUtils.getSourceID(this.basicResult);
const newPolygon: IPolygonData = {
id: line.id,
sourceID: basicSourceID,
valid: true, // !this.isCtrl
textAttribute: '',
pointList: line.pointList!,
attribute: this.defaultAttribute,
order:
CommonToolUtils.getMaxOrder(
this.lineList.filter((v) => CommonToolUtils.isSameSourceID(v.sourceID, basicSourceID)),
) + 1,
};
createPolygon = newPolygon;
this.emit('polygonCreated', createPolygon, this.zoom, this.currentPos);
}

public setActiveLine(pointList?: ILinePoint[]) {
this.activeLine = pointList ? _.cloneDeep(pointList) : undefined;
}

public onRightClick = (e: MouseEvent) => {
this.cursor = undefined;
console.log(123123);
if (this.isCreate) {
if (this.isLinePointsNotEnough()) {
// message.info(`顶点数不能少于${this.lowerLimitPointNum}`);
Expand Down Expand Up @@ -1459,6 +1443,7 @@ class LineToolOperation extends BasicToolOperation {
const line = this.lineList.find((i) => i.id === this.selectedID);
if (line) {
line.pointList = _.cloneDeep(this.activeLine);
this.updatedLine = line;
this.emit('dataUpdated', this.lineList);
}
}
Expand Down Expand Up @@ -1521,7 +1506,6 @@ class LineToolOperation extends BasicToolOperation {
public stopLineCreating(isAppend: boolean = true) {
/** 新建线条后在文本标注未开启时默认不选中, 续标后默认选中 */
const setActiveAfterCreating = this.selectedID ? true : !!this.isTextConfigurable;

let selectedID;
if (isAppend) {
if (this.selectedID) {
Expand All @@ -1537,6 +1521,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.history?.pushHistory(this.lineList);
}
}
Expand Down Expand Up @@ -1771,7 +1756,7 @@ class LineToolOperation extends BasicToolOperation {
this.lineList = this.lineList.filter((i) => i.id !== this.selectedID);
this.history?.pushHistory(this.lineList);
this.setNoneStatus();
this.emit('dataUpdated', this.lineList);
this.emit('lineDeleted', this.selectedID);
this.render();
}

Expand Down Expand Up @@ -1810,7 +1795,7 @@ class LineToolOperation extends BasicToolOperation {

/** 设置线条文本标注属性 */
public setTextAttribute(text: string) {
console.log('setText', 77)
console.log('setText', 77);
if (this.isTextConfigurable) {
this.setLineAttribute('textAttribute', text);
this.history?.applyAttribute(this.selectedID, 'textAttribute', text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export default class ViewOperation extends BasicToolOperation {

const extraData = _.pick(data, ['stroke', 'thickness']);

viewDataPointList.forEach((v, i) => {
viewDataPointList!.forEach((v, i) => {
const newAnnotation = {
...extraData,
id: `${annotation.annotation.id}-${i}`,
Expand All @@ -525,13 +525,13 @@ export default class ViewOperation extends BasicToolOperation {
case 'line':
this.renderLine({
type: 'line',
annotation: newAnnotation,
annotation: newAnnotation as any,
});
break;
case 'polygon':
this.renderPolygon({
type: 'polygon',
annotation: newAnnotation,
annotation: newAnnotation as any,
});
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ class PolygonOperation extends BasicToolOperation {
* @returns
*/
public addDrawingPointToPolygonList(isRect?: boolean) {
console.log('rect created');
let { lowerLimitPointNum = 3 } = this.config;

if (lowerLimitPointNum < 3) {
Expand Down Expand Up @@ -1398,7 +1399,6 @@ class PolygonOperation extends BasicToolOperation {

return;
}
console.log(123123);
if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ interface IAnnotationDataTemporarily {
}

const PointCloud2DView = ({ currentData, config }: IA2MapStateProps) => {
const ptCtx = React.useContext(PointCloudContext);
const [annotations2d, setAnnotations2d] = useState<IAnnotationDataTemporarily[]>([]);
const { topViewInstance, displayPointCloudList } = useContext(PointCloudContext);
const [mappingIndex, setMappingIndex] = useState(0);
Expand All @@ -54,17 +53,13 @@ const PointCloud2DView = ({ currentData, config }: IA2MapStateProps) => {
const size = useSize(ref);
const { t } = useTranslation();

const toolName = ptCtx?.topViewInstance?.toolInstance.toolName;
const isLine = toolName === 'lineTool';

const mappingData = currentData?.mappingImgList?.[mappingIndex];

useEffect(() => {
setMappingIndex(0);
}, [currentData]);

useEffect(() => {
if (isLine) return;
if (topViewInstance && mappingData) {
const defaultViewStyle = {
fill: 'transparent',
Expand All @@ -86,7 +81,7 @@ const PointCloud2DView = ({ currentData, config }: IA2MapStateProps) => {

return [
...acc,
...viewDataPointList.map((v: any) => {
...viewDataPointList!.map((v: any) => {
return {
type: v.type,
annotation: {
Expand All @@ -101,6 +96,7 @@ const PointCloud2DView = ({ currentData, config }: IA2MapStateProps) => {
},
[],
);
console.log('view data', newAnnotations2d);

setAnnotations2d(newAnnotations2d);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IPointCloudBox, IPointCloudBoxList, IPolygonData } from '@labelbee/lb-utils';
import { IPointCloudBox, IPointCloudBoxList, IPolygonData, ILine } from '@labelbee/lb-utils';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import {
PointCloud,
Expand Down Expand Up @@ -37,6 +37,9 @@ export interface IPointCloudContext extends IPointCloudContextInstances {
polygonList: IPolygonData[];
setPolygonList: (polygonList: IPolygonData[]) => void;

lineList: ILine[];
setLineList: (lineList: ILine[]) => void;

zoom: number;
setZoom: (zoom: number) => void;

Expand All @@ -63,6 +66,7 @@ export const PointCloudContext = React.createContext<IPointCloudContext>({
pointCloudBoxList: [],
displayPointCloudList: [],
polygonList: [],
lineList: [],
selectedID: '',
selectedIDs: [],
valid: true,
Expand All @@ -79,6 +83,7 @@ export const PointCloudContext = React.createContext<IPointCloudContext>({
return [];
},
setPolygonList: () => {},
setLineList: () => {},

zoom: 1,
setZoom: () => {},
Expand All @@ -101,6 +106,7 @@ export const PointCloudContext = React.createContext<IPointCloudContext>({
export const PointCloudProvider: React.FC<{}> = ({ children }) => {
const [pointCloudBoxList, setPointCloudResult] = useState<IPointCloudBoxList>([]);
const [polygonList, setPolygonList] = useState<IPolygonData[]>([]);
const [lineList, setLineList] = useState<ILine[]>([]);
const [selectedIDs, setSelectedIDsState] = useState<string[]>([]);
const [valid, setValid] = useState<boolean>(true);
const [zoom, setZoom] = useState<number>(1);
Expand Down Expand Up @@ -234,6 +240,8 @@ export const PointCloudProvider: React.FC<{}> = ({ children }) => {
setMainViewInstance,
polygonList,
setPolygonList,
lineList,
setLineList,
zoom,
setZoom,
history,
Expand All @@ -254,6 +262,7 @@ export const PointCloudProvider: React.FC<{}> = ({ children }) => {
selectedIDs,
pointCloudBoxList,
polygonList,
lineList,
topViewInstance,
sideViewInstance,
backViewInstance,
Expand Down
Loading

0 comments on commit 8f0bc46

Please sign in to comment.