Grid.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //
  2. // Created by wrede on 06.06.16.
  3. //
  4. #ifndef GBMOT_GRID_H
  5. #define GBMOT_GRID_H
  6. #include <vector>
  7. #include "../core/ObjectData.h"
  8. #include "Filter2D.h"
  9. namespace util
  10. {
  11. /**
  12. * Class for storing values in a three dimensional grid.
  13. * Can also be used for two dimensions but has a bit overhead.
  14. */
  15. class Grid
  16. {
  17. private:
  18. /**
  19. * The number of values on the x axis
  20. */
  21. const int width_count_;
  22. /**
  23. * The number of values on the y axis
  24. */
  25. const int height_count_;
  26. /**
  27. * The number of values on the z axis
  28. */
  29. const int depth_count_;
  30. /**
  31. * The size of the whole grid on the x axis
  32. */
  33. const double width_;
  34. /**
  35. * The size of the whole grid on the y axis
  36. */
  37. const double height_;
  38. /**
  39. * The size of the whole grid on the z axis
  40. */
  41. const double depth_;
  42. /**
  43. * The size of one grid cell on the x axis
  44. */
  45. const double cell_width_;
  46. /**
  47. * The size of one grid cell on the y axis
  48. */
  49. const double cell_height_;
  50. /**
  51. * The size of one grid cell on the z axis
  52. */
  53. const double cell_depth_;
  54. /**
  55. * The values stored in the grid cells
  56. */
  57. std::vector<std::vector<std::vector<core::ObjectDataPtr>>> values_;
  58. public:
  59. /**
  60. * Creates a new two dimensional grid.
  61. * @param width_count The number of elements on the x axis
  62. * @param height_count The number of elements on the y axis
  63. * @param width The size of the whole grid on the x axis
  64. * @param height The size of the whole grid on the y axis
  65. */
  66. Grid(int width_count, int height_count, double width, double height);
  67. /**
  68. * Creates a new three dimensional grid.
  69. * @param width_count The number of elements on the x axis
  70. * @param height_count The number of elements on the y axis
  71. * @param depth_count The number of elements on the z axis
  72. * @param width The size of the whole grid on the x axis
  73. * @param height The size of the whole grid on the y axis
  74. * @param depth The size of the whole grid on the z axis
  75. */
  76. Grid(int width_count, int height_count, int depth_count,
  77. double width, double height, double depth);
  78. /**
  79. * Sets a value in the grid cell with the given index.
  80. * @param value The value to set
  81. * @param x The x axis index
  82. * @param y The y axis index
  83. * @param z The z axis index
  84. */
  85. void SetValue(core::ObjectDataPtr value, int x, int y, int z = 0);
  86. /**
  87. * Sets a value in the grid cell at the given position.
  88. * @param value The value to set
  89. * @param x The x axis value
  90. * @param y The y axis value
  91. * @param z The z axis value
  92. */
  93. void SetValue(core::ObjectDataPtr value, double x, double y, double z = 0);
  94. /**
  95. * Gets the value in the grid cell with the given index.
  96. * @param x The x axis index
  97. * @param y The y axis index
  98. * @param z The z axis index
  99. * @return The value in the grid cell
  100. */
  101. core::ObjectDataPtr GetValue(int x, int y, int z = 0) const;
  102. /**
  103. * Gets the value in the grid cell at the given position.
  104. * @param x The x axis value
  105. * @param y The y axis value
  106. * @param z The z axis value
  107. * @return The value in the grid cell
  108. */
  109. core::ObjectDataPtr GetValue(double x, double y, double z = 0.0) const;
  110. /**
  111. * Gets the number of elements on the x axis.
  112. * @return The number of elements on the x axis
  113. */
  114. int GetWidthCount() const;
  115. /**
  116. * Gets the number of elements on the y axis.
  117. * @return The number of elements on the y axis
  118. */
  119. int GetHeightCount() const;
  120. /**
  121. * Gets the number of elements on the z axis.
  122. * @return The number of elements on the z axis
  123. */
  124. int GetDepthCount() const;
  125. /**
  126. * Gets the size of the whole grid on the x axis.
  127. * @return the size of the whole grid on the x axis
  128. */
  129. double GetWidth() const;
  130. /**
  131. * Gets the size of the whole grid on the y axis.
  132. * @return the size of the whole grid on the y axis
  133. */
  134. double GetHeight() const;
  135. /**
  136. * Gets the size of the whole grid on the z axis.
  137. * @return the size of the whole grid on the z axis
  138. */
  139. double GetDepth() const;
  140. /**
  141. * Converts a 3D position to an 3D index.
  142. * @param x The x axis value
  143. * @param y The y axis value
  144. * @param z The z axis value
  145. * @param xi The x axis index
  146. * @param yi The y axis index
  147. * @param zi The z axis index
  148. */
  149. void PositionToIndex(double x, double y, double z, int& xi, int& yi, int& zi) const;
  150. /**
  151. * Performs a 2D convolution.
  152. *
  153. * @param vicinity The size of the mask around the center (a 3x3 mask has a vicinity of 1)
  154. * @param mask The mask/kernel to use for the convolution
  155. * @param multiplier The value is multiplied with the result at the end of the convolution
  156. */
  157. void Convolve2D(int vicinity, double* mask, double multiplier);
  158. /**
  159. * Performs a 2D convolution.
  160. *
  161. * @param filter The 2D filter to use
  162. */
  163. void Convolve2D(util::Filter2D & filter);
  164. /**
  165. * Performs a 3D convolution.
  166. *
  167. * @param vicinity The size of the mask around the center (a 3x3 mask has a vicinity of 1)
  168. * @param mask The mask/kernel to use for the convolution
  169. * @param multiplier The value is multiplied with the result at the end of the convolution
  170. */
  171. void Convolve3D(int vicinity, double* mask, double multiplier);
  172. };
  173. }
  174. #endif //GBMOT_GRID_H