Skip to content

Commit

Permalink
Merge pull request #79 from gehelem/77-inspector-list-and-load-ostmed…
Browse files Browse the repository at this point in the history
…ia-fits

77 inspector list and load ostmedia fits
  • Loading branch information
gehelem authored Dec 12, 2024
2 parents 1a9038d + 55e2d69 commit 5e91626
Show file tree
Hide file tree
Showing 2 changed files with 308 additions and 70 deletions.
304 changes: 237 additions & 67 deletions src/modules/inspector/inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@ void Inspector::OnMyExternalEvent(const QString &eventType, const QString &even
getProperty("actions")->setState(OST::Ok);
}
}

}
if (keyprop == "fileselect")
{
if (keyelt == "name")
{
if (eventType == "Fposticon")
{
getProperty("actions")->setState(OST::Ok);
delete _image;
_image = new fileio();
_image->loadFits(getString("fileselect", "name"));
_image->generateQImage();
stats = _image->getStats();
emit newImage();
}
}
}
}
}
Expand Down Expand Up @@ -203,79 +220,174 @@ void Inspector::OnSucessSEP()
QImage rawImage = _image->getRawQImage();
QImage im = rawImage.convertToFormat(QImage::Format_RGB32);
im.setColorTable(rawImage.colorTable());
QImage immap = rawImage.convertToFormat(QImage::Format_RGB32);
immap.setColorTable(rawImage.colorTable());
QImage imHFR = rawImage.convertToFormat(QImage::Format_ARGB32);
//imHFR.setColorTable(rawImage.colorTable());
QImage imShape = rawImage.convertToFormat(QImage::Format_RGB32);
imShape.setColorTable(rawImage.colorTable());
int imgWidth = _image->getStats().width;
int imgHeight = _image->getStats().height;

double ech = getSampling();

//QRect r;
//r.setRect(0,0,im.width(),im.height());
/****************************************************************** HFR */
/****************************************************************** HFR */
/****************************************************************** HFR */
/****************************************************************** HFR */

/* Drw HFR ellipses around found stars */
foreach( FITSImage::Star s, _solver.stars )
/* smoothing avg 8 surround cell */
QList<float> smoothedHFR = _solver.HFRavgZone;
for (int line = 1; line < _solver.HFRZones - 1 ; line++)
{
QPainter p2;
p2.begin(&immap);
p2.setPen(QPen(Qt::green));

//qDebug() << "draw " << s.x << "/" << s.y;
int x = s.x;
int y = s.y;
int a = s.a;
int b = s.b;
float dx = 2 * s.a * cos(s.theta * 3.14159 / 360) / s.b;
float dy = 2 * s.a * sin(s.theta * 3.14159 / 360) / s.b;

//qDebug() << "draw " << x << "/" << y;
//p2.rotate(s.theta);
//p2.drawEllipse(QPoint(x / 2, y / 2), a * 5, b * 5);
p2.drawLine(x / 2 - dx, y / 2 - dy, x / 2 + dx, y / 2 + dy);
p2.end();
for (int column = 1; column < _solver.HFRZones - 1; column++)
{
int i = _solver.HFRZones * line + column;
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column - 0];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column + 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 0) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 0) + column + 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column - 0];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column + 1];
smoothedHFR[i] = smoothedHFR[i] / 9;
}
}

int imgWidth = _image->getStats().width;
int imgHeight = _image->getStats().height;
int ellipseSize = 0.20 * imgHeight / _solver.HFRZones;

