在 QT 对象类中声明 PCL 点云
Declare a PCL point cloud in QT object class
我是使用PCL(点云库)的新手。我尝试私下在QT对象类中声明一个点云,如下所示:
class pcl_sys : public QThread
{
Q_OBJECT
public:
explicit pcl_sys();
~pcl_sys();
void stop();
bool load_pcd_file(int type);
signals:
public slots:
protected:
void run();
private:
pcl::PointCloud<pcl::PointXYZ>::Ptr *cloud_test;
};
然后我在打开程序时新建了点云:
pcl_sys::pcl_sys()
{
cloud_test=0;
cloud_test= new pcl::PointCloud<pcl::PointXYZ>::Ptr (new pcl::PointCloud<pcl::PointXYZ>);
}
但是当我尝试在尝试加载文件时清除点时,QT 给我一个错误,显示点不属于模板cloud_test。
bool pcl_sys::load_pcd_file(int choice)
{
cloud_test->points.clear();
}
如何解决此问题?谢谢。
他cloud_test是一个指向PointCloud::P tr类型的指针。因此,您必须使用函数 get() 访问其主体,然后通过它访问点。
pcl::PointCloud<pcl::PointXYZ>::Ptr *cloud_test;
cloud_test= new pcl::PointCloud<pcl::PointXYZ>::Ptr (new pcl::PointCloud<pcl::PointXYZ>);
if (!cloud_test) cloud_test->get()->points.clear();
在下面,cloud_test是 PointCloud::P tr 类型(不是引用指针):
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_test ;
cloud_test = pcl::PointCloud<pcl::PointXYZ>::Ptr (new pcl::PointCloud<pcl::PointXYZ>);
cloud_test.get()->points.clear();
或者你可以使用 boost::shared_ptr 作为指向 PointCloud::P tr 类型的指针,如下所示:
boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ>::Ptr> cloud_test;
cloud_test = boost::make_shared <pcl::PointCloud<pcl::PointXYZ>::Ptr> (new pcl::PointCloud<pcl::PointXYZ>);
cloud_test->get()->points.clear();
:)
只需执行cloud_test = new pcl::PointCloud<pcl::PointXYZ>
,而不是创建指向PointCloud
的新指针。
相关文章:
- .cpp和.h文件中的模板专用化声明
- 未在作用域中声明unordered_map
- C++避免重复声明的语法是什么
- 如何确保C++函数在定义之前声明(如override关键字)
- 错误:未在此范围内声明'reverse'
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 为什么在定义函数之前先声明它
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- #ifdef和未声明的标识符
- 没有显式声明的int[]中的foreach
- 在基于范围的for循环中使用结构化绑定声明
- 在将变量声明为引用时,堆在释放后使用
- C++:无法访问声明的受保护成员
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 在函数内部的声明中初始化数组,并在外部使用它
- Visual Studio中的函数声明和函数定义问题
- 点云库 (PCL) - 声明点云时何时应使用 ::P tr 的经验法则?
- 在 QT 对象类中声明 PCL 点云