OTB  10.0.0
Orfeo Toolbox
otbShiftScaleImageAdaptor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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
Apply a shift scale operation to the value.
const ExternalType Get(const InternalType &input) const
itk::NumericTraits< TPixelType >::RealType InternalType
void Set(InternalType &output, const ExternalType &input)
Presents an image as being composed of the shift scale operation of its pixels.
itk::SmartPointer< Self > Pointer
AccessorType::ExternalType PixelType
TImage::PixelType GetScale() const
void operator=(const Self &)=delete
itk::SmartPointer< const Self > ConstPointer
ShiftScaleImageAdaptor(const Self &)=delete
virtual void SetShift(typename TImage::PixelType value)
itk::ImageAdaptor< TImage, Accessor::ShiftScalePixelAccessor< typename TImage::PixelType, TOutputPixelType > > Superclass
virtual void SetScale(typename TImage::PixelType value)
Accessor::ShiftScalePixelAccessor< typename TImage::PixelType, TOutputPixelType > AccessorType
TImage::PixelType GetShift() const
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.