Skip to content

Commit 5d3794e

Browse files
committed
fixes a bug found related to issue246. Hopefully the only bug. It caused
crashes when using test stand astig removal tool
1 parent c6ec43f commit 5d3794e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

surfacemanager.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,13 @@ cv::Mat SurfaceManager::computeWaveFrontFromZernikes(int wx, int wy, std::vector
438438

439439
double rho;
440440

441+
int maxZernToUse = 0;
442+
for (int value : zernsToUse) {
443+
if (value > maxZernToUse)
444+
maxZernToUse = value;
445+
}
446+
447+
441448
std::vector<bool> &en = zernEnables;
442449
mirrorDlg *md = mirrorDlg::get_Instance();
443450
for (int i = 0; i < wx; ++i)
@@ -452,7 +459,7 @@ cv::Mat SurfaceManager::computeWaveFrontFromZernikes(int wx, int wy, std::vector
452459
{
453460
double S1 = 0;
454461
double theta = atan2(y1,x1);
455-
zernikePolar zpolar(rho, theta, zernsToUse.size());
462+
zernikePolar zpolar(rho, theta, maxZernToUse+1);
456463
for (int ii = 0; ii < zernsToUse.size(); ++ii) {
457464
int z = zernsToUse[ii];
458465

zernikepolar.cpp

Lines changed: 3 additions & 1 deletion
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
@@ -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 > 35) // shouldn't this be 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)