Skip to content

Commit

Permalink
Merge pull request #462 from lihqi/lhq-hotfix-alpha-3.5.3
Browse files Browse the repository at this point in the history
feat(lb-components): Support enableAutoMap2DRect function
  • Loading branch information
lihqi committed May 27, 2024
2 parents d670c9b + daf94d5 commit 2c25b4a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<ReturnType<typeof getRectPointCloudBox>> = 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({
Expand Down
2 changes: 2 additions & 0 deletions packages/lb-components/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -81,6 +82,7 @@ export {
AnnotatedBox,
FindTrackIDIndex,
AudioPlayer,
generatePointCloudBoxRects,
};

export * from './constant';
Expand Down
37 changes: 37 additions & 0 deletions packages/lb-components/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.<string, ISize>} 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<ReturnType<typeof getRectPointCloudBox>> = 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 });
}
};
1 change: 1 addition & 0 deletions packages/lb-utils/src/types/pointCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export interface IPointCloudConfig {

lowerLimitPointsNumInBox: number;
trackConfigurable: boolean;
enableAutoMap2DRect?: boolean;
}

interface ICalib {
Expand Down

0 comments on commit 2c25b4a

Please sign in to comment.