Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00041 template <typename PointSource, typename PointTarget> inline void
00042 pcl::Registration<PointSource, PointTarget>::setInputTarget (const PointCloudTargetConstPtr &cloud)
00043 {
00044 if (cloud->points.empty ())
00045 {
00046 PCL_ERROR ("[pcl::%s::setInputTarget] Invalid or empty point cloud dataset given!\n", getClassName ().c_str ());
00047 return;
00048 }
00049 PointCloudTarget target = *cloud;
00050
00051 for (size_t i = 0; i < target.points.size (); ++i)
00052 target.points[i].data[3] = 1.0;
00053
00054
00055 target_ = target.makeShared ();
00056 tree_->setInputCloud (target_);
00057 }
00058
00060 template <typename PointSource, typename PointTarget> inline double
00061 pcl::Registration<PointSource, PointTarget>::getFitnessScore (const std::vector<float> &distances_a,
00062 const std::vector<float> &distances_b)
00063 {
00064 unsigned int nr_elem = static_cast<unsigned int> (std::min (distances_a.size (), distances_b.size ()));
00065 Eigen::VectorXf map_a = Eigen::VectorXf::Map (&distances_a[0], nr_elem);
00066 Eigen::VectorXf map_b = Eigen::VectorXf::Map (&distances_b[0], nr_elem);
00067 return (static_cast<double> ((map_a - map_b).sum ()) / static_cast<double> (nr_elem));
00068 }
00069
00071 template <typename PointSource, typename PointTarget> inline double
00072 pcl::Registration<PointSource, PointTarget>::getFitnessScore (double max_range)
00073 {
00074 double fitness_score = 0.0;
00075
00076
00077 PointCloudSource input_transformed;
00078 transformPointCloud (*input_, input_transformed, final_transformation_);
00079
00080 std::vector<int> nn_indices (1);
00081 std::vector<float> nn_dists (1);
00082
00083
00084 int nr = 0;
00085 for (size_t i = 0; i < input_transformed.points.size (); ++i)
00086 {
00087 Eigen::Vector4f p1 = Eigen::Vector4f (input_transformed.points[i].x,
00088 input_transformed.points[i].y,
00089 input_transformed.points[i].z, 0);
00090
00091 tree_->nearestKSearch (input_transformed.points[i], 1, nn_indices, nn_dists);
00092
00093
00094 if (nn_dists[0] > max_range)
00095 continue;
00096
00097 Eigen::Vector4f p2 = Eigen::Vector4f (target_->points[nn_indices[0]].x,
00098 target_->points[nn_indices[0]].y,
00099 target_->points[nn_indices[0]].z, 0);
00100
00101 fitness_score += fabs ((p1-p2).squaredNorm ());
00102 nr++;
00103 }
00104
00105 if (nr > 0)
00106 return (fitness_score / nr);
00107 else
00108 return (std::numeric_limits<double>::max ());
00109 }
00110
00112 template <typename PointSource, typename PointTarget> inline void
00113 pcl::Registration<PointSource, PointTarget>::align (PointCloudSource &output)
00114 {
00115 align (output, Eigen::Matrix4f::Identity());
00116 }
00117
00119 template <typename PointSource, typename PointTarget> inline void
00120 pcl::Registration<PointSource, PointTarget>::align (PointCloudSource &output, const Eigen::Matrix4f& guess)
00121 {
00122 if (!initCompute ()) return;
00123
00124 if (!target_)
00125 {
00126 PCL_WARN ("[pcl::%s::compute] No input target dataset was given!\n", getClassName ().c_str ());
00127 return;
00128 }
00129
00130
00131 if (output.points.size () != indices_->size ())
00132 output.points.resize (indices_->size ());
00133
00134 output.header = input_->header;
00135
00136 if (indices_->size () != input_->points.size ())
00137 {
00138 output.width = static_cast<uint32_t> (indices_->size ());
00139 output.height = 1;
00140 }
00141 else
00142 {
00143 output.width = static_cast<uint32_t> (input_->width);
00144 output.height = input_->height;
00145 }
00146 output.is_dense = input_->is_dense;
00147
00148
00149 for (size_t i = 0; i < indices_->size (); ++i)
00150 output.points[i] = input_->points[(*indices_)[i]];
00151
00152
00153 if (point_representation_)
00154 tree_->setPointRepresentation (point_representation_);
00155
00156
00157 converged_ = false;
00158 final_transformation_ = transformation_ = previous_transformation_ = Eigen::Matrix4f::Identity ();
00159
00160
00161
00162 for (size_t i = 0; i < indices_->size (); ++i)
00163 output.points[i].data[3] = 1.0;
00164
00165 computeTransformation (output, guess);
00166
00167 deinitCompute ();
00168 }
00169