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();
120 /// Initialise snapshotting.
121 void initSnapShotting();
123 /// Load a sequence of snapshots.
124 void loadSnapShots();
126 /// Load a single snapshot.
127 void loadSnapShot(int id
);
132 * Interface for derived class to implement
136 virtual void roundPortion(double* x1
, double* y1
, double* x2
, double* y2
);
139 virtual tcAbstractPixelData
* loadPortion(double x1
, double y1
, double x2
, double y2
, bool changed
);
147 /** Calculate the cost for a set of pixels.
148 * @param x1 Starting horizontal pixel (left).
149 * @param y1 Starting vertical pixel (top).
150 * @param x2 Ending horizontal pixel (right).
151 * @param y2 Ending horizontal pixel (bottom).
152 * @return Cost of the chosen pixels.
154 float cost(int x1
, int y1
, int x2
, int y2
) const;
156 /** Calculate the relative cost of changing a pixel's elevation.
157 * @param x Horizontal coordinate of pixel to change.
158 * @param y Vertical coordinate of pixel to change.
159 * @param dh Relative change in elevation.
160 * @return Relative cost of altering the elevation of the specified pixel.
162 float costChange(int x
, int y
, float dh
, int range
= 0);
164 /// Optimize a whole range of elevations.
165 void optimizeElevations(int x1
, int y1
, int x2
, int y2
, float dh
, int range
= 0);
167 /// Get pointer to elevation at a pixel.
168 float* pixelElevation(int x
, int y
) const;
170 /// Adjust elevation at a pixel.
171 void adjustElevation(int x
, int y
, float dh
, int range
= 0);
177 /// Worker thread class.
180 /// Shadow transition types.
181 enum TransitionType
{
182 TransitionEntrance
= 0,
186 /// Per-dataset-pixel data to cache
187 struct PerDatasetPixelCache
189 /// Coordinates of shadow entrance and exit.
190 maths::Vector
<2,int> shadowTransition
[2];
192 maths::Vector
<3,float> light
;
193 /// Length of light vector trace along ground.
194 float sinLightElevation
;
195 /// How lit pixel is.
197 /// Distance to shadow entrance and exit.
198 float shadowTransitionDistance
[2];
201 /// Per-pixel data to cache.
205 maths::Vector
<2,float> resolution
;
206 /// Original elevation.
207 float originalElevation
;
208 /// Reliability of original elevation.
209 unsigned char reliability
;
210 /// Accurate elevation.
211 float accurateElevation
;
212 /// Temporary values.
223 /// Number of datasets.
227 tcGeoImageData
** m_datasets
;
229 /// Transform local tex coords to dataset tex coords for each dataset.
230 tcAffineTransform2
<double>* m_texToDatasetTex
;
233 tcChannel
** m_shadowChannels
;
236 tcChannel
** m_shadingChannels
;
238 /// Current elevation data.
239 tcElevationData
* m_elevationData
;
241 /// Per-dataset-pixel data.
242 tcTypedPixelData
<PerDatasetPixelCache
>** m_datum
;
245 tcTypedPixelData
<PerPixelCache
>* m_data
;
247 /// Temporary shadow data.
248 Reference
<tcPixelData
<float> >* m_shadowData
;
250 /// Temporary shading data.
251 Reference
<tcPixelData
<float> >* m_shadingData
;
261 float belowShadowLine
;
262 float transitionElev
;
263 float transitionTangential
;
264 float transitionCurvingDown
;
267 /// Update voids only.
270 /// Currently loading from dem.
271 bool m_loadingFromDem
;
273 /// Main processing thread.
276 /// Main processing mutex.
277 QMutex m_processingMutex
;
279 /// Signal to stop processing.
280 bool m_stopProcessing
;
282 /// Optimize toggle button.
283 QPushButton
* m_btnOptimize
;
289 /// Configuration widget.
290 tcChannelConfigWidget
* m_configWidget
;
292 /// Number of iterations to perform.
293 QSpinBox
* m_spinIterations
;
295 /// Slider for delta h.
296 QSlider
* m_deltaHSlider
[2];
298 /// Slider for range.
299 QSlider
* m_rangeSlider
[2];
301 /// Plot of standard deviations.
304 /// Plot x coordinate data.
305 QwtArray
<double> m_plotX
;
307 /// Standard deviation curve.
308 QwtPlotCurve
* m_stdDevCurve
;
310 /// Standard deviation data.
311 QwtArray
<double> m_stdDevData
;
313 /// Standard deviation curve for void pixels.
314 QwtPlotCurve
* m_stdDevVoidCurve
;
316 /// Standard deviation data.
317 QwtArray
<double> m_stdDevVoidData
;
319 /// Standard deviation curve for non-void pixels.
320 QwtPlotCurve
* m_stdDevNonVoidCurve
;
322 /// Standard deviation data.
323 QwtArray
<double> m_stdDevNonVoidData
;
325 /// Snapshotting config file.
326 QString m_snapshotFile
;
328 /// Snapshot read file.
329 QString m_snapshotReadFile
;
331 /// Whether currently reading snapshots.
332 bool m_snapshotReading
;
334 /// Snapshot time slider.
335 QSlider
* m_snapshotSlider
;