grid.cpp 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 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 "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. Derivedres sub;
  23. sub.resizeLike(res);
  24. sub.setConstant(0);
  25. for(int gi = 0;gi<GV.rows();gi++)
  26. {
  27. // omg, I'm implementing addition...
  28. for(int c = 0;c<res.size()-1;c++)
  29. {
  30. if(sub(c)>=res(c))
  31. {
  32. sub(c) = 0;
  33. // roll over
  34. sub(c+1)++;
  35. }
  36. }
  37. for(int c = 0;c<res.size();c++)
  38. {
  39. GV(gi,c) = lerp(sub(c),c);
  40. }
  41. sub(0)++;
  42. }
  43. }
  44. #ifdef IGL_STATIC_LIBRARY
  45. // Explicit template instantiation
  46. // generated by autoexplicit.sh
  47. template void igl::grid<Eigen::Matrix<int, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, 3, 1, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<int, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> >&);
  48. // generated by autoexplicit.sh
  49. template void igl::grid<Eigen::Matrix<int, 3, 1, 0, 3, 1>, Eigen::Matrix<float, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> >&);
  50. // generated by autoexplicit.sh
  51. 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> >&);
  52. // generated by autoexplicit.sh
  53. 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> >&);
  54. // generated by autoexplicit.sh
  55. 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> >&);
  56. // generated by autoexplicit.sh
  57. 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> >&);
  58. // generated by autoexplicit.sh
  59. 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> >&);
  60. 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> >&);
  61. #endif