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"
30 /// Optimized elevation.
31 class tcElevationOptimization
: public tcChannelDem
36 * Constructors + destructor
39 /// Primary constructor.
40 tcElevationOptimization(tcChannel
* shadowChannel
, tcSrtmModel
* dem
, tcGeoImageData
* imagery
);
43 virtual ~tcElevationOptimization();
48 * Interface for derived class to implement
52 virtual void roundPortion(double* x1
, double* y1
, double* x2
, double* y2
);
55 virtual tcAbstractPixelData
* loadPortion(double x1
, double y1
, double x2
, double y2
);
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);
93 /// Shadow transition types.
95 TransitionEntrance
= 0,
99 /// Per-pixel data to cache.
102 /// Coordinates of shadow entrance and exit.
103 maths::Vector
<2,int> shadowTransition
[2];
105 maths::Vector
<2,float> resolution
;
107 maths::Vector
<3,float> light
;
108 /// How lit pixel is.
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
;
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
;
140 float transitionElev
;