pcl::PointCloud Ptr 作为成员变量的初始化

文章讲述了如何在C++中对pcl::PointCloud<PointType>::Ptr类型的变量进行初始化。作为非成员变量,可以直接在声明时初始化。而作为类的成员变量,可以在构造函数的初始化列表或函数体内初始化。对于结构体成员变量,需要使用reset方法进行初始化。
摘要由CSDN通过智能技术生成

pcl PointCloud Ptr非成员变量时可以直接在声明中初始化pcl::PointCloud<PointType>::Ptr p(new pcl::PointCloud<PointType>());

1. 作为类成员变量时,需要额外的初始化。可以在构造函数初始化列表中初始化或者构造函数内初始化。

class A{
public:
    A();
    pcl::PointCloud<PointType>::Ptr p;
}


A::A()
:p(new pcl::PointCloud<PointType>())
{

}
class A{
public:
    A();
    pcl::PointCloud<PointType>::Ptr p;
}


A::A()
{
    p = pcl::PointCloud<PointType>::Ptr(new pcl::PointCloud<PointType>());
}

2.作为结构体成员变量时,使用reset进行初始化

struct MyStruct
{
    pcl::PointCloud<PointType>::Ptr p;
}


MyStruct test;
test.p.reset(new pcl::PointCloud<PointType>());

class ArmConnect: public rclcpp::Node { public: ArmConnect(const arm_connect::TopicType &topic_param); ~ArmConnect() = default; Camera::ImageInfo& GetImageInfo(Camera::CameraNum num); std::vector<std::vector<double>>& GetPointCloudInfo(); void SaveCalibrationDataInfo(const std::string &filename); std::vector<CalibrationData::detection>& GetCalibrationDataInfo(); bool IsGetCalibrationIdInfo(); bool IsGetCakubrationDataInfo(); private: void ImageCallback(const sensor_msgs::msg::Image &msg); void PointCloudCallback(const sensor_msgs::msg::PointCloud2 &msg); void CalibrationDataCallback(const apriltag_msgs::msg::AprilTagDetectionArray &msg); private: rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr image_subscriber_; Camera::ImageInfo camera_image_; std::mutex image_lock_; rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr pointcloud_subscriber_; rclcpp::Publisher<sensor_msgs::msg::PointCloud2>:: SharedPtr pointcloud_publisher_; std::vector<std::vector<double>> pointcloud_vector_; pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud_; std::mutex pointcloud_lock_; rclcpp::Subscription<apriltag_msgs::msg::AprilTagDetectionArray>::SharedPtr calibrationdata_subscriber_; std::vector<CalibrationData::detection> calibrationdata_vector_; mutable bool calibrationdata_flag_ = false; mutable bool calibrationboard_flag_ = false; std::mutex Calibrationdata_lock_; int CalibrationID; }; 上述是一个类的定义,如何在main函数给上述类的 int CalibrationID 赋值
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值