add_barycenter.cpp 1.3 KB

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