procrustes.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Stefan Brugger <stefanbrugger@gmail.com>
  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_PROCRUSTES_H
  9. #define IGL_PROCRUSTES_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. #include <Eigen/Geometry>
  13. namespace igl
  14. {
  15. // Solve Procrustes problem in d dimensions.
  16. // Given two point sets X,Y in R^d find best scale s, rotation/reflection R and translation t
  17. // s.t. |s*X*R + t - Y|^2 is minimized.
  18. //
  19. // Example:
  20. // MatrixXd X, Y; (containing 3d points as rows)
  21. // AffineCompact3d T;
  22. // igl::procrustes(X,Y,true,false,T);
  23. // MatrixXd Xprime = (X * T.linear()).rowwise() + T.translation().transpose();
  24. //
  25. //
  26. // Templates:
  27. // DerivedV point type
  28. // Scalar scalar type
  29. // DIM point dimension
  30. // TType type of transformation (Isometry,Affine,AffineCompact,Projective)
  31. // Inputs:
  32. // X #V by DIM first list of points
  33. // Y #V by DIM second list of points
  34. // includeScaling if scaling should be allowed
  35. // includeReflections if R is allowed to be a reflection
  36. // Outputs:
  37. // T transformation that minimizes error
  38. template <typename DerivedV, typename Scalar, int DIM, int TType>
  39. IGL_INLINE void procrustes(
  40. const Eigen::PlainObjectBase<DerivedV>& X,
  41. const Eigen::PlainObjectBase<DerivedV>& Y,
  42. bool includeScaling,
  43. bool includeReflections,
  44. Eigen::Transform<Scalar,DIM,TType>& T);
  45. }
  46. #ifndef IGL_STATIC_LIBRARY
  47. #include "procrustes.cpp"
  48. #endif
  49. #endif