tetrahedralized_grid.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "tetrahedralized_grid.h"
  2. #include "grid.h"
  3. template <
  4. typename DerivedGV,
  5. typename DerivedGT>
  6. IGL_INLINE void igl::tetrahedralized_grid(
  7. const int nx,
  8. const int ny,
  9. const int nz,
  10. const TetrahedralizedGripType type,
  11. Eigen::PlainObjectBase<DerivedGV> & GV,
  12. Eigen::PlainObjectBase<DerivedGT> & GT)
  13. {
  14. Eigen::RowVector3i res(nx,ny,nz);
  15. igl::grid(res,GV);
  16. return igl::tetrahedralized_grid(res,type,GT);
  17. }
  18. template <
  19. typename Derivedside,
  20. typename DerivedGT>
  21. IGL_INLINE void igl::tetrahedralized_grid(
  22. const Eigen::MatrixBase<Derivedside> & side,
  23. const TetrahedralizedGripType type,
  24. Eigen::PlainObjectBase<DerivedGT> & GT)
  25. {
  26. const int nx = side(0);
  27. const int ny = side(1);
  28. const int nz = side(2);
  29. const int m = (nx-1)*(ny-1)*(nz-1);
  30. // Rotationally symmetric
  31. int nt = -1;
  32. switch(type)
  33. {
  34. default: assert(false); break;
  35. case TETRAHEDRALIZED_GRID_TYPE_5: nt = 5; break;
  36. case TETRAHEDRALIZED_GRID_TYPE_6_ROTATIONAL: nt = 6; break;
  37. }
  38. GT.resize(m*nt,4);
  39. {
  40. int u = 0;
  41. for(int i = 0;i<nx-1;i++)
  42. {
  43. for(int j = 0;j<ny-1;j++)
  44. {
  45. for(int k = 0;k<nz-1;k++)
  46. {
  47. int v1 = (i+0)+nx*((j+0)+ny*(k+0));
  48. int v2 = (i+0)+nx*((j+1)+ny*(k+0));
  49. int v3 = (i+1)+nx*((j+0)+ny*(k+0));
  50. int v4 = (i+1)+nx*((j+1)+ny*(k+0));
  51. int v5 = (i+0)+nx*((j+0)+ny*(k+1));
  52. int v6 = (i+0)+nx*((j+1)+ny*(k+1));
  53. int v7 = (i+1)+nx*((j+0)+ny*(k+1));
  54. int v8 = (i+1)+nx*((j+1)+ny*(k+1));
  55. switch(type)
  56. {
  57. default: assert(false); break;
  58. case TETRAHEDRALIZED_GRID_TYPE_6_ROTATIONAL:
  59. // Rotationally symmetric
  60. GT.row(u*nt+0) << v1,v3,v8,v7;
  61. GT.row(u*nt+1) << v1,v8,v5,v7;
  62. GT.row(u*nt+2) << v1,v3,v4,v8;
  63. GT.row(u*nt+3) << v1,v4,v2,v8;
  64. GT.row(u*nt+4) << v1,v6,v5,v8;
  65. GT.row(u*nt+5) << v1,v2,v6,v8;
  66. break;
  67. case TETRAHEDRALIZED_GRID_TYPE_5:
  68. {
  69. // Five
  70. bool flip = true;
  71. if(((bool(i%2))^ (bool(j%2)))^ (bool(k%2)))
  72. {
  73. std::swap(v1,v3);
  74. std::swap(v2,v4);
  75. std::swap(v5,v7);
  76. std::swap(v6,v8);
  77. flip = false;
  78. }
  79. GT.row(u*nt+0) << v5,v3,v2,v1;
  80. GT.row(u*nt+1) << v3,v2,v8,v5;
  81. GT.row(u*nt+2) << v3,v4,v8,v2;
  82. GT.row(u*nt+3) << v3,v8,v7,v5;
  83. GT.row(u*nt+4) << v2,v6,v8,v5;
  84. if(flip)
  85. {
  86. std::swap(GT(u*nt+0,0),GT(u*nt+0,1));
  87. std::swap(GT(u*nt+1,0),GT(u*nt+1,1));
  88. std::swap(GT(u*nt+2,0),GT(u*nt+2,1));
  89. std::swap(GT(u*nt+3,0),GT(u*nt+3,1));
  90. std::swap(GT(u*nt+4,0),GT(u*nt+4,1));
  91. }
  92. break;
  93. }
  94. }
  95. u++;
  96. }
  97. }
  98. }
  99. assert(u == m);
  100. }
  101. }
  102. #ifdef IGL_STATIC_LIBRARY
  103. // Explicit template instantiation
  104. // generated by autoexplicit.sh
  105. template void igl::tetrahedralized_grid<Eigen::Matrix<int, 1, 3, 1, 1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, 1, 3, 1, 1, 3> > const&, igl::TetrahedralizedGripType, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  106. // generated by autoexplicit.sh
  107. #endif