diff --git a/src/StretchBox.hpp b/src/StretchBox.hpp index 4c1931a..010acd1 100644 --- a/src/StretchBox.hpp +++ b/src/StretchBox.hpp @@ -105,6 +105,7 @@ protected slots: ///@} +public: /** \name Signals * The emitXXXX are required by StretchGraphicsItem, and each * emits the associated signal. diff --git a/src/rtimvBase.cpp b/src/rtimvBase.cpp index a89896b..541245f 100644 --- a/src/rtimvBase.cpp +++ b/src/rtimvBase.cpp @@ -1,6 +1,7 @@ - #include "rtimvBase.hpp" +#include + #ifdef RTIMV_MILK #include "images/shmimImage.hpp" #endif @@ -181,15 +182,6 @@ void rtimvBase::mtxL_setImsize( uint32_t x, } } -void rtimvBase::mtxL_postSetImsize(const std::unique_lock & lock) -{ - assert(lock.owns_lock()); - - RTIMV_DEBUG_BREADCRUMB - - return; -} - uint32_t rtimvBase::nx() { return m_nx; @@ -227,7 +219,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); + mtxUL_changeImdata(true); if(!connected) { @@ -539,7 +531,6 @@ void rtimvBase::mtxL_load_colorbar( int cb, if(update) { - //changeImdata(); mtxL_recolor(lock); } } @@ -717,7 +708,7 @@ int calcPixIndex_square(float pixval, float mindat, float maxdat, int mincol, in return pixval * (maxcol - mincol) + 0.5; } -void rtimvBase::changeImdata(bool newdata) +void rtimvBase::mtxUL_changeImdata(bool newdata) { RTIMV_DEBUG_BREADCRUMB @@ -820,27 +811,66 @@ void rtimvBase::changeImdata(bool newdata) RTIMV_DEBUG_BREADCRUMB //At this point the raw data has been copied out to calData. - //But we keep the mutex to make sure a subsequent call from a different thread doesn't delete m_calData. + //We have released the raw data mutex (rawlock). We keep the caldata mutex to make sure a subsequent call + //from a different thread doesn't delete m_calData. //This could be forced by newdata - if(resized || (newdata && m_autoScale)) - { - RTIMV_DEBUG_BREADCRUMB + RTIMV_DEBUG_BREADCRUMB - imdat_min = std::numeric_limits::max(); - imdat_max = -std::numeric_limits::max(); + imdat_min = std::numeric_limits::max(); + imdat_max = -std::numeric_limits::max(); - if(colorBoxActive) + float imval; + + for(uint32_t j = 0; j < m_ny; ++j) + { + for(uint32_t i = 0; i < m_nx; ++i) { - colorBox_min = std::numeric_limits::max(); - colorBox_max = -std::numeric_limits::max(); + imval = calPixel(i,j); + + if(!std::isfinite(imval)) + { + continue; + } + + if(imval > imdat_max) + { + imdat_max = imval; + } + + if(imval < imdat_min) + { + imdat_min = imval; + } } + } + + RTIMV_DEBUG_BREADCRUMB + + if(!std::isfinite(imdat_max) || !std::isfinite(imdat_min)) + { + // It should be impossible for them to be infinite by themselves unless it's all NaNs. + imdat_max = 0; + imdat_min = 0; + } + if( (resized || (newdata && m_autoScale)) && !colorBoxActive) + { + mindat(imdat_min); + maxdat(imdat_max); + } + else if(colorBoxActive) + { + normalizeColorBox(); + + m_colorBox_min = std::numeric_limits::max(); + m_colorBox_max = -std::numeric_limits::max(); + float imval; - for(uint32_t j = 0; j < m_ny; ++j) + for(uint32_t j = m_colorBox_j0; j <= m_colorBox_j1; ++j) { - for(uint32_t i = 0; i < m_nx; ++i) + for(uint32_t i = m_colorBox_i0; i <= m_colorBox_i1; ++i) { imval = calPixel(i,j); @@ -848,62 +878,35 @@ void rtimvBase::changeImdata(bool newdata) { continue; } - - if(imval > imdat_max) + + if(imval < m_colorBox_min) { - imdat_max = imval; + m_colorBox_min = imval; } - - if(imval < imdat_min) + if(imval > m_colorBox_max) { - imdat_min = imval; - } - - if(colorBoxActive) - { - if(i >= colorBox_i0 && i < colorBox_i1 && j >= colorBox_j0 && j < colorBox_j1) - { - if(imval < colorBox_min) - { - colorBox_min = imval; - } - if(imval > colorBox_max) - { - colorBox_max = imval; - } - } + m_colorBox_max = imval; } + } } - RTIMV_DEBUG_BREADCRUMB - - if(!std::isfinite(imdat_max) || !std::isfinite(imdat_min)) + if(!std::isfinite(m_colorBox_max) || !std::isfinite(m_colorBox_min)) { - // It should be impossible for them to be infinite by themselves unless it's all NaNs. - imdat_max = 0; - imdat_min = 0; + // It should be impossible for them to be infinite by themselves unless it's all NaNs in the box. + m_colorBox_max = 0; + m_colorBox_min = 0; } - if(colorBoxActive) + if(resized || (newdata && m_autoScale)) { - if(!std::isfinite(colorBox_max) || !std::isfinite(colorBox_min)) - { - // It should be impossible for them to be infinite by themselves unless it's all NaNs in the box. - colorBox_max = 0; - colorBox_min = 0; - } - - mindat(colorBox_min); - maxdat(colorBox_max); - } - else - { - mindat(imdat_min); - maxdat(imdat_max); + mindat(m_colorBox_min); + maxdat(m_colorBox_max); } + } + RTIMV_DEBUG_BREADCRUMB if(!m_qim) @@ -933,7 +936,7 @@ void rtimvBase::changeImdata(bool newdata) m_amChangingimdata = false; -} //void rtimvBase::changeImdata(bool newdata) +} //void rtimvBase::mtxUL_changeImdata(bool newdata) void rtimvBase::mtxL_recolor(const std::unique_lock & lock) { @@ -1023,20 +1026,6 @@ void rtimvBase::mtxL_recolor(const std::unique_lock & lock) mtxL_postRecolor(lock); } -void rtimvBase::mtxL_postRecolor( const std::unique_lock & lock ) -{ - RTIMV_DEBUG_BREADCRUMB - assert(lock.owns_lock()); - return; -} - -void rtimvBase::mtxL_postChangeImdata( const std::unique_lock & lock ) -{ - RTIMV_DEBUG_BREADCRUMB - assert(lock.owns_lock()); - return; -} - void rtimvBase::zoomLevel(float zl) { if(zl < m_zoomLevelMin) @@ -1058,80 +1047,113 @@ void rtimvBase::zoomLevel(float zl) RTIMV_DEBUG_BREADCRUMB } -void rtimvBase::post_zoomLevel() +void rtimvBase::normalizeColorBox() { - return; + if(m_colorBox_i0 < 0) + { + m_colorBox_i0 = 0; + } + else if(m_colorBox_i0 >= (int64_t) m_nx-1) + { + m_colorBox_i0 = (int64_t) m_nx - 2; + } + + if(m_colorBox_i1 < 0) + { + m_colorBox_i1 = 0; + } + else if(m_colorBox_i1 >= (int64_t )m_nx-1) + { + m_colorBox_i1 = m_nx-2; + } + + if(m_colorBox_i0 > m_colorBox_i1) + { + std::swap(m_colorBox_i0, m_colorBox_i1); + } + + if(m_colorBox_j0 < 0) + { + m_colorBox_j0 = 0; + } + else if(m_colorBox_j0 >= (int64_t) m_ny-1) + { + m_colorBox_j0 = (int64_t) m_ny - 2; + } + + if(m_colorBox_j1 <= 0) + { + m_colorBox_j1 = 0; + } + else if(m_colorBox_j1 >= (int64_t) m_ny-1) + { + m_colorBox_j1 = (int64_t) m_ny - 2; + } + + if(m_colorBox_j0 > m_colorBox_j1) + { + std::swap(m_colorBox_j0, m_colorBox_j1); + } } -void rtimvBase::mtxL_setUserBoxActive( bool usba, - const std::unique_lock & lock - ) +void rtimvBase::colorBox_i0( int64_t i0 ) { - assert(lock.owns_lock()); + m_colorBox_i0 = i0; +} - if(usba) - { - int idx; - float imval; +int64_t rtimvBase::colorBox_i0() +{ + return m_colorBox_i0; +} - if(colorBox_i0 > colorBox_i1) - { - idx = colorBox_i0; - colorBox_i0 = colorBox_i1; - colorBox_i1 = idx; - } +void rtimvBase::colorBox_i1( int64_t i1 ) +{ + m_colorBox_i1 = i1; +} - if(colorBox_i0 < 0) - { - colorBox_i0 = 0; - } - else if(colorBox_i0 >= (int64_t) m_nx) - { - colorBox_i0 = (int64_t)m_nx - (colorBox_i1 - colorBox_i0); - } +int64_t rtimvBase::colorBox_i1() +{ + return m_colorBox_i1; +} - if(colorBox_i1 <= 0) - { - colorBox_i1 = 0 + (colorBox_i1 - colorBox_i0); - } - - if(colorBox_i1 > (int64_t )m_nx) - { - colorBox_i1 = (int64_t)m_nx - 1; - } +void rtimvBase::colorBox_j0( int64_t j0 ) +{ + m_colorBox_j0 = j0; +} - if(colorBox_j0 > colorBox_j1) - { - idx = colorBox_j0; - colorBox_j0 = colorBox_j1; - colorBox_j1 = idx; - } +int64_t rtimvBase::colorBox_j0() +{ + return m_colorBox_j0; +} - if(colorBox_j0 < 0) - { - colorBox_j0 = 0; - } - else if(colorBox_j0 >= (int64_t) m_nx) - { - colorBox_j0 = (int64_t) m_ny - (colorBox_j1 - colorBox_j0); - } +void rtimvBase::colorBox_j1( int64_t j1 ) +{ + m_colorBox_j1 = j1; +} - if(colorBox_j1 <= 0) - { - colorBox_j1 = 0 + (colorBox_j1 - colorBox_j0); - } +int64_t rtimvBase::colorBox_j1() +{ + return m_colorBox_j1; +} - if(colorBox_j1 >= (int64_t) m_ny) - { - colorBox_j1 = (int64_t) m_ny - 1; - } +void rtimvBase::mtxL_setColorBoxActive( bool usba, + const std::unique_lock & lock + ) +{ + assert(lock.owns_lock()); - colorBox_min = std::numeric_limits::max(); - colorBox_max = -std::numeric_limits::max(); + if(usba) + { + float imval; + + normalizeColorBox(); + + m_colorBox_min = std::numeric_limits::max(); + m_colorBox_max = -std::numeric_limits::max(); - for(int i = colorBox_i0; i < colorBox_i1; i++) + for(int i = m_colorBox_i0; i <= m_colorBox_i1; i++) { - for(int j = colorBox_j0; j < colorBox_j1; j++) + for(int j = m_colorBox_j0; j <= m_colorBox_j1; j++) { imval = calPixel(i,j); @@ -1140,31 +1162,34 @@ void rtimvBase::mtxL_setUserBoxActive( bool usba, continue; } - if(imval < colorBox_min) - colorBox_min = imval; - if(imval > colorBox_max) - colorBox_max = imval; + if(imval < m_colorBox_min) + m_colorBox_min = imval; + if(imval > m_colorBox_max) + m_colorBox_max = imval; } } - if(colorBox_min == std::numeric_limits::max() && colorBox_max == -std::numeric_limits::max()) // If all nans + if(m_colorBox_min == std::numeric_limits::max() && m_colorBox_max == -std::numeric_limits::max()) // If all nans { - colorBox_min = 0; - colorBox_max = 0; + m_colorBox_min = 0; + m_colorBox_max = 0; } - mindat(colorBox_min); - maxdat(colorBox_max); + mindat(m_colorBox_min); + maxdat(m_colorBox_max); set_colorbar_mode(minmaxbox); - + } + else + { + set_colorbar_mode(minmaxglobal); } colorBoxActive = usba; mtxL_recolor(lock); - mtxL_postSetUserBoxActive(usba, lock); + mtxL_postSetColorBoxActive(usba, lock); } diff --git a/src/rtimvBase.hpp b/src/rtimvBase.hpp index f5ddfef..464359e 100644 --- a/src/rtimvBase.hpp +++ b/src/rtimvBase.hpp @@ -12,8 +12,8 @@ #include #include #include -#include -#include +//#include +//#include #include #include @@ -30,7 +30,7 @@ #include #include -#include +//#include #include "colorMaps.hpp" @@ -139,7 +139,7 @@ class rtimvBase : public QWidget ); /// Called after set_imsize to handle allocations for derived classes - virtual void mtxL_postSetImsize( const std::unique_lock & lock ); + virtual void mtxL_postSetImsize( const std::unique_lock & lock ) = 0; ///Get the number of x pixels /** @@ -450,13 +450,13 @@ protected slots: ///Updates the QImage and basic statistics after a new image. /** \param newdata determines whether statistics are calculated (true) or not (false). */ - void changeImdata(bool newdata = false); + void mtxUL_changeImdata(bool newdata = false); void mtxL_recolor(const std::unique_lock & lock); - virtual void mtxL_postRecolor( const std::unique_lock & lock ); /// & lock ) = 0; /// & lock ); /// & lock ) = 0; /// & lock - ); + void mtxL_setColorBoxActive( bool usba, + const std::unique_lock & lock + ); - virtual void mtxL_postSetUserBoxActive( bool usba, - const std::unique_lock & lock - ) = 0; + virtual void mtxL_postSetColorBoxActive( bool usba, + const std::unique_lock & lock + ) = 0; ///@} diff --git a/src/rtimvControlPanel.cpp b/src/rtimvControlPanel.cpp index 6d8ca79..4c7df9b 100644 --- a/src/rtimvControlPanel.cpp +++ b/src/rtimvControlPanel.cpp @@ -712,7 +712,7 @@ void rtimvControlPanel::update_contrastRelEntry() void rtimvControlPanel::on_scaleModeCombo_activated(int index) { - + std::cerr << "activated\n"; if(index == rtimvBase::minmaxglobal) { std::unique_lock lock(*m_calMutex); @@ -721,7 +721,7 @@ void rtimvControlPanel::on_scaleModeCombo_activated(int index) imv->maxdat(imv->get_imdat_max()); imv->mindat(imv->get_imdat_min()); - imv->mtxL_setUserBoxActive(false, lock); + imv->mtxL_setColorBoxActive(false, lock); update_mindatEntry(); update_maxdatEntry(); @@ -737,11 +737,11 @@ void rtimvControlPanel::on_scaleModeCombo_activated(int index) { std::unique_lock lock(*m_calMutex); imv->set_colorbar_mode(rtimvBase::user); - imv->mtxL_setUserBoxActive(false, lock); + imv->mtxL_setColorBoxActive(false, lock); } else if(index == rtimvBase::minmaxbox) { - imv->toggleColorBox(); + imv->toggleColorBoxOn(); update_mindatEntry(); update_maxdatEntry(); @@ -755,7 +755,7 @@ void rtimvControlPanel::on_scaleModeCombo_activated(int index) else { std::unique_lock lock(*m_calMutex); - imv->mtxL_setUserBoxActive(false, lock); + imv->mtxL_setColorBoxActive(false, lock); } } @@ -768,7 +768,7 @@ void rtimvControlPanel::on_mindatSlider_valueChanged(int value) std::unique_lock lock(*m_calMutex); imv->set_colorbar_mode(rtimvBase::user); - imv->mtxL_setUserBoxActive(false, lock); + imv->mtxL_setColorBoxActive(false, lock); lock.unlock(); @@ -792,7 +792,7 @@ void rtimvControlPanel::on_mindatEntry_editingFinished() std::unique_lock lock(*m_calMutex); imv->set_colorbar_mode(rtimvBase::user); - imv->mtxL_setUserBoxActive(false, lock); + imv->mtxL_setColorBoxActive(false, lock); lock.unlock(); @@ -808,7 +808,7 @@ void rtimvControlPanel::on_maxdatSlider_valueChanged(int value) std::unique_lock lock(*m_calMutex); imv->set_colorbar_mode(rtimvBase::user); - imv->mtxL_setUserBoxActive(false, lock); + imv->mtxL_setColorBoxActive(false, lock); lock.unlock(); @@ -831,7 +831,7 @@ void rtimvControlPanel::on_maxdatEntry_editingFinished() std::unique_lock lock(*m_calMutex); imv->set_colorbar_mode(rtimvBase::user); - imv->mtxL_setUserBoxActive(false, lock); + imv->mtxL_setColorBoxActive(false, lock); lock.unlock(); ui.scaleModeCombo->setCurrentIndex(SCALEMODE_USER); @@ -846,7 +846,7 @@ void rtimvControlPanel::on_biasSlider_valueChanged(int value) std::unique_lock lock(*m_calMutex); imv->set_colorbar_mode(rtimvBase::user); - imv->mtxL_setUserBoxActive(false, lock); + imv->mtxL_setColorBoxActive(false, lock); lock.unlock(); @@ -866,7 +866,7 @@ void rtimvControlPanel::on_biasEntry_editingFinished() std::unique_lock lock(*m_calMutex); imv->set_colorbar_mode(rtimvBase::user); - imv->mtxL_setUserBoxActive(false, lock); + imv->mtxL_setColorBoxActive(false, lock); lock.unlock(); ui.scaleModeCombo->setCurrentIndex(SCALEMODE_USER); @@ -888,7 +888,7 @@ void rtimvControlPanel::on_contrastSlider_valueChanged(int value) std::unique_lock lock(*m_calMutex); imv->set_colorbar_mode(rtimvBase::user); - imv->mtxL_setUserBoxActive(false, lock); + imv->mtxL_setColorBoxActive(false, lock); lock.unlock(); ui.scaleModeCombo->setCurrentIndex(SCALEMODE_USER); @@ -907,7 +907,7 @@ void rtimvControlPanel::on_contrastEntry_editingFinished() std::unique_lock lock(*m_calMutex); imv->set_colorbar_mode(rtimvBase::user); - imv->mtxL_setUserBoxActive(false, lock); + imv->mtxL_setColorBoxActive(false, lock); lock.unlock(); ui.scaleModeCombo->setCurrentIndex(SCALEMODE_USER); diff --git a/src/rtimvControlPanel.hpp b/src/rtimvControlPanel.hpp index 10a56c9..e4e2fd3 100644 --- a/src/rtimvControlPanel.hpp +++ b/src/rtimvControlPanel.hpp @@ -119,6 +119,12 @@ class rtimvControlPanel : public QWidget void viewBoxMoved ( const QRectF & newcen); /*** Color Controls ***/ + void setScaleMode(int sm) + { + std::cerr << "seeting scale mode\n"; + ui.scaleModeCombo->setCurrentIndex(sm); + } + protected slots: void on_scaleTypeCombo_activated(int); void on_colorbarCombo_activated(int); diff --git a/src/rtimvMainWindow.cpp b/src/rtimvMainWindow.cpp index feafc21..0fe1609 100644 --- a/src/rtimvMainWindow.cpp +++ b/src/rtimvMainWindow.cpp @@ -305,6 +305,13 @@ void rtimvMainWindow::mtxL_postSetImsize( const std::unique_lock & l imcp->ui.viewView->setTransform(transform); } + statsBoxRemove(m_statsBox); + + if(m_colorBox) + { + colorBoxRemove(m_colorBox); + } + std::unordered_set::iterator ubit = m_userBoxes.begin(); while(ubit != m_userBoxes.end()) { @@ -555,20 +562,19 @@ void rtimvMainWindow::reStretch() { set_colorbar_mode(minmaxglobal); } - - if(get_colorbar_mode() == minmaxglobal) + else if(get_colorbar_mode() == minmaxglobal) { mindat(get_imdat_min()); maxdat(get_imdat_max()); - changeImdata(false); } - - if(get_colorbar_mode() == minmaxbox) + else if(get_colorbar_mode() == minmaxbox) { - mindat(colorBox_min); - maxdat(colorBox_max); - changeImdata(false); + mindat(m_colorBox_min); + maxdat(m_colorBox_max); } + + std::unique_lock lock(m_calMutex); + mtxL_recolor(lock); } @@ -1073,30 +1079,30 @@ void rtimvMainWindow::mtxTry_colorBoxMoved(StretchBox * sb) QPointF np = m_qpmi->mapFromItem(m_colorBox, QPointF(newr.x(),newr.y())); QPointF np2 = m_qpmi->mapFromItem(m_colorBox, QPointF(newr.x()+newr.width(),newr.y()+newr.height())); - colorBox_i1 = (int) (np2.x() + .5); - colorBox_i0 = (int) np.x(); - colorBox_j0 = m_ny-(int) (np2.y() + .5); - colorBox_j1 = m_ny-(int) np.y(); - + colorBox_i0((int64_t) (np2.x() + .5)); + colorBox_i1((int64_t) np.x()); + colorBox_j0((int64_t) m_ny - (int64_t) (np2.y() + .5)); + colorBox_j1((int64_t) m_ny - (int64_t) np.y()); + char tmp[256]; char valMin[64]; char valMax[64]; - if(fabs(colorBox_min) < 1e-1) + if(fabs(m_colorBox_min) < 1e-1) { - snprintf(valMin, sizeof(valMin), "%0.04g", colorBox_min); + snprintf(valMin, sizeof(valMin), "%0.04g", m_colorBox_min); } else { - snprintf(valMin, sizeof(valMin), "%0.02f", colorBox_min); + snprintf(valMin, sizeof(valMin), "%0.02f", m_colorBox_min); } - if(fabs(colorBox_max) < 1e-1) + if(fabs(m_colorBox_max) < 1e-1) { - snprintf(valMax, sizeof(valMax), "%0.04g", colorBox_max); + snprintf(valMax, sizeof(valMax), "%0.04g", m_colorBox_max); } else { - snprintf(valMax, sizeof(valMax), "%0.02f", colorBox_max); + snprintf(valMax, sizeof(valMax), "%0.02f", m_colorBox_max); } snprintf(tmp, 256, "min: %s\nmax: %s", valMin, valMax); @@ -1114,7 +1120,7 @@ void rtimvMainWindow::mtxTry_colorBoxMoved(StretchBox * sb) mtxL_fontLuminance(ui.graphicsView->m_userItemSize, lock); - mtxL_setUserBoxActive(true, lock); //recalcs and recolors. + mtxL_setColorBoxActive(true, lock); //recalcs and recolors. } void rtimvMainWindow::mtxTry_colorBoxSelected(StretchBox * sb) @@ -1137,6 +1143,20 @@ void rtimvMainWindow::colorBoxRemove(StretchBox * sb) { static_cast(sb); + std::cerr << "colorBoxRemove\n"; + if(sb == nullptr || m_colorBox == nullptr) + { + return; + } + + colorBoxActive = false; + set_colorbar_mode(minmaxglobal); + + m_colorBox->disconnect(); + disconnect(m_colorBox); + m_colorBox->deleteLater(); + m_colorBox = nullptr; + ui.graphicsView->m_userItemSize->setVisible(false); ui.graphicsView->m_userItemMouseCoords->setVisible(false); m_objCenH->setVisible(false); @@ -1144,7 +1164,6 @@ void rtimvMainWindow::colorBoxRemove(StretchBox * sb) m_nullMouseCoords=false; m_userItemSelected = false; - toggleColorBox(); } /*---- Stats Box and Display ----*/ @@ -1174,6 +1193,11 @@ void rtimvMainWindow::doHideStatsBox() { std::cerr << "doHideStatsBox()\n"; + if(imStats) + { + delete imStats; + imStats = 0; //imStats is set to delete on close + } if(m_statsBox) { @@ -1185,11 +1209,7 @@ void rtimvMainWindow::doHideStatsBox() m_statsBox->setVisible(false); } - if(imStats) - { - delete imStats; - imStats = 0; //imStats is set to delete on close - } + } void rtimvMainWindow::imStatsClosed(int result) @@ -1245,7 +1265,19 @@ void rtimvMainWindow::mtxTry_statsBoxSelected(StretchBox * sb) void rtimvMainWindow::statsBoxRemove(StretchBox * sb) { static_cast(sb); - + + if(sb == nullptr || m_statsBox == nullptr) + { + return; + } + + doHideStatsBox(); + m_statsBox->disconnect(); + disconnect(m_statsBox); + m_statsBox->deleteLater(); + + m_statsBox = nullptr; + ui.graphicsView->m_userItemSize->setVisible(false); ui.graphicsView->m_userItemMouseCoords->setVisible(false); m_objCenH->setVisible(false); @@ -1253,7 +1285,6 @@ void rtimvMainWindow::statsBoxRemove(StretchBox * sb) m_nullMouseCoords=false; m_userItemSelected = false; - toggleStatsBox(); } @@ -1341,7 +1372,7 @@ void rtimvMainWindow::addStretchBox(StretchBox * sb) { if(sb == nullptr) return; - m_userBoxes.insert(sb); + //m_userBoxes.insert(sb); connect(sb, SIGNAL(rejectMouse(StretchBox *)), this, SLOT(userBoxRejectMouse(StretchBox *))); connect(sb, SIGNAL(remove(StretchBox*)), this, SLOT(userBoxRemove(StretchBox*))); @@ -1382,9 +1413,8 @@ void rtimvMainWindow::userBoxRejectMouse(StretchBox * sb) void rtimvMainWindow::userBoxRemove(StretchBox * sb) { - if(sb == m_statsBox) + if(sb == m_statsBox || sb == m_colorBox) { - doHideStatsBox(); return; } @@ -1399,11 +1429,6 @@ void rtimvMainWindow::userBoxRemove(StretchBox * sb) m_nullMouseCoords=false; m_userItemSelected = false; - if(sb == m_statsBox) - { - m_statsBox = nullptr; - return; - } } void rtimvMainWindow::mtxTry_userBoxSelected(StretchBox * sb) @@ -1879,15 +1904,16 @@ void rtimvMainWindow::savingState(bool ss) } } -void rtimvMainWindow::mtxL_postSetUserBoxActive( bool usba, - const std::unique_lock & lock - ) +void rtimvMainWindow::mtxL_postSetColorBoxActive( bool usba, + const std::unique_lock & lock + ) { assert(lock.owns_lock()); - if(!m_colorBox) return; - - m_colorBox->setVisible(usba); + if(m_colorBox) + { + m_colorBox->setVisible(usba); + } } @@ -2051,6 +2077,18 @@ void rtimvMainWindow::mtxUL_center() } void rtimvMainWindow::toggleColorBox() +{ + if(!colorBoxActive || !m_colorBox) + { + toggleColorBoxOn(); + } + else + { + toggleColorBoxOff(); + } +} + +void rtimvMainWindow::toggleColorBoxOn() { if(m_colorBox == nullptr) { @@ -2058,19 +2096,19 @@ void rtimvMainWindow::toggleColorBox() if(m_nx < m_ny) w = (m_nx/m_zoomLevel)/4; else w = (m_ny/m_zoomLevel)/4; - colorBox_i0 = 0.5*(m_nx)-w/2; - colorBox_i1 = colorBox_i0 + w; - colorBox_j0 = 0.5*(m_ny)-w/2; - colorBox_j1 = colorBox_j0 + w; + colorBox_i0(0.5*(m_nx)-w/2); + colorBox_i1(colorBox_i0() + w); + colorBox_j0(0.5*(m_ny)-w/2); + colorBox_j1(colorBox_j0() + w); - m_colorBox = new StretchBox(colorBox_i0, colorBox_j0, w, w); + m_colorBox = new StretchBox(colorBox_i0(), colorBox_j0(), w, w); m_colorBox->setPenColor(RTIMV_DEF_COLORBOXCOLOR); m_colorBox->setPenWidth(RTIMV_TOOLLINEWIDTH_DEFAULT); m_colorBox->setVisible(false); m_colorBox->setStretchable(true); m_colorBox->setRemovable(true); - m_userBoxes.insert(m_colorBox); + //m_userBoxes.insert(m_colorBox); connect(m_colorBox, SIGNAL(resized(StretchBox *)), this, SLOT(mtxTry_colorBoxMoved(StretchBox * ))); connect(m_colorBox, SIGNAL(moved(StretchBox *)), this, SLOT(mtxTry_colorBoxMoved(StretchBox * ))); @@ -2081,39 +2119,36 @@ void rtimvMainWindow::toggleColorBox() m_qgs->addItem(m_colorBox); } - if(!colorBoxActive) - { - m_colorBox->setVisible(true); + m_colorBox->setVisible(true); - std::unique_lock lock(m_calMutex); - mtxL_setUserBoxActive(true, lock); - lock.unlock(); + std::unique_lock lock(m_calMutex); + mtxL_setColorBoxActive(true, lock); + lock.unlock(); - ui.graphicsView->zoomText("color box scale"); - mtxTry_fontLuminance(ui.graphicsView->m_zoomText); - } - else - { - if(m_colorBox->isSelected()) - { - colorBoxDeselected(m_colorBox); - } + ui.graphicsView->zoomText("color box scale"); + mtxTry_fontLuminance(ui.graphicsView->m_zoomText); - m_colorBox->setVisible(false); +} + +void rtimvMainWindow::toggleColorBoxOff() +{ + if(m_colorBox->isSelected()) + { + colorBoxDeselected(m_colorBox); + } - std::unique_lock lock(m_calMutex); - mtxL_setUserBoxActive(false, lock); - lock.unlock(); + m_colorBox->setVisible(false); - m_colorBox->deleteLater(); - m_colorBox = nullptr; - + std::unique_lock lock(m_calMutex); + mtxL_setColorBoxActive(false, lock); + lock.unlock(); - ui.graphicsView->zoomText("global scale"); - mtxTry_fontLuminance(ui.graphicsView->m_zoomText); - } + ui.graphicsView->zoomText("global scale"); + mtxTry_fontLuminance(ui.graphicsView->m_zoomText); + } + void rtimvMainWindow::toggleStatsBox() { if(m_statsBox == nullptr) @@ -2234,7 +2269,8 @@ void rtimvMainWindow::setDarkSub( bool ds ) ui.graphicsView->zoomText("dark sub. off"); mtxTry_fontLuminance(ui.graphicsView->m_zoomText); } - changeImdata(false); + + mtxUL_changeImdata(false); } void rtimvMainWindow::toggleDarkSub() @@ -2262,7 +2298,8 @@ void rtimvMainWindow::setApplyMask( bool am ) ui.graphicsView->zoomText("mask off"); mtxTry_fontLuminance(ui.graphicsView->m_zoomText); } - changeImdata(false); + + mtxUL_changeImdata(false); } void rtimvMainWindow::toggleApplyMask() @@ -2291,7 +2328,7 @@ void rtimvMainWindow::setApplySatMask( bool as ) mtxTry_fontLuminance(ui.graphicsView->m_zoomText); } - changeImdata(false); + mtxUL_changeImdata(false); } diff --git a/src/rtimvMainWindow.hpp b/src/rtimvMainWindow.hpp index c387a6b..1916c37 100644 --- a/src/rtimvMainWindow.hpp +++ b/src/rtimvMainWindow.hpp @@ -577,9 +577,9 @@ public slots: public: - virtual void mtxL_postSetUserBoxActive( bool usba, - const std::unique_lock & lock - ); + virtual void mtxL_postSetColorBoxActive( bool usba, + const std::unique_lock & lock + ); protected: bool m_showLoopStat{false}; @@ -598,6 +598,8 @@ public slots: void toggleFPSGage(); void toggleColorBox(); + void toggleColorBoxOn(); + void toggleColorBoxOff(); void toggleStatsBox();