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

Commit

Permalink
docs: add Simple Example to readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxuhai committed Aug 26, 2022
1 parent 127f2ed commit 0d7914b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
33 changes: 33 additions & 0 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,39 @@ async function main() {
main();
</script>
```
### 简单示例
```typescript
import PCL from 'pcl.js';

async function main() {
const pcl = await PCL.init({
url: 'https://cdn.jsdelivr.net/npm/pcl.js/dist/pcl-core.wasm',
});
// 写入 PCD 文件
pcl.Module.FS.writeFile('/test.pcd', ArrayBuffer);
// 加载 PCD 文件,返回点云对象
const pointCloud = pcl.io.loadPCDFile('/test.pcd');

// 使用 PassThrough 过滤器过滤点云, 参考: https://pcl.readthedocs.io/projects/tutorials/en/master/passthrough.html#passthrough
const pass = new pcl.filters.PassThrough();
pass.setInputCloud(pointCloud);
pass.setFilterFieldName('z');
pass.setFilterLimits(0.0, 1.0);
pass.filter(pointCloud);

// 将过滤后的点云对象保存为 PCD 文件
pcl.io.savePCDFileASCII('/test-filtered.pcd', pointCloud);
// 读取 PCD 文件内容, 内容为 ArrayBuffer
const pcd = pcl.Module.FS.readFile('/test-filtered.pcd');

// 删除所有 PCD 文件
pcl.Module.FS.unlink('/test.pcd')
pcl.Module.FS.unlink('/test-filtered.pcd')
// ...
}

main();
```

## 资源大小

Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,41 @@ main();
</script>
```

### Simple Example
```typescript
import PCL from 'pcl.js';

async function main() {
const pcl = await PCL.init({
url: 'https://cdn.jsdelivr.net/npm/pcl.js/dist/pcl-core.wasm',
});
// Write a PCD file
pcl.Module.FS.writeFile('/test.pcd', ArrayBuffer);
// Load PCD file, return point cloud object
const pointCloud = pcl.io.loadPCDFile('/test.pcd');

// Filtering a PointCloud using a PassThrough filter, see: https://pcl.readthedocs.io/projects/tutorials/en/master/passthrough.html#passthrough
const pass = new pcl.filters.PassThrough();
pass.setInputCloud(pointCloud);
pass.setFilterFieldName('z');
pass.setFilterLimits(0.0, 1.0);
pass.filter(pointCloud);

// Save filtered point cloud objects as PCD files
pcl.io.savePCDFileASCII('/test-filtered.pcd', pointCloud);
// Read PCD file content, the content is ArrayBuffer
const pcd = pcl.Module.FS.readFile('/test-filtered.pcd');

// Delete all PCD files
pcl.Module.FS.unlink('/test.pcd')
pcl.Module.FS.unlink('/test-filtered.pcd')
// ...
}

main();
```


## Bundle Size

> PCL.js Version: 0.2.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pcl.js",
"version": "0.2.0",
"version": "0.2.1",
"description": "PCL for browser and node, powered by WebAssembly.",
"types": "dist/types/pcl.d.ts",
"main": "dist/pcl.cjs.js",
Expand Down

1 comment on commit 0d7914b

@vercel
Copy link

@vercel vercel bot commented on 0d7914b Aug 26, 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
pcljs.org
pcl-js-git-master-darkce.vercel.app
www.pcljs.org

Please sign in to comment.