39 #include <boost/concept_check.hpp>
44 #include <QApplication>
52 #include <boost/units/systems/si/length.hpp>
53 #include <boost/units/static_constant.hpp>
54 #include <boost/units/conversion.hpp>
56 #include "ui_mainboard.h"
85 using namespace Projection;
86 using namespace boost::units;
87 using namespace boost::units::si;
109 imageLabel =
new QLabel;
110 imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
111 imageLabel->setScaledContents(
true);
117 scrollArea =
new QScrollArea;
118 scrollArea->setWidget(imageLabel);
119 setCentralWidget(scrollArea);
130 void on_actionOpen_triggered ();
133 void on_actionLoadWorldFile_triggered ();
136 void on_actionLoadReferencePoints_triggered ();
139 void on_actionLoadDataFile_triggered ();
142 void on_actionZoomIn_triggered ();
145 void on_actionZoomOut_triggered ();
148 void on_actionNormalSize_triggered ();
151 void on_actionSaveReferencePoints_triggered ();
154 void on_actionSaveReferencePointsAs_triggered ();
162 void on_actionSaveWorldFile_triggered ();
165 void on_actionSaveDataFile_triggered ();
168 void on_actionSaveDataFileAs_triggered ();
171 void on_actionGeoreferenceImage_triggered ();
174 void on_actionSetData_triggered ();
177 void on_actionSampleIsobath_triggered ();
184 virtual void mousePressEvent (QMouseEvent *event);
188 typedef std::pair<Point2D, Point2D> ReferencePointType;
191 typedef std::list<ReferencePointType> ReferencePointListType;
194 const QString done = tr(
"Done.");
197 const QString geoOk = tr(
"Image with geo-reference.");
200 const QString geoNotOk = tr(
"Image without geo-reference.");
203 const QString noFile = tr(
"No file to be opened.");
206 const QString aborted = tr(
"Operation aborted.");
209 const QString openFile = tr(
"Open file");
212 const QString textOrAny = tr(
"Text files (*.txt);;All files (*)");
215 const size_t requiredReference = 3;
218 Eigen::Matrix<double, 2, 3> change;
221 ReferencePointListType referencePointList;
230 QString worldFileName;
233 QString dataFileName;
236 QString referencePointFileName;
245 QScrollArea* scrollArea;
251 size_t numberReferencePoints;
269 void loadWorldFile (
const QString &fileName) {
271 QFile worldFile (fileName);
272 if (worldFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
274 QTextStream worldFileStream (&worldFile);
275 worldFileStream >> change(0, 0) >> change(1, 0) >> change(0, 1)
276 >> change(1, 1) >> change(0, 2) >> change(1, 2);
279 ui.statusbar->showMessage(geoOk);
280 ui.actionSaveWorldFile->setEnabled(
false);
281 ui.actionSetData->setEnabled(
true);
282 ui.actionSampleIsobath->setEnabled(
true);
285 QMessageBox::critical(
this, tr(
"Error"),
286 tr(
"World file cannot be opened."));
291 void saveDataFile () {
292 if (!dataFileName.isEmpty()) {
294 QFile dataFile (dataFileName);
295 if (dataFile.open(QIODevice::WriteOnly | QIODevice::Text |
296 QIODevice::Truncate)) {
298 QTextStream dataFileStream (&dataFile);
299 dataFileStream << data;
303 QMessageBox::critical(
this, tr(
"Error"),
304 tr(
"File named \"%1\" cannot "
305 "be opened.").arg(dataFileName));
307 ui.statusbar->showMessage(done);
310 ui.statusbar->showMessage(tr(
"No file name specified."));
315 void saveReferencePointFile () {
316 if (!referencePointFileName.isEmpty()) {
318 QFile referencePointFile (referencePointFileName);
319 if (referencePointFile.open(QIODevice::WriteOnly | QIODevice::Text
320 | QIODevice::Truncate)) {
322 QTextStream referencePointFileStream (&referencePointFile);
324 for (ReferencePointListType::iterator point =
325 referencePointList.begin();
326 point != referencePointList.end(); ++point)
327 referencePointFileStream << point->first.x() <<
' '
328 << point->first.y() <<
' '
329 << point->second.x() <<
' '
330 << point->second.y() <<
'\n';
332 referencePointFile.close();
333 ui.actionSaveReferencePoints->setEnabled(
false);
334 ui.actionSaveReferencePointsAs->setEnabled(
false);
337 QMessageBox::critical(
this, tr(
"Error"),
338 tr(
"File named \"%1\" cannot "
339 "be opened.").arg(dataFileName));
341 ui.statusbar->showMessage(done);
344 ui.statusbar->showMessage(tr(
"No file name specified"));
353 void adjustScrollBar (QScrollBar* scrollBar,
double factor) {
354 scrollBar->setValue(static_cast<int>(factor * scrollBar->value()
355 + ((factor - 1) * scrollBar->pageStep() / 2)));
359 void scaleImage (
double factor) {
360 Q_ASSERT(imageLabel->pixmap());
361 scaleFactor *= factor;
362 imageLabel->resize(scaleFactor * imageLabel->pixmap()->size());
364 adjustScrollBar(scrollArea->horizontalScrollBar(), factor);
365 adjustScrollBar(scrollArea->verticalScrollBar(), factor);
367 ui.actionZoomIn->setEnabled(scaleFactor < 3.0);
368 ui.actionZoomOut->setEnabled(scaleFactor > 0.1);
377 Point2D getMousePosition (
const QPoint &pos) {
379 const double horizontalMinimum =
380 static_cast<double>(scrollArea->horizontalScrollBar()->minimum());
382 const double horizontalMaximum =
383 static_cast<double>(scrollArea->horizontalScrollBar()->maximum());
385 const double verticalMinimum =
386 static_cast<double>(scrollArea->verticalScrollBar()->minimum());
388 const double verticalMaximum =
389 static_cast<double>(scrollArea->verticalScrollBar()->maximum());
391 const double horizontalRemaining =
392 std::max((imageLabel->pixmap()->width() * scaleFactor)
393 - imageLabel->width(), 0.);
395 const double verticalRemaining =
396 std::max((imageLabel->pixmap()->height() * scaleFactor)
397 - imageLabel->height(), 0.);
399 const double horizontalPercentage =
400 (horizontalMaximum > horizontalMinimum)?
401 (static_cast<double>(scrollArea->horizontalScrollBar()->value())
403 / (horizontalMaximum - horizontalMinimum): 0. ;
405 const double verticalPercentage =
406 (verticalMaximum > verticalMinimum)?
407 (static_cast<double>(scrollArea->verticalScrollBar()->value())
409 / (verticalMaximum - verticalMinimum): 0. ;
411 const QPoint localisation =
412 pos - imageLabel->pos() - scrollArea->pos();
415 (
static_cast<double>(localisation.x())
416 + (horizontalRemaining * horizontalPercentage))
420 (
static_cast<double>(localisation.y())
421 + (verticalRemaining * verticalPercentage))
429 #endif // #ifndef MAINBOARD_HPP
virtual ~MainBoard()
Destructor.
MainBoard()
Default constructor.
Class for program main window.
Utilities for conversion from coordinates in an image to geographical coordinates.