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>
36 class tcShadowClassifyingData
;
43 /// Optimized elevation.
44 class tcElevationOptimization
: public tcChannelDem
51 * Constructors + destructor
54 /// Primary constructor.
55 tcElevationOptimization(const QList
<tcShadowClassifyingData
*>& datasets
, tcSrtmModel
* dem
, tcGeoImageData
* imagery
);
58 virtual ~tcElevationOptimization();
61 * Main image interface
65 virtual tcChannelConfigWidget
* configWidget();
69 /// Change statistics.
70 void statistics(const QString
& stats
);
81 /// Load elevation data from DEM.
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.
96 /// Clear standard deviations.
97 void clearStdDeviations();
99 /// Sample standard deviations.
100 void sampleStdDeviations();
102 /// Sample standard deviations.
103 void saveStdDeviations();
108 * Interface for derived class to implement
112 virtual void roundPortion(double* x1
, double* y1
, double* x2
, double* y2
);
115 virtual tcAbstractPixelData
* loadPortion(double x1
, double y1
, double x2
, double y2
, bool changed
);
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);
153 /// Shadow transition types.
154 enum TransitionType
{
155 TransitionEntrance
= 0,
159 /// Per-dataset-pixel data to cache
160 struct PerDatasetPixelCache
162 /// Coordinates of shadow entrance and exit.
163 maths::Vector
<2,int> shadowTransition
[2];
165 maths::Vector
<3,float> light
;
166 /// Length of light vector trace along ground.
167 float sinLightElevation
;
168 /// How lit pixel is.
170 /// Distance to shadow entrance and exit.
171 float shadowTransitionDistance
[2];
174 /// Per-pixel data to cache.
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.
196 /// Number of datasets.
200 tcGeoImageData
** m_datasets
;
202 /// Transform local tex coords to dataset tex coords for each dataset.
203 tcAffineTransform2
<double>* m_texToDatasetTex
;
206 tcChannel
** m_shadowChannels
;
209 tcChannel
** m_shadingChannels
;
211 /// Current elevation data.
212 tcElevationData
* m_elevationData
;
214 /// Per-dataset-pixel data.
215 tcTypedPixelData
<PerDatasetPixelCache
>** m_datum
;
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
;
234 float belowShadowLine
;
235 float transitionElev
;
236 float transitionTangential
;
237 float transitionCurvingDown
;
240 /// Update voids only.
243 /// Currently loading from dem.
244 bool m_loadingFromDem
;
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.
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
;