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