Skip to content

Commit

Permalink
Merge pull request #601 from Original-Recipe/feat-optimizeAttrSwitch
Browse files Browse the repository at this point in the history
feat: Optimize the main attribute problem to improve performance
  • Loading branch information
lihqi authored Nov 1, 2024
2 parents 281f813 + 786262f commit 22955c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 36 deletions.
16 changes: 4 additions & 12 deletions packages/lb-annotation/src/core/pointCloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ export class PointCloud extends EventListener {

private geometry: THREE.BufferGeometry;

private filterBoxWorkerTimer: ReturnType<typeof setTimeout> | null = null;

private highlightColor = 0xffff00;

constructor({
Expand Down Expand Up @@ -855,17 +853,11 @@ export class PointCloud extends EventListener {
this.geometry.setAttribute('color', new THREE.Float32BufferAttribute(newColor, 3));
this.geometry.computeBoundingSphere();

if (this.filterBoxWorkerTimer) {
clearTimeout(this.filterBoxWorkerTimer);
// Calculation completed, worker terminated, and destroyed
if (this.filterBoxWorker) {
this.filterBoxWorker.terminate();
this.filterBoxWorker = null;
}
// The creation of Worker themselves is time-consuming. Detect within 3 seconds whether the user still needs to use Worker to calculate
this.filterBoxWorkerTimer = setTimeout(() => {
if (this.filterBoxWorker) {
this.filterBoxWorker.terminate();
this.filterBoxWorker = null;
}
}, 3000);

resolve({ geometry: this.geometry, num });
};
});
Expand Down
9 changes: 5 additions & 4 deletions packages/lb-components/src/components/attributeList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ILimit, IDefaultSize } from '@labelbee/lb-utils';
import LimitPopover from './components/limitPopover';
import _ from 'lodash';
import { CommonToolUtils, MathUtils } from '@labelbee/lb-annotation';
import { useDebounceFn } from 'ahooks';

export const ATTRIBUTE_COLORS = [NULL_COLOR].concat(COLORS_ARRAY);

Expand Down Expand Up @@ -91,9 +92,10 @@ const AttributeList = React.forwardRef((props: IProps, ref) => {
}
};

const { run: keydownEventsDebounce } = useDebounceFn(keyDown, { wait: 200 });
useEffect(() => {
window.addEventListener('keydown', keyDown);
return () => window.removeEventListener('keydown', keyDown);
window.addEventListener('keydown', keydownEventsDebounce);
return () => window.removeEventListener('keydown', keydownEventsDebounce);
});

const changeColor = (value: string, color: string) => {
Expand All @@ -109,8 +111,7 @@ const AttributeList = React.forwardRef((props: IProps, ref) => {
}
props.attributeChanged(e.target.value);
};

const attributeClickDebounce = _.debounce(attributeClick, 100);
const { run: attributeClickDebounce } = useDebounceFn(attributeClick, { wait: 100 });

const checkLock = (e: any, attributeInfo: any) => {
if (props?.forbidColor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import { useBoxes } from './hooks/useBoxes';
import { useSingleBox } from './hooks/useSingleBox';
import { useSphere } from './hooks/useSphere';
import React, { useContext, useEffect } from 'react';
import {
cTool,
AttributeUtils,
CommonToolUtils,
EToolName,
EPointCloudName,
} from '@labelbee/lb-annotation';
import { cTool, CommonToolUtils, EToolName } from '@labelbee/lb-annotation';
import { message } from 'antd';
import { connect } from 'react-redux';
import { a2MapStateToProps, IA2MapStateProps } from '@/store/annotation/map';
Expand Down Expand Up @@ -188,19 +182,8 @@ const PointCloudListener: React.FC<IProps> = ({
deleteSelectedPointCloudBoxAndPolygon(currentDataRef.current);
break;

default: {
if (config.attributeList?.length > 0) {
const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(
e.keyCode,
config.attributeList,
);

if (keyCode2Attribute !== undefined) {
toolInstanceRef.current?.setDefaultAttribute(keyCode2Attribute);
}
}
return;
}
default:
break;
}
};

Expand Down

0 comments on commit 22955c3

Please sign in to comment.