barycentric2global.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 "barycentric2global.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> barycentric2global(
  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. }