Last active
December 15, 2022 17:24
-
-
Save roman-smirnov/469696c0b117178611663a08f23fa92a to your computer and use it in GitHub Desktop.
Usage of Eigen library with PCL PointCloud (PCL uses Eigen::Matrix as its representation for point clouds under the hood )
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template<typename PointT> | |
| std::pair<typename pcl::PointCloud<PointT>::Ptr, typename pcl::PointCloud<PointT>::Ptr> | |
| ProcessPointClouds<PointT>::SegmentPlane( typename pcl::PointCloud<PointT>::Ptr cloud, int maxIterations, float distanceThreshold) { | |
| // Time segmentation process | |
| auto startTime = std::chrono::steady_clock::now(); | |
| // downsample input point cloud | |
| auto cloud_ds = DownSample(cloud, 1.0); | |
| // convert point cloud into a 3xN float matrix | |
| Eigen::Matrix3Xf cloud_matrix = cloud_ds->getMatrixXfMap(3,4,0); | |
| // print cloud point matrix shape | |
| std::cout << "cloud_matrix.rows(): " << cloud_matrix.rows() << std::endl; | |
| std::cout << "cloud_matrix.cols(): " << cloud_matrix.cols() << std::endl; | |
| // generate 100 triplets of indices | |
| const int size = cloud_matrix.cols(); | |
| Eigen::Matrix<int,3,100> m = Eigen::Matrix<int,3,100>::Random().array().abs().unaryExpr([size](int x){ return x % size; }); | |
| /* ... */ | |
| auto endTime = std::chrono::steady_clock::now(); | |
| auto elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime); | |
| std::cout << "plane segmentation took " << elapsedTime.count() << " milliseconds" << std::endl; | |
| return segResult; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment