Find the extreme value of the point cloud, find the maximum and minimum values of xyz,
method one
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/common/common.h>
using namespace std;
int
main()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile<pcl::PointXYZ>("data//bunny.pcd", *cloud);
pcl::PointXYZ minPt, maxPt;
pcl::getMinMax3D (*cloud, minPt, maxPt);
cout << "Min x: " << minPt.x << endl;
cout << "Min y: " << minPt.y << endl;
cout << "Min z: " << minPt.z << endl;
cout << "Max x: " << maxPt.x << endl;
cout << "Max y: " << maxPt.y << endl;
cout << "Max z: " << maxPt.z << endl;
return (0);
}
Method Two
#include <iostream>
#include <algorithm>
#include <Eigen/Core>
#include <pcl/io/pcd_io.h>
using namespace std;
Eigen::Vector3f ComputeMaxBound(const std::vector<Eigen::Vector3f>& points)
{
if (points.empty()) {
return Eigen::Vector3f(0.0, 0.0, 0.0);
}
return std::accumulate(
points.begin(), points.end(), points[0],
[](const Eigen::Vector3f& a, const Eigen::Vector3f& b) {
return a.array().max(b.array()).matrix();
});
}
Eigen::Vector3f ComputeMinBound(const std::vector<Eigen::Vector3f>& points)
{
if (points.empty()) {
return Eigen::Vector3f(0.0, 0.0, 0.0);
}
return std::accumulate(
points.begin(), points.end(), points[0],
[](const Eigen::Vector3f& a, const Eigen::Vector3f& b) {
return a.array().min(b.array()).matrix();
});
}
int main(int argc, char** argv)
{
// ---------------------------加载点云数据--------------------------
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile<pcl::PointXYZ>("data//bunny.pcd", *cloud);
// ---------------------------计算点云最值--------------------------
vector<Eigen::Vector3f>points;
for (const auto& point_i : *cloud)
{
points.push_back(point_i.getVector3fMap());
}
Eigen::Vector3f max_pts, min_pts;
max_pts = ComputeMaxBound(points);
min_pts = ComputeMinBound(points);
cout << "点云坐标的最大值为:\n " << max_pts << endl;
cout << "点云坐标的最小值为:\n " << min_pts << endl;
return (0);
}
cpc segmentation of point cloud
//生成CPC分割器
pcl::CPCSegmentation<PointT>::CPCSegmentation seg;
//输入超体聚类结果
seg.setInputSupervoxels(supervoxel_clusters,supervoxel_adjacency);
//设置分割参数
setCutting (max_cuts = 20,
cutting_min_segments = 0,
cutting_min_score = 0.16,
locally_constrained = true,
directed_cutting = true,
clean_cutting = false);
seg.setRANSACIterations (ransac_iterations);
seg.segment();
seg.relabelCloud (pcl::PointCloud<pcl::PointXYZL> &labeled_cloud_arg);
#################cpc分割############
pcl::SupervoxelClustering<pcl::PointXYZ> super(voxel_resolution, seed_resolution);
super.setUseSingleCameraTransform(use_single_cam_transform);
super.setInputCloud(cloud);
super.setColorImportance(color_importance);
super.setSpatialImportance(spatial_importance);
super.setNormalImportance(normal_importance);
std::map<uint32_t, pcl::Supervoxel<pcl::PointXYZ>::Ptr> supervoxel_clusters;
super.extract(supervoxel_clusters);
std::multimap<uint32_t, uint32_t> supervoxel_adjacency;
super.getSupervoxelAdjacency(supervoxel_adjacency);
pcl::PointCloud<pcl::PointXYZL>::Ptr overseg = super.getLabeledCloud();
float concavity_tolerance_threshold = 1000;
float smoothness_threshold = 1;
uint32_t min_segment_size = 0;
//bool use_extended_convexity = true;
bool use_sanity_criterion = true;
float min_cut_score = p3;
unsigned int max_cuts = p4;
unsigned int cutting_min_segments = p5;
bool use_local_constrain = true;
bool use_directed_cutting = true;
bool use_clean_cutting = true;
unsigned int ransac_iterations = 1000;//迭代次数
pcl::CPCSegmentation<pcl::PointXYZ> cpc;
cpc.setConcavityToleranceThreshold(concavity_tolerance_threshold);
cpc.setSanityCheck(use_sanity_criterion);
cpc.setCutting(max_cuts, cutting_min_segments, min_cut_score, use_local_constrain, use_directed_cutting, use_clean_cutting);
cpc.setRANSACIterations(ransac_iterations);
cpc.setSmoothnessCheck(true, voxel_resolution, seed_resolution, smoothness_threshold);
cpc.setKFactor(k_factor);
cpc.setInputSupervoxels(supervoxel_clusters, supervoxel_adjacency);
cpc.setMinSegmentSize(min_segment_size);
cpc.segment();
pcl::PointCloud<pcl::PointXYZL>::Ptr sv_labeled_cloud = super.getLabeledCloud();
pcl::PointCloud<pcl::PointXYZL>::Ptr cpc_labeled_cloud = sv_labeled_cloud->makeShared();
cpc.relabelCloud(*cpc_labeled_cloud);
pcl::LCCPSegmentation<pcl::PointXYZ>::SupervoxelAdjacencyList sv_adjacency_list;
cpc.getSVAdjacencyList(sv_adjacency_list);