New steepness cost in elevation optimizer and tweaks settings
[tecorrec.git] / geo / tcElevationOptimization.h
blob2d58e18f61cfde472227ad2dfa89ec1033e19ce6
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"
31 class QSpinBox;
33 /// Optimized elevation.
34 class tcElevationOptimization : public tcChannelDem
36 Q_OBJECT
38 public:
41 * Constructors + destructor
44 /// Primary constructor.
45 tcElevationOptimization(tcChannel* shadowChannel, tcChannel* shadingChannel, tcSrtmModel* dem, tcGeoImageData* imagery);
47 /// Destructor.
48 virtual ~tcElevationOptimization();
51 * Main image interface
54 // Reimplemented
55 virtual tcChannelConfigWidget* configWidget();
57 private slots:
60 * Slots
63 /// Reset DEM.
64 void resetDem();
66 /// Load elevation data from DEM.
67 void loadFromDem();
69 /// Optimize a number of times.
70 void optimize();
72 protected:
75 * Interface for derived class to implement
78 // Reimplemented
79 virtual void roundPortion(double* x1, double* y1, double* x2, double* y2);
81 // Reimplemented
82 virtual tcAbstractPixelData* loadPortion(double x1, double y1, double x2, double y2);
84 private:
87 * Private functions
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);
117 * Types
120 /// Shadow transition types.
121 enum TransitionType {
122 TransitionEntrance = 0,
123 TransitionExit = 1
126 /// Per-pixel data to cache.
127 struct PerPixelCache
129 /// Coordinates of shadow entrance and exit.
130 maths::Vector<2,int> shadowTransition[2];
131 /// Resolution.
132 maths::Vector<2,float> resolution;
133 /// Light direction.
134 maths::Vector<3,float> light;
135 /// Length of light vector trace along ground.
136 float sinLightElevation;
137 /// How lit pixel is.
138 float lit;
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;
148 * Variables
151 /// Shadow channel.
152 tcChannel* m_shadowChannel;
154 /// Shading channel.
155 tcChannel* m_shadingChannel;
157 /// Current elevation data.
158 tcElevationData* m_elevationData;
160 /// per-pixel data.
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;
169 /// Weights.
170 struct
172 float variance;
173 float roughness;
174 float steepness;
175 float litFacing;
176 float shading;
177 float transitionElev;
178 float transitionTangential;
179 float transitionCurvingDown;
180 } m_weights;
183 * Configuration gui
186 /// Configuration widget.
187 tcChannelConfigWidget* m_configWidget;
189 /// Number of iterations to perform.
190 QSpinBox* m_spinIterations;
194 #endif