Skip to content

Commit 1309434

Browse files
author
mmassing
committed
Merge with WARP_REFACTORING branch, which refactors and adds infrastructure for
gcp fitting and residual error reporting. Part 1/2 of new georeferencer. git-svn-id: http://svn.osgeo.org/qgis/trunk@12944 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent dcb4310 commit 1309434

21 files changed

+1908
-649
lines changed

src/plugins/georeferencer/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,33 @@
33

44
SET (GEOREF_SRCS
55
qgsgeorefplugin.cpp
6+
qgsgcplistmodel.cpp
67
qgsgeorefdatapoint.cpp
78
qgsimagewarper.cpp
89
qgsleastsquares.cpp
910
qgspointdialog.cpp
1011
qgsgeorefdescriptiondialog.cpp
1112
qgsgeorefwarpoptionsdialog.cpp
13+
qgsgeoreftransform.cpp
1214
mapcoordsdialog.cpp
15+
qgsgcplistwidget.cpp
1316
)
1417

1518
SET (GEOREF_UIS
1619
qgspointdialogbase.ui
1720
mapcoordsdialogbase.ui
1821
qgsgeorefdescriptiondialogbase.ui
1922
qgsgeorefwarpoptionsdialogbase.ui
23+
qgsgcplistwidgetbase.ui
2024
)
2125

2226
SET (GEOREF_MOC_HDRS
27+
# qgsgcplistmodel.h
2328
qgsgeorefplugin.h
2429
qgspointdialog.h
2530
mapcoordsdialog.h
2631
qgsgeorefwarpoptionsdialog.h
32+
qgsgcplistwidget.h
2733
)
2834

