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"
33 /// Optimized elevation.
34 class tcElevationOptimization
: public tcChannelDem
41 * Constructors + destructor
44 /// Primary constructor.
45 tcElevationOptimization(tcChannel
* shadowChannel
, tcChannel
* shadingChannel
, tcSrtmModel
* dem
, tcGeoImageData
* imagery
);
48 virtual ~tcElevationOptimization();
51 * Main image interface
55 virtual tcChannelConfigWidget
* configWidget();
66 /// Load elevation data from DEM.
69 /// Optimize a number of times.
75 * Interface for derived class to implement
79 virtual void roundPortion(double* x1
, double* y1
, double* x2
, double* y2
);
82 virtual tcAbstractPixelData
* loadPortion(double x1
, double y1
, double x2
, double y2
);
90 /** Calculate the cost for a set of pixels.
91 * @param x1 Starting horizontal pixel (left).
92 * @param y1 Starting vertical pixel (top).
93 * @param x2 Ending horizontal pixel (right).
94 * @param y2 Ending horizontal pixel (bottom).
95 * @return Cost of the chosen pixels.
97 float cost(int x1
, int y1
, int x2
, int y2
) const;
99 /** Calculate the relative cost of changing a pixel's elevation.
100 * @param x Horizontal coordinate of pixel to change.
101 * @param y Vertical coordinate of pixel to change.
102 * @param dh Relative change in elevation.
103 * @return Relative cost of altering the elevation of the specified pixel.
105 float costChange(int x
, int y
, float dh
);
107 /// Optimize a whole range of elevations.
108 void optimizeElevations(int x1
, int y1
, int x2
, int y2
, float dh
);
110 /// Get pointer to elevation at a pixel.
111 float* pixelElevation(int x
, int y
) const;
113 /// Adjust elevation at a pixel.
114 float adjustElevation(int x
, int y
, float dh
, bool relative
= false);
120 /// Shadow transition types.
121 enum TransitionType
{
122 TransitionEntrance
= 0,
126 /// Per-pixel data to cache.
129 /// Coordinates of shadow entrance and exit.
130 maths::Vector
<2,int> shadowTransition
[2];
132 maths::Vector
<2,float> resolution
;
134 maths::Vector
<3,float> light
;
135 /// Length of light vector trace along ground.
136 float sinLightElevation
;
137 /// How lit pixel is.
139 /// Original elevation.
140 float originalElevation
;
141 /// Distance to shadow entrance and exit.
142 float shadowTransitionDistance
[2];
143 /// Reliability of original elevation.
144 unsigned char reliability
;
152 tcChannel
* m_shadowChannel
;
155 tcChannel
* m_shadingChannel
;
157 /// Current elevation data.
158 tcElevationData
* m_elevationData
;
161 tcTypedPixelData
<PerPixelCache
>* m_data
;
163 /// Temporary shadow data.
164 Reference
<tcPixelData
<float> > m_shadowData
;
166 /// Temporary shading data.
167 Reference
<tcPixelData
<float> > m_shadingData
;
177 float transitionElev
;
178 float transitionTangential
;
179 float transitionCurvingDown
;
186 /// Configuration widget.
187 tcChannelConfigWidget
* m_configWidget
;
189 /// Number of iterations to perform.
190 QSpinBox
* m_spinIterations
;