博客轉載自: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)
渲染參數說明