diff --git a/averagewavefrontfilesdlg.cpp b/averagewavefrontfilesdlg.cpp index 02343704..7fc615f0 100644 --- a/averagewavefrontfilesdlg.cpp +++ b/averagewavefrontfilesdlg.cpp @@ -123,7 +123,8 @@ void averageWaveFrontFilesDlg::on_process_clicked() ui->progressBar->setValue(0); ui->progressBar->setFormat("Done"); - emit averageComplete( average ); + if (average) + emit averageComplete( average ); } if (rejects.size() > 0){ rejectedWavefrontsDlg dlg(rejects); diff --git a/dftarea.cpp b/dftarea.cpp index dff592d2..e24723ec 100644 --- a/dftarea.cpp +++ b/dftarea.cpp @@ -1049,7 +1049,7 @@ void DFTArea::makeSurface(){ showData("result surface", result.clone()); } - emit newWavefront(result, m_outside, m_center, QFileInfo(igramArea->m_filename).baseName(), + emit newWavefront(result, m_outside, m_center, QFileInfo(igramArea->m_filename).baseName(), WavefrontOrigin::Igram, m_poly); QApplication::restoreOverrideCursor(); success = true; @@ -1514,7 +1514,7 @@ qDebug() << "rec" << left << top << width << height; m_center.m_center.rx() = (result.cols-1) - m_center.m_center.x(); } QString wfname = QString("PSI")+ finfo.baseName() + QString("-") + QFileInfo(m_psiFiles[imagecount-1]).baseName(); - emit newWavefront(result, m_outside, m_center, wfname, m_poly); + emit newWavefront(result, m_outside, m_center, wfname, WavefrontOrigin::Igram, m_poly); QApplication::restoreOverrideCursor(); } diff --git a/dftarea.h b/dftarea.h index 1e4db207..422e3ca7 100644 --- a/dftarea.h +++ b/dftarea.h @@ -28,6 +28,7 @@ #include #include "psi_dlg.h" #include "psiphasedisplay.h" +#include "wavefront.h" extern void showData(const std::string& txt, const cv::Mat &mat, bool useLog = false); extern QImage showMag(const cv::Mat &complexI, bool show = false, const char *title = "FFT", bool doLog = true, double gamma = 0); @@ -87,7 +88,7 @@ public slots: void setDftSizeVal(int); void selectDFTTab(); void updateFilterSize(int); - void newWavefront(cv::Mat, CircleOutline, CircleOutline, const QString &, + void newWavefront(cv::Mat, CircleOutline, CircleOutline, const QString &, WavefrontOrigin origin, QVector >); void dftReady(QImage); void statusBarUpdate(QString, int); diff --git a/mainwindow.cpp b/mainwindow.cpp index 208528ab..f94ef72b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -862,7 +862,7 @@ void MainWindow::on_actionWavefront_triggered() m_surfaceManager->createSurfaceFromPhaseMap(result, CircleOutline(QPointF(xcen,ycen),rad), CircleOutline(QPointF(0,0),0), - QString("Simulated_Wavefront")); + QString("Simulated_Wavefront"), WavefrontOrigin::Simulation); } void MainWindow::on_actionIgram_triggered() diff --git a/surfacemanager.cpp b/surfacemanager.cpp index d594de2c..f685f04a 100644 --- a/surfacemanager.cpp +++ b/surfacemanager.cpp @@ -378,8 +378,14 @@ void SurfaceManager::generateSurfacefromWavefront(wavefront * wf){ mirrorDlg *md = mirrorDlg::get_Instance(); zp.unwrap_to_zernikes(*wf); - // check for swapped conic value - if (!m_ignoreInverse) + + // + // AUTO INVERT CODE STARTS HERE + // + + if (!m_ignoreInverse && + wf->m_manuallyInverted == false && // don't auto-invert if user already manually inverted + wf->m_origin == WavefrontOrigin::Igram) // only auto-invert if wavefront created from processed igram { if (m_inverseMode==invNOTSET) { @@ -413,6 +419,9 @@ void SurfaceManager::generateSurfacefromWavefront(wavefront * wf){ } } + // + // AUTO INVERT CODE ENDS HERE/ + // ((MainWindow*)parent())-> zernTablemodel->setValues(wf->InputZerns, !wf->useSANull); ((MainWindow*)parent())-> zernTablemodel->update(); @@ -806,7 +815,7 @@ void SurfaceManager::useDemoWaveFront(){ createSurfaceFromPhaseMap(result, CircleOutline(QPointF(xcen,ycen),rad), CircleOutline(QPointF(0,0),0), - QString("Demo")); + QString("Demo"), WavefrontOrigin::Demo); } void SurfaceManager::waveFrontClickedSlot(int ndx) @@ -1062,7 +1071,8 @@ void SurfaceManager::SaveWavefronts(bool saveNulled){ } void SurfaceManager::createSurfaceFromPhaseMap(cv::Mat phase, CircleOutline outside, CircleOutline center, - const QString &name, QVector > polyArea){ + const QString &name, WavefrontOrigin origin, + QVector > polyArea){ wavefront *wf; @@ -1100,6 +1110,7 @@ void SurfaceManager::createSurfaceFromPhaseMap(cv::Mat phase, CircleOutline outs m_surfaceTools->addWaveFront(wf->name); m_currentNdx = m_wavefronts.size()-1; } + wf->m_origin = origin; wf->m_outside = outside; wf->m_inside = center; wf->data = phase; @@ -1129,6 +1140,7 @@ wavefront * SurfaceManager::readWaveFront(const QString &fileName){ } spdlog::get("logger")->trace("readWaveFront() step 1"); wavefront *wf = new wavefront(); + wf->m_origin = WavefrontOrigin::File; double width; double height; file >> width; @@ -1634,6 +1646,7 @@ void SurfaceManager::average(QList wfList){ wf->data = sum.clone(); wf->mask = mask; wf->workMask = mask.clone(); + wf->m_origin = WavefrontOrigin::Average; m_wavefronts << wf; wf->wasSmoothed = false; wf->name = "Average.wft"; @@ -1658,6 +1671,7 @@ void SurfaceManager::averageComplete(wavefront *wf){ wf->wasSmoothed = false; wf->name = "Average.wft"; wf->dirtyZerns = true; + wf->m_origin = WavefrontOrigin::Average; m_surfaceTools->addWaveFront(wf->name); m_currentNdx = m_wavefronts.size()-1; //makeMask(m_currentNdx); @@ -1726,7 +1740,7 @@ void SurfaceManager::rotateThese(double angle, QList list){ QStringList l = oldWf->name.split('.'); QString newName = QString("%1_%2%3.wft").arg(l[0]).arg((angle >= 0) ? "CW":"CCW").arg(fabs(angle), 5, 'f', 1, QLatin1Char('0')); // clazy:exclude=qstring-arg wavefront *wf = new wavefront(); - *wf = *oldWf; // copy everything to new wavefront including basic things like diameter,wavelength + *wf = *oldWf; // copy everything to new wavefront including basic things like diameter,wavelength,origin //emit nameChanged(wf->name, newName); wf->name = newName; @@ -1802,6 +1816,7 @@ void SurfaceManager::subtract(wavefront *wf1, wavefront *wf2, bool use_null){ resultwf->data = result.clone(); resultwf->mask = mask.clone(); resultwf->workMask = mask.clone(); + resultwf->m_origin = WavefrontOrigin::Subtraction; m_wavefronts << resultwf; m_currentNdx = m_wavefronts.size() -1; @@ -1861,8 +1876,7 @@ void SurfaceManager::invert(QList list){ m_wavefronts[list[i]]->data *= -1; m_wavefronts[list[i]]->dirtyZerns = true; m_wavefronts[list[i]]->wasSmoothed = false; - m_ignoreInverse = true; - + m_wavefronts[list[i]]->m_manuallyInverted = true; } m_waveFrontTimer->start(500); } diff --git a/surfacemanager.h b/surfacemanager.h index de8108f3..ac19c46b 100644 --- a/surfacemanager.h +++ b/surfacemanager.h @@ -177,7 +177,7 @@ private slots: public slots: void rotateThese(double angle, QList list); void createSurfaceFromPhaseMap(cv::Mat phase, CircleOutline outside, - CircleOutline center, const QString &name, + CircleOutline center, const QString &name, WavefrontOrigin origin, QVector > polyArea= QVector >()); void invert(QList list); void wftNameChanged(int, const QString&); diff --git a/wavefront.cpp b/wavefront.cpp index 05ff78c8..1beff681 100644 --- a/wavefront.cpp +++ b/wavefront.cpp @@ -18,7 +18,7 @@ #include "wavefront.h" wavefront::wavefront(): - gaussian_diameter(0.),useSANull(true),dirtyZerns(true),regions_have_been_expanded(false) + gaussian_diameter(0.),useSANull(true),m_origin(WavefrontOrigin::Unknown),m_manuallyInverted(false),dirtyZerns(true),regions_have_been_expanded(false) { } @@ -44,6 +44,8 @@ wavefront::wavefront( const wavefront &wf): wasSmoothed(wf.wasSmoothed), useSANull(wf.useSANull), GBSmoothingValue(wf.GBSmoothingValue), + m_origin(wf.m_origin), + m_manuallyInverted(wf.m_manuallyInverted), lambda(wf.lambda), m_outside(wf.m_outside), m_inside(wf.m_inside), diff --git a/wavefront.h b/wavefront.h index cbb29dcc..1d7d13df 100644 --- a/wavefront.h +++ b/wavefront.h @@ -20,6 +20,18 @@ #include #include "Circleoutline.h" #include + +enum class WavefrontOrigin : std::uint8_t { + Unknown = 0, + Igram, + File, + Simulation, + Demo, + Average, + Subtraction, + Zernikes, + Smoothed +}; class wavefront { public: @@ -40,6 +52,8 @@ class wavefront bool wasSmoothed; bool useSANull; double GBSmoothingValue; + WavefrontOrigin m_origin; + bool m_manuallyInverted; // true if user inverted this wavefront QString name; double lambda; diff --git a/zernikeeditdlg.cpp b/zernikeeditdlg.cpp index 21e4c3c8..f7815d2d 100644 --- a/zernikeeditdlg.cpp +++ b/zernikeeditdlg.cpp @@ -86,7 +86,7 @@ void zernikeEditDlg::on_createSurface_clicked() m_sm->createSurfaceFromPhaseMap(result, CircleOutline(QPointF(xcen,ycen),rad), CircleOutline(QPointF(0,0),0), - QString("Zernike_Wavefront")); + QString("Zernike_Wavefront"), WavefrontOrigin::Zernikes); } void zernikeEditDlg::on_clearAll_clicked() diff --git a/zernikesmoothingdlg.cpp b/zernikesmoothingdlg.cpp index e8759bf5..80f47aff 100644 --- a/zernikesmoothingdlg.cpp +++ b/zernikesmoothingdlg.cpp @@ -134,8 +134,7 @@ void ZernikeSmoothingDlg::on_createWaveFront_clicked() l.back().append(QString("_sm%1").arg(m_noOfTerms)); m_sm->createSurfaceFromPhaseMap(result, m_wf.m_outside, m_wf.m_inside - - ,l.back()); + ,l.back(), WavefrontOrigin::Smoothed); if (ui->showResidual->isChecked()){ m_sm->subtract(&m_wf, m_sm->m_wavefronts.back(), false);