edge_midpoints.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2020 Oded Stein <[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 "edge_midpoints.h"
  9. template<typename DerivedV,typename DerivedF,typename DerivedE,
  10. typename DerivedoE, typename Derivedmps>
  11. IGL_INLINE void
  12. igl::edge_midpoints(
  13. const Eigen::MatrixBase<DerivedV> &V,
  14. const Eigen::MatrixBase<DerivedF> &F,
  15. const Eigen::MatrixBase<DerivedE> &E,
  16. const Eigen::MatrixBase<DerivedoE> &oE,
  17. Eigen::PlainObjectBase<Derivedmps> &mps)
  18. {
  19. assert(E.rows()==F.rows() && "E does not match dimensions of F.");
  20. assert(oE.rows()==F.rows() && "oE does not match dimensions of F.");
  21. assert(E.cols()==3 && F.cols()==3 && oE.cols()==3 &&
  22. "This method is for triangle meshes.");
  23. assert(F.maxCoeff()<V.rows() && "V does not seem to belong to F.");
  24. using ScalarE = typename DerivedE::Scalar;
  25. using ScalarF = typename DerivedF::Scalar;
  26. const ScalarE m = E.maxCoeff()+1;
  27. mps.resize(m, V.cols());
  28. for(Eigen::Index i=0; i<F.rows(); ++i) {
  29. for(int j=0; j<3; ++j) {
  30. if(oE(i,j)<0) {
  31. continue;
  32. }
  33. const ScalarE e = E(i,j);
  34. const ScalarF vi=F(i,(j+1)%3), vj=F(i,(j+2)%3);
  35. mps.row(e) = 0.5*(V.row(vi) + V.row(vj));
  36. }
  37. }
  38. }
  39. #ifdef IGL_STATIC_LIBRARY
  40. // Explicit template instantiation
  41. template void igl::edge_midpoints<Eigen::Matrix<double, -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::Matrix<double, -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::MatrixBase<Eigen::Matrix<int, -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> >&);
  42. #endif