All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TiePointsLocatorDialog.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/widgets/rp/TiePointsLocatorDialog.cpp
22 
23  \brief A dialog used to execute tie points location.
24 */
25 
26 #include "TiePointsLocatorDialog.h"
28 #include "../Exception.h"
29 #include "../canvas/MapDisplay.h"
30 #include "../canvas/Canvas.h"
31 #include "../../widgets/tools/ZoomLeftAndRightClick.h"
32 #include "../../widgets/tools/CoordTracking.h"
33 #include "../../../raster/Grid.h"
34 #include "../../../geometry/GTFactory.h"
35 #include "../../../geometry/Point.h"
36 #include "../../../geometry/Envelope.h"
37 #include "../../../maptools/Utils.h"
38 #include "../../../rp/TiePointsLocator.h"
39 
40 #include <ui_TiePointsLocatorForm.h>
41 
42 #include <QtCore/QString>
43 #include <QGridLayout>
44 #include <QKeyEvent>
45 #include <QLineEdit>
46 #include <QColor>
47 
48 #define TPLDIALOG_P_PATTERN_W 11
49 
50 namespace te
51 {
52  namespace qt
53  {
54  namespace widgets
55  {
58  : QObject( parent ), m_mDisplay( parent )
59  {
60  }
61 
63  {
64  }
65 
67  QEvent * event )
68  {
69  if( event->type() == QEvent::Enter )
70  {
71  m_mDisplay->grabKeyboard();
72  }
73  else if( event->type() == QEvent::Leave )
74  {
75  m_mDisplay->releaseKeyboard();
76  }
77  else if( event->type() == QEvent::KeyPress )
78  {
79  if( m_mDisplay->underMouse() )
80  {
81  emit( keyPressed( ((QKeyEvent*)event)->key() ) );
82  }
83  }
84 
85  return false;
86  }
87 
89  : m_acqType( InvalidAcquisitionT )
90  {
91  }
92 
95  {
96  operator=( other );
97  }
98 
100  {
101  }
102 
105  {
106  m_acqType = other.m_acqType;
107  m_tiePoint = other.m_tiePoint;
108  return other;
109  }
110 
112  const te::map::DataSetLayerPtr& inLayer1Ptr,
113  const te::map::DataSetLayerPtr& inLayer2Ptr,
114  QWidget* parent, Qt::WindowFlags f )
115  : QDialog( parent, f ),
116  m_inLayer1Ptr( inLayer1Ptr ),
117  m_inLayer2Ptr( inLayer2Ptr ),
119  m_lastInsertedTPID( 0 )
120  {
121  if( inLayer1Ptr.get() == 0 ) throw te::qt::widgets::Exception(
122  "Invalid data set layer pointer" );
123  if( inLayer1Ptr.get() == 0 ) throw te::qt::widgets::Exception(
124  "Invalid data set layer pointer" );
125 
126  m_uiPtr = new Ui::TiePointsLocatorForm;
127  m_uiPtr->setupUi(this);
128 
131 
133  m_advDialogPtr->m_inputParameters.m_inMaskRaster1Ptr = m_raster1;
134  m_advDialogPtr->m_inputParameters.m_inMaskRaster2Ptr = m_raster2;
135 
136  QGridLayout* gridLayout1 = new QGridLayout( m_uiPtr->m_image1Frame );
137  QGridLayout* gridLayout2 = new QGridLayout( m_uiPtr->m_image2Frame );
138 
139  // map display 1
140 
142  m_uiPtr->m_image1Frame->size(), m_uiPtr->m_image1Frame );
143  m_mapDisplay1->setMouseTracking ( true );
144  gridLayout1->addWidget( m_mapDisplay1 );
146  std::list< te::map::AbstractLayerPtr > layerList1;
147  layerList1.push_back( m_inLayer1Ptr );
148  m_mapDisplay1->setLayerList( layerList1 );
150  te::gm::Envelope displayExtent1(*(m_raster1->getExtent()));
151  m_mapDisplay1->setExtent( displayExtent1 );
152 
153  // map display 2
154 
156  m_uiPtr->m_image2Frame->size(), m_uiPtr->m_image2Frame );
157  m_mapDisplay2->setMouseTracking ( true );
158  gridLayout2->addWidget( m_mapDisplay2 );
160  std::list< te::map::AbstractLayerPtr > layerList2;
161  layerList2.push_back( m_inLayer2Ptr );
162  m_mapDisplay2->setLayerList( layerList2 );
163  m_mapDisplay2->setSRID(m_raster2->getSRID());
164  te::gm::Envelope displayExtent2(*(m_raster2->getExtent()));
165  m_mapDisplay1->setExtent( displayExtent2 );
166 
167  // Events
168 
171 
174 
177 
178  m_mapDisplay1->installEventFilter( m_zoomClickEvent1 );
179  m_mapDisplay2->installEventFilter( m_zoomClickEvent2 );
180 
181  m_mapDisplay1->installEventFilter( m_coordTracking1 );
182  m_mapDisplay2->installEventFilter( m_coordTracking2 );
183 
184  m_mapDisplay1->installEventFilter( m_mDEventFilter1 );
185  m_mapDisplay2->installEventFilter( m_mDEventFilter2 );
186 
187 
188  // Signals & slots
189 
190  connect(m_uiPtr->m_okPushButton, SIGNAL(clicked()), this, SLOT(on_okPushButton_clicked()));
191  connect(m_uiPtr->m_autoAcquireTiePointsPushButton, SIGNAL(clicked()), this, SLOT(on_autoAcquireTiePointsPushButton_clicked()));
192  connect(m_uiPtr->m_selectAllPushButton, SIGNAL(clicked()), this, SLOT(on_selectAllPushButton_clicked()));
193  connect(m_uiPtr->m_unselectAllPushButton, SIGNAL(clicked()), this, SLOT(on_unselectAllPushButton_clicked()));
194  connect(m_uiPtr->m_deleteSelectedPushButton, SIGNAL(clicked()), this, SLOT(on_deleteSelectedPushButton_clicked()));
195  connect(m_uiPtr->m_advancedOptionsPushButton, SIGNAL(clicked()), this, SLOT(on_advancedOptionsPushButton_clicked()));
196  connect(m_uiPtr->m_addPushButton, SIGNAL(clicked()), this, SLOT(on_addPushButton_clicked()));
197  connect(m_coordTracking1, SIGNAL(coordTracked(QPointF&)), this, SLOT(on_mapDisplay1_coordTracked(QPointF&)));
198  connect(m_coordTracking2, SIGNAL(coordTracked(QPointF&)), this, SLOT(on_mapDisplay2_coordTracked(QPointF&)));
199  connect(m_mDEventFilter1, SIGNAL(keyPressed(int)), this, SLOT(on_mapDisplay1_keyPressed(int)));
200  connect(m_mDEventFilter2, SIGNAL(keyPressed(int)), this, SLOT(on_mapDisplay2_keyPressed(int)));
201  connect(m_uiPtr->m_tiePointsTableWidget, SIGNAL(itemSelectionChanged()), this, SLOT(on_tiePointsTableWidget_itemSelectionChanged()));
202  connect(m_mapDisplay1, SIGNAL(extentChanged()), this, SLOT(on_mapDisplay1_extentChanged()));
203  connect(m_mapDisplay2, SIGNAL(extentChanged()), this, SLOT(on_mapDisplay2_extentChanged()));
204 
205  // fill form
206 
207  for( unsigned band1Idx = 0 ; band1Idx < m_raster1->getNumberOfBands() ;
208  ++band1Idx )
209  m_uiPtr->m_referenceBand1ComboBox->addItem( QString::number( band1Idx ) );
210 
211  for( unsigned band2Idx = 0 ; band2Idx < m_raster2->getNumberOfBands() ;
212  ++band2Idx )
213  m_uiPtr->m_referenceBand2ComboBox->addItem( QString::number( band2Idx ) );
214 
215  // create points draw patterns
216 
220 
221  for( unsigned int line = 0 ; line < TPLDIALOG_P_PATTERN_W ; ++line )
222  {
226 
227  for( unsigned int col = 0 ; col < TPLDIALOG_P_PATTERN_W ; ++col )
228  {
229  if( ( line == col ) || ( line == ( TPLDIALOG_P_PATTERN_W - col - 1 ) ) )
230  {
231  m_selectedPointPattern[ line ][ col ].setColor( 255, 0, 0, TE_OPAQUE );
232  m_unselectedPointPattern[ line ][ col ].setColor( 0, 255, 0, TE_OPAQUE );
233  m_tempPointPattern[ line ][ col ].setColor( 0, 0, 255, TE_OPAQUE );
234  }
235  else
236  {
237  m_selectedPointPattern[ line ][ col ].setColor( 0, 0, 0, TE_TRANSPARENT );
238  m_unselectedPointPattern[ line ][ col ].setColor( 0, 0, 0, TE_TRANSPARENT );
239  m_tempPointPattern[ line ][ col ].setColor( 0, 0, 0, TE_TRANSPARENT );
240  }
241  }
242  }
243  }
244 
246  {
247  // assuring that the keyboard is released from the map displays
248 
249  m_mapDisplay1->releaseKeyboard();
250  m_mapDisplay2->releaseKeyboard();
251 
252  delete m_raster1;
253  delete m_raster2;
254 
255  // delete points draw patterns
256 
257  for( unsigned int line = 0 ; line < TPLDIALOG_P_PATTERN_W ; ++line )
258  {
259  delete[] m_selectedPointPattern[ line ];
260  delete[] m_unselectedPointPattern[ line ];
261  delete[] m_tempPointPattern[ line ];
262  }
263 
264  delete[] m_selectedPointPattern;
265  delete[] m_unselectedPointPattern;
266  delete[] m_tempPointPattern;
267 
268  // detroying the UI
269 
270  delete m_uiPtr;
271  }
272 
273  void TiePointsLocatorDialog::getTiePoints( std::vector< te::gm::GTParameters::TiePoint >&
274  tiePoints ) const
275  {
276  tiePoints.clear();
277 
278  TPContainerT::const_iterator itB = m_tiePoints.begin();
279  const TPContainerT::const_iterator itE = m_tiePoints.end();
280  tiePoints.reserve( m_tiePoints.size() );
281 
282  while( itB != itE )
283  {
284  tiePoints.push_back( itB->second.m_tiePoint );
285  ++itB;
286  }
287  }
288 
290  {
291  close();
292  }
293 
295  {
296  // creating the algorithm parameters
297 
300 
301  inputParams.m_inRaster1Ptr = m_raster1;
302  inputParams.m_inRaster2Ptr = m_raster2;
303 
304  te::gm::Envelope auxEnvelope1( m_mapDisplay1->getExtent() );
305  double r1LLX = 0;
306  double r1LLY = 0;
307  double r1URX = 0;
308  double r1URY = 0;
309  inputParams.m_inRaster1Ptr->getGrid()->geoToGrid(
310  auxEnvelope1.m_llx, auxEnvelope1.m_lly, r1LLX, r1LLY );
311  inputParams.m_inRaster1Ptr->getGrid()->geoToGrid(
312  auxEnvelope1.m_urx, auxEnvelope1.m_ury, r1URX, r1URY );
313  inputParams.m_raster1TargetAreaColStart = (unsigned int)std::max( 0.0,
314  r1LLX );
315  inputParams.m_raster1TargetAreaLineStart = (unsigned int)std::max( 0.0,
316  r1URY );
317  inputParams.m_raster1TargetAreaWidth = ( (unsigned int)std::min(
318  (double)inputParams.m_inRaster1Ptr->getNumberOfColumns(),
319  r1URX ) ) - inputParams.m_raster1TargetAreaColStart + 1;
320  inputParams.m_raster1TargetAreaHeight = ( (unsigned int)std::min(
321  (double)inputParams.m_inRaster1Ptr->getNumberOfRows(),
322  r1LLY ) ) - inputParams.m_raster1TargetAreaColStart + 1;
323 
324  te::gm::Envelope auxEnvelope2( m_mapDisplay2->getExtent() );
325  double r2LLX = 0;
326  double r2LLY = 0;
327  double r2URX = 0;
328  double r2URY = 0;
329  inputParams.m_inRaster2Ptr->getGrid()->geoToGrid(
330  auxEnvelope2.m_llx, auxEnvelope2.m_lly, r2LLX, r2LLY );
331  inputParams.m_inRaster2Ptr->getGrid()->geoToGrid(
332  auxEnvelope2.m_urx, auxEnvelope2.m_ury, r2URX, r2URY );
333  inputParams.m_raster2TargetAreaColStart = (unsigned int)std::max( 0.0,
334  r2LLX );
335  inputParams.m_raster2TargetAreaLineStart = (unsigned int)std::max( 0.0,
336  r2URY );
337  inputParams.m_raster2TargetAreaWidth = ( (unsigned int)std::min(
338  (double)inputParams.m_inRaster2Ptr->getNumberOfColumns(),
339  r2URX ) ) - inputParams.m_raster2TargetAreaColStart + 1;
340  inputParams.m_raster2TargetAreaHeight = ( (unsigned int)std::min(
341  (double)inputParams.m_inRaster2Ptr->getNumberOfRows(),
342  r2LLY ) ) - inputParams.m_raster2TargetAreaColStart + 1;
343 
344  inputParams.m_inRaster1Bands.push_back(
345  m_uiPtr->m_referenceBand1ComboBox->currentText().toUInt() );
346  inputParams.m_inRaster2Bands.push_back(
347  m_uiPtr->m_referenceBand2ComboBox->currentText().toUInt() );
348 
350 
351  // Looking for manual inserted tie-points for an initial estimate
352 
353  unsigned int manualTPNumber = 0;
354 
355  TPContainerT::const_iterator itB = m_tiePoints.begin();
356  const TPContainerT::const_iterator itE = m_tiePoints.end();
357  double coordDiffX = 0;
358  double coordDiffY = 0;
359 
360  while( itB != itE )
361  {
362  if( itB->second.m_acqType == TiePointData::ManualAcquisitionT )
363  {
364  coordDiffX = itB->second.m_tiePoint.first.x -
365  itB->second.m_tiePoint.second.x;
366  coordDiffY = itB->second.m_tiePoint.first.y -
367  itB->second.m_tiePoint.second.y;
368 // inputParams.m_maxR1ToR2Offset += std::max( inputParams.m_maxR1ToR2Offset,
369 // (unsigned int)std::ceil( std::sqrt( ( coordDiffX * coordDiffX ) +
370 // ( coordDiffY * coordDiffY ) ) ) );
371  ++manualTPNumber;
372  }
373 
374  ++itB;
375  }
376 
377 // if( inputParams.m_maxR1ToR2Offset > 0 )
378 // {
379 // inputParams.m_maxR1ToR2Offset /= manualTPNumber;
380 // inputParams.m_maxR1ToR2Offset += ( ( inputParams.m_maxR1ToR2Offset * 10 )
381 // / 100 );
382 // }
383 
384  // Executing the algorithm
385 
386  te::rp::TiePointsLocator algorithmInstance;
387 
388  if( algorithmInstance.initialize( inputParams ) )
389  {
390  if( algorithmInstance.execute( outputParams ) )
391  {
392  const unsigned int tpsNmb = (unsigned int)
393  outputParams.m_tiePoints.size();
394 
395  if( tpsNmb )
396  {
397  TiePointData auxTpData;
399 
400  for( unsigned int tpIdx = 0 ; tpIdx < tpsNmb ; ++tpIdx )
401  {
403  auxTpData.m_tiePoint = outputParams.m_tiePoints[ tpIdx ];
404  m_tiePoints[ m_lastInsertedTPID ] = auxTpData;
405  }
406 
408  }
409  }
410  }
411  }
412 
414  {
415  m_uiPtr->m_tiePointsTableWidget->selectAll();
416  }
417 
419  {
420  m_uiPtr->m_tiePointsTableWidget->clearSelection();
421  }
422 
424  {
425  const int rowCount =
426  m_uiPtr->m_tiePointsTableWidget->rowCount();
427  QTableWidgetItem* itemPtr = 0;
428  unsigned int tpID = 0;
429  TPContainerT::iterator deletionIt;
430 
431  for( int row = 0 ; row < rowCount ; ++row )
432  {
433  itemPtr = m_uiPtr->m_tiePointsTableWidget->item( row, 0 );
434 
435  if( itemPtr->isSelected() )
436  {
437  tpID = itemPtr->text().toUInt();
438  deletionIt = m_tiePoints.find( tpID );
439  assert( deletionIt != m_tiePoints.end() );
440  m_tiePoints.erase( deletionIt );
441  }
442  }
443 
444  if( m_tiePoints.empty() )
445  {
446  m_lastInsertedTPID = 0;
447  }
448 
450  }
451 
453  {
454  m_advDialogPtr->exec();
455  }
456 
458  {
459  if( ( ! m_uiPtr->m_x1LineEdit->text().isEmpty() ) &&
460  ( ! m_uiPtr->m_y1LineEdit->text().isEmpty() ) &&
461  ( ! m_uiPtr->m_x2LineEdit->text().isEmpty() ) &&
462  ( ! m_uiPtr->m_y2LineEdit->text().isEmpty() ) )
463  {
464  TiePointData auxTpData;
466  auxTpData.m_tiePoint.first.x = m_uiPtr->m_x1LineEdit->text().toDouble();
467  auxTpData.m_tiePoint.first.y = m_uiPtr->m_y1LineEdit->text().toDouble();
468  auxTpData.m_tiePoint.second.x = m_uiPtr->m_x2LineEdit->text().toDouble();
469  auxTpData.m_tiePoint.second.y = m_uiPtr->m_y2LineEdit->text().toDouble();
470 
472  m_tiePoints[ m_lastInsertedTPID ] = auxTpData;
473 
475  }
476  }
477 
479  {
482 
484  }
485 
487  {
489  {
491 
493 
494  TiePointData auxTpData;
497 
499  m_tiePoints[ m_lastInsertedTPID ] = auxTpData;
500 
502  }
503  }
504 
506  {
508  (double)coordinate.rx(), (double)coordinate.ry() );
509 
510  m_uiPtr->m_currentImage1LineLineEdit->setText( QString::number(
511  m_lastTrackedTiePoint.first.y ) );
512  m_uiPtr->m_currentImage1ColumnLineEdit->setText( QString::number(
513  m_lastTrackedTiePoint.first.x ) );
514  }
515 
517  {
519  (double)coordinate.rx(), (double)coordinate.ry() );
520 
521  m_uiPtr->m_currentImage2LineLineEdit->setText( QString::number(
522  m_lastTrackedTiePoint.second.y ) );
523  m_uiPtr->m_currentImage2ColumnLineEdit->setText( QString::number(
524  m_lastTrackedTiePoint.second.x ) );
525  }
526 
528  {
529  // building the geometric transformation
530 
531  te::gm::GTParameters transParams;
532 
533  TPContainerT::const_iterator tPIt = m_tiePoints.begin();
534  const TPContainerT::const_iterator tPItEnd = m_tiePoints.end();
535 
536  while( tPIt != tPItEnd )
537  {
538  transParams.m_tiePoints.push_back( tPIt->second.m_tiePoint );
539  ++tPIt;
540  }
541 
542  std::auto_ptr< te::gm::GeometricTransformation > transfPtr(
544 
545  if( transfPtr.get() )
546  {
547  if( ! transfPtr->initialize( transParams ) )
548  transfPtr.reset();
549  }
550 
551  // updating the tie points table
552 
553  m_uiPtr->m_tiePointsTableWidget->blockSignals( true );
554 
555  const int rowCount = m_uiPtr->m_tiePointsTableWidget->rowCount();
556 
557  for( int row = rowCount - 1 ; row >= 0 ; --row )
558  {
559  m_uiPtr->m_tiePointsTableWidget->removeRow( row );
560  }
561 
562  if( ! m_tiePoints.empty() )
563  {
564  tPIt = m_tiePoints.begin();
565  int currentRow = 0;
566  m_uiPtr->m_tiePointsTableWidget->setSortingEnabled( false );
567  double currTPError = 0;
568  QTableWidgetItem* newItemPtr = 0;
569 
570  while( tPIt != tPItEnd )
571  {
572  const te::gm::GTParameters::TiePoint& currTP = tPIt->second.m_tiePoint;
573  currTPError = transfPtr.get() ? transfPtr->getDirectMappingError(
574  currTP ) : 0.0;
575 
576  currentRow = m_uiPtr->m_tiePointsTableWidget->rowCount();
577 
578  m_uiPtr->m_tiePointsTableWidget->insertRow( currentRow );
579 
580  newItemPtr = new QTableWidgetItem( QString::number( tPIt->first ) );
581  newItemPtr->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
582  m_uiPtr->m_tiePointsTableWidget->setItem( currentRow, 0, newItemPtr );
583 
584  newItemPtr = new QTableWidgetItem( QString::number( currTPError ) );
585  newItemPtr->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
586  m_uiPtr->m_tiePointsTableWidget->setItem( currentRow, 1, newItemPtr );
587 
588  if( tPIt->second.m_acqType == TiePointData::ManualAcquisitionT )
589  {
590  newItemPtr = new QTableWidgetItem( QString( tr( "Manual" ) ) );
591  }
592  else
593  {
594  newItemPtr = new QTableWidgetItem( QString( tr( "Automatic" ) ) );
595  }
596  newItemPtr->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
597  m_uiPtr->m_tiePointsTableWidget->setItem( currentRow, 2, newItemPtr );
598 
599  newItemPtr = new QTableWidgetItem( QString::number( currTP.first.x ) );
600  newItemPtr->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
601  m_uiPtr->m_tiePointsTableWidget->setItem( currentRow, 3, newItemPtr );
602 
603  newItemPtr = new QTableWidgetItem( QString::number( currTP.first.y ) );
604  newItemPtr->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
605  m_uiPtr->m_tiePointsTableWidget->setItem( currentRow, 4, newItemPtr );
606 
607  newItemPtr = new QTableWidgetItem( QString::number( currTP.second.x ) );
608  newItemPtr->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
609  m_uiPtr->m_tiePointsTableWidget->setItem( currentRow, 5, newItemPtr );
610 
611  newItemPtr = new QTableWidgetItem( QString::number( currTP.second.y ) );
612  newItemPtr->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
613  m_uiPtr->m_tiePointsTableWidget->setItem( currentRow, 6, newItemPtr );
614 
615  ++tPIt;
616  }
617 
618  m_uiPtr->m_tiePointsTableWidget->setSortingEnabled( true );
619  m_uiPtr->m_tiePointsTableWidget->sortByColumn( 1, Qt::DescendingOrder );
620  }
621 
622  m_uiPtr->m_tiePointsTableWidget->blockSignals( false );
623 
627  }
628 
630  {
631  // creating the transformations parameters
632 
633  te::gm::GTParameters transParamsAllTP;
634  te::gm::GTParameters transParamsSelectedTP;
635  te::gm::GTParameters transParamsUnselectedTP;
636 
637  const int rowCount = m_uiPtr->m_tiePointsTableWidget->rowCount();
638  QTableWidgetItem* itemPtr = 0;
639  TPContainerT::const_iterator it;
640 
641  for( int row = 0 ; row < rowCount ; ++row )
642  {
643  itemPtr = m_uiPtr->m_tiePointsTableWidget->item( row, 0 );
644  it = m_tiePoints.find( itemPtr->text().toUInt() );
645  assert( it != m_tiePoints.end() );
646 
647  const te::gm::GTParameters::TiePoint& tiePoint = it->second.m_tiePoint;
648 
649  if( itemPtr->isSelected() )
650  {
651  transParamsSelectedTP.m_tiePoints.push_back( tiePoint );
652  }
653  else
654  {
655  transParamsUnselectedTP.m_tiePoints.push_back( tiePoint );
656  }
657 
658  transParamsAllTP.m_tiePoints.push_back( tiePoint );
659  }
660 
661  // instantiating the transformations
662 
663  std::auto_ptr< te::gm::GeometricTransformation > transfAllTPPtr(
665  if( transfAllTPPtr.get() )
666  {
667  if( ! transfAllTPPtr->initialize( transParamsAllTP ) )
668  transfAllTPPtr.reset();
669  }
670 
671  std::auto_ptr< te::gm::GeometricTransformation > transfSelectedTPPtr(
673  if( transfSelectedTPPtr.get() )
674  {
675  if( ! transfSelectedTPPtr->initialize( transParamsSelectedTP ) )
676  transfSelectedTPPtr.reset();
677  }
678 
679  std::auto_ptr< te::gm::GeometricTransformation > transfUnselectedTPPtr(
681  if( transfUnselectedTPPtr.get() )
682  {
683  if( ! transfUnselectedTPPtr->initialize( transParamsUnselectedTP ) )
684  transfUnselectedTPPtr.reset();
685  }
686 
687  // updating widgets
688 
689  m_uiPtr->m_tiePointsNumberLineEdit->setText( QString::number(
690  m_tiePoints.size() ) );
691 
692  if( transfAllTPPtr.get() )
693  m_uiPtr->m_transformationRMSEAllLineEdit->setText( QString::number(
694  transfAllTPPtr->getDirectMapRMSE() ) );
695  else
696  m_uiPtr->m_transformationRMSEAllLineEdit->setText("N/A");
697 
698  if( transfSelectedTPPtr.get() )
699  m_uiPtr->m_transformationRMSESelectedLineEdit->setText( QString::number(
700  transfSelectedTPPtr->getDirectMapRMSE() ) );
701  else
702  m_uiPtr->m_transformationRMSESelectedLineEdit->setText("N/A");
703 
704  if( transfUnselectedTPPtr.get() )
705  m_uiPtr->m_transformationRMSEunselectedLineEdit->setText( QString::number(
706  transfUnselectedTPPtr->getDirectMapRMSE() ) );
707  else
708  m_uiPtr->m_transformationRMSEunselectedLineEdit->setText("N/A");
709  }
710 
712  {
713  te::gm::Envelope auxEnvelope( m_mapDisplay1->getExtent() );
714  m_mapDisplay1->setExtent( auxEnvelope );
715  }
716 
718  {
719  te::gm::Envelope auxEnvelope( m_mapDisplay2->getExtent() );
720  m_mapDisplay2->setExtent( auxEnvelope );
721  }
722 
724  {
728  }
729 
731  {
732  const te::gm::Envelope& mapDisplayExtent =
734 
735  m_mapDisplay1->getDraftPixmap()->fill( QColor( 0, 0, 0, 0 ) );
736 
738  canvasInstance.setWindow( mapDisplayExtent.m_llx,
739  mapDisplayExtent.m_lly, mapDisplayExtent.m_urx,
740  mapDisplayExtent.m_ury );
741 
742  // Drawing the colected points
743 
744  const int rowCount =
745  m_uiPtr->m_tiePointsTableWidget->rowCount();
746  QTableWidgetItem* itemPtr = 0;
747  unsigned int tpID = 0;
748  TPContainerT::iterator tiePointsIt;
749  te::gm::Point auxPoint;
750  te::gm::Coord2D auxCoord2D;
751 
752  for( int row = 0 ; row < rowCount ; ++row )
753  {
754  itemPtr = m_uiPtr->m_tiePointsTableWidget->item( row, 0 );
755 
756  if( itemPtr->isSelected() )
757  {
758  canvasInstance.setPointPattern( m_selectedPointPattern,
760  }
761  else
762  {
763  canvasInstance.setPointPattern( m_unselectedPointPattern,
765  }
766 
767  tpID = itemPtr->text().toUInt();
768 
769  tiePointsIt = m_tiePoints.find( tpID );
770  assert( tiePointsIt != m_tiePoints.end() );
771 
773  tiePointsIt->second.m_tiePoint.first.x, tiePointsIt->second.m_tiePoint.first.y,
774  auxCoord2D.x, auxCoord2D.y );
775 
776  auxPoint.setX( auxCoord2D.x );
777  auxPoint.setY( auxCoord2D.y );
778 
779  canvasInstance.draw( &auxPoint );
780  }
781 
782  // Drawing the selected temporary point
783 
785  {
788  auxCoord2D.x, auxCoord2D.y );
789 
790  auxPoint.setX( auxCoord2D.x );
791  auxPoint.setY( auxCoord2D.y );
792 
793  canvasInstance.setPointPattern( m_tempPointPattern,
795 
796  canvasInstance.draw( &auxPoint );
797  }
798  }
799 
801  {
802  const te::gm::Envelope& mapDisplayExtent =
804 
805  m_mapDisplay2->getDraftPixmap()->fill( QColor( 0, 0, 0, 0 ) );
806 
808  canvasInstance.setWindow( mapDisplayExtent.m_llx,
809  mapDisplayExtent.m_lly, mapDisplayExtent.m_urx,
810  mapDisplayExtent.m_ury );
811 
812  // Drawing the colected points
813 
814  const int rowCount =
815  m_uiPtr->m_tiePointsTableWidget->rowCount();
816  QTableWidgetItem* itemPtr = 0;
817  unsigned int tpID = 0;
818  TPContainerT::iterator tiePointsIt;
819  te::gm::Point auxPoint;
820  te::gm::Coord2D auxCoord2D;
821 
822  for( int row = 0 ; row < rowCount ; ++row )
823  {
824  itemPtr = m_uiPtr->m_tiePointsTableWidget->item( row, 0 );
825 
826  if( itemPtr->isSelected() )
827  {
828  canvasInstance.setPointPattern( m_selectedPointPattern,
830  }
831  else
832  {
833  canvasInstance.setPointPattern( m_unselectedPointPattern,
835  }
836 
837  tpID = itemPtr->text().toUInt();
838 
839  tiePointsIt = m_tiePoints.find( tpID );
840  assert( tiePointsIt != m_tiePoints.end() );
841 
843  tiePointsIt->second.m_tiePoint.second.x, tiePointsIt->second.m_tiePoint.second.y,
844  auxCoord2D.x, auxCoord2D.y );
845 
846  auxPoint.setX( auxCoord2D.x );
847  auxPoint.setY( auxCoord2D.y );
848 
849  canvasInstance.draw( &auxPoint );
850  }
851  }
852  } // namespace qt
853  } // namespace qt
854 } // namespace te
855 
TiePointsLocatorDialogMDEventFilter * m_mDEventFilter1
Map display 1 event filter.
void refreshMapDisplay2()
Refresh map display 2.
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
Definition: Raster.cpp:104
This class implements a concrete tool to geographic zoom operation using the left and right mouse cli...
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
The generated tie-points (te::gm::GTParameters::TiePoint::first are raster 1 line/column indexes...
std::vector< TiePoint > m_tiePoints
Tie points.
Definition: GTParameters.h:95
double y
y-coordinate.
Definition: Coord2D.h:114
void setColor(const std::string &hexColor)
It sets the color using a two hexadecimal RGB-encoded color.
Definition: RGBAColor.h:329
std::vector< unsigned int > m_inRaster2Bands
Bands to be used from the input raster 2.
A event filter to handle map display events.
unsigned int m_raster2TargetAreaLineStart
The first line of the raster 2 target area to process (default:0 - The entire raster will be consider...
double x
x-coordinate.
Definition: Coord2D.h:113
te::qt::widgets::MapDisplay * m_mapDisplay1
Map display 1.
te::rp::TiePointsLocator::InputParameters m_inputParameters
The current parameters.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
Definition: Raster.cpp:213
unsigned int m_lastInsertedTPID
A ID counter for new tie pointes inserted into m_tiePoints;.
te::rst::Raster const * m_inRaster2Ptr
Input raster 2.
te::qt::widgets::MapDisplay * m_mapDisplay2
Map display 2.
void refreshMapDisplay1()
Refresh map display 1.
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
A widget to control the display of a set of layers.
Definition: MapDisplay.h:66
#define TPLDIALOG_P_PATTERN_W
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
CoordTracking * m_coordTracking2
Coord tracking (map display 2);.
te::qt::widgets::ZoomLeftAndRightClick * m_zoomClickEvent2
Zoom click event (map display 2).
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters.
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.
Definition: Grid.cpp:307
te::color::RGBAColor ** m_tempPointPattern
The display draw pattern used for temporary points.
virtual void setLayerList(const std::list< te::map::AbstractLayerPtr > &layers)
It sets the layer list to be showed in the Map Display.
Definition: MapDisplay.cpp:42
unsigned int m_raster1TargetAreaHeight
The raster 1 target area height (default:0 - The entire raster will be considered).
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).
Definition: Canvas.cpp:147
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
void tiePointsTableUpdate()
Uptate the tie-points table widget.
virtual void setResizePolicy(const ResizePolicy &policy)
Sets the resize policy to this map display.
Definition: MapDisplay.cpp:227
A point with x and y coordinate values.
Definition: Point.h:50
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
A dialog used to execute tie points location advanced options.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
Definition: Raster.cpp:208
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
Definition: Config.h:39
te::color::RGBAColor ** m_unselectedPointPattern
The display draw pattern used for unselected points.
std::vector< unsigned int > m_inRaster1Bands
Bands to be used from the input raster 1.
CoordTracking * m_coordTracking1
Coord tracking (map display 1);.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
TiePointsLocatorDialogMDEventFilter * m_mDEventFilter2
Map display 2 event filter.
TiePointsLocatorAdvancedDialog * m_advDialogPtr
User interface.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
Definition: MapDisplay.cpp:63
te::gm::GTParameters::TiePoint m_lastSelectedTiePoint
The last mouse tracked tie-point by pressing any key over the map areas.
Grid * getGrid()
It returns the raster grid.
Definition: Raster.cpp:94
TiePointsLocatorDialog(const te::map::DataSetLayerPtr &inLayer1Ptr, const te::map::DataSetLayerPtr &inLayer2Ptr, QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a basic dialog which is a child of parent, with widget flags set to f. ...
This class implements a concrete tool to geographic coordinate tracking on mouse move operation...
Definition: CoordTracking.h:52
static GeometricTransformation * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
TEMAPEXPORT te::rst::Raster * GetRaster(DataSetLayer *layer)
It gets the raster referenced by the given data set layer.
Definition: Utils.cpp:192
TiePointAcquisitionType m_acqType
Acquisition type.
TiePointsLocator output parameters.
te::rst::Raster const * m_inRaster1Ptr
Input raster 1.
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
A canvas built on top of Qt.
Definition: Canvas.h:54
Tie points locator.
int getSRID() const
Returns the raster spatial reference system identifier.
Definition: Raster.cpp:203
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:143
virtual QPixmap * getDraftPixmap() const
It returns the map display draft pixmap.
Definition: MapDisplay.cpp:222
unsigned int m_raster1TargetAreaLineStart
The first line of the raster 1 target area to process (default:0 - The entire raster will be consider...
te::rst::Raster * m_raster2
Input raster 1 pointer.
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
te::map::DataSetLayerPtr m_inLayer2Ptr
Input data set layer 1 pointer.
unsigned int m_raster2TargetAreaColStart
The first column of the raster 2 target area to process (default:0 - The entire raster will be consid...
#define TE_TRANSPARENT
For an RGBA color this is the value of the alpha-channel for totally transparent. ...
Definition: Config.h:46
unsigned int m_raster2TargetAreaHeight
The raster 2 target area height (default:0 - The entire raster will be considered).
A dialog used to execute tie points location advanced options.
boost::intrusive_ptr< DataSetLayer > DataSetLayerPtr
Definition: DataSetLayer.h:171
TiePointsLocatorDialogMDEventFilter(te::qt::widgets::MapDisplay *parent)
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
bool m_lastSelectedTiePointHasFirstOk
true if the last selected tie-point has the first part set;
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
Definition: Grid.cpp:301
void getTiePoints(std::vector< te::gm::GTParameters::TiePoint > &tiePoints) const
Get the current acquired tie-points.
te::qt::widgets::ZoomLeftAndRightClick * m_zoomClickEvent1
Input raster 2 pointer.
2D Geometric transformation parameters.
Definition: GTParameters.h:50
std::string m_geomTransfName
The name of the geometric transformation used to ensure tie-points consistency (see each te::gm::GTFa...
te::gm::GTParameters::TiePoint m_lastTrackedTiePoint
The last mouse tracked tie-point by analysing the mouse move over the map areas.
void setY(const double &y)
It sets the Point y-coordinate value.
Definition: Point.h:157
te::rst::Raster * m_raster1
Input data set layer 2 pointer.
TPContainerT m_tiePoints
Internal tie-points container.
virtual void setSRID(const int &srid, bool doRefresh=true)
It sets a new Spatial Reference System to be used by the Map Display.
Definition: MapDisplay.cpp:211
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display.
Definition: MapDisplay.cpp:150
A dialog used to execute tie points location.
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).
te::color::RGBAColor ** m_selectedPointPattern
The display draw pattern used for selected points.
const TiePointData & operator=(const TiePointData &other)
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.
void transformationInfoUpdate()
Uptate the current transformation information widgets.
te::gm::GTParameters::TiePoint m_tiePoint
Tie point coordinates.