prepare_lhs.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "prepare_lhs.h"
  2. #include <algorithm>
  3. template <typename DerivedV>
  4. IGL_INLINE void igl::prepare_lhs_double(
  5. const Eigen::PlainObjectBase<DerivedV> & V,
  6. mxArray *plhs[])
  7. {
  8. using namespace std;
  9. using namespace Eigen;
  10. plhs[0] = mxCreateDoubleMatrix(V.rows(),V.cols(), mxREAL);
  11. double * Vp = mxGetPr(plhs[0]);
  12. typedef typename DerivedV::Scalar Scalar;
  13. const Scalar * V_data;
  14. Matrix<Scalar, DerivedV::ColsAtCompileTime, DerivedV::RowsAtCompileTime, RowMajor> VT;
  15. if(DerivedV::IsRowMajor)
  16. {
  17. VT = V.transpose();
  18. V_data = VT.data();
  19. }else
  20. {
  21. V_data = V.data();
  22. }
  23. copy(V_data,V_data+V.size(),Vp);
  24. }
  25. template <typename DerivedV>
  26. IGL_INLINE void igl::prepare_lhs_logical(
  27. const Eigen::PlainObjectBase<DerivedV> & V,
  28. mxArray *plhs[])
  29. {
  30. using namespace std;
  31. using namespace Eigen;
  32. plhs[0] = mxCreateLogicalMatrix(V.rows(),V.cols());
  33. mxLogical * Vp = static_cast<mxLogical*>(mxGetData(plhs[0]));
  34. typedef typename DerivedV::Scalar Scalar;
  35. const Scalar * V_data;
  36. Matrix<Scalar, DerivedV::ColsAtCompileTime, DerivedV::RowsAtCompileTime, RowMajor> VT;
  37. if(DerivedV::IsRowMajor)
  38. {
  39. VT = V.transpose();
  40. V_data = VT.data();
  41. }else
  42. {
  43. V_data = V.data();
  44. }
  45. copy(V_data,V_data+V.size(),Vp);
  46. }
  47. template <typename DerivedV>
  48. IGL_INLINE void igl::prepare_lhs_index(
  49. const Eigen::PlainObjectBase<DerivedV> & V,
  50. mxArray *plhs[])
  51. {
  52. // Treat indices as reals
  53. const auto Vd = (V.template cast<double>().array()+1).eval();
  54. return prepare_lhs_double(Vd,plhs);
  55. }
  56. #ifdef IGL_STATIC_LIBRARY
  57. template void igl::prepare_lhs_index<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, mxArray_tag**);
  58. template void igl::prepare_lhs_index<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, mxArray_tag**);
  59. template void igl::prepare_lhs_double<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, mxArray_tag**);
  60. template void igl::prepare_lhs_index<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, mxArray_tag**);
  61. template void igl::prepare_lhs_logical<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, mxArray_tag**);
  62. template void igl::prepare_lhs_double<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, mxArray_tag**);
  63. #endif