prepare_lhs.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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 "prepare_lhs.h"
  9. #include <algorithm>
  10. template <typename DerivedV>
  11. IGL_INLINE void igl::matlab::prepare_lhs_double(
  12. const Eigen::PlainObjectBase<DerivedV> & V,
  13. mxArray *plhs[])
  14. {
  15. using namespace std;
  16. using namespace Eigen;
  17. const int m = V.rows();
  18. const int n = V.cols();
  19. plhs[0] = mxCreateDoubleMatrix(m,n, mxREAL);
  20. double * Vp = mxGetPr(plhs[0]);
  21. for(int i = 0;i<m;i++)
  22. {
  23. for(int j = 0;j<n;j++)
  24. {
  25. Vp[i+m*j] = V(i,j);
  26. }
  27. }
  28. }
  29. template <typename DerivedV>
  30. IGL_INLINE void igl::matlab::prepare_lhs_logical(
  31. const Eigen::PlainObjectBase<DerivedV> & V,
  32. mxArray *plhs[])
  33. {
  34. using namespace std;
  35. using namespace Eigen;
  36. const int m = V.rows();
  37. const int n = V.cols();
  38. plhs[0] = mxCreateLogicalMatrix(m,n);
  39. mxLogical * Vp = static_cast<mxLogical*>(mxGetData(plhs[0]));
  40. for(int i = 0;i<m;i++)
  41. {
  42. for(int j = 0;j<n;j++)
  43. {
  44. Vp[i+m*j] = V(i,j);
  45. }
  46. }
  47. }
  48. template <typename DerivedV>
  49. IGL_INLINE void igl::matlab::prepare_lhs_index(
  50. const Eigen::PlainObjectBase<DerivedV> & V,
  51. mxArray *plhs[])
  52. {
  53. // Treat indices as reals
  54. const auto Vd = (V.template cast<double>().array()+1).eval();
  55. return prepare_lhs_double(Vd,plhs);
  56. }
  57. #ifdef IGL_STATIC_LIBRARY
  58. template void igl::matlab::prepare_lhs_index<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, mxArray_tag**);
  59. template void igl::matlab::prepare_lhs_index<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, mxArray_tag**);
  60. template void igl::matlab::prepare_lhs_double<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, mxArray_tag**);
  61. template void igl::matlab::prepare_lhs_index<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::matlab::prepare_lhs_logical<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, mxArray_tag**);
  63. template void igl::matlab::prepare_lhs_double<Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, mxArray_tag**);
  64. #endif