TiePointLocatorWidget.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/rp/TiePointLocatorWidget.cpp
22 
23  \brief This file has the TiePointLocatorWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../common/STLUtils.h"
28 #include "../../../common/StringUtils.h"
29 #include "../../../dataaccess/dataset/DataSet.h"
30 #include "../../../dataaccess/utils/Utils.h"
31 #include "../../../geometry/Coord2D.h"
32 #include "../../../geometry/GTFactory.h"
33 #include "../../../maptools/MarkRendererManager.h"
34 #include "../../../geometry/Point.h"
35 #include "../../../raster/Interpolator.h"
36 #include "../../../raster/Grid.h"
37 #include "../../../raster/Raster.h"
38 #include "../../../rp/Functions.h"
39 #include "../../../se/Fill.h"
40 #include "../../../se/Mark.h"
41 #include "../../../se/Stroke.h"
42 #include "../../../se/Utils.h"
43 #include "../../../srs/Converter.h"
44 #include "../../widgets/canvas/Canvas.h"
45 #include "../../widgets/canvas/MapDisplay.h"
46 #include "../../widgets/srs/SRSManagerDialog.h"
47 #include "../../widgets/Utils.h"
48 #include "RasterNavigatorWidget.h"
49 #include "TiePointLocatorWidget.h"
51 #include "ui_RasterNavigatorWidgetForm.h"
52 #include "ui_TiePointLocatorWidgetForm.h"
53 #include "ui_TiePointLocatorParametersWidgetForm.h"
54 
55 // Qt
56 #include <QGridLayout>
57 #include <QMessageBox>
58 #include <QPixmap>
59 #include <QFileDialog>
60 #include <QString>
61 
62 // Boost
63 #include <boost/filesystem.hpp>
64 
65 // STL
66 #include <memory>
67 #include <fstream>
68 
69 #define PATTERN_SIZE 12
70 
71 /* TiePointData Class*/
72 
74  m_acqType(InvalidAcquisitionT),
75  m_selected(false)
76 {
77 
78 }
79 
81 {
82  operator=( other );
83 }
84 
86 
88 {
89  m_acqType = other.m_acqType;
90  m_tiePoint = other.m_tiePoint;
91  m_selected = other.m_selected;
92  return other;
93 }
94 
95 /* TiePointLocatorWidget Class*/
96 
98  : QWidget(parent, f),
99  m_ui(new Ui::TiePointLocatorWidgetForm),
100  m_tiePointFirstCoord(None),
101  m_tiePointIdCounter(0)
102 {
103  m_ui->setupUi(this);
104 
105  m_ui->m_x1LineEdit->setValidator(new QDoubleValidator(this));
106  m_ui->m_y1LineEdit->setValidator(new QDoubleValidator(this));
107  m_ui->m_x2LineEdit->setValidator(new QDoubleValidator(this));
108  m_ui->m_y2LineEdit->setValidator(new QDoubleValidator(this));
109 
110  m_ui->m_outResXLineEdit->setValidator(new QDoubleValidator(this));
111  m_ui->m_outResYLineEdit->setValidator(new QDoubleValidator(this));
112 
113  m_ui->m_selectAllToolButton->setIcon(QIcon::fromTheme("table-select"));
114  m_ui->m_unselectAllToolButton->setIcon(QIcon::fromTheme("table-unselect"));
115  m_ui->m_deleteSelectedToolButton->setIcon(QIcon::fromTheme("table-delete-select"));
116  m_ui->m_autoAcquireTiePointsToolButton->setIcon(QIcon::fromTheme("wand"));
117  m_ui->m_addToolButton->setIcon(QIcon::fromTheme("list-add"));
118  m_ui->m_refreshToolButton->setIcon(QIcon::fromTheme("view-refresh"));
119  m_ui->m_doneToolButton->setIcon(QIcon::fromTheme("check"));
120  m_ui->m_loadTiePointsToolButton_->setIcon(QIcon::fromTheme("folder-open"));
121  m_ui->m_saveTiePointsToolButton_->setIcon(QIcon::fromTheme("document-save"));
122 
123  //add tie point parameters widget
125  m_ui->m_tabWidget->addTab(m_tiePointParameters, tr("Options"));
126 
127  //connects
128  connect(m_ui->m_autoAcquireTiePointsToolButton, SIGNAL(clicked()), this, SLOT(onAutoAcquireTiePointsToolButtonClicked()));
129  connect(m_ui->m_selectAllToolButton, SIGNAL(clicked()), this, SLOT(onSelectAllToolButtonClicked()));
130  connect(m_ui->m_unselectAllToolButton, SIGNAL(clicked()), this, SLOT(onUnselectAllToolButtonClicked()));
131  connect(m_ui->m_deleteSelectedToolButton, SIGNAL(clicked()), this, SLOT(onDeleteSelectedToolButtonClicked()));
132  connect(m_ui->m_addToolButton, SIGNAL(clicked()), this, SLOT(onAddToolButtonClicked()));
133  connect(m_ui->m_refreshToolButton, SIGNAL(clicked()), this, SLOT(onRefreshToolButtonClicked()));
134  connect(m_ui->m_doneToolButton, SIGNAL(clicked()), this, SLOT(onDoneToolButtonClicked()));
135  connect(m_ui->m_tiePointsTableWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onTiePointsTableWidgetItemSelectionChanged()));
136  connect(m_ui->m_tiePointsTableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), SLOT(onTiePointsTableWidgetItemChanged(QTableWidgetItem*)));
137  connect(m_ui->m_sridPushButton, SIGNAL(clicked()), this, SLOT(onSRIDPushButtonClicked()));
138  connect(m_ui->m_loadTiePointsToolButton_, SIGNAL(clicked()), this, SLOT(onLoadTiePointsToolButtonClicked()));
139  connect(m_ui->m_saveTiePointsToolButton_, SIGNAL(clicked()), this, SLOT(onSaveTiePointsToolButtonClicked()));
140 
141  connect(m_tiePointParameters->getWidgetForm()->m_geomTransfNameComboBox, SIGNAL(activated(int)), this, SLOT(onRefreshToolButtonClicked()));
142 
143 
144 // connects
145  connect(this, SIGNAL(tiePointsUpdated()), this, SLOT(onTiePointsUpdated()));
146 
147 //define mark selected
148  te::se::Stroke* strokeSel = te::se::CreateStroke("#000000", "1");
149  te::se::Fill* fillSel = te::se::CreateFill("#FF0000", "1.0");
150  m_markSelected = te::se::CreateMark("cross", strokeSel, fillSel);
151 
153 
154  QPixmap markSelPix = getPixmap(m_rgbaMarkSelected);
155  setSelectedTiePointMarkLegend(markSelPix);
156 
157 //define mark unselected
158  te::se::Stroke* strokeUnsel = te::se::CreateStroke("#000000", "1");
159  te::se::Fill* fillUnsel = te::se::CreateFill("#00FF00", "1.0");
160  m_markUnselected = te::se::CreateMark("cross", strokeUnsel, fillUnsel);
161 
163 
164  QPixmap markPix = getPixmap(m_rgbaMarkUnselected);
165  setTiePointMarkLegend(markPix);
166 
167 //define mark reference
168  te::se::Stroke* strokeRef = te::se::CreateStroke("#000000", "1");
169  te::se::Fill* fillRef = te::se::CreateFill("#FFFFFF", "1.0");
170  m_markRef = te::se::CreateMark("cross", strokeRef, fillRef);
171 
173 
174  QPixmap markRefPix = getPixmap(m_rgbaMarkRef);
175  setReferenceTiePointMarkLegend(markRefPix);
176 
178 }
179 
181 {
183  delete m_markSelected;
184 
186  delete m_markUnselected;
187 
189  delete m_markRef;
190 }
191 
192 Ui::TiePointLocatorWidgetForm* te::qt::widgets::TiePointLocatorWidget::getForm() const
193 {
194  return m_ui.get();
195 }
196 
197 void te::qt::widgets::TiePointLocatorWidget::getTiePoints( std::vector< te::gm::GTParameters::TiePoint >& tiePoints ) const
198 {
199  tiePoints.clear();
200 
201  te::qt::widgets::TiePointData::TPContainerT::const_iterator itB = m_tiePoints.begin();
202 
203  const te::qt::widgets::TiePointData::TPContainerT::const_iterator itE = m_tiePoints.end();
204 
205  tiePoints.reserve( m_tiePoints.size() );
206 
207  if (!m_refLayer.get())
208  {
209  while (itB != itE)
210  {
212  tp.first = itB->second.m_tiePoint.second;
213  tp.second = itB->second.m_tiePoint.first;
214  tiePoints.push_back(tp);
215  ++itB;
216  }
217  return;
218  }
219 
220  std::unique_ptr<te::da::DataSet> ds(m_refLayer->getData());
221  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
222  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
223 
224  // create a SRS converter
225  std::unique_ptr<te::srs::Converter> converter(new te::srs::Converter());
226  converter->setSourceSRID(m_refLayer->getSRID());
227  converter->setTargetSRID(m_ui->m_outSridLineEdit->text().toInt());
228 
229  while( itB != itE )
230  {
232 
233  tp.first = itB->second.m_tiePoint.second;
234 
235  te::gm::Coord2D c = inputRst->getGrid()->gridToGeo(itB->second.m_tiePoint.first.x, itB->second.m_tiePoint.first.y);
236 
237  converter->convert(c.x, c.y, c.x, c.y);
238 
239  tp.second = c;
240 
241  tiePoints.push_back(tp);
242  ++itB;
243  }
244 }
245 
246 void te::qt::widgets::TiePointLocatorWidget::getTiePointsIdxCoords( std::vector< te::gm::GTParameters::TiePoint >& tiePoints ) const
247 {
248  tiePoints.clear();
249 
250  std::unique_ptr<te::da::DataSet> ds(m_refLayer->getData());
251  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
252  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
253 
254  te::qt::widgets::TiePointData::TPContainerT::const_iterator itB = m_tiePoints.begin();
255 
256  const te::qt::widgets::TiePointData::TPContainerT::const_iterator itE = m_tiePoints.end();
257 
258  tiePoints.reserve( m_tiePoints.size() );
259 
260  while( itB != itE )
261  {
262  te::gm::GTParameters::TiePoint tp = itB->second.m_tiePoint;
263 
264  tiePoints.push_back(tp);
265 
266  ++itB;
267  }
268 }
269 
271 {
272  return m_tiePoints;
273 }
274 
276 {
278  firstCoord = m_currentTiePoint.first;
279  else if (m_tiePointFirstCoord == Adjust)
280  firstCoord = m_currentTiePoint.second;
281 
282  return m_tiePointFirstCoord;
283 }
284 
286 {
287  reset();
288  m_refLayer = layer;
289 
290  if (!layer)
291  {
292  m_refNavigator->hide();
293  m_ui->m_referenceGroupBox->setMaximumSize(0,0);
294  m_ui->m_autoAcquireTiePointsToolButton->hide();
295  m_ui->m_referenceBandComboBox->hide();
296  m_ui->m_referenceBandLabel->hide();
297  m_ui->m_referenceGroupBox_2->hide();
298  m_ui->m_tiePointsTableWidget->setHorizontalHeaderItem(3, new QTableWidgetItem("X"));
299  m_ui->m_tiePointsTableWidget->setHorizontalHeaderItem(4, new QTableWidgetItem("Y"));
300  m_ui->m_tiePointsTableWidget->setHorizontalHeaderItem(5, new QTableWidgetItem(tr("Column")));
301  m_ui->m_tiePointsTableWidget->setHorizontalHeaderItem(6, new QTableWidgetItem(tr("Line")));
302  m_ui->m_x1Label->setText("X");
303  m_ui->m_y1Label->setText("Y");
304  m_ui->m_x2Label->setText(tr("Column"));
305  m_ui->m_y2Label->setText(tr("Line"));
307  return;
308  }
309 
310  m_ui->m_tiePointsTableWidget->setHorizontalHeaderItem(3, new QTableWidgetItem("X1"));
311  m_ui->m_tiePointsTableWidget->setHorizontalHeaderItem(4, new QTableWidgetItem("Y1"));
312  m_ui->m_tiePointsTableWidget->setHorizontalHeaderItem(5, new QTableWidgetItem("X2"));
313  m_ui->m_tiePointsTableWidget->setHorizontalHeaderItem(6, new QTableWidgetItem("Y2"));
314  m_ui->m_x1Label->setText("X1");
315  m_ui->m_y1Label->setText("Y1");
316  m_ui->m_x2Label->setText("X2");
317  m_ui->m_y2Label->setText("Y2");
318 
319  m_ui->m_referenceGroupBox->setMaximumSize(16777215, 16777215);
320  m_ui->m_autoAcquireTiePointsToolButton->show();
321  m_ui->m_referenceBandComboBox->show();
322  m_ui->m_referenceBandLabel->show();
323  m_ui->m_referenceGroupBox_2->show();
324  m_refNavigator->show();
325 
327 
328  m_refNavigator->set(layer);
329 
330  //list bands
331  std::unique_ptr<te::da::DataSet> ds = m_refLayer->getData();
332 
333  if(ds.get())
334  {
335  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
336  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
337 
338  m_ui->m_referenceGroupBox->setTitle( tr( "Reference - ") + " " + m_refLayer->getTitle().c_str() );
339 
340  if(inputRst.get())
341  {
342  m_ui->m_referenceBandComboBox->clear();
343 
344  for(unsigned band1Idx = 0; band1Idx < inputRst->getNumberOfBands(); ++band1Idx)
345  m_ui->m_referenceBandComboBox->addItem(QString::number(band1Idx));
346 
347 
348  QString strSRID;
349  strSRID.setNum(m_refLayer->getSRID());
350  m_ui->m_referenceSRIDLineEdit->setText(strSRID);
351 
352  QString strResX;
353  strResX.setNum(inputRst->getGrid()->getResolutionX(), 'f');
354  m_ui->m_referenceResXLineEdit->setText(strResX);
355 
356  QString strResY;
357  strResY.setNum(inputRst->getGrid()->getResolutionY(), 'f');
358  m_ui->m_referenceResYLineEdit->setText(strResY);
359  }
360 
361  if(m_adjLayer.get())
362  {
363  std::unique_ptr<te::da::DataSet> dsAdj = m_adjLayer->getData();
364 
365  if(dsAdj.get())
366  {
368  std::unique_ptr<te::rst::Raster> inputRstAdj = dsAdj->getRaster(rpos);
369 
370  if(inputRstAdj.get())
371  {
372  double maxSize1 = std::max(inputRst->getNumberOfColumns(), inputRstAdj->getNumberOfColumns());
373  double maxSize2 = std::max(inputRst->getNumberOfRows(), inputRstAdj->getNumberOfRows());
374  double maxSize = std::max(maxSize1, maxSize2);
375 
376  if(maxSize > 1000)
377  {
378  double rescaleFactor = 1000. / maxSize;
379  m_tiePointParameters->setRescaleFactor(rescaleFactor);
380  }
381  }
382  }
383  }
384  }
385 }
386 
388 {
389  reset();
390 
391  m_adjLayer = layer;
392 
393  m_adjNavigator->set(layer);
394 
395  //list bands
396  std::unique_ptr<te::da::DataSet> ds = m_adjLayer->getData();
397 
398  if(ds.get())
399  {
400  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
401  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
402 
403  m_ui->m_adjustGroupBox->setTitle( tr( "Adjust - ") + " " + m_adjLayer->getTitle().c_str() );
404 
405  if(inputRst.get())
406  {
407  m_ui->m_adjBandComboBox->clear();
408 
409  for(unsigned band2Idx = 0; band2Idx < inputRst->getNumberOfBands(); ++band2Idx)
410  m_ui->m_adjBandComboBox->addItem(QString::number(band2Idx));
411 
412  QString strSRID;
413  strSRID.setNum(m_adjLayer->getSRID());
414  m_ui->m_adjustSRIDLineEdit->setText(strSRID);
415  m_ui->m_outSridLineEdit->setText(strSRID);
416 
417  QString strResX;
418  strResX.setNum(inputRst->getGrid()->getResolutionX(), 'f');
419  m_ui->m_adjustResXLineEdit->setText(strResX);
420  m_ui->m_outResXLineEdit->setText(strResX);
421 
422  QString strResY;
423  strResY.setNum(inputRst->getGrid()->getResolutionY(), 'f');
424  m_ui->m_adjustResYLineEdit->setText(strResY);
425  m_ui->m_outResYLineEdit->setText(strResY);
426  }
427 
428  if(m_refLayer.get())
429  {
430  std::unique_ptr<te::da::DataSet> dsRef = m_refLayer->getData();
431 
432  if(dsRef.get())
433  {
435  std::unique_ptr<te::rst::Raster> inputRstRef = dsRef->getRaster(rpos);
436 
437  if(inputRstRef.get())
438  {
439  double maxSize1 = std::max(inputRst->getNumberOfColumns(), inputRstRef->getNumberOfColumns());
440  double maxSize2 = std::max(inputRst->getNumberOfRows(), inputRstRef->getNumberOfRows());
441  double maxSize = std::max(maxSize1, maxSize2);
442 
443  if(maxSize > 1000)
444  {
445  double rescaleFactor = 1000. / maxSize;
446  m_tiePointParameters->setRescaleFactor(rescaleFactor);
447  }
448  }
449  }
450  }
451  }
452 }
453 
455 {
456  srid = m_ui->m_outSridLineEdit->text().toInt();
457 }
458 
460 {
461  resX = m_ui->m_outResXLineEdit->text().toDouble();
462  resY = m_ui->m_outResYLineEdit->text().toDouble();
463 }
464 
466 {
468 }
469 
471 {
472  if( m_tiePointParameters->getWidgetForm()->m_interpMethodComboBox->currentText()
473  == "NearestNeighbor" )
474  {
476  }
477  else if( m_tiePointParameters->getWidgetForm()->m_interpMethodComboBox->currentText()
478  == "Bilinear" )
479  {
480  return te::rst::Bilinear;
481  }
482  else // Bicubic
483  {
484  return te::rst::Bicubic;
485  }
486 }
487 
489 {
490  assert(m_refLayer.get());
491 
492  //get input raster
493  std::unique_ptr<te::da::DataSet> ds = m_refLayer->getData();
494 
495  if(ds.get())
496  {
497  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
498  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
499 
500  if(inputRst.get())
501  {
502  m_currentTiePoint.first = inputRst->getGrid()->geoToGrid(x, y);
503 
504  m_refPoints[m_tiePointIdCounter] = QPointF(x, y);
505 
507  {
508  if (!shotSecondtPoint())
509  {
511  return;
512  }
513  }
514 
516  //add tie point
517  TiePointData tpD;
520 
522 
524 
525  }
526  }
527 }
528 
530 {
531  // building the geometric transformation
532  te::gm::GTParameters transParams;
533 
534  te::qt::widgets::TiePointData::TPContainerT::const_iterator tPIt = m_tiePoints.begin();
535  const te::qt::widgets::TiePointData::TPContainerT::const_iterator tPItEnd = m_tiePoints.end();
536 
537  while (tPIt != tPItEnd)
538  {
539  transParams.m_tiePoints.push_back(tPIt->second.m_tiePoint);
540  ++tPIt;
541  }
542 
543  std::string geoTransfName = m_tiePointParameters->getTransformationName();
544 
545  std::unique_ptr<te::gm::GeometricTransformation> transfPtr(te::gm::GTFactory::make(geoTransfName));
546 
547  if (!transfPtr.get())
548  return false;
549 
550  if (!transfPtr->initialize(transParams))
551  {
552  transfPtr.reset();
553  return false;
554  }
555 
556  te::gm::Coord2D newpt;
557  transfPtr->directMap(transfPtr->getParameters(), m_currentTiePoint.first, newpt);
558 
560 
561  m_currentTiePoint.second = newpt;
562 
563  //get input raster
564  std::unique_ptr<te::da::DataSet> ds = m_adjLayer->getData();
565 
566  if (ds.get())
567  {
568  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
569  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
570 
571  if (inputRst.get())
572  {
573  te::gm::Coord2D adjpt = inputRst->getGrid()->gridToGeo(newpt.getX(), newpt.getY());
574  m_adjPoints[m_tiePointIdCounter] = QPointF(adjpt.getX(), adjpt.getY());
575  }
576  }
577  transfPtr.reset();
578  return true;
579 }
580 
582 {
583  assert(m_adjLayer.get());
584 
585  //get input raster
586  std::unique_ptr<te::da::DataSet> ds = m_adjLayer->getData();
587 
588  if(ds.get())
589  {
590  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
591  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
592 
593  if(inputRst.get())
594  {
595  m_currentTiePoint.second = inputRst->getGrid()->geoToGrid(x, y);
596 
597  m_adjPoints[m_tiePointIdCounter] = QPointF(x, y);
598 
599  if (m_refLayer.get())
600  {
602  {
603  if (!shotFirstPoint())
604  {
606  return;
607  }
608  }
609  }
610  else
611  shotFirstPoint();
612 
614  //add tie point
615  TiePointData tpD;
618 
620 
622  }
623  }
624 }
625 
627 {
628  // building the geometric transformation
629  te::gm::GTParameters transParams;
630 
631  te::qt::widgets::TiePointData::TPContainerT::const_iterator tPIt = m_tiePoints.begin();
632  const te::qt::widgets::TiePointData::TPContainerT::const_iterator tPItEnd = m_tiePoints.end();
633 
634  while (tPIt != tPItEnd)
635  {
636  transParams.m_tiePoints.push_back(tPIt->second.m_tiePoint);
637  ++tPIt;
638  }
639 
640  std::string geoTransfName = m_tiePointParameters->getTransformationName();
641 
642  std::unique_ptr<te::gm::GeometricTransformation> transfPtr(te::gm::GTFactory::make(geoTransfName));
643 
644  if (!transfPtr.get())
645  return false;
646 
647  if (!transfPtr->initialize(transParams))
648  {
649  transfPtr.reset();
650  return false;
651  }
652  te::gm::Coord2D newpt;
653  transfPtr->inverseMap(transfPtr->getParameters(), m_currentTiePoint.second, newpt);
654 
655  m_currentTiePoint.first = newpt;
656 
657  //get input raster
658  if (m_refLayer.get())
659  {
660  std::unique_ptr<te::da::DataSet> ds = m_refLayer->getData();
661 
662  if (ds.get())
663  {
664  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
665  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
666 
667  if (inputRst.get())
668  {
669  te::gm::Coord2D refpt = inputRst->getGrid()->gridToGeo(newpt.getX(), newpt.getY());
670  m_refPoints[m_tiePointIdCounter] = QPointF(refpt.getX(), refpt.getY());
671  }
672  }
673  }
674  transfPtr.reset();
675  return true;
676 }
677 
678 void te::qt::widgets::TiePointLocatorWidget::refCoordMoved(double xorig, double yorig, double xnew, double ynew)
679 {
680  assert(m_refLayer.get());
681 
682  //get input raster
683  std::unique_ptr<te::da::DataSet> ds = m_refLayer->getData();
684 
685  if (ds.get())
686  {
687  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
688  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
689 
690  if (inputRst.get())
691  {
692  te::gm::Coord2D orig = inputRst->getGrid()->geoToGrid(xorig, yorig);
693 
694  te::qt::widgets::TiePointData::TPContainerT::iterator tPIt = m_tiePoints.begin();
695  const te::qt::widgets::TiePointData::TPContainerT::iterator tPItEnd = m_tiePoints.end();
696 
697  while (tPIt != tPItEnd)
698  {
699  if ((int)(tPIt->second.m_tiePoint.first.x) == (int)orig.x &&
700  (int)(tPIt->second.m_tiePoint.first.y) == (int)orig.y)
701  {
702  tPIt->second.m_tiePoint.first = inputRst->getGrid()->geoToGrid(xnew, ynew);
703  break;
704  }
705  ++tPIt;
706  }
708  }
709  }
710  }
711 
712 void te::qt::widgets::TiePointLocatorWidget::adjCoordMoved(double xorig, double yorig, double xnew, double ynew)
713 {
714  assert(m_adjLayer.get());
715 
716  //get input raster
717  std::unique_ptr<te::da::DataSet> ds = m_adjLayer->getData();
718 
719  if (ds.get())
720  {
721  std::size_t rpos = te::da::GetFirstPropertyPos(ds.get(), te::dt::RASTER_TYPE);
722  std::unique_ptr<te::rst::Raster> inputRst = ds->getRaster(rpos);
723  if (inputRst.get())
724  {
725  te::gm::Coord2D orig = inputRst->getGrid()->geoToGrid(xorig, yorig);
726 
727  te::qt::widgets::TiePointData::TPContainerT::iterator tPIt = m_tiePoints.begin();
728  const te::qt::widgets::TiePointData::TPContainerT::iterator tPItEnd = m_tiePoints.end();
729 
730  while (tPIt != tPItEnd)
731  {
732  if ((int)(tPIt->second.m_tiePoint.second.x) == (int)orig.x &&
733  (int)(tPIt->second.m_tiePoint.second.y) == (int)orig.y)
734  {
735  tPIt->second.m_tiePoint.second = inputRst->getGrid()->geoToGrid(xnew, ynew);
736  break;
737  }
738  ++tPIt;
739  }
741  }
742  }
743 }
744 
746 {
747  m_ui->m_tiePointLabel->setPixmap(p);
748 }
749 
751 {
752  m_ui->m_selectedTiePointLabel->setPixmap(p);
753 }
754 
756 {
757  m_ui->m_refTiePointLabel->setPixmap(p);
758 }
759 
761 {
762  m_ui->m_tiePointsTableWidget->clearSelection();
763 
764  QModelIndex idxStart = m_ui->m_tiePointsTableWidget->model()->index(initialIdx, 0);
765  QModelIndex idxEnd = m_ui->m_tiePointsTableWidget->model()->index(initialIdx + nPos - 1, 6);
766 
767  if(idxStart.isValid() && idxEnd.isValid())
768  {
769  QItemSelection itemSel(idxStart, idxEnd);
770 
771  m_ui->m_tiePointsTableWidget->selectionModel()->select(itemSel, QItemSelectionModel::Select);
772  }
773 }
774 
776 {
777  //check parameters
778  if(m_ui->m_outSridLineEdit->text().isEmpty())
779  {
780  QMessageBox::warning(this, tr("Warning"), tr("Output SRID not defined."));
781  return;
782  }
783 
784  if(m_ui->m_outResXLineEdit->text().isEmpty() || m_ui->m_outResYLineEdit->text().isEmpty())
785  {
786  QMessageBox::warning(this, tr("Warning"), tr("Output resolution not defined."));
787  return;
788  }
789 
790  if(
791  ( m_ui->m_adjustResXLineEdit->text().toDouble() <= 0.0 )
792  ||
793  ( m_ui->m_adjustResYLineEdit->text().toDouble() <= 0.0 )
794  ||
795  ( m_ui->m_referenceResXLineEdit->text().toDouble() <= 0.0 )
796  ||
797  ( m_ui->m_referenceResYLineEdit->text().toDouble() <= 0.0 )
798  ||
799  ( m_ui->m_outResXLineEdit->text().toDouble() <= 0.0 )
800  ||
801  ( m_ui->m_outResYLineEdit->text().toDouble() <= 0.0 )
802  )
803  {
804  QMessageBox::warning(this, tr("Warning"), "Invalid rasters resolution values" );
805  return;
806  }
807 
808  // creating the algorithm parameters
809  std::unique_ptr<te::da::DataSet> dsRef(m_refLayer->getData());
810  std::size_t rpos = te::da::GetFirstPropertyPos(dsRef.get(), te::dt::RASTER_TYPE);
811  std::unique_ptr<te::rst::Raster> inputRstRef = dsRef->getRaster(rpos);
812 
813  std::unique_ptr<te::da::DataSet> dsAdj(m_adjLayer->getData());
815  std::unique_ptr<te::rst::Raster> inputRstAdj = dsAdj->getRaster(rpos);
816 
818  inputParams.m_enableProgress = true;
819 
820  inputParams.m_inRaster1Ptr = inputRstRef.get();
821  inputParams.m_inRaster2Ptr = inputRstAdj.get();
822 
823  const te::gm::Envelope referenceNavigatorCurrentEnvelope(m_refNavigator->getCurrentExtent());
824  double r1LLX = 0;
825  double r1LLY = 0;
826  double r1URX = 0;
827  double r1URY = 0;
828  inputParams.m_inRaster1Ptr->getGrid()->geoToGrid(referenceNavigatorCurrentEnvelope.m_llx, referenceNavigatorCurrentEnvelope.m_lly, r1LLX, r1LLY);
829  inputParams.m_inRaster1Ptr->getGrid()->geoToGrid(referenceNavigatorCurrentEnvelope.m_urx, referenceNavigatorCurrentEnvelope.m_ury, r1URX, r1URY);
830  inputParams.m_raster1TargetAreaColStart = (unsigned int)std::max( 0.0, r1LLX);
831  inputParams.m_raster1TargetAreaLineStart = (unsigned int)std::max( 0.0, r1URY);
832  inputParams.m_raster1TargetAreaWidth = ((unsigned int)std::min((double)inputParams.m_inRaster1Ptr->getNumberOfColumns(), r1URX)) - inputParams.m_raster1TargetAreaColStart + 1;
833  inputParams.m_raster1TargetAreaHeight = ((unsigned int)std::min((double)inputParams.m_inRaster1Ptr->getNumberOfRows(), r1LLY)) - inputParams.m_raster1TargetAreaLineStart + 1;
834 
835  const te::gm::Envelope adjustNavigatorCurrentEnvelope(m_adjNavigator->getCurrentExtent());
836  double r2LLX = 0;
837  double r2LLY = 0;
838  double r2URX = 0;
839  double r2URY = 0;
840  inputParams.m_inRaster2Ptr->getGrid()->geoToGrid(adjustNavigatorCurrentEnvelope.m_llx, adjustNavigatorCurrentEnvelope.m_lly, r2LLX, r2LLY);
841  inputParams.m_inRaster2Ptr->getGrid()->geoToGrid(adjustNavigatorCurrentEnvelope.m_urx, adjustNavigatorCurrentEnvelope.m_ury, r2URX, r2URY);
842  inputParams.m_raster2TargetAreaColStart = (unsigned int)std::max( 0.0, r2LLX);
843  inputParams.m_raster2TargetAreaLineStart = (unsigned int)std::max( 0.0, r2URY);
844  inputParams.m_raster2TargetAreaWidth = ((unsigned int)std::min((double)inputParams.m_inRaster2Ptr->getNumberOfColumns(), r2URX)) - inputParams.m_raster2TargetAreaColStart + 1;
845  inputParams.m_raster2TargetAreaHeight = ((unsigned int)std::min((double)inputParams.m_inRaster2Ptr->getNumberOfRows(), r2LLY)) - inputParams.m_raster2TargetAreaLineStart + 1;
846 
847  inputParams.m_inRaster1Bands.push_back(m_ui->m_referenceBandComboBox->currentText().toUInt());
848  inputParams.m_inRaster2Bands.push_back(m_ui->m_adjBandComboBox->currentText().toUInt());
849 
850 
851  if(
852  (
853  m_ui->m_referenceSRIDLineEdit->text().toInt()
854  !=
855  m_ui->m_adjustSRIDLineEdit->text().toInt()
856  )
857  &&
858  (
859  m_ui->m_referenceSRIDLineEdit->text().toInt() != 0
860  )
861  &&
862  (
863  m_ui->m_adjustSRIDLineEdit->text().toInt() != 0
864  )
865  )
866  {
867  te::gm::Envelope adjustRasterEnvelope(*inputRstAdj->getExtent());
868 
869  adjustRasterEnvelope.transform( m_ui->m_adjustSRIDLineEdit->text().toInt(),
870  m_ui->m_referenceSRIDLineEdit->text().toInt() );
871 
872  double adjustResX = adjustRasterEnvelope.getWidth() /
873  inputRstAdj->getNumberOfColumns();
874  double adjustResY = adjustRasterEnvelope.getHeight() /
875  inputRstAdj->getNumberOfRows();
876 
877  inputParams.m_pixelSizeXRelation = inputRstRef->getGrid()->getResolutionX()
878  / adjustResX;
879  inputParams.m_pixelSizeYRelation = inputRstRef->getGrid()->getResolutionY()
880  / adjustResY;
881  }
882  else
883  {
884  inputParams.m_pixelSizeXRelation = m_ui->m_referenceResXLineEdit->text().toDouble()
885  / m_ui->m_adjustResXLineEdit->text().toDouble();
886  inputParams.m_pixelSizeYRelation = m_ui->m_referenceResYLineEdit->text().toDouble()
887  / m_ui->m_adjustResYLineEdit->text().toDouble();
888  }
889 
890  if(!(inputRstRef->getExtent()->within(referenceNavigatorCurrentEnvelope) &&
891  inputRstAdj->getExtent()->within(adjustNavigatorCurrentEnvelope)))
892  {
893  inputParams.m_subSampleOptimizationRescaleFactor = 1.;
894  }
895 
897 
898  // Looking for manual inserted tie-points for an initial estimate
899  unsigned int manualTPNumber = 0;
900  te::qt::widgets::TiePointData::TPContainerT::const_iterator itB = m_tiePoints.begin();
901  const te::qt::widgets::TiePointData::TPContainerT::const_iterator itE = m_tiePoints.end();
902 
903  while(itB != itE)
904  {
905  if(itB->second.m_acqType == TiePointData::ManualAcquisitionT)
906  {
907  ++manualTPNumber;
908  }
909 
910  ++itB;
911  }
912 
913  // Executing the algorithm
914  QApplication::setOverrideCursor(Qt::WaitCursor);
915 
916  try
917  {
918  te::rp::TiePointsLocator algorithmInstance;
919 
920  if(algorithmInstance.initialize(inputParams))
921  {
922  if(algorithmInstance.execute(outputParams))
923  {
924  const unsigned int tpsNmb = (unsigned int)outputParams.m_tiePoints.size();
925 
926  if(tpsNmb)
927  {
928  TiePointData auxTpData;
930 
931  int initialId = (int)m_tiePoints.size();
932 
933  for(unsigned int tpIdx = 0; tpIdx < tpsNmb; ++tpIdx)
934  {
935  auxTpData.m_tiePoint = outputParams.m_tiePoints[ tpIdx ];
936  m_tiePoints[ m_tiePointIdCounter ] = auxTpData;
937 
938  double x, y;
939  if (inputRstRef)
940  {
941  inputRstRef->getGrid()->gridToGeo(auxTpData.m_tiePoint.first.x, auxTpData.m_tiePoint.first.y, x, y);
942  m_refPoints[m_tiePointIdCounter] = QPointF(x,y);
943  }
944 
945  inputRstAdj->getGrid()->gridToGeo(auxTpData.m_tiePoint.second.x, auxTpData.m_tiePoint.second.y, x, y);
946  m_adjPoints[m_tiePointIdCounter] = QPointF(x, y);
947 
949  }
950 
952 
953  disconnect(m_ui->m_tiePointsTableWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onTiePointsTableWidgetItemSelectionChanged()));
954 
955  createSelection(initialId, (int)tpsNmb);
956 
957  connect(m_ui->m_tiePointsTableWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onTiePointsTableWidgetItemSelectionChanged()));
958 
960  }
961  else
962  {
963  QMessageBox::warning(this, tr("Warning"), tr("None tie points was located."));
964  }
965  }
966  else
967  {
968  QMessageBox::warning(this, tr("Warning"), te::rp::Module::getLastLogStr().c_str());
969  }
970  }
971  else
972  {
973  QMessageBox::warning(this, tr("Warning"), te::rp::Module::getLastLogStr().c_str());
974  }
975  }
976  catch(...)
977  {
978  QApplication::restoreOverrideCursor();
979 
980  QMessageBox::warning(this, tr("Warning"), tr("Error locating tie points."));
981  }
982 
983  QApplication::restoreOverrideCursor();
984 }
985 
987 {
988  m_ui->m_tiePointsTableWidget->selectAll();
989 }
990 
992 {
993  m_ui->m_tiePointsTableWidget->clearSelection();
994 }
995 
997 {
998  const int rowCount = m_ui->m_tiePointsTableWidget->rowCount();
999 
1000  for( int row = 0 ; row < rowCount ; ++row )
1001  {
1002  QTableWidgetItem* itemPtr = m_ui->m_tiePointsTableWidget->item(row, 0);
1003 
1004  if(itemPtr->isSelected())
1005  {
1006  unsigned int tpID = itemPtr->text().toUInt();
1007 
1008  te::qt::widgets::TiePointData::TPContainerT::iterator deletionIt = m_tiePoints.find(tpID);
1009 
1010  assert(deletionIt != m_tiePoints.end());
1011 
1012  m_tiePoints.erase(deletionIt);
1013 
1014  std::map<unsigned int, QPointF>::iterator it_pts = m_adjPoints.find(tpID);
1015  if (it_pts != m_adjPoints.end())
1016  m_adjPoints.erase(it_pts);
1017 
1018  it_pts = m_refPoints.find(tpID);
1019  if (it_pts != m_refPoints.end())
1020  m_refPoints.erase(it_pts);
1021  }
1022  }
1023 
1024  if(m_tiePoints.empty())
1025  {
1026  m_tiePointIdCounter = 0;
1027  }
1028 
1029  m_tiePointsSelected.clear();
1030 
1032 }
1033 
1035 {
1036 
1037  std::unique_ptr<te::da::DataSet> dsadj(m_adjLayer->getData());
1038  std::size_t rposadj = te::da::GetFirstPropertyPos(dsadj.get(), te::dt::RASTER_TYPE);
1039  std::unique_ptr<te::rst::Raster> adjRst = dsadj->getRaster(rposadj);
1040  std::unique_ptr<te::rst::Raster> refRst;
1041 
1042  if (m_refLayer.get())
1043  {
1044  std::unique_ptr<te::da::DataSet> dsref(m_refLayer->getData());
1045  std::size_t rposref = te::da::GetFirstPropertyPos(dsref.get(), te::dt::RASTER_TYPE);
1046  refRst = dsref->getRaster(rposref);
1047  }
1048 
1049  if ((!m_ui->m_x1LineEdit->text().isEmpty()) && (!m_ui->m_y1LineEdit->text().isEmpty()) &&
1050  (!m_ui->m_x2LineEdit->text().isEmpty()) && (!m_ui->m_y2LineEdit->text().isEmpty()))
1051  {
1052  m_currentTiePoint.first.x = m_ui->m_x1LineEdit->text().toDouble();
1053  m_currentTiePoint.first.y = m_ui->m_y1LineEdit->text().toDouble();
1054  m_currentTiePoint.second.x = m_ui->m_x2LineEdit->text().toDouble();
1055  m_currentTiePoint.second.y = m_ui->m_y2LineEdit->text().toDouble();
1056  }
1057  else if ((!m_ui->m_x1LineEdit->text().isEmpty()) && (!m_ui->m_y1LineEdit->text().isEmpty()) &&
1058  (m_ui->m_x2LineEdit->text().isEmpty()) && (m_ui->m_y2LineEdit->text().isEmpty()))
1059  {
1060  m_currentTiePoint.first.x = m_ui->m_x1LineEdit->text().toDouble();
1061  m_currentTiePoint.first.y = m_ui->m_y1LineEdit->text().toDouble();
1062  if (!shotSecondtPoint())
1063  {
1065  m_currentTiePoint.second = adjDisplay->getExtent().getCenter();
1066  adjRst->getGrid()->geoToGrid(m_currentTiePoint.second.x, m_currentTiePoint.second.y, m_currentTiePoint.second.x, m_currentTiePoint.second.y);
1067  }
1068  }
1069  else if ((m_ui->m_x1LineEdit->text().isEmpty()) && (m_ui->m_y1LineEdit->text().isEmpty()) &&
1070  (!m_ui->m_x2LineEdit->text().isEmpty()) && (!m_ui->m_y2LineEdit->text().isEmpty()))
1071  {
1072  m_currentTiePoint.second.x = m_ui->m_x2LineEdit->text().toDouble();
1073  m_currentTiePoint.second.y = m_ui->m_y2LineEdit->text().toDouble();
1074  if (!shotFirstPoint())
1075  {
1076  if (m_refLayer.get())
1077  {
1078  return;
1079  }
1080  else
1081  {
1082  m_currentTiePoint.first = adjRst->getExtent()->getCenter();
1083  }
1084  }
1085  }
1086  else
1087  return;
1088 
1089  TiePointData tpD;
1092 
1094 
1095  if (m_refLayer.get())
1096  {
1097  const te::gm::Coord2D refCoord = tpD.m_tiePoint.first;
1098  te::gm::Coord2D refGeoCoord;
1099  refRst->getGrid()->gridToGeo(refCoord.x, refCoord.y, refGeoCoord.x, refGeoCoord.y);
1100 
1101  m_refPoints[m_tiePointIdCounter] = QPointF(refGeoCoord.x, refGeoCoord.y);
1102 
1103  te::gm::Coord2D adjCoord = tpD.m_tiePoint.second;
1104  te::gm::Coord2D adjGeoCoord;
1105  adjRst->getGrid()->gridToGeo(adjCoord.x, adjCoord.y, adjGeoCoord.x, adjGeoCoord.y);
1106  m_adjPoints[m_tiePointIdCounter++] = QPointF(adjGeoCoord.x, adjGeoCoord.y);
1107  }
1108  else
1109  {
1110  te::gm::Coord2D adjGeoCoord;
1111  adjRst->getGrid()->gridToGeo(tpD.m_tiePoint.second.x, tpD.m_tiePoint.second.y, adjGeoCoord.x, adjGeoCoord.y);
1112  m_adjPoints[m_tiePointIdCounter++] = QPointF(adjGeoCoord.x, adjGeoCoord.y);
1113  }
1114 
1116 
1117 }
1118 
1120 {
1122 }
1123 
1125 {
1127 }
1128 
1130 {
1131  emit doneAcquiredTiePoints();
1132 }
1133 
1135 {
1136  drawTiePoints();
1137 }
1138 
1140 {
1141  drawTiePoints();
1142 }
1143 
1145 {
1146  refCoordPicked(x, y);
1147 
1148  drawTiePoints();
1149 }
1150 
1152 {
1153  adjCoordPicked(x, y);
1154 
1155  drawTiePoints();
1156 }
1157 
1158 void te::qt::widgets::TiePointLocatorWidget::onRefPointMoved(double xorig, double yorig,double xnew, double ynew)
1159 {
1160  refCoordMoved(xorig, yorig, xnew, ynew);
1161 
1162  drawTiePoints();
1163 }
1164 
1165 void te::qt::widgets::TiePointLocatorWidget::onAdjPointMoved(double xorig, double yorig, double xnew, double ynew)
1166 {
1167  adjCoordMoved(xorig, yorig, xnew, ynew);
1168 
1169  drawTiePoints();
1170 }
1171 
1173 {
1174  drawTiePoints();
1175 }
1176 
1178 {
1179  te::qt::widgets::SRSManagerDialog srsDialog(this);
1180  srsDialog.setWindowTitle(tr("Choose the SRS"));
1181 
1182  if(srsDialog.exec() == QDialog::Accepted)
1183  {
1184  std::pair<int, std::string> srid = srsDialog.getSelectedSRS();
1185 
1186  QString strSRID;
1187  strSRID.setNum(srid.first);
1188  m_ui->m_outSridLineEdit->setText(strSRID);
1189  }
1190 }
1191 
1193 {
1194  QString tiePointsFileName = QFileDialog::getOpenFileName(this, tr("Select the input file name"),
1195  te::qt::widgets::GetFilePathFromSettings("tie_points_file_directory"),
1196  tr("Tie-points file (*.tps)"), 0 ,QFileDialog::ReadOnly);
1197 
1198  if( !tiePointsFileName.isEmpty() )
1199  {
1200  boost::filesystem::path fullFilePath( tiePointsFileName.toUtf8().data() );
1201  te::qt::widgets::AddFilePathToSettings(fullFilePath.parent_path().string().c_str(),
1202  "tie_points_file_directory");
1203 
1204  std::ifstream tiePointsFile;
1205  tiePointsFile.open( tiePointsFileName.toUtf8().data(), std::ofstream::in );
1206  if( !tiePointsFile.good() )
1207  {
1208  QMessageBox::critical(this, tr("Warning"), tr("Tie points file open error"));
1209  return;
1210  }
1211 
1212  std::string lineStr;
1213  std::vector< std::string > tokens;
1214 
1215  int refSRID = 0;
1216  int adjSRID = 0;
1217 
1218  while( !tiePointsFile.eof() )
1219  {
1220  std::getline( tiePointsFile, lineStr );
1221 
1222  if( lineStr.find( "REFSRID", 0 ) == 0 )
1223  {
1224  tokens.clear();
1225  te::common::Tokenize( lineStr, tokens, " " );
1226  refSRID = boost::lexical_cast< int >( tokens[ 1 ] );
1227  }
1228  else if( lineStr.find( "ADJSRID", 0 ) == 0 )
1229  {
1230  tokens.clear();
1231  te::common::Tokenize( lineStr, tokens, " " );
1232  adjSRID = boost::lexical_cast< int >( tokens[ 1 ] );
1233  }
1234  else if( lineStr.find( "TPID", 0 ) == 0 )
1235  {
1236  break;
1237  }
1238  }
1239 
1240  TiePointData auxTpData;
1241  te::gm::Coord2D point;
1242  unsigned int tpID = static_cast<unsigned int>(m_tiePoints.size());
1243 
1244  if (m_refLayer.get())
1245  {
1246  if( refSRID <= 0 )
1247  {
1248  QMessageBox::critical(this, tr("Warning"), tr("Invalid tie-points file (invalid reference raster SRID)"));
1249  return;
1250  }
1251 
1252  te::gm::Coord2D reprojectedPoint;
1253  std::unique_ptr< te::rst::Raster > refRasterPtr = m_refLayer->getData()->getRaster(0);
1254  std::unique_ptr< te::rst::Raster > adjRasterPtr = m_adjLayer->getData()->getRaster(0);
1255  te::srs::Converter refConverter( refSRID, refRasterPtr->getSRID() );
1256  te::srs::Converter adjConverter;
1257  if (adjSRID && adjRasterPtr->getSRID())
1258  {
1259  adjConverter.setSourceSRID(adjSRID);
1260  adjConverter.setTargetSRID(adjRasterPtr->getSRID());
1261  }
1262 
1263  while( !tiePointsFile.eof() )
1264  {
1265  std::getline( tiePointsFile, lineStr );
1266 
1267  if( lineStr.size() )
1268  {
1269  tokens.clear();
1270  te::common::Tokenize( lineStr, tokens, ";" );
1271 
1272  if( tokens.size() > 9 )
1273  {
1274  if( tokens[ 1 ] == "auto" )
1275  {
1277  }
1278  else
1279  {
1281  }
1282 
1283  point.x = boost::lexical_cast< double >( tokens[ 4 ] );
1284  point.y = boost::lexical_cast< double >( tokens[ 5 ] );
1285  refConverter.convert( point.x, point.y, reprojectedPoint.x, reprojectedPoint.y );
1286  refRasterPtr->getGrid()->geoToGrid( reprojectedPoint.x, reprojectedPoint.y,
1287  auxTpData.m_tiePoint.first.x, auxTpData.m_tiePoint.first.y );
1288 
1289  if( adjSRID > 0 )
1290  {
1291  point.x = boost::lexical_cast< double >( tokens[ 8 ] );
1292  point.y = boost::lexical_cast< double >( tokens[ 9 ] );
1293  if (adjSRID && adjRasterPtr->getSRID())
1294  {
1295  adjConverter.convert( point.x, point.y, reprojectedPoint.x, reprojectedPoint.y );
1296  }
1297  else
1298  reprojectedPoint = point;
1299 
1300  adjRasterPtr->getGrid()->geoToGrid( reprojectedPoint.x, reprojectedPoint.y,
1301  auxTpData.m_tiePoint.second.x, auxTpData.m_tiePoint.second.y );
1302  }
1303  else
1304  {
1305  auxTpData.m_tiePoint.second.x = boost::lexical_cast< double >( tokens[ 6 ] );
1306  auxTpData.m_tiePoint.second.y = boost::lexical_cast< double >( tokens[ 7 ] );
1307  }
1308 
1309  while( m_tiePoints.find( tpID ) != m_tiePoints.end() )
1310  {
1311  ++tpID;
1312  }
1313 
1314  m_tiePoints[ tpID ] = auxTpData;
1315 
1316  double x, y;
1317  refRasterPtr->getGrid()->gridToGeo(auxTpData.m_tiePoint.first.x, auxTpData.m_tiePoint.first.y, x, y);
1318  m_refPoints[tpID] = QPointF(x, y);
1319 
1320  adjRasterPtr->getGrid()->gridToGeo(auxTpData.m_tiePoint.second.x, auxTpData.m_tiePoint.second.y, x, y);
1321  m_adjPoints[tpID] = QPointF(x, y);
1322  }
1324  }
1325  }
1326  }
1327  else
1328  {
1329  std::unique_ptr< te::rst::Raster > adjRasterPtr = m_adjLayer->getData()->getRaster(0);
1330  while (!tiePointsFile.eof())
1331  {
1332  std::getline(tiePointsFile, lineStr);
1333 
1334  if (lineStr.size())
1335  {
1336  tokens.clear();
1337  te::common::Tokenize(lineStr, tokens, ";");
1338 
1339  if (tokens.size() > 9)
1340  {
1341  QMessageBox::critical(this, tr("Warning"), tr("Invalid tie-points file (reference raster is necessary)"));
1342  return;
1343  }
1344  else if (tokens.size() > 5)
1345  {
1346  if (tokens[1] == "auto")
1347  {
1349  }
1350  else
1351  {
1353  }
1354 
1355  auxTpData.m_tiePoint.first.x = boost::lexical_cast<double>(tokens[2]);
1356  auxTpData.m_tiePoint.first.y = boost::lexical_cast<double>(tokens[3]);
1357  auxTpData.m_tiePoint.second.x = boost::lexical_cast<double>(tokens[4]);
1358  auxTpData.m_tiePoint.second.y = boost::lexical_cast<double>(tokens[5]);
1359  }
1360  while (m_tiePoints.find(tpID) != m_tiePoints.end())
1361  {
1362  ++tpID;
1363  }
1364 
1365  m_tiePoints[tpID] = auxTpData;
1366 
1367  double x, y;
1368  adjRasterPtr->getGrid()->gridToGeo(auxTpData.m_tiePoint.second.x, auxTpData.m_tiePoint.second.y, x, y);
1369  m_adjPoints[tpID] = QPointF(x, y);
1371  }
1372  }
1373  }
1374 
1376 
1378  }
1379 }
1380 
1382 {
1383  QString tiePointsFileName = QFileDialog::getSaveFileName(this, tr("Select the output file name"),
1384  te::qt::widgets::GetFilePathFromSettings("tie_points_file_directory"),
1385  tr("Tie-points file (*.tps)"), 0, 0);
1386 
1387  if( !tiePointsFileName.isEmpty() )
1388  {
1389  boost::filesystem::path fullFilePath( tiePointsFileName.toUtf8().data() );
1390  te::qt::widgets::AddFilePathToSettings(fullFilePath.parent_path().string().c_str(),
1391  "tie_points_file_directory");
1392 
1393  std::ofstream tiePointsFile;
1394  tiePointsFile.open( tiePointsFileName.toUtf8().data(), std::ofstream::out |
1395  std::ofstream::trunc );
1396 
1397  if( !tiePointsFile.good() )
1398  {
1399  QMessageBox::critical(this, tr("Warning"), tr("Tie points file creation error"));
1400  return;
1401  }
1402  tiePointsFile.precision( 40 );
1403 
1404  if (m_refLayer.get())
1405  {
1406  std::unique_ptr< te::rst::Raster > refRasterPtr = m_refLayer->getData()->getRaster(0);
1407  std::unique_ptr< te::rst::Raster > adjRasterPtr = m_adjLayer->getData()->getRaster(0);
1408 
1409  tiePointsFile << "REFSRID " << refRasterPtr->getSRID();
1410  tiePointsFile << std::endl << "REFDSNAME " << m_refLayer->getDataSetName();
1411  tiePointsFile << std::endl << "ADJSRID " << adjRasterPtr->getSRID();
1412  tiePointsFile << std::endl << "ADJDSNAME " << m_adjLayer->getDataSetName();
1413  tiePointsFile << std::endl << "TPID;ACKTYPE;REFCOL;REFROW;REFX;REFY;ADJCOL;AJDROW;ADJX;ADJY";
1414 
1415  const te::rst::Grid& refGrid = *refRasterPtr->getGrid();
1416  const te::rst::Grid& adjGrid = *adjRasterPtr->getGrid();
1417 
1418  TiePointData::TPContainerT::const_iterator tpIt = m_tiePoints.begin();
1419  TiePointData::TPContainerT::const_iterator tpItEnd = m_tiePoints.end();
1420  te::gm::Coord2D auxCood;
1421 
1422  while( tpIt != tpItEnd )
1423  {
1424  tiePointsFile << std::endl << tpIt->first;
1425 
1426  if( tpIt->second.m_acqType == TiePointData::ManualAcquisitionT )
1427  {
1428  tiePointsFile << ";manual";
1429  }
1430  else
1431  {
1432  tiePointsFile << ";auto";
1433  }
1434 
1435  auxCood = refGrid.gridToGeo( tpIt->second.m_tiePoint.first.x,
1436  tpIt->second.m_tiePoint.first.y );
1437  tiePointsFile
1438  << ";" << tpIt->second.m_tiePoint.first.x
1439  << ";" << tpIt->second.m_tiePoint.first.y
1440  << ";" << auxCood.x
1441  << ";" << auxCood.y
1442  ;
1443 
1444  auxCood = adjGrid.gridToGeo( tpIt->second.m_tiePoint.second.x,
1445  tpIt->second.m_tiePoint.second.y );
1446  tiePointsFile
1447  << ";" << tpIt->second.m_tiePoint.second.x
1448  << ";" << tpIt->second.m_tiePoint.second.y
1449  << ";" << auxCood.x
1450  << ";" << auxCood.y
1451  ;
1452 
1453  ++tpIt;
1454  }
1455  }
1456  else //only adjust image
1457  {
1458  std::unique_ptr< te::rst::Raster > adjRasterPtr = m_adjLayer->getData()->getRaster(0);
1459 
1460  tiePointsFile << std::endl << "ADJSRID " << adjRasterPtr->getSRID();
1461  tiePointsFile << std::endl << "ADJDSNAME " << m_adjLayer->getDataSetName();
1462  tiePointsFile << std::endl << "TPID;ACKTYPE;ADJX;ADJY;ADJCOL;AJDROW";
1463 
1464  TiePointData::TPContainerT::const_iterator tpIt = m_tiePoints.begin();
1465  TiePointData::TPContainerT::const_iterator tpItEnd = m_tiePoints.end();
1466 
1467  while (tpIt != tpItEnd)
1468  {
1469  tiePointsFile << std::endl << tpIt->first;
1470 
1471  tiePointsFile << ";manual";
1472 
1473  tiePointsFile
1474  << ";" << tpIt->second.m_tiePoint.first.x
1475  << ";" << tpIt->second.m_tiePoint.first.y
1476  << ";" << tpIt->second.m_tiePoint.second.x
1477  << ";" << tpIt->second.m_tiePoint.second.y
1478  ;
1479 
1480  ++tpIt;
1481  }
1482  }
1483  }
1484 }
1485 
1487 {
1488  // building the geometric transformation
1489  te::gm::GTParameters transParams;
1490 
1491  te::qt::widgets::TiePointData::TPContainerT::const_iterator tPIt = m_tiePoints.begin();
1492  const te::qt::widgets::TiePointData::TPContainerT::const_iterator tPItEnd = m_tiePoints.end();
1493 
1494  while( tPIt != tPItEnd )
1495  {
1496  transParams.m_tiePoints.push_back(tPIt->second.m_tiePoint);
1497  ++tPIt;
1498  }
1499 
1500  std::string geoTransfName = m_tiePointParameters->getTransformationName();
1501 
1502  std::unique_ptr<te::gm::GeometricTransformation> transfPtr(te::gm::GTFactory::make(geoTransfName));
1503 
1504  if(transfPtr.get())
1505  {
1506  if(!transfPtr->initialize(transParams))
1507  transfPtr.reset();
1508  }
1509 
1510  // updating the tie points table
1511  m_ui->m_tiePointsTableWidget->blockSignals( true );
1512  m_ui->m_tiePointsTableWidget->setSortingEnabled( false );
1513 
1514  m_ui->m_tiePointsTableWidget->setRowCount(0);
1515 
1516  double currTPError = 0;
1517 
1518  tPIt = m_tiePoints.begin();
1519 
1520  while( tPIt != tPItEnd )
1521  {
1522  int newrow = m_ui->m_tiePointsTableWidget->rowCount();
1523  m_ui->m_tiePointsTableWidget->insertRow(newrow);
1524 
1525  const te::gm::GTParameters::TiePoint& currTP = tPIt->second.m_tiePoint;
1526  currTPError = transfPtr.get() ? transfPtr->getInverseMappingError(currTP) : 0.0;
1527 
1528  //tie point id
1529  QTableWidgetItem* itemId = new QTableWidgetItem(QString::number(tPIt->first));
1530  itemId->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1531  m_ui->m_tiePointsTableWidget->setItem(newrow, 0, itemId);
1532 
1533  //tie point current tie point error
1534  QTableWidgetItem* itemError = new QTableWidgetItem(QString::number(currTPError));
1535  itemError->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1536  m_ui->m_tiePointsTableWidget->setItem(newrow, 1, itemError);
1537 
1538  //acquisition type
1539  QString type;
1540  if(tPIt->second.m_acqType == TiePointData::ManualAcquisitionT)
1541  {
1542  type = tr("Manual");
1543  }
1544  else
1545  {
1546  type = tr("Automatic");
1547  }
1548 
1549  QTableWidgetItem* itemType = new QTableWidgetItem(type);
1550  itemType->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
1551  m_ui->m_tiePointsTableWidget->setItem(newrow, 2, itemType);
1552 
1553  if (m_refLayer.get())
1554  {
1555  //ref x coord
1556  QTableWidgetItem* itemRefX = new QTableWidgetItem(QString::number((int)currTP.first.x));
1557  itemRefX->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
1558  m_ui->m_tiePointsTableWidget->setItem(newrow, 3, itemRefX);
1559 
1560  //ref y coord
1561  QTableWidgetItem* itemRefY = new QTableWidgetItem(QString::number((int)currTP.first.y));
1562  itemRefY->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
1563  m_ui->m_tiePointsTableWidget->setItem(newrow, 4, itemRefY);
1564  }
1565  else
1566  {
1567  //geo x coord
1568  QTableWidgetItem* itemRefX = new QTableWidgetItem(QString::number(currTP.first.x));
1569  itemRefX->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
1570  m_ui->m_tiePointsTableWidget->setItem(newrow, 3, itemRefX);
1571 
1572  //geo y coord
1573  QTableWidgetItem* itemRefY = new QTableWidgetItem(QString::number(currTP.first.y));
1574  itemRefY->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
1575  m_ui->m_tiePointsTableWidget->setItem(newrow, 4, itemRefY);
1576  }
1577 
1578  //adj x coord
1579  QTableWidgetItem* itemAdjX = new QTableWidgetItem(QString::number((int)currTP.second.x));
1580  itemAdjX->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
1581  m_ui->m_tiePointsTableWidget->setItem(newrow, 5, itemAdjX);
1582 
1583  //adj y coord
1584  QTableWidgetItem* itemAdjY = new QTableWidgetItem(QString::number((int)currTP.second.y));
1585  itemAdjY->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
1586  m_ui->m_tiePointsTableWidget->setItem(newrow, 6, itemAdjY);
1587 
1588  //check if this item was selected
1589  std::set<int>::iterator it = m_tiePointsSelected.find(tPIt->first);
1590 
1591  if(it != m_tiePointsSelected.end())
1592  {
1593  m_ui->m_tiePointsTableWidget->selectRow(newrow);
1594  }
1595 
1596  ++tPIt;
1597  }
1598 
1599  m_ui->m_tiePointsTableWidget->setSortingEnabled(true);
1600  m_ui->m_tiePointsTableWidget->blockSignals( false );
1601  m_ui->m_tiePointsTableWidget->resizeColumnsToContents();
1602 
1604 }
1605 
1607 {
1608  // creating the transformations parameters
1609  te::gm::GTParameters transParamsAllTP;
1610  te::gm::GTParameters transParamsSelectedTP;
1611  te::gm::GTParameters transParamsUnselectedTP;
1612 
1613  m_tiePointsSelected.clear();
1614 
1615  const int rowCount = m_ui->m_tiePointsTableWidget->rowCount();
1616 
1617  for(int row = 0; row < rowCount; ++row)
1618  {
1619  QTableWidgetItem* itemPtr = m_ui->m_tiePointsTableWidget->item(row, 0);
1620 
1621  int id = itemPtr->text().toUInt();
1622 
1623  te::qt::widgets::TiePointData::TPContainerT::iterator it = m_tiePoints.find(id);
1624 
1625  assert(it != m_tiePoints.end());
1626 
1627  const te::gm::GTParameters::TiePoint& tiePoint = it->second.m_tiePoint;
1628 
1629  if( itemPtr->isSelected() )
1630  {
1631  it->second.m_selected = true;
1632 
1633  transParamsSelectedTP.m_tiePoints.push_back(tiePoint);
1634 
1635  m_tiePointsSelected.insert(id);
1636  }
1637  else
1638  {
1639  it->second.m_selected = false;
1640 
1641  transParamsUnselectedTP.m_tiePoints.push_back(tiePoint);
1642  }
1643 
1644  transParamsAllTP.m_tiePoints.push_back(tiePoint);
1645  }
1646 
1647  // instantiating the transformations
1648  std::string geoTransfName = m_tiePointParameters->getTransformationName();
1649 
1650  std::unique_ptr<te::gm::GeometricTransformation> transfAllTPPtr(te::gm::GTFactory::make(geoTransfName));
1651  if(transfAllTPPtr.get())
1652  if(!transfAllTPPtr->initialize(transParamsAllTP))
1653  transfAllTPPtr.reset();
1654 
1655  std::unique_ptr<te::gm::GeometricTransformation> transfSelectedTPPtr(te::gm::GTFactory::make(geoTransfName));
1656  if(transfSelectedTPPtr.get())
1657  if(!transfSelectedTPPtr->initialize(transParamsSelectedTP))
1658  transfSelectedTPPtr.reset();
1659 
1660  std::unique_ptr<te::gm::GeometricTransformation> transfUnselectedTPPtr(te::gm::GTFactory::make(geoTransfName));
1661  if(transfUnselectedTPPtr.get())
1662  if(!transfUnselectedTPPtr->initialize(transParamsUnselectedTP))
1663  transfUnselectedTPPtr.reset();
1664 
1665  // updating widgets
1666  m_ui->m_tiePointsNumberLineEdit->setText(QString::number(m_tiePoints.size()));
1667 
1668  if(transfAllTPPtr.get())
1669  m_ui->m_transformationRMSEAllLineEdit->setText(QString::number(transfAllTPPtr->getInverseMapRMSE()));
1670  else
1671  m_ui->m_transformationRMSEAllLineEdit->setText("N/A");
1672 
1673  if(transfSelectedTPPtr.get())
1674  m_ui->m_transformationRMSESelectedLineEdit->setText(QString::number(transfSelectedTPPtr->getInverseMapRMSE()));
1675  else
1676  m_ui->m_transformationRMSESelectedLineEdit->setText("N/A");
1677 
1678  if(transfUnselectedTPPtr.get())
1679  m_ui->m_transformationRMSEunselectedLineEdit->setText(QString::number(transfUnselectedTPPtr->getInverseMapRMSE()));
1680  else
1681  m_ui->m_transformationRMSEunselectedLineEdit->setText("N/A");
1682 
1683  //emit signal
1684  emit tiePointsUpdated();
1685 }
1686 
1688 {
1689  //reference
1690  QGridLayout* layoutRef = new QGridLayout(m_ui->m_refWidget);
1691 
1693  m_refNavigator->setWindowTitle(tr("Reference"));
1694  m_refNavigator->setMinimumSize(550, 400);
1697  m_refNavigator->hideBoxTool(true);
1699 
1700  layoutRef->addWidget(m_refNavigator);
1701  layoutRef->setContentsMargins(0,0,0,0);
1702 
1703  connect(m_refNavigator, SIGNAL(mapDisplayExtentChanged()), this, SLOT(onRefMapDisplayExtentChanged()));
1704  connect(m_refNavigator, SIGNAL(pointPicked(double, double)), this, SLOT(onRefPointPicked(double, double)));
1705  connect(m_refNavigator, SIGNAL(pointMoved(double, double, double, double)), this, SLOT(onRefPointMoved(double, double, double, double)));
1706 
1707  //adjust
1708  QGridLayout* layoutAdj = new QGridLayout(m_ui->m_adjWidget);
1709 
1711  m_adjNavigator->setWindowTitle(tr("Adjust"));
1712  m_adjNavigator->setMinimumSize(550, 400);
1715  m_adjNavigator->hideBoxTool(true);
1717 
1718  layoutAdj->addWidget(m_adjNavigator);
1719  layoutAdj->setContentsMargins(0,0,0,0);
1720 
1721  connect(m_adjNavigator, SIGNAL(mapDisplayExtentChanged()), this, SLOT(onAdjMapDisplayExtentChanged()));
1722  connect(m_adjNavigator, SIGNAL(pointPicked(double, double)), this, SLOT(onAdjPointPicked(double, double)));
1723  connect(m_adjNavigator, SIGNAL(pointMoved(double, double, double, double)), this, SLOT(onAdjPointMoved(double, double, double, double)));
1724 }
1725 
1727 {
1728  std::size_t rpos;
1729  te::qt::widgets::MapDisplay* refDisplay = 0;
1730  std::unique_ptr<te::qt::widgets::Canvas> refCanvasInstance;
1731  std::unique_ptr<te::rst::Raster> rstRef;
1732 
1733  if (m_refLayer.get())
1734  {
1735  refDisplay = m_refNavigator->getDisplay();
1736  refDisplay->getDraftPixmap()->fill(Qt::transparent);
1737  const te::gm::Envelope& refMapExt = refDisplay->getExtent();
1738  refCanvasInstance.reset(new te::qt::widgets::Canvas(refDisplay->getDraftPixmap()));
1739  refCanvasInstance->setWindow(refMapExt.m_llx, refMapExt.m_lly, refMapExt.m_urx, refMapExt.m_ury);
1740 
1741  std::unique_ptr<te::da::DataSet> dsRef = m_refLayer->getData();
1742  if(!dsRef.get())
1743  return;
1744  std::size_t rpos = te::da::GetFirstPropertyPos(dsRef.get(), te::dt::RASTER_TYPE);
1745  rstRef.reset(dsRef->getRaster(rpos).release());
1746  if(!rstRef.get())
1747  return;
1748 
1749  refCanvasInstance->setTextContourEnabled(true);
1750  refCanvasInstance->setTextContourWidth(2);
1751  refCanvasInstance->setTextContourColor(te::color::RGBAColor(0, 0, 0, TE_OPAQUE));
1752  }
1753 
1755  adjDisplay->getDraftPixmap()->fill(Qt::transparent);
1756  const te::gm::Envelope& adjMapExt = adjDisplay->getExtent();
1757  te::qt::widgets::Canvas adjCanvasInstance(adjDisplay->getDraftPixmap());
1758  adjCanvasInstance.setWindow(adjMapExt.m_llx, adjMapExt.m_lly, adjMapExt.m_urx, adjMapExt.m_ury);
1759 
1760  if(!m_adjLayer.get())
1761  return;
1762  std::unique_ptr<te::da::DataSet> dsAdj = m_adjLayer->getData();
1763  if(!dsAdj.get())
1764  return;
1765  rpos = te::da::GetFirstPropertyPos(dsAdj.get(), te::dt::RASTER_TYPE);
1766  std::unique_ptr<te::rst::Raster> rstAdj = dsAdj->getRaster(rpos);
1767  if(!rstAdj.get())
1768  return;
1769 
1770  //get tie points
1772 
1773  te::qt::widgets::TiePointData::TPContainerT::const_iterator it = tpc.begin();
1774 
1775  adjCanvasInstance.setTextContourEnabled( true );
1776  adjCanvasInstance.setTextContourWidth( 2 );
1777  adjCanvasInstance.setTextContourColor( te::color::RGBAColor(0,0,0, TE_OPAQUE) );
1778 
1779  while(it != tpc.end())
1780  {
1781  int id = it->first;
1782 
1783  te::qt::widgets::TiePointData tpd = it->second;
1784 
1785  if (refCanvasInstance.get())
1786  refCanvasInstance->setPointColor(te::color::RGBAColor(0,0,0, TE_TRANSPARENT));
1787  adjCanvasInstance.setPointColor(te::color::RGBAColor(0,0,0, TE_TRANSPARENT));
1788 
1789  //configure mark
1790  if(tpd.m_selected)
1791  {
1792  if (refCanvasInstance.get())
1793  {
1794  refCanvasInstance->setPointPattern(m_rgbaMarkSelected, PATTERN_SIZE, PATTERN_SIZE);
1795  refCanvasInstance->setTextColor(te::color::RGBAColor(255, 0, 0, TE_OPAQUE));
1796  }
1797 
1798  adjCanvasInstance.setPointPattern(m_rgbaMarkSelected, PATTERN_SIZE, PATTERN_SIZE);
1799  adjCanvasInstance.setTextColor( te::color::RGBAColor(255,0,0, TE_OPAQUE) );
1800  }
1801  else
1802  {
1803  if (refCanvasInstance.get())
1804  {
1805  refCanvasInstance->setPointPattern(m_rgbaMarkUnselected, PATTERN_SIZE, PATTERN_SIZE);
1806  refCanvasInstance->setTextColor(te::color::RGBAColor(0, 255, 0, TE_OPAQUE));
1807  }
1808 
1809  adjCanvasInstance.setPointPattern(m_rgbaMarkUnselected, PATTERN_SIZE, PATTERN_SIZE);
1810  adjCanvasInstance.setTextColor( te::color::RGBAColor(0,255,0, TE_OPAQUE) );
1811  }
1812 
1813  if (m_refLayer.get())
1814  {
1815  //ref coord
1816  const te::gm::Coord2D refCoord = it->second.m_tiePoint.first;
1817  te::gm::Coord2D refGeoCoord;
1818  rstRef->getGrid()->gridToGeo(refCoord.x, refCoord.y, refGeoCoord.x, refGeoCoord.y );
1819 
1820  te::gm::Point refPoint(refGeoCoord.x, refGeoCoord.y);
1821  refCanvasInstance->draw(&refPoint);
1822 
1823  //ref text
1824  QMatrix matrix = refCanvasInstance->getMatrix();
1825  QPointF pointCanvas = matrix.map(QPointF(refGeoCoord.x, refGeoCoord.y ) );
1826  pointCanvas.setY(pointCanvas.y() + 15);
1827  QPointF pointGeo = matrix.inverted().map(pointCanvas);
1828  refPoint.setX(pointGeo.x());
1829  refPoint.setY(pointGeo.y());
1830  refCanvasInstance->drawText(&refPoint, QString::number(id).toUtf8().data());
1831  }
1832 
1833  //adj coord
1834  te::gm::Coord2D adjCoord = it->second.m_tiePoint.second;
1835  te::gm::Coord2D adjGeoCoord;
1836  rstAdj->getGrid()->gridToGeo(adjCoord.x, adjCoord.y, adjGeoCoord.x, adjGeoCoord.y );
1837 
1838  te::gm::Point adjPoint(adjGeoCoord.x, adjGeoCoord.y);
1839  adjCanvasInstance.draw(&adjPoint);
1840 
1841  //adj text
1842  QMatrix matrix = adjCanvasInstance.getMatrix();
1843  QPointF pointCanvas = matrix.map(QPointF(adjGeoCoord.x, adjGeoCoord.y) );
1844  pointCanvas.setY(pointCanvas.y() + 15);
1845  QPointF pointGeo = matrix.inverted().map(pointCanvas);
1846  adjPoint.setX(pointGeo.x());
1847  adjPoint.setY(pointGeo.y());
1848  adjCanvasInstance.drawText(&adjPoint, QString::number(id).toUtf8().data());
1849 
1850  ++it;
1851  }
1852 
1853  //draw ref coord if exist
1854  te::gm::Coord2D firstCoord;
1855  FirstCoordType type = getFirstTiePointCoord(firstCoord);
1856  if(type == Reference)
1857  {
1858  refCanvasInstance->setPointColor(te::color::RGBAColor(0, 0, 0, TE_TRANSPARENT));
1859  refCanvasInstance->setPointPattern(m_rgbaMarkRef, PATTERN_SIZE, PATTERN_SIZE);
1860 
1861  te::gm::Coord2D geoCoord;
1862  rstRef->getGrid()->gridToGeo(firstCoord.x, firstCoord.y, geoCoord.x, geoCoord.y );
1863 
1864  te::gm::Point refPoint(geoCoord.x, geoCoord.y);
1865  refCanvasInstance->draw(&refPoint);
1866  }
1867  if (m_refLayer.get())
1868  refDisplay->repaint();
1869 
1870  if (type == Adjust)
1871  {
1872  adjCanvasInstance.setPointColor(te::color::RGBAColor(0, 0, 0, TE_TRANSPARENT));
1873  adjCanvasInstance.setPointPattern(m_rgbaMarkRef, PATTERN_SIZE, PATTERN_SIZE);
1874 
1875  te::gm::Coord2D geoCoord;
1876  rstAdj->getGrid()->gridToGeo(firstCoord.x, firstCoord.y, geoCoord.x, geoCoord.y);
1877 
1878  te::gm::Point geoPoint(geoCoord.x, geoCoord.y);
1879  adjCanvasInstance.draw(&geoPoint);
1880  }
1881  adjDisplay->repaint();
1882 }
1883 
1885 {
1886  QImage* img = te::qt::widgets::GetImage(rgba, PATTERN_SIZE, PATTERN_SIZE);
1887  QPixmap p = QPixmap::fromImage(*img);
1888  delete img;
1889  return p;
1890 }
1891 
1893 {
1894  try
1895  {
1896  int row = item->row();
1897  QTableWidgetItem* itemPtr = m_ui->m_tiePointsTableWidget->item(row, 0);
1898  unsigned int tpID = itemPtr->text().toUInt();
1899  te::qt::widgets::TiePointData::TPContainerT::iterator editIt = m_tiePoints.find(tpID);
1900  assert(editIt != m_tiePoints.end());
1901 
1902  int col = item->column();
1903  bool ok = true;
1904  switch (col)
1905  {
1906  case 3: //X1
1907  (*editIt).second.m_tiePoint.first.x = item->text().toDouble(&ok);
1908  break;
1909  case 4: //Y1
1910  (*editIt).second.m_tiePoint.first.y = item->text().toDouble(&ok);
1911  break;
1912  case 5: //X2
1913  (*editIt).second.m_tiePoint.second.x = item->text().toDouble(&ok);
1914  break;
1915  case 6: //Y2
1916  (*editIt).second.m_tiePoint.second.y = item->text().toDouble(&ok);
1917  break;
1918  default:
1919  break;
1920  }
1921  if (!ok)
1922  QMessageBox::critical(this, tr("Warning"), tr("Invalid Value"));
1923 
1924  std::unique_ptr<te::da::DataSet> dsadj(m_adjLayer->getData());
1925  std::size_t rposadj = te::da::GetFirstPropertyPos(dsadj.get(), te::dt::RASTER_TYPE);
1926  std::unique_ptr<te::rst::Raster> adjRst = dsadj->getRaster(rposadj);
1927 
1928  if (m_refLayer.get())
1929  {
1930  std::unique_ptr<te::da::DataSet> dsref(m_refLayer->getData());
1931  std::size_t rposref = te::da::GetFirstPropertyPos(dsref.get(), te::dt::RASTER_TYPE);
1932  std::unique_ptr<te::rst::Raster> refRst = dsref->getRaster(rposref);
1933 
1934  const te::gm::Coord2D refCoord = (*editIt).second.m_tiePoint.first;
1935  te::gm::Coord2D refGeoCoord;
1936  refRst->getGrid()->gridToGeo(refCoord.x, refCoord.y, refGeoCoord.x, refGeoCoord.y);
1937 
1938  m_refPoints[tpID] = QPointF(refGeoCoord.x, refGeoCoord.y);
1939 
1940  te::gm::Coord2D adjCoord = (*editIt).second.m_tiePoint.second;
1941  te::gm::Coord2D adjGeoCoord;
1942  adjRst->getGrid()->gridToGeo(adjCoord.x, adjCoord.y, adjGeoCoord.x, adjGeoCoord.y);
1943  m_adjPoints[tpID] = QPointF(adjGeoCoord.x, adjGeoCoord.y);
1944  }
1945  else
1946  {
1947  te::gm::Coord2D adjGeoCoord;
1948  adjRst->getGrid()->gridToGeo((*editIt).second.m_tiePoint.second.x, (*editIt).second.m_tiePoint.second.y, adjGeoCoord.x, adjGeoCoord.y);
1949  m_adjPoints[tpID] = QPointF(adjGeoCoord.x, adjGeoCoord.y);
1950  }
1951  }
1952  catch (const std::exception&)
1953  {
1954  QMessageBox::critical(this, tr("Warning"), tr("Invalid Value"));
1955  }
1956 
1958 
1959 }
1960 
1962 {
1963  m_tiePoints.clear();
1964  m_refPoints.clear();
1965  m_adjPoints.clear();
1966  m_tiePointIdCounter = 0;
1967  m_tiePointsSelected.clear();
1969 
1971 
1972 }
void set(te::map::AbstractLayerPtr layer, bool setFullScaleBox=false)
This method is used to set the selected layer.
te::color::RGBAColor ** m_rgbaMarkSelected
Represents the pattern of a selected tie point.
void getTiePointsIdxCoords(std::vector< te::gm::GTParameters::TiePoint > &tiePoints) const
Get the current acquired tie-points.
Near neighborhood interpolation method.
std::map< unsigned int, TiePointData > TPContainerT
Tie-pints container type definition.
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
The generated tie-points (te::gm::GTParameters::TiePoint::first are raster 1 line/column indexes...
te::qt::widgets::RasterNavigatorWidget * m_refNavigator
Reference raster navigator.
std::vector< TiePoint > m_tiePoints
Tie points.
Definition: GTParameters.h:95
void refCoordMoved(double xorig, double yorig, double xnew, double ynew)
double y
y-coordinate.
Definition: Coord2D.h:114
std::vector< unsigned int > m_inRaster2Bands
Bands to be used from the input raster 2.
te::se::Mark * m_markRef
Represents the mark of a reference tie point.
te::map::AbstractLayerPtr m_refLayer
Layer with reference imagem.
bool m_enableProgress
Enable/Disable the progress interface (default:false).
unsigned int m_raster2TargetAreaLineStart
The first line of the raster 2 target area to process (default:0 - The entire raster will be consider...
te::qt::widgets::RasterNavigatorWidget * m_adjNavigator
Adjust raster navigator.
double x
x-coordinate.
Definition: Coord2D.h:113
This file has the TiePointLocatorWidget class.
QPixmap getPixmap(te::color::RGBAColor **rgba)
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
const te::qt::widgets::TiePointData::TPContainerT & getTiePointContainer()
Get tie point data container.
te::gm::GTParameters::TiePoint m_tiePoint
Tie point coordinates - std::pair< Reference Raster Line/Col Coord,. Adjust Raster Line/Col Coord >...
std::map< unsigned int, QPointF > m_refPoints
Display reference coordinates.
TEQTWIDGETSEXPORT void AddFilePathToSettings(const QString &path, const QString &typeFile)
Save last used path in QSettings.
double m_subSampleOptimizationRescaleFactor
Sub-sampled optimization tie-points search rescale factor (Tie-ponts will be searched into a subsabmp...
te::rst::Raster const * m_inRaster2Ptr
Input raster 2.
std::map< unsigned int, QPointF > m_adjPoints
Display adjust coordinates.
void tiePointsTableUpdate()
Uptate the tie-points table widget.
double m_urx
Upper right corner x-coordinate.
void setPoints(std::map< unsigned int, QPointF > *points)
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
TiePointLocatorWidget(QWidget *parent=0, Qt::WindowFlags f=0)
A widget to control the display of a set of layers.
void onAdjPointMoved(double xorig, double yorig, double xnew, double ynew)
This file has the TiePointLocatorParametersWidget class.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
double getY() const
It returns the y-coordinate.
Definition: Coord2D.h:108
static te::dt::Date ds(2010, 01, 01)
te::rp::TiePointsLocator::InputParameters getTiePointInputParameters()
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
InterpolationMethod
Allowed interpolation methods.
te::qt::widgets::TiePointLocatorParametersWidget * m_tiePointParameters
Tie Point parameters widget.
void createSelection(int initialIdx, int nPos)
static const std::string getLastLogStr()
Returns the last log string generated by this module.
std::pair< Coord2D, Coord2D > TiePoint
Tie point type definition.
Definition: GTParameters.h:59
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
FirstCoordType m_tiePointFirstCoord
Type of coord if the tie-point has the first part set;.
void setSourceSRID(int sourceSRID)
Sets the source SRS identifier.
Definition: Converter.cpp:104
Ui::TiePointLocatorWidgetForm * getForm() const
void getOutputResolution(double &resX, double &resY)
void onRefPointMoved(double xorig, double yorig, double xnew, double ynew)
te::qt::widgets::TiePointData::TPContainerT m_tiePoints
Internal tie-points container.
te::se::Mark * m_markSelected
Represents the mark of a selected tie point.
Coord2D getCenter() const
It returns the rectangle&#39;s center coordinate.
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
Definition: StringUtils.h:221
unsigned int m_raster1TargetAreaHeight
The raster 1 target area height (default:0 - The entire raster will be considered).
const TiePointData & operator=(const TiePointData &other)
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
Definition: STLUtils.h:131
void setWindow(const double &llx, const double &lly, const double &urx, const double &ury)
It sets the world (or window) coordinates area (supposing a cartesian reference system).
double m_llx
Lower left corner x-coordinate.
static MarkRendererManager & getInstance()
It returns a reference to the singleton instance.
te::map::AbstractLayerPtr m_adjLayer
Layer with adjust imagem.
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
std::unique_ptr< Ui::TiePointLocatorWidgetForm > m_ui
double m_pixelSizeXRelation
The pixel resolution relation m_pixelSizeXRelation = raster1_pixel_res_x / raster2_pixel_res_x (defau...
unsigned int getNumberOfRows() const
Returns the raster number of rows.
std::vector< unsigned int > m_inRaster1Bands
Bands to be used from the input raster 1.
te::se::Mark * m_markUnselected
Represents the mark of a unselected tie point.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
te::color::RGBAColor ** m_rgbaMarkRef
Represents the pattern of reference tie point.
te::gm::Polygon * p
bool m_selected
Tie point selection status;.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
te::gm::GTParameters::TiePoint m_currentTiePoint
The current tie-point.
std::set< int > m_tiePointsSelected
List of selected tie points.
FirstCoordType getFirstTiePointCoord(te::gm::Coord2D &firstCoord)
Get tie point reference coord that does not have an adjust coordenate or \ tie point adjust coord tha...
Grid * getGrid()
It returns the raster grid.
TESEEXPORT Mark * CreateMark(const std::string &wellKnownName, Stroke *stroke, Fill *fill)
Creates a mark.
static GeometricTransformation * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
TiePointsLocator output parameters.
#define PATTERN_SIZE
te::rst::Raster const * m_inRaster1Ptr
Input raster 1.
double m_lly
Lower left corner y-coordinate.
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
Definition: Converter.h:53
TESEEXPORT Stroke * CreateStroke(const std::string &color, const std::string &width)
Creates a stroke.
Bicubic interpolation method.
void getTiePoints(std::vector< te::gm::GTParameters::TiePoint > &tiePoints) const
Get the current acquired tie-points.
Ui::TiePointLocatorParametersWidgetForm * getWidgetForm()
Tie points locator.
This class is used to define a widget for tie point parameters acquirement.
double getX() const
It returns the x-coordinate.
Definition: Coord2D.h:102
unsigned int m_raster1TargetAreaWidth
The raster 1 target area width (default:0 - The entire raster will be considered).
void setX(const double &x)
It sets the Point x-coordinate value.
Definition: Point.h:145
double m_pixelSizeYRelation
The pixel resolution relation m_pixelSizeYRelation = raster1_pixel_res_y / raster2_pixel_res_y (defau...
virtual QPixmap * getDraftPixmap() const
It returns the map display draft pixmap.
unsigned int m_raster1TargetAreaLineStart
The first line of the raster 1 target area to process (default:0 - The entire raster will be consider...
TEQTWIDGETSEXPORT QImage * GetImage(te::color::RGBAColor **img, int width, int height)
It creates a QImage from an RGBA color array.
double m_ury
Upper right corner y-coordinate.
This class is used to navigate over a DataSetLayer (having a raster representation) and given a set o...
unsigned int m_raster2TargetAreaColStart
The first column of the raster 2 target area to process (default:0 - The entire raster will be consid...
void onTiePointsTableWidgetItemChanged(QTableWidgetItem *)
te::color::RGBAColor ** m_rgbaMarkUnselected
Represents the pattern of a unselected tie point.
A Stroke specifies the appearance of a linear geometry.
Definition: Stroke.h:67
unsigned int m_raster2TargetAreaHeight
The raster 2 target area height (default:0 - The entire raster will be considered).
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
void setAdjustLayer(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer used to be the adjust layer.
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
te::qt::widgets::MapDisplay * getDisplay()
Bilinear interpolation method.
This file has the RasterNavigatorWidget class.
2D Geometric transformation parameters.
Definition: GTParameters.h:50
void transformationInfoUpdate()
Uptate the current transformation information widgets.
TEQTWIDGETSEXPORT QString GetFilePathFromSettings(const QString &typeFile)
Returns the value of the last saved file path for the typeFile required.
TiePointAcquisitionType m_acqType
Acquisition type.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
void setY(const double &y)
It sets the Point y-coordinate value.
Definition: Point.h:159
void adjCoordMoved(double xorig, double yorig, double xnew, double ynew)
A dialog used to build a SRSManagerDialog element.
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
te::rst::Interpolator::Method getInterpolatorMethod() const
#define TE_TRANSPARENT
For an RGBA color this is the value of the alpha-channel for totally transparent. ...
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
unsigned int m_tiePointIdCounter
A ID counter for new tie pointes inserted into m_tiePoints;.
void setReferenceLayer(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer used to be the reference layer.
unsigned int m_raster1TargetAreaColStart
The first column of the raster 2 target area to process (default:0 - The entire raster will be consid...
unsigned int m_raster2TargetAreaWidth
The raster 2 target area width (default:0 - The entire raster will be considered).
const std::pair< int, std::string > & getSelectedSRS() const
Returns the selected SRS in the window.
unsigned int col
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
TESEEXPORT Fill * CreateFill(const std::string &color, const std::string &opacity)
Creates a fill.