sort_triangles.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 "sort_triangles.h"
  9. #include "barycenter.h"
  10. #include "sort.h"
  11. #include "sortrows.h"
  12. #include "slice.h"
  13. #include "round.h"
  14. #include "placeholders.h"
  15. #include "colon.h"
  16. #include <iostream>
  17. template <
  18. typename DerivedV,
  19. typename DerivedF,
  20. typename DerivedMV,
  21. typename DerivedP,
  22. typename DerivedFF,
  23. typename DerivedI>
  24. IGL_INLINE void igl::sort_triangles(
  25. const Eigen::MatrixBase<DerivedV> & V,
  26. const Eigen::MatrixBase<DerivedF> & F,
  27. const Eigen::MatrixBase<DerivedMV> & MV,
  28. const Eigen::MatrixBase<DerivedP> & P,
  29. Eigen::PlainObjectBase<DerivedFF> & FF,
  30. Eigen::PlainObjectBase<DerivedI> & I)
  31. {
  32. typedef typename DerivedV::Scalar Scalar;
  33. // Barycenter, centroid
  34. Eigen::Matrix<Scalar, DerivedF::RowsAtCompileTime,1> D,sD;
  35. Eigen::Matrix<Scalar, DerivedF::RowsAtCompileTime,3> BC;
  36. barycenter(V,F,BC);
  37. Eigen::Matrix<Scalar, DerivedF::RowsAtCompileTime,4> BC4(BC.rows(),4);
  38. BC4.leftCols(3) = BC;
  39. BC4.col(3).setConstant(1);
  40. D = BC4*(
  41. MV.template cast<Scalar>().transpose()*
  42. P.template cast<Scalar>().transpose().eval().col(2));
  43. sort(D,1,false,sD,I);
  44. FF = F(I.derived(),igl::placeholders::all);
  45. }
  46. #ifdef IGL_STATIC_LIBRARY
  47. // Explicit template instantiation
  48. // generated by autoexplicit.sh
  49. template void igl::sort_triangles<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<int, -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::MatrixBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::MatrixBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  50. template void igl::sort_triangles<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, 4, 4, 0, 4, 4>, Eigen::Matrix<double, 4, 4, 0, 4, 4>, Eigen::Matrix<int, -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::MatrixBase<Eigen::Matrix<double, 4, 4, 0, 4, 4> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  51. #endif