launch_medit.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. {
  15. using namespace std;
  16. // Build medit command, end with & so command returns without waiting
  17. stringstream command;
  18. command<<MEDIT_PATH<<" "<<TEMP_MESH_FILE<<" "<<TEMP_MEDIT_FILE<<" &"<<endl;
  19. bool mesh_saved = writeMESH(TEMP_MESH_FILE,V,T,F);
  20. if(!mesh_saved)
  21. {
  22. return -1;
  23. }
  24. // Write default medit options
  25. const string default_medit_file_contents =
  26. "BackgroundColor 1 1 1\n"
  27. "LineColor 0 0 0\n"
  28. "WindowSize 1024 800\n"
  29. "RenderMode shading + lines\n";
  30. FILE * fp = fopen(TEMP_MEDIT_FILE,"w");
  31. if(fp == NULL)
  32. {
  33. cerr<<"^"<<__FUNCTION__<<": Could not write to "<<TEMP_MEDIT_FILE<<endl;
  34. return -1;
  35. }
  36. fprintf(fp,"%s",default_medit_file_contents.c_str());
  37. fclose(fp);
  38. try
  39. {
  40. return system(command.str().c_str());
  41. }catch(int e)
  42. {
  43. cerr<<"^"<<__FUNCTION__<<": Calling to medit crashed..."<<endl;
  44. return -1;
  45. }
  46. // Could clean up and delete these files but not really worth it
  47. }
  48. #ifndef IGL_HEADER_ONLY
  49. // Explicit template specialization
  50. 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&);
  51. #endif