From 36aa89580d3214a63b6f885d1fa2571cd827ec1c Mon Sep 17 00:00:00 2001 From: lihqi <455711093@qq.com> Date: Fri, 24 May 2024 17:28:25 +0800 Subject: [PATCH 1/2] feat(lb-components): Support enableAutoMap2DRect function --- .../hooks/usePointCloudViews.ts | 20 ++++------ packages/lb-components/src/index.tsx | 2 + packages/lb-components/src/utils/index.ts | 37 +++++++++++++++++++ packages/lb-utils/src/types/pointCloud.ts | 1 + 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts index 440242cc..c6eab1c9 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, getPointCloudBoxRects } 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) }); + getPointCloudBoxRects({ + 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..4ecc8a1b 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 { getPointCloudBoxRects } from './utils'; export const store = configureStore(); @@ -81,6 +82,7 @@ export { AnnotatedBox, FindTrackIDIndex, AudioPlayer, + getPointCloudBoxRects, }; export * from './constant'; diff --git a/packages/lb-components/src/utils/index.ts b/packages/lb-components/src/utils/index.ts index 864465ed..384e7c4d 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 getPointCloudBoxRects = (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 { From daf94d53fca0d3999294cdb2b2a0d0052ad7c8b3 Mon Sep 17 00:00:00 2001 From: lihqi <455711093@qq.com> Date: Mon, 27 May 2024 11:14:17 +0800 Subject: [PATCH 2/2] fix(lb-components): Rename getPointCloudBoxRects --- .../src/components/pointCloudView/hooks/usePointCloudViews.ts | 4 ++-- packages/lb-components/src/index.tsx | 4 ++-- packages/lb-components/src/utils/index.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudViews.ts index c6eab1c9..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, getPointCloudBoxRects } from '@/utils'; +import { jsonParser, getRectPointCloudBox, generatePointCloudBoxRects } from '@/utils'; import { PreDataProcess, SetPointCloudLoading, @@ -640,7 +640,7 @@ export const usePointCloudViews = () => { const { enableAutoMap2DRect = false } = config; if (!cuboidBoxIn2DViewLatest.current || enableAutoMap2DRect) { const { mappingImgList = [] } = currentData; - getPointCloudBoxRects({ + generatePointCloudBoxRects({ pointCloudBox: boxParams, mappingImgList, imageSizes, diff --git a/packages/lb-components/src/index.tsx b/packages/lb-components/src/index.tsx index 4ecc8a1b..71cf5171 100644 --- a/packages/lb-components/src/index.tsx +++ b/packages/lb-components/src/index.tsx @@ -24,7 +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 { getPointCloudBoxRects } from './utils'; +import { generatePointCloudBoxRects } from './utils'; export const store = configureStore(); @@ -82,7 +82,7 @@ export { AnnotatedBox, FindTrackIDIndex, AudioPlayer, - getPointCloudBoxRects, + generatePointCloudBoxRects, }; export * from './constant'; diff --git a/packages/lb-components/src/utils/index.ts b/packages/lb-components/src/utils/index.ts index 384e7c4d..a408e659 100644 --- a/packages/lb-components/src/utils/index.ts +++ b/packages/lb-components/src/utils/index.ts @@ -138,7 +138,7 @@ export const getRectPointCloudBox = (params: IGetRectPointCloudBoxParams) => { * 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 getPointCloudBoxRects = (params: { +export const generatePointCloudBoxRects = (params: { pointCloudBox: IPointCloudBox; mappingImgList: IMappingImg[]; imageSizes: {