is_edge_manifold.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 "is_edge_manifold.h"
  9. #include "oriented_facets.h"
  10. #include "unique_simplices.h"
  11. #include "unique_edge_map.h"
  12. #include <algorithm>
  13. #include <vector>
  14. template <
  15. typename DerivedF,
  16. typename DerivedEMAP,
  17. typename DerivedBF,
  18. typename DerivedBE>
  19. IGL_INLINE bool igl::is_edge_manifold(
  20. const Eigen::MatrixBase<DerivedF>& F,
  21. const typename DerivedF::Index ne,
  22. const Eigen::MatrixBase<DerivedEMAP>& EMAP,
  23. Eigen::PlainObjectBase<DerivedBF>& BF,
  24. Eigen::PlainObjectBase<DerivedBE>& BE)
  25. {
  26. typedef typename DerivedF::Index Index;
  27. std::vector<Index> count(ne,0);
  28. for(Index e = 0;e<EMAP.rows();e++)
  29. {
  30. count[EMAP[e]]++;
  31. }
  32. const Index m = F.rows();
  33. BF.resize(m,3);
  34. BE.resize(ne,1);
  35. bool all = true;
  36. for(Index e = 0;e<EMAP.rows();e++)
  37. {
  38. const bool manifold = count[EMAP[e]] <= 2;
  39. all &= BF(e%m,e/m) = manifold;
  40. BE(EMAP[e]) = manifold;
  41. }
  42. return all;
  43. }
  44. template <
  45. typename DerivedF,
  46. typename DerivedBF,
  47. typename DerivedE,
  48. typename DerivedEMAP,
  49. typename DerivedBE>
  50. IGL_INLINE bool igl::is_edge_manifold(
  51. const Eigen::MatrixBase<DerivedF>& F,
  52. Eigen::PlainObjectBase<DerivedBF>& BF,
  53. Eigen::PlainObjectBase<DerivedE>& E,
  54. Eigen::PlainObjectBase<DerivedEMAP>& EMAP,
  55. Eigen::PlainObjectBase<DerivedBE>& BE)
  56. {
  57. typedef Eigen::Matrix<typename DerivedF::Scalar ,Eigen::Dynamic,2> MatrixXF2;
  58. MatrixXF2 allE;
  59. unique_edge_map(F,allE,E,EMAP);
  60. return is_edge_manifold(F,E.rows(),EMAP,BF,BE);
  61. }
  62. template <typename DerivedF>
  63. IGL_INLINE bool igl::is_edge_manifold(
  64. const Eigen::MatrixBase<DerivedF>& F)
  65. {
  66. Eigen::Array<bool,Eigen::Dynamic,Eigen::Dynamic> BF;
  67. Eigen::Array<bool,Eigen::Dynamic,1> BE;
  68. Eigen::MatrixXi E;
  69. Eigen::VectorXi EMAP;
  70. return is_edge_manifold(F,BF,E,EMAP,BE);
  71. }
  72. #ifdef IGL_STATIC_LIBRARY
  73. // Explicit template instantiation
  74. template bool igl::is_edge_manifold<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&);
  75. template bool igl::is_edge_manifold<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
  76. template bool igl::is_edge_manifold<Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&);
  77. template bool igl::is_edge_manifold<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Array<bool, -1, -1, 0, -1, -1>, Eigen::Array<bool, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1>::Index, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Array<bool, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Array<bool, -1, 1, 0, -1, 1> >&);
  78. #endif