frame_to_cross_field.cpp 1.7 KB

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