Grid.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. namespace util
  9. {
  10. /**
  11. * Class for storing values in a three dimensional grid.
  12. * Can also be used for two dimensions but has a bit overhead.
  13. */
  14. class Grid
  15. {
  16. private:
  17. /**
  18. * The number of values on the x axis
  19. */
  20. const int width_count_;
  21. /**
  22. * The number of values on the y axis
  23. */
  24. const int height_count_;
  25. /**
  26. * The number of values on the z axis
  27. */
  28. const int depth_count_;
  29. /**
  30. * The size of the whole grid on the x axis
  31. */
  32. const double width_;
  33. /**
  34. * The size of the whole grid on the y axis
  35. */
  36. const double height_;
  37. /**
  38. * The size of the whole grid on the z axis
  39. */
  40. const double depth_;
  41. /**
  42. * The size of one grid cell on the x axis
  43. */
  44. const double cell_width_;
  45. /**
  46. * The size of one grid cell on the y axis
  47. */
  48. const double cell_height_;
  49. /**
  50. * The size of one grid cell on the z axis
  51. */
  52. const double cell_depth_;
  53. /**
  54. * The values stored in the grid cells
  55. */
  56. std::vector<std::vector<std::vector<core::ObjectDataPtr>>> values_;
  57. public:
  58. /**
  59. * Creates a new two dimensional grid.
  60. * @param width_count The number of elements on the x axis
  61. * @param height_count The number of elements on the y axis
  62. * @param width The size of the whole grid on the x axis
  63. * @param height The size of the whole grid on the y axis
  64. */
  65. Grid(int width_count, int height_count, double width, double height);
  66. /**
  67. * Creates a new three dimensional grid.
  68. * @param width_count The number of elements on the x axis
  69. * @param height_count The number of elements on the y axis
  70. * @param depth_count The number of elements on the z axis
  71. * @param width The size of the whole grid on the x axis
  72. * @param height The size of the whole grid on the y axis
  73. * @param depth The size of the whole grid on the z axis
  74. */
  75. Grid(int width_count, int height_count, int depth_count,
  76. double width, double height, double depth);
  77. /**
  78. * Sets a value in the grid cell with the given index.
  79. * @param value The value to set
  80. * @param x The x axis index
  81. * @param y The y axis index
  82. * @param z The z axis index
  83. */
  84. void SetValue(core::ObjectDataPtr value, int x, int y, int z = 0);
  85. /**
  86. * Sets a value in the grid cell at the given position.
  87. * @param value The value to set
  88. * @param x The x axis value
  89. * @param y The y axis value
  90. * @param z The z axis value
  91. */
  92. void SetValue(core::ObjectDataPtr value,
  93. 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,
  150. int& xi, int& yi, int& zi) const;
  151. //TODO comment
  152. void Convolve2D(int vicinity, double* mask, double multiplier);
  153. void Convolve3D(int vicinity, double* mask, double multiplier);
  154. };
  155. }
  156. #endif //GBMOT_GRID_H