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
00040
00041 #ifndef PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_PARALLEL_PLANE_H_
00042 #define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_PARALLEL_PLANE_H_
00043
00044 #include <pcl/sample_consensus/sac_model_normal_parallel_plane.h>
00045
00047 template <typename PointT, typename PointNT> void
00048 pcl::SampleConsensusModelNormalParallelPlane<PointT, PointNT>::selectWithinDistance (
00049 const Eigen::VectorXf &model_coefficients, const double threshold, std::vector<int> &inliers)
00050 {
00051 if (!normals_)
00052 {
00053 PCL_ERROR ("[pcl::SampleConsensusModelNormalParallelPlane::selectWithinDistance] No input dataset containing normals was given!\n");
00054 return;
00055 }
00056
00057
00058 if (!isModelValid (model_coefficients))
00059 {
00060 inliers.clear ();
00061 return;
00062 }
00063
00064
00065 Eigen::Vector4f coeff = model_coefficients;
00066
00067 int nr_p = 0;
00068 inliers.resize (indices_->size ());
00069 error_sqr_dists_.resize (indices_->size ());
00070
00071
00072 for (size_t i = 0; i < indices_->size (); ++i)
00073 {
00074
00075
00076 Eigen::Vector4f p (input_->points[(*indices_)[i]].x, input_->points[(*indices_)[i]].y, input_->points[(*indices_)[i]].z, 1);
00077 Eigen::Vector4f n (normals_->points[(*indices_)[i]].normal[0], normals_->points[(*indices_)[i]].normal[1], normals_->points[(*indices_)[i]].normal[2], 0);
00078 double d_euclid = fabs (coeff.dot (p));
00079
00080
00081 double d_normal = getAngle3D (n, coeff);
00082 d_normal = (std::min) (d_normal, fabs(M_PI - d_normal));
00083
00084 double distance = fabs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid);
00085 if (distance < threshold)
00086 {
00087
00088 inliers[nr_p] = (*indices_)[i];
00089 error_sqr_dists_[nr_p] = distance;
00090 ++nr_p;
00091 }
00092 }
00093 inliers.resize (nr_p);
00094 error_sqr_dists_.resize (nr_p);
00095 }
00096
00098 template <typename PointT, typename PointNT> int
00099 pcl::SampleConsensusModelNormalParallelPlane<PointT, PointNT>::countWithinDistance (
00100 const Eigen::VectorXf &model_coefficients, const double threshold)
00101 {
00102 if (!normals_)
00103 {
00104 PCL_ERROR ("[pcl::SampleConsensusModelNormalParallelPlane::countWithinDistance] No input dataset containing normals was given!\n");
00105 return (0);
00106 }
00107
00108
00109 if (!isModelValid (model_coefficients))
00110 return (0);
00111
00112
00113 Eigen::Vector4f coeff = model_coefficients;
00114
00115 int nr_p = 0;
00116
00117
00118 for (size_t i = 0; i < indices_->size (); ++i)
00119 {
00120
00121
00122 Eigen::Vector4f p (input_->points[(*indices_)[i]].x, input_->points[(*indices_)[i]].y, input_->points[(*indices_)[i]].z, 1);
00123 Eigen::Vector4f n (normals_->points[(*indices_)[i]].normal[0], normals_->points[(*indices_)[i]].normal[1], normals_->points[(*indices_)[i]].normal[2], 0);
00124 double d_euclid = fabs (coeff.dot (p));
00125
00126
00127 double d_normal = fabs (getAngle3D (n, coeff));
00128 d_normal = (std::min) (d_normal, fabs(M_PI - d_normal));
00129
00130 if (fabs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid) < threshold)
00131 nr_p++;
00132 }
00133 return (nr_p);
00134 }
00135
00136
00138 template <typename PointT, typename PointNT> void
00139 pcl::SampleConsensusModelNormalParallelPlane<PointT, PointNT>::getDistancesToModel (
00140 const Eigen::VectorXf &model_coefficients, std::vector<double> &distances)
00141 {
00142 if (!normals_)
00143 {
00144 PCL_ERROR ("[pcl::SampleConsensusModelNormalParallelPlane::getDistancesToModel] No input dataset containing normals was given!\n");
00145 return;
00146 }
00147
00148
00149 if (!isModelValid (model_coefficients))
00150 {
00151 distances.clear ();
00152 return;
00153 }
00154
00155
00156 Eigen::Vector4f coeff = model_coefficients;
00157
00158 distances.resize (indices_->size ());
00159
00160
00161 for (size_t i = 0; i < indices_->size (); ++i)
00162 {
00163
00164
00165 Eigen::Vector4f p (input_->points[(*indices_)[i]].x, input_->points[(*indices_)[i]].y, input_->points[(*indices_)[i]].z, 1);
00166 Eigen::Vector4f n (normals_->points[(*indices_)[i]].normal[0], normals_->points[(*indices_)[i]].normal[1], normals_->points[(*indices_)[i]].normal[2], 0);
00167 double d_euclid = fabs (coeff.dot (p));
00168
00169
00170 double d_normal = getAngle3D (n, coeff);
00171 d_normal = (std::min) (d_normal, fabs (M_PI - d_normal));
00172
00173 distances[i] = fabs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid);
00174 }
00175 }
00176
00178 template <typename PointT, typename PointNT> bool
00179 pcl::SampleConsensusModelNormalParallelPlane<PointT, PointNT>::isModelValid (const Eigen::VectorXf &model_coefficients)
00180 {
00181
00182 if (model_coefficients.size () != 4)
00183 {
00184 PCL_ERROR ("[pcl::SampleConsensusModelNormalParallelPlane::isModelValid] Invalid number of model coefficients given (%zu)!\n", model_coefficients.size ());
00185 return (false);
00186 }
00187
00188
00189 if (eps_angle_ > 0.0)
00190 {
00191
00192 Eigen::Vector4f coeff = model_coefficients;
00193 coeff[3] = 0;
00194 coeff.normalize ();
00195
00196 if (fabs (axis_.dot (coeff)) < cos_angle_)
00197 return (false);
00198 }
00199
00200 if (eps_dist_ > 0.0)
00201 {
00202 if (fabs (-model_coefficients[3] - distance_from_origin_) > eps_dist_)
00203 return (false);
00204 }
00205
00206 return (true);
00207 }
00208
00209 #define PCL_INSTANTIATE_SampleConsensusModelNormalParallelPlane(PointT, PointNT) template class PCL_EXPORTS pcl::SampleConsensusModelNormalParallelPlane<PointT, PointNT>;
00210
00211 #endif // PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_PARALLEL_PLANE_H_
00212
00213