Skip to content

Commit d7890fd

Browse files
committed
added exclude radius and mm/inches, and knive display to percent correction graph. Compared resutls to zambuto sheet and it percent correction matches with it.
1 parent 832feb6 commit d7890fd

File tree

5 files changed

+200
-45
lines changed

5 files changed

+200
-45
lines changed

percentcorrectiondlg.cpp

Lines changed: 125 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,14 @@ percentCorrectionDlg::percentCorrectionDlg( QWidget *parent) :
3434
QSettings set;
3535
ui->minvalue->blockSignals(true);
3636
ui->maxvalue->blockSignals(true);
37+
ui->exclusionRadius->blockSignals(true);
3738
ui->minvalue->setValue(set.value("percent_correction_min",-10).toDouble());
3839
ui->maxvalue->setValue(set.value("percent_correction_max", 120).toDouble());
40+
m_exclusionRadius = set.value("correction exclusion", 19).toDouble();
41+
ui->exclusionRadius->setValue(m_exclusionRadius);
3942
ui->minvalue->blockSignals(false);
4043
ui->maxvalue->blockSignals(false);
44+
ui->exclusionRadius->blockSignals(false);
4145
ui->maxOrder->blockSignals(true);
4246
m_maxOrder = set.value("percentMaxOrder",18).toUInt();
4347
ui->maxOrder->setValue(m_maxOrder);
@@ -50,7 +54,7 @@ percentCorrectionDlg::percentCorrectionDlg( QWidget *parent) :
5054
sizes << 500 << 100;
5155
ui->splitter->setSizes(sizes);
5256
m_number_of_zones = set.value("percent number of zones", 5).toInt();
53-
57+
m_exclusionRadius = ui->exclusionRadius->value();
5458
ui->numberOfZones->blockSignals(true);
5559
ui->numberOfZones->setValue(m_number_of_zones);
5660
ui->numberOfZones->blockSignals(false);
@@ -59,6 +63,7 @@ percentCorrectionDlg::percentCorrectionDlg( QWidget *parent) :
5963
}
6064

6165
makeZones();
66+
ui->useInches->setChecked(set.value("correction useInches", true).toBool());
6267

6368

