Debian Codegraph @

src/imageclasses/jldem_lib.h

raw symbols SCIP
1 /**********************************************************************
2 jldsm_lib.h: perform digital elevation model data operations on image
3 Author(s): [email protected]
4 Copyright (C) 2016-2022 European Union (Joint Research Centre)
5
6 This file is part of jiplib.
7
8 jiplib is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 jiplib is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with jiplib. If not, see <https://www.gnu.org/licenses/>.
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));//in pixels
49 // int theDist=static_cast<int>(sqrt((currentValue*tan(DEG2RAD(psza[index]))/pixelSize)*(currentValue*tan(DEG2RAD(psza[index]))/pixelSize)));//in pixels
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){//d in pixels
58 size_t indexI=x+d*cos(theDir);//in pixels
59 size_t indexJ=y+d*sin(theDir);//in pixels
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))//in m
66 ptrt[pos]=1;
67 }
68 }
69 }
70 #endif // _JLDEM_LIB_H_