17#include "SpecialPixel.h"
65 Hillshade::~Hillshade() {
164 if (input.SampleDimension() != 3 ||
165 input.LineDimension() != 3 ||
166 input.BandDimension() != 1) {
168 QObject::tr(
"Hillshade requires a 3x3x1 portal of data, but a %1x%2x%3 "
169 "portal of data was provided instead")
170 .arg(input.SampleDimension()).arg(input.LineDimension())
171 .arg(input.BandDimension()),
177 QObject::tr(
"Hillshade requires a valid azimuth angle (sun direction) to "
184 QObject::tr(
"Hillshade azimuth angle [%1] must be between 0 and 360 degrees")
191 QObject::tr(
"Hillshade requires a valid zenith angle (solar elevation) to "
198 QObject::tr(
"Hillshade zenith angle [%1] must be between 0 and 90 degrees")
205 QObject::tr(
"Hillshade requires a pixel resolution (meters/pixel) to "
212 QObject::tr(
"Hillshade requires a non-zero pixel resolution (meters/pixel) "
227 double result =
Null;
230 bool anySpecialPixels =
false;
231 for(
int i = 0; i < input.size(); ++i) {
233 anySpecialPixels =
true;
238 if (!anySpecialPixels) {
253 double p = ( (-1) * input[0] + (0) * input[1] + (1) * input[2]
254 + (-1) * input[3] + (0) * input[4] + (1) * input[5]
255 + (-1) * input[6] + (0) * input[7] + (1) * input[8]) / (3.0 *
m_pixelResolution);
257 double q = ( (-1) * input[0] + (-1) * input[1] + (-1) * input[2]
258 + (0) * input[3] + (0) * input[4] + (0) * input[5]
277 double p0 = -cos(azimuthFromThree.radians()) * tan(
m_zenith->
radians());
278 double q0 = -sin(azimuthFromThree.radians()) * tan(
m_zenith->
radians());
280 double numerator = 1.0 + p0 * p + q0 * q;
282 double denominator = sqrt(1 + p * p + q * q) * sqrt(1 + p0 * p0 + q0 * q0);
283 result = numerator / denominator;
295 std::swap(
m_zenith, other.m_zenith);
314 QString resolution =
"Null";
317 resolution =
toString(hillshade.resolution());
319 debug <<
"Hillshade[ azimuth =" << hillshade.azimuth().toString().toLatin1().data()
320 <<
"zenith =" << hillshade.zenith().toString().toLatin1().data()
321 <<
"resolution =" << resolution.toLatin1().data() <<
"]";
Defines an angle and provides unit conversions.
bool isValid() const
This indicates whether we have a legitimate angle stored or are in an unset, or invalid,...
double radians() const
Convert an angle to a double.
static Angle fullRotation()
Makes an angle to represent a full rotation (0-360 or 0-2pi).
@ Degrees
Degrees are generally considered more human readable, 0-360 is one circle, however most math does not...
virtual QString toString(bool includeUnits=true) const
Get the angle in human-readable form.
Buffer for reading and writing cube data.
Calculate light intensity reflected off a local slope of DEM.
Hillshade & operator=(const Hillshade &rhs)
Assignment operator.
Angle zenith() const
Get the current zenith angle.
void setResolution(double resolution)
The resolution is the meters per pixel of the input to shadedValue().
void setAzimuth(Angle azimuth)
The azimuth is the direction of the light.
Angle * m_zenith
This is the altitide of the light, with 0 directly overhead and 90 at the horizon.
void swap(Hillshade &other)
Swap class data with other; this cannot throw an exception.
Angle * m_azimuth
This is direction of the light, with 0 at north.
Hillshade()
Create a default-constructed Hillshade.
double m_pixelResolution
meters per pixel
Angle azimuth() const
Get the current azimuth angle.
double resolution() const
Get the current resolution (meters per pixel).
void setZenith(Angle zenith)
The zenith is the altitude/solar elevation of the light.
double shadedValue(Buffer &input) const
Calculate the shaded value from a 3x3x1 window.
@ Unknown
A type of error that cannot be classified as any of the other error types.
@ Programmer
This error is for when a programmer made an API call that was illegal.
This is free and unencumbered software released into the public domain.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
const double Null
Value for an Isis Null pixel.
bool IsSpecial(const double d)
Returns if the input pixel is special.
QDebug operator<<(QDebug debug, const Hillshade &hillshade)
Print this class out to a QDebug object.