Basic elevation optimisation channel
[tecorrec.git] / geo / tcElevationOptimization.h
blobec1093b787d5675d3504023dc161ea2f6f4d222e
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"
30 /// Optimized elevation.
31 class tcElevationOptimization : public tcChannelDem
33 public:
36 * Constructors + destructor
39 /// Primary constructor.
40 tcElevationOptimization(tcChannel* shadowChannel, tcSrtmModel* dem, tcGeoImageData* imagery);
42 /// Destructor.
43 virtual ~tcElevationOptimization();
45 protected:
48 * Interface for derived class to implement
51 // Reimplemented
52 virtual void roundPortion(double* x1, double* y1, double* x2, double* y2);
54 // Reimplemented
55 virtual tcAbstractPixelData* loadPortion(double x1, double y1, double x2, double y2);
57 private:
60 * Private functions
63 /** Calculate the cost for a set of pixels.
64 * @param x1 Starting horizontal pixel (left).
65 * @param y1 Starting vertical pixel (top).
66 * @param x2 Ending horizontal pixel (right).
67 * @param y2 Ending horizontal pixel (bottom).
68 * @return Cost of the chosen pixels.
70 float cost(int x1, int y1, int x2, int y2) const;
72 /** Calculate the relative cost of changing a pixel's elevation.
73 * @param x Horizontal coordinate of pixel to change.
74 * @param y Vertical coordinate of pixel to change.
75 * @param dh Relative change in elevation.
76 * @return Relative cost of altering the elevation of the specified pixel.
78 float costChange(int x, int y, float dh);
80 /// Optimize a whole range of elevations.
81 void optimizeElevations(int x1, int y1, int x2, int y2, float dh);
83 /// Get pointer to elevation at a pixel.
84 float* pixelElevation(int x, int y) const;
86 /// Adjust elevation at a pixel.
87 float adjustElevation(int x, int y, float dh, bool relative = false);
90 * Types
93 /// Shadow transition types.
94 enum TransitionType {
95 TransitionEntrance = 0,
96 TransitionExit = 1
99 /// Per-pixel data to cache.
100 struct PerPixelCache
102 /// Coordinates of shadow entrance and exit.
103 maths::Vector<2,int> shadowTransition[2];
104 /// Resolution.
105 maths::Vector<2,float> resolution;
106 /// Light direction.
107 maths::Vector<3,float> light;
108 /// How lit pixel is.
109 float lit;
110 /// Original elevation.
111 float originalElevation;
112 /// Distance to shadow entrance and exit.
113 float shadowTransitionDistance[2];
114 /// Reliability of original elevation.
115 unsigned char reliability;
119 * Variables
122 /// Shadow channel.
123 tcChannel* m_shadowChannel;
125 /// Temporary shadow data.
126 tcPixelData<float>* m_shadowData;
128 /// Temporary elevation data.
129 tcPixelData<float>* m_elevationData;
131 /// Temporary per-pixel data.
132 tcTypedPixelData<PerPixelCache>* m_data;
134 /// Weights.
135 struct
137 float variance;
138 float roughness;
139 float litFacing;
140 float transitionElev;
141 } m_weights;
145 #endif