cdt.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "tetrahedralize.h"
  11. template <
  12. typename DerivedV,
  13. typename DerivedF,
  14. typename DerivedTV,
  15. typename DerivedTT,
  16. typename DerivedTF>
  17. IGL_INLINE bool igl::copyleft::tetgen::cdt(
  18. const Eigen::PlainObjectBase<DerivedV>& V,
  19. const Eigen::PlainObjectBase<DerivedF>& F,
  20. const CDTParam & param,
  21. Eigen::PlainObjectBase<DerivedTV>& TV,
  22. Eigen::PlainObjectBase<DerivedTT>& TT,
  23. Eigen::PlainObjectBase<DerivedTF>& TF)
  24. {
  25. using namespace Eigen;
  26. using namespace std;
  27. // Effective input mesh
  28. DerivedV U;
  29. DerivedF G;
  30. if(param.use_bounding_box)
  31. {
  32. // Construct bounding box mesh
  33. DerivedV BV;
  34. DerivedF BF;
  35. bounding_box(V,BV,BF);
  36. // scale bounding box
  37. const RowVector3d mid =
  38. (BV.colwise().minCoeff() + BV.colwise().maxCoeff()).eval()*0.5;
  39. BV.rowwise() -= mid;
  40. assert(param.bounding_box_scale >= 1.);
  41. BV.array() *= param.bounding_box_scale;
  42. BV.rowwise() += mid;
  43. // Append bounding box to mesh
  44. U.resize(V.rows()+BV.rows(),V.cols());
  45. U<<V,BV;
  46. BF.array() += V.rows();
  47. G.resize(F.rows()+BF.rows(),F.cols());
  48. G<<F,BF;
  49. }else
  50. {
  51. // needless copies
  52. U = V;
  53. G = F;
  54. }
  55. // effective flags;
  56. string flags = param.flags + (param.use_bounding_box ? "" : "c");
  57. return tetrahedralize(U,G,flags,TV,TT,TF);
  58. }
  59. #ifdef IGL_STATIC_LIBRARY
  60. // Explicit template instantiation
  61. 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> >&);
  62. #endif