| 1 | /********************************************************************** |
| 2 | jldem_lib.cc: perform digital elevation model 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 | #include <assert.h> |
| 22 | #include <string> |
| 23 | #include <iostream> |
| 24 | #include <algorithm> |
| 25 | #include <memory> |
| 26 | #include "imageclasses/Jim.h" |
| 27 | #include "jldem_lib.h" |
| 28 | |
| 29 | using namespace std; |
| 30 | using namespace app; |
| 31 | |
| 32 | shared_ptr<Jim> Jim::hillShade(Jim& sza, Jim& saa){ |
| 33 | shared_ptr<Jim> imgWriter=Jim::createImg(); |
| 34 | hillShade(*imgWriter, sza, saa); |
| 35 | return(imgWriter); |
| 36 | } |
| 37 | |
| 38 | void Jim::hillShade(Jim& imgWriter, Jim& sza, Jim& saa){ |
| 39 | assert(sza.getDataType() == saa.getDataType()); |
| 40 | imgWriter.open(nrOfCol(),nrOfRow(), 1, 1, GDT_Byte); |
| 41 | imgWriter.copyGeoTransform(*this); |
| 42 | imgWriter.setProjection(this->getProjection()); |
| 43 | switch(getDataType()){ |
| 44 | case(GDT_Byte): |
| 45 | switch(sza.getDataType()){ |
| 46 | case(GDT_Byte): |
| 47 | hillShade_t<unsigned char,unsigned char>(imgWriter, sza, saa); |
| 48 | break; |
| 49 | case(GDT_Int16): |
| 50 | hillShade_t<unsigned char,short>(imgWriter, sza, saa); |
| 51 | break; |
| 52 | case(GDT_UInt16): |
| 53 | hillShade_t<unsigned char,unsigned short>(imgWriter, sza, saa); |
| 54 | break; |
| 55 | case(GDT_Int32): |
| 56 | hillShade_t<unsigned char,int>(imgWriter, sza, saa); |
| 57 | break; |
| 58 | case(GDT_UInt32): |
| 59 | hillShade_t<unsigned char,unsigned int>(imgWriter, sza, saa); |
| 60 | break; |
| 61 | case(GDT_Float32): |
| 62 | hillShade_t<unsigned char,float>(imgWriter, sza, saa); |
| 63 | break; |
| 64 | case(GDT_Float64): |
| 65 | hillShade_t<unsigned char,double>(imgWriter, sza, saa); |
| 66 | break; |
| 67 | default: |
| 68 | std::string errorString="Error: data type not supported"; |
| 69 | throw(errorString); |
| 70 | break; |
| 71 | } |
| 72 | break; |
| 73 | case(GDT_Int16): |
| 74 | switch(sza.getDataType()){ |
| 75 | case(GDT_Byte): |
| 76 | hillShade_t<short,unsigned char>(imgWriter, sza, saa); |
| 77 | break; |
| 78 | case(GDT_Int16): |
| 79 | hillShade_t<short,short>(imgWriter, sza, saa); |
| 80 | break; |
| 81 | case(GDT_UInt16): |
| 82 | hillShade_t<short,unsigned short>(imgWriter, sza, saa); |
| 83 | break; |
| 84 | case(GDT_Int32): |
| 85 | hillShade_t<short,int>(imgWriter, sza, saa); |
| 86 | break; |
| 87 | case(GDT_UInt32): |
| 88 | hillShade_t<short,unsigned int>(imgWriter, sza, saa); |
| 89 | break; |
| 90 | case(GDT_Float32): |
| 91 | hillShade_t<short,float>(imgWriter, sza, saa); |
| 92 | break; |
| 93 | case(GDT_Float64): |
| 94 | hillShade_t<short,double>(imgWriter, sza, saa); |
| 95 | break; |
| 96 | default: |
| 97 | std::string errorString="Error: data type not supported"; |
| 98 | throw(errorString); |
| 99 | break; |
| 100 | } |
| 101 | break; |
| 102 | case(GDT_UInt16): |
| 103 | switch(sza.getDataType()){ |
| 104 | case(GDT_Byte): |
| 105 | hillShade_t<unsigned short,unsigned char>(imgWriter, sza, saa); |
| 106 | break; |
| 107 | case(GDT_Int16): |
| 108 | hillShade_t<unsigned short,short>(imgWriter, sza, saa); |
| 109 | break; |
| 110 | case(GDT_UInt16): |
| 111 | hillShade_t<unsigned short,unsigned short>(imgWriter, sza, saa); |
| 112 | break; |
| 113 | case(GDT_Int32): |
| 114 | hillShade_t<unsigned short,int>(imgWriter, sza, saa); |
| 115 | break; |
| 116 | case(GDT_UInt32): |
| 117 | hillShade_t<unsigned short,unsigned int>(imgWriter, sza, saa); |
| 118 | break; |
| 119 | case(GDT_Float32): |
| 120 | hillShade_t<unsigned short,float>(imgWriter, sza, saa); |
| 121 | break; |
| 122 | case(GDT_Float64): |
| 123 | hillShade_t<unsigned short,double>(imgWriter, sza, saa); |
| 124 | break; |
| 125 | default: |
| 126 | std::string errorString="Error: data type not supported"; |
| 127 | throw(errorString); |
| 128 | break; |
| 129 | } |
| 130 | break; |
| 131 | case(GDT_Int32): |
| 132 | switch(sza.getDataType()){ |
| 133 | case(GDT_Byte): |
| 134 | hillShade_t<int,unsigned char>(imgWriter, sza, saa); |
| 135 | break; |
| 136 | case(GDT_Int16): |
| 137 | hillShade_t<int,short>(imgWriter, sza, saa); |
| 138 | break; |
| 139 | case(GDT_UInt16): |
| 140 | hillShade_t<int,unsigned short>(imgWriter, sza, saa); |
| 141 | break; |
| 142 | case(GDT_Int32): |
| 143 | hillShade_t<int,int>(imgWriter, sza, saa); |
| 144 | break; |
| 145 | case(GDT_UInt32): |
| 146 | hillShade_t<int,unsigned int>(imgWriter, sza, saa); |
| 147 | break; |
| 148 | case(GDT_Float32): |
| 149 | hillShade_t<int,float>(imgWriter, sza, saa); |
| 150 | break; |
| 151 | case(GDT_Float64): |
| 152 | hillShade_t<int,double>(imgWriter, sza, saa); |
| 153 | break; |
| 154 | default: |
| 155 | std::string errorString="Error: data type not supported"; |
| 156 | throw(errorString); |
| 157 | break; |
| 158 | } |
| 159 | break; |
| 160 | case(GDT_UInt32): |
| 161 | switch(sza.getDataType()){ |
| 162 | case(GDT_Byte): |
| 163 | hillShade_t<unsigned int,unsigned char>(imgWriter, sza, saa); |
| 164 | break; |
| 165 | case(GDT_Int16): |
| 166 | hillShade_t<unsigned int,short>(imgWriter, sza, saa); |
| 167 | break; |
| 168 | case(GDT_UInt16): |
| 169 | hillShade_t<unsigned int,unsigned short>(imgWriter, sza, saa); |
| 170 | break; |
| 171 | case(GDT_Int32): |
| 172 | hillShade_t<unsigned int,int>(imgWriter, sza, saa); |
| 173 | break; |
| 174 | case(GDT_UInt32): |
| 175 | hillShade_t<unsigned int,unsigned int>(imgWriter, sza, saa); |
| 176 | break; |
| 177 | case(GDT_Float32): |
| 178 | hillShade_t<unsigned int,float>(imgWriter, sza, saa); |
| 179 | break; |
| 180 | case(GDT_Float64): |
| 181 | hillShade_t<unsigned int,double>(imgWriter, sza, saa); |
| 182 | break; |
| 183 | default: |
| 184 | std::string errorString="Error: data type not supported"; |
| 185 | throw(errorString); |
| 186 | break; |
| 187 | } |
| 188 | break; |
| 189 | case(GDT_Float32): |
| 190 | switch(sza.getDataType()){ |
| 191 | case(GDT_Byte): |
| 192 | hillShade_t<float,unsigned char>(imgWriter, sza, saa); |
| 193 | break; |
| 194 | case(GDT_Int16): |
| 195 | hillShade_t<float,short>(imgWriter, sza, saa); |
| 196 | break; |
| 197 | case(GDT_UInt16): |
| 198 | hillShade_t<float,unsigned short>(imgWriter, sza, saa); |
| 199 | break; |
| 200 | case(GDT_Int32): |
| 201 | hillShade_t<float,int>(imgWriter, sza, saa); |
| 202 | break; |
| 203 | case(GDT_UInt32): |
| 204 | hillShade_t<float,unsigned int>(imgWriter, sza, saa); |
| 205 | break; |
| 206 | case(GDT_Float32): |
| 207 | hillShade_t<float,float>(imgWriter, sza, saa); |
| 208 | break; |
| 209 | case(GDT_Float64): |
| 210 | hillShade_t<float,double>(imgWriter, sza, saa); |
| 211 | break; |
| 212 | default: |
| 213 | std::string errorString="Error: data type not supported"; |
| 214 | throw(errorString); |
| 215 | break; |
| 216 | } |
| 217 | break; |
| 218 | case(GDT_Float64): |
| 219 | switch(sza.getDataType()){ |
| 220 | case(GDT_Byte): |
| 221 | hillShade_t<double,unsigned char>(imgWriter, sza, saa); |
| 222 | break; |
| 223 | case(GDT_Int16): |
| 224 | hillShade_t<double,short>(imgWriter, sza, saa); |
| 225 | break; |
| 226 | case(GDT_UInt16): |
| 227 | hillShade_t<double,unsigned short>(imgWriter, sza, saa); |
| 228 | break; |
| 229 | case(GDT_Int32): |
| 230 | hillShade_t<double,int>(imgWriter, sza, saa); |
| 231 | break; |
| 232 | case(GDT_UInt32): |
| 233 | hillShade_t<double,unsigned int>(imgWriter, sza, saa); |
| 234 | break; |
| 235 | case(GDT_Float32): |
| 236 | hillShade_t<double,float>(imgWriter, sza, saa); |
| 237 | break; |
| 238 | case(GDT_Float64): |
| 239 | hillShade_t<double,double>(imgWriter, sza, saa); |
| 240 | break; |
| 241 | default: |
| 242 | std::string errorString="Error: data type not supported"; |
| 243 | throw(errorString); |
| 244 | break; |
| 245 | } |
| 246 | break; |
| 247 | default: |
| 248 | std::string errorString="Error: data type not supported"; |
| 249 | throw(errorString); |
| 250 | break; |
| 251 | } |
| 252 | } |