// // IGL Lib - Simple C++ mesh library // // Copyright 2011, Daniele Panozzo. All rights reserved. // WARNING: These functions require matlab installed // Additional header folder required: // /Applications/MATLAB_R2011a.app/extern/include // Additional binary lib to be linked with: // /Applications/MATLAB_R2011a.app/bin/maci64/libeng.dylib // /Applications/MATLAB_R2011a.app/bin/maci64/libmx.dylib // MAC ONLY: // Add to the environment variables: // DYLD_LIBRARY_PATH = /Applications/MATLAB_R2011a.app/bin/maci64 // 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 #ifndef IGL_MATLAB_INTERFACE_H #define IGL_MATLAB_INTERFACE_H #include #include #include #include #include #include #include #include "engine.h" // Matlab engine header namespace igl { // Init the MATLAB engine // (no need to call it directly since it is automatically invoked by any other command) inline void mlinit(Engine** engine); // Closes the MATLAB engine inline void mlclose(Engine** engine); // Send a matrix to MATLAB inline void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXd& M); // Send a matrix to MATLAB inline void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXf& M); // Send a matrix to MATLAB inline void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXi& M); // Receive a matrix from MATLAB inline void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXd& M); // Receive a matrix from MATLAB inline void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXf& M); // Receive a matrix from MATLAB inline void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXi& M); // Send a single scalar to MATLAB inline void mlsetscalar(Engine** engine, std::string name, double s); // Receive a single scalar from MATLAB inline double mlgetscalar(Engine** engine, std::string name); // Execute arbitrary MATLAB code and return the MATLAB output inline std::string mleval(Engine** engine, std::string code); } // Implementation // Init the MATLAB engine // (no need to call it directly since it is automatically invoked by any other command) inline void igl::mlinit(Engine** mlengine) { *mlengine = engOpen("\0"); } // Closes the MATLAB engine inline void igl::mlclose(Engine** mlengine) { engClose(*mlengine); *mlengine = 0; } // Send a matrix to MATLAB inline void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::MatrixXd& M) { if (*mlengine == 0) mlinit(mlengine); mxArray *A = mxCreateDoubleMatrix(M.rows(), M.cols(), mxREAL); double *pM = mxGetPr(A); int c = 0; for(int j=0; j t; mxArray *ary = engGetVariable(*mlengine, name.c_str()); if (ary == NULL) { m = 0; n = 0; M = Eigen::MatrixXd(0,0); } else { m = mxGetM(ary); n = mxGetN(ary); M = Eigen::MatrixXd(m,n); double *pM = mxGetPr(ary); int c = 0; for(int j=0; j t; mxArray *ary = engGetVariable(*mlengine, name.c_str()); if (ary == NULL) { m = 0; n = 0; M = Eigen::MatrixXf(0,0); } else { m = mxGetM(ary); n = mxGetN(ary); M = Eigen::MatrixXf(m,n); double *pM = mxGetPr(ary); int c = 0; for(int j=0; j t; mxArray *ary = engGetVariable(*mlengine, name.c_str()); if (ary == NULL) { m = 0; n = 0; M = Eigen::MatrixXi(0,0); } else { m = mxGetM(ary); n = mxGetN(ary); M = Eigen::MatrixXi(m,n); double *pM = mxGetPr(ary); int c = 0; for(int j=0; j' && buf[1] == '>' && buf[2] == ' ') buf += 3; if (buf[0] == '\n') ++buf; return std::string(buf); } #endif