Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
feat: add size and data to PointCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxuhai committed Oct 22, 2022
1 parent a2367fa commit b9d32d9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 24 deletions.
19 changes: 19 additions & 0 deletions src/modules/common/PointCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ export class Vector<T> {
return this._native.empty();
}

get data() {
const size = this.size;
const _data: T[] = [];

for (let i = 0; i < size; i++) {
_data.push(this._native.get(i));
}

return _data;
}

public resize(count: number, value?: T) {
this._native.resize(count, value ?? null);
}
Expand Down Expand Up @@ -147,6 +158,14 @@ class PointCloud<T extends PointTypes = PointXYZ> {
return this._points;
}

get isEmpty() {
return this.points.isEmpty();
}

get data() {
return this.points.data;
}

/**
* Removes all points in a cloud and sets the width and height to 0.
*/
Expand Down
9 changes: 9 additions & 0 deletions tests/common/PointCloud.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as PCL from '../../';
import { getTestPCDFile } from '../utils';

describe('PointCloud', () => {
it('should create a point cloud data with XYZ fields, `width` = 5, `height` = 1', async () => {
Expand All @@ -21,4 +22,12 @@ describe('PointCloud', () => {
cloud.manager.delete();
expect(cloud.manager.isDeleted()).toBe(true);
});

it('should get `size` and `data`', () => {
const data = getTestPCDFile('bun4.pcd');
const cloud = PCL.loadPCDData(data);

expect(cloud.size).toBe(361);
expect(cloud.data.length).toBe(361);
});
});
58 changes: 34 additions & 24 deletions website/docs/api/basic-structures.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,41 @@ sidebar_position: 2
new PointCloud();
```

### Members

#### isDense

#### isOrganized

#### points

#### width

#### height

#### header

#### size

### Methods

#### clear()

#### resize()

#### addPoint()
```ts showLineNumbers
class PointCloud<T extends PointTypes = PointXYZ> {
manager: Manager;
constructor(_PT?: PointTypesTypeof, _native?: NativeAPI);
get isOrganized(): boolean;
get isDense(): boolean;
set width(v: number);
get width(): number;
set height(v: number);
get height(): number;
get header(): PCLHeader;
get size(): number;
get points(): Points<T>;
get isEmpty(): boolean;
get data(): T[];
/**
* Removes all points in a cloud and sets the width and height to 0.
*/
clear(): void;
/**
* Resizes the container to contain `count` elements
* @params count - New size of the point cloud
* @params pt - The value to initialize the new points with
*/
resize(count: number, pt?: T): void;
/**
* Insert a new point in the cloud, at the end of the container.
* @description This breaks the organized structure of the cloud by setting the height to 1!
* @params pt - The point to insert
*/
addPoint(pt?: T | null): void;
}
```

#### manager
## Manager

```ts
class Manager {
Expand Down

1 comment on commit b9d32d9

@vercel
Copy link

@vercel vercel bot commented on b9d32d9 Oct 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pcl-js – ./

pcl-js-darkce.vercel.app
pcl-js-git-master-darkce.vercel.app
pcl.js.org
www.pcljs.org
pcljs.org

Please sign in to comment.