connect_boundary_to_infinity.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 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 "connect_boundary_to_infinity.h"
  9. #include "boundary_facets.h"
  10. template <typename DerivedF, typename DerivedFO>
  11. IGL_INLINE void igl::connect_boundary_to_infinity(
  12. const Eigen::MatrixBase<DerivedF> & F,
  13. Eigen::PlainObjectBase<DerivedFO> & FO)
  14. {
  15. return connect_boundary_to_infinity(F,F.maxCoeff(),FO);
  16. }
  17. template <typename DerivedF, typename DerivedFO>
  18. IGL_INLINE void igl::connect_boundary_to_infinity(
  19. const Eigen::MatrixBase<DerivedF> & F,
  20. const typename DerivedF::Scalar inf_index,
  21. Eigen::PlainObjectBase<DerivedFO> & FO)
  22. {
  23. // Determine boundary edges
  24. Eigen::Matrix<typename DerivedFO::Scalar,Eigen::Dynamic,Eigen::Dynamic> O;
  25. boundary_facets(F,O);
  26. FO.resize(F.rows()+O.rows(),F.cols());
  27. FO.topLeftCorner(F.rows(),F.cols()) = F;
  28. FO.bottomLeftCorner(O.rows(),O.cols()) = O.rowwise().reverse();
  29. FO.bottomRightCorner(O.rows(),1).setConstant(inf_index);
  30. }
  31. template <
  32. typename DerivedV,
  33. typename DerivedF,
  34. typename DerivedVO,
  35. typename DerivedFO>
  36. IGL_INLINE void igl::connect_boundary_to_infinity(
  37. const Eigen::MatrixBase<DerivedV> & V,
  38. const Eigen::MatrixBase<DerivedF> & F,
  39. Eigen::PlainObjectBase<DerivedVO> & VO,
  40. Eigen::PlainObjectBase<DerivedFO> & FO)
  41. {
  42. typename DerivedV::Index inf_index = V.rows();
  43. connect_boundary_to_infinity(F,inf_index,FO);
  44. VO.resize(V.rows()+1,V.cols());
  45. VO.topLeftCorner(V.rows(),V.cols()) = V;
  46. auto inf = std::numeric_limits<typename DerivedVO::Scalar>::infinity();
  47. VO.row(V.rows()).setConstant(inf);
  48. }
  49. #ifdef IGL_STATIC_LIBRARY
  50. template void igl::connect_boundary_to_infinity<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  51. #endif