Skip to content

Commit d422256

Browse files
authored
Merge pull request #247 from githubdoe/issue246
fixes a bug found related to issue246. But there's still another (not understood) bug in the code that reads in the wavefront file. But only in QT6.
2 parents c6ec43f + 06bab5d commit d422256

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

surfacemanager.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#include "ui_oglrendered.h"
7676
#include "astigpolargraph.h"
7777

78+
7879
cv::Mat theMask;
7980
cv::Mat deb;
8081
double outputLambda;
@@ -438,6 +439,13 @@ cv::Mat SurfaceManager::computeWaveFrontFromZernikes(int wx, int wy, std::vector
438439

439440
double rho;
440441

442+
int maxZernToUse = 0;
443+
for (int value : zernsToUse) {
444+
if (value > maxZernToUse)
445+
maxZernToUse = value;
446+
}
447+
448+
441449
std::vector<bool> &en = zernEnables;
442450
mirrorDlg *md = mirrorDlg::get_Instance();
443451
for (int i = 0; i < wx; ++i)
@@ -452,7 +460,7 @@ cv::Mat SurfaceManager::computeWaveFrontFromZernikes(int wx, int wy, std::vector
452460
{
453461
double S1 = 0;
454462
double theta = atan2(y1,x1);
455-
zernikePolar zpolar(rho, theta, zernsToUse.size());
463+
zernikePolar zpolar(rho, theta, maxZernToUse+1);
456464
for (int ii = 0; ii < zernsToUse.size(); ++ii) {
457465
int z = zernsToUse[ii];
458466

@@ -1099,19 +1107,22 @@ wavefront * SurfaceManager::readWaveFront(const QString &fileName){
10991107
QMessageBox::warning(NULL, tr("Read Wavefront File"),b);
11001108
return 0;
11011109
}
1110+
spdlog::get("logger")->trace("readWaveFront() step 1");
11021111
wavefront *wf = new wavefront();
11031112
double width;
11041113
double height;
11051114
file >> width;
11061115
file >> height;
11071116
cv::Mat data(height,width, numType,0.);
1117+
spdlog::get("logger")->trace("readWaveFront() width {} height {}", width, height);
11081118

11091119
for( size_t y = 0; y < height; y++ ) {
11101120
for( size_t x = 0; x < width; x++ ) {
11111121
file >> data.at<double>(height - y-1,x);
11121122
//data.at<double>(height - y - 1, x) += dist(generator);
11131123
}
11141124
}
1125+
spdlog::get("logger")->trace("readWaveFront() step 2");
11151126

11161127
std::string line;
11171128
QString l;
@@ -1160,6 +1171,7 @@ wavefront * SurfaceManager::readWaveFront(const QString &fileName){
11601171
}
11611172
}
11621173

1174+
11631175
wf->m_outside = CircleOutline(QPointF(xm,ym), radm);
11641176
if (rado == 0){
11651177
xo = xm;
@@ -1290,8 +1302,9 @@ bool SurfaceManager::loadWavefront(const QString &fileName){
12901302
QMessageBox::warning(NULL, tr("Read Wavefront File"),b);
12911303
}
12921304
wavefront *wf;
1293-
1305+
spdlog::get("logger")->trace("loadWavefront()");
12941306
if (m_currentNdx == 0 && m_wavefronts[0]->name == "Demo"){
1307+
spdlog::get("logger")->trace("loadWavefront() delete current");
12951308
deleteCurrent();
12961309
}
12971310

@@ -1306,16 +1319,17 @@ bool SurfaceManager::loadWavefront(const QString &fileName){
13061319

13071320
// if resize to smaller
13081321
if (Settings2::getInstance()->m_general->shouldDownsize()){
1322+
spdlog::get("logger")->trace("loadWavefront() downSize");
13091323
downSizeWf(wf);
13101324
}
13111325
makeMask(m_currentNdx);
1312-
13131326
m_surface_finished = false;
13141327
try {
13151328
generateSurfacefromWavefront(m_currentNdx);
13161329
}
13171330
catch (int i){
13181331
deleteCurrent();
1332+
spdlog::get("logger")->critical("loadWavefront() crash while generating surface");
13191333
throw i;
13201334
}
13211335

@@ -2414,7 +2428,7 @@ textres SurfaceManager::Phase2(QList<rotationDef *> list, QList<wavefront *> inp
24142428
void SurfaceManager::computeStandAstig(define_input *wizPage, QList<rotationDef *> list){
24152429
// check for pairs
24162430
QVector<rotationDef*> lookat = list.toVector();
2417-
2431+
spdlog::get("logger")->trace("computeStandAstig()");
24182432
while (lookat.size()){
24192433
for (int i = 0; i < lookat.size(); ++i){
24202434
double angle1 = wrapAngle(lookat[i]->angle);
@@ -2449,6 +2463,7 @@ void SurfaceManager::computeStandAstig(define_input *wizPage, QList<rotationDef
24492463
}
24502464
}
24512465
QApplication::setOverrideCursor(Qt::WaitCursor);
2466+
spdlog::get("logger")->trace("computeStandAstig() create printer step 1");
24522467
QPrinter printer(QPrinter::HighResolution);
24532468
printer.setColorMode( QPrinter::Color );
24542469
printer.setFullPage( true );
@@ -2486,6 +2501,7 @@ void SurfaceManager::computeStandAstig(define_input *wizPage, QList<rotationDef
24862501
html.append("<td><p align='center'><b> Counter Rotated </b></p></td></tr>");
24872502

24882503

2504+
24892505
QTextDocument *doc = editor->document();
24902506
QList<QString> doc1Res;
24912507
doc->setPageSize(printer.pageLayout().paintRectPixels(printer.resolution()).size()); // This is necessary if you want to hide the page number

zernikepolar.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "zernikepolar.h"
2020
#include <cmath>
2121
#include <QDebug>
22+
#include "spdlog/spdlog.h"
2223

2324
zernikePolar::zernikePolar(double rho, double theta, size_t nbTerms) {
2425
// Having all terms computed at once here let's compiler optimize the code better
@@ -61,7 +62,7 @@ zernikePolar::zernikePolar(double rho, double theta, size_t nbTerms) {
6162

6263
// only compute what is actually needed
6364
// but to avoid complex code I use only 4 ranges
64-
if(nbTerms > 8)
65+
if(nbTerms > 9)
6566
{
6667
rho3 = rho2 * rho;
6768
rho4 = rho3 * rho;
@@ -91,7 +92,7 @@ zernikePolar::zernikePolar(double rho, double theta, size_t nbTerms) {
9192
zernTerms[24] = 1. - 20. * rho2 + 90. * rho4 - 140. * rho6 + 70. * rho8;
9293
}
9394

94-
if(nbTerms > 24) {
95+
if(nbTerms > 25) {
9596
rho10 = rho8 * rho2;
9697
cos5theta = std::cos(5. * theta);
9798
sin5theta = std::sin(5. * theta);
@@ -109,7 +110,7 @@ zernikePolar::zernikePolar(double rho, double theta, size_t nbTerms) {
109110
zernTerms[35] = -1 + 30. * rho2 -210 * rho4 + 560. * rho6 - 630 * rho8 + 252. * rho10;
110111
}
111112

112-
if(nbTerms > 35)
113+
if(nbTerms > 36)
113114
{
114115
zernTerms[36] = rho6 * std::cos(6. * theta);
115116
zernTerms[37] = rho6 * std::sin(6. * theta);
@@ -133,6 +134,7 @@ double zernikePolar::zernike(size_t n){
133134
}
134135
else
135136
{
137+
spdlog::get("logger")->critical("zernikePolar() Zernike order exceeds maximum computed.");
136138
throw std::out_of_range("Zernike order exceeds maximum computed order");
137139
return 0.;
138140
}

0 commit comments

Comments
 (0)