/* first row */
for (int column = 1; column < _solver.HFRZones - 1; column++)
{
int line = 0;
int i = _solver.HFRZones * line + column;
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 0) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 0) + column + 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column - 0];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column + 1];
smoothedHFR[i] = smoothedHFR[i] / 6;
}
/* last row */
for (int column = 1; column < _solver.HFRZones - 1; column++)
{
int line = _solver.HFRZones - 1;
int i = _solver.HFRZones * line + column;
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column - 0];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column + 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 0) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 0) + column + 1];
smoothedHFR[i] = smoothedHFR[i] / 6;
}
/* first column */
for (int line = 1; line < _solver.HFRZones - 1 ; line++)
{
int column = 0;
int i = _solver.HFRZones * line + column;
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column - 0];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column + 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 0) + column + 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column - 0];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column + 1];
smoothedHFR[i] = smoothedHFR[i] / 6;
}
/* last column */
for (int line = 1; line < _solver.HFRZones - 1 ; line++)
{
int column = _solver.HFRZones - 1;
int i = _solver.HFRZones * line + column;
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column - 0];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 0) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column - 0];
smoothedHFR[i] = smoothedHFR[i] / 6;
}
/*corners*/
{
/* upper left */
int line = 0;
int column = 0;
int i = _solver.HFRZones * line + column;
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 0) + column + 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column + 0];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column + 1];
smoothedHFR[i] = smoothedHFR[i] / 4;
/* upper right */
line = 0;
column = _solver.HFRZones - 1;
i = _solver.HFRZones * line + column;
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 0) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column + 0];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 1) + column - 1];
smoothedHFR[i] = smoothedHFR[i] / 4;
/* lower left */
line = _solver.HFRZones - 1;
column = 0;
i = _solver.HFRZones * line + column;
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column + 0];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column + 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 0) + column + 1];
smoothedHFR[i] = smoothedHFR[i] / 4;
/* lower right */
line = _solver.HFRZones - 1;
column = _solver.HFRZones - 1;
i = _solver.HFRZones * line + column;
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column + 0];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line - 1) + column - 1];
smoothedHFR[i] = smoothedHFR[i] + _solver.HFRavgZone[_solver.HFRZones * (line + 0) + column - 1];
smoothedHFR[i] = smoothedHFR[i] / 4;
}
/* calculate min & max HFR */
float minHFR = 99;
float maxHFR = 0;
for (int i = 0; i < _solver.HFRZones * _solver.HFRZones ; i++)
{
if (smoothedHFR[i] < minHFR) minHFR = smoothedHFR[i];
if ((smoothedHFR[i] > maxHFR) && (smoothedHFR[i] < 99)) maxHFR = smoothedHFR[i];
}
/*zoning*/
QPainter p2;
p2.begin(&imHFR);
p2.setOpacity(0.5);
for (int line = 0; line < _solver.HFRZones ; line++)
{
for (int column = 0; column < _solver.HFRZones; column++)
{
int zone = _solver.HFRZones * line + column;

//qDebug() << "zones theta" << zone << _solver.thetaAvgZone[zone] << _solver.thetaDevAvgZone[zone] <<
// _solver.aAxeAvgZone[zone] <<
// _solver.bAxeAvgZone[zone] << _solver.eAxeAvgZone[zone];
int x = (imgWidth / _solver.HFRZones) * (column) ;
int y = (imgHeight / _solver.HFRZones) * (line) ;
int dx = imgWidth / _solver.HFRZones;
int dy = imgHeight / _solver.HFRZones;

qreal alpha = 1 * (smoothedHFR[zone] - minHFR) / (maxHFR - minHFR);
unsigned int r = 255 * (smoothedHFR[zone] - minHFR) / (maxHFR - minHFR);
unsigned int g = 255 * (maxHFR - smoothedHFR[zone]) / (maxHFR - minHFR);
p2.fillRect(QRect(x / 2, y / 2, dx / 2, dy / 2), qRgb(r, 0, 0));

int x = (imgWidth / _solver.HFRZones) * (column + 0.5) ;
int y = (imgHeight / _solver.HFRZones) * (line + 0.5) ;
float e = _solver.aAxeAvgZone[zone] / _solver.bAxeAvgZone[zone] - 1;
float dx = (imgWidth / _solver.HFRZones) * e * e * cos(_solver.thetaAvgZone[zone] * 3.14159 / 360);
float dy = (imgWidth / _solver.HFRZones) * e * e * sin(_solver.thetaAvgZone[zone] * 3.14159 / 360);

QPainter p2;
p2.begin(&immap);
p2.setPen(QPen(Qt::red, 20));

//qDebug() << "draw " << x << "/" << y;
//p2.rotate(_solver.thetaAvgZone[zone]);
//p2.drawEllipse(QPoint(x / 2, y / 2), a * 15, b * 15);
//p2.drawEllipse(QPoint(x / 2, y / 2), ellipseSize, ellipseSize);
p2.drawLine(x / 2 - dx, y / 2 - dy, x / 2 + dx, y / 2 + dy);
p2.end();
}
}
QPainter p;
p.begin(&immap);
p.setPen(QPen(Qt::red));
p2.end();

