sample_edges.cpp 924 B

123456789101112131415161718192021222324252627282930313233
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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 "sample_edges.h"
  9. IGL_INLINE void igl::sample_edges(
  10. const Eigen::MatrixXd & V,
  11. const Eigen::MatrixXi & E,
  12. const int k,
  13. Eigen::MatrixXd & S)
  14. {
  15. using namespace Eigen;
  16. // Resize output
  17. S.resize(V.rows() + k * E.rows(),V.cols());
  18. // Copy V at front of S
  19. S.block(0,0,V.rows(),V.cols()) = V;
  20. // loop over edges
  21. for(int i = 0;i<E.rows();i++)
  22. {
  23. VectorXd tip = V.row(E(i,0));
  24. VectorXd tail = V.row(E(i,1));
  25. for(int s=0;s<k;s++)
  26. {
  27. double f = double(s+1)/double(k+1);
  28. S.row(V.rows()+k*i+s) = f*tail + (1.0-f)*tip;
  29. }
  30. }
  31. }