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