| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef _JLDEM_LIB_H_ |
| 22 |
#define _JLDEM_LIB_H_ |
| 23 |
#include "imageclasses/Jim.h" |
| 24 |
|
| 25 |
#ifndef PI |
| 26 |
#define PI 3.1415926535897932384626433832795 |
| 27 |
#endif |
| 28 |
|
| 29 |
#ifndef DEG2RAD |
| 30 |
#define DEG2RAD(DEG) (DEG/180.0*PI) |
| 31 |
#endif |
| 32 |
|
| 33 |
#ifndef RAD2DEG |
| 34 |
#define RAD2DEG(RAD) (RAD/PI*180) |
| 35 |
#endif |
| 36 |
|
| 37 |
template<class T1, class T2> void Jim::hillShade_t(Jim& imgWriter, Jim& sza, Jim& saa){ |
| 38 |
T1* psrc=static_cast<T1*>(getDataPointer()); |
| 39 |
T2* psza=static_cast<T2*>(sza.getDataPointer()); |
| 40 |
T2* psaa=static_cast<T2*>(saa.getDataPointer()); |
| 41 |
unsigned char* ptrt=static_cast<unsigned char*>(imgWriter.getDataPointer()); |
| 42 |
double pixelSize = getDeltaX(); |
| 43 |
for(size_t index=0;index<nrOfCol()*nrOfRow();++index){ |
| 44 |
double currentValue = psrc[index]; |
| 45 |
ptrt[index]=0; |
| 46 |
double tansza = tan(DEG2RAD(psza[index])); |
| 47 |
double product = currentValue*tansza/pixelSize; |
| 48 |
int theDist=static_cast<int>(sqrt(product*product)); |
| 49 |
|
| 50 |
double theDir=DEG2RAD(psaa[index])+PI/2.0; |
| 51 |
if(theDir<0) |
| 52 |
theDir+=2*PI; |
| 53 |
std::div_t dv{}; |
| 54 |
dv = std::div(index, nrOfCol()); |
| 55 |
double x = dv.rem; |
| 56 |
double y = dv.quot; |
| 57 |
for(int d=0;d<theDist;++d){ |
| 58 |
size_t indexI=x+d*cos(theDir); |
| 59 |
size_t indexJ=y+d*sin(theDir); |
| 60 |
size_t pos = (indexJ)*nrOfCol() + indexI; |
| 61 |
if(indexJ<0||indexJ>=nrOfRow()) |
| 62 |
continue; |
| 63 |
if(indexI<0||indexI>=nrOfCol()) |
| 64 |
continue; |
| 65 |
if(tansza > 0 && (psrc[pos]<currentValue-d*pixelSize/tansza)) |
| 66 |
ptrt[pos]=1; |
| 67 |
} |
| 68 |
} |
| 69 |
} |
| 70 |
#endif |