OTB  7.2.0
Orfeo Toolbox
otbImage.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2020 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 
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 : public itk::Image<TPixel, VImageDimension>
90 {
91 public:
93  typedef Image Self;
94  typedef itk::Image<TPixel, VImageDimension> Superclass;
95  typedef itk::SmartPointer<Self> Pointer;
96  typedef itk::SmartPointer<const Self> ConstPointer;
97  typedef itk::WeakPointer<const Self> ConstWeakPointer;
98 
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 
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 
159 
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 
184  NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
185  {
186  return NeighborhoodAccessorFunctorType();
187  }
188 
190  const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
191  {
192  return NeighborhoodAccessorFunctorType();
193  }
194 
196  virtual std::string GetProjectionRef(void) const;
197 
198  virtual void SetProjectionRef(const std::string& wkt);
199 
200 
202  virtual std::string GetGCPProjection(void) const;
203 
204  virtual unsigned int GetGCPCount(void) const;
205 
206  virtual OTB_GCP& GetGCPs(unsigned int GCPnum);
207  virtual const OTB_GCP& GetGCPs(unsigned int GCPnum) const;
208 
209  virtual std::string GetGCPId(unsigned int GCPnum) const;
210  virtual std::string GetGCPInfo(unsigned int GCPnum) const;
211  virtual double GetGCPRow(unsigned int GCPnum) const;
212  virtual double GetGCPCol(unsigned int GCPnum) const;
213  virtual double GetGCPX(unsigned int GCPnum) const;
214  virtual double GetGCPY(unsigned int GCPnum) const;
215  virtual double GetGCPZ(unsigned int GCPnum) const;
216 
218  virtual VectorType GetGeoTransform(void) const;
219 
221  SpacingType GetSignedSpacing() const;
222 
223  // SpacingType GetSpacing() const
224  // {
225  // PixelType a;
226  // a.toto();
227  // SpacingType t = this->GetSignedSpacing();
228  // return t ;
229  // };
230 
232  virtual void SetSignedSpacing(SpacingType spacing);
233  virtual void SetSignedSpacing(double spacing[VImageDimension]);
235 
237  virtual VectorType GetUpperLeftCorner(void) const;
238  virtual VectorType GetUpperRightCorner(void) const;
239  virtual VectorType GetLowerLeftCorner(void) const;
240  virtual VectorType GetLowerRightCorner(void) const;
242 
244  virtual ImageKeywordlistType GetImageKeywordlist(void);
245 
246  virtual const ImageKeywordlistType GetImageKeywordlist(void) const;
247 
248  virtual void SetImageKeywordList(const ImageKeywordlistType& kwl);
249 
250  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
251 
253  void CopyInformation(const itk::DataObject*) override;
254 
255 protected:
256  Image();
257  ~Image() override
258  {
259  }
260 
261 private:
262  Image(const Self&) = delete;
263  void operator=(const Self&) = delete;
264 
268  ImageMetadataInterfacePointerType GetMetaDataInterface() const;
269 
270  // The image metadata accessor object. Don't use it directly. Instead use GetMetaDataInterface()
271  mutable ImageMetadataInterfacePointerType m_ImageMetadataInterface;
272 };
273 
274 } // end namespace otb
275 
276 #ifndef OTB_MANUAL_INSTANTIATION
277 #include "otbImage.hxx"
278 #endif
279 
280 #include <complex>
281 
282 namespace otb
283 {
284 
285 // Prevent implicit instantiation of common types to improve build performance
286 // Explicit instanciations are provided in the .cxx
287 extern template class OTBImageBase_EXPORT_TEMPLATE Image<unsigned int, 2>;
288 extern template class OTBImageBase_EXPORT_TEMPLATE Image<int, 2>;
289 extern template class OTBImageBase_EXPORT_TEMPLATE Image<unsigned char, 2>;
290 extern template class OTBImageBase_EXPORT_TEMPLATE Image<char, 2>;
291 extern template class OTBImageBase_EXPORT_TEMPLATE Image<unsigned short, 2>;
292 extern template class OTBImageBase_EXPORT_TEMPLATE Image<short, 2>;
293 extern template class OTBImageBase_EXPORT_TEMPLATE Image<float, 2>;
294 extern template class OTBImageBase_EXPORT_TEMPLATE Image<double, 2>;
295 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<int>, 2>;
296 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<short>, 2>;
297 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<float>, 2>;
298 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<double>, 2>;
299 }
300 
301 #endif
itk::Size< Monteverdi_DIMENSION > SizeType
Definition: mvdTypes.h:137
Superclass::ValueType ValueType
Definition: otbImage.h:114
NeighborhoodAccessorFunctorType GetNeighborhoodAccessor()
Definition: otbImage.h:184
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
PixelContainer::Pointer PixelContainerPointer
Definition: otbImage.h:165
const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
Definition: otbImage.h:190
Superclass::RegionType RegionType
Definition: otbImage.h:154
Storage and conversion for OSSIM metadata.
This OTB_GCP class is used to manage the GCP parameters in OTB.
void SetSignedSpacing(InputImage *input, SpacingType spacing)
Definition: otbImage.h:53
ImageMetadataInterfacePointerType m_ImageMetadataInterface
Definition: otbImage.h:271
Superclass::PixelContainer PixelContainer
Definition: otbImage.h:139
Superclass::IndexType IndexType
Definition: otbImage.h:142
ImageMetadataInterfaceBase::Pointer ImageMetadataInterfacePointerType
Definition: otbImage.h:101
ImageMetadataInterfaceBase::ImageKeywordlistType ImageKeywordlistType
Definition: otbImage.h:100
Superclass::PointType PointType
Definition: otbImage.h:162
itk::NeighborhoodAccessorFunctor< Self > NeighborhoodAccessorFunctorType
Definition: otbImage.h:130
itk::Image< TPixel, VImageDimension > Superclass
Definition: otbImage.h:94
ImageType::SpacingType GetSignedSpacing(const ImageType *input)
Definition: otbImage.h:41
Superclass::OffsetValueType OffsetValueType
Definition: otbImage.h:169
itk::SmartPointer< const Self > ConstPointer
Definition: otbImage.h:96
PixelContainer::ConstPointer PixelContainerConstPointer
Definition: otbImage.h:166
~Image() override
Definition: otbImage.h:257
Creation of an "otb" image which contains metadata.
Definition: otbImage.h:89
Superclass::IOPixelType IOPixelType
Definition: otbImage.h:122
Superclass::DirectionType DirectionType
Definition: otbImage.h:151
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Image Self
Definition: otbImage.h:93
Superclass::SpacingType SpacingType
Definition: otbImage.h:158
Superclass::OffsetType OffsetType
Definition: otbImage.h:145
ImageMetadataInterfaceBase::VectorType VectorType
Definition: otbImage.h:99
Superclass::PixelType PixelType
Definition: otbImage.h:107
Superclass::InternalPixelType InternalPixelType
Definition: otbImage.h:120
VectorImageType::SpacingType SpacingType
Definition: mvdTypes.h:175
itk::SmartPointer< Self > Pointer
Definition: otbImage.h:95
VectorImageType::PointType PointType
Definition: mvdTypes.h:183
itk::WeakPointer< const Self > ConstWeakPointer
Definition: otbImage.h:97
Superclass::SizeType SizeType
Definition: otbImage.h:148