Skip to content

Commit

Permalink
fix warning, indentation and little cleanup
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@13989 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Aug 1, 2010
1 parent d237cb2 commit 91f00be
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 64 deletions.
8 changes: 4 additions & 4 deletions src/plugins/georeferencer/qgsgcplistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ class QgsStandardItem : public QStandardItem
QgsStandardItem( QString text ) : QStandardItem( text )
{
// In addition to the DisplayRole, also set the user role, which is used for sorting.
setData( QVariant( text ), Qt::UserRole);
setData( QVariant( text ), Qt::UserRole );
setTextAlignment( Qt::AlignRight );
}

QgsStandardItem( int value ) : QStandardItem( QString::number( value ) )
{
// In addition to the DisplayRole, also set the user role, which is used for sorting.
// This is needed for numerical sorting to work corretly (otherwise sorting is lexicographic).
setData( QVariant( value ), Qt::UserRole);
setData( QVariant( value ), Qt::UserRole );
setTextAlignment( Qt::AlignCenter );
}

QgsStandardItem( double value ) : QStandardItem( QString::number( value, 'f', 2 ) )
{
// In addition to the DisplayRole, also set the user role, which is used for sorting.
// This is needed for numerical sorting to work corretly (otherwise sorting is lexicographic).
setData( QVariant( value ), Qt::UserRole);
setData( QVariant( value ), Qt::UserRole );
setTextAlignment( Qt::AlignRight );
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/georeferencer/qgsgcplistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ QgsGCPListWidget::QgsGCPListWidget( QWidget *parent )
proxyModel->setSortRole( Qt::UserRole );
setModel( proxyModel );
setSortingEnabled( true );

setContextMenuPolicy( Qt::CustomContextMenu );
setFocusPolicy( Qt::NoFocus );

Expand Down Expand Up @@ -99,7 +99,7 @@ void QgsGCPListWidget::updateGCPList()
void QgsGCPListWidget::itemDoubleClicked( QModelIndex index )
{
index = static_cast<const QSortFilterProxyModel*>( model() )->mapToSource( index );
QStandardItem *item = mGCPListModel->item( index.row(), 1);
QStandardItem *item = mGCPListModel->item( index.row(), 1 );
bool ok;
int id = item->text().toInt( &ok );

Expand Down Expand Up @@ -193,7 +193,7 @@ void QgsGCPListWidget::showContextMenu( QPoint p )
connect( removeAction, SIGNAL( triggered() ), this, SLOT( removeRow() ) );
m.addAction( removeAction );
m.exec( QCursor::pos(), removeAction );

index = static_cast<const QSortFilterProxyModel*>( model() )->mapToSource( index );
mPrevRow = index.row();
mPrevColumn = index.column();
Expand Down
57 changes: 23 additions & 34 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
#include "qgstransformsettingsdialog.h"

#include "qgsgeorefplugingui.h"
#include <assert.h>


QgsGeorefDockWidget::QgsGeorefDockWidget( const QString & title, QWidget * parent, Qt::WindowFlags flags )
Expand All @@ -85,9 +84,9 @@ QgsGeorefPluginGui::QgsGeorefPluginGui( QgisInterface* theQgisInterface, QWidget
, mTransformParam( QgsGeorefTransform::InvalidTransform )
, mIface( theQgisInterface )
, mLayer( 0 )
, mAgainAddRaster ( false )
, mAgainAddRaster( false )
, mMovingPoint( 0 )
, mMovingPointQgis ( 0 )
, mMovingPointQgis( 0 )
, mMapCoordsDialog( 0 )
, mUseZeroForTrans( false )
, mLoadInQgis( false )
Expand Down Expand Up @@ -254,7 +253,7 @@ void QgsGeorefPluginGui::openRaster()
QgsMapLayerRegistry::instance()->removeMapLayer( mLayer->getLayerID(), false );

// Add raster
addRaster(mRasterFileName);
addRaster( mRasterFileName );

// load previously added points
mGCPpointsFileName = mRasterFileName + ".points";
Expand Down Expand Up @@ -487,7 +486,7 @@ void QgsGeorefPluginGui::deleteDataPoint( const QPoint &coords )
delete *it;
mPoints.erase( it );
mGCPListWidget->updateGCPList();

mCanvas->refresh();
break;
}
Expand All @@ -497,7 +496,7 @@ void QgsGeorefPluginGui::deleteDataPoint( const QPoint &coords )

void QgsGeorefPluginGui::deleteDataPoint( int theGCPIndex )
{
assert( theGCPIndex >= 0 );
Q_ASSERT( theGCPIndex >= 0 );
delete mPoints.takeAt( theGCPIndex );
mGCPListWidget->updateGCPList();
updateGeorefTransform();
Expand All @@ -506,34 +505,24 @@ void QgsGeorefPluginGui::deleteDataPoint( int theGCPIndex )
void QgsGeorefPluginGui::selectPoint( const QPoint &p )
{
// Get Map Sender
QObject *tool = sender();
if ( tool == 0)
{
return;
}
bool isMapPlugin = ( (void *)tool == (void *)mToolMovePoint ) ? true : false;
bool isMapPlugin = sender() == mToolMovePoint;
QgsGeorefDataPoint *&mvPoint = isMapPlugin ? mMovingPoint : mMovingPointQgis;

for ( QgsGCPList::iterator it = mPoints.begin(); it != mPoints.end(); ++it )
{
if ( ( *it )->contains( p, isMapPlugin ) )
if (( *it )->contains( p, isMapPlugin ) )
{
isMapPlugin ? mMovingPoint = *it : mMovingPointQgis = *it;
mvPoint = *it;
break;
}
}

}

void QgsGeorefPluginGui::movePoint( const QPoint &p )
{
// Get Map Sender
QObject *tool = sender();
if ( tool == 0)
{
return;
}
bool isMapPlugin = ( (void *)tool == (void *)mToolMovePoint ) ? true : false;
QgsGeorefDataPoint *mvPoint = (isMapPlugin ? mMovingPoint : mMovingPointQgis);
bool isMapPlugin = sender() == mToolMovePoint;
QgsGeorefDataPoint *mvPoint = isMapPlugin ? mMovingPoint : mMovingPointQgis;

if ( mvPoint )
{
Expand All @@ -546,13 +535,14 @@ void QgsGeorefPluginGui::movePoint( const QPoint &p )
void QgsGeorefPluginGui::releasePoint( const QPoint &p )
{
// Get Map Sender
QObject *tool = sender();
if ( tool == 0)
if ( sender() == mToolMovePoint )
{
return;
mMovingPoint = 0;
}
else
{
mMovingPointQgis = 0;
}
bool isMapPlugin = ( (void *)tool == (void *)mToolMovePoint ) ? true : false;
isMapPlugin ? mMovingPoint = 0 : mMovingPointQgis = 0;
}

void QgsGeorefPluginGui::showCoordDialog( const QgsPoint &pixelCoords )
Expand Down Expand Up @@ -770,7 +760,7 @@ void QgsGeorefPluginGui::extentsChanged()
{
if ( QFile::exists( mRasterFileName ) )
{
addRaster(mRasterFileName);
addRaster( mRasterFileName );
}
else
{
Expand All @@ -781,10 +771,9 @@ void QgsGeorefPluginGui::extentsChanged()
}

// Registry layer QGis
void QgsGeorefPluginGui::layerWillBeRemoved ( QString theLayerId )
void QgsGeorefPluginGui::layerWillBeRemoved( QString theLayerId )
{
mAgainAddRaster = ( mLayer && mLayer->getLayerID().compare(theLayerId) == 0 )
? true : false;
mAgainAddRaster = mLayer && mLayer->getLayerID().compare( theLayerId ) == 0;
}

// ------------------------------ private ---------------------------------- //
Expand Down Expand Up @@ -1032,15 +1021,15 @@ void QgsGeorefPluginGui::setupConnections()
connect( mCanvas, SIGNAL( zoomLastStatusChanged( bool ) ), mActionZoomLast, SLOT( setEnabled( bool ) ) );
connect( mCanvas, SIGNAL( zoomNextStatusChanged( bool ) ), mActionZoomNext, SLOT( setEnabled( bool ) ) );
// Connect when one Layer is removed - Case where change the Projetct in QGIS
connect( QgsMapLayerRegistry::instance() , SIGNAL( layerWillBeRemoved (QString) ), this, SLOT( layerWillBeRemoved (QString) ) );
connect( QgsMapLayerRegistry::instance() , SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( layerWillBeRemoved( QString ) ) );

// Connect extents changed - Use for need add again Raster
connect( mCanvas, SIGNAL( extentsChanged () ), this, SLOT( extentsChanged() ) );
connect( mCanvas, SIGNAL( extentsChanged() ), this, SLOT( extentsChanged() ) );

}

// Mapcanvas Plugin
void QgsGeorefPluginGui::addRaster(QString file)
void QgsGeorefPluginGui::addRaster( QString file )
{
mLayer = new QgsRasterLayer( file, "Raster" );

Expand Down
46 changes: 23 additions & 23 deletions src/plugins/georeferencer/qgsleastsquares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,12 @@ void QgsLeastSquares::projective( std::vector<QgsPoint> mapCoords,

// GSL does not support a full SVD, so we artificially add a linear dependent row
// to the matrix in case the system is underconstrained.
uint m = std::max(9u, (uint)mapCoords.size()*2u);
uint m = std::max( 9u, ( uint )mapCoords.size() * 2u );
uint n = 9;
gsl_matrix *S = gsl_matrix_alloc ( m, n );
gsl_matrix *S = gsl_matrix_alloc( m, n );

for ( uint i = 0; i < mapCoords.size(); i++ ) {
for ( uint i = 0; i < mapCoords.size(); i++ )
{
gsl_matrix_set( S, i*2, 0, pixelCoords[i].x() );
gsl_matrix_set( S, i*2, 1, -pixelCoords[i].y() );
gsl_matrix_set( S, i*2, 2, 1.0 );
Expand All @@ -201,51 +202,50 @@ void QgsLeastSquares::projective( std::vector<QgsPoint> mapCoords,
gsl_matrix_set( S, i*2, 5, 0.0 );

gsl_matrix_set( S, i*2, 6, -mapCoords[i].x()* pixelCoords[i].x() );
gsl_matrix_set( S, i*2, 7, -mapCoords[i].x()*-pixelCoords[i].y() );
gsl_matrix_set( S, i*2, 7, -mapCoords[i].x()* -pixelCoords[i].y() );
gsl_matrix_set( S, i*2, 8, -mapCoords[i].x()*1.0 );

gsl_matrix_set( S, i*2+1, 0, 0.0 );
gsl_matrix_set( S, i*2+1, 1, 0.0 );
gsl_matrix_set( S, i*2+1, 2, 0.0 );
gsl_matrix_set( S, i*2 + 1, 0, 0.0 );
gsl_matrix_set( S, i*2 + 1, 1, 0.0 );
gsl_matrix_set( S, i*2 + 1, 2, 0.0 );

gsl_matrix_set( S, i*2+1, 3, pixelCoords[i].x() );
gsl_matrix_set( S, i*2+1, 4, -pixelCoords[i].y() );
gsl_matrix_set( S, i*2+1, 5, 1.0 );
gsl_matrix_set( S, i*2 + 1, 3, pixelCoords[i].x() );
gsl_matrix_set( S, i*2 + 1, 4, -pixelCoords[i].y() );
gsl_matrix_set( S, i*2 + 1, 5, 1.0 );

gsl_matrix_set( S, i*2+1, 6, -mapCoords[i].y()* pixelCoords[i].x() );
gsl_matrix_set( S, i*2+1, 7, -mapCoords[i].y()*-pixelCoords[i].y() );
gsl_matrix_set( S, i*2+1, 8, -mapCoords[i].y()*1.0 );
gsl_matrix_set( S, i*2 + 1, 6, -mapCoords[i].y()* pixelCoords[i].x() );
gsl_matrix_set( S, i*2 + 1, 7, -mapCoords[i].y()* -pixelCoords[i].y() );
gsl_matrix_set( S, i*2 + 1, 8, -mapCoords[i].y()*1.0 );
}

if (mapCoords.size() == 4)
if ( mapCoords.size() == 4 )
{
// The GSL SVD routine only supports matrices with rows >= columns (m >= n)
// Unfortunately, we can't use the SVD of the transpose (i.e. S^T = (U D V^T)^T = V D U^T)
// to work around this, because the solution lies in the right nullspace of S, and
// to work around this, because the solution lies in the right nullspace of S, and
// gsl only supports a thin SVD of S^T, which does not return these vectors.

// HACK: duplicate last row to get a 9x9 equation system
for (int j = 0; j < 9; j++)
for ( int j = 0; j < 9; j++ )
{
gsl_matrix_set( S, 8, j, gsl_matrix_get( S, 7, j) );
gsl_matrix_set( S, 8, j, gsl_matrix_get( S, 7, j ) );
}
}

// Solve Sh = 0 in the total least squares sense, i.e.
// with Sh = min and |h|=1. The solution "h" is given by the
// right singular eigenvector of S corresponding, to the smallest
// singular value (via SVD).
gsl_matrix *V = gsl_matrix_alloc (n, n);
gsl_vector *singular_values = gsl_vector_alloc(n);
gsl_vector *work = gsl_vector_alloc(n);
gsl_matrix *V = gsl_matrix_alloc( n, n );
gsl_vector *singular_values = gsl_vector_alloc( n );
gsl_vector *work = gsl_vector_alloc( n );

// V = n x n
// U = m x n (thin SVD) U D V^T
gsl_linalg_SV_decomp(S, V, singular_values, work);
gsl_linalg_SV_decomp( S, V, singular_values, work );

double eigen[9];
// Columns of V store the right singular vectors of S
for (int i = 0; i < n; i++)
for ( unsigned int i = 0; i < n; i++ )
{
H[i] = gsl_matrix_get( V, i, n - 1 );
}
Expand Down

0 comments on commit 91f00be

Please sign in to comment.