mesh_to_tetgenio.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "mesh_to_tetgenio.h"
  9. // IGL includes
  10. #include "../../matrix_to_list.h"
  11. // STL includes
  12. #include <cassert>
  13. IGL_INLINE bool igl::copyleft::tetgen::mesh_to_tetgenio(
  14. const std::vector<std::vector<REAL > > & V,
  15. const std::vector<std::vector<int> > & F,
  16. tetgenio & in)
  17. {
  18. using namespace std;
  19. // all indices start from 0
  20. in.firstnumber = 0;
  21. in.numberofpoints = V.size();
  22. in.pointlist = new REAL[in.numberofpoints * 3];
  23. // loop over points
  24. for(int i = 0; i < (int)V.size(); i++)
  25. {
  26. assert(V[i].size() == 3);
  27. in.pointlist[i*3+0] = V[i][0];
  28. in.pointlist[i*3+1] = V[i][1];
  29. in.pointlist[i*3+2] = V[i][2];
  30. }
  31. in.numberoffacets = F.size();
  32. in.facetlist = new tetgenio::facet[in.numberoffacets];
  33. in.facetmarkerlist = new int[in.numberoffacets];
  34. // loop over face
  35. for(int i = 0;i < (int)F.size(); i++)
  36. {
  37. in.facetmarkerlist[i] = i;
  38. tetgenio::facet * f = &in.facetlist[i];
  39. f->numberofpolygons = 1;
  40. f->polygonlist = new tetgenio::polygon[f->numberofpolygons];
  41. f->numberofholes = 0;
  42. f->holelist = NULL;
  43. tetgenio::polygon * p = &f->polygonlist[0];
  44. p->numberofvertices = F[i].size();
  45. p->vertexlist = new int[p->numberofvertices];
  46. // loop around face
  47. for(int j = 0;j < (int)F[i].size(); j++)
  48. {
  49. p->vertexlist[j] = F[i][j];
  50. }
  51. }
  52. return true;
  53. }
  54. template <typename DerivedV, typename DerivedF>
  55. IGL_INLINE bool igl::copyleft::tetgen::mesh_to_tetgenio(
  56. const Eigen::PlainObjectBase<DerivedV>& V,
  57. const Eigen::PlainObjectBase<DerivedF>& F,
  58. tetgenio & in)
  59. {
  60. using namespace std;
  61. vector<vector<REAL> > vV;
  62. vector<vector<int> > vF;
  63. matrix_to_list(V,vV);
  64. matrix_to_list(F,vF);
  65. return mesh_to_tetgenio(vV,vF,in);
  66. }
  67. #ifdef IGL_STATIC_LIBRARY
  68. // Explicit template specialization
  69. template bool igl::copyleft::tetgen::mesh_to_tetgenio<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, tetgenio&);
  70. #endif