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.
 
 
 
 
 
 

263 lines
8.4 KiB

#include "MastBaumWidget.h"
#include "../../components/base/basicCameraPTZ.h"
MastbaumWidget::MastbaumWidget(QWidget *parent) : QFrame(parent), targetDisplay(), m_mImageLock(){
m_dScaleFactor = 1.f;
//setStyleSheet(QString::fromUtf8("border: 1px;"));
setContentsMargins(0, 0, 0, 0);
//m_pVerticalLayout = new QVBoxLayout(parent);
//m_pVerticalLayout->setSpacing(0);
//setLayout(m_pVerticalLayout);
//setMinimumSize(400, 325);
//setMaximumSize(2304, 325);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setFrameShadow(QFrame::Sunken);
m_bShowMinimums = true;
m_pImageLabel = new QLabel(this);
m_pImageLabel->setText("m_pOpLabel");
m_pImageLabel->setAutoFillBackground(false);
m_pImageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);//setGeometry(QRect(250, 440, 220, 13));
m_nAltStep = 10;
m_pAniTimer = new QTimer(this);
if (m_pAniTimer != NULL){
connect(m_pAniTimer, &QTimer::timeout, this, &MastbaumWidget::handleTimer);
m_pAniTimer->start(300);
};
m_nCursorX = -1;
m_nCursorY = -1;
m_nSelectedAlt = 144;// Q_SCAN_COUNT - ((Q_SCAN_COUNT*Q_SHIFT_DOWN_FOV) / Q_DEGREE_FOV);
//setVisible(false);
//setMouseTracking( true );
//m_pScrollArea->grabMouse();
m_oImage = QImage(640, 640, QImage::Format_RGB888 );
m_oImage.fill( QColor(0,0,0));
m_pRanges = NULL;
m_pDeviceControl = NULL;
m_fMaxRange = 300.f;
m_bCurrentMouseMode = 0; // No Mode;
//loadPolygons("polygons.ply");
//loadFromFile("test.raw");
//https://www.ebay.com/itm/KKMOON-16CH-960H-D1-CCTV-Network-Standalone-H-264-HD-DVR-Security-System-Z5Z4-/161965230971
//https://www.ebay.com/itm/KKmoon-1080P-PTZ-CCTV-Camera-IR-Day-Night-2MP-AHD-2-8-12mm-Auto-Focus-IP66-P1F5/112672024175
//https://www.ebay.com/itm/KKMOON-960P-AHD-CCTV-CAMERA-1-3MP-HD-ANALOG-OUTDOOR-SECURITY-BULLET-METAL-Z9M4/322419271266
m_pPoint = NULL;
updateBackStage();
updateDisplay();
};
MastbaumWidget::~MastbaumWidget(){
};
void MastbaumWidget::savePicture(QString fname){
m_oImage.save(fname);
};
void MastbaumWidget::setMaximums(void){
//m_bShowMinimums = false;
//if( m_nRangesCount > 0 ) updateBackStage();
};
void MastbaumWidget::setMinimums(void){
//m_bShowMinimums = true;
//if( m_nRangesCount > 0 ) updateBackStage();
};
void MastbaumWidget::updateBackStage(void){
m_mImageLock.lock();
try{
QPainter painter;
QPen Pen(Qt::SolidPattern, 1);
Pen.setColor(QColor(0, 40, 0));
QBrush Brush(QColor(0, 40, 0), Qt::SolidPattern);
if (painter.begin(&m_oImage)){
painter.setRenderHint((QPainter::RenderHint)7);// QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing
painter.setPen(Pen);
painter.setBrush(Brush);
painter.fillRect(0, 0, m_oPixmap.width(), m_oPixmap.height(), Qt::black);
painter.drawPie(width() * .1, width() * .1, width() * .8, width() * .8, 0, 6000);
Pen.setColor(QColor(0, 255, 0, 10));
painter.setPen(Pen);
Brush.setColor(QColor(0, 255, 0, 10));
painter.setBrush(Brush);
int cX, cY, mR;
cX = width() / 2;
cY = height() / 2;
mR = width() * .4;
if (m_pRanges != NULL){
float k;
k = 6.283185307179586476925286766559f / TH_LINE_NODES;
QPoint aArray[TH_LINE_NODES * 2];
int nArray = TH_LINE_NODES;
//float z = (mR * m_dScaleFactor) / 4095.f;
for (int layer = 0; layer < 144; layer++){
float z = (mR * m_dScaleFactor * sin(((Q_RADIAN_FOV / Q_SCAN_COUNT) * (Q_SCAN_COUNT - layer)) - Q_RADIAN_SHIFT_DOWN_FOV)) / 4095.f;
uint32_t base = layer * TH_LINE_NODES;
for (int index = 0; index < TH_LINE_NODES; index++){
if (layer == 0){
aArray[index].setX(cX + mR*cos(k*index));
aArray[index].setY(cY + mR*sin(k*index));
};
if (m_pRanges[base + index].values.max < 4090){ // Real Point
int Range = m_pRanges[base + index].values.min * z;
if( Range < mR ){
aArray[nArray].setX(cX + Range * cos(k*index));
aArray[nArray].setY(cY + Range * sin(k*index));
//nArray++;
} else {
aArray[nArray].setX(cX + mR * cos(k*index));
aArray[nArray].setY(cY + mR * sin(k*index));
};
} else {
aArray[nArray].setX(aArray[index].x());
aArray[nArray].setY(aArray[index].y());
};
nArray++;
};
painter.drawPolyline(aArray, nArray);
//painter.drawPolygon(aArray, nArray);
nArray = TH_LINE_NODES;
};
};
painter.end();
};
} catch ( exception e ){};
m_mImageLock.unlock();
};
void MastbaumWidget::updateDisplay( void ){
m_mImageLock.lock();
try{
char tBuf[64];
QPainter painter;
m_oPixmap = QPixmap::fromImage(m_oImage);
QPen BgPen(Qt::SolidPattern,1);
BgPen.setColor(QColor(255, 0, 255, 255));
painter.begin( &m_oPixmap );
painter.setRenderHint((QPainter::RenderHint)7);// QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing
painter.setPen( BgPen );
float k = 3.1415926535897932384626433832795 / 4.f;
int cX, cY, mR;
cX = width() / 2;
cY = height() / 2;
mR = width() * .4;
int pX, pY;
for( int i=0; i<8; i++ ){
pX = cX + mR * cos(k * i);
pY = cY + mR * sin(k * i);
painter.drawLine( cX, cY, pX, pY );
sprintf( tBuf,"%d", 360 - ( i*45 ) );
painter.drawText(QRect(pX + 5, pY + 1, pX + 15, pY + 6 ), Qt::AlignLeft | Qt::AlignBaseline, tBuf);
};
sprintf( tBuf,"%0.2f m.", 300.f / m_dScaleFactor );
painter.drawText( QRect(20, 20, 60, 15 ), Qt::AlignLeft | Qt::AlignBaseline, tBuf);
// Draw Targets
float Range = 0;
k = 6.283185307179586476925286766559f / TH_LINE_NODES;
//float z;
//z = Q_RADIAN_FOV - Q_RADIAN_SHIFT_DOWN_FOV / Q_SCAN_COUNT;
for (uint8_t index = 0; index < MAX_SIMUL_TARGETS; index++){
if(m_aTargets[index].status!= 0){
float z = (mR * m_dScaleFactor * sin(((Q_RADIAN_FOV / Q_SCAN_COUNT) * m_aTargets[index].dY ) - Q_RADIAN_SHIFT_DOWN_FOV)) / 4095.f;
Range = m_aTargets[index].range * z;
if( Range < mR ){
pX = cX + Range * cos(k*m_aTargets[index].dX);
pY = cY + Range * sin(k*m_aTargets[index].dX);
painter.fillRect( pX-1, pY-1, 3, 3, QColor( 255, 0, 0 ) );
};
} else continue;
};
painter.end();
m_pImageLabel->setPixmap(m_oPixmap);
} catch( exception e ){};
m_mImageLock.unlock();
//m_pImageLabel->adjustSize();
//setVisible(true);
//update();
};
//void RangeMapWidget::mouseMoveEvent(QMouseEvent* event) {
// qDebug() << QString::number(event->pos().x());
// qDebug() << QString::number(event->pos().y());
//}
bool MastbaumWidget::eventFilter(QObject* ZZ/*obj*/, QEvent* evt){
if( evt->type() == QEvent::MouseMove ){
evt->ignore();
};
if( evt->type() == QEvent::MouseButtonPress ){
evt->ignore();
};
if( evt->type() == QEvent::MouseButtonRelease ){
evt->ignore();
};
if( evt->type() == QEvent::MouseButtonDblClick ){
evt->ignore();
};
if( evt->type() == QEvent::Wheel ){
// ignore the event (this effectively makes it "skip" one object)
evt->ignore();
};
// return false to continue event propagation
// for all events
return false;
};
void MastbaumWidget::wheelEvent(QWheelEvent* event){
if (event->orientation() == Qt::Horizontal) {
} else {
if (event->delta() > 0){
m_dScaleFactor *= 1.2;
} else {
m_dScaleFactor *= 0.8;
};
};
event->accept();
updateBackStage();
updateDisplay();
};
void MastbaumWidget::attachMastBaum(objectLGS *ptr){
m_pDeviceControl = ptr;
if( m_pDeviceControl != NULL ){
m_vAllPoly.clear();
if( m_pDeviceControl->areMasksLoadded() ){
if (m_pDeviceControl->getMask()->getMPoly(m_vAllPoly)){
};
};
updateBackStage();
updateDisplay();
};
};
QSize MastbaumWidget::sizeHint() const {
QSize s = size();
//lastHeight = s.height();
s.setWidth(s.height());
s.setHeight(s.height());// QGroupBox::sizeHint().height());
return s;
};
void MastbaumWidget::resizeEvent(QResizeEvent *event){
if ( abs( width() - height() ) > 4 ){
setFixedWidth(height());
};
m_oImage = QImage(width(), width(), QImage::Format_RGB888 );
//m_pPixmap = new QPixmap(width(), height());
updateBackStage();
updateDisplay();
event->accept();
};
void MastbaumWidget::handleTimer(void){
if( m_pRanges != NULL ){
//m_nSelectedAlt+= m_nAltStep;
//if( m_nSelectedAlt > 287 ) m_nSelectedAlt = 0;
//updateBackStage();
updateDisplay();
};
};