read_into_tetgenio.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "read_into_tetgenio.h"
  9. #include "mesh_to_tetgenio.h"
  10. // IGL includes
  11. #include "../../pathinfo.h"
  12. #ifndef IGL_NO_EIGEN
  13. # define IGL_NO_EIGEN_WAS_NOT_ALREADY_DEFINED
  14. # define IGL_NO_EIGEN
  15. #endif
  16. // Include igl headers without including Eigen
  17. #include "../../readOBJ.h"
  18. #ifdef IGL_NO_EIGEN_WAS_NOT_ALREADY_DEFINED
  19. # undef IGL_NO_EIGEN
  20. #endif
  21. // STL includes
  22. #include <algorithm>
  23. #include <iostream>
  24. #include <vector>
  25. IGL_INLINE bool igl::copyleft::tetgen::read_into_tetgenio(
  26. const std::string & path,
  27. tetgenio & in)
  28. {
  29. using namespace std;
  30. // get file extension
  31. string dirname,basename,ext,filename;
  32. pathinfo(path,dirname,basename,ext,filename);
  33. // convert to lower case for easy comparison
  34. transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
  35. bool success = false;
  36. char basename_char[1024];
  37. strcpy(basename_char,basename.c_str());
  38. if(ext == "obj")
  39. {
  40. // read obj into vertex list and face list
  41. vector<vector<REAL> > V,TC,N;
  42. vector<vector<int> > F,FTC,FN;
  43. success = readOBJ(path,V,TC,N,F,FTC,FN);
  44. success &= mesh_to_tetgenio(V,F,in);
  45. }else if(ext == "off")
  46. {
  47. success = in.load_off(basename_char);
  48. }else if(ext == "node")
  49. {
  50. success = in.load_node(basename_char);
  51. }else
  52. {
  53. if(ext.length() > 0)
  54. {
  55. cerr<<"^read_into_tetgenio Warning: Unsupported extension ("<<ext<<
  56. "): try to load as basename..."<<endl;
  57. }
  58. // This changed as of (the so far unreleased) tetgen 1.5
  59. //success = in.load_tetmesh(basename_char);
  60. //int object = tetgenbehavior::NODES;
  61. //if(ext == "mesh")
  62. //{
  63. // object = tetgenbehavior::MEDIT;
  64. //}
  65. success = in.load_tetmesh(basename_char,!tetgenbehavior::MEDIT);
  66. }
  67. return success;
  68. }