Skip to content

Commit

Permalink
Merge with WARP_REFACTORING branch, which refactors and adds infrastr…
Browse files Browse the repository at this point in the history
…ucture for

gcp fitting and residual error reporting. Part 1/2 of new georeferencer.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12944 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mmassing committed Feb 14, 2010
1 parent 9fb3f85 commit 06ce53e
Show file tree
Hide file tree
Showing 21 changed files with 1,908 additions and 649 deletions.
6 changes: 6 additions & 0 deletions src/plugins/georeferencer/CMakeLists.txt
Expand Up @@ -3,27 +3,33 @@

SET (GEOREF_SRCS
qgsgeorefplugin.cpp
qgsgcplistmodel.cpp
qgsgeorefdatapoint.cpp
qgsimagewarper.cpp
qgsleastsquares.cpp
qgspointdialog.cpp
qgsgeorefdescriptiondialog.cpp
qgsgeorefwarpoptionsdialog.cpp
qgsgeoreftransform.cpp
mapcoordsdialog.cpp
qgsgcplistwidget.cpp
)

SET (GEOREF_UIS
qgspointdialogbase.ui
mapcoordsdialogbase.ui
qgsgeorefdescriptiondialogbase.ui
qgsgeorefwarpoptionsdialogbase.ui
qgsgcplistwidgetbase.ui
)

SET (GEOREF_MOC_HDRS
# qgsgcplistmodel.h
qgsgeorefplugin.h
qgspointdialog.h
mapcoordsdialog.h
qgsgeorefwarpoptionsdialog.h
qgsgcplistwidget.h
)

SET (GEOREF_RCCS georeferencer.qrc)
Expand Down
26 changes: 26 additions & 0 deletions src/plugins/georeferencer/qgsgcplist.h
@@ -0,0 +1,26 @@
/***************************************************************************
qgsgcplist.h - GCP list class
--------------------------------------
Date : 27-Feb-2009
Copyright : (c) 2009 by Manuel Massing
Email : m.massing at warped-space.de
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id */

#ifndef QGS_GCP_LIST_H
#define QGS_GCP_LIST_H

#include <vector>

class QgsGeorefDataPoint;

typedef std::vector<QgsGeorefDataPoint *> QgsGCPList;

#endif
147 changes: 147 additions & 0 deletions src/plugins/georeferencer/qgsgcplistmodel.cpp
@@ -0,0 +1,147 @@
/***************************************************************************
qgsgcplistmodel.cpp - Model implementation of GCPList Model/View
--------------------------------------
Date : 27-Feb-2009
Copyright : (c) 2009 by Manuel Massing
Email : m.massing at warped-space.de
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id */
#include "qgsgcplistmodel.h"

#include "qgsgeorefdatapoint.h"
#include "qgsgeoreftransform.h"

#include <cmath>
using namespace std;

template <class T> class QNumericItem : public QStandardItem {
public:
QNumericItem(T value) : QStandardItem(QString("%1").arg(value)), mValue(value)
{
}

bool operator < (const QStandardItem &other) const
{
const QNumericItem<T> *otherD = dynamic_cast<const QNumericItem<T> *>(&other);
if (otherD == NULL)
return false;
return mValue < otherD->mValue;
}
private:
T mValue;
};

QgsGCPListModel::QgsGCPListModel(QObject *parent) : QStandardItemModel(parent), mGCPList(0), mGeorefTransform(0)
{
}

void QgsGCPListModel::setGCPList(QgsGCPList *theGCPList)
{
mGCPList = theGCPList;
updateModel(true);
}

void QgsGCPListModel::setGeorefTransform(QgsGeorefTransform *theGeorefTransform)
{
mGeorefTransform = theGeorefTransform;
updateModel(true);
}

void QgsGCPListModel::onGCPListModified()
{
}

void QgsGCPListModel::onTransformationModified()
{
}

template <class T> QNumericItem<T> *create_item(const T value, bool isEditable = false)
{
QNumericItem<T> *item = new QNumericItem<T>(value);
item->setEditable(isEditable);
return item;
}

QStandardItem *create_std_item(const QString &S, bool isEditable = false)
{
QStandardItem *std_item = new QStandardItem(S);
std_item->setEditable(isEditable);
return std_item;
}

