OTB  6.7.0
Orfeo Toolbox
otbImage.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 #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;
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 
132 
137  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
138 
140  typedef typename Superclass::PixelContainer PixelContainer;
141 
144 
146  typedef typename Superclass::OffsetType OffsetType;
147 
149  typedef typename Superclass::SizeType SizeType;
150 
152  typedef typename Superclass::DirectionType DirectionType;
153 
155  typedef typename Superclass::RegionType RegionType;
156 
160 
164 
168 
170  typedef typename Superclass::OffsetValueType OffsetValueType;
171 
173 // AccessorType GetPixelAccessor( void )
174 // {
175 // return AccessorType();
176 // }
177 
179 // const AccessorType GetPixelAccessor( void ) const
180 // {
181 // return AccessorType();
182 // }
183 
186  {
188  }
189 
192  {
194  }
195 
197  virtual std::string GetProjectionRef(void) const;
198 
199  virtual void SetProjectionRef(const std::string& wkt);
200 
201 
203  virtual std::string GetGCPProjection(void) const;
204 
205  virtual unsigned int GetGCPCount(void) const;
206 
207  virtual OTB_GCP& GetGCPs(unsigned int GCPnum);
208  virtual const OTB_GCP& GetGCPs(unsigned int GCPnum) const;
209 
210  virtual std::string GetGCPId(unsigned int GCPnum) const;
211  virtual std::string GetGCPInfo(unsigned int GCPnum) const;
212  virtual double GetGCPRow(unsigned int GCPnum) const;
213  virtual double GetGCPCol(unsigned int GCPnum) const;
214  virtual double GetGCPX(unsigned int GCPnum) const;
215  virtual double GetGCPY(unsigned int GCPnum) const;
216  virtual double GetGCPZ(unsigned int GCPnum) const;
217 
219  virtual VectorType GetGeoTransform(void) const;
220 
223 
224  // SpacingType GetSpacing() const
225  // {
226  // PixelType a;
227  // a.toto();
228  // SpacingType t = this->GetSignedSpacing();
229  // return t ;
230  // };
231 
233  virtual void SetSignedSpacing( SpacingType spacing );
234  virtual void SetSignedSpacing( double spacing[ VImageDimension ] );
236 
238  virtual VectorType GetUpperLeftCorner(void) const;
239  virtual VectorType GetUpperRightCorner(void) const;
240  virtual VectorType GetLowerLeftCorner(void) const;
241  virtual VectorType GetLowerRightCorner(void) const;
243 
245  virtual ImageKeywordlistType GetImageKeywordlist(void);
246 
247  virtual const ImageKeywordlistType GetImageKeywordlist(void) const;
248 
249  virtual void SetImageKeywordList(const ImageKeywordlistType& kwl);
250 
251  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
252 
254  void CopyInformation(const itk::DataObject *) override;
255 
256 protected:
257  Image();
258  ~Image() override {}
259 
260 private:
261  Image(const Self &) = delete;
262  void operator =(const Self&) = delete;
263 
267  ImageMetadataInterfacePointerType GetMetaDataInterface() const;
268 
269  // The image metadata accessor object. Don't use it directly. Instead use GetMetaDataInterface()
271 
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 // Prevent implicit instanciation of common types to improve build performance
285 // Explicit instanciations are provided in the .cxx
286 extern template class OTBImageBase_EXPORT_TEMPLATE Image<unsigned int, 2>;
287 extern template class OTBImageBase_EXPORT_TEMPLATE Image<int, 2>;
288 extern template class OTBImageBase_EXPORT_TEMPLATE Image<unsigned char, 2>;
289 extern template class OTBImageBase_EXPORT_TEMPLATE Image<char, 2>;
290 extern template class OTBImageBase_EXPORT_TEMPLATE Image<unsigned short, 2>;
291 extern template class OTBImageBase_EXPORT_TEMPLATE Image<short, 2>;
292 extern template class OTBImageBase_EXPORT_TEMPLATE Image<float, 2>;
293 extern template class OTBImageBase_EXPORT_TEMPLATE Image<double, 2>;
294 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<int> , 2>;
295 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<short> , 2>;
296 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<float> , 2>;
297 extern template class OTBImageBase_EXPORT_TEMPLATE Image<std::complex<double> , 2>;
298 
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:185
PixelContainer::Pointer PixelContainerPointer
Definition: otbImage.h:166
Superclass::RegionType RegionType
Definition: otbImage.h:155
Storage and conversion for OSSIM metadata.
std::vector< double > VectorType
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:270
Superclass::PixelContainer PixelContainer
Definition: otbImage.h:140
const NeighborhoodAccessorFunctorType GetNeighborhoodAccessor() const
Definition: otbImage.h:191
Superclass::IndexType IndexType
Definition: otbImage.h:143
template class OTBImageBase_EXPORT_TEMPLATE Image< unsigned short, 2 >
ImageMetadataInterfaceBase::Pointer ImageMetadataInterfacePointerType
Definition: otbImage.h:101
template class OTBImageBase_EXPORT_TEMPLATE Image< float, 2 >
ImageMetadataInterfaceBase::ImageKeywordlistType ImageKeywordlistType
Definition: otbImage.h:100
Superclass::PointType PointType
Definition: otbImage.h:163
itk::NeighborhoodAccessorFunctor< Self > NeighborhoodAccessorFunctorType
Definition: otbImage.h:131
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:170
itk::SmartPointer< const Self > ConstPointer
Definition: otbImage.h:96
itk::Index< Monteverdi_DIMENSION > IndexType
Definition: mvdTypes.h:133
template class OTBImageBase_EXPORT_TEMPLATE Image< int, 2 >
template class OTBImageBase_EXPORT_TEMPLATE Image< double, 2 >
PixelContainer::ConstPointer PixelContainerConstPointer
Definition: otbImage.h:167
~Image() override
Definition: otbImage.h:258
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:152
Image Self
Definition: otbImage.h:93
template class OTBImageBase_EXPORT_TEMPLATE Image< short, 2 >
Superclass::SpacingType SpacingType
Definition: otbImage.h:159
template class OTBImageBase_EXPORT_TEMPLATE Image< char, 2 >
Superclass::OffsetType OffsetType
Definition: otbImage.h:146
template class OTBImageBase_EXPORT_TEMPLATE Image< unsigned int, 2 >
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:181
itk::SmartPointer< Self > Pointer
Definition: otbImage.h:95
template class OTBImageBase_EXPORT_TEMPLATE Image< unsigned char, 2 >
VectorImageType::PointType PointType
Definition: mvdTypes.h:189
itk::WeakPointer< const Self > ConstWeakPointer
Definition: otbImage.h:97
Superclass::SizeType SizeType
Definition: otbImage.h:149