field_local_global_conversions.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Alec Jacobson <alecjacobson@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 <igl/field_local_global_conversions.h>
  9. template <typename DerivedG, typename DerivedL, typename DerivedB>
  10. IGL_INLINE void igl::global2local(
  11. const Eigen::PlainObjectBase<DerivedB>& B1,
  12. const Eigen::PlainObjectBase<DerivedB>& B2,
  13. const Eigen::PlainObjectBase<DerivedG>& global,
  14. Eigen::PlainObjectBase<DerivedL>& local)
  15. {
  16. int n = global.cols()/3;
  17. //get 2D vectors from 3D vectors
  18. local.resize(global.rows(), n*2);
  19. for (int i =0; i<global.rows(); ++i)
  20. {
  21. for (int k =0; k<n; k++)
  22. {
  23. const Eigen::Matrix<typename DerivedG::Scalar,1,3> &g = global.block(i, k*3,1,3);
  24. 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>()) ;
  25. }
  26. }
  27. }
  28. template <typename DerivedG, typename DerivedL, typename DerivedB>
  29. IGL_INLINE void igl::local2global(
  30. const Eigen::PlainObjectBase<DerivedB>& B1,
  31. const Eigen::PlainObjectBase<DerivedB>& B2,
  32. const Eigen::PlainObjectBase<DerivedL>& local,
  33. Eigen::PlainObjectBase<DerivedG>& global)
  34. {
  35. int n = local.cols()/2;
  36. //get 3D vectors from 2D vectors
  37. global.resize(local.rows(), n*3);
  38. for (int i =0; i<global.rows(); ++i)
  39. {
  40. for (int k =0; k<n; k++)
  41. {
  42. const Eigen::Matrix<typename DerivedL::Scalar,1,2> &l = local.block(i, k*2,1,2);
  43. 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>() ;
  44. }
  45. }
  46. }
  47. #ifdef IGL_STATIC_LIBRARY
  48. // Explicit template specialization
  49. 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> >&);
  50. 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> >&);
  51. #endif