Skip to content

Commit 812e61c

Browse files
authored
Merge pull request #304 from githubdoe/issue167
skips auto-invert code for wavefronts not created from an igram.
2 parents 470001a + 73b445d commit 812e61c

File tree

10 files changed

+48
-17
lines changed

10 files changed

+48
-17
lines changed

averagewavefrontfilesdlg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ void averageWaveFrontFilesDlg::on_process_clicked()
123123
ui->progressBar->setValue(0);
124124
ui->progressBar->setFormat("Done");
125125

126-
emit averageComplete( average );
126+
if (average)
127+
emit averageComplete( average );
127128
}
128129
if (rejects.size() > 0){
129130
rejectedWavefrontsDlg dlg(rejects);

dftarea.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ void DFTArea::makeSurface(){
10491049
showData("result surface", result.clone());
10501050
}
10511051

1052-
emit newWavefront(result, m_outside, m_center, QFileInfo(igramArea->m_filename).baseName(),
1052+
emit newWavefront(result, m_outside, m_center, QFileInfo(igramArea->m_filename).baseName(), WavefrontOrigin::Igram,
10531053
m_poly);
10541054
QApplication::restoreOverrideCursor();
10551055
success = true;
@@ -1514,7 +1514,7 @@ qDebug() << "rec" << left << top << width << height;
15141514
m_center.m_center.rx() = (result.cols-1) - m_center.m_center.x();
15151515
}
15161516
QString wfname = QString("PSI")+ finfo.baseName() + QString("-") + QFileInfo(m_psiFiles[imagecount-1]).baseName();
1517-
emit newWavefront(result, m_outside, m_center, wfname, m_poly);
1517+
emit newWavefront(result, m_outside, m_center, wfname, WavefrontOrigin::Igram, m_poly);
15181518
QApplication::restoreOverrideCursor();
15191519
}
15201520

dftarea.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <string>
2929
#include "psi_dlg.h"
3030
#include "psiphasedisplay.h"
31+
#include "wavefront.h"
3132

3233
extern void showData(const std::string& txt, const cv::Mat &mat, bool useLog = false);
3334
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:
8788
void setDftSizeVal(int);
8889
void selectDFTTab();
8990
void updateFilterSize(int);
90-
void newWavefront(cv::Mat, CircleOutline, CircleOutline, const QString &,
91+
void newWavefront(cv::Mat, CircleOutline, CircleOutline, const QString &, WavefrontOrigin origin,
9192
QVector<std::vector<cv::Point> >);
9293
void dftReady(QImage);
9394
void statusBarUpdate(QString, int);

mainwindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ void MainWindow::on_actionWavefront_triggered()
862862
m_surfaceManager->createSurfaceFromPhaseMap(result,
863863
CircleOutline(QPointF(xcen,ycen),rad),
864864
CircleOutline(QPointF(0,0),0),
865-
QString("Simulated_Wavefront"));
865+
QString("Simulated_Wavefront"), WavefrontOrigin::Simulation);
866866
}
867867

868868
void MainWindow::on_actionIgram_triggered()

