read_into_tetgenio.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "read_into_tetgenio.h"
  2. #include "mesh_to_tetgenio.h"
  3. // IGL includes
  4. #include <igl/pathinfo.h>
  5. #ifndef IGL_NO_EIGEN
  6. # define IGL_NO_EIGEN_WAS_NOT_ALREADY_DEFINED
  7. # define IGL_NO_EIGEN
  8. #endif
  9. // Include igl headers without including Eigen
  10. #include <igl/readOBJ.h>
  11. #ifdef IGL_NO_EIGEN_WAS_NOT_ALREADY_DEFINED
  12. # undef IGL_NO_EIGEN
  13. #endif
  14. // STL includes
  15. #include <algorithm>
  16. #include <iostream>
  17. #include <vector>
  18. IGL_INLINE bool igl::read_into_tetgenio(
  19. const std::string & path,
  20. tetgenio & in)
  21. {
  22. using namespace igl;
  23. using namespace std;
  24. // get file extension
  25. string dirname,basename,ext,filename;
  26. pathinfo(path,dirname,basename,ext,filename);
  27. // convert to lower case for easy comparison
  28. transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
  29. bool success = false;
  30. char basename_char[1024];
  31. strcpy(basename_char,basename.c_str());
  32. if(ext == "obj")
  33. {
  34. // read obj into vertex list and face list
  35. vector<vector<REAL> > V,TC,N;
  36. vector<vector<int> > F,FTC,FN;
  37. success = readOBJ(path,V,TC,N,F,FTC,FN);
  38. success &= mesh_to_tetgenio(V,F,in);
  39. }else if(ext == "off")
  40. {
  41. success = in.load_off(basename_char);
  42. }else if(ext == "node")
  43. {
  44. success = in.load_node(basename_char);
  45. }else
  46. {
  47. if(ext.length() > 0)
  48. {
  49. cerr<<"^read_into_tetgenio Warning: Unsupported extension ("<<ext<<
  50. "): try to load as basename..."<<endl;
  51. }
  52. // This changed as of (the so far unreleased) tetgen 1.5
  53. //success = in.load_tetmesh(basename_char);
  54. int object = tetgenbehavior::NODES;
  55. if(ext == "mesh")
  56. {
  57. object = tetgenbehavior::MEDIT;
  58. }
  59. success = in.load_tetmesh(basename_char,!tetgenbehavior::MEDIT);
  60. }
  61. return success;
  62. }