rapid
A ROS robotics library.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
rgbd.h
Go to the documentation of this file.
1 // Contains general purpose code for working with point clouds.
2 // In the future, we may want to split this into more meaningfully named files.
3 #ifndef _RAPID_PERCEPTION_RGBD_H_
4 #define _RAPID_PERCEPTION_RGBD_H_
5 
6 #include <string>
7 #include <vector>
8 
9 #include "Eigen/Dense"
10 #include "geometry_msgs/Pose.h"
11 #include "geometry_msgs/PoseStamped.h"
12 #include "geometry_msgs/Vector3.h"
13 #include "pcl/ModelCoefficients.h"
14 #include "pcl/PointIndices.h"
15 #include "pcl/filters/extract_indices.h"
16 #include "pcl/point_cloud.h"
17 #include "pcl/point_types.h"
18 #include "pcl/search/search.h"
19 #include "pcl/sample_consensus/method_types.h"
20 #include "pcl/sample_consensus/model_types.h"
21 #include "pcl/segmentation/sac_segmentation.h"
22 #include "ros/ros.h"
23 
24 namespace rapid {
25 namespace perception {
26 // Given a 3x3 matrix and a 3x3 vector, find which column of the matrix is
27 // closest (in cosine similarity) or most diametrically opposite to the vector.
28 // E.g., a cosine similarity of -1 is considered closer than 0.5.
29 void ClosestAxis(const Eigen::Matrix3d& mat, const Eigen::Vector3d& vec,
30  int* index, double* cosine_sim);
31 
32 // Same as FindHorizontalPlane below, except using the entire cloud as given.
34  const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& cloud,
35  double distance_threshold, double eps_angle,
36  pcl::PointIndices::Ptr inliers);
37 
38 // Given a point cloud, finds the dominant horizontal plane (as determined by
39 // RANSAC). Assumes that the point cloud is transformed such that the z axis
40 // corresponds to "up."
41 //
42 // Implementation notes: after finding a plane, there can sometimes be points in
43 // the background which are part of the plane. These should be filtered using
44 // clustering.
45 //
46 // Returns true if a plane was found, false otherwise.
48  const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& cloud,
49  const pcl::PointIndices::ConstPtr& indices, double distance_threshold,
50  double eps_angle, pcl::PointIndices::Ptr inliers);
51 
52 // Computes the bounding box for the given point cloud using PCA.
53 // The midpoint is given in the same frame as input cloud. The +z direction
54 // points in the direction closest to +z in the input cloud, and the same with
55 // +x.
56 //
57 // Args:
58 // cloud: The input cloud. Assumed to not have any NaN points.
59 // midpoint: The geometric center of the cloud, i.e., the midpoint between the
60 // minimum and maximum points in each of the x, y, and z directions. The
61 // orientation is such that the x direction points along the principal
62 // component and the z direction points up.
63 // dimensions: A vector containing the length of the cloud in the x, y, and z
64 // directions.
65 void GetBoundingBox(const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& cloud,
66  const pcl::PointIndices::ConstPtr& indices,
67  geometry_msgs::PoseStamped* midpoint,
68  geometry_msgs::Vector3* dimensions);
69 
70 // Computes the bounding box for the given point cloud on the XY plane.
71 //
72 // Args:
73 // cloud: The input cloud. Assumed to not have any NaN points.
74 // midpoint: The geometric center of the cloud, i.e., the midpoint between the
75 // minimum and maximum points in each of the x, y, and z directions. The
76 // orientation is such that the x direction points along the principal
77 // component and the z direction points up.
78 // dimensions: A vector containing the length of the cloud in the x, y, and z
79 // directions.
81  const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& cloud,
82  const pcl::PointIndices::ConstPtr& indices, geometry_msgs::Pose* midpoint,
83  geometry_msgs::Vector3* dimensions);
84 
85 // Like GetPlanarBoundingBox, but with the entire cloud as given.
87  const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& cloud,
88  geometry_msgs::Pose* midpoint, geometry_msgs::Vector3* dimensions);
89 
90 // Given PointIndices to a PointCloud, returns the point cloud referred to by
91 // the PointIndices.
92 pcl::PointCloud<pcl::PointXYZRGB>::Ptr IndicesToCloud(
93  const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& cloud,
94  const pcl::PointIndices::ConstPtr& indices);
95 
96 // Computes the resolution of the given point cloud, defined as the average
97 // distance between a point and its nearest neighbor.
98 double ComputeResolution(
99  const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& cloud);
100 double ComputeResolution(
101  const pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr& cloud,
102  const pcl::search::Search<pcl::PointXYZRGB>& tree);
103 
104 // Combines the given point clouds into one point cloud with the same resolution
105 // as the first point cloud.
106 // The point clouds are "averaged" using a voxel grid filter.
107 // leaf_size = 0 means use the resolution of the point cloud as the leaf size.
108 pcl::PointCloud<pcl::PointXYZRGB>::Ptr Average(
109  const std::vector<pcl::PointCloud<pcl::PointXYZRGB>::Ptr>& clouds);
110 
111 // Get a smoothed point cloud made up of an average of multiple point clouds.
112 // Each point cloud is smoothed using a filter. Then, they are concatenated with
113 // each other. Finally, a voxel grid is laid over the result.
114 // leaf_size = 0 means use the resolution of the point cloud as the leaf size.
115 pcl::PointCloud<pcl::PointXYZRGB>::Ptr GetSmoothedKinectCloud(
116  const std::string& topic, int num_clouds = 5);
117 } // namespace perception
118 } // namespace rapid
119 #endif // _RAPID_PERCEPTION_RGBD_H_
bool FindHorizontalPlane(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &cloud, double distance_threshold, double eps_angle, pcl::PointIndices::Ptr inliers)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr Average(const std::vector< pcl::PointCloud< pcl::PointXYZRGB >::Ptr > &clouds)
double ComputeResolution(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &cloud)
void ClosestAxis(const Eigen::Matrix3d &mat, const Eigen::Vector3d &vec, int *index, double *cosine_sim)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr GetSmoothedKinectCloud(const std::string &topic, int num_clouds=5)
void GetPlanarBoundingBox(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &cloud, const pcl::PointIndices::ConstPtr &indices, geometry_msgs::Pose *midpoint, geometry_msgs::Vector3 *dimensions)
void GetBoundingBox(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &cloud, const pcl::PointIndices::ConstPtr &indices, geometry_msgs::PoseStamped *midpoint, geometry_msgs::Vector3 *dimensions)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr IndicesToCloud(const pcl::PointCloud< pcl::PointXYZRGB >::ConstPtr &cloud, const pcl::PointIndices::ConstPtr &indices)