You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

243 lines
5.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __SHADOW_MASKS_HEADER__
  2. #define __SHADOW_MASKS_HEADER__
  3. #include "../../components/base/basicLogCollection.h"
  4. #include "../../components/base/basicTypes.h"
  5. #include "../../hardware/soc/general/3DLRF.h"
  6. #if (defined(__linux__) && ! defined(__GUI__)) || defined(_MEKOROT_)
  7. typedef struct
  8. {
  9. private:
  10. int16_t m_x;
  11. int16_t m_y;
  12. public:
  13. void setX(int a)
  14. {
  15. m_x = a;
  16. }
  17. void setY(int a)
  18. {
  19. m_y = a;
  20. }
  21. int16_t x(void)
  22. {
  23. return m_x;
  24. }
  25. int16_t y(void)
  26. {
  27. return m_y;
  28. }
  29. } simplePoint;
  30. typedef struct
  31. {
  32. uint8_t color[3];
  33. simplePoint * points;
  34. uint8_t count;
  35. } simplePolygone;
  36. typedef std::vector<simplePolygone *> vectorMasking;
  37. typedef std::vector<simplePolygone *> vectorQPoly;
  38. #else
  39. #include "../../gui/gui.h"
  40. typedef QPoint simplePoint;
  41. // typedef QPolygon simplePolygone;
  42. typedef struct
  43. {
  44. uint8_t color[3];
  45. QPoint * points;
  46. uint8_t count;
  47. } simplePolygone;
  48. typedef std::vector<simplePolygone *> vectorMasking;
  49. typedef std::vector<QPolygon *> vectorQPoly;
  50. #endif
  51. typedef struct
  52. {
  53. uint16_t start;
  54. uint16_t stop;
  55. } raySegment;
  56. typedef struct
  57. {
  58. uint16_t column;
  59. uint16_t count;
  60. raySegment * zones;
  61. } rawRay;
  62. typedef std::vector<rawRay *> vectorZoneMask;
  63. /*
  64. // Given three collinear points p, q, r, the function checks if
  65. // point q lies on line segment 'pr'
  66. inline bool onSegment( simplePoint p, simplePoint q, simplePoint r ){
  67. if (q.x() <= max(p.x(), r.x()) && q.x() >= min(p.x(), r.x()) &&
  68. q.y() <= max(p.y(), r.y()) && q.y() >= min(p.y(), r.y()))
  69. return true;
  70. return false;
  71. };
  72. // To find orientation of ordered triplet (p, q, r).
  73. // The function returns following values
  74. // 0 --> p, q and r are collinear
  75. // 1 --> Clockwise
  76. // 2 --> Counterclockwise
  77. inline int orientation( simplePoint p, simplePoint q, simplePoint r ){
  78. int val = (q.y() - p.y()) * (r.x() - q.x()) -
  79. (q.x() - p.x()) * (r.y() - q.y());
  80. if (val == 0) return 0; // collinear
  81. return (val > 0)? 1: 2; // clock or counterclock wise
  82. };
  83. // The function that returns true if line segment 'p1q1'
  84. // and 'p2q2' intersect.
  85. inline bool doIntersect(simplePoint p1, simplePoint q1, simplePoint p2, simplePoint q2){
  86. // Find the four orientations needed for general and
  87. // special cases
  88. int o1 = orientation(p1, q1, p2);
  89. int o2 = orientation(p1, q1, q2);
  90. int o3 = orientation(p2, q2, p1);
  91. int o4 = orientation(p2, q2, q1);
  92. // General case
  93. if (o1 != o2 && o3 != o4)
  94. return true;
  95. // Special Cases
  96. // p1, q1 and p2 are collinear and p2 lies on segment p1q1
  97. if (o1 == 0 && onSegment(p1, p2, q1)) return true;
  98. // p1, q1 and p2 are collinear and q2 lies on segment p1q1
  99. if (o2 == 0 && onSegment(p1, q2, q1)) return true;
  100. // p2, q2 and p1 are collinear and p1 lies on segment p2q2
  101. if (o3 == 0 && onSegment(p2, p1, q2)) return true;
  102. // p2, q2 and q1 are collinear and q1 lies on segment p2q2
  103. if (o4 == 0 && onSegment(p2, q1, q2)) return true;
  104. return false; // Doesn't fall in any of the above cases
  105. }
  106. // Returns true if the point p lies inside the polygon[] with n vertices
  107. inline bool isInside( simplePoint polygon[], int n, simplePoint p ){
  108. // There must be at least 3 vertices in polygon[]
  109. if( n < 3 ) return false;
  110. // Create a point for line segment from p to infinite
  111. simplePoint extreme;
  112. extreme.setX(10000);
  113. extreme.setY(p.y());
  114. // Count intersections of the above line with sides of polygon
  115. int count = 0, i = 0;
  116. do
  117. {
  118. int next = (i+1)%n;
  119. // Check if the line segment from 'p' to 'extreme' intersects
  120. // with the line segment from 'polygon[i]' to 'polygon[next]'
  121. if (doIntersect(polygon[i], polygon[next], p, extreme))
  122. {
  123. // If the point 'p' is collinear with line segment 'i-next',
  124. // then check if it lies on segment. If it lies, return true,
  125. // otherwise false
  126. if (orientation(polygon[i], p, polygon[next]) == 0)
  127. return onSegment(polygon[i], p, polygon[next]);
  128. count++;
  129. }
  130. i = next;
  131. } while (i != 0);
  132. // Return true if count is odd, false otherwise
  133. return count&1; // Same as (count%2 == 1)
  134. }
  135. */
  136. class ShadowMask
  137. {
  138. private:
  139. basicLogCollection * m_pLog;
  140. vectorZoneMask m_vZoneMask;
  141. bool m_bActive;
  142. bool m_bAutoSave;
  143. vectorMasking m_vVectorMask;
  144. bool m_bRasterized;
  145. #if defined(__linux__) && ! defined(__GUI__)
  146. CSTR m_pRasterFileName;
  147. CSTR m_pVertexFileName;
  148. bool onSegment(simplePoint p, simplePoint q, simplePoint r);
  149. int orientation(simplePoint p, simplePoint q, simplePoint r);
  150. bool doIntersect(simplePoint p1, simplePoint q1, simplePoint p2, simplePoint q2);
  151. bool isInside(simplePolygone * polygon, simplePoint p);
  152. #endif
  153. public:
  154. ShadowMask();
  155. ~ShadowMask();
  156. #if defined(__linux__) && ! defined(__GUI__)
  157. bool loadRastered(CSTR fName = NULL);
  158. bool saveRastered(CSTR fName = NULL);
  159. bool saveVertexes(CSTR fName = NULL);
  160. bool loadVertexes(CSTR fName = NULL);
  161. #endif
  162. bool getMPoly(vectorMasking & VM);
  163. bool getZoneMask(vectorZoneMask & ZM);
  164. simplePolygone * getPoly(int id);
  165. bool addPoly(simplePolygone * SP);
  166. bool clear(void);
  167. bool deletePoly(int ID);
  168. uint8_t getPolyCount(void)
  169. {
  170. return (m_vVectorMask.size() & 0xFF);
  171. }
  172. uint16_t getRayCount(void)
  173. {
  174. return (m_vZoneMask.size() & 0xFFFF);
  175. }
  176. bool rasterizeVertexes(void);
  177. #if defined(WIN32) || defined(__GUI__)
  178. bool getQPoly(vectorQPoly & VM);
  179. bool addVertex(uint16_t polyID, simplePoint SP);
  180. bool addVertex(uint16_t polyID, uint32_t SP); // Binary Data to Vertex
  181. #endif
  182. bool isOutside(uint16_t x, uint16_t y);
  183. bool isOutside(simplePoint);
  184. bool isActive(void)
  185. {
  186. return m_bActive;
  187. }
  188. void setActive(bool tVal);
  189. bool addRay(uint16_t column, raySegment RS);
  190. bool addRay(uint16_t column, uint32_t RS); // Binary Data to RaySegment
  191. void disableAutoSave(void)
  192. {
  193. m_bAutoSave = false;
  194. }
  195. void enableAutoSave(void)
  196. {
  197. m_bAutoSave = false;
  198. }
  199. };
  200. #endif