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" 
   40 #include <ui_TiePointsLocatorForm.h> 
   42 #include <QtCore/QString> 
   43 #include <QGridLayout> 
   48 #define TPLDIALOG_P_PATTERN_W 11 
   58         : QObject( parent ), m_mDisplay( parent )
 
   69         if( event->type() == QEvent::Enter )
 
   73         else if( event->type() == QEvent::Leave )
 
   77         else if( event->type() == QEvent::KeyPress )
 
   81             emit( 
keyPressed( ((QKeyEvent*)event)->key() ) );
 
   89       : m_acqType( InvalidAcquisitionT )
 
  114         QWidget* parent, Qt::WindowFlags f )
 
  115         : QDialog( parent, f ),
 
  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" );
 
  126         m_uiPtr = 
new Ui::TiePointsLocatorForm;
 
  133         m_advDialogPtr->m_inputParameters.m_inMaskRaster1Ptr = 
m_raster1;
 
  134         m_advDialogPtr->m_inputParameters.m_inMaskRaster2Ptr = 
m_raster2;
 
  136         QGridLayout* gridLayout1 = 
new QGridLayout( 
m_uiPtr->m_image1Frame );
 
  137         QGridLayout* gridLayout2 = 
new QGridLayout( 
m_uiPtr->m_image2Frame );
 
  146         std::list< te::map::AbstractLayerPtr >  layerList1;  
 
  160         std::list< te::map::AbstractLayerPtr >  layerList2;  
 
  209           m_uiPtr->m_referenceBand1ComboBox->addItem( QString::number( band1Idx ) );
 
  211         for( 
unsigned band2Idx = 0 ; band2Idx < m_raster2->getNumberOfBands() ;
 
  213           m_uiPtr->m_referenceBand2ComboBox->addItem( QString::number( band2Idx ) );
 
  229             if( ( line == col ) || ( line == ( TPLDIALOG_P_PATTERN_W - col - 1 ) ) )
 
  278         TPContainerT::const_iterator itB = 
m_tiePoints.begin();
 
  279         const TPContainerT::const_iterator itE = 
m_tiePoints.end();
 
  284           tiePoints.push_back( itB->second.m_tiePoint );
 
  310           auxEnvelope1.m_llx, auxEnvelope1.m_lly, r1LLX, r1LLY );
 
  312           auxEnvelope1.m_urx, auxEnvelope1.m_ury, r1URX, r1URY );
 
  330           auxEnvelope2.m_llx, auxEnvelope2.m_lly, r2LLX, r2LLY );
 
  332           auxEnvelope2.m_urx, auxEnvelope2.m_ury, r2URX, r2URY );
 
  345           m_uiPtr->m_referenceBand1ComboBox->currentText().toUInt() );
 
  347           m_uiPtr->m_referenceBand2ComboBox->currentText().toUInt() );
 
  353         unsigned int manualTPNumber = 0;
 
  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;
 
  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;              
 
  369               (
unsigned int)std::ceil( std::sqrt( ( coordDiffX * coordDiffX ) + 
 
  370               ( coordDiffY * coordDiffY ) ) ) );
 
  388         if( algorithmInstance.
initialize( inputParams ) )
 
  390           if( algorithmInstance.
execute( outputParams ) )
 
  392             const unsigned int tpsNmb = (
unsigned int)
 
  400               for( 
unsigned int tpIdx = 0 ; tpIdx < tpsNmb ; ++tpIdx )
 
  415         m_uiPtr->m_tiePointsTableWidget->selectAll();
 
  420         m_uiPtr->m_tiePointsTableWidget->clearSelection();
 
  426           m_uiPtr->m_tiePointsTableWidget->rowCount();
 
  427         QTableWidgetItem* itemPtr = 0;
 
  428         unsigned int tpID = 0;
 
  429         TPContainerT::iterator deletionIt;
 
  431         for( 
int row = 0 ; row < rowCount ; ++row )
 
  433           itemPtr = 
