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.

262 lines
8.4 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "RadarMapWidget.h"
  2. #include "../../components/base/basicCameraPTZ.h"
  3. RadarMapWidget::RadarMapWidget(QWidget *parent) : QFrame(parent), targetDisplay(), m_mImageLock(){
  4. m_dScaleFactor = 1.f;
  5. //setStyleSheet(QString::fromUtf8("border: 1px;"));
  6. setContentsMargins(0, 0, 0, 0);
  7. //m_pVerticalLayout = new QVBoxLayout(parent);
  8. //m_pVerticalLayout->setSpacing(0);
  9. //setLayout(m_pVerticalLayout);
  10. //setMinimumSize(400, 325);
  11. //setMaximumSize(2304, 325);
  12. setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  13. setFrameShadow(QFrame::Sunken);
  14. m_bShowMinimums = true;
  15. m_pImageLabel = new QLabel(this);
  16. m_pImageLabel->setText("m_pOpLabel");
  17. m_pImageLabel->setAutoFillBackground(false);
  18. m_pImageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);//setGeometry(QRect(250, 440, 220, 13));
  19. m_nAltStep = 10;
  20. m_pAniTimer = new QTimer(this);
  21. if (m_pAniTimer != NULL){
  22. connect(m_pAniTimer, &QTimer::timeout, this, &RadarMapWidget::handleTimer);
  23. m_pAniTimer->start(300);
  24. };
  25. m_nCursorX = -1;
  26. m_nCursorY = -1;
  27. m_nSelectedAlt = 144;// Q_SCAN_COUNT - ((Q_SCAN_COUNT*Q_SHIFT_DOWN_FOV) / Q_DEGREE_FOV);
  28. //setVisible(false);
  29. //setMouseTracking( true );
  30. //m_pScrollArea->grabMouse();
  31. m_oImage = QImage(640, 640, QImage::Format_RGB888 );
  32. m_oImage.fill( QColor(0,0,0));
  33. m_pRanges = NULL;
  34. m_pDeviceControl = NULL;
  35. m_fMaxRange = 300.f;
  36. m_bCurrentMouseMode = 0; // No Mode;
  37. //loadPolygons("polygons.ply");
  38. //loadFromFile("test.raw");
  39. //https://www.ebay.com/itm/KKMOON-16CH-960H-D1-CCTV-Network-Standalone-H-264-HD-DVR-Security-System-Z5Z4-/161965230971
  40. //https://www.ebay.com/itm/KKmoon-1080P-PTZ-CCTV-Camera-IR-Day-Night-2MP-AHD-2-8-12mm-Auto-Focus-IP66-P1F5/112672024175
  41. //https://www.ebay.com/itm/KKMOON-960P-AHD-CCTV-CAMERA-1-3MP-HD-ANALOG-OUTDOOR-SECURITY-BULLET-METAL-Z9M4/322419271266
  42. m_pPoint = NULL;
  43. updateBackStage();
  44. updateDisplay();
  45. };
  46. RadarMapWidget::~RadarMapWidget(){
  47. };
  48. void RadarMapWidget::savePicture(QString fname){
  49. m_oImage.save(fname);
  50. };
  51. void RadarMapWidget::setMaximums(void){
  52. //m_bShowMinimums = false;
  53. //if( m_nRangesCount > 0 ) updateBackStage();
  54. };
  55. void RadarMapWidget::setMinimums(void){
  56. //m_bShowMinimums = true;
  57. //if( m_nRangesCount > 0 ) updateBackStage();
  58. };
  59. void RadarMapWidget::updateBackStage(void){
  60. m_mImageLock.lock();
  61. try{
  62. QPainter painter;
  63. QPen Pen(Qt::SolidPattern, 1);
  64. Pen.setColor(QColor(0, 40, 0));
  65. QBrush Brush(QColor(0, 40, 0), Qt::SolidPattern);
  66. if (painter.begin(&m_oImage)){
  67. painter.setRenderHint((QPainter::RenderHint)7);// QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing
  68. painter.setPen(Pen);
  69. painter.setBrush(Brush);
  70. painter.fillRect(0, 0, m_oPixmap.width(), m_oPixmap.height(), Qt::black);
  71. painter.drawPie(width() * .1, width() * .1, width() * .8, width() * .8, 0, 6000);
  72. Pen.setColor(QColor(0, 255, 0, 10));
  73. painter.setPen(Pen);
  74. Brush.setColor(QColor(0, 255, 0, 10));
  75. painter.setBrush(Brush);
  76. int cX, cY, mR;
  77. cX = width() / 2;
  78. cY = height() / 2;
  79. mR = width() * .4;
  80. if (m_pRanges != NULL){
  81. float k;
  82. k = 6.283185307179586476925286766559f / TH_LINE_NODES;
  83. QPoint aArray[TH_LINE_NODES * 2];
  84. int nArray = TH_LINE_NODES;
  85. //float z = (mR * m_dScaleFactor) / 4095.f;
  86. for (int layer = 0; layer < 144; layer++){
  87. float z = (mR * m_dScaleFactor * sin(((Q_RADIAN_FOV / Q_SCAN_COUNT) * (Q_SCAN_COUNT - layer)) - Q_RADIAN_SHIFT_DOWN_FOV)) / 4095.f;
  88. uint32_t base = layer * TH_LINE_NODES;
  89. for (int index = 0; index < TH_LINE_NODES; index++){
  90. if (layer == 0){
  91. aArray[index].setX(cX + mR*cos(k*index));
  92. aArray[index].setY(cY + mR*sin(k*index));
  93. };
  94. if (m_pRanges[base + index].values.max < 4090){ // Real Point
  95. int Range = m_pRanges[base + index].values.min * z;
  96. if( Range < mR ){
  97. aArray[nArray].setX(cX + Range * cos(k*index));
  98. aArray[nArray].setY(cY + Range * sin(k*index));
  99. //nArray++;
  100. } else {
  101. aArray[nArray].setX(cX + mR * cos(k*index));
  102. aArray[nArray].setY(cY + mR * sin(k*index));
  103. };
  104. } else {
  105. aArray[nArray].setX(aArray[index].x());
  106. aArray[nArray].setY(aArray[index].y());
  107. };
  108. nArray++;
  109. };
  110. painter.drawPolyline(aArray, nArray);
  111. //painter.drawPolygon(aArray, nArray);
  112. nArray = TH_LINE_NODES;
  113. };
  114. };
  115. painter.end();
  116. };
  117. } catch ( exception e ){};
  118. m_mImageLock.unlock();
  119. };
  120. void RadarMapWidget::updateDisplay( void ){
  121. m_mImageLock.lock();
  122. try{
  123. char tBuf[64];
  124. QPainter painter;
  125. m_oPixmap = QPixmap::fromImage(m_oImage);
  126. QPen BgPen(Qt::SolidPattern,1);
  127. BgPen.setColor(QColor(255, 0, 255, 255));
  128. painter.begin( &m_oPixmap );
  129. painter.setRenderHint((QPainter::RenderHint)7);// QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing
  130. painter.setPen( BgPen );
  131. float k = 3.1415926535897932384626433832795 / 4.f;
  132. int cX, cY, mR;
  133. cX = width() / 2;
  134. cY = height() / 2;
  135. mR = width() * .4;
  136. int pX, pY;
  137. for( int i=0; i<8; i++ ){
  138. pX = cX + mR * cos(k * i);
  139. pY = cY + mR * sin(k * i);
  140. painter.drawLine( cX, cY, pX, pY );
  141. sprintf( tBuf,"%d", 360 - ( i*45 ) );
  142. painter.drawText(QRect(pX + 5, pY + 1, pX + 15, pY + 6 ), Qt::AlignLeft | Qt::AlignBaseline, tBuf);
  143. };
  144. sprintf( tBuf,"%0.2f m.", 300.f / m_dScaleFactor );
  145. painter.drawText( QRect(20, 20, 60, 15 ), Qt::AlignLeft | Qt::AlignBaseline, tBuf);
  146. // Draw Targets
  147. float Range = 0;
  148. k = 6.283185307179586476925286766559f / TH_LINE_NODES;
  149. //float z;
  150. //z = Q_RADIAN_FOV - Q_RADIAN_SHIFT_DOWN_FOV / Q_SCAN_COUNT;
  151. for (uint8_t index = 0; index < MAX_SIMUL_TARGETS; index++){
  152. if(m_aTargets[index].status!= 0){
  153. float z = (mR * m_dScaleFactor * sin(((Q_RADIAN_FOV / Q_SCAN_COUNT) * m_aTargets[index].dY ) - Q_RADIAN_SHIFT_DOWN_FOV)) / 4095.f;
  154. Range = m_aTargets[index].range * z;
  155. if( Range < mR ){
  156. pX = cX + Range * cos(k*m_aTargets[index].dX);
  157. pY = cY + Range * sin(k*m_aTargets[index].dX);
  158. painter.fillRect( pX-1, pY-1, 3, 3, QColor( 255, 0, 0 ) );
  159. };
  160. } else continue;
  161. };
  162. painter.end();
  163. m_pImageLabel->setPixmap(m_oPixmap);
  164. } catch( exception e ){};
  165. m_mImageLock.unlock();
  166. //m_pImageLabel->adjustSize();
  167. //setVisible(true);
  168. //update();
  169. };
  170. //void RangeMapWidget::mouseMoveEvent(QMouseEvent* event) {
  171. // qDebug() << QString::number(event->pos().x());
  172. // qDebug() << QString::number(event->pos().y());
  173. //}
  174. bool RadarMapWidget::eventFilter(QObject* ZZ/*obj*/, QEvent* evt){
  175. if( evt->type() == QEvent::MouseMove ){
  176. evt->ignore();
  177. };
  178. if( evt->type() == QEvent::MouseButtonPress ){
  179. evt->ignore();
  180. };
  181. if( evt->type() == QEvent::MouseButtonRelease ){
  182. evt->ignore();
  183. };
  184. if( evt->type() == QEvent::MouseButtonDblClick ){
  185. evt->ignore();
  186. };
  187. if( evt->type() == QEvent::Wheel ){
  188. // ignore the event (this effectively makes it "skip" one object)
  189. evt->ignore();
  190. };
  191. // return false to continue event propagation
  192. // for all events
  193. return false;
  194. };
  195. void RadarMapWidget::wheelEvent(QWheelEvent* event){
  196. if (event->orientation() == Qt::Horizontal) {
  197. } else {
  198. if (event->delta() > 0){
  199. m_dScaleFactor *= 1.2;
  200. } else {
  201. m_dScaleFactor *= 0.8;
  202. };
  203. };
  204. event->accept();
  205. updateBackStage();
  206. updateDisplay();
  207. };
  208. void RadarMapWidget::attachLGS(objectLGS *ptr){
  209. m_pDeviceControl = ptr;
  210. if( m_pDeviceControl != NULL ){
  211. m_vAllPoly.clear();
  212. if( m_pDeviceControl->areMasksLoadded() ){
  213. if (m_pDeviceControl->getMask()->getMPoly(m_vAllPoly)){
  214. };
  215. };
  216. updateBackStage();
  217. updateDisplay();
  218. };
  219. };
  220. QSize RadarMapWidget::sizeHint() const {
  221. QSize s = size();
  222. //lastHeight = s.height();
  223. s.setWidth(s.height());
  224. s.setHeight(s.height());// QGroupBox::sizeHint().height());
  225. return s;
  226. };
  227. void RadarMapWidget::resizeEvent(QResizeEvent *event){
  228. if ( abs( width() - height() ) > 4 ){
  229. setFixedWidth(height());
  230. };
  231. m_oImage = QImage(width(), width(), QImage::Format_RGB888 );
  232. //m_pPixmap = new QPixmap(width(), height());
  233. updateBackStage();
  234. updateDisplay();
  235. event->accept();
  236. };
  237. void RadarMapWidget::handleTimer(void){
  238. if( m_pRanges != NULL ){
  239. //m_nSelectedAlt+= m_nAltStep;
  240. //if( m_nSelectedAlt > 287 ) m_nSelectedAlt = 0;
  241. //updateBackStage();
  242. updateDisplay();
  243. };
  244. };