tcElevationOptimization: fix typo s/write/read/
[tecorrec.git] / geo / tcElevationOptimization.h
blobb898850e235fec3dfe1c78389af87d1de918eed3
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>
35 #include <QMutex>
37 class tcShadowClassifyingData;
38 class tcGeoImageData;
39 class QwtPlot;
40 class QwtPlotCurve;
41 class QSpinBox;
42 class QSlider;
43 class QThread;
44 class QPushButton;
45 class QLabel;
47 /// Optimized elevation.
48 class tcElevationOptimization : public tcChannelDem
50 Q_OBJECT
52 public:
55 * Constructors + destructor
58 /// Primary constructor.
59 tcElevationOptimization(const QList<tcShadowClassifyingData*>& datasets, tcSrtmModel* dem, tcGeoImageData* imagery);
61 /// Destructor.
62 virtual ~tcElevationOptimization();
65 * Main image interface
68 // Reimplemented
69 virtual tcChannelConfigWidget* configWidget();
71 signals:
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();
82 private slots:
85 * Slots
88 /// Reset DEM.
89 void resetDem();
91 /// Load elevation data from DEM.
92 void loadFromDem();
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.
107 void optimize();
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();
136 /// Save weights.
137 void saveWeights();
139 /// Load weights.
140 void loadWeights();
142 protected:
145 * Interface for derived class to implement
148 // Reimplemented
149 virtual void roundPortion(double* x1, double* y1, double* x2, double* y2);
151 // Reimplemented
152 virtual tcAbstractPixelData* loadPortion(double x1, double y1, double x2, double y2, bool changed);
154 private:
157 * Private functions
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);
187 * Types
190 /// Worker thread class.
191 class WorkerThread;
193 /// Shadow transition types.
194 enum TransitionType {
195 TransitionEntrance = 0,
196 TransitionExit = 1
199 /// Per-dataset-pixel data to cache
200 struct PerDatasetPixelCache
202 /// Coordinates of shadow entrance and exit.
203 maths::Vector<2,int> shadowTransition[2];
204 /// Light direction.
205 maths::Vector<3,float> light;
206 /// Length of light direction in x y.
207 float lxy;
208 /// Gradiant of light direction.
209 float dlz_dlxy;
210 /// Distance to shadow entrance and exit.
211 float shadowTransitionDistance[2];
214 /// Per-pixel data to cache.
215 struct PerPixelCache
217 /// Resolution.
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.
228 union {
229 float f;
230 int i;
231 } temporary;
235 * Variables
238 /// Number of datasets.
239 int m_numDatasets;
241 /// Datasets.
242 tcGeoImageData** m_datasets;
244 /// Transform local tex coords to dataset tex coords for each dataset.
245 tcAffineTransform2<double>* m_texToDatasetTex;
247 /// Shadow channel.
248 tcChannel** m_shadowChannels;
250 /// Shading channel.
251 tcChannel** m_shadingChannels;
253 /// Current elevation data.
254 tcElevationData* m_elevationData;
256 /// Per-dataset-pixel data.
257 tcTypedPixelData<PerDatasetPixelCache>** m_data;
259 /// Per-pixel 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;
268 enum Weights
270 Variance,
271 Roughness,
272 Steepness,
273 LitFacing,
274 Shading,
275 PhotometricStereo,
276 BelowShadowLine,
277 TransitionElevTop,
278 TransitionElevBottom,
279 TransitionTangential,
280 TransitionCurvingDown,
281 ElevationStep,
282 Range,
283 WeightsMax
286 /// Weights.
287 float m_weights[WeightsMax];
289 /// Weight sliders.
290 QSlider* m_weightSliders[2][WeightsMax];
292 /// Weight labels.
293 QLabel* m_weightLabels[WeightsMax];
295 /// Weight limits.
296 float m_weightLimits[2][WeightsMax];
298 /// Update voids only.
299 bool m_voidsOnly;
301 /// Currently loading from dem.
302 bool m_loadingFromDem;
304 /// Main processing thread.
305 QThread* m_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;
317 * Configuration gui
320 /// Configuration widget.
321 tcChannelConfigWidget* m_configWidget;
323 /// Number of iterations to perform.
324 QSpinBox* m_spinIterations;
326 /// Plot of standard deviations.
327 QwtPlot* m_plot;
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;
372 #endif