//p.drawLine(0, imgHeight / 6, imgWidth / 2, imgHeight / 6);
//p.drawLine(0, 2 * imgHeight / 6, imgWidth / 2, 2 * imgHeight / 6);
//p.drawLine(imgWidth / 6, 0, imgWidth / 6, imgHeight / 2);
//p.drawLine(2 * imgWidth / 6, 0, 2 * imgWidth / 6, imgHeight / 2);
/*surround stars*/
p2.begin(&imHFR);
p2.setPen(QPen(Qt::blue, 10));
foreach( FITSImage::Star s, _solver.stars )
{
QPainter p2;
int x = s.x;
int y = s.y;
int hfr = s.HFR;
p2.drawEllipse(QPoint(x / 2, y / 2), hfr, hfr);
}
p2.end();

/* determine 4 corner HFR */



/* HFR rectangle*/
QPainter p;
p.begin(&imHFR);
p.setPen(QPen(Qt::red));
int upperLeftI = 0;
int lowerLeftI = 0;
int upperRightI = 0;
Expand Down Expand Up @@ -311,26 +423,30 @@ void Inspector::OnSucessSEP()
p.setPen(QPen(Qt::white));
int mul = 200;
QVector<QPointF> hexPoints;
hexPoints << QPointF(1 * im.width() / 4 - mul*(upperLeftHFR - _solver.HFRavg*ech),
1 * im.height() / 4 - mul*(upperLeftHFR - _solver.HFRavg*ech));
hexPoints << QPointF(3 * im.width() / 4 + mul*(upperRightHFR - _solver.HFRavg*ech),
1 * im.height() / 4 - mul*(upperRightHFR - _solver.HFRavg*ech));
hexPoints << QPointF(3 * im.width() / 4 - mul*(lowerRightHFR - _solver.HFRavg*ech),
3 * im.height() / 4 + mul*(lowerRightHFR - _solver.HFRavg*ech));
hexPoints << QPointF(1 * im.width() / 4 + mul*(lowerLeftHFR - _solver.HFRavg*ech),
3 * im.height() / 4 + mul*(lowerLeftHFR - _solver.HFRavg*ech));
hexPoints << QPointF(1 * im.width() / 4 - mul * (upperLeftHFR - _solver.HFRavg * ech),
1 * im.height() / 4 - mul * (upperLeftHFR - _solver.HFRavg * ech));
hexPoints << QPointF(3 * im.width() / 4 + mul * (upperRightHFR - _solver.HFRavg * ech),
1 * im.height() / 4 - mul * (upperRightHFR - _solver.HFRavg * ech));
hexPoints << QPointF(3 * im.width() / 4 - mul * (lowerRightHFR - _solver.HFRavg * ech),
3 * im.height() / 4 + mul * (lowerRightHFR - _solver.HFRavg * ech));
hexPoints << QPointF(1 * im.width() / 4 + mul * (lowerLeftHFR - _solver.HFRavg * ech),
3 * im.height() / 4 + mul * (lowerLeftHFR - _solver.HFRavg * ech));
p.drawPolygon(hexPoints);
p.setFont(QFont("Courrier", im.width() / 50, QFont::Normal));
p.drawText( QRect(0, 0, im.width(), im.height()), Qt::AlignCenter, QString::number(_solver.HFRavg*ech, 'f', 3) + "''");
p.drawText( QRect(0, 0, im.width(), im.height()), Qt::AlignCenter, QString::number(_solver.HFRavg * ech, 'f', 3) + "''");
p.drawText(1 * im.width() / 4, 1 * im.height() / 4, QString::number(upperLeftHFR, 'f', 3) + "''");
p.drawText(3 * im.width() / 4, 1 * im.height() / 4, QString::number(upperRightHFR, 'f', 3) + "''");
p.drawText(1 * im.width() / 4, 3 * im.height() / 4, QString::number(lowerLeftHFR, 'f', 3) + "''");
p.drawText(3 * im.width() / 4, 3 * im.height() / 4, QString::number(lowerRightHFR, 'f', 3) + "''");

