grid.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 "grid.h"
  9. #include <cassert>
  10. template <
  11. typename Derivedres,
  12. typename DerivedGV>
  13. IGL_INLINE void igl::grid(
  14. const Eigen::MatrixBase<Derivedres> & res,
  15. Eigen::PlainObjectBase<DerivedGV> & GV)
  16. {
  17. using namespace Eigen;
  18. typedef typename DerivedGV::Scalar Scalar;
  19. GV.resize(res.array().prod(),res.size());
  20. const auto lerp =
  21. [&res](const Scalar di, const int d)->Scalar{return di/(Scalar)(res(d)-1);};
  22. int gi = 0;
  23. Derivedres sub;
  24. sub.resizeLike(res);
  25. sub.setConstant(0);
  26. for(int gi = 0;gi<GV.rows();gi++)
  27. {
  28. // omg, I'm implementing addition...
  29. for(int c = 0;c<res.size()-1;c++)
  30. {
  31. if(sub(c)>=res(c))
  32. {
  33. sub(c) = 0;
  34. // roll over
  35. sub(c+1)++;
  36. }
  37. }
  38. for(int c = 0;c<res.size();c++)
  39. {
  40. GV(gi,c) = lerp(sub(c),c);
  41. }
  42. sub(0)++;
  43. }
  44. }
  45. #ifdef IGL_STATIC_LIBRARY
  46. // Explicit template instantiation
  47. // generated by autoexplicit.sh
  48. template void igl::grid<Eigen::Matrix<int, 2, 1, 0, 2, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, 2, 1, 0, 2, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  49. // generated by autoexplicit.sh
  50. template void igl::grid<Eigen::Matrix<int, 1, 3, 1, 1, 3>, Eigen::Matrix<float, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> >&);
  51. // generated by autoexplicit.sh
  52. template void igl::grid<Eigen::Matrix<int, 3, 1, 0, 3, 1>, Eigen::Matrix<float, -1, 3, 0, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<int, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 0, -1, 3> >&);
  53. // generated by autoexplicit.sh
  54. template void igl::grid<Eigen::Matrix<int, 3, 1, 0, 3, 1>, Eigen::Matrix<float, -1, 3, 1, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<int, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> >&);
  55. // generated by autoexplicit.sh
  56. template void igl::grid<Eigen::Matrix<int, 3, 1, 0, 3, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  57. template void igl::grid<Eigen::Matrix<int, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  58. #endif