基于PCL绘制模型并渲染
博客转载自:https://blog.csdn.net/wokaowokaowokao12345/article/details/51321988
前言
抛开算法层面不谈,要利用PCL库中PCLVisualizer可视化类,显示出不同模型并对模型做出不同渲染,制作出丰富的可视化效果以增强自己应用的功能。下面将对如何添加立方体模型和圆球模型到视窗并渲染进行一个大概描述。
立方体模型
//向视窗添加一个立方体模型并渲染,只显示线框。若不要显示线框将下面一行代码注释即可。 viewer->addCube(0.1, 0.2, 0.1, 0.2, 0.1, 0.2); viewer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_REPRESENTATION, pcl::visualization::PCL_VISUALIZER_REPRESENTATION_WIREFRAME,"cube");
PCL Docs
bool addCube (const pcl::ModelCoefficients &coefficients, const std::string &id="cube", int viewport=0) bool addCube (const Eigen::Vector3f &translation, const Eigen::Quaternionf &rotation, double width, double height, double depth, const std::string &id="cube", int viewport=0) bool addCube (float x_min, float x_max, float y_min, float y_max, float z_min, float z_max, double r=1.0, double g=1.0, double b=1.0, const std::string &id="cube", int viewport=0)
圆球模型
//向视窗添加一个立方体模型并渲染,透明显示。若不要透明显示将下面一行代码注释即可。 viewer->addSphere(cloud->points.at(0), 0.1, 1, 1, 1); viewer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY, 0.3, "sphere");
圆球模型
#include"Eigen/Core" //绕Z轴旋转15° Eigen::AngleAxisf rotation_vector(M_PI / 4, Eigen::Vector3f(0, 0, 1)); _viewer->addCube(Eigen::Vector3f(16.4842, 11.3017, 0), Eigen::Quaternionf(rotation_vector),1.3,1.0,1.1,"cube2"); _viewer>setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_REPRESENTATION, pcl::visualization::PCL_VISUALIZER_REPRESENTATION_WIREFRAME, "cube2"); //移除Shape _viewer->removeShape("cube2");
PCL Docs
bool addSphere (const PointT ¢er, double radius, double r, double g, double b, const std::string &id="sphere", int viewport=0) bool addSphere (const pcl::ModelCoefficients &coefficients, const std::string &id="sphere", int viewport=0) bool addSphere (const PointT ¢er, double radius, const std::string &id="sphere", int viewport=0)
渲染模式
PCL Docs
//Set the rendering properties of a shape bool setShapeRenderingProperties (int property, double value, const std::string &id, int viewport=0) //Set the rendering properties of a shape (2x values - e.g., LUT minmax values) bool setShapeRenderingProperties (int property, double val1, double val2, const std::string &id, int viewport=0) //Set the rendering properties of a shape (3x values - e.g., RGB) bool setShapeRenderingProperties (int property, double val1, double val2, double val3, const std::string &id, int viewport=0)
渲染参数说明