Added standard deviation graphs which use Qwt
[tecorrec.git] / geo / tcElevationOptimization.h
blob40f3aa96c734937b2e0fca463fef76b66113b02e
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 #ifndef _tcElevationOptimization_h_
21 #define _tcElevationOptimization_h_
23 /**
24 * @file tcElevationOptimization.h
25 * @brief Optimized elevation.
28 #include "tcChannelDem.h"
29 #include "tcElevationData.h"
30 #include "tcAffineTransform.h"
32 #include <qwt_array.h>
34 #include <QList>
36 class tcShadowClassifyingData;
37 class tcGeoImageData;
38 class QwtPlot;
39 class QwtPlotCurve;
40 class QSpinBox;
41 class QSlider;
43 /// Optimized elevation.
44 class tcElevationOptimization : public tcChannelDem
46 Q_OBJECT
48 public:
51 * Constructors + destructor
54 /// Primary constructor.
55 tcElevationOptimization(const QList<tcShadowClassifyingData*>& datasets, tcSrtmModel* dem, tcGeoImageData* imagery);
57 /// Destructor.
58 virtual ~tcElevationOptimization();
61 * Main image interface
64 // Reimplemented
65 virtual tcChannelConfigWidget* configWidget();
67 signals:
69 /// Change statistics.
70 void statistics(const QString& stats);
72 private slots:
75 * Slots
78 /// Reset DEM.
79 void resetDem();
81 /// Load elevation data from DEM.
82 void loadFromDem();
84 /// Apply hard constraints to elevation data.
85 void applyHardConstraints();
87 /// Void-fill bilinear.
88 void voidFillBilinear();
90 /// Void-fill bicubic.
91 void voidFillBicubic();
93 /// Optimize a number of times.
94 void optimize();
96 /// Clear standard deviations.
97 void clearStdDeviations();
99 /// Sample standard deviations.
100 void sampleStdDeviations();
102 /// Sample standard deviations.
103 void saveStdDeviations();
105 protected:
108 * Interface for derived class to implement
111 // Reimplemented
112 virtual void roundPortion(double* x1, double* y1, double* x2, double* y2);
114 // Reimplemented
115 virtual tcAbstractPixelData* loadPortion(double x1, double y1, double x2, double y2, bool changed);
117 private:
120 * Private functions
123 /** Calculate the cost for a set of pixels.
124 * @param x1 Starting horizontal pixel (left).
125 * @param y1 Starting vertical pixel (top).
126 * @param x2 Ending horizontal pixel (right).
127 * @param y2 Ending horizontal pixel (bottom).
128 * @return Cost of the chosen pixels.
130 float cost(int x1, int y1, int x2, int y2) const;
132 /** Calculate the relative cost of changing a pixel's elevation.
133 * @param x Horizontal coordinate of pixel to change.
134 * @param y Vertical coordinate of pixel to change.
135 * @param dh Relative change in elevation.
136 * @return Relative cost of altering the elevation of the specified pixel.
138 float costChange(int x, int y, float dh, int range = 0);
140 /// Optimize a whole range of elevations.
141 void optimizeElevations(int x1, int y1, int x2, int y2, float dh, int range = 0);
143 /// Get pointer to elevation at a pixel.
144 float* pixelElevation(int x, int y) const;
146 /// Adjust elevation at a pixel.
147 void adjustElevation(int x, int y, float dh, int range = 0);
150 * Types
153 /// Shadow transition types.
154 enum TransitionType {
155 TransitionEntrance = 0,
156 TransitionExit = 1
159 /// Per-dataset-pixel data to cache
160 struct PerDatasetPixelCache
162 /// Coordinates of shadow entrance and exit.
163 maths::Vector<2,int> shadowTransition[2];
164 /// Light direction.
165 maths::Vector<3,float> light;
166 /// Length of light vector trace along ground.
167 float sinLightElevation;
168 /// How lit pixel is.
169 float lit;
170 /// Distance to shadow entrance and exit.
171 float shadowTransitionDistance[2];
174 /// Per-pixel data to cache.
175 struct PerPixelCache
177 /// Resolution.
178 maths::Vector<2,float> resolution;
179 /// Original elevation.
180 float originalElevation;
181 /// Reliability of original elevation.
182 unsigned char reliability;
183 /// Accurate elevation.
184 float accurateElevation;
185 /// Temporary values.
186 union {
187 float f;
188 int i;
189 } temporary;
193 * Variables
196 /// Number of datasets.
197 int m_numDatasets;
199 /// Datasets.
200 tcGeoImageData** m_datasets;
202 /// Transform local tex coords to dataset tex coords for each dataset.
203 tcAffineTransform2<double>* m_texToDatasetTex;
205 /// Shadow channel.
206 tcChannel** m_shadowChannels;
208 /// Shading channel.
209 tcChannel** m_shadingChannels;
211 /// Current elevation data.
212 tcElevationData* m_elevationData;
214 /// Per-dataset-pixel data.
215 tcTypedPixelData<PerDatasetPixelCache>** m_datum;
217 /// Per-pixel data.
218 tcTypedPixelData<PerPixelCache>* m_data;
220 /// Temporary shadow data.
221 Reference<tcPixelData<float> >* m_shadowData;
223 /// Temporary shading data.
224 Reference<tcPixelData<float> >* m_shadingData;
226 /// Weights.
227 struct
229 float variance;
230 float roughness;
231 float steepness;
232 float litFacing;
233 float shading;
234 float belowShadowLine;
235 float transitionElev;
236 float transitionTangential;
237 float transitionCurvingDown;
238 } m_weights;
240 /// Update voids only.
241 bool m_voidsOnly;
243 /// Currently loading from dem.
244 bool m_loadingFromDem;
247 * Configuration gui
250 /// Configuration widget.
251 tcChannelConfigWidget* m_configWidget;
253 /// Number of iterations to perform.
254 QSpinBox* m_spinIterations;
256 /// Slider for delta h.
257 QSlider* m_deltaHSlider[2];
259 /// Slider for range.
260 QSlider* m_rangeSlider[2];
262 /// Plot of standard deviations.
263 QwtPlot* m_plot;
265 /// Plot x coordinate data.
266 QwtArray<double> m_plotX;
268 /// Standard deviation curve.
269 QwtPlotCurve* m_stdDevCurve;
271 /// Standard deviation data.
272 QwtArray<double> m_stdDevData;
274 /// Standard deviation curve for void pixels.
275 QwtPlotCurve* m_stdDevVoidCurve;
277 /// Standard deviation data.
278 QwtArray<double> m_stdDevVoidData;
280 /// Standard deviation curve for non-void pixels.
281 QwtPlotCurve* m_stdDevNonVoidCurve;
283 /// Standard deviation data.
284 QwtArray<double> m_stdDevNonVoidData;
287 #endif