Skip to content

Commit

Permalink
feat(pointcloud): Add pointCloud count to annotationResult
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerwin-L committed Sep 21, 2022
1 parent 9c5178c commit 2195996
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 15 deletions.
22 changes: 16 additions & 6 deletions packages/lb-annotation/src/core/pointCloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,19 +454,19 @@ export class PointCloud {
const polygonPointList = [
{
x: center.x + width / 2,
y: center.y + height / 2,
y: center.y - height / 2,
},
{
x: center.x + width / 2,
y: center.y - height / 2,
y: center.y + height / 2,
},
{
x: center.x - width / 2,
y: center.y - height / 2,
y: center.y + height / 2,
},
{
x: center.x - width / 2,
y: center.y + height / 2,
y: center.y - height / 2,
},
].map((v) => {
const vector = this.rotatePoint(v, center, rotation);
Expand Down Expand Up @@ -819,10 +819,12 @@ export class PointCloud {
return canvas;
}

public getSensesPointZAxisInPolygon(polygon: IPolygonPoint[]) {
public getSensesPointZAxisInPolygon(polygon: IPolygonPoint[], zScope?: [number, number]) {
const points = this.scene.children.find((i) => i.uuid === this.pointsUuid) as THREE.Points;
let minZ = 0;
let maxZ = 0;
let count = 0;
let zCount = 0;

if (points && points?.geometry) {
const pointPosArray = points?.geometry.attributes.position;
Expand All @@ -838,11 +840,19 @@ export class PointCloud {
if (inPolygon && z) {
maxZ = Math.max(z, maxZ);
minZ = Math.min(z, minZ);

zCount++;

if (zScope) {
if (z >= zScope[0] && z <= zScope[1]) {
count++;
}
}
}
}
}

return { maxZ, minZ };
return { maxZ, minZ, count, zCount };
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PointCloudContainer } from './PointCloudLayout';
import React, { useEffect, useRef } from 'react';
import { PointCloudContext } from './PointCloudContext';
import { useSingleBox } from './hooks/useSingleBox';
import { EPerspectiveView, IPointCloudBox } from '@labelbee/lb-utils';
import { EPerspectiveView, IPointCloudBox, IPolygonPoint } from '@labelbee/lb-utils';
import { SizeInfoForView } from './PointCloudInfos';
import { connect } from 'react-redux';
import { aMapStateToProps, IAnnotationStateProps } from '@/store/annotation/map';
Expand Down Expand Up @@ -161,13 +161,30 @@ const PointCloudSideView = ({ currentData }: IAnnotationStateProps) => {
const oldWidth = MathUtils.getLineLength(op2, op3);
const offsetWidth = width - oldWidth; // 3D width

const { newBoxParams } = backPointCloud.getNewBoxByBackUpdate(
let { newBoxParams } = backPointCloud.getNewBoxByBackUpdate(
offsetCenterPoint,
offsetWidth,
offsetHeight,
ptCtx.selectedPointCloudBox,
);

// Update count
if (ptCtx.mainViewInstance) {
const { count } = ptCtx.mainViewInstance.getSensesPointZAxisInPolygon(
ptCtx.mainViewInstance.getCuboidFromPointCloudBox(newBoxParams)
.polygonPointList as IPolygonPoint[],
[
newBoxParams.center.z - newBoxParams.depth / 2,
newBoxParams.center.z + newBoxParams.depth / 2,
],
);

newBoxParams = {
...newBoxParams,
count,
};
}

synchronizeTopView(newBoxParams, newPolygon, ptCtx.topViewInstance, ptCtx.mainViewInstance);
synchronizeSideView(newBoxParams, newPolygon, ptCtx.sideViewInstance, currentData.url);
ptCtx.mainViewInstance.highlightOriginPointCloud(newBoxParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
* @createdate 2022-08-17
*/
import { PointCloudAnnotation, PointCloud, MathUtils } from '@labelbee/lb-annotation';
import { IPointCloudBox, EPerspectiveView, PointCloudUtils } from '@labelbee/lb-utils';
import {
IPointCloudBox,
EPerspectiveView,
PointCloudUtils,
IPolygonPoint,
} from '@labelbee/lb-utils';
import { useContext } from 'react';
import { PointCloudContext } from '../PointCloudContext';
import { useSingleBox } from './useSingleBox';
Expand Down Expand Up @@ -47,7 +52,7 @@ export const topViewPolygon2PointCloud = (
newPolygon: any,
size: ISize,
pointCloud?: PointCloud,
selectedPointCloud?: IPointCloudBox,
selectedPointCloudBox?: IPointCloudBox,
defaultValue?: { [v: string]: any },
) => {
const [point1, point2, point3, point4] = newPolygon.pointList.map((v: any) =>
Expand All @@ -60,15 +65,21 @@ export const topViewPolygon2PointCloud = (
const rotation = MathUtils.getRadiusFromQuadrangle(newPolygon.pointList);
let z = 0;
let depth = 1;
let extraData = {};

// Init PointCloud Data
if (pointCloud) {
const zInfo = pointCloud.getSensesPointZAxisInPolygon([point1, point2, point3, point4]);
z = (zInfo.maxZ + zInfo.minZ) / 2;
depth = zInfo.maxZ - zInfo.minZ;
extraData = {
count: zInfo.count,
};
}

if (selectedPointCloud) {
z = selectedPointCloud.center.z;
depth = selectedPointCloud.depth;
if (selectedPointCloudBox) {
z = selectedPointCloudBox.center.z;
depth = selectedPointCloudBox.depth;
}

/** TrackID will append before it pushed */
Expand All @@ -85,6 +96,7 @@ export const topViewPolygon2PointCloud = (
id: newPolygon.id,
attribute: '',
valid: true,
...extraData,
};

if (defaultValue) {
Expand Down Expand Up @@ -381,12 +393,28 @@ export const usePointCloudViews = () => {
*/
const viewUpdateBox = (newPolygon: any, originPolygon: any, fromView: string) => {
if (selectedPointCloudBox) {
const newBoxParams = sideViewPolygon2PointCloud(
let newBoxParams = sideViewPolygon2PointCloud(
newPolygon,
originPolygon,
selectedPointCloudBox,
sideViewInstance.pointCloudInstance,
);
// Update count
if (mainViewInstance) {
const { count } = mainViewInstance.getSensesPointZAxisInPolygon(
mainViewInstance.getCuboidFromPointCloudBox(newBoxParams)
.polygonPointList as IPolygonPoint[],
[
newBoxParams.center.z - newBoxParams.depth / 2,
newBoxParams.center.z + newBoxParams.depth / 2,
],
);

newBoxParams = {
...newBoxParams,
count,
};
}

updateSelectedBox(newBoxParams);
syncPointCloudViews(fromView, newPolygon, newBoxParams);
Expand All @@ -411,7 +439,7 @@ export const usePointCloudViews = () => {
const newBoxParams = topViewPolygon2PointCloud(
polygon,
size,
undefined,
topViewInstance.pointCloudInstance,
selectedPointCloudBox,
);

Expand Down

0 comments on commit 2195996

Please sign in to comment.