235template <
typename Po
intT> std::size_t
237 const Eigen::VectorXf &
model_coefficients,
const double threshold, std::size_t i)
const
239 std::size_t
nr_p = 0;
244 for (; i < indices_->size (); ++i)
256#if defined (__SSE__) && defined (__SSE2__) && defined (__SSE4_1__)
257template <
typename Po
intT> std::size_t
259 const Eigen::VectorXf &model_coefficients,
const double threshold, std::size_t i)
const
261 std::size_t nr_p = 0;
262 const __m128 a_vec = _mm_set1_ps (model_coefficients[0]);
263 const __m128 b_vec = _mm_set1_ps (model_coefficients[1]);
264 const __m128 c_vec = _mm_set1_ps (model_coefficients[2]);
266 const __m128 sqr_inner_radius = _mm_set1_ps ((model_coefficients[3] <= threshold ? 0.0 : (model_coefficients[3]-threshold)*(model_coefficients[3]-threshold)));
267 const __m128 sqr_outer_radius = _mm_set1_ps ((model_coefficients[3]+threshold)*(model_coefficients[3]+threshold));
268 __m128i res = _mm_set1_epi32(0);
269 for (; (i + 4) <= indices_->size (); i += 4)
271 const __m128 sqr_dist = sqr_dist4 (i, a_vec, b_vec, c_vec);
272 const __m128 mask = _mm_and_ps (_mm_cmplt_ps (sqr_inner_radius, sqr_dist), _mm_cmplt_ps (sqr_dist, sqr_outer_radius));
273 res = _mm_add_epi32 (res, _mm_and_si128 (_mm_set1_epi32 (1), _mm_castps_si128 (mask)));
280 nr_p += _mm_extract_epi32 (res, 0);
281 nr_p += _mm_extract_epi32 (res, 1);
282 nr_p += _mm_extract_epi32 (res, 2);
283 nr_p += _mm_extract_epi32 (res, 3);
286 nr_p += countWithinDistanceStandard (model_coefficients, threshold, i);
292#if defined (__AVX__) && defined (__AVX2__)
293template <
typename Po
intT> std::size_t
295 const Eigen::VectorXf &model_coefficients,
const double threshold, std::size_t i)
const
297 std::size_t nr_p = 0;
298 const __m256 a_vec = _mm256_set1_ps (model_coefficients[0]);
299 const __m256 b_vec = _mm256_set1_ps (model_coefficients[1]);
300 const __m256 c_vec = _mm256_set1_ps (model_coefficients[2]);
302 const __m256 sqr_inner_radius = _mm256_set1_ps ((model_coefficients[3] <= threshold ? 0.0 : (model_coefficients[3]-threshold)*(model_coefficients[3]-threshold)));
303 const __m256 sqr_outer_radius = _mm256_set1_ps ((model_coefficients[3]+threshold)*(model_coefficients[3]+threshold));
304 __m256i res = _mm256_set1_epi32(0);
305 for (; (i + 8) <= indices_->size (); i += 8)
307 const __m256 sqr_dist = sqr_dist8 (i, a_vec, b_vec, c_vec);
308 const __m256 mask = _mm256_and_ps (_mm256_cmp_ps (sqr_inner_radius, sqr_dist, _CMP_LT_OQ), _mm256_cmp_ps (sqr_dist, sqr_outer_radius, _CMP_LT_OQ));
309 res = _mm256_add_epi32 (res, _mm256_and_si256 (_mm256_set1_epi32 (1), _mm256_castps_si256 (mask)));
320 nr_p += _mm256_extract_epi32 (res, 0);
321 nr_p += _mm256_extract_epi32 (res, 1);
322 nr_p += _mm256_extract_epi32 (res, 2);
323 nr_p += _mm256_extract_epi32 (res, 3);
324 nr_p += _mm256_extract_epi32 (res, 4);
325 nr_p += _mm256_extract_epi32 (res, 5);
326 nr_p += _mm256_extract_epi32 (res, 6);
327 nr_p += _mm256_extract_epi32 (res, 7);
330 nr_p += countWithinDistanceStandard (model_coefficients, threshold, i);
336template <
typename Po
intT>
void
345 PCL_ERROR (
"[pcl::SampleConsensusModelSphere::optimizeModelCoefficients] Given model is invalid!\n");
352 PCL_ERROR (
"[pcl::SampleConsensusModelSphere::optimizeModelCoefficients] Not enough inliers to refine/optimize the model's coefficients (%lu)! Returning the same coefficients.\n",
inliers.
size ());
356 OptimizationFunctor functor (
this,
inliers);
357 Eigen::NumericalDiff<OptimizationFunctor>
num_diff (functor);
358 Eigen::LevenbergMarquardt<Eigen::NumericalDiff<OptimizationFunctor>,
float>
lm (
num_diff);
362 PCL_DEBUG (
"[pcl::SampleConsensusModelSphere::optimizeModelCoefficients] LM solver finished with exit code %i, having a residual norm of %g. \nInitial solution: %g %g %g %g \nFinal solution: %g %g %g %g\n",
367template <
typename Po
intT>
void
374 PCL_ERROR (
"[pcl::SampleConsensusModelSphere::projectPoints] Given model is invalid!\n");
385 PCL_WARN (
"[pcl::SampleConsensusModelSphere::projectPoints] Not implemented yet.\n");
390template <
typename Po
intT>
bool
392 const std::set<index_t> &indices,
const Eigen::VectorXf &
model_coefficients,
const double threshold)
const
397 PCL_ERROR (
"[pcl::SampleConsensusModelSphere::doSamplesVerifyModel] Given model is invalid!\n");
404 for (
const auto &index : indices)
418#define PCL_INSTANTIATE_SampleConsensusModelSphere(T) template class PCL_EXPORTS pcl::SampleConsensusModelSphere<T>;