parse_rhs.cpp 2.2 KB

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