matlabinterface.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Daniele Panozzo <[email protected]>
  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. #ifndef IGL_MATLAB_MATLAB_INTERFACE_H
  9. #define IGL_MATLAB_MATLAB_INTERFACE_H
  10. #include "../igl_inline.h"
  11. // WARNING: These functions require matlab installed
  12. // Additional header folder required:
  13. // /Applications/MATLAB_R2011a.app/extern/include
  14. // Additional binary lib to be linked with:
  15. // /Applications/MATLAB_R2011a.app/bin/maci64/libeng.dylib
  16. // /Applications/MATLAB_R2011a.app/bin/maci64/libmx.dylib
  17. // MAC ONLY:
  18. // Add to the environment variables:
  19. // DYLD_LIBRARY_PATH = /Applications/MATLAB_R2011a.app/bin/maci64/
  20. // PATH = /opt/local/bin:/opt/local/sbin:/Applications/MATLAB_R2011a.app/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin
  21. #include <Eigen/Core>
  22. #include <Eigen/Sparse>
  23. #include <string>
  24. #include <complex>
  25. #include <cassert>
  26. #include <map>
  27. #include <string>
  28. #include <vector>
  29. #include <engine.h> // Matlab engine header
  30. namespace igl
  31. {
  32. namespace matlab
  33. {
  34. /// Init the MATLAB engine
  35. /// (no need to call it directly since it is automatically invoked by any other command)
  36. ///
  37. /// @param[in,out] engine pointer to the MATLAB engine
  38. IGL_INLINE void mlinit(Engine** engine);
  39. /// Closes the MATLAB engine
  40. ///
  41. /// @param[in,out] engine pointer to the MATLAB engine
  42. IGL_INLINE void mlclose(Engine** engine);
  43. /// Send a matrix to MATLAB
  44. ///
  45. /// @param[in,out] engine pointer to the MATLAB engine
  46. /// @param[in] name name of the variable in MATLAB
  47. /// @param[in] M matrix to be sent
  48. IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXd& M);
  49. /// \overload
  50. IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXf& M);
  51. /// \overload
  52. IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXi& M);
  53. /// \overload
  54. IGL_INLINE void mlsetmatrix(Engine** mlengine, std::string name, const Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M);
  55. /// \overload
  56. IGL_INLINE void mlsetmatrix(Engine** mlengine, std::string name, const Eigen::SparseMatrix<double>& M);
  57. /// Receive a matrix from MATLAB
  58. ///
  59. /// @param[in,out] engine pointer to the MATLAB engine
  60. /// @param[in] name name of the variable in MATLAB
  61. /// @param[out] M matrix received
  62. IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXd& M);
  63. /// \overload
  64. IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXf& M);
  65. /// \overload
  66. IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXi& M);
  67. /// \overload
  68. IGL_INLINE void mlgetmatrix(Engine** mlengine, std::string name, Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M);
  69. /// Send a single scalar to MATLAB
  70. ///
  71. /// @param[in,out] engine pointer to the MATLAB engine
  72. /// @param[in] name name of the variable in MATLAB
  73. /// @param[in] M value to be sent
  74. IGL_INLINE void mlsetscalar(Engine** engine, std::string name, double s);
  75. /// \overload
  76. IGL_INLINE double mlgetscalar(Engine** engine, std::string name);
  77. /// Execute arbitrary MATLAB code and return the MATLAB output
  78. ///
  79. /// @param[in,out] engine pointer to the MATLAB engine
  80. /// @param[in] code MATLAB code to be executed
  81. /// @return output of the MATLAB code
  82. ///
  83. IGL_INLINE std::string mleval(Engine** engine, std::string code);
  84. }
  85. }
  86. // Be sure that this is not compiled into libigl.a
  87. #ifndef IGL_STATIC_LIBRARY
  88. # include "matlabinterface.cpp"
  89. #endif
  90. #endif