moveFV.h 1011 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // moveFV.h
  3. // Preview3D
  4. //
  5. // Created by Olga Diamanti on 11/11/11.
  6. // Copyright (c) 2011 __MyCompanyName__. All rights reserved.
  7. //
  8. #ifndef Preview3D_moveFV_h
  9. #define Preview3D_moveFV_h
  10. namespace igl
  11. {
  12. // moveFV
  13. // Move a scalar field defined on faces to vertices by averaging
  14. //
  15. // Input:
  16. // V,F: mesh
  17. // S: scalar field defined on faces, Fx1
  18. //
  19. // Output:
  20. // SV: scalar field defined on vertices
  21. void moveFV(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::MatrixXd &S, Eigen::MatrixXd &SV);
  22. }
  23. inline void igl::moveFV(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::MatrixXd &S, Eigen::MatrixXd &SV)
  24. {
  25. SV = Eigen::MatrixXd::Zero(V.rows(),S.cols());
  26. Eigen::VectorXd COUNT = Eigen::VectorXd::Zero(V.rows());
  27. for (int i = 0; i <F.rows(); ++i)
  28. {
  29. for (int j = 0; j<F.cols(); ++j)
  30. {
  31. SV.row(F(i,j)) += S.row(i);
  32. COUNT[F(i,j)] ++;
  33. }
  34. }
  35. for (int i = 0; i <V.rows(); ++i)
  36. SV.row(i) /= COUNT[i];
  37. };
  38. #endif