m_uiPtr->m_tiePointsTableWidget->item( row, 0 );
 
  435           if( itemPtr->isSelected() )
 
  437             tpID = itemPtr->text().toUInt();
 
  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() ) )
 
  508           (
double)coordinate.rx(), (double)coordinate.ry() );
 
  510         m_uiPtr->m_currentImage1LineLineEdit->setText( QString::number( 
 
  512         m_uiPtr->m_currentImage1ColumnLineEdit->setText( QString::number( 
 
  519           (
double)coordinate.rx(), (double)coordinate.ry() );
 
  521         m_uiPtr->m_currentImage2LineLineEdit->setText( QString::number( 
 
  523         m_uiPtr->m_currentImage2ColumnLineEdit->setText( QString::number( 
 
  533         TPContainerT::const_iterator tPIt = 
m_tiePoints.begin();
 
  534         const TPContainerT::const_iterator tPItEnd = 
m_tiePoints.end(); 
 
  536         while( tPIt != tPItEnd )   
 
  538           transParams.
m_tiePoints.push_back( tPIt->second.m_tiePoint );
 
  542         std::auto_ptr< te::gm::GeometricTransformation > transfPtr( 
 
  545         if( transfPtr.get() ) 
 
  547           if( ! transfPtr->initialize( transParams ) )
 
  553         m_uiPtr->m_tiePointsTableWidget->blockSignals( 
true );
 
  555         const int rowCount = 
m_uiPtr->m_tiePointsTableWidget->rowCount();
 
  557         for( 
int row = rowCount - 1 ; row >= 0 ; --row )
 
  559           m_uiPtr->m_tiePointsTableWidget->removeRow( row );
 
  566           m_uiPtr->m_tiePointsTableWidget->setSortingEnabled( 
false );
 
  567           double currTPError = 0;
 
  568           QTableWidgetItem* newItemPtr = 0;
 
  570           while( tPIt != tPItEnd )
 
  573             currTPError = transfPtr.get() ? transfPtr->getDirectMappingError( 
 
  576             currentRow = 
m_uiPtr->m_tiePointsTableWidget->rowCount();
 
  578             m_uiPtr->m_tiePointsTableWidget->insertRow( currentRow );
 
  580             newItemPtr = 
new QTableWidgetItem( QString::number( tPIt->first ) );
 
  581             newItemPtr->setFlags(  Qt::ItemIsSelectable | Qt::ItemIsEnabled );
 
  582             m_uiPtr->m_tiePointsTableWidget->setItem( currentRow, 0, newItemPtr );
 
  584             newItemPtr = 
new QTableWidgetItem( QString::number( currTPError ) );
 
  585             newItemPtr->setFlags(  Qt::ItemIsSelectable | Qt::ItemIsEnabled );
 
  586             m_uiPtr->m_tiePointsTableWidget->setItem( currentRow, 1, newItemPtr );
 
  590               newItemPtr = 
new QTableWidgetItem( QString( tr( 
"Manual" ) ) );
 
  594               newItemPtr = 
new QTableWidgetItem( QString( tr( 
"Automatic" ) ) );
 
  596             newItemPtr->setFlags(  Qt::ItemIsSelectable | Qt::ItemIsEnabled );
 
  597             m_uiPtr->m_tiePointsTableWidget->setItem( currentRow, 2, newItemPtr );
 
  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 );          
 
  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 );      
 
  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 );              
 
  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 );              
 
  618           m_uiPtr->m_tiePointsTableWidget->setSortingEnabled( 
true );
 
  619           m_uiPtr->m_tiePointsTableWidget->sortByColumn( 1, Qt::DescendingOrder );
 
  622         m_uiPtr->m_tiePointsTableWidget->blockSignals( 
false );
 
  637         const int rowCount = 
m_uiPtr->m_tiePointsTableWidget->rowCount();
 
  638         QTableWidgetItem* itemPtr = 0;
 
  639         TPContainerT::const_iterator it;
 
  641         for( 
int row = 0 ; row < rowCount ; ++row )
 
  643           itemPtr = 
m_uiPtr->m_tiePointsTableWidget->item( row, 0 );
 
  649           if( itemPtr->isSelected() )
 
  651             transParamsSelectedTP.
m_tiePoints.push_back( tiePoint );
 
  655             transParamsUnselectedTP.
m_tiePoints.push_back( tiePoint );
 
  658           transParamsAllTP.
m_tiePoints.push_back( tiePoint );
 
  663         std::auto_ptr< te::gm::GeometricTransformation > transfAllTPPtr( 
 
  665         if( transfAllTPPtr.get() ) 
 
  667           if( ! transfAllTPPtr->initialize( transParamsAllTP ) )
 
  668             transfAllTPPtr.reset();
 
  671         std::auto_ptr< te::gm::GeometricTransformation > transfSelectedTPPtr( 
 
  673         if( transfSelectedTPPtr.get() ) 
 
  675           if( ! transfSelectedTPPtr->initialize( transParamsSelectedTP ) )
 
  676             transfSelectedTPPtr.reset();
 
  679         std::auto_ptr< te::gm::GeometricTransformation > transfUnselectedTPPtr( 
 
  681         if( transfUnselectedTPPtr.get() ) 
 
  683           if( ! transfUnselectedTPPtr->initialize( transParamsUnselectedTP ) )
 
  684             transfUnselectedTPPtr.reset();
 
  689         m_uiPtr->m_tiePointsNumberLineEdit->setText( QString::number( 
 
  692         if( transfAllTPPtr.get() )
 
  693           m_uiPtr->m_transformationRMSEAllLineEdit->setText( QString::number( 
 
  694           transfAllTPPtr->getDirectMapRMSE() ) );
 
  696           m_uiPtr->m_transformationRMSEAllLineEdit->setText(
"N/A");
 
  698         if( transfSelectedTPPtr.get() )
 
  699           m_uiPtr->m_transformationRMSESelectedLineEdit->setText( QString::number( 
 
  700           transfSelectedTPPtr->getDirectMapRMSE() ) );
 
  702           m_uiPtr->m_transformationRMSESelectedLineEdit->setText(
"N/A");   
 
  704         if( transfUnselectedTPPtr.get() )
 
  705           m_uiPtr->m_transformationRMSEunselectedLineEdit->setText( QString::number( 
 
  706           transfUnselectedTPPtr->getDirectMapRMSE() ) );
 
  708           m_uiPtr->m_transformationRMSEunselectedLineEdit->setText(
"N/A");     
 
  739           mapDisplayExtent.
m_lly, mapDisplayExtent.
m_urx,
 
  740           mapDisplayExtent.
m_ury );
 
  745           m_uiPtr->m_tiePointsTableWidget->rowCount();
 
  746         QTableWidgetItem* itemPtr = 0;
 
  747         unsigned int tpID = 0;
 
  748         TPContainerT::iterator tiePointsIt;
 
  752         for( 
int row = 0 ; row < rowCount ; ++row )
 
  754           itemPtr = 
m_uiPtr->m_tiePointsTableWidget->item( row, 0 );
 
  756           if( itemPtr->isSelected() )
 
  767           tpID = itemPtr->text().toUInt();
 
  773             tiePointsIt->second.m_tiePoint.first.x, tiePointsIt->second.m_tiePoint.first.y,
 
  774             auxCoord2D.
x, auxCoord2D.
y );
 
  776           auxPoint.
setX( auxCoord2D.
x );
 
  777           auxPoint.
setY( auxCoord2D.
y );
 
  779           canvasInstance.draw( &auxPoint );            
 
  788             auxCoord2D.
x, auxCoord2D.
y );
 
  790           auxPoint.
setX( auxCoord2D.
x );
 
  791           auxPoint.
setY( auxCoord2D.
y );
 
  796           canvasInstance.draw( &auxPoint );  
 
  809           mapDisplayExtent.
m_lly, mapDisplayExtent.
m_urx,
 
  810           mapDisplayExtent.
m_ury );          
 
  815           m_uiPtr->m_tiePointsTableWidget->rowCount();
 
  816         QTableWidgetItem* itemPtr = 0;
 
  817         unsigned int tpID = 0;
 
  818         TPContainerT::iterator tiePointsIt;
 
  822         for( 
int row = 0 ; row < rowCount ; ++row )
 
  824           itemPtr = 
m_uiPtr->m_tiePointsTableWidget->item( row, 0 );
 
  826           if( itemPtr->isSelected() )
 
  837           tpID = itemPtr->text().toUInt();
 
  843             tiePointsIt->second.m_tiePoint.second.x, tiePointsIt->second.m_tiePoint.second.y,
 
  844             auxCoord2D.
x, auxCoord2D.
y );
 
  846           auxPoint.
setX( auxCoord2D.
x );
 
  847           auxPoint.
setY( auxCoord2D.
y );
 
  849           canvasInstance.draw( &auxPoint );            
 
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data. 
 
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
The generated tie-pionts (te::gm::GTParameters::TiePoint::first are raster 1 line/column indexes...
 
std::vector< TiePoint > m_tiePoints
Tie points. 
 
void setColor(const std::string &hexColor)
It sets the color using a two hexadecimal RGB-encoded color. 
 
unsigned int getNumberOfColumns() const 
Returns the raster number of columns. 
 
double m_urx
Upper right corner x-coordinate. 
 
#define TPLDIALOG_P_PATTERN_W
 
An utility struct for representing 2D coordinates. 
 
bool execute(AlgorithmOutputParameters &outputParams)
Executes the algorithm using the supplied parameters. 
 
std::pair< Coord2D, Coord2D > TiePoint
Tie point type definition. 
 
void geoToGrid(const double &x, const double &y, double &col, double &row) const 
Get the grid point associated to a spatial location. 
 
virtual void setLayerList(const std::list< te::map::AbstractLayerPtr > &layers)
It sets the layer list to be showed in the Map Display. 
 
double m_llx
Lower left corner x-coordinate. 
 
A point with x and y coordinate values. 
 
An Envelope defines a 2D rectangular region. 
 
A dialog used to execute tie points location advanced options. 
 
unsigned int getNumberOfRows() const 
Returns the raster number of rows. 
 
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque. 
 
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster. 
 
virtual const te::gm::Envelope & getExtent() const 
It returns the world extent showned by the MapDisplay. 
 
Grid * getGrid()
It returns the raster grid. 
 
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. 
 
TiePointsLocator output parameters. 
 
double m_lly
Lower left corner y-coordinate. 
 
int getSRID() const 
Returns the raster spatial reference system identifier. 
 
void setX(const double &x)
It sets the Point x-coordinate value. 
 
double m_ury
Upper right corner y-coordinate. 
 
#define TE_TRANSPARENT
For an RGBA color this is the value of the alpha-channel for totally transparent. ...
 
boost::intrusive_ptr< DataSetLayer > DataSetLayerPtr
 
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color. 
 
void gridToGeo(const double &col, const double &row, double &x, double &y) const 
Get the spatial location of a grid point. 
 
2D Geometric transformation parameters. 
 
void setY(const double &y)
It sets the Point y-coordinate value. 
 
A dialog used to execute tie points location. 
 
bool initialize(const AlgorithmInputParameters &inputParams)
Initialize the algorithm instance making it ready for execution.