false_barycentric_subdivision.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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 "false_barycentric_subdivision.h"
  9. #include "PlainMatrix.h"
  10. #include "barycenter.h"
  11. #include <algorithm>
  12. template <typename DerivedV, typename DerivedF, typename DerivedVD, typename DerivedFD>
  13. IGL_INLINE void igl::false_barycentric_subdivision(
  14. const Eigen::MatrixBase<DerivedV> & V,
  15. const Eigen::MatrixBase<DerivedF> & F,
  16. Eigen::PlainObjectBase<DerivedVD> & VD,
  17. Eigen::PlainObjectBase<DerivedFD> & FD)
  18. {
  19. // Compute face barycenter
  20. PlainMatrix<DerivedV> BC;
  21. igl::barycenter(V,F,BC);
  22. // Add the barycenters to the vertices
  23. VD.resize(V.rows()+F.rows(),3);
  24. VD.block(0,0,V.rows(),3) = V;
  25. VD.block(V.rows(),0,F.rows(),3) = BC;
  26. // Each face is split four ways
  27. FD.resize(F.rows()*3,3);
  28. for (unsigned i=0; i<F.rows(); ++i)
  29. {
  30. int i0 = F(i,0);
  31. int i1 = F(i,1);
  32. int i2 = F(i,2);
  33. int i3 = V.rows() + i;
  34. Eigen::Matrix<typename DerivedFD::Scalar,1,3> F0,F1,F2;
  35. F0 << i0,i1,i3;
  36. F1 << i1,i2,i3;
  37. F2 << i2,i0,i3;
  38. FD.row(i*3 + 0) = F0;
  39. FD.row(i*3 + 1) = F1;
  40. FD.row(i*3 + 2) = F2;
  41. }
  42. }
  43. #ifdef IGL_STATIC_LIBRARY
  44. // Explicit template instantiation
  45. template void igl::false_barycentric_subdivision<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::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>> const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1>>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1>>&);
  46. #endif