1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
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. *
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. *
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_
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>
37 class tcShadowClassifyingData
;
46 /// Optimized elevation.
47 class tcElevationOptimization
: public tcChannelDem
54 * Constructors + destructor
57 /// Primary constructor.
58 tcElevationOptimization(const QList
<tcShadowClassifyingData
*>& datasets
, tcSrtmModel
* dem
, tcGeoImageData
* imagery
);
61 virtual ~tcElevationOptimization();
64 * Main image interface
68 virtual tcChannelConfigWidget
* configWidget();
72 /// Change statistics.
73 void statistics(const QString
& stats
);
75 /// Queued non blocking signal to replot.
76 void replotStdDeviations();
78 /// Queued blocking signal to invalidate and redraw.
79 void invalidateAndRedraw();
90 /// Load elevation data from DEM.
93 /// Apply hard constraints to elevation data.
94 void applyHardConstraints();
96 /// Void-fill bilinear.
97 void voidFillBilinear();
99 /// Void-fill bicubic.
100 void voidFillBicubic();
102 /// Start/stop optimization process.
103 void startStopOptimize();
105 /// Optimize a number of times.
108 /// Clear standard deviations.
109 void clearStdDeviations();
111 /// Sample standard deviations.
112 void sampleStdDeviations();
114 /// Sample standard deviations.
115 void saveStdDeviations();
117 /// Invalidate and redraw.
118 void invalidateAndRedrawSlot();
123 * Interface for derived class to implement
127 virtual void roundPortion(double* x1
, double* y1
, double* x2
, double* y2
);
130 virtual tcAbstractPixelData
* loadPortion(double x1
, double y1
, double x2
, double y2
, bool changed
);
138 /** Calculate the cost for a set of pixels.
139 * @param x1 Starting horizontal pixel (left).
140 * @param y1 Starting vertical pixel (top).
141 * @param x2 Ending horizontal pixel (right).
142 * @param y2 Ending horizontal pixel (bottom).
143 * @return Cost of the chosen pixels.
145 float cost(int x1
, int y1
, int x2
, int y2
) const;
147 /** Calculate the relative cost of changing a pixel's elevation.
148 * @param x Horizontal coordinate of pixel to change.
149 * @param y Vertical coordinate of pixel to change.
150 * @param dh Relative change in elevation.
151 * @return Relative cost of altering the elevation of the specified pixel.
153 float costChange(int x
, int y
, float dh
, int range
= 0);
155 /// Optimize a whole range of elevations.
156 void optimizeElevations(int x1
, int y1
, int x2
, int y2
, float dh
, int range
= 0);
158 /// Get pointer to elevation at a pixel.
159 float* pixelElevation(int x
, int y
) const;
161 /// Adjust elevation at a pixel.
162 void adjustElevation(int x
, int y
, float dh
, int range
= 0);
168 /// Worker thread class.
171 /// Shadow transition types.
172 enum TransitionType
{
173 TransitionEntrance
= 0,
177 /// Per-dataset-pixel data to cache
178 struct PerDatasetPixelCache
180 /// Coordinates of shadow entrance and exit.
181 maths::Vector
<2,int> shadowTransition
[2];
183 maths::Vector
<3,float> light
;
184 /// Length of light vector trace along ground.
185 float sinLightElevation
;
186 /// How lit pixel is.
188 /// Distance to shadow entrance and exit.
189 float shadowTransitionDistance
[2];
192 /// Per-pixel data to cache.
196 maths::Vector
<2,float> resolution
;
197 /// Original elevation.
198 float originalElevation
;
199 /// Reliability of original elevation.
200 unsigned char reliability
;
201 /// Accurate elevation.
202 float accurateElevation
;
203 /// Temporary values.
214 /// Number of datasets.
218 tcGeoImageData
** m_datasets
;
220 /// Transform local tex coords to dataset tex coords for each dataset.
221 tcAffineTransform2
<double>* m_texToDatasetTex
;
224 tcChannel
** m_shadowChannels
;
227 tcChannel
** m_shadingChannels
;
229 /// Current elevation data.
230 tcElevationData
* m_elevationData
;
232 /// Per-dataset-pixel data.
233 tcTypedPixelData
<PerDatasetPixelCache
>** m_datum
;
236 tcTypedPixelData
<PerPixelCache
>* m_data
;
238 /// Temporary shadow data.
239 Reference
<tcPixelData
<float> >* m_shadowData
;
241 /// Temporary shading data.
242 Reference
<tcPixelData
<float> >* m_shadingData
;
252 float belowShadowLine
;
253 float transitionElev
;
254 float transitionTangential
;
255 float transitionCurvingDown
;
258 /// Update voids only.
261 /// Currently loading from dem.
262 bool m_loadingFromDem
;
264 /// Main processing thread.
267 /// Main processing mutex.
268 QMutex m_processingMutex
;
270 /// Signal to stop processing.
271 bool m_stopProcessing
;
273 /// Optimize toggle button.
274 QPushButton
* m_btnOptimize
;
280 /// Configuration widget.
281 tcChannelConfigWidget
* m_configWidget
;
283 /// Number of iterations to perform.
284 QSpinBox
* m_spinIterations
;
286 /// Slider for delta h.
287 QSlider
* m_deltaHSlider
[2];
289 /// Slider for range.
290 QSlider
* m_rangeSlider
[2];
292 /// Plot of standard deviations.
295 /// Plot x coordinate data.
296 QwtArray
<double> m_plotX
;
298 /// Standard deviation curve.
299 QwtPlotCurve
* m_stdDevCurve
;
301 /// Standard deviation data.
302 QwtArray
<double> m_stdDevData
;
304 /// Standard deviation curve for void pixels.
305 QwtPlotCurve
* m_stdDevVoidCurve
;
307 /// Standard deviation data.
308 QwtArray
<double> m_stdDevVoidData
;
310 /// Standard deviation curve for non-void pixels.
311 QwtPlotCurve
* m_stdDevNonVoidCurve
;
313 /// Standard deviation data.
314 QwtArray
<double> m_stdDevNonVoidData
;