readOBJ_mex.cpp 896 B

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