ndt_cuda_impl.hpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #ifndef FAST_GICP_NDT_CUDA_IMPL_HPP
  2. #define FAST_GICP_NDT_CUDA_IMPL_HPP
  3. #include <fast_gicp/ndt/ndt_cuda.hpp>
  4. #include <fast_gicp/cuda/ndt_cuda.cuh>
  5. namespace fast_gicp {
  6. template <typename PointSource, typename PointTarget>
  7. NDTCuda<PointSource, PointTarget>::NDTCuda() : LsqRegistration<PointSource, PointTarget>() {
  8. this->reg_name_ = "NDTCuda";
  9. ndt_cuda_.reset(new cuda::NDTCudaCore());
  10. }
  11. template <typename PointSource, typename PointTarget>
  12. NDTCuda<PointSource, PointTarget>::~NDTCuda() {}
  13. template <typename PointSource, typename PointTarget>
  14. void NDTCuda<PointSource, PointTarget>::setDistanceMode(NDTDistanceMode mode) {
  15. ndt_cuda_->set_distance_mode(mode);
  16. }
  17. template <typename PointSource, typename PointTarget>
  18. void NDTCuda<PointSource, PointTarget>::setResolution(double resolution) {
  19. ndt_cuda_->set_resolution(resolution);
  20. }
  21. template <typename PointSource, typename PointTarget>
  22. void NDTCuda<PointSource, PointTarget>::setNeighborSearchMethod(NeighborSearchMethod method, double radius) {
  23. ndt_cuda_->set_neighbor_search_method(method, radius);
  24. }
  25. template <typename PointSource, typename PointTarget>
  26. void NDTCuda<PointSource, PointTarget>::swapSourceAndTarget() {
  27. ndt_cuda_->swap_source_and_target();
  28. input_.swap(target_);
  29. }
  30. template <typename PointSource, typename PointTarget>
  31. void NDTCuda<PointSource, PointTarget>::clearSource() {
  32. input_.reset();
  33. }
  34. template <typename PointSource, typename PointTarget>
  35. void NDTCuda<PointSource, PointTarget>::clearTarget() {
  36. target_.reset();
  37. }
  38. template <typename PointSource, typename PointTarget>
  39. void NDTCuda<PointSource, PointTarget>::setInputSource(const PointCloudSourceConstPtr& cloud) {
  40. if (cloud == input_) {
  41. return;
  42. }
  43. pcl::Registration<PointSource, PointTarget, Scalar>::setInputSource(cloud);
  44. std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f>> points(cloud->size());
  45. std::transform(cloud->begin(), cloud->end(), points.begin(), [=](const PointSource& pt) { return pt.getVector3fMap(); });
  46. ndt_cuda_->set_source_cloud(points);
  47. }
  48. template <typename PointSource, typename PointTarget>
  49. void NDTCuda<PointSource, PointTarget>::setInputTarget(const PointCloudTargetConstPtr& cloud) {
  50. if (cloud == target_) {
  51. return;
  52. }
  53. pcl::Registration<PointSource, PointTarget, Scalar>::setInputTarget(cloud);
  54. std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f>> points(cloud->size());
  55. std::transform(cloud->begin(), cloud->end(), points.begin(), [=](const PointTarget& pt) { return pt.getVector3fMap(); });
  56. ndt_cuda_->set_target_cloud(points);
  57. }
  58. template <typename PointSource, typename PointTarget>
  59. void NDTCuda<PointSource, PointTarget>::computeTransformation(PointCloudSource& output, const Matrix4& guess) {
  60. ndt_cuda_->create_voxelmaps();
  61. LsqRegistration<PointSource, PointTarget>::computeTransformation(output, guess);
  62. }
  63. template <typename PointSource, typename PointTarget>
  64. double NDTCuda<PointSource, PointTarget>::linearize(const Eigen::Isometry3d& trans, Eigen::Matrix<double, 6, 6>* H, Eigen::Matrix<double, 6, 1>* b) {
  65. ndt_cuda_->update_correspondences(trans);
  66. return ndt_cuda_->compute_error(trans, H, b);
  67. }
  68. template <typename PointSource, typename PointTarget>
  69. double NDTCuda<PointSource, PointTarget>::compute_error(const Eigen::Isometry3d& trans) {
  70. return ndt_cuda_->compute_error(trans, nullptr, nullptr);
  71. }
  72. } // namespace fast_gicp
  73. #endif