parse_rhs.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "parse_rhs.h"
  2. #include <algorithm>
  3. template <typename DerivedV>
  4. IGL_INLINE void igl::parse_rhs_double(
  5. const mxArray *prhs[],
  6. Eigen::PlainObjectBase<DerivedV> & V)
  7. {
  8. using namespace std;
  9. using namespace Eigen;
  10. // set number of mesh vertices
  11. const int n = mxGetM(prhs[0]);
  12. // set vertex position pointers
  13. double * Vp = mxGetPr(prhs[0]);
  14. const int dim = mxGetN(prhs[0]);
  15. typedef typename DerivedV::Scalar Scalar;
  16. Matrix<Scalar, DerivedV::ColsAtCompileTime, DerivedV::RowsAtCompileTime, RowMajor> VT;
  17. Scalar * V_data;
  18. if(DerivedV::IsRowMajor)
  19. {
  20. VT.resize(dim,n);
  21. V_data = VT.data();
  22. }else
  23. {
  24. V.resize(n,dim);
  25. V_data = V.data();
  26. }
  27. copy(Vp,Vp+n*dim,V_data);
  28. if(DerivedV::IsRowMajor)
  29. {
  30. V = VT.transpose();
  31. }
  32. }
  33. template <typename DerivedV>
  34. IGL_INLINE void igl::parse_rhs_index(
  35. const mxArray *prhs[],
  36. Eigen::PlainObjectBase<DerivedV> & V)
  37. {
  38. parse_rhs_double(prhs,V);
  39. V.array() -= 1;
  40. }
  41. #ifdef IGL_STATIC_LIBRARY
  42. template void igl::parse_rhs_index<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(mxArray_tag const**, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  43. template void igl::parse_rhs_index<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(mxArray_tag const**, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  44. template void igl::parse_rhs_double<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(mxArray_tag const**, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  45. #endif