colon.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #ifndef IGL_COLON_H
  9. #define IGL_COLON_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. namespace igl
  13. {
  14. // Note:
  15. // This should be potentially replaced with eigen's LinSpaced() function
  16. //
  17. // If step = 1, it's about 5 times faster to use:
  18. // X = Eigen::VectorXi::LinSpaced(n,0,n-1);
  19. // than
  20. // X = igl::colon<int>(0,n-1);
  21. //
  22. // Colon operator like matlab's colon operator. Enumerats values between low
  23. // and hi with step step.
  24. // Templates:
  25. // L should be a eigen matrix primitive type like int or double
  26. // S should be a eigen matrix primitive type like int or double
  27. // H should be a eigen matrix primitive type like int or double
  28. // T should be a eigen matrix primitive type like int or double
  29. // Inputs:
  30. // low starting value if step is valid then this is *always* the first
  31. // element of I
  32. // step step difference between sequential elements returned in I,
  33. // remember this will be cast to template T at compile time. If low<hi
  34. // then step must be positive. If low>hi then step must be negative.
  35. // Otherwise I will be set to empty.
  36. // hi ending value, if (hi-low)%step is zero then this will be the last
  37. // element in I. If step is positive there will be no elements greater
  38. // than hi, vice versa if hi<low
  39. // Output:
  40. // I list of values from low to hi with step size step
  41. template <typename L,typename S,typename H,typename T>
  42. IGL_INLINE void colon(
  43. const L low,
  44. const S step,
  45. const H hi,
  46. Eigen::Matrix<T,Eigen::Dynamic,1> & I);
  47. // Same as above but step == (T)1
  48. template <typename L,typename H,typename T>
  49. IGL_INLINE void colon(
  50. const L low,
  51. const H hi,
  52. Eigen::Matrix<T,Eigen::Dynamic,1> & I);
  53. // Return output rather than set in reference
  54. template <typename T,typename L,typename H>
  55. IGL_INLINE Eigen::Matrix<T,Eigen::Dynamic,1> colon(
  56. const L low,
  57. const H hi);
  58. }
  59. #ifndef IGL_STATIC_LIBRARY
  60. # include "colon.cpp"
  61. #endif
  62. #endif