OTB  9.0.0
Orfeo Toolbox
otbVectorImage.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 otbVectorImage_hxx
22 #define otbVectorImage_hxx
23 
24 
25 #include "otbVectorImage.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 < VImageDimension; ++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 VectorImage<TPixel, VImageDimension>::SetSignedSpacing(double spacing[VImageDimension])
74 {
75  SpacingType s(spacing);
76  this->SetSignedSpacing(s);
77 }
78 
79 template <class TPixel, unsigned int VImageDimension>
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  // std::cout << "hello " << this->GetNumberOfComponentsPerPixel() << std::endl;
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 
102 template< typename TPixel, unsigned int VImageDimension >
103 void
105 {
106  if (this->GetNumberOfComponentsPerPixel() != n)
107  {
108  SetBandImageMetadata(ImageMetadata::ImageMetadataBandsType(n));
109  }
110 
111  Superclass::SetNumberOfComponentsPerPixel(n);
112 }
113 
114 template <class TPixel, unsigned int VImageDimension>
116 {
118 
119  auto origin = this->GetOrigin();
120  auto spacing = this->GetSpacing();
121  auto direction = this->GetDirection();
122 
123  // Note : OTB does not handle rotated geoTransform (see GDALImageIO)
124  geoTransform[0] = origin[0] - 0.5 * spacing[0] * direction[0][0];
125  geoTransform[3] = origin[1] - 0.5 * spacing[1] * direction[1][1];
126  geoTransform[1] = spacing[0] * direction[0][0];
127  geoTransform[5] = spacing[1] * direction[1][1];
128  geoTransform[2] = 0.;
129  geoTransform[4] = 0.;
130  return (geoTransform);
131 }
132 
133 
134 template <class TPixel, unsigned int VImageDimension>
137 {
138  PointType physicalPoint;
139  itk::ContinuousIndex<double, VImageDimension> index;
140  index.Fill(-0.5);
141  this->TransformContinuousIndexToPhysicalPoint (index, physicalPoint) ;
142  return {physicalPoint[0],physicalPoint[1]};
143 }
144 
145 template <class TPixel, unsigned int VImageDimension>
148 {
149  PointType physicalPoint;
150  itk::ContinuousIndex<double, VImageDimension> index;
151  index.Fill(-0.5);
152  index[0] = -0.5 + this->GetLargestPossibleRegion().GetSize()[0];
153  this->TransformContinuousIndexToPhysicalPoint (index, physicalPoint) ;
154  return {physicalPoint[0],physicalPoint[1]};
155 }
156 
157 template <class TPixel, unsigned int VImageDimension>
160 {
161  PointType physicalPoint;
162  itk::ContinuousIndex<double, VImageDimension> index;
163  index.Fill(-0.5);
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>
172 {
173  PointType physicalPoint;
174  itk::ContinuousIndex<double, VImageDimension> index;
175  index.Fill(-0.5);
176  index[0] = -0.5 + this->GetLargestPossibleRegion().GetSize()[0];
177  index[1] = -0.5 + this->GetLargestPossibleRegion().GetSize()[1];
178  this->TransformContinuousIndexToPhysicalPoint (index, physicalPoint) ;
179  return {physicalPoint[0],physicalPoint[1]};
180 }
181 
182 template <class TPixel, unsigned int VImageDimension>
183 void VectorImage<TPixel, VImageDimension>::PrintSelf(std::ostream& os, itk::Indent indent) const
184 {
185  Superclass::PrintSelf(os, indent);
186  os << indent << this->GetImageMetadata();
187 }
188 
189 } // end namespace otb
190 #endif
otb::VectorImage::GetGeoTransform
virtual VectorType GetGeoTransform(void) const
Definition: otbVectorImage.hxx:115
otb::VectorImage::GetUpperLeftCorner
VectorType GetUpperLeftCorner(void) const
Definition: otbVectorImage.hxx:136
otb::VectorImage::GetSignedSpacing
SpacingType GetSignedSpacing() const
Definition: otbVectorImage.hxx:38
otb::VectorImage::GetLowerRightCorner
VectorType GetLowerRightCorner(void) const
Definition: otbVectorImage.hxx:171
otbVectorImage.h
otb::VectorImage::SpacingType
Superclass::SpacingType SpacingType
Definition: otbVectorImage.h:117
otb::VectorImage::SetSignedSpacing
virtual void SetSignedSpacing(SpacingType spacing)
Definition: otbVectorImage.hxx:50
otb::VectorImage::CopyInformation
void CopyInformation(const itk::DataObject *) override
Copy metadata from a DataObject.
Definition: otbVectorImage.hxx:80
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::VectorImage::GetLowerLeftCorner
VectorType GetLowerLeftCorner(void) const
Definition: otbVectorImage.hxx:159
otb::VectorImage::VectorType
ImageMetadataInterfaceBase::VectorType VectorType
Definition: otbVectorImage.h:57
otb::ImageCommons::GetImageMetadata
const ImageMetadata & GetImageMetadata() const
otb::VectorImage< TOutputPixelType, 2 >::PointType
Superclass::PointType PointType
Definition: otbVectorImage.h:121
otb::VectorImage::GetUpperRightCorner
VectorType GetUpperRightCorner(void) const
Definition: otbVectorImage.hxx:147
otb::ImageCommons
Definition: otbImageCommons.h:31
otb::VectorImage::SetNumberOfComponentsPerPixel
virtual void SetNumberOfComponentsPerPixel(unsigned int n) override
Definition: otbVectorImage.hxx:104
otb::VectorImage::VectorImage
VectorImage()
Definition: otbVectorImage.hxx:32
otb::VectorImage::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbVectorImage.hxx:183
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