false_barycentric_subdivision.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 "false_barycentric_subdivision.h"
  9. #include "verbose.h"
  10. #include <algorithm>
  11. #include <igl/barycenter.h>
  12. template <typename Scalar, typename Index>
  13. IGL_INLINE void igl::false_barycentric_subdivision(
  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. #ifdef IGL_STATIC_LIBRARY
  45. // Explicit template specialization
  46. template void igl::false_barycentric_subdivision<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&);
  47. template void igl::false_barycentric_subdivision<Eigen::Matrix<double, -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&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  48. #endif