readOBJ_mex.cpp 904 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "mex.h"
  2. #define IGL_HEADER_ONLY
  3. #include <igl/readOBJ.h>
  4. #include <igl/matlab/prepare_lhs.h>
  5. #include <Eigen/Core>
  6. void mexFunction(
  7. int nlhs,
  8. mxArray *plhs[],
  9. int nrhs,
  10. const mxArray *prhs[]
  11. )
  12. {
  13. using namespace Eigen;
  14. /* Check for proper number of arguments */
  15. if (nrhs != 1)
  16. {
  17. mexErrMsgIdAndTxt("MATLAB:mexcpp:nargin",
  18. "readOBJ requires 1 input arguments, the path of the file to open");
  19. }
  20. // Read the file path
  21. char* file_path = mxArrayToString(prhs[0]);
  22. MatrixXd V;
  23. MatrixXi F;
  24. // Read the mesh
  25. if(!igl::readOBJ(file_path,V,F))
  26. {
  27. mexErrMsgIdAndTxt("MATLAB:mexcpp:fileio", "igl::readOBJ failed.");
  28. }
  29. // Return the matrices to matlab
  30. switch(nlhs)
  31. {
  32. case 2:
  33. igl::prepare_lhs_index(F,plhs+1);
  34. case 1:
  35. igl::prepare_lhs_double(V,plhs);
  36. default: break;
  37. }
  38. return;
  39. }