Skip to content

Commit

Permalink
fix(pointcloud): Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Apr 13, 2023
2 parents feb27bf + 581a682 commit c838753
Show file tree
Hide file tree
Showing 45 changed files with 1,325 additions and 249 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/labelbee-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Publish
on:
release:
types: [published]
push:
branches: ["release", "beta", "alpha"]

jobs:
publish:
Expand Down
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,47 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [1.13.0](https://github.com/open-mmlab/labelbee/compare/v1.12.1...v1.13.0) (2023-04-12)


### Features

* Extract "FooterPopover" component and uses in annotatedList ([753a7b2](https://github.com/open-mmlab/labelbee/commit/753a7b24f7848bb7e32fa8c85b50cfb2e2fd8351))
* **pointcloud:** 3Dview sync the direction with topview after selected ([7ed2855](https://github.com/open-mmlab/labelbee/commit/7ed285580defef82c75cb404cf42d5df66bc3bba))
* **pointcloud:** Adding component for selecting boxes by attribute ([5e6b648](https://github.com/open-mmlab/labelbee/commit/5e6b6487d4c3e30e6dccd8673d60e285ab6119b7))
* **pointcloud:** Annotated-Attributes-Panel supports fixed layout ([f698cf1](https://github.com/open-mmlab/labelbee/commit/f698cf1fc77769eeaedff3e2f920e04947a0a56f))
* **pointcloud:** Confirm before deleteGraphByAttr ([e8759ac](https://github.com/open-mmlab/labelbee/commit/e8759acd88c7476348ae6031d1d00ad9eac6ea5b))
* **pointcloud:** Follow top add tooltip ([f0c360e](https://github.com/open-mmlab/labelbee/commit/f0c360e4fbffa6b9ecf7bb10dfc3e0a7a5221bc0))
* **pointcloud:** Hide the operation in checkmode(side&backView) ([a12901e](https://github.com/open-mmlab/labelbee/commit/a12901e208bed684561ede01d154195a9c7a5680))
* **pointcloud:** MainView support to follow top view ([81fba17](https://github.com/open-mmlab/labelbee/commit/81fba17476d3f458f38293fe921058118cb4fbb0))
* **pointcloud:** Support select spec attribute boxes ([05228c5](https://github.com/open-mmlab/labelbee/commit/05228c5c66bb73166e486b51bab151e204176687))
* **pointcloud:** Support selecting polygons by attributes ([b0b4a43](https://github.com/open-mmlab/labelbee/commit/b0b4a431a79ebeb6e0e368a18071fdd916f601a5))
* **pointcloud:** Support updating position by keydown events ([12e6d68](https://github.com/open-mmlab/labelbee/commit/12e6d686a598f64e1ef3da4c4b3db56b90055c58))
* **pointcloud:** Supports moving multiple selected rects ([dbfa665](https://github.com/open-mmlab/labelbee/commit/dbfa6652bf54eba141799681bf7eb1b74294c178))
* **pointcloud:** Supports rendering after moving multi-boxes ([4228988](https://github.com/open-mmlab/labelbee/commit/42289888e0883ccdc8a07cfb3c9b42fd8c4f944c))
* **pointcloud:** Update the backgroundColor of pointCloud ([df16fdc](https://github.com/open-mmlab/labelbee/commit/df16fdc87df911088e800527274cf36cb492da99))


### Bug Fixes

* **copy-result:** AsyncData needs to determine if it exists ([17dc99a](https://github.com/open-mmlab/labelbee/commit/17dc99a7633e01541650e948d7eeb436a83c1691))
* **pointcloud:** Fix applyCameraTarget not to apply zoom ([c7b426a](https://github.com/open-mmlab/labelbee/commit/c7b426a6b75b458f4e126cee1df923c44255f5f0))
* **pointcloud:** Fix attribute list hide attr fail ([7d4d28d](https://github.com/open-mmlab/labelbee/commit/7d4d28d51c7bf49c92b05d9a9957fdb21471f72e))
* **pointcloud:** Fix size changed and init point cloud result ([f940e42](https://github.com/open-mmlab/labelbee/commit/f940e42d16f66394469e2b46264937418d136856))
* **pointcloud:** Fix the feature of COPY_BACKWARD_RESULT ([26b3062](https://github.com/open-mmlab/labelbee/commit/26b30624c23267deb262417d4a103c71dee90f7d))
* **pointcloud:** Init hideAttr while imgIndex changed ([99e5642](https://github.com/open-mmlab/labelbee/commit/99e5642d435f62332434c81537ad5360f48e73cf))
* **pointcloud:** Prevent default event on ctrl + a ([cf2d147](https://github.com/open-mmlab/labelbee/commit/cf2d147005911fb58c497e1e25b0bc4675fc61af))
* **pointcloud:** Repeated updates of pointCloudBackView ([bfe634a](https://github.com/open-mmlab/labelbee/commit/bfe634a5f57e6e1ca33547e7b950f7612a6fe449))
* **pointcloud:** SyncTopview doesn't need to update camera ([634ca61](https://github.com/open-mmlab/labelbee/commit/634ca6196e95a710b762e419ad5800044eab9d24))
* **pointcloud:** Update attr list style ([d26691e](https://github.com/open-mmlab/labelbee/commit/d26691ec248fc940e63e53850fb2c0ba5ae42e17))

### [1.12.1](https://github.com/open-mmlab/labelbee/compare/v1.12.0...v1.12.1) (2023-03-23)


### Bug Fixes

* **view-operation:** Update the range of direction judgement ([943c2b0](https://github.com/open-mmlab/labelbee/commit/943c2b0dbb025c983352f12d16793b508b4c15ce))

## [1.12.0](https://github.com/open-mmlab/labelbee/compare/v1.11.0...v1.12.0) (2023-03-09)


Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "labelbee",
"private": true,
"version": "1.12.0",
"version": "1.13.0",
"scripts": {
"start": "lerna run build:type && lerna run --parallel --stream start",
"start:quick": "lerna run --parallel --stream start",
Expand All @@ -14,7 +14,8 @@
"version": "lerna version --conventional-graduate --yes",
"publish": "lerna publish from-package --yes",
"commit": "cz",
"release": "standard-version"
"release": "standard-version",
"prerelease": "lerna version prerelease --conventional-graduate --yes"
},
"main": "index.js",
"license": "Apache-2.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/lb-annotation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@labelbee/lb-annotation",
"version": "1.13.0-alpha.1",
"version": "1.13.0",
"description": "Annotation tool collection",
"keywords": [
"annotation",
Expand Down Expand Up @@ -92,7 +92,7 @@
"typescript": "^4.2.3"
},
"dependencies": {
"@labelbee/lb-utils": "^1.6.0-alpha.1",
"@labelbee/lb-utils": "^1.6.0",
"@turf/turf": "5.1.6",
"color-rgba": "^2.3.0",
"lodash": "^4.17.20",
Expand Down
128 changes: 103 additions & 25 deletions packages/lb-annotation/src/core/pointCloud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import {
I3DSpaceCoord,
IPointCloudConfig,
toolStyleConverter,
PointCloudUtils,
} from '@labelbee/lb-utils';
import { BufferAttribute, OrthographicCamera, PerspectiveCamera, PointsMaterial, Shader } from 'three';
import HighlightWorker from 'web-worker:./highlightWorker.js';
import FilterBoxWorker from 'web-worker:./filterBoxWorker.js';
import { isInPolygon } from '@/utils/tool/polygonTool';
import { IPolygonPoint } from '@/types/tool/polygon';
import uuid from '@/utils/uuid';
import MathUtils from '@/utils/MathUtils';
import { PCDLoader } from './PCDLoader';
import { OrbitControls } from './OrbitControls';
import { PointCloudCache } from './cache';
Expand Down Expand Up @@ -105,7 +107,7 @@ export class PointCloud {
noAppend,
isOrthographicCamera,
orthographicParams,
backgroundColor = 'black',
backgroundColor = '#4C4C4C', // GRAY_BACKGROUND
config,
}: IProps) {
this.container = container;
Expand Down Expand Up @@ -414,10 +416,19 @@ export class PointCloud {
* Update Camera position & target
* @param boxParams
* @param perspectiveView
* @param customCameraVector Provide a custom way.
*/
public updateCameraByBox(boxParams: IPointCloudBox, perspectiveView: EPerspectiveView) {
public updateCameraByBox(
boxParams: IPointCloudBox,
perspectiveView: EPerspectiveView,
customCameraVector?: I3DSpaceCoord,
) {
const { center, width, height, depth, rotation } = boxParams;
const cameraPositionVector = this.getCameraVector(center, rotation, { width, height, depth }, perspectiveView);
if (customCameraVector) {
this.updateCamera(customCameraVector, center);
return new THREE.Vector3(customCameraVector.x, customCameraVector.y, customCameraVector.z);
}
this.updateCamera(cameraPositionVector, center);
return cameraPositionVector;
}
Expand Down Expand Up @@ -504,7 +515,7 @@ export class PointCloud {

if (camera) {
const cameraTarget = this.getOrthographicCameraTarget(camera as OrthographicCamera);
this.camera.zoom = camera.zoom;
this.updateCameraZoom(camera.zoom);
this.updateCamera(camera.position, cameraTarget);
}
};
Expand Down Expand Up @@ -873,39 +884,106 @@ export class PointCloud {
return canvas;
}

public getSensesPointZAxisInPolygon(polygon: IPolygonPoint[], zScope?: [number, number]) {
/**
* Filter road points and noise in all directions
* 1. The first 5% of the z-axis is used as the road coordinate
* 2. Filter out points 10cm above the road surface.
* 3. Filter out the first 0.5% of noise points in other directions
*/
public filterNoise(pointList: I3DSpaceCoord[]) {
let newPointList = [...pointList];
newPointList.sort((a, b) => a.z - b.z);

const startIndexZ = Math.floor(newPointList.length * 0.05);
const roadPoint = newPointList[startIndexZ];
newPointList = newPointList.filter(({ z }) => z > roadPoint.z + 0.1);

const noisePercent = 0.005;
const endIndexZ = Math.floor(newPointList.length * (1 - noisePercent));
newPointList = newPointList.slice(0, endIndexZ);

newPointList.sort((a, b) => a.x - b.x);
const startIndexX = Math.floor(newPointList.length * noisePercent);
const endIndexX = Math.floor(newPointList.length * (1 - noisePercent));
newPointList = newPointList.slice(startIndexX, endIndexX);

newPointList.sort((a, b) => a.y - b.y);
const startIndexY = Math.floor(newPointList.length * noisePercent);
const endIndexY = Math.floor(newPointList.length * (1 - noisePercent));
newPointList = newPointList.slice(startIndexY, endIndexY);

return newPointList.length > 100 ? newPointList : pointList;
}

// Get the polygon coordinates after fitting
public getFittedCoordinates(polygon: IPolygonPoint[], innerPointList: ICoordinate[]) {
const minDistanceList: Array<{ distance: number; point: ICoordinate }> = [];
let _polygon = [...polygon, polygon[0]];
innerPointList.forEach(({ x, y }) => {
polygon.forEach((p1, index) => {
const p2 = _polygon[index + 1];
const distance = MathUtils.getFootOfPerpendicular({ x, y }, p1, p2, false, true).length;
if (!minDistanceList[index] || distance < minDistanceList[index].distance) {
minDistanceList[index] = { distance, point: { x, y } };
}
});
});

// todo: should leave a little margin
_polygon = [polygon[polygon.length - 1], ...polygon, polygon[0]];
const _minDistanceList = [minDistanceList[minDistanceList.length - 1], ...minDistanceList];
const fittedCoordinates = polygon.map((_, index) => {
const p1 = _polygon[index];
const p2 = _polygon[index + 1];
const p3 = _polygon[index + 2];
return PointCloudUtils.getIntersectionBySlope({
p1: _minDistanceList[index].point,
k1: (p1.y - p2.y) / (p1.x - p2.x),
p2: _minDistanceList[index + 1].point,
k2: (p2.y - p3.y) / (p2.x - p3.x),
});
});
return fittedCoordinates;
}

public getSensesPointZAxisInPolygon(polygon: IPolygonPoint[], zScope?: [number, number], intelligentFit?: boolean) {
const points = this.scene.children.find((i) => i.uuid === this.pointsUuid) as THREE.Points;
let minZ = 0;
let maxZ = 0;
let count = 0; // The count of scope
let zCount = 0; // The Count of Polygon range
let fittedCoordinates: ICoordinate[] = []; // Vertex coordinates after fitting(ThreeJs coordinates)
let innerPointList: I3DSpaceCoord[] = []; // Points within the polygon range

if (points && points?.geometry) {
const pointPosArray = points?.geometry.attributes.position.array;

for (let idx = 0; idx < pointPosArray.length; idx += 3) {
const x = pointPosArray[idx];
const y = pointPosArray[idx + 1];
const z = pointPosArray[idx + 2];

const inPolygon = isInPolygon({ x, y }, polygon);

if (inPolygon && z) {
maxZ = Math.max(z, maxZ);
minZ = Math.min(z, minZ);
if (!points?.geometry) {
return { maxZ, minZ, count, zCount, fittedCoordinates: [] };
}

zCount++;
const pointPosArray = points?.geometry.attributes.position.array;

if (zScope) {
if (z >= zScope[0] && z <= zScope[1]) {
count++;
}
}
}
for (let idx = 0; idx < pointPosArray.length; idx += 3) {
const x = pointPosArray[idx];
const y = pointPosArray[idx + 1];
const z = pointPosArray[idx + 2];
const inPolygon = isInPolygon({ x, y }, polygon);
if (inPolygon && (z || z === 0)) {
innerPointList.push({ x, y, z });
}
}

return { maxZ, minZ, count, zCount };
if (intelligentFit) {
innerPointList = this.filterNoise(innerPointList);
fittedCoordinates = this.getFittedCoordinates(polygon, innerPointList);
}
innerPointList.sort((a, b) => a.z - b.z);
minZ = innerPointList[0].z - 0.01;
maxZ = innerPointList[innerPointList.length - 1].z + 0.01;
zCount = innerPointList.length;
if (zScope) {
count = innerPointList.filter(({ z }) => z >= zScope[0] && z <= zScope[1]).length;
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export default class ViewOperation extends BasicToolOperation {
newPointList = DrawUtils.drawPolygon(this.canvas, renderLineWithZoom, lineRenderOptions);
}

const isShowDirection = line?.showDirection === true && line?.pointList?.length > 2;
const isShowDirection = line?.showDirection === true && line?.pointList?.length >= 2;

// 是否展示方向
if (isShowDirection) {
Expand Down Expand Up @@ -460,7 +460,7 @@ export default class ViewOperation extends BasicToolOperation {
newPointList = DrawUtils.drawPolygon(this.canvas, renderPolygon, polygonRenderOptions);
}

const isShowDirection = polygon?.showDirection === true && polygon?.pointList?.length > 2;
const isShowDirection = polygon?.showDirection === true && polygon?.pointList?.length >= 2;

// 是否展示方向
if (isShowDirection) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IBasicText } from '@labelbee/lb-utils';
import { IBasicText, toolStyleConverter } from '@labelbee/lb-utils';
import { isNumber } from 'lodash';
import { styleDefaultConfig } from '@/constant/defaultConfig';
import { EOperationMode, EToolName } from '@/constant/tool';
import { IPolygonConfig, IPolygonData } from '@/types/tool/polygon';
import MathUtils from '@/utils/MathUtils';
Expand Down Expand Up @@ -1175,22 +1174,18 @@ class BasicToolOperation extends EventListener {
this.emit('updateResult');
}

/** 获取当前属性颜色 */
/** Get the current property color */
public getColor(attribute = '', config = this.config) {
if (config?.attributeConfigurable === true && this.style.attributeColor) {
const attributeIndex = AttributeUtils.getAttributeIndex(attribute, config.attributeList ?? []) + 1;
return this.style.attributeColor[attributeIndex];
}
const { color, toolColor } = this.style;
if (toolColor) {
return toolColor[color];
}
return styleDefaultConfig.toolColor['1'];
return toolStyleConverter.getColorByConfig({ attribute, config, style: this.style });
}

public getLineColor(attribute = '') {
if (this.config?.attributeConfigurable === true) {
const attributeIndex = AttributeUtils.getAttributeIndex(attribute, this.config?.attributeList ?? []) + 1;
const color = this.config?.attributeList?.find((i: any) => i.value === attribute)?.color;
if (color) {
return toolStyleConverter.getColorByConfig({ attribute, config: this.config })?.valid?.stroke;
}
return this.style.attributeLineColor ? this.style.attributeLineColor[attributeIndex] : '';
}
const { color, lineColor } = this.style;
Expand Down
3 changes: 2 additions & 1 deletion packages/lb-annotation/src/utils/MathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export default class MathUtils {
end: ICoordinate,
/* 使用坐标范围 */
useAxisRange = false,
allowOverRange = false,
) => {
// 直线结束点
let retVal: any = { x: 0, y: 0 };
Expand Down Expand Up @@ -183,7 +184,7 @@ export default class MathUtils {

const isOverRange = useAxisRange ? allAxisOverRange : someAxisOverRange;

if (isOverRange) {
if (!allowOverRange && isOverRange) {
return {
footPoint: retVal,
length: Infinity,
Expand Down
24 changes: 23 additions & 1 deletion packages/lb-annotation/src/utils/tool/AttributeUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isNumber } from 'lodash';
import { ToolStyleUtils } from '@labelbee/lb-utils';
import { ELang } from '../../constant/annotation';
import { IPolygonData } from '../../types/tool/polygon';
import { COLORS_ARRAY, ICON_ARRAY, INVALID_ICON, NULL_COLOR, NULL_ICON } from '../../constant/style';
Expand Down Expand Up @@ -254,14 +255,35 @@ export default class AttributeUtils {
baseIcon: any,
) {
if (attributeConfigurable === true) {
// 含有属性配置
// Open attribute configuration
const attributeIndex = (attributeList?.findIndex((i: any) => i?.value === attribute) % COLORS_ARRAY.length) + 1;
const color = attributeList?.find((i: any) => i.value === attribute)?.color;
if (color) {
const getHexColor = ToolStyleUtils.rgbaStringToHex(color);
return this.generateIconAttribute({ fill: getHexColor });
}
return ICON_ARRAY[attributeIndex];
}

return baseIcon;
}

public static generateIconAttribute({
fill,
width = 16,
height = 16,
xmlns = 'http://www.w3.org/2000/svg',
xlink = 'http://www.w3.org/1999/xlink',
}: {
fill?: string;
width?: number;
height?: number;
xmlns?: string;
xlink?: string;
}) {
return `<span style={color:${fill}}><svg xmlns=${xmlns} xmlns:xlink=${xlink} width=${width} height=${height} viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill='currentColor'/></g></g></svg></span>`;
}

/**
* 根据keycode返回attribute, 没有匹配到时为undefined
* @param keyCode
Expand Down
Loading

0 comments on commit c838753

Please sign in to comment.