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 #include <iostream>
00039 #include <pcl/common/poses_from_matches.h>
00040 #include <pcl/common/transformation_from_correspondences.h>
00041
00042 namespace pcl
00043 {
00044
00045 PosesFromMatches::PosesFromMatches ()
00046 {
00047 }
00048
00049 PosesFromMatches::~PosesFromMatches ()
00050 {
00051 }
00052
00053 void
00054 PosesFromMatches::estimatePosesUsing1Correspondence (const PointCorrespondences6DVector& correspondences,
00055 int max_no_of_results,
00056 PosesFromMatches::PoseEstimatesVector& pose_estimates) const
00057 {
00058
00059
00060
00061 if (max_no_of_results < 0)
00062 max_no_of_results = correspondences.size ();
00063 else
00064 max_no_of_results = std::min (max_no_of_results, (int)correspondences.size ());
00065
00066 for (int correspondence_idx=0; correspondence_idx<max_no_of_results; ++correspondence_idx)
00067 {
00068 const PointCorrespondence6D& correspondence = correspondences[correspondence_idx];
00069 PoseEstimate pose_estimate;
00070 pose_estimate.transformation = correspondence.transformation;
00071 pose_estimate.score = correspondence.score;
00072 pose_estimate.correspondence_indices.push_back (correspondence_idx);
00073 pose_estimates.push_back (pose_estimate);
00074 }
00075
00076
00077
00078 }
00079
00080
00081 void
00082 PosesFromMatches::estimatePosesUsing2Correspondences (const PointCorrespondences6DVector& correspondences,
00083 int max_no_of_tested_combinations, int max_no_of_results,
00084 PosesFromMatches::PoseEstimatesVector& pose_estimates) const
00085 {
00086 const Eigen::Vector3f x_direction (1.0f, 0.0f, 0.0f),
00087 y_direction (0.0f, 1.0f, 0.0f),
00088 z_direction (0.0f, 0.0f, 1.0f);
00089
00090 int max_correspondence_idx = correspondences.size ();
00091 int counter_for_tested_combinations = 0,
00092 counter_for_added_pose_estimates = 0;
00093 float max_distance_quotient = 1.0f+parameters_.max_correspondence_distance_error,
00094 max_distance_quotient_squared=powf (max_distance_quotient, 2),
00095 min_distance_quotient = 1.0f / (max_distance_quotient),
00096 min_distance_quotient_squared=powf (min_distance_quotient, 2);
00097
00098 TransformationFromCorrespondences transformation_from_correspondeces;
00099
00100
00101
00102
00103 bool done = false;
00104 for (int correspondence2_idx=0; correspondence2_idx<max_correspondence_idx && !done; ++correspondence2_idx)
00105 {
00106 const PointCorrespondence6D& correspondence2 = correspondences[correspondence2_idx];
00107 for (int correspondence1_idx=0; correspondence1_idx<correspondence2_idx; ++correspondence1_idx)
00108 {
00109 if (counter_for_tested_combinations >= max_no_of_tested_combinations)
00110 {
00111 done = true;
00112 break;
00113 }
00114
00115 const PointCorrespondence6D& correspondence1 = correspondences[correspondence1_idx];
00116 ++counter_for_tested_combinations;
00117
00118 const Eigen::Vector3f& point1 = correspondence1.point1, & point2 = correspondence2.point1,
00119 & corr1 = correspondence1.point2, & corr2 = correspondence2.point2;
00120
00121 float distance_squared = (point2-point1).squaredNorm (),
00122 distance_corr_squared = (corr2-corr1).squaredNorm (),
00123 distance_quotient_squared = distance_squared/distance_corr_squared;
00124 if ( distance_quotient_squared < min_distance_quotient_squared
00125 || distance_quotient_squared > max_distance_quotient_squared)
00126 {
00127
00128
00129 continue;
00130 }
00131
00132 float distance = sqrtf (distance_squared);
00133
00134 Eigen::Vector3f corr3=corr1, corr4=corr2;
00135 corr3[0]+=distance; corr4[0]+=distance;
00136 Eigen::Vector3f point3=correspondence1.transformation*corr3, point4=correspondence2.transformation*corr4;
00137
00138 distance_squared = (point4-point3).squaredNorm (),
00139 distance_corr_squared = (corr4-corr3).squaredNorm (),
00140 distance_quotient_squared = distance_squared/distance_corr_squared;
00141 if ( distance_quotient_squared < min_distance_quotient_squared
00142 || distance_quotient_squared > max_distance_quotient_squared)
00143 continue;
00144
00145 Eigen::Vector3f corr5=corr1, corr6=corr2;
00146 corr5[1]+=distance; corr6[1]+=distance;
00147 Eigen::Vector3f point5=correspondence1.transformation*corr5, point6=correspondence2.transformation*corr6;
00148
00149 distance_squared = (point6-point5).squaredNorm (),
00150 distance_corr_squared = (corr6-corr5).squaredNorm (),
00151 distance_quotient_squared = distance_squared/distance_corr_squared;
00152 if ( distance_quotient_squared < min_distance_quotient_squared
00153 || distance_quotient_squared > max_distance_quotient_squared)
00154 continue;
00155
00156 Eigen::Vector3f corr7=corr1, corr8=corr2;
00157 corr7[2]+=distance; corr8[2]+=distance;
00158 Eigen::Vector3f point7=correspondence1.transformation*corr7, point8=correspondence2.transformation*corr8;
00159
00160 distance_squared = (point8-point7).squaredNorm (),
00161 distance_corr_squared = (corr8-corr7).squaredNorm (),
00162 distance_quotient_squared = distance_squared/distance_corr_squared;
00163 if ( distance_quotient_squared < min_distance_quotient_squared
00164 || distance_quotient_squared > max_distance_quotient_squared)
00165 continue;
00166
00167 transformation_from_correspondeces.reset ();
00168 transformation_from_correspondeces.add (corr1, point1);
00169 transformation_from_correspondeces.add (corr2, point2);
00170 transformation_from_correspondeces.add (corr3, point3);
00171 transformation_from_correspondeces.add (corr4, point4);
00172 transformation_from_correspondeces.add (corr5, point5);
00173 transformation_from_correspondeces.add (corr6, point6);
00174 transformation_from_correspondeces.add (corr7, point7);
00175 transformation_from_correspondeces.add (corr8, point8);
00176
00177 ++counter_for_added_pose_estimates;
00178 PoseEstimate pose_estimate;
00179 pose_estimate.transformation = transformation_from_correspondeces.getTransformation ();
00180 pose_estimate.score = 0.5f*(correspondence1.score+correspondence2.score);
00181
00182 pose_estimate.correspondence_indices.push_back (correspondence1_idx);
00183 pose_estimate.correspondence_indices.push_back (correspondence2_idx);
00184 pose_estimates.push_back (pose_estimate);
00185 if (counter_for_added_pose_estimates >= max_no_of_results)
00186 {
00187 done = true;
00188 break;
00189 }
00190 }
00191 }
00192
00193
00194
00195 }
00196
00197 void
00198 PosesFromMatches::estimatePosesUsing3Correspondences (const PointCorrespondences6DVector& correspondences,
00199 int max_no_of_tested_combinations, int max_no_of_results,
00200 PosesFromMatches::PoseEstimatesVector& pose_estimates) const
00201 {
00202 const Eigen::Vector3f x_direction (1.0f, 0.0f, 0.0f),
00203 y_direction (0.0f, 1.0f, 0.0f),
00204 z_direction (0.0f, 0.0f, 1.0f);
00205
00206 int max_correspondence_idx = correspondences.size ();
00207 int counter_for_tested_combinations = 0,
00208 counter_for_added_pose_estimates = 0;
00209 float max_distance_quotient = 1.0f+parameters_.max_correspondence_distance_error,
00210 max_distance_quotient_squared=powf (max_distance_quotient, 2),
00211 min_distance_quotient = 1.0f / (max_distance_quotient),
00212 min_distance_quotient_squared=powf (min_distance_quotient, 2);
00213
00214 TransformationFromCorrespondences transformation_from_correspondeces;
00215
00216
00217
00218
00219 bool done = false;
00220 for (int correspondence3_idx=0; correspondence3_idx<max_correspondence_idx && !done; ++correspondence3_idx)
00221 {
00222 const PointCorrespondence6D& correspondence3 = correspondences[correspondence3_idx];
00223 const Eigen::Vector3f& point3 = correspondence3.point1,
00224 & corr3 = correspondence3.point2;
00225 for (int correspondence2_idx=0; correspondence2_idx<correspondence3_idx && !done; ++correspondence2_idx)
00226 {
00227 const PointCorrespondence6D& correspondence2 = correspondences[correspondence2_idx];
00228 const Eigen::Vector3f& point2 = correspondence2.point1,
00229 & corr2 = correspondence2.point2;
00230
00231 float distance23_squared = (point3-point2).squaredNorm (),
00232 distance23_corr_squared = (corr3-corr2).squaredNorm (),
00233 distance23_quotient_squared = distance23_squared/distance23_corr_squared;
00234 if ( distance23_quotient_squared < min_distance_quotient_squared
00235 || distance23_quotient_squared > max_distance_quotient_squared)
00236 {
00237
00238
00239 continue;
00240 }
00241
00242 for (int correspondence1_idx=0; correspondence1_idx<correspondence2_idx; ++correspondence1_idx)
00243 {
00244 if (counter_for_tested_combinations >= max_no_of_tested_combinations)
00245 {
00246 done = true;
00247 break;
00248 }
00249 ++counter_for_tested_combinations;
00250 const PointCorrespondence6D& correspondence1 = correspondences[correspondence1_idx];
00251 const Eigen::Vector3f& point1 = correspondence1.point1,
00252 & corr1 = correspondence1.point2;
00253 float distance12_squared = (point2-point1).squaredNorm (),
00254 distance12_corr_squared = (corr2-corr1).squaredNorm (),
00255 distance12_quotient_squared = distance12_squared/distance12_corr_squared;
00256 if ( distance12_quotient_squared < min_distance_quotient_squared
00257 || distance12_quotient_squared > max_distance_quotient_squared)
00258 continue;
00259 float distance13_squared = (point3-point1).squaredNorm (),
00260 distance13_corr_squared = (corr3-corr1).squaredNorm (),
00261 distance13_quotient_squared = distance13_squared/distance13_corr_squared;
00262 if ( distance13_quotient_squared < min_distance_quotient_squared
00263 || distance13_quotient_squared > max_distance_quotient_squared)
00264 continue;
00265
00266 transformation_from_correspondeces.reset ();
00267 transformation_from_correspondeces.add (corr1, point1);
00268 transformation_from_correspondeces.add (corr2, point2);
00269 transformation_from_correspondeces.add (corr3, point3);
00270
00271 ++counter_for_added_pose_estimates;
00272 PoseEstimate pose_estimate;
00273 pose_estimate.transformation = transformation_from_correspondeces.getTransformation ();
00274 pose_estimate.score = (correspondence1.score+correspondence2.score+correspondence3.score) / 3.0f;
00275
00276 pose_estimate.correspondence_indices.push_back (correspondence1_idx);
00277 pose_estimate.correspondence_indices.push_back (correspondence2_idx);
00278 pose_estimate.correspondence_indices.push_back (correspondence3_idx);
00279 pose_estimates.push_back (pose_estimate);
00280 if (counter_for_added_pose_estimates >= max_no_of_results)
00281 {
00282 done = true;
00283 break;
00284 }
00285 }
00286 }
00287 }
00288
00289
00290
00291 }
00292
00293 }
00294