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.

179 lines
4.8 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "CortexLayerWidget.h"
  2. #define LOG( X ) m_pLog->Log( "CortexLayerWidget", this, X )
  3. #define LOG_ERROR( X ) m_pLog->Log( "CortexLayerWidget", this, _LOG_ERROR, X )
  4. CortexLayerWidget::CortexLayerWidget(QWidget* parent) : QWidget(parent) {
  5. m_pLog = basicLogCollection::getInstance();
  6. m_pLayer = NULL;
  7. m_bDirectDrawing = false;
  8. setMinimumSize(QSize(320, 240));
  9. setSizeIncrement(QSize(20, 20));
  10. //m_backingStore = new QBackingStore( );
  11. //setBackgroundRole(QPalette::Window);
  12. setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
  13. setAutoFillBackground(false);
  14. setAttribute(Qt::WA_OpaquePaintEvent);
  15. setCursor(QCursor(Qt::PointingHandCursor));
  16. m_pPixmap = NULL;
  17. m_pOverlayPixmap = NULL;
  18. m_pGraber = NULL;
  19. m_mFrame = NULL;
  20. m_mOutput = NULL;
  21. m_pTimer = NULL;
  22. m_pPropertiesProtectorMutex = new basicMutex();
  23. m_pWidgetProtectorMutex = new basicMutex();
  24. m_pPropertiesProtectorMutex->lock();
  25. m_pWidgetProtectorMutex->lock();
  26. };
  27. CortexLayerWidget::~CortexLayerWidget() {
  28. };
  29. bool CortexLayerWidget::init(void) {
  30. LOG("init.");
  31. m_pPixmap = new QPixmap(width(), height()); //, QImage::Format_RGB888 );
  32. if (m_pPixmap == NULL) return false;
  33. m_pOverlayPixmap = new QPixmap(":pictures/43a.png", "PNG");
  34. m_pTimer = new QTimer();
  35. if (m_pTimer != NULL) {
  36. QObject::connect(m_pTimer, SIGNAL(timeout()), this, SLOT(update()));
  37. m_pTimer->start(40);
  38. };
  39. m_pPixmap->fill(Qt::black);
  40. m_pPropertiesProtectorMutex->unlock();
  41. m_pWidgetProtectorMutex->unlock();
  42. return true;
  43. };
  44. void CortexLayerWidget::renderNow() {
  45. m_pWidgetProtectorMutex->lock();
  46. try {
  47. QPainter painter(this);
  48. painter.setRenderHint(QPainter::Antialiasing);
  49. render(&painter);
  50. }
  51. catch (std::exception & e) {
  52. LOG_ERROR("RenderNow exception!");
  53. };
  54. m_pWidgetProtectorMutex->unlock();
  55. };
  56. void CortexLayerWidget::render(QPainter* painter) {
  57. if (painter != NULL) {
  58. try {
  59. //char buffer[64];
  60. //sprintf(buffer, "Coords: %dx%d %d %d ? %d %d", pos().x(), pos().y(), width(), height(), m_nMouseX, m_nMouseY);
  61. painter->save();
  62. //painter->fillRect(QRect(0, 0, width(), height()), Qt::green);
  63. QPen BgPen(Qt::SolidPattern, 3);
  64. BgPen.setColor(Qt::black);
  65. //if (m_bErrorMode && m_pOverlayPixmap != NULL) {
  66. painter->drawPixmap(QRect(0, 0, width(), height()), *m_pOverlayPixmap);
  67. //if (m_pErrorMsg != NULL) {
  68. //QPen FgPen(Qt::SolidPattern, 0);
  69. //FgPen.setColor(Qt::yellow);
  70. //painter->setPen(BgPen);
  71. //
  72. //painter->setPen(FgPen);
  73. //painter->drawText(QRect(0, 0, width(), height()), Qt::AlignHCenter | Qt::AlignBaseline, m_pErrorMsg);
  74. //};
  75. //} else {
  76. painter->drawPixmap(QRect(0, 0, width(), height()), *m_pPixmap);
  77. //};
  78. //if (m_bSelected) {
  79. BgPen.setColor(Qt::blue);
  80. painter->setPen(BgPen);
  81. painter->drawRect(QRect(2, 2, width() - 4, height() - 4));
  82. //};
  83. //if (m_bMouseActive){
  84. // if (m_pOverlayPixmap != NULL){
  85. // painter->drawPixmap(QRect(0, 0, width(), height()), *m_pOverlayPixmap);
  86. // };
  87. //};
  88. if (m_pLayer != NULL) {
  89. QPen FgPen(Qt::SolidPattern, 0);
  90. FgPen.setColor(Qt::yellow);
  91. painter->setPen(FgPen);
  92. painter->drawText( QRect(0, 0, width(), height()), Qt::AlignHCenter | Qt::AlignBaseline, m_pLayer->getString() );
  93. switch (m_pLayer->m_eType) {
  94. case CONVOLUTIONAL:
  95. case DECONVOLUTIONAL:
  96. case CONNECTED:
  97. case MAXPOOL:
  98. case SOFTMAX:
  99. case DETECTION:
  100. case DROPOUT:
  101. case CROP:
  102. case ROUTE:
  103. case COST:
  104. case NORMALIZATION:
  105. case AVGPOOL:
  106. case LOCAL:
  107. case SHORTCUT:
  108. case ACTIVE:
  109. case RNN:
  110. case GRU:
  111. case LSTM:
  112. case CRNN:
  113. case BATCHNORM:
  114. case NETWORK:
  115. case XNOR:
  116. case REGION:
  117. case REORG:
  118. case BLANK:
  119. break;
  120. };
  121. };
  122. painter->restore();
  123. } catch (std::exception & e) {
  124. LOG_ERROR("Render exception!");
  125. };
  126. };
  127. };
  128. bool CortexLayerWidget::event(QEvent* event) {
  129. /*
  130. if (event->type() == QEvent::UpdateRequest) {
  131. m_bUpdateIsPending = false;
  132. renderNow();
  133. return true;
  134. }
  135. if (event->type() == QEvent::MouseButtonRelease) {
  136. //m_bSelected = (m_bSelected) ? false : true;
  137. if (((QMouseEvent*)event)->button() == Qt::RightButton) {
  138. ShowContextMenu(QPoint(((QMouseEvent*)event)->x(), ((QMouseEvent*)event)->y()));
  139. };// else selected(m_pSignalParameter);
  140. return true;
  141. }
  142. if (event->type() == QEvent::MouseButtonDblClick) {
  143. m_bEnhanced = (m_bEnhanced) ? false : true;
  144. renderLater();
  145. return true;
  146. }
  147. if (event->type() == QEvent::MouseMove) {
  148. m_nMouseX = ((QMouseEvent*)event)->x();
  149. m_nMouseY = ((QMouseEvent*)event)->y();
  150. m_bMouseActive = true;
  151. m_nMenuActivityCounter = 75;// 3 Sec
  152. };*/
  153. return QWidget::event(event);
  154. };
  155. void CortexLayerWidget::exposeEvent(QExposeEvent*) {
  156. LOG_ERROR("Expose EVT!");
  157. };
  158. void CortexLayerWidget::paintEvent(QPaintEvent* evt) {
  159. renderNow();
  160. };
  161. void CortexLayerWidget::attachCortexLayer(cortexLayer* L) {
  162. m_pLayer = L;
  163. };
  164. #undef LOG
  165. #undef LOG_ERROR