diff --git a/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts index 440242cc..81a7d2f3 100644 --- a/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts +++ b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts @@ -34,7 +34,7 @@ import _ from 'lodash'; import { useDispatch, useSelector } from '@/store/ctx'; import { AppState } from '@/store'; import StepUtils from '@/utils/StepUtils'; -import { jsonParser, getRectPointCloudBox } from '@/utils'; +import { jsonParser, getRectPointCloudBox, generatePointCloudBoxRects } from '@/utils'; import { PreDataProcess, SetPointCloudLoading, @@ -637,18 +637,14 @@ export const usePointCloudViews = () => { const cuboidBoxIn2DViewLatest = useLatest(cuboidBoxIn2DView); const generateRects = (boxParams: IPointCloudBox) => { - if (!cuboidBoxIn2DViewLatest.current) { + const { enableAutoMap2DRect = false } = config; + if (!cuboidBoxIn2DViewLatest.current || enableAutoMap2DRect) { const { mappingImgList = [] } = currentData; - const rects: Array> = mappingImgList.map( - (v: IMappingImg) => - getRectPointCloudBox({ - pointCloudBox: boxParams, - mappingData: v, - imageSizes, - }), - ); - - Object.assign(boxParams, { rects: rects.filter((rect) => rect !== undefined) }); + generatePointCloudBoxRects({ + pointCloudBox: boxParams, + mappingImgList, + imageSizes, + }); } }; const { selectedBox, updateSelectedBox, updateSelectedBoxes, getPointCloudByID } = useSingleBox({ diff --git a/packages/lb-components/src/index.tsx b/packages/lb-components/src/index.tsx index 698340b5..71cf5171 100644 --- a/packages/lb-components/src/index.tsx +++ b/packages/lb-components/src/index.tsx @@ -24,6 +24,7 @@ import MeasureCanvas from './components/measureCanvas'; import AnnotatedBox from './views/MainView/sidebar/PointCloudToolSidebar/components/annotatedBox'; import { FindTrackIDIndexInCheckMode as FindTrackIDIndex } from './views/MainView/sidebar/PointCloudToolSidebar/components/findTrackIDIndex'; import { WrapAudioPlayer as AudioPlayer } from './components/audioPlayer'; +import { generatePointCloudBoxRects } from './utils'; export const store = configureStore(); @@ -81,6 +82,7 @@ export { AnnotatedBox, FindTrackIDIndex, AudioPlayer, + generatePointCloudBoxRects, }; export * from './constant'; diff --git a/packages/lb-components/src/utils/index.ts b/packages/lb-components/src/utils/index.ts index 864465ed..a408e659 100644 --- a/packages/lb-components/src/utils/index.ts +++ b/packages/lb-components/src/utils/index.ts @@ -124,3 +124,40 @@ export const getRectPointCloudBox = (params: IGetRectPointCloudBoxParams) => { if (isRectInImage) return boundingRect; }; +/** + * Updates the given point cloud box with rectangles derived from the mapping image list and image sizes. + * + * @param {Object} params - The parameters for the function. + * @param {IPointCloudBox} params.pointCloudBox - The point cloud box object to be updated. + * @param {IMappingImg[]} params.mappingImgList - The list of mapping images to process. + * @param {Object.} params.imageSizes - An object containing image sizes keyed by image paths. + * + * @returns {void} + * + * @description This function processes a list of mapping images to generate rectangles for the provided point cloud box. + * It filters out undefined rectangles and updates the point cloud box with the valid rectangles. Note that this function + * modifies the `pointCloudBox` parameter by adding a `rects` property. + */ +export const generatePointCloudBoxRects = (params: { + pointCloudBox: IPointCloudBox; + mappingImgList: IMappingImg[]; + imageSizes: { + [key: string]: ISize; + }; +}) => { + const { pointCloudBox, mappingImgList, imageSizes } = params; + const rects: Array> = mappingImgList.map( + (v: IMappingImg) => + getRectPointCloudBox({ + pointCloudBox, + mappingData: v, + imageSizes, + }), + ); + + const filteredRects = rects.filter((rect) => rect !== undefined); + + if (filteredRects.length > 0) { + Object.assign(pointCloudBox, { rects: filteredRects }); + } +}; diff --git a/packages/lb-utils/src/types/pointCloud.ts b/packages/lb-utils/src/types/pointCloud.ts index 5f438b38..a8345bf9 100644 --- a/packages/lb-utils/src/types/pointCloud.ts +++ b/packages/lb-utils/src/types/pointCloud.ts @@ -130,6 +130,7 @@ export interface IPointCloudConfig { lowerLimitPointsNumInBox: number; trackConfigurable: boolean; + enableAutoMap2DRect?: boolean; } interface ICalib {