OTB  9.0.0
Orfeo Toolbox
otbShiftScaleImageAdaptor.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 
22 #ifndef otbShiftScaleImageAdaptor_h
23 #define otbShiftScaleImageAdaptor_h
24 
25 #include "vnl/vnl_math.h"
26 #include "itkImageAdaptor.h"
27 
28 namespace otb
29 {
30 
31 namespace Accessor
32 {
49 template <class TPixelType, class TExternalType>
50 class ITK_EXPORT ShiftScalePixelAccessor
51 {
52 public:
55  typedef TExternalType ExternalType;
56 
59  typedef typename itk::NumericTraits<TPixelType>::RealType InternalType;
60 
62  {
63  return m_Shift;
64  }
65  void SetShift(InternalType value)
66  {
67  m_Shift = value;
68  }
69 
71  {
72  return m_Scale;
73  }
74  void SetScale(InternalType value)
75  {
76  m_Scale = value;
77  }
78 
79  inline void Set(InternalType& output, const ExternalType& input)
80  {
81  output = static_cast<InternalType>(m_Scale * (static_cast<InternalType>(input) + m_Shift));
82  }
83 
84  inline const ExternalType Get(const InternalType& input) const
85  {
86  return static_cast<ExternalType>(m_Scale * (static_cast<InternalType>(input) + m_Shift));
87  }
88 
89 private:
92 };
93 
94 } // end namespace Accessor
95 
106 template <class TImage, class TOutputPixelType>
107 class ITK_EXPORT ShiftScaleImageAdaptor : public itk::ImageAdaptor<TImage, Accessor::ShiftScalePixelAccessor<typename TImage::PixelType, TOutputPixelType>>
108 {
109 public:
112  typedef itk::ImageAdaptor<TImage, Accessor::ShiftScalePixelAccessor<typename TImage::PixelType, TOutputPixelType>> Superclass;
113  typedef itk::SmartPointer<Self> Pointer;
114  typedef itk::SmartPointer<const Self> ConstPointer;
115  typedef typename TImage::PixelType InternalType;
116  typedef typename Superclass::IndexType IndexType;
119 
121  itkNewMacro(Self);
122 
124  itkTypeMacro(ShiftScaleImageAdaptor, ImageAdaptor);
125 
126  typename TImage::PixelType GetShift() const
127  {
128  itkDebugMacro("returning "
129  << " m_Shift of " << this->GetPixelAccessor().GetShift());
130  return this->GetPixelAccessor().GetShift();
131  }
132 
133  virtual void SetShift(typename TImage::PixelType value)
134  {
135  itkDebugMacro("setting m_Shift to " << value);
136  if (this->GetPixelAccessor().GetShift() != value)
137  {
138  this->GetPixelAccessor().SetShift(value);
139  this->Modified();
140  }
141  }
142 
143  typename TImage::PixelType GetScale() const
144  {
145  itkDebugMacro("returning "
146  << " m_Scale of " << this->GetPixelAccessor().GetScale());
147  return this->GetPixelAccessor().GetScale();
148  }
149 
150  virtual void SetScale(typename TImage::PixelType value)
151  {
152  itkDebugMacro("setting m_Scale to " << value);
153  if (this->GetPixelAccessor().GetScale() != value)
154  {
155  this->GetPixelAccessor().SetScale(value);
156  this->Modified();
157  }
158  }
159 
160 protected:
162  {
163  }
165  {
166  }
167 
168 private:
169  ShiftScaleImageAdaptor(const Self&) = delete;
170  void operator=(const Self&) = delete;
171 };
172 
173 } // end namespace otb
174 
175 #endif
otb::Accessor::ShiftScalePixelAccessor
Apply a shift scale operation to the value.
Definition: otbShiftScaleImageAdaptor.h:50
otb::ShiftScaleImageAdaptor::Self
ShiftScaleImageAdaptor Self
Definition: otbShiftScaleImageAdaptor.h:111
otb::Accessor::ShiftScalePixelAccessor::Set
void Set(InternalType &output, const ExternalType &input)
Definition: otbShiftScaleImageAdaptor.h:79
otb::ShiftScaleImageAdaptor::IndexType
Superclass::IndexType IndexType
Definition: otbShiftScaleImageAdaptor.h:116
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ShiftScaleImageAdaptor::GetShift
TImage::PixelType GetShift() const
Definition: otbShiftScaleImageAdaptor.h:126
otb::Accessor::ShiftScalePixelAccessor::m_Shift
InternalType m_Shift
Definition: otbShiftScaleImageAdaptor.h:90
otb::Accessor::ShiftScalePixelAccessor::GetShift
InternalType GetShift() const
Definition: otbShiftScaleImageAdaptor.h:61
otb::ShiftScaleImageAdaptor::SetShift
virtual void SetShift(typename TImage::PixelType value)
Definition: otbShiftScaleImageAdaptor.h:133
otb::ShiftScaleImageAdaptor::ShiftScaleImageAdaptor
ShiftScaleImageAdaptor()
Definition: otbShiftScaleImageAdaptor.h:161
otb::ShiftScaleImageAdaptor::Superclass
itk::ImageAdaptor< TImage, Accessor::ShiftScalePixelAccessor< typename TImage::PixelType, TOutputPixelType > > Superclass
Definition: otbShiftScaleImageAdaptor.h:112
otb::ShiftScaleImageAdaptor::InternalType
TImage::PixelType InternalType
Definition: otbShiftScaleImageAdaptor.h:115
otb::Accessor::ShiftScalePixelAccessor::InternalType
itk::NumericTraits< TPixelType >::RealType InternalType
Definition: otbShiftScaleImageAdaptor.h:59
otb::Accessor::ShiftScalePixelAccessor::SetShift
void SetShift(InternalType value)
Definition: otbShiftScaleImageAdaptor.h:65
otb::ShiftScaleImageAdaptor::AccessorType
Accessor::ShiftScalePixelAccessor< typename TImage::PixelType, TOutputPixelType > AccessorType
Definition: otbShiftScaleImageAdaptor.h:117
otb::Accessor::ShiftScalePixelAccessor::m_Scale
InternalType m_Scale
Definition: otbShiftScaleImageAdaptor.h:91
otb::ShiftScaleImageAdaptor::~ShiftScaleImageAdaptor
~ShiftScaleImageAdaptor() override
Definition: otbShiftScaleImageAdaptor.h:164
otb::Accessor::ShiftScalePixelAccessor::SetScale
void SetScale(InternalType value)
Definition: otbShiftScaleImageAdaptor.h:74
otb::ShiftScaleImageAdaptor::GetScale
TImage::PixelType GetScale() const
Definition: otbShiftScaleImageAdaptor.h:143
otb::Accessor::ShiftScalePixelAccessor::Get
const ExternalType Get(const InternalType &input) const
Definition: otbShiftScaleImageAdaptor.h:84
otb::ShiftScaleImageAdaptor::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbShiftScaleImageAdaptor.h:114
otb::ShiftScaleImageAdaptor::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbShiftScaleImageAdaptor.h:113
otb::ShiftScaleImageAdaptor::SetScale
virtual void SetScale(typename TImage::PixelType value)
Definition: otbShiftScaleImageAdaptor.h:150
otb::ShiftScaleImageAdaptor
Presents an image as being composed of the shift scale operation of its pixels.
Definition: otbShiftScaleImageAdaptor.h:107
otb::Accessor::ShiftScalePixelAccessor::ExternalType
TExternalType ExternalType
Definition: otbShiftScaleImageAdaptor.h:55
otb::ShiftScaleImageAdaptor::PixelType
AccessorType::ExternalType PixelType
Definition: otbShiftScaleImageAdaptor.h:118
otb::Accessor::ShiftScalePixelAccessor::GetScale
InternalType GetScale() const
Definition: otbShiftScaleImageAdaptor.h:70