tetrahedralize.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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 "tetrahedralize.h"
  9. #include "mesh_to_tetgenio.h"
  10. #include "tetgenio_to_tetmesh.h"
  11. // IGL includes
  12. #include "../../matrix_to_list.h"
  13. #include "../../list_to_matrix.h"
  14. #include "../../boundary_facets.h"
  15. // STL includes
  16. #include <cassert>
  17. #include <iostream>
  18. template <
  19. typename DerivedV,
  20. typename DerivedF,
  21. typename DerivedH,
  22. typename DerivedVM,
  23. typename DerivedFM,
  24. typename DerivedR,
  25. typename DerivedTV,
  26. typename DerivedTT,
  27. typename DerivedTF,
  28. typename DerivedTM,
  29. typename DerivedTR,
  30. typename DerivedTN,
  31. typename DerivedPT,
  32. typename DerivedFT>
  33. IGL_INLINE int igl::copyleft::tetgen::tetrahedralize(
  34. const Eigen::MatrixBase<DerivedV>& V,
  35. const Eigen::MatrixBase<DerivedF>& F,
  36. const Eigen::MatrixBase<DerivedH>& H,
  37. const Eigen::MatrixBase<DerivedVM>& VM,
  38. const Eigen::MatrixBase<DerivedFM>& FM,
  39. const Eigen::MatrixBase<DerivedR>& R,
  40. const std::string switches,
  41. Eigen::PlainObjectBase<DerivedTV>& TV,
  42. Eigen::PlainObjectBase<DerivedTT>& TT,
  43. Eigen::PlainObjectBase<DerivedTF>& TF,
  44. Eigen::PlainObjectBase<DerivedTM>& TM,
  45. Eigen::PlainObjectBase<DerivedTR>& TR,
  46. Eigen::PlainObjectBase<DerivedTN>& TN,
  47. Eigen::PlainObjectBase<DerivedPT>& PT,
  48. Eigen::PlainObjectBase<DerivedFT>& FT,
  49. int & num_regions)
  50. {
  51. // REAL is what tetgen is using as floating point precision
  52. // Prepare input
  53. tetgenio in,out;
  54. mesh_to_tetgenio(V,F,H,VM,FM,R,in);
  55. try
  56. {
  57. char * cswitches = new char[switches.size() + 1];
  58. std::strcpy(cswitches,switches.c_str());
  59. ::tetrahedralize(cswitches,&in, &out);
  60. delete[] cswitches;
  61. }catch(int e)
  62. {
  63. std::cerr<<"^"<<__FUNCTION__<<": TETGEN CRASHED... KABOOOM!!!"<<std::endl;
  64. return 1;
  65. }
  66. if(out.numberoftetrahedra == 0)
  67. {
  68. std::cerr<<"^"<<__FUNCTION__<<": Tetgen failed to create tets"<<std::endl;
  69. return 2;
  70. }
  71. // Prepare output
  72. bool ret = tetgenio_to_tetmesh(out,TV,TT,TF,TM,TR,TN,PT,FT,num_regions);
  73. if(!ret)
  74. {
  75. return -1;
  76. }
  77. if(TF.size() == 0)
  78. {
  79. boundary_facets(TT,TF);
  80. }
  81. return 0;
  82. }
  83. template <
  84. typename DerivedV,
  85. typename DerivedF,
  86. typename DerivedTV,
  87. typename DerivedTT,
  88. typename DerivedTF>
  89. IGL_INLINE int igl::copyleft::tetgen::tetrahedralize(
  90. const Eigen::MatrixBase<DerivedV>& V,
  91. const Eigen::MatrixBase<DerivedF>& F,
  92. const std::string switches,
  93. Eigen::PlainObjectBase<DerivedTV>& TV,
  94. Eigen::PlainObjectBase<DerivedTT>& TT,
  95. Eigen::PlainObjectBase<DerivedTF>& TF)
  96. {
  97. Eigen::VectorXi VM,FM;
  98. Eigen::MatrixXd H,R;
  99. Eigen::VectorXi TM,TR,PT;
  100. Eigen::MatrixXi FT,TN;
  101. int numRegions;
  102. return tetrahedralize(V,F,H,VM,FM,R,switches,TV,TT,TF,TM,TR,TN,PT,FT,numRegions);
  103. }
  104. #ifdef IGL_STATIC_LIBRARY
  105. // Explicit template instantiation
  106. // generated by autoexplicit.sh
  107. template int igl::copyleft::tetgen::tetrahedralize<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, 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&, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>>&);
  108. // generated by autoexplicit.sh
  109. template int igl::copyleft::tetgen::tetrahedralize<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, 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::Matrix<double, -1, -1, 0, -1, -1>, 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::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -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<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&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>> const&, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>>&, int&);
  110. #endif