barycentric_coordinates.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 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 "barycentric_coordinates.h"
  9. #include "volume.h"
  10. template <
  11. typename DerivedP,
  12. typename DerivedA,
  13. typename DerivedB,
  14. typename DerivedC,
  15. typename DerivedD,
  16. typename DerivedL>
  17. IGL_INLINE void igl::barycentric_coordinates(
  18. const Eigen::PlainObjectBase<DerivedP> & P,
  19. const Eigen::PlainObjectBase<DerivedA> & A,
  20. const Eigen::PlainObjectBase<DerivedB> & B,
  21. const Eigen::PlainObjectBase<DerivedC> & C,
  22. const Eigen::PlainObjectBase<DerivedD> & D,
  23. Eigen::PlainObjectBase<DerivedL> & L)
  24. {
  25. using namespace Eigen;
  26. assert(P.cols() == 3 && "query must be in 3d");
  27. assert(A.cols() == 3 && "corners must be in 3d");
  28. assert(B.cols() == 3 && "corners must be in 3d");
  29. assert(C.cols() == 3 && "corners must be in 3d");
  30. assert(D.cols() == 3 && "corners must be in 3d");
  31. assert(P.rows() == A.rows() && "Must have same number of queries as corners");
  32. assert(A.rows() == B.rows() && "Corners must be same size");
  33. assert(A.rows() == C.rows() && "Corners must be same size");
  34. assert(A.rows() == D.rows() && "Corners must be same size");
  35. typedef Matrix<typename DerivedL::Scalar,DerivedL::RowsAtCompileTime,1>
  36. VectorXS;
  37. // Total volume
  38. VectorXS vol,LA,LB,LC,LD;
  39. volume(B,D,C,P,LA);
  40. volume(A,C,D,P,LB);
  41. volume(A,D,B,P,LC);
  42. volume(A,B,C,P,LD);
  43. volume(A,B,C,D,vol);
  44. L.resize(P.rows(),4);
  45. L<<LA,LB,LC,LD;
  46. L.array().colwise() /= vol.array();
  47. }
  48. #ifndef IGL_HEADER_ONLY
  49. template void igl::barycentric_coordinates<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::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> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  50. #endif