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
179 lines
4.8 KiB
#include "CortexLayerWidget.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "CortexLayerWidget", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "CortexLayerWidget", this, _LOG_ERROR, X )
|
|
|
|
CortexLayerWidget::CortexLayerWidget(QWidget* parent) : QWidget(parent) {
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pLayer = NULL;
|
|
m_bDirectDrawing = false;
|
|
setMinimumSize(QSize(320, 240));
|
|
setSizeIncrement(QSize(20, 20));
|
|
//m_backingStore = new QBackingStore( );
|
|
//setBackgroundRole(QPalette::Window);
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
setAutoFillBackground(false);
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
setCursor(QCursor(Qt::PointingHandCursor));
|
|
m_pPixmap = NULL;
|
|
m_pOverlayPixmap = NULL;
|
|
m_pGraber = NULL;
|
|
m_mFrame = NULL;
|
|
m_mOutput = NULL;
|
|
m_pTimer = NULL;
|
|
m_pPropertiesProtectorMutex = new basicMutex();
|
|
m_pWidgetProtectorMutex = new basicMutex();
|
|
m_pPropertiesProtectorMutex->lock();
|
|
m_pWidgetProtectorMutex->lock();
|
|
};
|
|
|
|
CortexLayerWidget::~CortexLayerWidget() {
|
|
|
|
};
|
|
|
|
bool CortexLayerWidget::init(void) {
|
|
LOG("init.");
|
|
m_pPixmap = new QPixmap(width(), height()); //, QImage::Format_RGB888 );
|
|
if (m_pPixmap == NULL) return false;
|
|
m_pOverlayPixmap = new QPixmap(":pictures/43a.png", "PNG");
|
|
m_pTimer = new QTimer();
|
|
if (m_pTimer != NULL) {
|
|
QObject::connect(m_pTimer, SIGNAL(timeout()), this, SLOT(update()));
|
|
m_pTimer->start(40);
|
|
};
|
|
m_pPixmap->fill(Qt::black);
|
|
m_pPropertiesProtectorMutex->unlock();
|
|
m_pWidgetProtectorMutex->unlock();
|
|
return true;
|
|
};
|
|
|
|
void CortexLayerWidget::renderNow() {
|
|
m_pWidgetProtectorMutex->lock();
|
|
try {
|
|
QPainter painter(this);
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
render(&painter);
|
|
}
|
|
catch (std::exception & e) {
|
|
LOG_ERROR("RenderNow exception!");
|
|
};
|
|
m_pWidgetProtectorMutex->unlock();
|
|
};
|
|
|
|
void CortexLayerWidget::render(QPainter* painter) {
|
|
if (painter != NULL) {
|
|
try {
|
|
//char buffer[64];
|
|
//sprintf(buffer, "Coords: %dx%d %d %d ? %d %d", pos().x(), pos().y(), width(), height(), m_nMouseX, m_nMouseY);
|
|
painter->save();
|
|
//painter->fillRect(QRect(0, 0, width(), height()), Qt::green);
|
|
QPen BgPen(Qt::SolidPattern, 3);
|
|
BgPen.setColor(Qt::black);
|
|
//if (m_bErrorMode && m_pOverlayPixmap != NULL) {
|
|
painter->drawPixmap(QRect(0, 0, width(), height()), *m_pOverlayPixmap);
|
|
//if (m_pErrorMsg != NULL) {
|
|
//QPen FgPen(Qt::SolidPattern, 0);
|
|
//FgPen.setColor(Qt::yellow);
|
|
//painter->setPen(BgPen);
|
|
//
|
|
//painter->setPen(FgPen);
|
|
//painter->drawText(QRect(0, 0, width(), height()), Qt::AlignHCenter | Qt::AlignBaseline, m_pErrorMsg);
|
|
//};
|
|
//} else {
|
|
painter->drawPixmap(QRect(0, 0, width(), height()), *m_pPixmap);
|
|
//};
|
|
//if (m_bSelected) {
|
|
BgPen.setColor(Qt::blue);
|
|
painter->setPen(BgPen);
|
|
painter->drawRect(QRect(2, 2, width() - 4, height() - 4));
|
|
//};
|
|
//if (m_bMouseActive){
|
|
// if (m_pOverlayPixmap != NULL){
|
|
// painter->drawPixmap(QRect(0, 0, width(), height()), *m_pOverlayPixmap);
|
|
// };
|
|
//};
|
|
|
|
if (m_pLayer != NULL) {
|
|
QPen FgPen(Qt::SolidPattern, 0);
|
|
FgPen.setColor(Qt::yellow);
|
|
painter->setPen(FgPen);
|
|
painter->drawText( QRect(0, 0, width(), height()), Qt::AlignHCenter | Qt::AlignBaseline, m_pLayer->getString() );
|
|
switch (m_pLayer->m_eType) {
|
|
case CONVOLUTIONAL:
|
|
case DECONVOLUTIONAL:
|
|
case CONNECTED:
|
|
case MAXPOOL:
|
|
case SOFTMAX:
|
|
case DETECTION:
|
|
case DROPOUT:
|
|
case CROP:
|
|
case ROUTE:
|
|
case COST:
|
|
case NORMALIZATION:
|
|
case AVGPOOL:
|
|
case LOCAL:
|
|
case SHORTCUT:
|
|
case ACTIVE:
|
|
case RNN:
|
|
case GRU:
|
|
case LSTM:
|
|
case CRNN:
|
|
case BATCHNORM:
|
|
case NETWORK:
|
|
case XNOR:
|
|
case REGION:
|
|
case REORG:
|
|
case BLANK:
|
|
break;
|
|
};
|
|
};
|
|
painter->restore();
|
|
} catch (std::exception & e) {
|
|
LOG_ERROR("Render exception!");
|
|
};
|
|
};
|
|
};
|
|
|
|
bool CortexLayerWidget::event(QEvent* event) {
|
|
/*
|
|
if (event->type() == QEvent::UpdateRequest) {
|
|
m_bUpdateIsPending = false;
|
|
renderNow();
|
|
return true;
|
|
}
|
|
if (event->type() == QEvent::MouseButtonRelease) {
|
|
//m_bSelected = (m_bSelected) ? false : true;
|
|
if (((QMouseEvent*)event)->button() == Qt::RightButton) {
|
|
ShowContextMenu(QPoint(((QMouseEvent*)event)->x(), ((QMouseEvent*)event)->y()));
|
|
};// else selected(m_pSignalParameter);
|
|
return true;
|
|
}
|
|
if (event->type() == QEvent::MouseButtonDblClick) {
|
|
m_bEnhanced = (m_bEnhanced) ? false : true;
|
|
renderLater();
|
|
return true;
|
|
}
|
|
if (event->type() == QEvent::MouseMove) {
|
|
m_nMouseX = ((QMouseEvent*)event)->x();
|
|
m_nMouseY = ((QMouseEvent*)event)->y();
|
|
m_bMouseActive = true;
|
|
m_nMenuActivityCounter = 75;// 3 Sec
|
|
};*/
|
|
return QWidget::event(event);
|
|
};
|
|
|
|
void CortexLayerWidget::exposeEvent(QExposeEvent*) {
|
|
LOG_ERROR("Expose EVT!");
|
|
};
|
|
|
|
void CortexLayerWidget::paintEvent(QPaintEvent* evt) {
|
|
renderNow();
|
|
};
|
|
|
|
void CortexLayerWidget::attachCortexLayer(cortexLayer* L) {
|
|
m_pLayer = L;
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|