read_into_tetgenio.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 igl;
  30. using namespace std;
  31. // get file extension
  32. string dirname,basename,ext,filename;
  33. pathinfo(path,dirname,basename,ext,filename);
  34. // convert to lower case for easy comparison
  35. transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
  36. bool success = false;
  37. char basename_char[1024];
  38. strcpy(basename_char,basename.c_str());
  39. if(ext == "obj")
  40. {
  41. // read obj into vertex list and face list
  42. vector<vector<REAL> > V,TC,N;
  43. vector<vector<int> > F,FTC,FN;
  44. success = readOBJ(path,V,TC,N,F,FTC,FN);
  45. success &= mesh_to_tetgenio(V,F,in);
  46. }else if(ext == "off")
  47. {
  48. success = in.load_off(basename_char);
  49. }else if(ext == "node")
  50. {
  51. success = in.load_node(basename_char);
  52. }else
  53. {
  54. if(ext.length() > 0)
  55. {
  56. cerr<<"^read_into_tetgenio Warning: Unsupported extension ("<<ext<<
  57. "): try to load as basename..."<<endl;
  58. }
  59. // This changed as of (the so far unreleased) tetgen 1.5
  60. //success = in.load_tetmesh(basename_char);
  61. //int object = tetgenbehavior::NODES;
  62. //if(ext == "mesh")
  63. //{
  64. // object = tetgenbehavior::MEDIT;
  65. //}
  66. success = in.load_tetmesh(basename_char,!tetgenbehavior::MEDIT);
  67. }
  68. return success;
  69. }