OTB  9.0.0
Orfeo Toolbox
otbImage.hxx
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_hxx
22 #define otbImage_hxx
23 
24 
25 #include "otbImage.h"
26 #include "itkMetaDataObject.h"
27 
28 namespace otb
29 {
30 
31 template <class TPixel, unsigned int VImageDimension>
33 {
34 }
35 
36 
37 template <class TPixel, unsigned int VImageDimension>
39 {
40  auto spacing = this->GetSpacing();
41  for (unsigned int i = 0; i < Image::ImageDimension; ++i)
42  {
43  if (this->m_Direction[i][i] < 0)
44  spacing[i] = -spacing[i];
45  }
46  return spacing;
47 }
48 
49 template <class TPixel, unsigned int VImageDimension>
51 {
52 
53  for (unsigned int i = 0; i < VImageDimension; i++)
54  {
55  if (spacing[i] < 0.0)
56  {
57  if (this->m_Direction[i][i] > 0)
58  {
59  for (unsigned j = 0; j < VImageDimension; ++j)
60  {
61  this->m_Direction[j][i] = -this->m_Direction[j][i];
62  }
63  }
64  spacing[i] = -spacing[i];
65  }
66  }
67  this->SetSpacing(spacing);
68  this->ComputeIndexToPhysicalPointMatrices();
69  this->Modified();
70 }
71 
72 template <class TPixel, unsigned int VImageDimension>
73 void Image<TPixel, VImageDimension>::SetSignedSpacing(double spacing[VImageDimension])
74 {
75  SpacingType s(spacing);
76  this->SetSignedSpacing(s);
77 }
78 
79 template <class TPixel, unsigned int VImageDimension>
80 void Image<TPixel, VImageDimension>::CopyInformation(const itk::DataObject* data)
81 {
82  Superclass::CopyInformation(data);
83  this->itk::Object::SetMetaDataDictionary(data->GetMetaDataDictionary());
84  const ImageCommons* imc = dynamic_cast<const ImageCommons*>(data);
85  if (imc != nullptr)
86  {
87  const auto & imd = imc->GetImageMetadata();
88 
89  if (imd.Bands.size() > 0 && imd.Bands.size() != this->GetNumberOfComponentsPerPixel())
90  {
91  SetImageMetadata(ImageMetadata(imd.GeometryKeys, imd.NumericKeys, imd.StringKeys, imd.LUT1DKeys,
92  imd.LUT2DKeys, imd.TimeKeys, imd.ExtraKeys, ImageMetadata::ImageMetadataBandsType(this->GetNumberOfComponentsPerPixel())));
93  }
94  else
95  {
96  SetImageMetadata(imd);
97  }
98  }
99 }
100 
101 template <class TPixel, unsigned int VImageDimension>
103 {
105 
106  auto origin = this->GetOrigin();
107  auto spacing = this->GetSpacing();
108  auto direction = this->GetDirection();
109 
110  // Note : OTB does not handle rotated geoTransform (see GDALImageIO)
111  geoTransform[0] = origin[0] - 0.5 * spacing[0] * direction[0][0];
112  geoTransform[3] = origin[1] - 0.5 * spacing[1] * direction[1][1];
113  geoTransform[1] = spacing[0] * direction[0][0];
114  geoTransform[5] = spacing[1] * direction[1][1];
115  geoTransform[2] = 0.;
116  geoTransform[4] = 0.;
117  return (geoTransform);
118 }
119 
120 
121 template <class TPixel, unsigned int VImageDimension>
124 {
125  PointType physicalPoint;
126  itk::ContinuousIndex<double, VImageDimension> index;
127  index.Fill(-0.5);
128  this->TransformContinuousIndexToPhysicalPoint (index, physicalPoint) ;
129  return {physicalPoint[0],physicalPoint[1]};
130 }
131 
132 template <class TPixel, unsigned int VImageDimension>
135 {
136  PointType physicalPoint;
137  itk::ContinuousIndex<double, VImageDimension> index;
138  index.Fill(-0.5);
139  index[0] = -0.5 + this->GetLargestPossibleRegion().GetSize()[0];
140  this->TransformContinuousIndexToPhysicalPoint (index, physicalPoint) ;
141  return {physicalPoint[0],physicalPoint[1]};
142 }
143 
144 template <class TPixel, unsigned int VImageDimension>
147 {
148  PointType physicalPoint;
149  itk::ContinuousIndex<double, VImageDimension> index;
150  index.Fill(-0.5);
151  index[1] = -0.5 + this->GetLargestPossibleRegion().GetSize()[1];
152  this->TransformContinuousIndexToPhysicalPoint (index, physicalPoint) ;
153  return {physicalPoint[0],physicalPoint[1]};
154 }
155 
156 template <class TPixel, unsigned int VImageDimension>
159 {
160  PointType physicalPoint;
161  itk::ContinuousIndex<double, VImageDimension> index;
162  index.Fill(-0.5);
163  index[0] = -0.5 + this->GetLargestPossibleRegion().GetSize()[0];
164  index[1] = -0.5 + this->GetLargestPossibleRegion().GetSize()[1];
165  this->TransformContinuousIndexToPhysicalPoint (index, physicalPoint) ;
166  return {physicalPoint[0],physicalPoint[1]};
167 }
168 
169 template <class TPixel, unsigned int VImageDimension>
170 void Image<TPixel, VImageDimension>::PrintSelf(std::ostream& os, itk::Indent indent) const
171 {
172  Superclass::PrintSelf(os, indent);
173  os << indent << this->GetImageMetadata();
174 }
175 
176 } // end namespace otb
177 #endif
otb::Image::GetUpperRightCorner
VectorType GetUpperRightCorner(void) const
Definition: otbImage.hxx:134
otb::Image::CopyInformation
void CopyInformation(const itk::DataObject *) override
Copy metadata from a DataObject.
Definition: otbImage.hxx:80
otb::Image::GetGeoTransform
virtual VectorType GetGeoTransform(void) const
Definition: otbImage.hxx:102
otbImage.h
otb::Image::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbImage.hxx:170
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Image::ImageDimension
static const unsigned int ImageDimension
Definition: otbImage.h:136
otb::Image::Image
Image()
Definition: otbImage.hxx:32
otb::Image::SetSignedSpacing
virtual void SetSignedSpacing(SpacingType spacing)
Definition: otbImage.hxx:50
otb::ImageCommons::GetImageMetadata
const ImageMetadata & GetImageMetadata() const
otb::ImageCommons
Definition: otbImageCommons.h:31
otb::Image::GetLowerRightCorner
VectorType GetLowerRightCorner(void) const
Definition: otbImage.hxx:158
otb::Image::GetLowerLeftCorner
VectorType GetLowerLeftCorner(void) const
Definition: otbImage.hxx:146
otb::Image::GetSignedSpacing
SpacingType GetSignedSpacing() const
Definition: otbImage.hxx:38
otb::Image::VectorType
ImageMetadataInterfaceBase::VectorType VectorType
Definition: otbImage.h:101
otb::Image::GetUpperLeftCorner
VectorType GetUpperLeftCorner(void) const
Definition: otbImage.hxx:123
otb::Image::SpacingType
Superclass::SpacingType SpacingType
Definition: otbImage.h:158
otb::Image< TOutputPixelType, 2 >::PointType
Superclass::PointType PointType
Definition: otbImage.h:162
otb::ImageMetadata
Generic class containing image metadata used in OTB.
Definition: otbImageMetadata.h:270
otb::internal::SetSignedSpacing
void SetSignedSpacing(InputImage *input, SpacingType spacing)
Definition: otbImage.h:53
otb::ImageMetadata::ImageMetadataBandsType
std::vector< ImageMetadataBase > ImageMetadataBandsType
Definition: otbImageMetadata.h:277