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.

196 lines
6.1 KiB

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