iterative_closest_point.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2019 Alec Jacobson <[email protected]>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_ITERATIVE_CLOSEST_POINT_H
  9. #define IGL_ITERATIVE_CLOSEST_POINT_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include "AABB.h"
  13. namespace igl
  14. {
  15. /// Solve for the rigid transformation that places mesh X onto mesh Y using the
  16. /// iterative closest point method. In particular, optimize:
  17. ///
  18. /// min ∫_X inf ‖x*R+t - y‖² dx
  19. /// R∈SO(3) y∈Y
  20. /// t∈R³
  21. ///
  22. /// Typically optimization strategies include using Gauss Newton
  23. /// ("point-to-plane" linearization) and stochastic descent (sparse random
  24. /// sampling each iteration).
  25. ///
  26. /// @param[in] VX #VX by 3 list of mesh X vertices
  27. /// @param[in] FX #FX by 3 list of mesh X triangle indices into rows of VX
  28. /// @param[in] VY #VY by 3 list of mesh Y vertices
  29. /// @param[in] FY #FY by 3 list of mesh Y triangle indices into rows of VY
  30. /// @param[in] num_samples number of random samples to use (larger --> more accurate,
  31. /// but also more suceptible to sticking to local minimum)
  32. /// @param[out] R 3x3 rotation matrix so that (VX*R+t,FX) ~~ (VY,FY)
  33. /// @param[out] t 1x3 translation row vector
  34. template <
  35. typename DerivedVX,
  36. typename DerivedFX,
  37. typename DerivedVY,
  38. typename DerivedFY,
  39. typename DerivedR,
  40. typename Derivedt
  41. >
  42. IGL_INLINE void iterative_closest_point(
  43. const Eigen::MatrixBase<DerivedVX> & VX,
  44. const Eigen::MatrixBase<DerivedFX> & FX,
  45. const Eigen::MatrixBase<DerivedVY> & VY,
  46. const Eigen::MatrixBase<DerivedFY> & FY,
  47. const int num_samples,
  48. const int max_iters,
  49. Eigen::PlainObjectBase<DerivedR> & R,
  50. Eigen::PlainObjectBase<Derivedt> & t);
  51. /// \overload
  52. /// @param[in] Ytree precomputed AABB tree for accelerating closest point queries
  53. /// @param[in] NY #FY by 3 list of precomputed unit face normals
  54. template <
  55. typename DerivedVX,
  56. typename DerivedFX,
  57. typename DerivedVY,
  58. typename DerivedFY,
  59. typename DerivedNY,
  60. typename DerivedR,
  61. typename Derivedt
  62. >
  63. IGL_INLINE void iterative_closest_point(
  64. const Eigen::MatrixBase<DerivedVX> & VX,
  65. const Eigen::MatrixBase<DerivedFX> & FX,
  66. const Eigen::MatrixBase<DerivedVY> & VY,
  67. const Eigen::MatrixBase<DerivedFY> & FY,
  68. const igl::AABB<DerivedVY,3> & Ytree,
  69. const Eigen::MatrixBase<DerivedNY> & NY,
  70. const int num_samples,
  71. const int max_iters,
  72. Eigen::PlainObjectBase<DerivedR> & R,
  73. Eigen::PlainObjectBase<Derivedt> & t);
  74. }
  75. #ifndef IGL_STATIC_LIBRARY
  76. # include "iterative_closest_point.cpp"
  77. #endif
  78. #endif