2935
SET (GEOREF_RCCS georeferencer.qrc)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/***************************************************************************
2+
qgsgcplist.h - GCP list class
3+
--------------------------------------
4+
Date : 27-Feb-2009
5+
Copyright : (c) 2009 by Manuel Massing
6+
Email : m.massing at warped-space.de
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
/* $Id */
16+
17+
#ifndef QGS_GCP_LIST_H
18+
#define QGS_GCP_LIST_H
19+
20+
#include <vector>
21+
22+
class QgsGeorefDataPoint;
23+
24+
typedef std::vector<QgsGeorefDataPoint *> QgsGCPList;
25+
26+
#endif
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/***************************************************************************
2+
qgsgcplistmodel.cpp - Model implementation of GCPList Model/View
3+
--------------------------------------
4+
Date : 27-Feb-2009
5+
Copyright : (c) 2009 by Manuel Massing
6+
Email : m.massing at warped-space.de
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
/* $Id */
16+
#include "qgsgcplistmodel.h"
17+
18+
#include "qgsgeorefdatapoint.h"
19+
#include "qgsgeoreftransform.h"
20+
21+
#include <cmath>
22+
using namespace std;
23+
24+
template <class T> class QNumericItem : public QStandardItem {
25+
public:
26+
QNumericItem(T value) : QStandardItem(QString("%1").arg(value)), mValue(value)
27+
{
28+
}
29+
30+
bool operator < (const QStandardItem &other) const
31+
{
32+
const QNumericItem<T> *otherD = dynamic_cast<const QNumericItem<T> *>(&other);
33+
if (otherD == NULL)
34+
return false;
35+
return mValue < otherD->mValue;
36+
}
37+
private:
38+
T mValue;
39+
};
40+
41+
QgsGCPListModel::QgsGCPListModel(QObject *parent) : QStandardItemModel(parent), mGCPList(0), mGeorefTransform(0)
42+
{
43+
}
44+
45+
void QgsGCPListModel::setGCPList(QgsGCPList *theGCPList)
46+
{
47+
mGCPList = theGCPList;
48+
updateModel(true);
49+
}
50+
51+
void QgsGCPListModel::setGeorefTransform(QgsGeorefTransform *theGeorefTransform)
52+
{
53+
mGeorefTransform = theGeorefTransform;
54+
updateModel(true);
55+
}
56+
57+
void QgsGCPListModel::onGCPListModified()
58+
{
59+
}
60+
61+
void QgsGCPListModel::onTransformationModified()
62+
{
63+
}
64+
65+
template <class T> QNumericItem<T> *create_item(const T value, bool isEditable = false)
66+
{
67+
QNumericItem<T> *item = new QNumericItem<T>(value);
68+
item->setEditable(isEditable);
69+
return item;
70+
}
71+
72+
QStandardItem *create_std_item(const QString &S, bool isEditable = false)
73+
{
74+
QStandardItem *std_item = new QStandardItem(S);
75+
std_item->setEditable(isEditable);
76+
return std_item;
77+
}
78+
79+
void QgsGCPListModel::updateModel(bool gcpsDirty)
80+
{
81+
clear();
82+
if (!mGCPList)
83+
return;
84+
85+
// Setup table header
86+
QStringList itemLabels;
87+
// Set column headers
88+
itemLabels<<"id"<<"srcX"<<"srcY"<<"dstX"<<"dstY"<<"dX"<<"dY"<<"residual";
89+
setColumnCount(itemLabels.size());
90+
setHorizontalHeaderLabels(itemLabels);
91+
92+
setRowCount(mGCPList->size());
93+
94+
95+
if (gcpsDirty && mGeorefTransform)
96+
{
97+
vector<QgsPoint> rC, mC;
98+
// TODO: move this vector extraction snippet into QgsGCPList
99+
for (int i = 0; i < mGCPList->size(); i++) {
100+
rC.push_back((*mGCPList)[i]->pixelCoords());
101+
mC.push_back((*mGCPList)[i]->mapCoords());
102+
}
103+
104+
// TODO: the parameters should probable be updated externally (by user interaction)
105+
mGeorefTransform->updateParametersFromGCPs(mC, rC);
106+
}
107+
108+
for (int i = 0; i < mGCPList->size(); i++)
109+
{
110+
int j = 0;
111+
QgsGeorefDataPoint &p = *(*mGCPList)[i];
112+
113+
setItem(i, j++, create_item<int>(i));
114+
setItem(i, j++, create_item<double>( p.pixelCoords().x() ));
115+
setItem(i, j++, create_item<double>(-p.pixelCoords().y() ));
116+
setItem(i, j++, create_item<double>( p.mapCoords().x() ));
117+
setItem(i, j++, create_item<double>( p.mapCoords().y() ));
118+
119+
double residual = -1.f;
120+
double dX, dY;
121+
// Calculate residual if transform is available and up-to-date
122+
if (mGeorefTransform && mGeorefTransform->parametersInitialized())
123+
{
124+
QgsPoint dst;
125+
// Transform from world to raster coordinate:
126+
// This is the transform direction used by the warp operation.
127+
// As transforms of order >=2 are not invertible, we are only
128+
// interested in the residual in this direction
129+
mGeorefTransform->transformWorldToRaster(p.mapCoords(), dst);
130+
dX = (dst.x() - p.pixelCoords().x());
131+
dY = (dst.y() - p.pixelCoords().y());
132+
residual = sqrt(dX*dX + dY*dY);
133+
}
134+
if (residual >= 0.f) {
135+
setItem(i, j++, create_item<double>(dX));
136+
setItem(i, j++, create_item<double>(-dY));
137+
setItem(i, j++, create_item<double>(residual));
138+
}
139+
else {
140+
setItem(i, j++, create_std_item("n/a"));
141+
setItem(i, j++, create_std_item("n/a"));
142+
setItem(i, j++, create_std_item("n/a"));
143+
}
144+
}
145+
//sort(); // Sort data
146+
//reset(); // Signal to views that the model has changed
147+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/***************************************************************************
2+
qgsgcplistmodel.h - Model implementation of GCPList Model/View
3+
--------------------------------------
4+
Date : 27-Feb-2009
5+
Copyright : (c) 2009 by Manuel Massing
6+
Email : m.massing at warped-space.de
7+
/***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSGCP_LIST_TABLE_VIEW_H
17+
#define QGSGCP_LIST_TABLE_VIEW_H
18+
19+
#include <QTreeView>
20+
#include <QStandardItemModel>
21+
22+
#include "qgsgcplist.h"
23+
24+
class QgsGeorefTransform;
25+
//class QgsGCPList;
26+
//^^currently a typedef, so no forward dec possible
27+
28+
29+
class QgsGCPListModel : public QStandardItemModel {
30+
//Q_OBJECT
31+
public:
32+
QgsGCPListModel(QObject *parent = NULL);
33+
34+
void setGCPList(QgsGCPList *theGCPList);
35+
void setGeorefTransform(QgsGeorefTransform *theGeorefTransform);
36+
public slots:
37+
void onGCPListModified();
38+
void onTransformationModified();
39+
private:
40+
void updateModel(bool gcpsDirty);
41+
42+
QgsGCPList *mGCPList;
43+
QgsGeorefTransform *mGeorefTransform;
44+
};
45+
46+
#endif
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/***************************************************************************
2+
qgsgcplistwidget.cpp - Widget for GCP list display
3+
--------------------------------------
4+
Date : 27-Feb-2009
5+
Copyright : (c) 2009 by Manuel Massing
6+
Email : m.massing at warped-space.de
7+
/***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
/* $Id */
16+
17+
#include <QHeaderView>
18+
19+
#include "qgsgcplistwidget.h"
20+
#include "qgsgcplistmodel.h"
21+
22+
#include "qgspointdialog.h"
23+
24+
#include <iostream> //debugging
25+
26+
QgsGCPListWidget::QgsGCPListWidget(QWidget *parent) : QWidget(parent)
27+
{
28+
setupUi(this);
29+
initialize();
30+
}
31+
32+
void QgsGCPListWidget::initialize()
33+
{
34+
mGCPListModel = new QgsGCPListModel;
35+
mGCPTableView->setModel(mGCPListModel);
36+
mGCPTableView->setSortingEnabled(true);
37+
mGCPTableView->verticalHeader()->hide();
38+
39+
connect(mGCPTableView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(itemDoubleClicked(const QModelIndex &)));
40+
}
41+
42+
void QgsGCPListWidget::setGCPList(QgsGCPList *theGCPList)
43+
{
44+
mGCPListModel->setGCPList(theGCPList);
45+
}
46+
47+
void QgsGCPListWidget::setGeorefTransform(QgsGeorefTransform *theGeorefTransform)
48+
{
49+
mGCPListModel->setGeorefTransform(theGeorefTransform);
50+
}
51+
52+
void QgsGCPListWidget::itemDoubleClicked(const QModelIndex &index)
53+
{
54+
QStandardItem *item = mGCPListModel->item(index.row(), 0);
55+
bool ok;
56+
int id = item->text().toInt(&ok);
57+
58+
if (ok)
59+
{
60+
emit jumpToGCP(id);
61+
}
62+
}
63+
64+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/***************************************************************************
2+
qgsgcplistwidget.h - Widget for GCP list display
3+
--------------------------------------
4+
Date : 27-Feb-2009
5+
Copyright : (c) 2009 by Manuel Massing
6+
Email : m.massing at warped-space.de
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
/* $Id */
16+
#ifndef QGS_GCP_LIST_WIDGET_H
17+
#define QGS_GCP_LIST_WIDGET_H
18+
19+
#include <QWidget>
20+
#include "ui_qgsgcplistwidgetbase.h"
21+
#include "qgsgcplist.h"
22+
23+
//class QgsGCPList;
24+
class QgsGCPListModel;
25+
class QgsGeorefTransform;
26+
27+
class QgsGCPListWidget : public QWidget, private Ui::QgsGCPListWidgetBase {
28+
Q_OBJECT
29+
public:
30+
QgsGCPListWidget(QWidget *parent = 0);
31+
32+
void setGCPList(QgsGCPList *theGCPList);
33+
void setGeorefTransform(QgsGeorefTransform *theGeorefTransform);
34+
public slots:
35+
// This slot is called by the list view if an item is double-clicked
36+
void itemDoubleClicked(const QModelIndex &);
37+
signals:
38+
void jumpToGCP(uint theGCPIndex);
39+
private:
40+
void initialize();
41+
42+
QgsGCPList *mGCPList;
43+
QgsGCPListModel *mGCPListModel;
44+
};
45+
46+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<ui version="4.0" >
2+
<class>QgsGCPListWidgetBase</class>
3+
<widget class="QWidget" name="QgsGCPListWidgetBase" >
4+
<property name="geometry" >
5+
<rect>
6+
<x>0</x>
7+
<y>0</y>
8+
<width>584</width>
9+
<height>412</height>
10+
</rect>
11+
</property>
12+
<property name="windowTitle" >
13+
<string>GCP List</string>
14+
</property>
15+
<layout class="QVBoxLayout" name="verticalLayout" >
16+
<item>
17+
<layout class="QGridLayout" name="gridLayout" >
18+
<item row="0" column="0" >
19+
<widget class="QTableView" name="mGCPTableView" />
20+
</item>
21+
</layout>
22+
</item>
23+
</layout>
24+
</widget>
25+
<resources/>
26+
<connections/>
27+
</ui>

0 commit comments

Comments
 (0)