unique_simplices.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "unique_simplices.h"
  9. #include "sort.h"
  10. #include "unique.h"
  11. #include "get_seconds.h"
  12. template <
  13. typename DerivedF,
  14. typename DerivedFF,
  15. typename DerivedIA,
  16. typename DerivedIC>
  17. IGL_INLINE void igl::unique_simplices(
  18. const Eigen::PlainObjectBase<DerivedF>& F,
  19. Eigen::PlainObjectBase<DerivedFF>& FF,
  20. Eigen::PlainObjectBase<DerivedIA>& IA,
  21. Eigen::PlainObjectBase<DerivedIC>& IC)
  22. {
  23. using namespace Eigen;
  24. using namespace igl;
  25. using namespace std;
  26. // Sort each face
  27. MatrixXi sortF, unusedI;
  28. igl::sort(F,2,true,sortF,unusedI);
  29. // Find unique faces
  30. MatrixXi C;
  31. igl::unique_rows(sortF,C,IA,IC);
  32. FF.resize(IA.size(),F.cols());
  33. const size_t mff = FF.rows();
  34. // Minimum number of iterms per openmp thread
  35. #ifndef IGL_OMP_MIN_VALUE
  36. # define IGL_OMP_MIN_VALUE 1000
  37. #endif
  38. #pragma omp parallel for if (mff>IGL_OMP_MIN_VALUE)
  39. // Copy into output
  40. for(int i = 0;i<mff;i++)
  41. {
  42. FF.row(i) = F.row(IA(i));
  43. }
  44. }
  45. template <
  46. typename DerivedF,
  47. typename DerivedFF>
  48. IGL_INLINE void igl::unique_simplices(
  49. const Eigen::PlainObjectBase<DerivedF>& F,
  50. Eigen::PlainObjectBase<DerivedFF>& FF)
  51. {
  52. Eigen::VectorXi IA,IC;
  53. return unique_simplices(F,FF,IA,IC);
  54. }
  55. #ifdef IGL_STATIC_LIBRARY
  56. // Explicit template instanciations
  57. template void igl::unique_simplices<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  58. template void igl::unique_simplices<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&);
  59. template void igl::unique_simplices<Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<long, -1, 1, 0, -1, 1>, Eigen::Matrix<long, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<long, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<long, -1, 1, 0, -1, 1> >&);
  60. #endif