cdt.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // Effective input mesh
  29. DerivedV U;
  30. DerivedF G;
  31. if(param.use_bounding_box)
  32. {
  33. // Construct bounding box mesh
  34. DerivedV BV;
  35. DerivedF BF;
  36. bounding_box(V,BV,BF);
  37. // scale bounding box
  38. const RowVector3d mid =
  39. (BV.colwise().minCoeff() + BV.colwise().maxCoeff()).eval()*0.5;
  40. BV.rowwise() -= mid;
  41. assert(param.bounding_box_scale >= 1.);
  42. BV.array() *= param.bounding_box_scale;
  43. BV.rowwise() += mid;
  44. // Append bounding box to mesh
  45. U.resize(V.rows()+BV.rows(),V.cols());
  46. U<<V,BV;
  47. BF.array() += V.rows();
  48. G.resize(F.rows()+BF.rows(),F.cols());
  49. G<<F,BF;
  50. }else
  51. {
  52. // needless copies
  53. U = V;
  54. G = F;
  55. }
  56. // effective flags;
  57. string flags = param.flags + (param.use_bounding_box ? "" : "c");
  58. writeOBJ("UG.obj",U,G);
  59. return tetrahedralize(U,G,flags,TV,TT,TF);
  60. }
  61. #ifdef IGL_STATIC_LIBRARY
  62. // Explicit template specialization
  63. 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> >&);
  64. #endif