barycentric_to_global.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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 "barycentric_to_global.h"
  9. // For error printing
  10. #include <cstdio>
  11. #include <vector>
  12. namespace igl
  13. {
  14. template <typename Scalar, typename Index>
  15. IGL_INLINE Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic> barycentric_to_global(
  16. const Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic> & V,
  17. const Eigen::Matrix<Index,Eigen::Dynamic,Eigen::Dynamic> & F,
  18. const Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic> & bc)
  19. {
  20. Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic> R;
  21. R.resize(bc.rows(),3);
  22. for (unsigned i=0; i<R.rows(); ++i)
  23. {
  24. unsigned id = round(bc(i,0));
  25. double u = bc(i,1);
  26. double v = bc(i,2);
  27. if (id != -1)
  28. R.row(i) = V.row(F(id,0)) +
  29. ((V.row(F(id,1)) - V.row(F(id,0))) * u +
  30. (V.row(F(id,2)) - V.row(F(id,0))) * v );
  31. else
  32. R.row(i) << 0,0,0;
  33. }
  34. return R;
  35. }
  36. }
  37. #ifdef IGL_STATIC_LIBRARY
  38. template Eigen::Matrix<double, -1, -1, 0, -1, -1> igl::barycentric_to_global<double, int>(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::Matrix<double, -1, -1, 0, -1, -1> const&);
  39. #endif