diff --git a/src/rtimvBase.cpp b/src/rtimvBase.cpp index 643d645..ecd58cf 100644 --- a/src/rtimvBase.cpp +++ b/src/rtimvBase.cpp @@ -70,11 +70,15 @@ void rtimvBase::startup(const std::vector &shkeys) mzmqImage *mi = new mzmqImage(&m_rawMutex); // change defaults - std::cerr << m_mzmqServer << "\n"; if(m_mzmqServer != "") + { mi->imageServer(m_mzmqServer); + } + if(m_mzmqPort != 0) + { mi->imagePort(m_mzmqPort); + } m_images[i] = (rtimvImage *)mi; } @@ -208,6 +212,7 @@ void rtimvBase::updateImages() } } + ///\todo onConnect should maybe only be called upon connection to main image, and may need to wait a sec to let things settle. if(doupdate >= RTIMVIMAGE_IMUPDATE || supportUpdate >= RTIMVIMAGE_IMUPDATE) { changeImdata(true); diff --git a/src/rtimvBase.hpp b/src/rtimvBase.hpp index c468f87..4dc5b83 100644 --- a/src/rtimvBase.hpp +++ b/src/rtimvBase.hpp @@ -59,44 +59,76 @@ class rtimvBase : public QWidget protected: + /** @name Connection - Data + * + * @{ + */ + + /// The images to be displayed + /** By index: + * - 0 is the main image. + * - 1 is the dark image which is (optionally) subtracted from the main image. + * - 2 is the mask image which is (optionally) multiplied by the dark-subtracted image. Normally a 1/0 image. + * - 3 is the saturation mask which (optionally) denotes which pixels to turn the saturation color. + */ + std::vector m_images; + + /// Flag to indicate that the milkzmq protocol should be used for all ImageStremIO images bool m_mzmqAlways {false}; + + /// Default milkzmq server to use, if set this overrides default "localhost" in \ref mzmqImage std::string m_mzmqServer; + + /// Default milkzmq server to use, if set this overrides default "5556" in \ref mzmqImage int m_mzmqPort {0}; - + + ///@} + public: - - /** @name The Images - Data + /** @name Connection + * + * @{ + */ + + /// Configure the image sources and start checking for updates. + /** + */ + void startup( const std::vector & shkeys /**< [in] The keys used to access the images (see \ref m_images)*/); + + /// Function called on connection + virtual void onConnect() {} + + /// Check if an image is currently valid. + /** An image is valid if it was supplied on command line, and if the image itself returns true from valid(). + * + * \returns true if valid + * \returns false otherwise + */ + bool imageValid( size_t n /**< [in] the image number */); + + ///@} + + + /** @name Image Size - Data * * @{ */ protected: uint32_t m_nx {0}; ///< The number of pixels in the x (horizontal) direction + uint32_t m_ny {0}; ///< The number of pixels in the y (vertical) direction - std::vector m_images; - ///@} public: - /** @name The Images + /** @name Image Size * * @{ */ - /// Configure the image sources and start checking for updates. - /** - */ - void startup( const std::vector & shkeys /**< [in] The shmim keys used ot access the images.*/); - - /// Check if an image is currently valid. - /** \returns true if valid - * \returns false otherwise - */ - bool imageValid( size_t n /**< [in] the image number */); - /// Changes the image size, but only if necessary. /** The reallocates m_calData and m_qim * @@ -122,11 +154,8 @@ class rtimvBase : public QWidget /// @} -protected: - - virtual void onConnect() {} - /** @name Image Update Data + /** @name Image Update - Data * * @{ */ @@ -139,7 +168,7 @@ class rtimvBase : public QWidget ///@} - /** @name Image Update Slots + /** @name Image Update - Slots * * @{ */ @@ -189,7 +218,7 @@ protected slots: bool m_applyMask {false}; /// Whether or not the saturation mask is applied, default is false. - /** Note this only controls whether the pixles are colored m_satColor. It does + /** Note this only controls whether the pixels are colored m_satColor. It does * not change the values returned by rawPixel(). */ bool m_applySatMask {false}; @@ -275,12 +304,13 @@ protected slots: ///@} - /** @name Colorbar Selection - * - * @{ - */ + /** @name Colorbar Selection + * + * @{ + */ + public: - typedef int (*pixelIndexF)(float); + typedef int (*pixelIndexF)(float); enum en_cbStretches{ stretchLinear, ///< The pixel values are scaled linearly to between m_mindat and m_maxdat stretchLog, ///< The pixel values are scaled logarithmically between m_mindat and m_maxdat diff --git a/src/rtimvMainWindow.cpp b/src/rtimvMainWindow.cpp index f5db4b1..e0bfa76 100644 --- a/src/rtimvMainWindow.cpp +++ b/src/rtimvMainWindow.cpp @@ -703,7 +703,7 @@ void rtimvMainWindow::updateMouseCoords() if(m_userItemSelected) { nullMouseCoords(); - userItemMouseCoords(m_userItemMouseViewX, m_userItemMouseViewY); + userItemMouseCoords( m_userItemMouseViewX, m_userItemMouseViewY, m_userItemXCen, m_userItemYCen); } if(!m_nullMouseCoords) @@ -949,7 +949,10 @@ void rtimvMainWindow::userCircleItemSize(StretchCircle * sc) QFontMetrics fm(ui.graphicsView->m_userItemSize->currentFont()); QSize textSize = fm.size(0, tmp); - ui.graphicsView->m_userItemSize->setGeometry(sc->rect().x() + sc->pos().x() + sc->rect().width()*0.5 - sc->radius()*0.707, sc->rect().y() + sc->pos().y()+ sc->rect().height()*0.5 - sc->radius()*0.707, textSize.width()+5,textSize.height()+5); + float posx = sc->rect().x() + sc->pos().x() + sc->rect().width()*0.5 - sc->radius()*0.707; + float posy = sc->rect().y() + sc->pos().y()+ sc->rect().height()*0.5 - sc->radius()*0.707; + + ui.graphicsView->m_userItemSize->setGeometry( posx, posy, textSize.width()+5,textSize.height()+5); //Take scene coordinates to viewport coordinates. QRectF sbr = sc->sceneBoundingRect(); @@ -977,7 +980,9 @@ void rtimvMainWindow::userCircleItemCoords(StretchCircle * sc) } void rtimvMainWindow::userItemMouseCoords( float mx, - float my + float my, + float dx, + float dy ) { if(m_qpmi == nullptr) return; @@ -1021,8 +1026,25 @@ void rtimvMainWindow::userItemMouseCoords( float mx, QFontMetrics fm(ui.graphicsView->m_userItemMouseCoords->currentFont()); QSize textSize = fm.size(0, str.c_str()); - ui.graphicsView->m_userItemMouseCoords->setGeometry(mx, my, textSize.width()+5,textSize.height()+5); + + float offsetx = 0; + float offsety = 0; + if(m_offsetItemMouseCoordsX) + { + offsetx = textSize.width()+5; + } + + if(m_offsetItemMouseCoordsY) + { + offsety = textSize.height()+5; + } + + //Take scene coordinates to viewport coordinates. + QPoint qr = ui.graphicsView->mapFromScene(QPointF(dx, dy)); + ui.graphicsView->m_userItemMouseCoords->resize(textSize.width()+5,textSize.height()+5); + ui.graphicsView->m_userItemMouseCoords->move(qr.x() - offsetx, qr.y() - offsety); + fontLuminance(ui.graphicsView->m_userItemMouseCoords); } @@ -1034,17 +1056,22 @@ void rtimvMainWindow::userBoxItemMouseCoords(StretchBox * sb) m_userItemMouseViewX = qr.x(); m_userItemMouseViewY = qr.y(); - userItemMouseCoords(qr.x(), qr.y()); + + m_userItemXCen = sb->rect().x() + sb->pos().x() + sb->rect().width()*0.5; + m_userItemYCen = sb->rect().y() + sb->pos().y() + sb->rect().height()*0.5; + + userItemMouseCoords( m_userItemMouseViewX, m_userItemMouseViewY, m_userItemXCen, m_userItemYCen); } void rtimvMainWindow::userCircleItemMouseCoords(StretchCircle * sc) { QRectF sbr = sc->sceneBoundingRect(); - QPointF qr = QPointF(sbr.x()+0.5*sbr.width(),sbr.y()+0.5*sbr.height()); + QPointF qr = QPointF(sbr.x()+0.5*sbr.width(), sbr.y()+0.5*sbr.height()); m_userItemMouseViewX = qr.x(); m_userItemMouseViewY = qr.y(); - userItemMouseCoords(qr.x(), qr.y()); + + userItemMouseCoords( m_userItemMouseViewX, m_userItemMouseViewY, m_userItemXCen, m_userItemYCen); } void rtimvMainWindow::addUserBox() @@ -1463,15 +1490,15 @@ void rtimvMainWindow::userBoxDeSelected(StretchBox * sb) void rtimvMainWindow::userCircleResized(StretchCircle * sc) { userCircleItemSize(sc); - userCircleItemMouseCoords(sc); userCircleItemCoords(sc); + userCircleItemMouseCoords(sc); } void rtimvMainWindow::userCircleMoved(StretchCircle * sc) { userCircleItemSize(sc); - userCircleItemMouseCoords(sc); userCircleItemCoords(sc); + userCircleItemMouseCoords(sc); } void rtimvMainWindow::userCircleMouseIn(StretchCircle * sc) @@ -1545,52 +1572,88 @@ void rtimvMainWindow::userCircleDeSelected(StretchCircle * sb) void rtimvMainWindow::userLineResized(StretchLine * sl) { - userLineMoved(sl); //Move the text along with us. - - float ang = fmod(sl->angle() -90 + northAngle(), 360.0); - - if(ang < 0) ang += 360.0; - - char tmp[256]; - snprintf(tmp, 256, "%0.1f @ %0.1f", sl->length(), ang); - - ui.graphicsView->m_userItemSize->setText(tmp); - - m_userItemXCen = sl->line().x1(); - m_userItemYCen = sl->line().y1(); - - QPointF qr = QPointF(sl->line().x1(), sl->line().y1()); - - m_userItemMouseViewX = qr.x(); - m_userItemMouseViewY = qr.y(); - userItemMouseCoords(qr.x(), qr.y()); + userLineMoved(sl); //Move the text along with us. + + float ang = fmod(sl->angle() -90 + northAngle(), 360.0); + + if(ang < 0) ang += 360.0; + + char tmp[256]; + snprintf(tmp, 256, "%0.1f @ %0.1f", sl->length(), ang); + + ui.graphicsView->m_userItemSize->setText(tmp); + + m_userItemXCen = sl->line().x1(); + m_userItemYCen = sl->line().y1(); + + if(sl->angle() > 270) + { + m_offsetItemMouseCoordsX = true; + m_offsetItemMouseCoordsY = true; + } + else + { + m_offsetItemMouseCoordsX = false; + m_offsetItemMouseCoordsY = false; + } + + QPointF qr = QPointF(sl->line().x1(), sl->line().y1()); + + m_userItemMouseViewX = qr.x(); + m_userItemMouseViewY = qr.y(); + + userItemMouseCoords( m_userItemMouseViewX, m_userItemMouseViewY, m_userItemXCen, m_userItemYCen); } void rtimvMainWindow::userLineMoved(StretchLine * sl) { - if(!m_qpmi) return; - - QPointF np = m_qpmi->mapFromItem(sl, sl->line().p2()); - - float x = np.x(); - float y = np.y(); - - ui.graphicsView->m_userItemSize->setGeometry(x*m_screenZoom, y*m_screenZoom-20., 200,40); + if(!m_qpmi) return; - m_userItemXCen = sl->line().x1(); - m_userItemYCen = sl->line().y1(); + QPointF np = m_qpmi->mapFromItem(sl, sl->line().p2()); + + float x = np.x(); + float y = np.y(); + + float offsetX = 0; + float offsetY = 10; - QPointF qr = QPointF(sl->line().x1(), sl->line().y1()); + if(sl->angle() > 90 && sl->angle() < 270) + { + QFontMetrics fm(ui.graphicsView->m_userItemSize->currentFont()); + QSize fntsz = fm.size(0, ui.graphicsView->m_userItemSize->toPlainText()); - m_userItemMouseViewX = qr.x(); - m_userItemMouseViewY = qr.y(); - userItemMouseCoords(qr.x(), qr.y()); + offsetX = fntsz.width() + 20; + offsetY = 0; + } - float w = sl->penWidth(); - if(w < 1) w = 1; - float lhx = sl->line().x1() - w*1.5; - float lhy = sl->line().y1() - w*1.5; - m_lineHead->setRect(lhx, lhy, 3*w, 3*w); + ui.graphicsView->m_userItemSize->setGeometry(x*m_screenZoom - offsetX, y*m_screenZoom - offsetY, 200,40); + + m_userItemXCen = sl->line().x1(); + m_userItemYCen = sl->line().y1(); + + QPointF qr = QPointF(sl->line().x1(), sl->line().y1()); + + m_userItemMouseViewX = qr.x(); + m_userItemMouseViewY = qr.y(); + + if(sl->angle() > 270) + { + m_offsetItemMouseCoordsX = true; + m_offsetItemMouseCoordsY = true; + } + else + { + m_offsetItemMouseCoordsX = false; + m_offsetItemMouseCoordsY = false; + } + + userItemMouseCoords( m_userItemMouseViewX, m_userItemMouseViewY, m_userItemXCen, m_userItemYCen); + + float w = sl->penWidth(); + if(w < 1) w = 1; + float lhx = sl->line().x1() - w*1.5; + float lhy = sl->line().y1() - w*1.5; + m_lineHead->setRect(lhx, lhy, 3*w, 3*w); } void rtimvMainWindow::userLineMouseIn(StretchLine * sl) @@ -1608,7 +1671,6 @@ void rtimvMainWindow::userLineMouseIn(StretchLine * sl) m_lineHead->setRect(lhx, lhy, 3*w, 3*w); userLineResized(sl); - userLineMoved(sl); } void rtimvMainWindow::userLineMouseOut(StretchLine * sl) diff --git a/src/rtimvMainWindow.hpp b/src/rtimvMainWindow.hpp index ca693b2..6ae9e1e 100644 --- a/src/rtimvMainWindow.hpp +++ b/src/rtimvMainWindow.hpp @@ -357,8 +357,10 @@ public slots: * @{ */ - void userItemMouseCoords( float mx, - float my + void userItemMouseCoords( float mx, ///< [in] the pixel x-coordinate of the center + float my, ///< [in] the pixel y-coordinate of the center + float dx, ///< [in] the display coordinates of the center + float dy ); void userBoxItemSize(StretchBox *sb); @@ -369,8 +371,12 @@ public slots: float m_userItemXCen{0}; ///< Center of active user item in scene coordinates float m_userItemYCen{0}; ///< Center of active user item in scene coordinates + float m_userItemMouseViewX{0}; ///< Center of active user item in viewport coordinates float m_userItemMouseViewY{0}; ///< Center of active user item in viewport coordinates + + bool m_offsetItemMouseCoordsX {false}; ///< Flag to indicate that the x mouse coordinates should be offset to avoid the item. + bool m_offsetItemMouseCoordsY {false}; ///< Flag to indicate that the y mouse coordinates should be offset to avoid the item. void userBoxItemMouseCoords(StretchBox *sb);