cdt.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 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 "cdt.h"
  9. #include "../../bounding_box.h"
  10. #include "../../writeOBJ.h"
  11. #include "tetrahedralize.h"
  12. template <
  13. typename DerivedV,
  14. typename DerivedF,
  15. typename DerivedTV,
  16. typename DerivedTT,
  17. typename DerivedTF>
  18. IGL_INLINE bool igl::copyleft::tetgen::cdt(
  19. const Eigen::PlainObjectBase<DerivedV>& V,
  20. const Eigen::PlainObjectBase<DerivedF>& F,
  21. const CDTParam & param,
  22. Eigen::PlainObjectBase<DerivedTV>& TV,
  23. Eigen::PlainObjectBase<DerivedTT>& TT,
  24. Eigen::PlainObjectBase<DerivedTF>& TF)
  25. {
  26. using namespace Eigen;
  27. using namespace std;
  28. typedef Eigen::PlainObjectBase<DerivedV> MatrixXS;
  29. typedef Eigen::PlainObjectBase<DerivedF> MatrixXI;
  30. // Effective input mesh
  31. MatrixXS U;
  32. MatrixXI G;
  33. if(param.use_bounding_box)
  34. {
  35. // Construct bounding box mesh
  36. MatrixXS BV;
  37. MatrixXI BF;
  38. bounding_box(V,BV,BF);
  39. // scale bounding box
  40. const RowVector3d mid =
  41. (BV.colwise().minCoeff() + BV.colwise().maxCoeff()).eval()*0.5;
  42. BV.rowwise() -= mid;
  43. assert(param.bounding_box_scale >= 1.);
  44. BV.array() *= param.bounding_box_scale;
  45. BV.rowwise() += mid;
  46. // Append bounding box to mesh
  47. U.resize(V.rows()+BV.rows(),V.cols());
  48. U<<V,BV;
  49. BF.array() += V.rows();
  50. G.resize(F.rows()+BF.rows(),F.cols());
  51. G<<F,BF;
  52. }else
  53. {
  54. // needless copies
  55. U = V;
  56. G = F;
  57. }
  58. // effective flags;
  59. string flags = param.flags + (param.use_bounding_box ? "" : "c");
  60. writeOBJ("UG.obj",U,G);
  61. return tetrahedralize(U,G,flags,TV,TT,TF);
  62. }
  63. #ifdef IGL_STATIC_LIBRARY
  64. // Explicit template specialization
  65. template bool igl::copyleft::tetgen::cdt<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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, igl::copyleft::tetgen::CDTParam const&, 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> >&);
  66. #endif