OTB  6.7.0
Orfeo Toolbox
otbGdalDataTypeBridge.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 
22 #ifndef otbGdalDataTypeBridge_h
23 #define otbGdalDataTypeBridge_h
24 
25 #include <typeinfo>
26 #include "gdal.h"
27 
28 namespace otb
29 {
30 
31 
32 namespace GdalDataTypeBridge
33 {
34 
35 template<class Type>
36 GDALDataType GetGDALDataType()
37 {
38  if (typeid(Type) == typeid(char))
39  {
40  return GDT_Byte;
41  }
42  else if (typeid(Type) == typeid(unsigned char))
43  {
44  return GDT_Byte;
45  }
46  else if (typeid(Type) == typeid(unsigned short))
47  {
48  return GDT_UInt16;
49  }
50  else if (typeid(Type) == typeid(short))
51  {
52  return GDT_Int16;
53  }
54  else if (typeid(Type) == typeid(int))
55  {
56  return GDT_Int32;
57  }
58  else if (typeid(Type) == typeid(unsigned int))
59  {
60  return GDT_UInt32;
61  }
62  else if (typeid(Type) == typeid(long))
63  {
64  if( sizeof(long) == 8 )
65  {
66  //itkWarningMacro(<< "Cast a long (64 bit) image to an int (32 bit) one.")
67  }
68  return GDT_Int32;
69  }
70  else if (typeid(Type) == typeid(unsigned long))
71  {
72  if( sizeof(unsigned long) == 8 )
73  {
74  //itkWarningMacro(<< "Cast an unsigned long (64 bit) image to an unsigned int (32 bit) one.")
75  }
76  return GDT_UInt32;
77  }
78  else if (typeid(Type) == typeid(float))
79  {
80  return GDT_Float32;
81  }
82  else if (typeid(Type) == typeid(double))
83  {
84  return GDT_Float64;
85  }
86  else
87  {
88  return GDT_Byte;
89  }
90 }
91 
92 } // End namespace GdalDataTypeBridge
93 
94 
95 } // End namespace otb
96 
97 #endif