20 #include <pcl/features/from_meshes.h> 21 #include <pcl/filters/filter.h> 34 fine_tf_ = Eigen::Matrix4f::Identity();
60 double normal_radius = (target_res + source_res) * 2.0;
65 pcl::IndicesPtr nan_indices(
new std::vector<int>);
66 pcl::removeNaNNormalsFromPointCloud(*normals, *normals, *nan_indices);
67 Filter::extractIndices(cloud, cloud, nan_indices);
70 pcl::features::computeApproximateCovariances(*cloud, *normals, *covs);
78 ROS_INFO(
"Extract covariances from clouds");
82 gicp_.setSourceCovariances(source_covariances);
83 gicp_.setTargetCovariances(target_covariances);
88 ROS_INFO(
"Perform GICP with %d iterations",
gicp_.getMaximumIterations());
95 ROS_INFO(
"This step may take a while ...");
96 gicp_.align(*aligned_cloud);
101 if (
gicp_.hasConverged())
103 ROS_INFO(
"Converged in %f FitnessScore",
gicp_.getFitnessScore());
118 if (
gicp_.hasConverged())
120 Eigen::Matrix4f temp_tf =
gicp_.getFinalTransformation();
123 ROS_INFO(
"Converged in %f FitnessScore",
gicp_.getFitnessScore());
152 ROS_ERROR(
"No transform yet. Please run algorithm");
static void printTransform(const Eigen::Matrix4f &transform)
Print on console transform values with matrix format.
double tf_epsilon_
Value for TFEpsilon for GICP. Define the convergence criterion.
static bool getNormals(PointCloudRGB::Ptr &cloud, double normal_radius, PointCloudNormal::Ptr &normals)
Get the normals for input cloud with specified normal's radius.
void undo()
Undo last iteration and back up results.
void getCovariances(PointCloudRGB::Ptr cloud, boost::shared_ptr< CovariancesVector > covs)
Get the covariances from cloud.
static bool isValidTransform(Eigen::Matrix4f transform)
Check whether transform contains valid data and is not NaN.
double ransac_outlier_th_
Value for RANSAC outlier threshold.
std::vector< Eigen::Matrix3d, Eigen::aligned_allocator< Eigen::Matrix3d > > CovariancesVector
PointCloudRGB::Ptr backup_cloud_
Save aligned pointcloud to restore if undo.
void run()
Perform GICP alignment.
bool covariances_
If true, perform GICP with convariances.
void setTargetCloud(PointCloudRGB::Ptr target_cloud)
Set the Target Cloud object.
void configParameters()
Set parameters to compute GICP alignment.
void iterate()
Do more iterations of GICP alignment.
void applyTFtoCloud(PointCloudRGB::Ptr cloud)
Once GICP is finished, apply fine transformation to source cloud.
void setTfEpsilon(double tf_epsilon)
Set the Tf Epsilon object.
static void cloudToROSMsg(PointCloudRGB::Ptr cloud, sensor_msgs::PointCloud2 &cloud_msg, const std::string &frameid="world")
Convert XYZRGB cloud to PointCloud2.
pcl::PointCloud< pcl::Normal > PointCloudNormal
GICPAlignment(PointCloudRGB::Ptr target_cloud, PointCloudRGB::Ptr source_cloud, bool use_covariances)
Construct a new GICPAlignment object.
void getAlignedCloud(PointCloudRGB::Ptr aligned_cloud)
Get the aligned cloud object.
void setSourceCloud(PointCloudRGB::Ptr source_cloud)
Set the Source Cloud object.
PointCloudRGB::Ptr source_cloud_
Source pointcloud.
bool transform_exists_
If true, fine transformation is finished.
pcl::PointCloud< pcl::PointXYZRGB > PointCloudRGB
static double computeCloudResolution(PointCloudXYZ::Ptr cloud)
Obtain the resolution of the cloud.
void setRANSACOutlierTh(int ransac_threshold)
Set the RANSAC Outlier threshold.
void fineAlignment()
Apply GICP to perform fine alignment.
double max_corresp_distance_
Value for Max CorrespondenceDistance for GICP.
void setMaxCorrespondenceDistance(int max_corresp_distance)
Set the Max Correspondence Distance object.
void iterateFineAlignment(PointCloudRGB::Ptr cloud)
Re-iterate GICP and save new aligned cloud.
void setMaxIterations(int iterations)
Set the Max Iterations object.
void applyCovariances()
Apply the covariances before running GICP.
pcl::GeneralizedIterativeClosestPoint< pcl::PointXYZRGB, pcl::PointXYZRGB > gicp_
GICP object.
void getAlignedCloudROSMsg(sensor_msgs::PointCloud2 &aligned_cloud_msg)
Get the aligned cloud msg in PointCloud2 format.
PointCloudRGB::Ptr aligned_cloud_
Source pointcloud aligned with target cloud.
Eigen::Matrix4f fine_tf_
Transformation matrix as result of GICP alignment.
Eigen::Matrix4f getFineTransform()
Get the fine transform object.
PointCloudRGB::Ptr target_cloud_
Target pointcloud.
void backUp(PointCloudRGB::Ptr cloud)
Store cloud as backup cloud.
int max_iter_
Maximum number of GICP iterations.