mexFunction.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "parse_rhs.h"
  2. #include <igl/matlab/mexStream.h>
  3. #include <igl/matlab/MatlabWorkspace.h>
  4. #include <igl/embree/EmbreeIntersector.h>
  5. #include <igl/embree/ambient_occlusion.h>
  6. #include <igl/matlab_format.h>
  7. #include <igl/read.h>
  8. #include <igl/per_vertex_normals.h>
  9. #include <mex.h>
  10. #include <iostream>
  11. #include <string>
  12. void mexFunction(int nlhs, mxArray *plhs[],
  13. int nrhs, const mxArray *prhs[])
  14. {
  15. // This is useful for debugging whether Matlab is caching the mex binary
  16. //mexPrintf("%s %s\n",__TIME__,__DATE__);
  17. igl::mexStream mout;
  18. std::streambuf *outbuf = std::cout.rdbuf(&mout);
  19. using namespace std;
  20. using namespace Eigen;
  21. using namespace igl;
  22. MatrixXd V,P,N;
  23. VectorXd S;
  24. MatrixXi F;
  25. int num_samples;
  26. parse_rhs(nrhs,prhs,V,F,P,N,num_samples);
  27. // Prepare left-hand side
  28. nlhs = 1;
  29. //read("../shared/cheburashka.obj",V,F);
  30. //P = V;
  31. //per_vertex_normals(V,F,N);
  32. EmbreeIntersector<Eigen::MatrixXd,Eigen::MatrixXi,Eigen::Vector3d> ei;
  33. ei = EmbreeIntersector<MatrixXd,MatrixXi,Vector3d>(V,F);
  34. ambient_occlusion(ei,P,N,num_samples,S);
  35. MatlabWorkspace mw;
  36. mw.save(V,"V");
  37. mw.save(P,"P");
  38. mw.save(N,"N");
  39. mw.save_index(F,"F");
  40. mw.save(S,"S");
  41. mw.write("out.mat");
  42. plhs[0] = mxCreateDoubleMatrix(S.rows(),S.cols(), mxREAL);
  43. copy(S.data(),S.data()+S.size(),mxGetPr(plhs[0]));
  44. // Restore the std stream buffer Important!
  45. std::cout.rdbuf(outbuf);
  46. }