6469
}
@@ -71,7 +76,7 @@ void percentCorrectionDlg::saveSettings(){
7176
QJsonObject myJsonObject;
7277
myJsonObject["ROC"] = m_roc;
7378
myJsonObject["mirror radius"] = m_radius;
74-
79+
myJsonObject["exclusion radius"] = ui->exclusionRadius->value();
7580
QJsonArray jzones;
7681
for (const auto &item : zoneCenter) {
7782
jzones.append((double)item/m_radius); // zone centers are saved as a percentage.
@@ -91,21 +96,23 @@ void percentCorrectionDlg::saveSettings(){
9196
* allow loading and saveing of zones
9297
* allways save current accpeted zones in settings probalby in json format.
9398
*/
94-
QList<double> generateZoneCenters(double radius, int number_of_zones){
95-
double exc_pct = 100. * pow(16.75,2.)/pow(radius,2.);
99+
QList<double> percentCorrectionDlg::generateZoneCenters(double radius, int number_of_zones){
100+
double exc_pct = 100. * pow(m_exclusionRadius,2.)/pow(radius,2.);
101+
96102
QList<double> zoneCenters;
97-
QList<double> zoneedge;
103+
zoneedge.clear();
104+
zoneedge << m_exclusionRadius;
98105
// create the zones and the zone centers
99-
for (int i = 0; i < number_of_zones+1; ++i){
106+
for (int i = 1; i <= number_of_zones; ++i){
100107
zoneedge << radius * sqrt((1. -.01 * exc_pct) * i/number_of_zones + .01 * exc_pct);
101108
}
102109

103-
double lastzone = 0.;
110+
104111
for (int i = 0; i < number_of_zones; ++i){
105-
double zoneCenter = (lastzone + zoneedge[i])/2.;
106-
lastzone = zoneedge[i];
107-
zoneCenters << QString::number(zoneCenter,'f',0).toDouble();
112+
double zoneCenter = (zoneedge[i] + zoneedge[i+1])/2.;
113+
zoneCenters << QString::number(zoneCenter,'f',2).toDouble();
108114
}
115+
109116
return zoneCenters;
110117
}
111118
void percentCorrectionDlg::updateZoneTable(){
@@ -122,7 +129,11 @@ void percentCorrectionDlg::updateZoneTable(){
122129

123130
for (int i = 0; i < zoneCenter.size(); ++i) {
124131

125-
QTableWidgetItem *item = new QTableWidgetItem(QString("%1mm").arg(zoneCenter[i],0,'f',0));
132+
QTableWidgetItem *item;
133+
if (ui->useInches->isChecked())
134+
item = new QTableWidgetItem(QString("%1 inches").arg(zoneCenter[i]/25.4,0,'f',2));
135+
else
136+
item = new QTableWidgetItem(QString("%1 mm").arg(zoneCenter[i],0,'f',1));
126137
item->setTextAlignment(Qt::AlignCenter);
127138
ui->percentTable->setItem(0, i, item);
128139
item->setTextAlignment(Qt::AlignCenter);
@@ -177,26 +188,14 @@ arma::mat percentCorrectionDlg::makeZoneZerns(QList<double> centers){
177188

178189
void percentCorrectionDlg::makeZones(){
179190

180-
QSettings set;
181-
if (!set.contains("correctionZones")){
182-
generateZoneCenters(m_radius, m_number_of_zones);
183191

184-
saveSettings();
185-
}
186-
else { // read zones from settings
187-
// if mirror is different now than last then make the same number of zones but with new radius values
188-
QString jsonString = set.value("correctionZones").toString();
189-
190-
QJsonDocument doc = loadZonesFromJson(jsonString);
191-
// if number of zones has changed then generate new zones.
192-
if ((zoneCenter.size() != m_number_of_zones) || (m_radius != doc.object()["mirror radius"].toDouble())){
193-
zoneCenter = generateZoneCenters(m_radius, m_number_of_zones);
194-
saveSettings();
195-
}
192+
zoneCenter = generateZoneCenters(m_radius, m_number_of_zones);
193+
196194

197-
}
198195
updateZoneTable();
196+
199197
zoneZerns = makeZoneZerns(zoneCenter);
198+
200199
}
201200

202201
// the profile version needs the null removed and is in output lambda (usually 550);
@@ -296,6 +295,7 @@ QPolygonF percentCorrectionDlg::makePercentages(surfaceData *surf){
296295
auto knifeDeltas = [](QPolygonF &knives){
297296
double last = knives[0].y();
298297
QPolygonF deltas;
298+
299299
for (int i = 1; i < knives.length(); ++i ){
300300
deltas << QPointF( knives[i].x(),knives[i].y() - last);
301301
last = knives[i].y();
@@ -326,9 +326,9 @@ QPolygonF percentCorrectionDlg::makePercentages(surfaceData *surf){
326326
nullval *= m_lambda_nm/m_outputLambda; // only data from the profile needs the null but it's data is at the output wavelength;
327327
// process each zone center
328328

329-
QPolygonF idealknives;
329+
idealknives.clear();
330330
QPolygonF actualknives;
331-
QPolygonF zernKnives;
331+
zernKnives.clear();
332332
QPolygonF zernSurf;
333333

334334
double idealoffset = 0.;
@@ -344,6 +344,7 @@ QPolygonF percentCorrectionDlg::makePercentages(surfaceData *surf){
344344
// null from the profile thus the nullval being passed.
345345
double zernKnife = GetActualKE(m_roc, m_radius, surf->zernvalues, x, nullval ,false);
346346

347+
347348
if (zone == 0){
348349
idealoffset = idealknife;
349350
zernOffset = zernKnife;
@@ -358,13 +359,12 @@ QPolygonF percentCorrectionDlg::makePercentages(surfaceData *surf){
358359

359360
QPolygonF idealDeltas = knifeDeltas(idealknives);
360361
QPolygonF zernDeltas = knifeDeltas(zernKnives);
361-
362362
QPolygonF correction = getZoneCorrection(idealDeltas, zernDeltas);
363363

364364
return correction;
365365
}
366366

367-
367+
// no longer used but left in case it should be.
368368
void percentCorrectionDlg::plotProfile(){
369369

370370
mirrorDlg *md = mirrorDlg::get_Instance();
@@ -391,7 +391,7 @@ void percentCorrectionDlg::plotProfile(){
391391
// now plot the m_avg surface
392392
for(double r = 0; r < m_avg.length(); r += 1. ){
393393

394-
// qDebug() << "r" << r << m_avg[i];
394+
395395
double y = m_avg[r].y();//getZernSurface(m_roc, m_radius, surfs[i]->zernvalues, fabs(r), true);
396396

397397
//double sphery = m_roc - sqrt(pow(m_roc, 2.0) - pow(r, 2.0));
@@ -458,6 +458,12 @@ void percentCorrectionDlg::plot(){
458458
// make percentages
459459
QPolygonF percent = makePercentages( surfs[i]);
460460

461+
if (ui->useInches->isChecked()){
462+
for(int p = 0; p < percent.length(); ++p){
463+
percent[p].setX(percent[p].x() /25.4);
464+
}
465+
}
466+
461467
// Create 3D bar data
462468
QVector<double> row;
463469

@@ -475,20 +481,42 @@ void percentCorrectionDlg::plot(){
475481

476482
ui->percentTable->setVerticalHeaderItem(i+1, item);
477483
m_seriesName << surfs[i]->m_name;
484+
double mm = 1.;
485+
if (ui->useInches->isChecked())
486+
mm = 1./25.4;
487+
QPolygonF bars;
488+
// draw zone rectangles
489+
for(int p = 0; p < zoneedge.length();++p){
490+
QwtPlotShapeItem *rectangleItem = new QwtPlotShapeItem();
491+
double x1 = zoneedge[p] * mm;
492+
double x2;
493+
if (p+1 == zoneedge.length()){
494+
x2 = m_radius * mm;
495+
}
496+
else
497+
x2 = zoneedge[p+1] * mm;
498+
//x2 *= .9;
478499

500+
double width = x2 - x1;
501+
double border = (width - width * .95)/2;
479502

480-
QPolygonF bars;
503+
rectangleItem->setRect(QRectF(x1 + border,ui->minvalue->value(), width * .95 , ui->maxvalue->value() - ui->minvalue->value()));
481504

505+
506+
rectangleItem->setBrush(QBrush(QColor(240, 250, 250)));
507+
rectangleItem->attach(ui->plot);
508+
rectangleItem->setZ(0);
509+
}
482510
if (surfs.length() < 2) {
483-
// draw zone rectangles
511+
484512

485513
double width= 0.;
486514
for(int i = 0; i < percent.length(); ++i){
487515

488516
double y = percent[i].y();
489517

490518
if (i < percent.length()-1)
491-
width= .80 * (percent[i+1].x() - percent[i].x()) ;
519+
width= .80 * (percent[i+1].x() - percent[i].x()) ;
492520

493521
QwtPlotShapeItem *rectangleItem = new QwtPlotShapeItem();
494522

@@ -502,7 +530,7 @@ void percentCorrectionDlg::plot(){
502530
rectangleItem->setZ(0);
503531
QwtPlotMarker *label = new QwtPlotMarker();
504532
label->setLineStyle(QwtPlotMarker::NoLine);
505-
label->setLabel(QString("%1\%").arg(y, 0, 'f',1)) ;
533+
label->setLabel(QString("%1\%").arg(y, 0, 'f',2)) ;
506534
label->setValue(percent[i].x(), y-10);
507535
label->attach(ui->plot);
508536
}
@@ -514,7 +542,7 @@ void percentCorrectionDlg::plot(){
514542
if (surfs.length() == 1) {
515543
// draw markers
516544
for (int i = 0; i < zoneCenter.size(); ++i) {
517-
double center= zoneCenter[i];
545+
double center= zoneCenter[i] * mm;
518546
QwtPlotMarker *marker = new QwtPlotMarker();
519547
marker->setLineStyle(QwtPlotMarker::VLine); // Set the line style to vertical
520548
marker->setLinePen(Qt::red,2,Qt::DashLine);
@@ -524,7 +552,7 @@ void percentCorrectionDlg::plot(){
524552

525553
QwtPlotMarker *label = new QwtPlotMarker();
526554
label->setLineStyle(QwtPlotMarker::NoLine);
527-
label->setLabel(QString("%1\n%2\%").arg(center, 0, 'f',1).arg(100. * center/m_radius,0,'f',1 )) ;
555+
label->setLabel(QString("%1\n%2\%").arg(center, 0, 'f',1).arg(100. * center/(m_radius * mm),0,'f',1 )) ;
528556
label->setLabelAlignment(Qt::AlignCenter);
529557
label->setXValue(center);
530558
label->setYValue(-23);
@@ -551,10 +579,11 @@ void percentCorrectionDlg::plot(){
551579

552580
ui->plot->setAxisTitle( ui->plot->yLeft, "Percent correction" );
553581
ui->plot->setAxisScale(ui->plot->yRight, -10, 20, 1);
554-
ui->plot->setAxisTitle( ui->plot->xBottom, "Mirror Radius mm" );
582+
583+
ui->plot->setAxisTitle( ui->plot->xBottom, (ui->useInches->isChecked())? " mirror radius inches":" mirror radius mm" );
555584
slopeCurve3->setZ(1);
556585
ui->plot->setAxisScale(QwtPlot::yLeft, ui->minvalue->value(), ui->maxvalue->value());
557-
ui->plot->setAxisScale(QwtPlot::xBottom, 0, m_radius);
586+
ui->plot->setAxisScale(QwtPlot::xBottom, 0, m_radius * mm);
558587
}
559588
ui->percentTable->blockSignals(false);
560589
// Add the series to the graph
@@ -580,7 +609,7 @@ bool compare(QVector< surfaceData *> data1, QVector< surfaceData *> data2){
580609
void percentCorrectionDlg::setData( QVector< surfaceData *> data) {
581610

582611
bool different = !compare(data,surfs);
583-
qDebug() << "true if different" << different;
612+
584613
mirrorDlg &md = *mirrorDlg::get_Instance();
585614
m_roc = md.roc;
586615
m_lambda_nm = md.lambda;
@@ -660,6 +689,7 @@ void percentCorrectionDlg::on_help_clicked()
660689

661690
void percentCorrectionDlg::on_loadZones_clicked()
662691
{
692+
663693
QSettings set;
664694
QString path = set.value("projectPath").toString();
665695
QString extensionTypes(tr( "zone file (*.zones)"));
@@ -750,5 +780,59 @@ void percentCorrectionDlg::on_percentTable_itemChanged(QTableWidgetItem *item)
750780

751781

752782

783+
void percentCorrectionDlg::on_useInches_clicked(bool use)
784+
{
785+
786+
QSettings set;
787+
set.setValue("correction useInches", use);
788+
ui->exclusionRadius->blockSignals(true);
789+
ui->exclusionRadius->setValue(m_exclusionRadius/25.4);
790+
ui->exclusionRadius->blockSignals(false);
791+
makeZones();
792+
plot();
793+
}
794+
795+
796+
void percentCorrectionDlg::on_useMM_clicked(bool use)
797+
{
798+
QSettings set;
799+
800+
set.setValue("correction useInches", false);
801+
ui->exclusionRadius->blockSignals(true);
802+
ui->exclusionRadius->setValue(m_exclusionRadius);
803+
ui->exclusionRadius->blockSignals(false);
804+
makeZones();
805+
plot();
806+
}
807+
808+
809+
void percentCorrectionDlg::on_exclusionRadius_valueChanged(double arg1)
810+
{
811+
QSettings set;
812+
813+
if (ui->useInches->isChecked()){
814+
m_exclusionRadius = arg1 * 25.4;
815+
}
816+
else
817+
m_exclusionRadius = arg1;
818+
set.setValue("correction exclusion", arg1);
819+
makeZones();
820+
plot();
821+
}
822+
753823

824+
void percentCorrectionDlg::on_knives_clicked()
825+
{
826+
QString knives;
827+
double mm = 1.;
828+
if (ui->useInches->isChecked())
829+
mm /=25.4;
830+
for (int i = 0; i < idealknives.length(); ++i){
831+
QString k = QString("%1 Ideal: %2 actual: %3\n").arg(i+1).arg(idealknives[i].y() * mm ,0,'f',3).arg(zernKnives[i].y()*mm,0,'f',3);
832+
knives.append(k);
833+
}
834+
QMessageBox msg(QMessageBox::NoIcon, "Knife Posiitons", knives, QMessageBox::Ok, this);
835+
msg.setTextInteractionFlags(Qt::TextSelectableByMouse);
836+
msg.exec();
837+
}
754838

percentcorrectiondlg.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ class percentCorrectionDlg : public QDialog
3030
double m_desiredZ8;
3131
double m_lambda_nm;
3232
double m_outputLambda;
33+
double m_exclusionRadius;
3334
bool m_showZones;
3435
double m_roc;
3536
double m_roc_offset = 0.;
37+
QPolygonF idealknives;
38+
39+
QPolygonF zernKnives;
3640
arma::mat zoneZerns;
3741
QList<double> zoneCenter;
3842
QList<double> zoneedge;
@@ -76,7 +80,7 @@ class percentCorrectionDlg : public QDialog
7680
void updateZoneTable();
7781
QJsonDocument loadZonesFromJson(QString str);
7882
double GetActualKE(double RoC, double MirrorRad, std::vector<double> Zernikes, double x, double nulll, bool use_avg);
79-
83+
QList<double> generateZoneCenters(double radius, int number_of_zones);
8084
private slots:
8185
void on_percentTable_itemChanged(QTableWidgetItem *item);
8286

@@ -101,6 +105,14 @@ private slots:
101105
arma::mat makeZoneZerns(QList<double> centers);
102106

103107

108+
void on_useInches_clicked(bool checked);
109+
110+
void on_useMM_clicked(bool checked);
111+
112+
void on_exclusionRadius_valueChanged(double arg1);
113+
114+
void on_knives_clicked();
115+
104116
private:
105117
Ui::percentCorrectionDlg *ui;
106118

0 commit comments

Comments
 (0)