surfacemanager.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,14 @@ void SurfaceManager::generateSurfacefromWavefront(wavefront * wf){
378378

379379
mirrorDlg *md = mirrorDlg::get_Instance();
380380
zp.unwrap_to_zernikes(*wf);
381-
// check for swapped conic value
382-
if (!m_ignoreInverse)
381+
382+
//
383+
// AUTO INVERT CODE STARTS HERE
384+
//
385+
386+
if (!m_ignoreInverse &&
387+
wf->m_manuallyInverted == false && // don't auto-invert if user already manually inverted
388+
wf->m_origin == WavefrontOrigin::Igram) // only auto-invert if wavefront created from processed igram
383389
{
384390
if (m_inverseMode==invNOTSET)
385391
{
@@ -413,6 +419,9 @@ void SurfaceManager::generateSurfacefromWavefront(wavefront * wf){
413419
}
414420
}
415421

422+
//
423+
// AUTO INVERT CODE ENDS HERE/
424+
//
416425

417426
((MainWindow*)parent())-> zernTablemodel->setValues(wf->InputZerns, !wf->useSANull);
418427
((MainWindow*)parent())-> zernTablemodel->update();
@@ -806,7 +815,7 @@ void SurfaceManager::useDemoWaveFront(){
806815
createSurfaceFromPhaseMap(result,
807816
CircleOutline(QPointF(xcen,ycen),rad),
808817
CircleOutline(QPointF(0,0),0),
809-
QString("Demo"));
818+
QString("Demo"), WavefrontOrigin::Demo);
810819
}
811820

812821
void SurfaceManager::waveFrontClickedSlot(int ndx)
@@ -1062,7 +1071,8 @@ void SurfaceManager::SaveWavefronts(bool saveNulled){
10621071
}
10631072
void SurfaceManager::createSurfaceFromPhaseMap(cv::Mat phase, CircleOutline outside,
10641073
CircleOutline center,
1065-
const QString &name, QVector<std::vector<cv::Point> > polyArea){
1074+
const QString &name, WavefrontOrigin origin,
1075+
QVector<std::vector<cv::Point> > polyArea){
10661076

10671077
wavefront *wf;
10681078

@@ -1100,6 +1110,7 @@ void SurfaceManager::createSurfaceFromPhaseMap(cv::Mat phase, CircleOutline outs
11001110
m_surfaceTools->addWaveFront(wf->name);
11011111
m_currentNdx = m_wavefronts.size()-1;
11021112
}
1113+
wf->m_origin = origin;
11031114
wf->m_outside = outside;
11041115
wf->m_inside = center;
11051116
wf->data = phase;
@@ -1129,6 +1140,7 @@ wavefront * SurfaceManager::readWaveFront(const QString &fileName){
11291140
}
11301141
spdlog::get("logger")->trace("readWaveFront() step 1");
11311142
wavefront *wf = new wavefront();
1143+
wf->m_origin = WavefrontOrigin::File;
11321144
double width;
11331145
double height;
11341146
file >> width;
@@ -1634,6 +1646,7 @@ void SurfaceManager::average(QList<wavefront *> wfList){
16341646
wf->data = sum.clone();
16351647
wf->mask = mask;
16361648
wf->workMask = mask.clone();
1649+
wf->m_origin = WavefrontOrigin::Average;
16371650
m_wavefronts << wf;
16381651
wf->wasSmoothed = false;
16391652
wf->name = "Average.wft";
@@ -1658,6 +1671,7 @@ void SurfaceManager::averageComplete(wavefront *wf){
16581671
wf->wasSmoothed = false;
16591672
wf->name = "Average.wft";
16601673
wf->dirtyZerns = true;
1674+
wf->m_origin = WavefrontOrigin::Average;
16611675
m_surfaceTools->addWaveFront(wf->name);
16621676
m_currentNdx = m_wavefronts.size()-1;
16631677
//makeMask(m_currentNdx);
@@ -1726,7 +1740,7 @@ void SurfaceManager::rotateThese(double angle, QList<int> list){
17261740
QStringList l = oldWf->name.split('.');
17271741
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
17281742
wavefront *wf = new wavefront();
1729-
*wf = *oldWf; // copy everything to new wavefront including basic things like diameter,wavelength
1743+
*wf = *oldWf; // copy everything to new wavefront including basic things like diameter,wavelength,origin
17301744
//emit nameChanged(wf->name, newName);
17311745

17321746
wf->name = newName;
@@ -1802,6 +1816,7 @@ void SurfaceManager::subtract(wavefront *wf1, wavefront *wf2, bool use_null){
18021816
resultwf->data = result.clone();
18031817
resultwf->mask = mask.clone();
18041818
resultwf->workMask = mask.clone();
1819+
resultwf->m_origin = WavefrontOrigin::Subtraction;
18051820
m_wavefronts << resultwf;
18061821
m_currentNdx = m_wavefronts.size() -1;
18071822

@@ -1861,8 +1876,7 @@ void SurfaceManager::invert(QList<int> list){
18611876
m_wavefronts[list[i]]->data *= -1;
18621877
m_wavefronts[list[i]]->dirtyZerns = true;
18631878
m_wavefronts[list[i]]->wasSmoothed = false;
1864-
m_ignoreInverse = true;
1865-
1879+
m_wavefronts[list[i]]->m_manuallyInverted = true;
18661880
}
18671881
m_waveFrontTimer->start(500);
18681882
}

surfacemanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private slots:
177177
public slots:
178178
void rotateThese(double angle, QList<int> list);
179179
void createSurfaceFromPhaseMap(cv::Mat phase, CircleOutline outside,
180-
CircleOutline center, const QString &name,
180+
CircleOutline center, const QString &name, WavefrontOrigin origin,
181181
QVector<std::vector<cv::Point> > polyArea= QVector<std::vector<cv::Point> >());
182182
void invert(QList<int> list);
183183
void wftNameChanged(int, const QString&);

wavefront.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "wavefront.h"
1919

2020
wavefront::wavefront():
21-
gaussian_diameter(0.),useSANull(true),dirtyZerns(true),regions_have_been_expanded(false)
21+
gaussian_diameter(0.),useSANull(true),m_origin(WavefrontOrigin::Unknown),m_manuallyInverted(false),dirtyZerns(true),regions_have_been_expanded(false)
2222
{
2323
}
2424

@@ -44,6 +44,8 @@ wavefront::wavefront( const wavefront &wf):
4444
wasSmoothed(wf.wasSmoothed),
4545
useSANull(wf.useSANull),
4646
GBSmoothingValue(wf.GBSmoothingValue),
47+
m_origin(wf.m_origin),
48+
m_manuallyInverted(wf.m_manuallyInverted),
4749
lambda(wf.lambda),
4850
m_outside(wf.m_outside),
4951
m_inside(wf.m_inside),

wavefront.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@
2020
#include <opencv2/opencv.hpp>
2121
#include "Circleoutline.h"
2222
#include <QPointF>
23+
24+
enum class WavefrontOrigin : std::uint8_t {
25+
Unknown = 0,
26+
Igram,
27+
File,
28+
Simulation,
29+
Demo,
30+
Average,
31+
Subtraction,
32+
Zernikes,
33+
Smoothed
34+
};
2335
class wavefront
2436
{
2537
public:
@@ -40,6 +52,8 @@ class wavefront
4052
bool wasSmoothed;
4153
bool useSANull;
4254
double GBSmoothingValue;
55+
WavefrontOrigin m_origin;
56+
bool m_manuallyInverted; // true if user inverted this wavefront
4357

4458
QString name;
4559
double lambda;

zernikeeditdlg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void zernikeEditDlg::on_createSurface_clicked()
8686

8787
m_sm->createSurfaceFromPhaseMap(result, CircleOutline(QPointF(xcen,ycen),rad),
8888
CircleOutline(QPointF(0,0),0),
89-
QString("Zernike_Wavefront"));
89+
QString("Zernike_Wavefront"), WavefrontOrigin::Zernikes);
9090
}
9191

9292
void zernikeEditDlg::on_clearAll_clicked()

zernikesmoothingdlg.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ void ZernikeSmoothingDlg::on_createWaveFront_clicked()
134134
l.back().append(QString("_sm%1").arg(m_noOfTerms));
135135

136136
m_sm->createSurfaceFromPhaseMap(result, m_wf.m_outside, m_wf.m_inside
137-
138-
,l.back());
137+
,l.back(), WavefrontOrigin::Smoothed);
139138

140139
if (ui->showResidual->isChecked()){
141140
m_sm->subtract(&m_wf, m_sm->m_wavefronts.back(), false);

0 commit comments

Comments
 (0)