tcElevationOptimization::loadSnapShot: simplify reliability expression
[tecorrec.git] / geo / tcElevationDifference.cpp
blobbcef73510cfff1e575439153802900938ae05f67
1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * Tecorrec 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 General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file tcElevationDifference.cpp
22 * @brief Elevation map including void highlighting.
25 #include "tcElevationDifference.h"
26 #include "tcSrtmModel.h"
27 #include "tcGeoImageData.h"
28 #include "tcChannelConfigWidget.h"
30 #include <QVBoxLayout>
31 #include <QLabel>
34 * Constructors + destructor
37 /// Primary constructor.
38 tcElevationDifference::tcElevationDifference(const tcGeoImageData* refImagery, tcChannel* reference, tcSrtmModel* dem, tcGeoImageData* imagery)
39 : tcChannelDem(dem, imagery,
40 tr("Elevation difference"),
41 tr("Difference in elevation between primary and secondary DEM."))
42 , m_referenceChannel(reference)
43 , m_refTransform(imagery->texToGeo() * refImagery->geoToTex())
44 , m_configWidget(0)
45 , m_stdDeviation(-1.0f)
49 /// Destructor.
50 tcElevationDifference::~tcElevationDifference()
52 delete m_configWidget;
56 * Main image interface
59 tcChannelConfigWidget* tcElevationDifference::configWidget()
61 if (0 == m_configWidget)
63 m_configWidget = new tcChannelConfigWidget();
64 m_configWidget->setWindowTitle(tr("%1 Configuration").arg(name()));
66 QVBoxLayout* layout = new QVBoxLayout(m_configWidget);
68 QLabel* standardDeviation = new QLabel(tr("Standard deviation: %1 m").arg(m_stdDeviation), m_configWidget);
69 layout->addWidget(standardDeviation);
70 connect(this, SIGNAL(stdDeviationChanged(const QString&)), standardDeviation, SLOT(setText(const QString&)));
72 return m_configWidget;
76 * Interface for derived class to implement
79 void tcElevationDifference::roundPortion(double* x1, double* y1, double* x2, double* y2)
83 tcAbstractPixelData* tcElevationDifference::loadPortion(double x1, double y1, double x2, double y2, bool changed)
85 maths::Vector<2,double> xy1 = m_refTransform * maths::Vector<2,double>(x1,y1);
86 maths::Vector<2,double> xy2 = m_refTransform * maths::Vector<2,double>(x2,y2);
87 Reference<tcAbstractPixelData> channelData = m_referenceChannel->loadPortion(xy1[0], xy1[1], xy2[0], xy2[1], changed);
88 int width = channelData->width();
89 int height = channelData->height();
91 // Create a new pixel buffer
92 tcPixelData<float>* data = new tcPixelData<float>(width, height);
93 startProcessing("Diffing elevation data");
94 int index = 0;
95 double sum = 0.0;
96 for (int j = 0; j < height; ++j)
98 progress((float)j/(height-1));
99 for (int i = 0; i < width; ++i)
101 // Transform coordinates
102 maths::Vector<2,float> coord(x1 + (x2-x1)*i / (width - 1),
103 y1 + (y2-y1)*j / (height - 1));
104 tcGeo geoCoord = geoAt(coord);
106 // Get some elevation data
107 bool accurate;
108 float altitude1 = dem()[0].altitudeAt(geoCoord, true, &accurate);
109 float altitude2 = dem()[1].altitudeAt(geoCoord, true, &accurate);
110 float diff = altitude2 - altitude1;
111 diff *= diff;
112 sum += diff;
113 data->buffer()[index] = diff/(500.0f*500.0f);
114 ++index;
117 m_stdDeviation = sqrt(sum/(width*height));
118 emit stdDeviationChanged(tr("Standard deviation: %1 m").arg(m_stdDeviation));
119 endProcessing();
120 return data;