p.end();

imHFR.save(getWebroot() + "/" + getModuleName() + "HFR.jpeg", "JPG", 100);

immap.save(getWebroot() + "/" + getModuleName() + "map.jpeg", "JPG", 100);
/****************************************************************** corners */
/****************************************************************** corners */
/****************************************************************** corners */
/****************************************************************** corners */

int s = getInt("parms", "cornersize");
int h = rawImage.height();
Expand Down Expand Up @@ -359,19 +475,73 @@ void Inspector::OnSucessSEP()
painter.drawRect(QRect(0, 0, 3 * s - 1, 3 * s - 1));

painter.end();

corners.save(getWebroot() + "/" + getModuleName() + "corners.jpeg", "JPG", 100);

im.save(getWebroot() + "/" + getModuleName() + ".jpeg", "JPG", 100);

/****************************************************************** aberations */
/****************************************************************** aberations */
/****************************************************************** aberations */
/****************************************************************** aberations */

int ellipseSize = 0.20 * imgHeight / _solver.HFRZones;

/* min and max aberations */
float eMin = 99;
float eMax = 0;
for (int line = 0; line < _solver.HFRZones ; line++)
{
for (int column = 0; column < _solver.HFRZones; column++)
{
int zone = _solver.HFRZones * line + column;
float e = _solver.aAxeAvgZone[zone] / _solver.bAxeAvgZone[zone] - 1;
if (e < eMin) eMin = e;
if (e > eMax) eMax = e;
}
}

/* draw aberations */
p2.begin(&imShape);
p2.setOpacity(0.5);
p2.setPen(QPen(Qt::red, 10));
for (int line = 0; line < _solver.HFRZones ; line++)
{
for (int column = 0; column < _solver.HFRZones; column++)
{
int zone = _solver.HFRZones * line + column;

int x = (imgWidth / _solver.HFRZones) * (column + 0.5) ;
int y = (imgHeight / _solver.HFRZones) * (line + 0.5) ;
float e = _solver.aAxeAvgZone[zone] / _solver.bAxeAvgZone[zone] - 1;
float dx = (0.5 * imgWidth / _solver.HFRZones) * ((e - eMin) / (eMax - eMin)) * cos(_solver.thetaAvgZone[zone] * 3.14159 /
360);
float dy = (0.5 * imgWidth / _solver.HFRZones) * ((e - eMin) / (eMax - eMin)) * sin(_solver.thetaAvgZone[zone] * 3.14159 /
360);

p2.drawLine(x / 2 - dx, y / 2 - dy, x / 2 + dx, y / 2 + dy);
}
}
p2.end();
imShape.save(getWebroot() + "/" + getModuleName() + "shape.jpeg", "JPG", 100);


OST::ImgData dta = _image->ImgStats();
dta.mUrlJpeg = getModuleName() + ".jpeg";
dta.HFRavg = ech * _solver.HFRavg;
dta.starsCount = _solver.stars.size();
dta.mAlternates.clear();
dta.mAlternates.push_front(getModuleName() + "corners.jpeg");
dta.mAlternates.push_front(getModuleName() + "map.jpeg");
dta.mAlternates.push_front(getModuleName() + "HFR.jpeg");
dta.mAlternates.push_front(getModuleName() + "shape.jpeg");
getEltImg("image", "image")->setValue(dta, true);

dta = _image->ImgStats();
dta.mUrlJpeg = getModuleName() + "corners.jpeg";
getEltImg("corners", "image")->setValue(dta, true);
dta.mUrlJpeg = getModuleName() + "HFR.jpeg";
getEltImg("hfr", "image")->setValue(dta, true);
dta.mUrlJpeg = getModuleName() + "shape.jpeg";
getEltImg("shape", "image")->setValue(dta, true);



emit FindStarsDone();
Expand Down
Loading

0 comments on commit 5e91626

Please sign in to comment.