matlabinterface.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Daniele Panozzo <daniele.panozzo@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. #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. IGL_INLINE void mlinit(Engine** engine);
  37. // Closes the MATLAB engine
  38. IGL_INLINE void mlclose(Engine** engine);
  39. // Send a matrix to MATLAB
  40. IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXd& M);
  41. // Send a matrix to MATLAB
  42. IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXf& M);
  43. // Send a matrix to MATLAB
  44. IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXi& M);
  45. // Send a matrix to MATLAB
  46. IGL_INLINE void mlsetmatrix(Engine** mlengine, std::string name, const Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M);
  47. // Receive a matrix from MATLAB
  48. IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXd& M);
  49. // Receive a matrix from MATLAB
  50. IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXf& M);
  51. // Receive a matrix from MATLAB
  52. IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXi& M);
  53. // Receive a matrix from MATLAB
  54. IGL_INLINE void mlgetmatrix(Engine** mlengine, std::string name, Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M);
  55. // Send a single scalar to MATLAB
  56. IGL_INLINE void mlsetscalar(Engine** engine, std::string name, double s);
  57. // Receive a single scalar from MATLAB
  58. IGL_INLINE double mlgetscalar(Engine** engine, std::string name);
  59. // Execute arbitrary MATLAB code and return the MATLAB output
  60. IGL_INLINE std::string mleval(Engine** engine, std::string code);
  61. // Send a sparse matrix to MATLAB
  62. IGL_INLINE void mlsetmatrix(Engine** mlengine, std::string name, const Eigen::SparseMatrix<double>& M);
  63. }
  64. }
  65. // Be sure that this is not compiled into libigl.a
  66. #ifndef IGL_STATIC_LIBRARY
  67. # include "matlabinterface.cpp"
  68. #endif
  69. #endif