From f7dc09918594d5a096e6895f99a108cd52114005 Mon Sep 17 00:00:00 2001 From: Original-Recipe-Chicken Date: Mon, 30 Sep 2024 18:48:53 +0800 Subject: [PATCH 1/3] fix: AttributeDisplayIssue --- .../src/core/toolOperation/ViewOperation.ts | 13 +++++++++++-- .../src/components/AnnotationView/index.tsx | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/lb-annotation/src/core/toolOperation/ViewOperation.ts b/packages/lb-annotation/src/core/toolOperation/ViewOperation.ts index 4c4bae91..c339f992 100644 --- a/packages/lb-annotation/src/core/toolOperation/ViewOperation.ts +++ b/packages/lb-annotation/src/core/toolOperation/ViewOperation.ts @@ -24,7 +24,7 @@ import RectUtils from '@/utils/tool/RectUtils'; import PolygonUtils, { IConvexHullGroupType } from '@/utils/tool/PolygonUtils'; import MathUtils from '@/utils/MathUtils'; import RenderDomClass from '@/utils/tool/RenderDomClass'; -import { DEFAULT_FONT, ELineTypes, SEGMENT_NUMBER } from '@/constant/tool'; +import { DEFAULT_FONT, ELineTypes, EToolName, SEGMENT_NUMBER } from '@/constant/tool'; import { DEFAULT_TEXT_SHADOW, DEFAULT_TEXT_OFFSET, TEXT_ATTRIBUTE_OFFSET } from '@/constant/annotation'; import ImgUtils, { cropAndEnlarge } from '@/utils/ImgUtils'; import CanvasUtils from '@/utils/tool/CanvasUtils'; @@ -39,6 +39,7 @@ interface IViewOperationProps extends IBasicToolOperationProps { style: IBasicStyle; staticMode?: boolean; annotations: TAnnotationViewData[]; + toolName?: EToolName; } export interface ISpecificStyle { @@ -83,6 +84,8 @@ export default class ViewOperation extends BasicToolOperation { private hiddenText?: boolean = false; + private toolName?: EToolName = EToolName.Empty; + constructor(props: IViewOperationProps) { super({ ...props, showDefaultCursor: true }); this.style = props.style ?? { stroke: DEFAULT_STROKE_COLOR, thickness: 3 }; @@ -93,6 +96,7 @@ export default class ViewOperation extends BasicToolOperation { container: this.container, height: this.canvas.height, }); + this.toolName = props.toolName || EToolName.Empty; } public clearConnectionPoints() { @@ -450,6 +454,7 @@ export default class ViewOperation extends BasicToolOperation { /** * Separate rendering of sub attribute content * The principle is the same as other tools for rendering sub attribute content + * Currently, only secondary attributes are being rendered in point cloud rendering */ public renderAttribute() { const annotationChunks = _.chunk(this.annotations, 6); @@ -460,6 +465,8 @@ export default class ViewOperation extends BasicToolOperation { const { fontStyle } = this.getRenderStyle(annotation); const polygon = annotation.annotation as IBasicPolygon; const curPointCloudBox = this.pointCloudBoxList?.find((item: IPointCloudBox) => item.id === polygon.id); + // Without this rendered graphic, return in advance to avoid errors in the future + if (!curPointCloudBox) return; const headerText = this.hiddenText ? '' : `${curPointCloudBox?.trackID} ${curPointCloudBox?.attribute}`; const renderPolygon = AxisUtils.changePointListByZoom(polygon?.pointList ?? [], this.zoom, this.currentPos); @@ -975,7 +982,9 @@ export default class ViewOperation extends BasicToolOperation { }); this.renderConnectionPoints(); - this.renderAttribute(); + if (this.toolName && this.toolName === EToolName.Rect) { + this.renderAttribute(); + } } catch (e) { console.error('ViewOperation Render Error', e); } diff --git a/packages/lb-components/src/components/AnnotationView/index.tsx b/packages/lb-components/src/components/AnnotationView/index.tsx index 66ad18c4..d3b715a5 100644 --- a/packages/lb-components/src/components/AnnotationView/index.tsx +++ b/packages/lb-components/src/components/AnnotationView/index.tsx @@ -109,7 +109,7 @@ const AnnotationView = (props: IProps, ref: any) => { const annotationListCacheRef = useRef([]); const canUpdateRef = useRef(true); // Judge if rending is Possible. - const { setSelectedIDs } = useContext(PointCloudContext); + const { setSelectedIDs, pointCloudPattern } = useContext(PointCloudContext); useImperativeHandle( ref, @@ -139,6 +139,7 @@ const AnnotationView = (props: IProps, ref: any) => { config: '{}', // TODO,暂时不需要 zoomInfo: props.zoomInfo, staticMode: props.staticMode, + toolName: pointCloudPattern, }); viewOperation.current.init(); From 9812e57b91f7ef9b32876a2f3fb84245c83fe9ef Mon Sep 17 00:00:00 2001 From: Original-Recipe-Chicken Date: Tue, 15 Oct 2024 19:32:31 +0800 Subject: [PATCH 2/3] feat: Code review --- .../src/core/toolOperation/ViewOperation.ts | 14 +++++++------- .../src/components/AnnotationView/index.tsx | 8 +++++--- .../pointCloudView/PointCloud2DSingleView.tsx | 3 ++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/lb-annotation/src/core/toolOperation/ViewOperation.ts b/packages/lb-annotation/src/core/toolOperation/ViewOperation.ts index c339f992..d6f33589 100644 --- a/packages/lb-annotation/src/core/toolOperation/ViewOperation.ts +++ b/packages/lb-annotation/src/core/toolOperation/ViewOperation.ts @@ -24,7 +24,7 @@ import RectUtils from '@/utils/tool/RectUtils'; import PolygonUtils, { IConvexHullGroupType } from '@/utils/tool/PolygonUtils'; import MathUtils from '@/utils/MathUtils'; import RenderDomClass from '@/utils/tool/RenderDomClass'; -import { DEFAULT_FONT, ELineTypes, EToolName, SEGMENT_NUMBER } from '@/constant/tool'; +import { DEFAULT_FONT, ELineTypes, SEGMENT_NUMBER, EPointCloudName } from '@/constant/tool'; import { DEFAULT_TEXT_SHADOW, DEFAULT_TEXT_OFFSET, TEXT_ATTRIBUTE_OFFSET } from '@/constant/annotation'; import ImgUtils, { cropAndEnlarge } from '@/utils/ImgUtils'; import CanvasUtils from '@/utils/tool/CanvasUtils'; @@ -39,7 +39,7 @@ interface IViewOperationProps extends IBasicToolOperationProps { style: IBasicStyle; staticMode?: boolean; annotations: TAnnotationViewData[]; - toolName?: EToolName; + renderToolName?: EPointCloudName; } export interface ISpecificStyle { @@ -84,7 +84,7 @@ export default class ViewOperation extends BasicToolOperation { private hiddenText?: boolean = false; - private toolName?: EToolName = EToolName.Empty; + private renderToolName?: EPointCloudName = undefined; constructor(props: IViewOperationProps) { super({ ...props, showDefaultCursor: true }); @@ -96,7 +96,7 @@ export default class ViewOperation extends BasicToolOperation { container: this.container, height: this.canvas.height, }); - this.toolName = props.toolName || EToolName.Empty; + this.renderToolName = props.renderToolName; } public clearConnectionPoints() { @@ -456,7 +456,7 @@ export default class ViewOperation extends BasicToolOperation { * The principle is the same as other tools for rendering sub attribute content * Currently, only secondary attributes are being rendered in point cloud rendering */ - public renderAttribute() { + public renderPointCloud3DRectAttribute() { const annotationChunks = _.chunk(this.annotations, 6); annotationChunks.forEach((annotationList) => { const annotation = annotationList.find((item) => item.type === 'polygon'); @@ -982,8 +982,8 @@ export default class ViewOperation extends BasicToolOperation { }); this.renderConnectionPoints(); - if (this.toolName && this.toolName === EToolName.Rect) { - this.renderAttribute(); + if (this.renderToolName && this.renderToolName === EPointCloudName.PointCloud) { + this.renderPointCloud3DRectAttribute(); } } catch (e) { console.error('ViewOperation Render Error', e); diff --git a/packages/lb-components/src/components/AnnotationView/index.tsx b/packages/lb-components/src/components/AnnotationView/index.tsx index d3b715a5..788e9f1a 100644 --- a/packages/lb-components/src/components/AnnotationView/index.tsx +++ b/packages/lb-components/src/components/AnnotationView/index.tsx @@ -11,7 +11,7 @@ import React, { useState, useContext, } from 'react'; -import { ViewOperation, ImgUtils } from '@labelbee/lb-annotation'; +import { ViewOperation, ImgUtils, EPointCloudName } from '@labelbee/lb-annotation'; import { Spin } from 'antd/es'; import useRefCache from '@/hooks/useRefCache'; import { TAnnotationViewData, IPointCloudBoxList } from '@labelbee/lb-utils'; @@ -51,6 +51,7 @@ interface IProps { onRightClick?: (e: { event: MouseEvent; targetId: string }) => void; pointCloudBoxList?: IPointCloudBoxList; hiddenText?: boolean; + renderToolName: EPointCloudName.PointCloud | undefined; } const DEFAULT_SIZE = { @@ -100,6 +101,7 @@ const AnnotationView = (props: IProps, ref: any) => { onRightClick, pointCloudBoxList = [], hiddenText = false, + renderToolName, } = props; const size = sizeInitialized(props.size); const [loading, setLoading] = useState(false); @@ -109,7 +111,7 @@ const AnnotationView = (props: IProps, ref: any) => { const annotationListCacheRef = useRef([]); const canUpdateRef = useRef(true); // Judge if rending is Possible. - const { setSelectedIDs, pointCloudPattern } = useContext(PointCloudContext); + const { setSelectedIDs } = useContext(PointCloudContext); useImperativeHandle( ref, @@ -139,7 +141,7 @@ const AnnotationView = (props: IProps, ref: any) => { config: '{}', // TODO,暂时不需要 zoomInfo: props.zoomInfo, staticMode: props.staticMode, - toolName: pointCloudPattern, + renderToolName, }); viewOperation.current.init(); diff --git a/packages/lb-components/src/components/pointCloudView/PointCloud2DSingleView.tsx b/packages/lb-components/src/components/pointCloudView/PointCloud2DSingleView.tsx index 3318081d..4befce7d 100644 --- a/packages/lb-components/src/components/pointCloudView/PointCloud2DSingleView.tsx +++ b/packages/lb-components/src/components/pointCloudView/PointCloud2DSingleView.tsx @@ -3,7 +3,7 @@ import React, { useCallback, useContext, useEffect, useMemo, useRef, useState } import AnnotationView from '@/components/AnnotationView'; import useSize from '@/hooks/useSize'; import { useSingleBox } from './hooks/useSingleBox'; -import { ViewOperation } from '@labelbee/lb-annotation'; +import { ViewOperation, EPointCloudName } from '@labelbee/lb-annotation'; import { IAnnotationData2dView, IAnnotationDataTemporarily } from './PointCloud2DView'; import { useHighlight } from './hooks/useHighlight'; import HighlightVisible from './components/HighlightVisible'; @@ -133,6 +133,7 @@ const PointCloud2DSingleView = ({ onRightClick={({ targetId }) => setSelectedIDs(targetId)} pointCloudBoxList={pointCloudBoxList} hiddenText={hiddenText} + renderToolName={EPointCloudName.PointCloud} /> ) : ( <> From d793e0a0733fc058dddfaf4c75462f78c3cfbb53 Mon Sep 17 00:00:00 2001 From: Original-Recipe-Chicken Date: Tue, 15 Oct 2024 19:35:08 +0800 Subject: [PATCH 3/3] fix: RenderToolName Change to optional --- packages/lb-components/src/components/AnnotationView/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lb-components/src/components/AnnotationView/index.tsx b/packages/lb-components/src/components/AnnotationView/index.tsx index 788e9f1a..f99754d0 100644 --- a/packages/lb-components/src/components/AnnotationView/index.tsx +++ b/packages/lb-components/src/components/AnnotationView/index.tsx @@ -51,7 +51,7 @@ interface IProps { onRightClick?: (e: { event: MouseEvent; targetId: string }) => void; pointCloudBoxList?: IPointCloudBoxList; hiddenText?: boolean; - renderToolName: EPointCloudName.PointCloud | undefined; + renderToolName?: EPointCloudName.PointCloud | undefined; } const DEFAULT_SIZE = {