project_isometrically_to_plane.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "project_isometrically_to_plane.h"
  2. #include "edge_lengths.h"
  3. template <
  4. typename DerivedV,
  5. typename DerivedF,
  6. typename DerivedU,
  7. typename DerivedUF,
  8. typename Scalar>
  9. IGL_INLINE void igl::project_isometrically_to_plane(
  10. const Eigen::PlainObjectBase<DerivedV> & V,
  11. const Eigen::PlainObjectBase<DerivedF> & F,
  12. Eigen::PlainObjectBase<DerivedU> & U,
  13. Eigen::PlainObjectBase<DerivedUF> & UF,
  14. Eigen::SparseMatrix<Scalar>& I)
  15. {
  16. using namespace std;
  17. using namespace Eigen;
  18. assert(F.cols() == 3 && "F should contain triangles");
  19. typedef Eigen::PlainObjectBase<DerivedV> MatrixX;
  20. MatrixX l;
  21. edge_lengths(V,F,l);
  22. // Number of faces
  23. const int m = F.rows();
  24. // First corner at origin
  25. U = Eigen::PlainObjectBase<DerivedU>::Zero(m*3,2);
  26. // Second corner along x-axis
  27. U.block(m,0,m,1) = l.col(2);
  28. // Third corner rotated onto plane
  29. U.block(m*2,0,m,1) =
  30. (-l.col(0).array().square() +
  31. l.col(1).array().square() +
  32. l.col(2).array().square())/(2.*l.col(2).array());
  33. U.block(m*2,1,m,1) =
  34. (l.col(1).array().square()-U.block(m*2,0,m,1).array().square()).sqrt();
  35. typedef Triplet<Scalar> IJV;
  36. vector<IJV > ijv;
  37. ijv.reserve(3*m);
  38. UF.resize(m,3);
  39. for(int f = 0;f<m;f++)
  40. {
  41. for(int c = 0;c<3;c++)
  42. {
  43. UF(f,c) = c*m+f;
  44. ijv.push_back(IJV(F(f,c),c*m+f,1));
  45. }
  46. }
  47. I.resize(V.rows(),m*3);
  48. I.setFromTriplets(ijv.begin(),ijv.end());
  49. }
  50. #ifdef IGL_STATIC_LIBRARY
  51. template void igl::project_isometrically_to_plane<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, double>(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::SparseMatrix<double, 0, int>&);
  52. #endif