launch_medit.cpp 1.9 KB

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