mexFunction.cpp 1.2 KB

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