Commit 1a319e7f authored by Jasem Mutlaq's avatar Jasem Mutlaq
Browse files

More progress on mosaic tool...

parent a63c4ccd
......@@ -47,7 +47,7 @@ QRectF MosaicTile::boundingRect() const
return QRectF(0, 0, w*fovW, h*fovH);
}
void MosaicTile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
void MosaicTile::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
if (w == 1 && h == 1)
......@@ -100,8 +100,13 @@ void MosaicTile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
//setRotation(pa);
}
QList<OneTile *> MosaicTile::getTiles() const
{
return tiles;
}
MosaicTile::OneTile *MosaicTile::getTile(int row, int col)
OneTile *MosaicTile::getTile(int row, int col)
{
int offset = row * w + col;
if (offset < 0 || offset > tiles.size())
......@@ -200,19 +205,14 @@ Mosaic::Mosaic(Scheduler *scheduler)
pixelHSizeSpin->setValue(Options::cameraPixelHeight());
cameraWSpin->setValue(Options::cameraWidth());
cameraHSpin->setValue(Options::cameraHeight());
rotationSpin->setValue(Options::cameraRotation());
/*connect(focalLenSpin, SIGNAL(editingFinished()), this, SLOT(calculateFOV()));
connect(pixelWSizeSpin, SIGNAL(editingFinished()), this, SLOT(calculateFOV()));
connect(pixelHSizeSpin, SIGNAL(editingFinished()), this, SLOT(calculateFOV()));
connect(cameraWSpin, SIGNAL(valueChanged(int)), this, SLOT(calculateFOV()));
connect(cameraHSpin, SIGNAL(valueChanged(int)), this, SLOT(calculateFOV()));
connect(targetWFOVSpin, SIGNAL(editingFinished()), this, SLOT(drawTargetFOV()));
connect(targetHFOVSpin, SIGNAL(editingFinished()), this, SLOT(drawTargetFOV()));*/
jobsDir->setText(QDir::homePath());
connect(updateB, SIGNAL(clicked()), this, SLOT(constructMosaic()));
connect(resetB, SIGNAL(clicked()), this, SLOT(resetFOV()));
connect(createJobsB, SIGNAL(clicked()), this, SLOT(createJobs()));
connect(selectJobsDirB, SIGNAL(clicked()), this, SLOT(saveJobsDirectory()));
targetItem = scene.addPixmap(targetPix);
mosaicTile = new MosaicTile();
......@@ -231,6 +231,14 @@ Mosaic::~Mosaic()
}
void Mosaic::saveJobsDirectory()
{
QString dir = QFileDialog::getExistingDirectory(KStars::Instance(), i18n("FITS Save Directory"), jobsDir->text());
if (!dir.isEmpty())
jobsDir->setText(dir);
}
void Mosaic::setCenter(const SkyPoint &value)
{
center = value;
......@@ -269,6 +277,7 @@ void Mosaic::calculateFOV()
Options::setCameraPixelHeight(pixelHSizeSpin->value());
Options::setCameraWidth(cameraWSpin->value());
Options::setCameraHeight(cameraHSpin->value());
Options::setCameraRotation(rotationSpin->value());
// Calculate FOV in arcmins
double fov_x = 206264.8062470963552 * cameraWSpin->value() * pixelWSizeSpin->value() / 60000.0 / focalLenSpin->value();
......@@ -364,8 +373,8 @@ void Mosaic::updateTargetFOV()
targetPix = QPixmap::fromImage(*m_skyChart);
targetItem->setPixmap(targetPix);
qDebug() << "Pixmap w " << targetPix.width() << " h " << targetPix.height();
QRectF bound = (targetItem->boundingRect());
// qDebug() << "Pixmap w " << targetPix.width() << " h " << targetPix.height();
// QRectF bound = (targetItem->boundingRect());
scene.setSceneRect(targetItem->boundingRect());
// mosaicView->fitInView(targetItem, Qt::KeepAspectRatio);
// mosaicView->resize(targetItem->boundingRect().width(), targetItem->boundingRect().height());
......@@ -385,16 +394,16 @@ void Mosaic::render()
//targetPix = QPixmap::fromImage( *m_skyChart ).scaled( mosaicView->width(), mosaicView->height(), Qt::KeepAspectRatio );
//targetItem->setPixmap(targetPix);
double scale_x = (double) targetPix.width() / (double) m_skyChart->width();
double scale_y = (double) targetPix.height() / (double) m_skyChart->height();
//double scale_x = (double) targetPix.width() / (double) m_skyChart->width();
//double scale_y = (double) targetPix.height() / (double) m_skyChart->height();
// mosaicTile->moveBy(center_x, center_y);
QPointF tile1Center = mosaicTile->scenePos();
//QPointF tile1Center = mosaicTile->scenePos();
mosaicTile->setTransformOriginPoint(mosaicTile->boundingRect().center());
mosaicTile->setRotation(mosaicTile->getPA());
QPointF tile1Center2 = mosaicTile->scenePos();
//QPointF tile1Center2 = mosaicTile->scenePos();
// mosaicView->scale(scale_x, scale_y);
......@@ -412,28 +421,29 @@ void Mosaic::render()
}
void Mosaic::resizeEvent(QResizeEvent *ev)
void Mosaic::resizeEvent(QResizeEvent *)
{
QRectF bounds = scene.itemsBoundingRect();
//bounds.setWidth(bounds.width()*1.2); // to tighten-up margins
//bounds.setHeight(bounds.height()*1.2); // same as above
bounds.setWidth(bounds.width()); // to tighten-up margins
bounds.setHeight(bounds.height()); // same as above
//QRectF bounds = scene.itemsBoundingRect();
QRectF bounds = targetItem->boundingRect();
bounds.setWidth(bounds.width()*1.1);
bounds.setHeight(bounds.height()*1.1);
bounds.setWidth(bounds.width());
bounds.setHeight(bounds.height());
mosaicView->fitInView(bounds, Qt::KeepAspectRatio);
mosaicView->centerOn(0, 0);
}
void Mosaic::showEvent(QShowEvent *)
{
QRectF bounds = scene.itemsBoundingRect();
//bounds.setWidth(bounds.width()*1.2); // to tighten-up margins
//bounds.setHeight(bounds.height()*1.2); // same as above
bounds.setWidth(bounds.width()); // to tighten-up margins
bounds.setHeight(bounds.height()); // same as above
//QRectF bounds = scene.itemsBoundingRect();
QRectF bounds = targetItem->boundingRect();
bounds.setWidth(bounds.width()*1.1);
bounds.setHeight(bounds.height()*1.1);
bounds.setWidth(bounds.width());
bounds.setHeight(bounds.height());
mosaicView->fitInView(bounds, Qt::KeepAspectRatio);
mosaicView->centerOn(0, 0);
qDebug() << "Scene item bound width " << bounds.width() << " height " << bounds.height();
}
void Mosaic::resetFOV()
......@@ -444,29 +454,6 @@ void Mosaic::resetFOV()
updateTargetFOV();
}
void Mosaic::setPreset()
{
/* int scale=1;
if (scale > 1)
{
targetWFOVSpin->setValue(cameraWFOVSpin->value()*scale);
targetHFOVSpin->setValue(cameraHFOVSpin->value()*scale);
drawTargetFOV();
}*/
}
void Mosaic::createOverlay()
{
qDeleteAll(jobCenter);
}
void Mosaic::drawOverlay()
{
}
void Mosaic::constructMosaic()
{
......@@ -489,7 +476,9 @@ void Mosaic::constructMosaic()
mosaicTile->setOverlap(overlapSpin->value());
mosaicTile->updateTiles();
render();
//render();
mosaicTile->setTransformOriginPoint(mosaicTile->boundingRect().center());
mosaicTile->setRotation(mosaicTile->getPA());
}
}
......@@ -529,30 +518,28 @@ void Mosaic::createJobs()
for (int j=0; j < mosaicTile->getWidth(); j++)
{
MosaicTile::OneTile *tile = mosaicTile->getTile(i, j);
OneTile *tile = mosaicTile->getTile(i, j);
qDebug() << "Tile # " << i*mosaicTile->getWidth() + j << " X " << tile->center.x() << " Y " << tile->center.y() << endl;
qDebug() << "Scene coords" << mosaicTile->mapToScene(tile->center);
qDebug() << "Rotated coords" << tile->center_rot;
QPointF tileScreenPoint(screenPoint.x()-targetItem->boundingRect().width()/2.0 + tile->center_rot.x(), screenPoint.y()-targetItem->boundingRect().height()/2.0 + tile->center_rot.y());
SkyPoint tileSky = map->projector()->fromScreen(tileScreenPoint, KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
tile->skyCenter = map->projector()->fromScreen(tileScreenPoint, KStarsData::Instance()->lst(), KStarsData::Instance()->geo()->lat());
tile->skyCenter.apparentCoord(KStars::Instance()->data()->ut().djd(), (long double) J2000);
tile->skyCenter.setRA0(tile->skyCenter.ra());
tile->skyCenter.setDec0(tile->skyCenter.dec());
// TODO Check if J2000 are VALID. If they are use them to generate the jobs
// Add directory to save job file along with sequence files
// Add target name + part # as the prefix, and also the directory
// Find out issue between first view and then resizing later, something odd happens to display.
qDebug() << "Coords are RA " << tileSky.ra().toHMSString() << " DEC " << tileSky.dec().toDMSString();
qDebug() << "Coords are J2000 RA " << tile->skyCenter.ra0().toHMSString() << " DEC " << tile->skyCenter.dec0().toDMSString();
}
}
accept();
}
QPointF Mosaic::rotatePoint(QPointF pointToRotate, QPointF centerPoint)
......
......@@ -22,21 +22,20 @@ namespace Ekos
class Scheduler;
typedef struct
{
QPointF pos;
QPointF center;
QPointF center_rot;
SkyPoint skyCenter;
} OneTile;
class MosaicTile : public QGraphicsItem
{
public:
MosaicTile();
~MosaicTile();
struct OneTile
{
QPointF pos;
QPointF center;
QPointF center_rot;
QPointF skyCenter;
QGraphicsRectItem* rectItem;
};
void setPA(double positionAngle) { pa = positionAngle*-1; }
void setDimension(int width, int height) { w = width; h = height; }
void setFOV(double fov_x, double fov_y) { fovW = fov_x; fovH = fov_y; }
......@@ -56,9 +55,11 @@ public:
QPointF getTileCenter(int row, int col);
QList<OneTile *> getTiles() const;
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
private:
......@@ -95,32 +96,33 @@ public:
void setCameraSize(uint16_t width, uint16_t height);
void setPixelSize(double pixelWSize, double pixelHSize);
void setFocalLength(double focalLength);
void setCenter(const SkyPoint &value);
QString getJobsDir() { return jobsDir->text(); }
QList<OneTile*> getJobs() { return mosaicTile->getTiles(); }
protected:
virtual void showEvent(QShowEvent *);
virtual void resizeEvent(QResizeEvent *);
public slots:
void constructMosaic();
void calculateFOV();
void updateTargetFOV();
void drawOverlay();
void saveJobsDirectory();
void resetFOV();
void setPreset();
void createJobs();
/**
* @short Re-renders the view
*/
void render();
private:
void createOverlay();
QPointF rotatePoint(QPointF pointToRotate, QPointF centerPoint);
Scheduler *ekosScheduler;
......@@ -128,7 +130,6 @@ private:
QImage *m_skyChart;
QImage *m_skyImage;
QList<SkyPoint *> jobCenter;
QPixmap targetPix;
QGraphicsPixmapItem *targetItem;
......
......@@ -7,13 +7,13 @@
<x>0</x>
<y>0</y>
<width>728</width>
<height>403</height>
<height>478</height>
</rect>
</property>
<property name="windowTitle">
<string>Mosaic Job Creator</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10" stretch="1,10">
<item>
......@@ -232,37 +232,20 @@
<string>FOV</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="3">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="targetFOVHLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>H</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="targetHFOVSpin">
<property name="enabled">
<bool>true</bool>
</property>
<property name="maximum">
<double>3600.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="2">
<widget class="QLabel" name="overlapUnits">
<item row="0" column="0">
<widget class="QLabel" name="cameraFOVLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>%</string>
<string>Camera FOV:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Mosaic:</string>
</property>
</widget>
</item>
......@@ -279,36 +262,13 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="overlapLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Overlap:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="jobCountLabel">
<item row="0" column="4">
<widget class="QLabel" name="cameraFOVUnits">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Job Count:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="jobCountSpin">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>1</number>
<string>arcmin</string>
</property>
</widget>
</item>
......@@ -359,20 +319,10 @@
</item>
</layout>
</item>
<item row="0" column="4">
<widget class="QLabel" name="cameraFOVUnits">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>arcmin</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item row="0" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="targetFOVWLabel">
<widget class="QLabel" name="cameraWFOVLabel">
<property name="enabled">
<bool>true</bool>
</property>
......@@ -382,10 +332,13 @@
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="targetWFOVSpin">
<widget class="QDoubleSpinBox" name="cameraWFOVSpin">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="maximum">
<double>3600.000000000000000</double>
</property>
......@@ -393,47 +346,40 @@
</item>
</layout>
</item>
<item row="0" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item row="1" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="cameraWFOVLabel">
<property name="enabled">
<bool>true</bool>
</property>
<widget class="QLabel" name="label_7">
<property name="text">
<string>W</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="cameraWFOVSpin">
<property name="enabled">
<bool>true</bool>
<widget class="QSpinBox" name="mosaicWSpin">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<bool>true</bool>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<double>3600.000000000000000</double>
<number>10</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="cameraFOVLabel">
<item row="4" column="2">
<widget class="QLabel" name="overlapUnits">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Camera FOV:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Mosaic:</string>
<string>%</string>
</property>
</widget>
</item>
......@@ -464,28 +410,153 @@
</item>
</layout>
</item>
<item row="1" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item row="4" column="0">
<widget class="QLabel" name="overlapLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Overlap:</string>
</property>
</widget>
</item>
<item row="2" column="3">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label_7">
<widget class="QLabel" name="targetFOVHLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>H</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="targetHFOVSpin">
<property name="enabled">
<bool>true</bool>
</property>
<property name="maximum">
<double>3600.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="targetFOVWLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>W</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="mosaicWSpin">
<widget class="QDoubleSpinBox" name="targetWFOVSpin">
<property name="enabled">
<bool>true</bool>
</property>
<property name="maximum">
<double>3600.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Output</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<item>
<widget class="QLabel" name="jobCountLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Job Count:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="jobCountSpin">
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>