connect_boundary_to_infinity.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 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 "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::PlainObjectBase<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::PlainObjectBase<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. typedef Eigen::Matrix<typename DerivedFO::Scalar,Eigen::Dynamic,1> VectorXI;
  28. FO.topLeftCorner(F.rows(),F.cols()) = F;
  29. FO.bottomLeftCorner(O.rows(),O.cols()) = O.rowwise().reverse();
  30. FO.bottomRightCorner(O.rows(),1).setConstant(inf_index);
  31. }
  32. template <
  33. typename DerivedV,
  34. typename DerivedF,
  35. typename DerivedVO,
  36. typename DerivedFO>
  37. IGL_INLINE void igl::connect_boundary_to_infinity(
  38. const Eigen::PlainObjectBase<DerivedV> & V,
  39. const Eigen::PlainObjectBase<DerivedF> & F,
  40. Eigen::PlainObjectBase<DerivedVO> & VO,
  41. Eigen::PlainObjectBase<DerivedFO> & FO)
  42. {
  43. typename DerivedV::Index inf_index = V.rows();
  44. connect_boundary_to_infinity(F,inf_index,FO);
  45. VO.resize(V.rows()+1,V.cols());
  46. VO.topLeftCorner(V.rows(),V.cols()) = V;
  47. auto inf = std::numeric_limits<typename DerivedVO::Scalar>::infinity();
  48. VO.row(V.rows()).setConstant(inf);
  49. }
  50. #ifdef IGL_STATIC_LIBRARY
  51. 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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<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> >&);
  52. #endif