2
0

is_irregular_vertex.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Daniele Panozzo <[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_irregular_vertex.h"
  9. #include <vector>
  10. #include "is_border_vertex.h"
  11. template <typename DerivedF>
  12. IGL_INLINE std::vector<bool> igl::is_irregular_vertex(const Eigen::MatrixBase<DerivedF> &F)
  13. {
  14. Eigen::VectorXi count = Eigen::VectorXi::Zero(F.maxCoeff()+1);
  15. for(unsigned i=0; i<F.rows();++i)
  16. {
  17. for(unsigned j=0; j<F.cols();++j)
  18. {
  19. if (F(i,j) < F(i,(j+1)%F.cols())) // avoid duplicate edges
  20. {
  21. count(F(i,j )) += 1;
  22. count(F(i,(j+1)%F.cols())) += 1;
  23. }
  24. }
  25. }
  26. std::vector<bool> border;
  27. if(F.cols() == 3)
  28. {
  29. border = is_border_vertex(F);
  30. }else
  31. {
  32. assert(F.cols() == 4 && "Only triangle and quad meshes are supported");
  33. // Silly way to find border vertices for now
  34. Eigen::Matrix<typename DerivedF::Scalar, Eigen::Dynamic, Eigen::Dynamic> T(2*F.rows(),3);
  35. T << F.col(0), F.col(1), F.col(2),
  36. F.col(0), F.col(2), F.col(3);
  37. border = is_border_vertex(T);
  38. }
  39. std::vector<bool> res(count.size());
  40. for (unsigned i=0; i<res.size(); ++i)
  41. res[i] = !border[i] && count[i] != (F.cols() == 3 ? 6 : 4 );
  42. return res;
  43. }
  44. #ifdef IGL_STATIC_LIBRARY
  45. // Explicit template instantiation
  46. template std::vector<bool, std::allocator<bool> > igl::is_irregular_vertex<Eigen::Matrix<int, -1, 3, 0, -1, 3> > (Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&);
  47. template std::vector<bool, std::allocator<bool> > igl::is_irregular_vertex<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
  48. #endif