prepare_lhs.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. plhs[0] = mxCreateDoubleMatrix(V.rows(),V.cols(), mxREAL);
  10. double * Vp = mxGetPr(plhs[0]);
  11. copy(&V.data()[0],&V.data()[0]+V.size(),Vp);
  12. }
  13. template <typename DerivedV>
  14. IGL_INLINE void igl::prepare_lhs_logical(
  15. const Eigen::PlainObjectBase<DerivedV> & V,
  16. mxArray *plhs[])
  17. {
  18. using namespace std;
  19. plhs[0] = mxCreateLogicalMatrix(V.rows(),V.cols());
  20. mxLogical * Vp = static_cast<mxLogical*>(mxGetData(plhs[0]));
  21. copy(&V.data()[0],&V.data()[0]+V.size(),Vp);
  22. }
  23. template <typename DerivedV>
  24. IGL_INLINE void igl::prepare_lhs_index(
  25. const Eigen::PlainObjectBase<DerivedV> & V,
  26. mxArray *plhs[])
  27. {
  28. // Treat indices as reals
  29. const auto Vd = (V.template cast<double>().array()+1).eval();
  30. return prepare_lhs_double(Vd,plhs);
  31. }
  32. #ifdef IGL_STATIC_LIBRARY
  33. 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**);
  34. 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**);
  35. 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**);
  36. #endif