matlabinterface.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #ifndef IGL_MATLAB_INTERFACE_H
  9. #define IGL_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 <string>
  23. #include <complex>
  24. #include <cassert>
  25. #include <map>
  26. #include <string>
  27. #include <vector>
  28. #include "engine.h" // Matlab engine header
  29. namespace igl
  30. {
  31. // Init the MATLAB engine
  32. // (no need to call it directly since it is automatically invoked by any other command)
  33. IGL_INLINE void mlinit(Engine** engine);
  34. // Closes the MATLAB engine
  35. IGL_INLINE void mlclose(Engine** engine);
  36. // Send a matrix to MATLAB
  37. IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXd& M);
  38. // Send a matrix to MATLAB
  39. IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXf& M);
  40. // Send a matrix to MATLAB
  41. IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXi& M);
  42. // Send a matrix to MATLAB
  43. IGL_INLINE void mlsetmatrix(Engine** mlengine, std::string name, const Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M);
  44. // Receive a matrix from MATLAB
  45. IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXd& M);
  46. // Receive a matrix from MATLAB
  47. IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXf& M);
  48. // Receive a matrix from MATLAB
  49. IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXi& M);
  50. // Receive a matrix from MATLAB
  51. IGL_INLINE void mlgetmatrix(Engine** mlengine, std::string name, Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M);
  52. // Send a single scalar to MATLAB
  53. IGL_INLINE void mlsetscalar(Engine** engine, std::string name, double s);
  54. // Receive a single scalar from MATLAB
  55. IGL_INLINE double mlgetscalar(Engine** engine, std::string name);
  56. // Execute arbitrary MATLAB code and return the MATLAB output
  57. IGL_INLINE std::string mleval(Engine** engine, std::string code);
  58. }
  59. // Be sure that this is not compiled into libigl.a
  60. #ifdef IGL_HEADER_ONLY
  61. # include "matlabinterface.cpp"
  62. #endif
  63. #endif