launch_medit.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "launch_medit.h"
  2. #include "writeMESH.h"
  3. #include <iostream>
  4. #include <string>
  5. #include <sstream>
  6. #define MEDIT_PATH "/opt/local/bin/medit"
  7. #define TEMP_MESH_FILE "/var/tmp/temp.mesh"
  8. #define TEMP_MEDIT_FILE "/var/tmp/temp.medit"
  9. template <typename DerivedV, typename DerivedT, typename DerivedF>
  10. IGL_INLINE int igl::launch_medit(
  11. const Eigen::MatrixBase<DerivedV> & V,
  12. const Eigen::MatrixBase<DerivedT> & T,
  13. const Eigen::MatrixBase<DerivedF> & F,
  14. const bool wait)
  15. {
  16. using namespace std;
  17. // Build medit command, end with & so command returns without waiting
  18. stringstream command;
  19. command<<MEDIT_PATH<<" "<<TEMP_MESH_FILE<<" "<<TEMP_MEDIT_FILE;
  20. if(!wait)
  21. {
  22. command<<" &";
  23. }
  24. bool mesh_saved = writeMESH(TEMP_MESH_FILE,V,T,F);
  25. if(!mesh_saved)
  26. {
  27. return -1;
  28. }
  29. // Write default medit options
  30. const string default_medit_file_contents =
  31. "BackgroundColor 1 1 1\n"
  32. "LineColor 0 0 0\n"
  33. "WindowSize 1024 800\n"
  34. "RenderMode shading + lines\n";
  35. FILE * fp = fopen(TEMP_MEDIT_FILE,"w");
  36. if(fp == NULL)
  37. {
  38. cerr<<"^"<<__FUNCTION__<<": Could not write to "<<TEMP_MEDIT_FILE<<endl;
  39. return -1;
  40. }
  41. fprintf(fp,"%s",default_medit_file_contents.c_str());
  42. fclose(fp);
  43. try
  44. {
  45. return system(command.str().c_str());
  46. }catch(int e)
  47. {
  48. cerr<<"^"<<__FUNCTION__<<": Calling to medit crashed..."<<endl;
  49. return -1;
  50. }
  51. // Could clean up and delete these files but not really worth it
  52. }
  53. #ifndef IGL_HEADER_ONLY
  54. // Explicit template specialization
  55. template int igl::launch_medit<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, bool);
  56. #endif