void QgsGCPListModel::updateModel(bool gcpsDirty)
{
clear();
if (!mGCPList)
return;

// Setup table header
QStringList itemLabels;
// Set column headers
itemLabels<<"id"<<"srcX"<<"srcY"<<"dstX"<<"dstY"<<"dX"<<"dY"<<"residual";
setColumnCount(itemLabels.size());
setHorizontalHeaderLabels(itemLabels);

setRowCount(mGCPList->size());


if (gcpsDirty && mGeorefTransform)
{
vector<QgsPoint> rC, mC;
// TODO: move this vector extraction snippet into QgsGCPList
for (int i = 0; i < mGCPList->size(); i++) {
rC.push_back((*mGCPList)[i]->pixelCoords());
mC.push_back((*mGCPList)[i]->mapCoords());
}

// TODO: the parameters should probable be updated externally (by user interaction)
mGeorefTransform->updateParametersFromGCPs(mC, rC);
}

for (int i = 0; i < mGCPList->size(); i++)
{
int j = 0;
QgsGeorefDataPoint &p = *(*mGCPList)[i];

setItem(i, j++, create_item<int>(i));
setItem(i, j++, create_item<double>( p.pixelCoords().x() ));
setItem(i, j++, create_item<double>(-p.pixelCoords().y() ));
setItem(i, j++, create_item<double>( p.mapCoords().x() ));
setItem(i, j++, create_item<double>( p.mapCoords().y() ));

double residual = -1.f;
double dX, dY;
// Calculate residual if transform is available and up-to-date
if (mGeorefTransform && mGeorefTransform->parametersInitialized())
{
QgsPoint dst;
// Transform from world to raster coordinate:
// This is the transform direction used by the warp operation.
// As transforms of order >=2 are not invertible, we are only
// interested in the residual in this direction
mGeorefTransform->transformWorldToRaster(p.mapCoords(), dst);
dX = (dst.x() - p.pixelCoords().x());
dY = (dst.y() - p.pixelCoords().y());
residual = sqrt(dX*dX + dY*dY);
}
if (residual >= 0.f) {
setItem(i, j++, create_item<double>(dX));
setItem(i, j++, create_item<double>(-dY));
setItem(i, j++, create_item<double>(residual));
}
else {
setItem(i, j++, create_std_item("n/a"));
setItem(i, j++, create_std_item("n/a"));
setItem(i, j++, create_std_item("n/a"));
}
}
//sort(); // Sort data
//reset(); // Signal to views that the model has changed
}
46 changes: 46 additions & 0 deletions src/plugins/georeferencer/qgsgcplistmodel.h
@@ -0,0 +1,46 @@
/***************************************************************************
qgsgcplistmodel.h - Model implementation of GCPList Model/View
--------------------------------------
Date : 27-Feb-2009
Copyright : (c) 2009 by Manuel Massing
Email : m.massing at warped-space.de
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSGCP_LIST_TABLE_VIEW_H
#define QGSGCP_LIST_TABLE_VIEW_H

#include <QTreeView>
#include <QStandardItemModel>

#include "qgsgcplist.h"

class QgsGeorefTransform;
//class QgsGCPList;
//^^currently a typedef, so no forward dec possible


class QgsGCPListModel : public QStandardItemModel {
//Q_OBJECT
public:
QgsGCPListModel(QObject *parent = NULL);

void setGCPList(QgsGCPList *theGCPList);
void setGeorefTransform(QgsGeorefTransform *theGeorefTransform);
public slots:
void onGCPListModified();
void onTransformationModified();
private:
void updateModel(bool gcpsDirty);

QgsGCPList *mGCPList;
QgsGeorefTransform *mGeorefTransform;
};

#endif
64 changes: 64 additions & 0 deletions src/plugins/georeferencer/qgsgcplistwidget.cpp
@@ -0,0 +1,64 @@
/***************************************************************************
qgsgcplistwidget.cpp - Widget for GCP list display
--------------------------------------
Date : 27-Feb-2009
Copyright : (c) 2009 by Manuel Massing
Email : m.massing at warped-space.de
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id */

#include <QHeaderView>

#include "qgsgcplistwidget.h"
#include "qgsgcplistmodel.h"

#include "qgspointdialog.h"

#include <iostream> //debugging

QgsGCPListWidget::QgsGCPListWidget(QWidget *parent) : QWidget(parent)
{
setupUi(this);
initialize();
}

void QgsGCPListWidget::initialize()
{
mGCPListModel = new QgsGCPListModel;
mGCPTableView->setModel(mGCPListModel);
mGCPTableView->setSortingEnabled(true);
mGCPTableView->verticalHeader()->hide();

connect(mGCPTableView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(itemDoubleClicked(const QModelIndex &)));
}

void QgsGCPListWidget::setGCPList(QgsGCPList *theGCPList)
{
mGCPListModel->setGCPList(theGCPList);
}

void QgsGCPListWidget::setGeorefTransform(QgsGeorefTransform *theGeorefTransform)
{
mGCPListModel->setGeorefTransform(theGeorefTransform);
}

void QgsGCPListWidget::itemDoubleClicked(const QModelIndex &index)
{
QStandardItem *item = mGCPListModel->item(index.row(), 0);
bool ok;
int id = item->text().toInt(&ok);

if (ok)
{
emit jumpToGCP(id);
}
}


46 changes: 46 additions & 0 deletions src/plugins/georeferencer/qgsgcplistwidget.h
@@ -0,0 +1,46 @@
/***************************************************************************
qgsgcplistwidget.h - Widget for GCP list display
--------------------------------------
Date : 27-Feb-2009
Copyright : (c) 2009 by Manuel Massing
Email : m.massing at warped-space.de
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id */
#ifndef QGS_GCP_LIST_WIDGET_H
#define QGS_GCP_LIST_WIDGET_H

#include <QWidget>
#include "ui_qgsgcplistwidgetbase.h"
#include "qgsgcplist.h"

//class QgsGCPList;
class QgsGCPListModel;
class QgsGeorefTransform;

class QgsGCPListWidget : public QWidget, private Ui::QgsGCPListWidgetBase {
Q_OBJECT
public:
QgsGCPListWidget(QWidget *parent = 0);

void setGCPList(QgsGCPList *theGCPList);
void setGeorefTransform(QgsGeorefTransform *theGeorefTransform);
public slots:
// This slot is called by the list view if an item is double-clicked
void itemDoubleClicked(const QModelIndex &);
signals:
void jumpToGCP(uint theGCPIndex);
private:
void initialize();

QgsGCPList *mGCPList;
QgsGCPListModel *mGCPListModel;
};

#endif
27 changes: 27 additions & 0 deletions src/plugins/georeferencer/qgsgcplistwidgetbase.ui
@@ -0,0 +1,27 @@
<ui version="4.0" >
<class>QgsGCPListWidgetBase</class>
<widget class="QWidget" name="QgsGCPListWidgetBase" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>584</width>
<height>412</height>
</rect>
</property>
<property name="windowTitle" >
<string>GCP List</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
<widget class="QTableView" name="mGCPTableView" />
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

0 comments on commit 06ce53e

Please sign in to comment.