PCL-获取点云体素中的所有点的索引的方法

使用 octree 将点云体素化之后,获取体素中所有点的方法
即OctreeContainerBase中的三个方法的介绍:

getPointIndex()、getPointIndicesVector()、getPointIndices()

这三个方法都是定义在 pcl/octree/octree_container.h 文件中,源码如下:

首先在该文件中,leafDataTVector_ 是一个存储了该体素中所有点的 vector

        /** \brief Leaf node DataT vector. */
        std::vector<int> leafDataTVector_;

getPointIndex() 是一个 int 类型的方法,能够将该体素中所有点的索引的最后一个返回 

        /** \brief Retrieve point index from container. This container stores a vector of point indices.
         * \return index stored within container.
         */
        int
        getPointIndex ( ) const
        {
          return leafDataTVector_.back ();
        }

getPointIndices() 方法是 void 类型的,没有返回值,使用是需要将定义好的 vector 写进函数的参数中,调用该方法时会将该体素中所有点的索引都插入到参数中的 vector

       /** \brief Retrieve point indices from container. This container stores a vector of point indices.
         * \param[out] data_vector_arg vector of point indices to be stored within data vector
         */
        void
        getPointIndices (std::vector<int>& data_vector_arg) const
        {
          data_vector_arg.insert (data_vector_arg.end (), leafDataTVector_.begin (), leafDataTVector_.end ());
        }

getPointIndicesVector() 是 vector 类型,将体素中所有点的 vector 返回,需要一个 vector 接收

        /** \brief Retrieve reference to point indices vector. This container stores a vector of point indices.
         * \return reference to vector of point indices to be stored within data vector
         */
        std::vector<int>&
        getPointIndicesVector ()
        {
          return leafDataTVector_;
        }

测试代码如下:

	std::cout << "\n---- tranverse octree leaf node ----" << std::endl;
	pcl::octree::OctreePointCloud<pcl::PointXYZ>::LeafNodeIterator iter_leaf;
	iter_leaf = octree.leaf_begin();

	int counter = 0;
	while (iter_leaf != octree.leaf_end()) {
		std::vector<int> pointsIdx1;
		std::vector<int> pointsIdx2;
		
		int last_idx = iter_leaf.getLeafContainer().getPointIndex();
		pointsIdx1 = iter_leaf.getLeafContainer().getPointIndicesVector();
		iter_leaf.getLeafContainer().getPointIndices(pointsIdx2);

		std::cout << "last_idx: " << last_idx << std::endl;
		std::cout << "pointsIdx1.size(): " << pointsIdx1.size() << std::endl;
		std::cout << "pointsIdx2.size(): " << pointsIdx2.size() << std::endl;
    }

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值