Skip to content

Commit

Permalink
Merge pull request #314 from open-mmlab/feat/pointCloudSegment-projec…
Browse files Browse the repository at this point in the history
…tion

feat(pointcloud): Support displaying status on hover
  • Loading branch information
Kerwin-L authored Sep 25, 2023
2 parents 8bf6b08 + e7a513e commit 0d36e52
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/lb-annotation/src/core/pointCloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export class PointCloud extends EventListener {
this.segmentOperation = new PointCloudSegmentOperation({
dom: this.container,
store: this.store,
...this.eventBus,
});

this.pointCloudRender = new PointCloudRender({
Expand Down
9 changes: 9 additions & 0 deletions packages/lb-annotation/src/core/pointCloud/segmentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { EPointCloudSegmentStatus } from '@labelbee/lb-utils';
import EventListener from '@/core/toolOperation/eventListener';
import LassoSelector from './selector/lassoSelector';
import PointCloudStore, { ThreePoints } from './store';
import CircleSelector from './selector/circleSelector';
Expand All @@ -13,6 +14,7 @@ import RectSelector from './selector/rectSelector';
interface IProps {
dom: HTMLElement;
store: PointCloudStore;
emit: EventListener['emit'];
}

class PointCloudSegmentOperation {
Expand All @@ -32,6 +34,8 @@ class PointCloudSegmentOperation {

public circleSelector: CircleSelector;

private emit: EventListener['emit'];

constructor(props: IProps) {
this.dom = props.dom;
this.store = props.store;
Expand All @@ -47,6 +51,7 @@ class PointCloudSegmentOperation {
this.updateSelector2Lasso = this.updateSelector2Lasso.bind(this);
this.updateSelector2Circle = this.updateSelector2Circle.bind(this);

this.emit = props.emit;
// this.setupRaycaster();
}

Expand Down Expand Up @@ -149,6 +154,10 @@ class PointCloudSegmentOperation {

const intersect = intersects[0];

this.emit('hoverSegmentInstance', {
segmentData: this.store.segmentData.get(intersect?.object?.name),
currentSegmentStatus: this.store.segmentStatus,
});
if (intersect) {
this.store.highlightPoints(intersect.object as ThreePoints);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ interface IProps {
updateColorConfig?: (value: string, color: string) => void;
updateSize?: (size: IDefaultSize) => void;
attributeLockChange?: (list: any) => void;
forbidShowLimitPopover?: boolean;
}

const AttributeList = React.forwardRef((props: IProps, ref) => {
Expand Down Expand Up @@ -93,7 +94,7 @@ const AttributeList = React.forwardRef((props: IProps, ref) => {
// Determine if a scope configuration exists
const hasLimit =
i?.limit?.positionLimit || defaultSize || sizeRange || logicalCondition?.length > 0;
const showLimitPopover = isChosen && hasLimit;
const showLimitPopover = isChosen && hasLimit && props.forbidShowLimitPopover !== true;

return (
<Radio value={i.value} ref={radioRef} key={i.label + index}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,36 @@ const PointCloudSegmentStatus = (props: { config: IPointCloudConfig }) => {
}
};

const updateHoverData = ({
segmentData,
currentSegmentStatus,
}: {
segmentData?: IPointCloudSegmentation;
currentSegmentStatus: EPointCloudSegmentStatus;
}) => {
// Just run in ready.
if (currentSegmentStatus !== EPointCloudSegmentStatus.Ready) {
return;
}

if (!segmentData) {
setData({
segmentStatus: EPointCloudSegmentStatus.Ready,
});
return;
}
setData({
segmentStatus: EPointCloudSegmentStatus.Hover,
cacheSegData: segmentData,
});
};

ptSegmentInstance?.on('syncPointCloudStatus', updateVisible);
ptSegmentInstance?.on('hoverSegmentInstance', updateHoverData);

return () => {
ptSegmentInstance?.unbind('syncPointCloudStatus', updateVisible);
ptSegmentInstance?.unbind('hoverSegmentInstance', updateHoverData);
};
}
}, [ptSegmentInstance]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
IDefaultSize,
EPointCloudSegmentStatus,
IPointCloudSegmentation,
EPointCloudPattern,
} from '@labelbee/lb-utils';
import AttributeList from '@/components/attributeList';
import { useAttribute } from '@/components/pointCloudView/hooks/useAttribute';
Expand Down Expand Up @@ -211,6 +212,22 @@ const BoxTrackIDInput = () => {
);
};

/**
* Determine if the
*/
const isAllowUpdateInSegment = ({
segmentStatus,
globalPattern,
}: {
segmentStatus: EPointCloudSegmentStatus;
globalPattern: EPointCloudPattern;
}) => {
return (
globalPattern === EPointCloudPattern.Segmentation &&
![EPointCloudSegmentStatus.Edit, EPointCloudSegmentStatus.Ready].includes(segmentStatus)
);
};

const AttributeUpdater = ({
attributeList,
subAttributeList,
Expand Down Expand Up @@ -241,6 +258,7 @@ const AttributeUpdater = ({
const { t } = useTranslation();
const { defaultAttribute } = useAttribute();
const pointCloudViews = usePointCloudViews();
const { isPointCloudSegmentationPattern } = useStatus();

const dispatch = useDispatch();

Expand Down Expand Up @@ -298,10 +316,28 @@ const AttributeUpdater = ({
};

const setAttribute = (attribute: string) => {
if (
isAllowUpdateInSegment({
globalPattern: ptx.globalPattern,
segmentStatus: segmentData.segmentStatus,
})
) {
return;
}

toolInstance.setDefaultAttribute(attribute);
};

const setSubAttribute = (key: string, value: string) => {
if (
isAllowUpdateInSegment({
globalPattern: ptx.globalPattern,
segmentStatus: segmentData.segmentStatus,
})
) {
return;
}

toolInstance.setSubAttribute(key, value);
};

Expand All @@ -313,6 +349,13 @@ const AttributeUpdater = ({
isDefault: i?.isDefault,
}));

const isSelected =
selectedBox ||
(segmentData.cacheSegData && segmentData.segmentStatus === EPointCloudSegmentStatus.Edit);

// Just segment pattern forbid limitPopover
const forbidShowLimitPopover = isPointCloudSegmentationPattern;

return (
<div>
<div style={titleStyle}>{t('Attribute')}</div>
Expand All @@ -324,9 +367,10 @@ const AttributeUpdater = ({
updateColorConfig={updateColorConfig}
enableColorPicker={enableColorPicker}
updateSize={updateSize}
forbidShowLimitPopover={forbidShowLimitPopover}
/>
<Divider style={{ margin: 0 }} />
{(selectedBox || segmentData.cacheSegData) && (
{isSelected && (
<>
{subAttributeList.map(
(subAttribute) =>
Expand Down
1 change: 1 addition & 0 deletions packages/lb-utils/src/constant/pointCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ export enum EPointCloudSegmentStatus {
Ready = 'READY',
Check = 'CHECK',
Edit = 'EDIT',
Hover = "HOVER",
}

0 comments on commit 0d36e52

Please sign in to comment.