feat:调整为分别调用
parent
ef90958618
commit
9f31523913
|
@ -1,2 +1,3 @@
|
||||||
|
.idea/
|
||||||
/build/
|
/build/
|
||||||
/cmake-build-debug/
|
/cmake-build-debug/
|
||||||
|
|
|
@ -1,24 +1,65 @@
|
||||||
// pcl_wrapper.cpp
|
|
||||||
#include <pcl/io/pcd_io.h>
|
#include <pcl/io/pcd_io.h>
|
||||||
#include <pcl/filters/voxel_grid.h>
|
#include <pcl/filters/voxel_grid.h>
|
||||||
#include <pcl/point_types.h>
|
#include <pcl/point_types.h>
|
||||||
|
|
||||||
|
using PointType = pcl::PointXYZ;
|
||||||
|
|
||||||
|
class PclPointCloud {
|
||||||
|
public:
|
||||||
|
pcl::PointCloud<PointType>::Ptr cloud;
|
||||||
|
|
||||||
|
PclPointCloud() : cloud(new pcl::PointCloud<PointType>) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class PclVoxelGrid {
|
||||||
|
public:
|
||||||
|
pcl::VoxelGrid<PointType> filter;
|
||||||
|
};
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
int filter_pcd(const char* input_path, const char* output_path, float leaf_size) {
|
void* create_point_cloud() {
|
||||||
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
|
return new PclPointCloud();
|
||||||
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);
|
|
||||||
|
|
||||||
if (pcl::io::loadPCDFile<pcl::PointXYZ>(input_path, *cloud) == -1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
pcl::VoxelGrid<pcl::PointXYZ> sor;
|
|
||||||
sor.setInputCloud(cloud);
|
|
||||||
sor.setLeafSize(leaf_size, leaf_size, leaf_size);
|
|
||||||
sor.filter(*cloud_filtered);
|
|
||||||
|
|
||||||
pcl::io::savePCDFile(output_path, *cloud_filtered);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
void delete_point_cloud(void* ptr) {
|
||||||
|
delete static_cast<PclPointCloud*>(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
int load_point_cloud(void* ptr, const char* path) {
|
||||||
|
auto* cloud = static_cast<PclPointCloud*>(ptr);
|
||||||
|
return pcl::io::loadPCDFile<PointType>(path, *cloud->cloud);
|
||||||
|
}
|
||||||
|
|
||||||
|
int save_point_cloud(void* ptr, const char* path) {
|
||||||
|
auto* cloud = static_cast<PclPointCloud*>(ptr);
|
||||||
|
return pcl::io::savePCDFileBinary(path, *cloud->cloud);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* create_voxel_filter() {
|
||||||
|
return new PclVoxelGrid();
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete_voxel_filter(void* ptr) {
|
||||||
|
delete static_cast<PclVoxelGrid*>(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_voxel_leaf_size(void* ptr, float lx, float ly, float lz) {
|
||||||
|
auto* vf = static_cast<PclVoxelGrid*>(ptr);
|
||||||
|
vf->filter.setLeafSize(lx, ly, lz);
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_voxel_input_cloud(void* vf_ptr, void* cloud_ptr) {
|
||||||
|
auto* vf = static_cast<PclVoxelGrid*>(vf_ptr);
|
||||||
|
auto* cloud = static_cast<PclPointCloud*>(cloud_ptr);
|
||||||
|
vf->filter.setInputCloud(cloud->cloud);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* apply_voxel_filter(void* vf_ptr) {
|
||||||
|
auto* vf = static_cast<PclVoxelGrid*>(vf_ptr);
|
||||||
|
auto* result = new PclPointCloud();
|
||||||
|
vf->filter.filter(*result->cloud);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue