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
;
47 /// Optimized elevation.
48 class tcElevationOptimization
: public tcChannelDem
55 * Constructors + destructor
58 /// Primary constructor.
59 tcElevationOptimization(const QList
<tcShadowClassifyingData
*>& datasets
, tcSrtmModel
* dem
, tcGeoImageData
* imagery
);
62 virtual ~tcElevationOptimization();
65 * Main image interface
69 virtual tcChannelConfigWidget
* configWidget();
73 /// Change statistics.
74 void statistics(const QString
& stats
);
76 /// Queued non blocking signal to replot.
77 void replotStdDeviations();
79 /// Queued blocking signal to invalidate and redraw.
80 void invalidateAndRedraw();
91 /// Load elevation data from DEM.
94 /// Apply hard constraints to elevation data.
95 void applyHardConstraints();
97 /// Void-fill bilinear.
98 void voidFillBilinear();
100 /// Void-fill bicubic.
101 void voidFillBicubic();
103 /// Start/stop optimization process.
104 void startStopOptimize();
106 /// Optimize a number of times.
109 /// Clear standard deviations.
110 void clearStdDeviations();
112 /// Sample standard deviations.
113 void sampleStdDeviations();
115 /// Sample standard deviations.
116 void saveStdDeviations();
118 /// Save cross section data.
119 void saveCrossSections();
121 /// Invalidate and redraw.
122 void invalidateAndRedrawSlot();
124 /// Initialise snapshotting.
125 void initSnapShotting();
127 /// Load a sequence of snapshots.
128 void loadSnapShots();
130 /// Load a single snapshot.
131 void loadSnapShot(int id
);
133 /// Update weight labels.
134 void updateWeightLabels();
145 * Interface for derived class to implement
149 virtual void roundPortion(double* x1
, double* y1
, double* x2
, double* y2
);
152 virtual tcAbstractPixelData
* loadPortion(double x1
, double y1
, double x2
, double y2
, bool changed
);
160 /** Calculate the cost for a set of pixels.
161 * @param x1 Starting horizontal pixel (left).
162 * @param y1 Starting vertical pixel (top).
163 * @param x2 Ending horizontal pixel (right).
164 * @param y2 Ending horizontal pixel (bottom).
165 * @return Cost of the chosen pixels.
167 float cost(int x1
, int y1
, int x2
, int y2
) const;
169 /** Calculate the relative cost of changing a pixel's elevation.
170 * @param x Horizontal coordinate of pixel to change.
171 * @param y Vertical coordinate of pixel to change.
172 * @param dh Relative change in elevation.
173 * @return Relative cost of altering the elevation of the specified pixel.
175 float costChange(int x
, int y
, float dh
, int range
= 0);
177 /// Optimize a whole range of elevations.
178 void optimizeElevations(int x1
, int y1
, int x2
, int y2
, float dh
, int range
= 0);
180 /// Get pointer to elevation at a pixel.
181 float* pixelElevation(int x
, int y
) const;
183 /// Adjust elevation at a pixel.
184 void adjustElevation(int x
, int y
, float dh
, int range
= 0);
190 /// Worker thread class.
193 /// Shadow transition types.
194 enum TransitionType
{
195 TransitionEntrance
= 0,
199 /// Per-dataset-pixel data to cache
200 struct PerDatasetPixelCache
202 /// Coordinates of shadow entrance and exit.
203 maths::Vector
<2,int> shadowTransition
[2];
205 maths::Vector
<3,float> light
;
206 /// Length of light direction in x y.
208 /// Gradiant of light direction.
210 /// Distance to shadow entrance and exit.
211 float shadowTransitionDistance
[2];
214 /// Per-pixel data to cache.
218 maths::Vector
<2,float> resolution
;
219 /// Original elevation.
220 float originalElevation
;
221 /// Reliability of original elevation.
222 unsigned char reliability
;
223 /// Accurate elevation.
224 float accurateElevation
;
225 /// Estimated normal.
226 maths::Vector
<3,float> normalEstimate
;
227 /// Temporary values.
238 /// Number of datasets.
242 tcGeoImageData
** m_datasets
;
244 /// Transform local tex coords to dataset tex coords for each dataset.
245 tcAffineTransform2
<double>* m_texToDatasetTex
;
248 tcChannel
** m_shadowChannels
;
251 tcChannel
** m_shadingChannels
;
253 /// Current elevation data.
254 tcElevationData
* m_elevationData
;
256 /// Per-dataset-pixel data.
257 tcTypedPixelData
<PerDatasetPixelCache
>** m_data
;
260 tcTypedPixelData
<PerPixelCache
>* m_datum
;
262 /// Temporary shadow data.
263 Reference
<tcPixelData
<float> >* m_shadowData
;
265 /// Temporary shading data.
266 Reference
<tcPixelData
<float> >* m_shadingData
;
278 TransitionElevBottom
,
279 TransitionTangential
,
280 TransitionCurvingDown
,
287 float m_weights
[WeightsMax
];
290 QSlider
* m_weightSliders
[2][WeightsMax
];
293 QLabel
* m_weightLabels
[WeightsMax
];
296 float m_weightLimits
[2][WeightsMax
];
298 /// Update voids only.
301 /// Currently loading from dem.
302 bool m_loadingFromDem
;
304 /// Main processing thread.
307 /// Main processing mutex.
308 QMutex m_processingMutex
;
310 /// Signal to stop processing.
311 bool m_stopProcessing
;
313 /// Optimize toggle button.
314 QPushButton
* m_btnOptimize
;
320 /// Configuration widget.
321 tcChannelConfigWidget
* m_configWidget
;
323 /// Number of iterations to perform.
324 QSpinBox
* m_spinIterations
;
326 /// Plot of standard deviations.
329 /// Plot x coordinate data.
330 QwtArray
<double> m_plotX
;
332 /// Standard deviation curve.
333 QwtPlotCurve
* m_stdDevCurve
;
335 /// Standard deviation data.
336 QwtArray
<double> m_stdDevData
;
338 /// Standard deviation curve for void pixels.
339 QwtPlotCurve
* m_stdDevVoidCurve
;
341 /// Standard deviation data.
342 QwtArray
<double> m_stdDevVoidData
;
344 /// Standard deviation curve for non-void pixels.
345 QwtPlotCurve
* m_stdDevNonVoidCurve
;
347 /// Standard deviation data.
348 QwtArray
<double> m_stdDevNonVoidData
;
350 /// Cross sectioning resolution.
351 QSpinBox
* m_crossResolution
;
353 /// Cross sectioning frequency.
354 QSpinBox
* m_crossFrequency
;
356 /// Snapshotting config file.
357 QString m_snapshotFile
;
359 /// Snapshot read file.
360 QString m_snapshotReadFile
;
362 /// Whether currently reading snapshots.
363 bool m_snapshotReading
;
365 /// Snapshot time slider.
366 QSlider
* m_snapshotSlider
;
368 /// Counter of snapshot frames.
369 QLabel
* m_snapshotCounter
;