OTB  9.0.0
Orfeo Toolbox
otbImage.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 #ifndef otbImage_h
22 #define otbImage_h
23 
24 #if defined(__GNUC__) || defined(__clang__)
25 #pragma GCC diagnostic push
26 #pragma GCC diagnostic ignored "-Wunused-parameter"
27 #include "itkImage.h"
28 #pragma GCC diagnostic pop
29 #else
30 #include "itkImage.h"
31 #endif
32 
33 #include "otbImageCommons.h"
34 #include "OTBImageBaseExport.h"
35 
36 namespace otb
37 {
38 namespace internal
39 {
40 template <class ImageType>
41 typename ImageType::SpacingType GetSignedSpacing(const ImageType* input)
42 {
43  typename ImageType::SpacingType spacing = input->GetSpacing();
44  typename ImageType::DirectionType direction = input->GetDirection();
45  for (unsigned int i = 0; i < ImageType::ImageDimension; i++)
46  {
47  spacing[i] *= direction[i][i];
48  }
49  return spacing;
50 }
51 
52 template <class InputImage, typename SpacingType>
53 void SetSignedSpacing(InputImage* input, SpacingType spacing)
54 {
55  // TODO check for spacing size ==> error
56  typename InputImage::DirectionType direction = input->GetDirection();
57  for (unsigned int i = 0; i < InputImage::ImageDimension; i++)
58  {
59  // TODO check if spacing[i] = 0 ==> error
60  if (spacing[i] < 0)
61  {
62  if (direction[i][i] > 0)
63  {
64  for (unsigned int j = 0; j < InputImage::ImageDimension; j++)
65  {
66  direction[j][i] = -direction[j][i];
67  }
68  }
69  spacing[i] = -spacing[i];
70  }
71  }
72  input->SetDirection(direction);
73  input->SetSpacing(spacing);
74 }
75 }
76 }
77 
78 
79 namespace otb
80 {
88 template <class TPixel, unsigned int VImageDimension = 2>
89 class OTBImageBase_EXPORT_TEMPLATE Image
90  : public itk::Image<TPixel, VImageDimension>
91  , public ImageCommons
92 {
93 public:
95  using Self = Image;
96  using Superclass = itk::Image<TPixel, VImageDimension>;
97  using Pointer = itk::SmartPointer<Self>;
98  using ConstPointer = itk::SmartPointer<const Self>;
99  using ConstWeakPointer = itk::WeakPointer<const Self>;
100 
102 
104  itkNewMacro(Self);
105 
107  itkTypeMacro(Image, itk::Image);
108 
111  typedef typename Superclass::PixelType PixelType;
112 
114  typedef typename Superclass::ValueType ValueType;
115 
120  typedef typename Superclass::InternalPixelType InternalPixelType;
121 
122  typedef typename Superclass::IOPixelType IOPixelType;
123 
126  // typedef itk::DefaultPixelAccessor< PixelType > AccessorType;
127  // typedef itk::DefaultPixelAccessorFunctor< Self > AccessorFunctorType;
128 
130  typedef itk::NeighborhoodAccessorFunctor<Self> NeighborhoodAccessorFunctorType;
131 
136  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
137 
139  typedef typename Superclass::PixelContainer PixelContainer;
140 
142  typedef typename Superclass::IndexType IndexType;
143 
145  typedef typename Superclass::OffsetType OffsetType;
146 
148  typedef typename Superclass::SizeType SizeType;
149 
151  typedef typename Superclass::DirectionType DirectionType;
152 
154  typedef typename Superclass::RegionType RegionType;
155 
158  typedef typename Superclass::SpacingType SpacingType;
159 
162  typedef typename Superclass::PointType PointType;
163 
165  typedef typename PixelContainer::Pointer PixelContainerPointer;
166  typedef typename PixelContainer::ConstPointer PixelContainerConstPointer;
167 
169  typedef typename Superclass::OffsetValueType OffsetValueType;
170 
172  // AccessorType GetPixelAccessor( void )
173  // {
174  // return AccessorType();
175  // }
176 
178  // const AccessorType GetPixelAccessor( void ) const
179  // {
180  // return AccessorType();
181  // }
182 
185  {
187  }
188 
191  {
193  }
194 
195 
197  virtual VectorType GetGeoTransform(void) const;
198 
200  // TODO: GenericRSTransform should be instantiated to translate from physical
201  // space to EPSG:4328 ?
202  VectorType GetUpperLeftCorner(void) const;
203  VectorType GetUpperRightCorner(void) const;
204  VectorType GetLowerLeftCorner(void) const;
205  VectorType GetLowerRightCorner(void) const;
207 
209  SpacingType GetSignedSpacing() const;
210 
211  // SpacingType GetSpacing() const
212  // {
213  // PixelType a;
214  // a.toto();
215  // SpacingType t = this->GetSignedSpacing();
216  // return t ;
217  // };
218 
220  virtual void SetSignedSpacing(SpacingType spacing);
221  virtual void SetSignedSpacing(double spacing[VImageDimension]);
223 
224  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
225 
227  void CopyInformation(const itk::DataObject*) override;
228 
229 protected:
230  Image();
231  ~Image() override
232  {
233  }
234 
235 private:
236  Image(const Self&) = delete;
237  void operator=(const Self&) = delete;
238 };
239 
240 } // end namespace otb
241 
242 #ifndef OTB_MANUAL_INSTANTIATION
243 #include "otbImage.hxx"
244 #endif
245 
246 #include <complex>
247 
248 namespace otb
249 {
250 
251 // Prevent implicit instantiation of common types to improve build performance
252 // Explicit instantiations are provided in the .cxx
253 extern template class OTBImageBase_EXPORT_TEMPLATE Image<unsigned int, 2>;
254 extern template class OTBImageBase_EXPORT_TEMPLATE Image<int, 2>;
255 extern template class OTBImageBase_EXPORT_TEMPLATE Image<unsigned char, 2>;
256 extern template class OTBImageBase_EXPORT_TEMPLATE Image<char, 2>;
257 extern template class OTBImageBase_EXPORT_TEMPLATE Image<unsigned short, 2>;
258 extern template class OTBImageBase_EXPORT_TEMPLATE Image<short, 2>;
259 extern template class OTBImageBase_EXPORT_TEMPLATE Image<float, 2>;
260 extern template class OTBImageBase_EXPORT_TEMPLATE Image<double, 2>;
261 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<int>, 2>;
262 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<short>, 2>;
263 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<float>, 2>;
264 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<double>, 2>;
265 }
266 
267 #endif
otb::Image::OffsetType
Superclass::OffsetType OffsetType
Definition: otbImage.h:145
otb::Image< short, 2 >
template class OTBImageBase_EXPORT_TEMPLATE Image< short, 2 >
otb::Image::IOPixelType
Superclass::IOPixelType IOPixelType
Definition: otbImage.h:122
otb::Image::IndexType
Superclass::IndexType IndexType
Definition: otbImage.h:142
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Image
Creation of an "otb" image which contains metadata.
Definition: otbImage.h:89
otb::MetaDataKey::VectorType
std::vector< double > VectorType
Definition: otbMetaDataKey.h:119
otb::Image< TOutputPixelType, 2 >::Superclass
itk::Image< TOutputPixelType, VImageDimension > Superclass
Definition: otbImage.h:96
otb::Image::PixelContainer
Superclass::PixelContainer PixelContainer
Definition: otbImage.h:139
otb::Image< double, 2 >
template class OTBImageBase_EXPORT_TEMPLATE Image< double, 2 >
otb::Image< TOutputPixelType, 2 >::ConstWeakPointer
itk::WeakPointer< const Self > ConstWeakPointer
Definition: otbImage.h:99
otb::ImageCommons
Definition: otbImageCommons.h:31
otb::Image::~Image
~Image() override
Definition: otbImage.h:231
otb::Image< float, 2 >
template class OTBImageBase_EXPORT_TEMPLATE Image< float, 2 >
otb::Image< int, 2 >
template class OTBImageBase_EXPORT_TEMPLATE Image< int, 2 >
otb::Image::InternalPixelType
Superclass::InternalPixelType InternalPixelType
Definition: otbImage.h:120
otb::Image< TOutputPixelType, 2 >::VectorType
ImageMetadataInterfaceBase::VectorType VectorType
Definition: otbImage.h:101
otb::Image::PixelContainerConstPointer
PixelContainer::ConstPointer PixelContainerConstPointer
Definition: otbImage.h:166
otb::Image< TOutputPixelType, 2 >::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbImage.h:98
otb::Image::PixelContainerPointer
PixelContainer::Pointer PixelContainerPointer
Definition: otbImage.h:165
otb::Image< char, 2 >
template class OTBImageBase_EXPORT_TEMPLATE Image< char, 2 >
otb::Image::NeighborhoodAccessorFunctorType
itk::NeighborhoodAccessorFunctor< Self > NeighborhoodAccessorFunctorType
Definition: otbImage.h:130
otb::ImageMetadataInterfaceBase::VectorType
MetaDataKey::VectorType VectorType
Definition: otbImageMetadataInterfaceBase.h:57
otb::Image::DirectionType
Superclass::DirectionType DirectionType
Definition: otbImage.h:151
otb::Image< unsigned short, 2 >
template class OTBImageBase_EXPORT_TEMPLATE Image< unsigned short, 2 >
otb::Image< unsigned int, 2 >
template class OTBImageBase_EXPORT_TEMPLATE Image< unsigned int, 2 >
otb::Image::SpacingType
Superclass::SpacingType SpacingType
Definition: otbImage.h:158
otb::Image::PointType
Superclass::PointType PointType
Definition: otbImage.h:162
otb::internal::GetSignedSpacing
ImageType::SpacingType GetSignedSpacing(const ImageType *input)
Definition: otbImage.h:41
otb::Image::PixelType
Superclass::PixelType PixelType
Definition: otbImage.h:107
otb::Image< TOutputPixelType, 2 >::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbImage.h:97
otbImage.hxx
otb::Image::RegionType
Superclass::RegionType RegionType
Definition: otbImage.h:154
otb::Image::OffsetValueType
Superclass::OffsetValueType OffsetValueType
Definition: otbImage.h:169
otb::Image::GetNeighborhoodAccessor
const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
Definition: otbImage.h:190
otb::Image::GetNeighborhoodAccessor
NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
Definition: otbImage.h:184
otb::Image::ValueType
Superclass::ValueType ValueType
Definition: otbImage.h:114
otb::Image< unsigned char, 2 >
template class OTBImageBase_EXPORT_TEMPLATE Image< unsigned char, 2 >
otb::internal::SetSignedSpacing
void SetSignedSpacing(InputImage *input, SpacingType spacing)
Definition: otbImage.h:53
otbImageCommons.h
otb::Image::SizeType
Superclass::SizeType SizeType
Definition: otbImage.h:148