field_local_global_conversions.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <igl/field_local_global_conversions.h>
  2. template <typename DerivedG, typename DerivedL, typename DerivedB>
  3. IGL_INLINE void igl::global2local(
  4. const Eigen::PlainObjectBase<DerivedB>& B1,
  5. const Eigen::PlainObjectBase<DerivedB>& B2,
  6. const Eigen::PlainObjectBase<DerivedG>& global,
  7. Eigen::PlainObjectBase<DerivedL>& local)
  8. {
  9. int n = global.cols()/3;
  10. //get 2D vectors from 3D vectors
  11. local.resize(global.rows(), n*2);
  12. for (int i =0; i<global.rows(); ++i)
  13. {
  14. for (int k =0; k<n; k++)
  15. {
  16. const Eigen::Matrix<typename DerivedG::Scalar,1,3> &g = global.block(i, k*3,1,3);
  17. local.block(i, k*2,1,2) << g.dot(B1.row(i).template cast<typename DerivedG::Scalar>()), g.dot(B2.row(i).template cast<typename DerivedG::Scalar>()) ;
  18. }
  19. }
  20. }
  21. template <typename DerivedG, typename DerivedL, typename DerivedB>
  22. IGL_INLINE void igl::local2global(
  23. const Eigen::PlainObjectBase<DerivedB>& B1,
  24. const Eigen::PlainObjectBase<DerivedB>& B2,
  25. const Eigen::PlainObjectBase<DerivedL>& local,
  26. Eigen::PlainObjectBase<DerivedG>& global)
  27. {
  28. int n = local.cols()/2;
  29. //get 3D vectors from 2D vectors
  30. global.resize(local.rows(), n*3);
  31. for (int i =0; i<global.rows(); ++i)
  32. {
  33. for (int k =0; k<n; k++)
  34. {
  35. const Eigen::Matrix<typename DerivedL::Scalar,1,2> &l = local.block(i, k*2,1,2);
  36. global.block(i, k*3, 1,3) = l[0]*B1.row(i).template cast<typename DerivedG::Scalar>() + l[1]*B2.row(i).template cast<typename DerivedG::Scalar>() ;
  37. }
  38. }
  39. }
  40. #ifdef IGL_STATIC_LIBRARY
  41. // Explicit template specialization
  42. template void igl::global2local<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  43. template void igl::local2global<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  44. #endif