colon.h 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #ifndef IGL_COLON_H
  9. #define IGL_COLON_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. namespace igl
  13. {
  14. /// Colon operator like matlab's colon operator. Enumerates values between low
  15. /// and hi with step step.
  16. ///
  17. /// @tparam L should be a eigen matrix primitive type like int or double
  18. /// @tparam S should be a eigen matrix primitive type like int or double
  19. /// @tparam H should be a eigen matrix primitive type like int or double
  20. /// @tparam T should be a eigen matrix primitive type like int or double
  21. /// @param[in] low starting value if step is valid then this is *always* the first
  22. /// element of I
  23. /// @param[in] step step difference between sequential elements returned in I,
  24. /// remember this will be cast to template T at compile time. If low<hi
  25. /// then step must be positive. If low>hi then step must be negative.
  26. /// Otherwise I will be set to empty.
  27. /// @param[in] hi ending value, if (hi-low)%step is zero then this will be the last
  28. /// element in I. If step is positive there will be no elements greater
  29. /// than hi, vice versa if hi<low
  30. /// @param[out] I list of values from low to hi with step size step
  31. ///
  32. /// \note
  33. /// This should be potentially replaced with eigen's LinSpaced() function
  34. ///
  35. /// If step = 1, it's about 5 times faster to use:
  36. /// X = Eigen::VectorXi::LinSpaced(n,0,n-1);
  37. /// than
  38. /// X = igl::colon<int>(0,n-1);
  39. ///
  40. template <typename L,typename S,typename H,typename T>
  41. IGL_INLINE void colon(
  42. const L low,
  43. const S step,
  44. const H hi,
  45. Eigen::Matrix<T,Eigen::Dynamic,1> & I);
  46. /// Colon operator like matlab's colon operator. Enumerates values between low
  47. /// and hi with unit step.
  48. ///
  49. /// @tparam L should be a eigen matrix primitive type like int or double
  50. /// @tparam H should be a eigen matrix primitive type like int or double
  51. /// @tparam T should be a eigen matrix primitive type like int or double
  52. /// @param[in] low starting value if step is valid then this is *always* the first
  53. /// element of I
  54. /// @param[in] step step difference between sequential elements returned in I,
  55. /// remember this will be cast to template T at compile time. If low<hi
  56. /// then step must be positive. If low>hi then step must be negative.
  57. /// Otherwise I will be set to empty.
  58. /// @param[in] hi ending value, if (hi-low)%step is zero then this will be the last
  59. /// element in I. If step is positive there will be no elements greater
  60. /// than hi, vice versa if hi<low
  61. /// @param[out] I list of values from low to hi with step size step
  62. template <typename L,typename H,typename T>
  63. IGL_INLINE void colon(
  64. const L low,
  65. const H hi,
  66. Eigen::Matrix<T,Eigen::Dynamic,1> & I);
  67. /// @private
  68. ///
  69. /// Hiding this from doxygen because it's messing up the indentation.
  70. ///
  71. /// Colon operator like matlab's colon operator. Enumerates values between low
  72. /// and hi with unit step.
  73. ///
  74. /// @tparam T should be a eigen matrix primitive type like int or double
  75. /// @tparam L should be a eigen matrix primitive type like int or double
  76. /// @tparam H should be a eigen matrix primitive type like int or double
  77. /// @param[in] low starting value if step is valid then this is *always* the first
  78. /// element of I
  79. /// @param[in] step step difference between sequential elements returned in I,
  80. /// remember this will be cast to template T at compile time. If low<hi
  81. /// then step must be positive. If low>hi then step must be negative.
  82. /// Otherwise I will be set to empty.
  83. /// @param[in] hi ending value, if (hi-low)%step is zero then this will be the last
  84. /// element in I. If step is positive there will be no elements greater
  85. /// than hi, vice versa if hi<low
  86. /// @return list of values from low to hi with step size step
  87. template <typename T,typename L,typename H>
  88. IGL_INLINE Eigen::Matrix<T,Eigen::Dynamic,1> colon(
  89. const L low,
  90. const H hi);
  91. }
  92. #ifndef IGL_STATIC_LIBRARY
  93. # include "colon.cpp"
  94. #endif
  95. #endif