From e10b047318f975eeab1abde9a99b34a0157f4736 Mon Sep 17 00:00:00 2001 From: tanjunbao Date: Fri, 26 Aug 2022 10:00:58 +0800 Subject: [PATCH] feat: Point cloud annotation view --- packages/lb-annotation/package.json | 2 +- .../pointCloudAnnotationView.tsx | 62 +++++++++++++++++++ packages/lb-components/src/index.tsx | 3 +- packages/lb-demo/src/App.js | 26 ++++++-- 4 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 packages/lb-components/src/components/AnnotationView/pointCloudAnnotationView.tsx diff --git a/packages/lb-annotation/package.json b/packages/lb-annotation/package.json index e3006c295..38582b753 100644 --- a/packages/lb-annotation/package.json +++ b/packages/lb-annotation/package.json @@ -96,7 +96,7 @@ "color-rgba": "^2.3.0", "lodash": "^4.17.20" }, - "pureDependencies": { + "peerDependencies": { "three": ">=0.141.0" } } diff --git a/packages/lb-components/src/components/AnnotationView/pointCloudAnnotationView.tsx b/packages/lb-components/src/components/AnnotationView/pointCloudAnnotationView.tsx new file mode 100644 index 000000000..97d0a1533 --- /dev/null +++ b/packages/lb-components/src/components/AnnotationView/pointCloudAnnotationView.tsx @@ -0,0 +1,62 @@ +/* + * @Author: Laoluo luozefeng@sensetime.com + * @Date: 2022-06-13 19:31:36 + * @LastEditors: Laoluo luozefeng@sensetime.com + * @LastEditTime: 2022-06-27 19:43:25 + */ + +import { PointCloud } from '@labelbee/lb-annotation'; +import { IPointCloudBox, PointCloudUtils } from '@labelbee/lb-utils'; +import React, { useCallback, useEffect, useRef } from 'react'; + +interface IProps { + src: string; // 图片路径 + result: string; + size: { + width: number; + height: number; + }; +} + +const PointCloudAnnotationView = (props: IProps) => { + const { src, result, size } = props; + let viewOperation = useRef(); + const instance = useRef(); + + const refCallback = useCallback((node) => { + viewOperation.current = node; + }, []); + + useEffect(() => { + const pointCloud = new PointCloud({ + container: viewOperation.current, + backgroundColor: '#ccc', + }); + instance.current = pointCloud; + }, []); + + useEffect(() => { + instance.current?.init(); + }, [size]); + + useEffect(() => { + if (instance.current && src) { + instance.current?.loadPCDFile(src); + } + }, [src]); + + useEffect(() => { + if (result) { + const boxParamsList = PointCloudUtils.getBoxParamsFromResultList(result); + + // Add Init Box + boxParamsList.forEach((v: IPointCloudBox) => { + instance.current?.generateBox(v, v.id); + }); + } + }, [result]); + + return
; +}; + +export default PointCloudAnnotationView; diff --git a/packages/lb-components/src/index.tsx b/packages/lb-components/src/index.tsx index 55d6b6604..0a433a099 100644 --- a/packages/lb-components/src/index.tsx +++ b/packages/lb-components/src/index.tsx @@ -1,5 +1,6 @@ import { AppProps } from '@/App'; import AnnotationView from '@/components/AnnotationView'; +import PointCloudAnnotationView from '@/components/AnnotationView/pointCloudAnnotationView'; import { i18n } from '@labelbee/lb-utils'; import React, { useImperativeHandle, useState } from 'react'; import { I18nextProvider } from 'react-i18next'; @@ -48,4 +49,4 @@ const OutputApp = (props: AppProps, ref: any) => { export default React.forwardRef(OutputApp); -export { AnnotationView, i18n, VideoTagTool }; +export { AnnotationView, PointCloudAnnotationView, i18n, VideoTagTool }; diff --git a/packages/lb-demo/src/App.js b/packages/lb-demo/src/App.js index e39d25d36..cdc6dccce 100644 --- a/packages/lb-demo/src/App.js +++ b/packages/lb-demo/src/App.js @@ -4,10 +4,14 @@ * @LastEditors: Laoluo luozefeng@sensetime.com * @LastEditTime: 2022-06-13 19:34:53 */ +import { AnnotationView, PointCloudAnnotationView } from '@labelbee/lb-components'; +import StepUtils from '@labelbee/lb-components/dist/utils/StepUtils'; +import 'antd/dist/antd.css'; +import qs from 'qs'; import React, { useState } from 'react'; import './App.css'; -import 'antd/dist/antd.css'; import Annotation from './components/Annotation'; +import { DEFAULT_ANNOTATIONS } from './mock'; import { fileList as mockFileList, getMockResult, @@ -15,11 +19,7 @@ import { pointCloudMappingImgList, videoList, } from './mock/index'; -import { getStepList, getDependStepList } from './mock/taskConfig'; -import qs from 'qs'; -import { AnnotationView } from '@labelbee/lb-components'; -import { DEFAULT_ANNOTATIONS } from './mock'; -import StepUtils from '@labelbee/lb-components/dist/utils/StepUtils'; +import { getDependStepList, getStepList } from './mock/taskConfig'; const App = () => { const tool = qs.parse(window.location.search, { ignoreQueryPrefix: true, comma: true }).tool; @@ -72,6 +72,20 @@ const App = () => { ); } + if (tool === 'PointCloudAnnotationView') { + return ( + + ); + } + const goBack = (data) => { console.log('goBack', data); };