Skip to content

Commit

Permalink
Merge pull request #576 from Original-Recipe/fix-attributeDisplayIssue
Browse files Browse the repository at this point in the history
fix: AttributeDisplayIssue
  • Loading branch information
lihqi authored Oct 16, 2024
2 parents e2987f8 + d793e0a commit 304e47e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
15 changes: 12 additions & 3 deletions packages/lb-annotation/src/core/toolOperation/ViewOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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';
Expand All @@ -39,6 +39,7 @@ interface IViewOperationProps extends IBasicToolOperationProps {
style: IBasicStyle;
staticMode?: boolean;
annotations: TAnnotationViewData[];
renderToolName?: EPointCloudName;
}

export interface ISpecificStyle {
Expand Down Expand Up @@ -83,6 +84,8 @@ export default class ViewOperation extends BasicToolOperation {

private hiddenText?: boolean = false;

private renderToolName?: EPointCloudName = undefined;

constructor(props: IViewOperationProps) {
super({ ...props, showDefaultCursor: true });
this.style = props.style ?? { stroke: DEFAULT_STROKE_COLOR, thickness: 3 };
Expand All @@ -93,6 +96,7 @@ export default class ViewOperation extends BasicToolOperation {
container: this.container,
height: this.canvas.height,
});
this.renderToolName = props.renderToolName;
}

public clearConnectionPoints() {
Expand Down Expand Up @@ -450,8 +454,9 @@ 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() {
public renderPointCloud3DRectAttribute() {
const annotationChunks = _.chunk(this.annotations, 6);
annotationChunks.forEach((annotationList) => {
const annotation = annotationList.find((item) => item.type === 'polygon');
Expand All @@ -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);

Expand Down Expand Up @@ -975,7 +982,9 @@ export default class ViewOperation extends BasicToolOperation {
});

this.renderConnectionPoints();
this.renderAttribute();
if (this.renderToolName && this.renderToolName === EPointCloudName.PointCloud) {
this.renderPointCloud3DRectAttribute();
}
} catch (e) {
console.error('ViewOperation Render Error', e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,6 +51,7 @@ interface IProps {
onRightClick?: (e: { event: MouseEvent; targetId: string }) => void;
pointCloudBoxList?: IPointCloudBoxList;
hiddenText?: boolean;
renderToolName?: EPointCloudName.PointCloud | undefined;
}

const DEFAULT_SIZE = {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -139,6 +141,7 @@ const AnnotationView = (props: IProps, ref: any) => {
config: '{}', // TODO,暂时不需要
zoomInfo: props.zoomInfo,
staticMode: props.staticMode,
renderToolName,
});

viewOperation.current.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -133,6 +133,7 @@ const PointCloud2DSingleView = ({
onRightClick={({ targetId }) => setSelectedIDs(targetId)}
pointCloudBoxList={pointCloudBoxList}
hiddenText={hiddenText}
renderToolName={EPointCloudName.PointCloud}
/>
) : (
<>
Expand Down

0 comments on commit 304e47e

Please sign in to comment.