sample_edges.cpp 913 B

1234567891011121314151617181920212223242526272829303132
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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 "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. // Resize output
  16. S.resize(V.rows() + k * E.rows(),V.cols());
  17. // Copy V at front of S
  18. S.block(0,0,V.rows(),V.cols()) = V;
  19. // loop over edges
  20. for(int i = 0;i<E.rows();i++)
  21. {
  22. Eigen::VectorXd tip = V.row(E(i,0));
  23. Eigen::VectorXd tail = V.row(E(i,1));
  24. for(int s=0;s<k;s++)
  25. {
  26. double f = double(s+1)/double(k+1);
  27. S.row(V.rows()+k*i+s) = f*tail + (1.0-f)*tip;
  28. }
  29. }
  30. }