mexFunction.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. ambient_occlusion(V,F,P,N,num_samples,S);
  33. //MatlabWorkspace mw;
  34. //mw.save(V,"V");
  35. //mw.save(P,"P");
  36. //mw.save(N,"N");
  37. //mw.save_index(F,"F");
  38. //mw.save(S,"S");
  39. //mw.write("out.mat");
  40. plhs[0] = mxCreateDoubleMatrix(S.rows(),S.cols(), mxREAL);
  41. copy(S.data(),S.data()+S.size(),mxGetPr(plhs[0]));
  42. // Restore the std stream buffer Important!
  43. std::cout.rdbuf(outbuf);
  44. }