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