cdt.cpp 2.4 KB

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