1.获取最小最大值
#include <pcl/common/common.h>
pcl::PointXYZ minPt, maxPt;
getMinMax3D(*cloud, minPt, maxPt);
2.旋转和平移
#include <pcl/common/transforms.h>
float theta = M_PI / 180 * 22.6255761874;
float thetax = M_PI / 180 * 8.4;
Eigen::Affine3f transform_2 = Eigen::Affine3f::Identity();
transform_2.translation() << 0.0, 0.0, 6.5;
transform_2.rotate(Eigen::AngleAxisf(theta, Eigen::Vector3f::UnitY()));
transform_2.rotate(Eigen::AngleAxisf(-thetax, Eigen::Vector3f::UnitZ()));
pcl::PointCloud<pcl::PointXYZ>::Ptr transformed_cloud(new pcl::PointCloud<pcl::PointXYZ>());
pcl::transformPointCloud(*cloud, *transformed_cloud, transform_2);
3.view视图中添加坐标系显示
visualizer->addCoordinateSystem(10.0, 0, 0, 0, "CloudPoint");
4.view视图中添加一条线,设置颜色和线宽
pcl::PointXYZ startPt,endPt;
visualizer->addLine<pcl::PointXYZ>(startPt, endPt, 255, 255, 255, "line" );
visualizer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_LINE_WIDTH, 2, "line");
5.view视图中点云赋单色和设置点大小
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(transformed_cloud, 255, 255, 0);
visualizer->addPointCloud<pcl::PointXYZ>(cloud, single_color, "CloudPoint");
visualizer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 5, "CloudPoint");
6.view视图总设置相机视点信息
visualizer->initCameraParameters();
visualizer->setCameraPosition(0,-100,0,0,0,0,0,-100,1);//(0,-100,0)表示相机的位置,(0,0,0)表示从相机位置看向该点设置相机的朝向,(0,-100,1)表示相机的张上方的位置用于设置相机的旋转
7.保存点云数据
pcl::io::savePCDFileASCII(“cloud.pcd”, *cloud);