From 3da88afc1528709567d5facc8d995991cb750dba Mon Sep 17 00:00:00 2001 From: Original-Recipe-Chicken Date: Wed, 30 Oct 2024 11:38:07 +0800 Subject: [PATCH 1/3] feat: Unified parameter submission --- .../pointCloudView/PointCloud3DView.tsx | 37 ++++++------- .../hooks/usePointCloudAttribute.ts | 55 +++++++++++++++++++ .../src/components/pointCloudView/index.tsx | 2 +- .../lb-components/src/store/annotation/map.ts | 1 + 4 files changed, 75 insertions(+), 20 deletions(-) create mode 100644 packages/lb-components/src/components/pointCloudView/hooks/usePointCloudAttribute.ts diff --git a/packages/lb-components/src/components/pointCloudView/PointCloud3DView.tsx b/packages/lb-components/src/components/pointCloudView/PointCloud3DView.tsx index ae3a0e814..f9e44f8f1 100644 --- a/packages/lb-components/src/components/pointCloudView/PointCloud3DView.tsx +++ b/packages/lb-components/src/components/pointCloudView/PointCloud3DView.tsx @@ -31,6 +31,7 @@ import PointCloudSizeSlider from './components/PointCloudSizeSlider'; import TitleButton from './components/TitleButton'; import { LeftOutlined } from '@ant-design/icons'; import { useToolStyleContext } from '@/hooks/useToolStyle'; +import { usePointCloudAttribute } from './hooks/usePointCloudAttribute'; const EKeyCode = cKeyCode.default; const pointCloudID = 'LABELBEE-POINTCLOUD'; @@ -121,7 +122,12 @@ const PointCloud3DSideBar = ({ isEnlarge }: { isEnlarge?: boolean }) => { ); }; -const PointCloud3D: React.FC = ({ currentData, config, highlightAttribute }) => { +const PointCloud3D: React.FC = ({ + currentData, + config, + highlightAttribute, + setResourceLoading, +}) => { const ptCtx = useContext(PointCloudContext); const [showDirection, setShowDirection] = useState(true); const [isEnlarge, setIsEnlarge] = useState(false); @@ -131,6 +137,7 @@ const PointCloud3D: React.FC = ({ currentData, config, highlig const { t } = useTranslation(); const { value: toolStyle } = useToolStyleContext(); const { hiddenText } = toolStyle || {}; + const { updatePointCloudAttribute } = usePointCloudAttribute(setResourceLoading, config); useEffect(() => { let pointCloud = ptCtx.mainViewInstance; @@ -194,7 +201,7 @@ const PointCloud3D: React.FC = ({ currentData, config, highlig config, hiddenText, }); - pointCloud.setHandlerPipe({setSelectedIDs: ptCtx.setSelectedIDs, setNeedUpdateCenter}); + pointCloud.setHandlerPipe({ setSelectedIDs: ptCtx.setSelectedIDs, setNeedUpdateCenter }); ptCtx.setMainViewInstance(pointCloud); } } @@ -207,26 +214,19 @@ const PointCloud3D: React.FC = ({ currentData, config, highlig if (ref.current && currentData?.url) { if (currentData.result && ptCtx.mainViewInstance) { let pointCloud = ptCtx.mainViewInstance; + const rectParamsList = PointCloudUtils.getRectParamsFromResultList(currentData.result); const boxParamsList = PointCloudUtils.getBoxParamsFromResultList(currentData.result); - - // Add Init Box - boxParamsList.forEach((v: IPointCloudBox) => { - const hex = toolStyleConverter.getColorFromConfig( - { attribute: v.attribute }, - { ...config, attributeConfigurable: true }, - {}, - )?.hex; - - pointCloud?.addBoxToSense(v, hex); - }); - pointCloud.render(); + const currentSelectInfo = boxParamsList.find((item) => item.id === ptCtx.selectedID); + if (currentSelectInfo) { + updatePointCloudAttribute(currentSelectInfo.attribute); + } + ptCtx.setPointCloudValid(jsonParser(currentData.result)?.valid); ptCtx.setPointCloudResult(boxParamsList); - const rectParamsList = PointCloudUtils.getRectParamsFromResultList(currentData.result); ptCtx.setRectList(rectParamsList); - ptCtx.setPointCloudValid(jsonParser(currentData.result)?.valid); + pointCloud.generateBoxes(boxParamsList); } } - }, [currentData, ptCtx.mainViewInstance]); + }, [currentData.result]); /** * Observe selectedID and reset camera to target top-view @@ -241,7 +241,7 @@ const PointCloud3D: React.FC = ({ currentData, config, highlig if (!needUpdateCenter) { setNeedUpdateCenter(true); return; - }; + } if (selectedId !== undefined) { setTarget3DView(EPerspectiveView.Top); @@ -254,7 +254,6 @@ const PointCloud3D: React.FC = ({ currentData, config, highlig // when create new box, need to wait for a moment to init box. ptCtx.mainViewInstance?.setHighlightColor(selectedId); ptCtx.mainViewInstance?.render(); - }, [selectedBox?.info?.id]); useEffect(() => { diff --git a/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudAttribute.ts b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudAttribute.ts new file mode 100644 index 000000000..6ce868ed2 --- /dev/null +++ b/packages/lb-components/src/components/pointCloudView/hooks/usePointCloudAttribute.ts @@ -0,0 +1,55 @@ +import { useContext } from 'react'; +import { PointCloudContext } from '../PointCloudContext'; +import { useUpdatePointCloudColor } from './useUpdatePointCloudColor'; +import { useAttribute } from './useAttribute'; +import { usePolygon } from './usePolygon'; +import { useLine } from './useLine'; +import { useSphere } from './useSphere'; +import { useHistory } from './useHistory'; +import { usePointCloudViews } from './usePointCloudViews'; + +export const usePointCloudAttribute = (setResourceLoading: any, config: any) => { + const { updatePointCloudColor } = useUpdatePointCloudColor(setResourceLoading, config); + const { syncThreeViewsAttribute } = useAttribute(); + const { selectedPolygon } = usePolygon(); + const { selectedLine } = useLine(); + const { selectedSphere } = useSphere(); + const { updatePointCloudSphere } = useSphere(); + const { pushHistoryUnderUpdatePolygon, pushHistoryUnderUpdateLine } = useHistory(); + const { topViewSelectedChanged } = usePointCloudViews(); + const ptCtx = useContext(PointCloudContext); + + const updatePointCloudAttribute = (newAttribute: string) => { + syncThreeViewsAttribute(newAttribute); + + /** + * The logic for extracting the updated color of the original point cloud due to changes in the main attribute, + * which originally only supported single selection, now supports multiple selection, and merges to reduce the number of updates + */ + updatePointCloudColor(newAttribute); + + if (selectedPolygon) { + pushHistoryUnderUpdatePolygon({ ...selectedPolygon, attribute: newAttribute }); + } + if (selectedLine) { + pushHistoryUnderUpdateLine({ ...selectedLine, attribute: newAttribute }); + } + if (selectedSphere) { + const newSphereList = updatePointCloudSphere({ + ...selectedSphere, + attribute: newAttribute, + }); + if (ptCtx.mainViewInstance) { + ptCtx.mainViewInstance?.generateSpheres(newSphereList); + topViewSelectedChanged({ + newSelectedSphere: selectedSphere, + newSphereList: newSphereList, + }); + } + } + }; + + return { + updatePointCloudAttribute, + }; +}; diff --git a/packages/lb-components/src/components/pointCloudView/index.tsx b/packages/lb-components/src/components/pointCloudView/index.tsx index 7fd887cef..d4081267d 100644 --- a/packages/lb-components/src/components/pointCloudView/index.tsx +++ b/packages/lb-components/src/components/pointCloudView/index.tsx @@ -173,7 +173,7 @@ const PointCloudView: React.FC = (props) => {
- + {backAndSideView}
void; } export const a2MapStateToProps = (state: AppState) => { From 650705f663894560aee3167bca996280d74c8ca5 Mon Sep 17 00:00:00 2001 From: Original-Recipe-Chicken Date: Thu, 31 Oct 2024 16:52:38 +0800 Subject: [PATCH 2/3] fix: Historical issues with unified parameter submissions --- .../pointCloudView/PointCloud3DView.tsx | 2 +- .../components/UnifyParamsModal/index.tsx | 15 ++++++++++----- .../src/store/annotation/actionCreators.ts | 2 ++ .../lb-components/src/store/annotation/reducer.ts | 4 ++-- .../lb-components/src/store/annotation/types.ts | 1 + 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/lb-components/src/components/pointCloudView/PointCloud3DView.tsx b/packages/lb-components/src/components/pointCloudView/PointCloud3DView.tsx index f9e44f8f1..eda1ea32b 100644 --- a/packages/lb-components/src/components/pointCloudView/PointCloud3DView.tsx +++ b/packages/lb-components/src/components/pointCloudView/PointCloud3DView.tsx @@ -226,7 +226,7 @@ const PointCloud3D: React.FC = ({ pointCloud.generateBoxes(boxParamsList); } } - }, [currentData.result]); + }, [currentData.result, ptCtx.mainViewInstance]); /** * Observe selectedID and reset camera to target top-view diff --git a/packages/lb-components/src/components/pointCloudView/components/UnifyParamsModal/index.tsx b/packages/lb-components/src/components/pointCloudView/components/UnifyParamsModal/index.tsx index 243ea52e9..2ba506ac3 100644 --- a/packages/lb-components/src/components/pointCloudView/components/UnifyParamsModal/index.tsx +++ b/packages/lb-components/src/components/pointCloudView/components/UnifyParamsModal/index.tsx @@ -77,8 +77,10 @@ const UnifyParamsModal = ({ id, visible, onCancel, config, imgList, imgIndex }: message.info('该范围不存在更改数据, 请更改统一范围'); return; } - - dispatch(ToSubmitFileData(ESubmitType.SyncImgList)); + /** + * Previously, imgList was retrieved from the state in dispatch(ToSubmitFileData(ESubmitType.SyncImgList)), but it was not the most up-to-date imgList. + * To fix this, the dispatch method was removed, and imgList is now passed through props to BatchUpdateResultByTrackID to ensure the latest data is used. + */ const newData = { attribute: values.attribute, }; @@ -101,7 +103,9 @@ const UnifyParamsModal = ({ id, visible, onCancel, config, imgList, imgIndex }: Object.assign(newData, size); } - dispatch(BatchUpdateResultByTrackID(id, newData, [values.prevPage - 1, values.nextPage - 1])); + dispatch( + BatchUpdateResultByTrackID(id, newData, [values.prevPage - 1, values.nextPage - 1], imgList), + ); onCancel(); }; @@ -190,7 +194,7 @@ const UnifyParamsModal = ({ id, visible, onCancel, config, imgList, imgIndex }: rules={defaultNumberRules} name='prevPage' noStyle={true} - initialValue={1} // First Page + initialValue={1} // First Page > { return { imgIndex: state.annotation.imgIndex, + ...state, }; }; diff --git a/packages/lb-components/src/store/annotation/actionCreators.ts b/packages/lb-components/src/store/annotation/actionCreators.ts index a3c2fb878..137065804 100644 --- a/packages/lb-components/src/store/annotation/actionCreators.ts +++ b/packages/lb-components/src/store/annotation/actionCreators.ts @@ -249,6 +249,7 @@ export function BatchUpdateResultByTrackID( id: number, // originData newData: Partial, rangeIndex: [number, number], + imgList: IFileItem[], ): AnnotationActionTypes { return { type: ANNOTATION_ACTIONS.BATCH_UPDATE_RESULT_BY_TRACK_ID, @@ -256,6 +257,7 @@ export function BatchUpdateResultByTrackID( id, newData, rangeIndex, + imgList, }, }; } diff --git a/packages/lb-components/src/store/annotation/reducer.ts b/packages/lb-components/src/store/annotation/reducer.ts index d2f640dd8..6309e3f5c 100644 --- a/packages/lb-components/src/store/annotation/reducer.ts +++ b/packages/lb-components/src/store/annotation/reducer.ts @@ -874,8 +874,8 @@ export const annotationReducer = ( } case ANNOTATION_ACTIONS.BATCH_UPDATE_RESULT_BY_TRACK_ID: { - const { id, newData, rangeIndex } = action.payload; - const { imgList, imgIndex, onSubmit } = state; + const { id, newData, rangeIndex, imgList } = action.payload; + const { imgIndex, onSubmit } = state; // Record the updated list. const updateImgList: Array<{ newInfo: IFileItem; imgIndex: number }> = []; const newImgList = imgList.map((v, i) => { diff --git a/packages/lb-components/src/store/annotation/types.ts b/packages/lb-components/src/store/annotation/types.ts index a7a8f608a..4367cfe4e 100644 --- a/packages/lb-components/src/store/annotation/types.ts +++ b/packages/lb-components/src/store/annotation/types.ts @@ -204,6 +204,7 @@ interface BatchUpdateResultByTrackID { id: number; newData: Partial; range: [number, number]; + imgList: IFileItem[]; }; } From ec11fb1e555bc185df45ecea4a59f172b075c310 Mon Sep 17 00:00:00 2001 From: Original-Recipe-Chicken Date: Thu, 31 Oct 2024 17:22:10 +0800 Subject: [PATCH 3/3] fix: Type issue --- .../pointCloudView/components/UnifyParamsModal/index.tsx | 2 +- packages/lb-components/src/store/annotation/reducer.ts | 5 +++-- packages/lb-components/src/store/annotation/types.ts | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/lb-components/src/components/pointCloudView/components/UnifyParamsModal/index.tsx b/packages/lb-components/src/components/pointCloudView/components/UnifyParamsModal/index.tsx index 2ba506ac3..ef09dcaa9 100644 --- a/packages/lb-components/src/components/pointCloudView/components/UnifyParamsModal/index.tsx +++ b/packages/lb-components/src/components/pointCloudView/components/UnifyParamsModal/index.tsx @@ -18,7 +18,7 @@ interface IProps { onCancel: () => void; config: IPointCloudConfig; imgList: AnnotationFileList; - imgIndex: number; + imgIndex?: number; } const layout = { diff --git a/packages/lb-components/src/store/annotation/reducer.ts b/packages/lb-components/src/store/annotation/reducer.ts index 6309e3f5c..00d151779 100644 --- a/packages/lb-components/src/store/annotation/reducer.ts +++ b/packages/lb-components/src/store/annotation/reducer.ts @@ -16,7 +16,7 @@ import { Modal } from 'antd'; import { message } from 'antd/es'; import _ from 'lodash'; import { SetAnnotationLoading } from './actionCreators'; -import { AnnotationActionTypes, AnnotationState } from './types'; +import { AnnotationActionTypes, AnnotationState, BatchUpdateResultByTrackID } from './types'; import { EToolName } from '@/data/enums/ToolType'; export const getStepConfig = (stepList: any[], step: number) => @@ -874,7 +874,8 @@ export const annotationReducer = ( } case ANNOTATION_ACTIONS.BATCH_UPDATE_RESULT_BY_TRACK_ID: { - const { id, newData, rangeIndex, imgList } = action.payload; + const actionNew = action as BatchUpdateResultByTrackID; + const { id, newData, rangeIndex, imgList } = actionNew.payload; const { imgIndex, onSubmit } = state; // Record the updated list. const updateImgList: Array<{ newInfo: IFileItem; imgIndex: number }> = []; diff --git a/packages/lb-components/src/store/annotation/types.ts b/packages/lb-components/src/store/annotation/types.ts index 4367cfe4e..77c9c98af 100644 --- a/packages/lb-components/src/store/annotation/types.ts +++ b/packages/lb-components/src/store/annotation/types.ts @@ -198,12 +198,12 @@ interface BatchUpdateTrackID { }; } -interface BatchUpdateResultByTrackID { +export interface BatchUpdateResultByTrackID { type: typeof ANNOTATION_ACTIONS.BATCH_UPDATE_RESULT_BY_TRACK_ID; payload: { id: number; newData: Partial; - range: [number, number]; + rangeIndex: [number, number]; imgList: IFileItem[]; }; }