triangulated_grid.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 "triangulated_grid.h"
  9. #include "grid.h"
  10. #include <cassert>
  11. template <
  12. typename XType,
  13. typename YType,
  14. typename DerivedGV,
  15. typename DerivedGF>
  16. IGL_INLINE void igl::triangulated_grid(
  17. const XType & nx,
  18. const YType & ny,
  19. Eigen::PlainObjectBase<DerivedGV> & GV,
  20. Eigen::PlainObjectBase<DerivedGF> & GF)
  21. {
  22. using namespace Eigen;
  23. Eigen::Matrix<XType,2,1> res(nx,ny);
  24. igl::grid(res,GV);
  25. GF.resize((nx-1)*(ny-1)*2,3);
  26. for(int y = 0;y<ny-1;y++)
  27. {
  28. for(int x = 0;x<nx-1;x++)
  29. {
  30. // index of southwest corner
  31. const XType sw = (x +nx*(y+0));
  32. const XType se = (x+1+nx*(y+0));
  33. const XType ne = (x+1+nx*(y+1));
  34. const XType nw = (x +nx*(y+1));
  35. // Index of first triangle in this square
  36. const XType gf = 2*(x+(nx-1)*y);
  37. GF(gf+0,0) = sw;
  38. GF(gf+0,1) = se;
  39. GF(gf+0,2) = nw;
  40. GF(gf+1,0) = se;
  41. GF(gf+1,1) = ne;
  42. GF(gf+1,2) = nw;
  43. }
  44. }
  45. }
  46. #ifdef IGL_STATIC_LIBRARY
  47. // Explicit template instantiation
  48. // generated by autoexplicit.sh
  49. template void igl::triangulated_grid<int, int, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(int const&, int const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  50. #endif