frame_to_cross_field.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@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. #include "frame_to_cross_field.h"
  9. #include <igl/local_basis.h>
  10. #include <igl/dot_row.h>
  11. IGL_INLINE void igl::frame_to_cross_field(
  12. const Eigen::MatrixXd& V,
  13. const Eigen::MatrixXi& F,
  14. const Eigen::MatrixXd& FF1,
  15. const Eigen::MatrixXd& FF2,
  16. Eigen::MatrixXd& X)
  17. {
  18. using namespace Eigen;
  19. // Generate local basis
  20. MatrixXd B1, B2, B3;
  21. igl::local_basis(V,F,B1,B2,B3);
  22. // Project the frame fields in the local basis
  23. MatrixXd d1, d2;
  24. d1.resize(F.rows(),2);
  25. d2.resize(F.rows(),2);
  26. d1 << igl::dot_row(B1,FF1), igl::dot_row(B2,FF1);
  27. d2 << igl::dot_row(B1,FF2), igl::dot_row(B2,FF2);
  28. X.resize(F.rows(), 3);
  29. for (int i=0;i<F.rows();i++)
  30. {
  31. Vector2d v1 = d1.row(i);
  32. Vector2d v2 = d2.row(i);
  33. // define inverse map that maps the canonical axis to the given frame directions
  34. Matrix2d A;
  35. A << v1[0], v2[0],
  36. v1[1], v2[1];
  37. // find the closest rotation
  38. Eigen::JacobiSVD<Matrix<double,2,2> > svd(A, Eigen::ComputeFullU | Eigen::ComputeFullV );
  39. Matrix2d C = svd.matrixU() * svd.matrixV().transpose();
  40. Vector2d v = C.col(0);
  41. X.row(i) = v(0) * B1.row(i) + v(1) * B2.row(i);
  42. }
  43. }
  44. #ifdef IGL_STATIC_LIBRARY
  45. // Explicit template specialization
  46. #endif