OTB  9.0.0
Orfeo Toolbox
otbStreamingMosaicFilterBase.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
4  * Copyright (C) 2016-2019 IRSTEA
5  *
6  * This file is part of Orfeo Toolbox
7  *
8  * https://www.orfeo-toolbox.org/
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 #ifndef __StreamingMosaicFilterBase_H
23 #define __StreamingMosaicFilterBase_H
24 
25 #include "itkImageToImageFilter.h"
26 #include "itkNearestNeighborInterpolateImageFunction.h"
27 #include "otbStreamingTraits.h"
28 
29 // No data
30 #include "otbNoDataHelper.h"
31 
32 namespace otb
33 {
53 template <class TInputImage, class TOutputImage = TInputImage, class TInternalValueType = double>
54 class ITK_EXPORT StreamingMosaicFilterBase : public itk::ImageToImageFilter<TInputImage, TOutputImage>
55 {
56 public:
59  typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
60  typedef itk::SmartPointer<Self> Pointer;
61  typedef itk::SmartPointer<const Self> ConstPointer;
62 
64  itkTypeMacro(StreamingMosaicFilterBase, ImageToImageFilter);
65 
67  typedef TInputImage InputImageType;
68  typedef typename InputImageType::ConstPointer InputImagePointer;
69  typedef typename InputImageType::RegionType InputImageRegionType;
70  typedef typename InputImageType::PixelType InputImagePixelType;
71  typedef typename InputImageType::PointType InputImagePointType;
72  typedef typename InputImageType::IndexType InputImageIndexType;
73  typedef typename InputImageType::SizeType InputImageSizeType;
74  typedef typename InputImageType::SpacingType InputImageSpacingType;
75  typedef typename InputImageType::InternalPixelType InputImageInternalPixelType;
76 
78  typedef TOutputImage OutputImageType;
79  typedef typename OutputImageType::Pointer OutputImagePointer;
80  typedef typename OutputImageType::RegionType OutputImageRegionType;
81  typedef typename OutputImageType::IndexType OutputImageIndexType;
82  typedef typename OutputImageType::PointType OutputImagePointType;
83  typedef typename OutputImageType::SizeType OutputImageSizeType;
84  typedef typename OutputImageType::SpacingType OutputImageSpacingType;
85  typedef typename OutputImageType::PixelType OutputImagePixelType;
86  typedef typename OutputImageType::InternalPixelType OutputImageInternalPixelType;
87 
89  typedef TInternalValueType InternalValueType;
90  typedef typename itk::ContinuousIndex<double, 2> ContinuousIndexType;
91  typedef itk::InterpolateImageFunction<InputImageType, InternalValueType> InterpolatorType;
92  typedef typename InterpolatorType::Pointer InterpolatorPointerType;
93  typedef itk::NearestNeighborInterpolateImageFunction<InputImageType, InternalValueType> DefaultInterpolatorType;
96  typedef itk::ImageRegionIterator<OutputImageType> IteratorType;
97  typedef itk::ImageRegionConstIterator<OutputImageType> ConstIteratorType;
99 
102  typedef std::vector<unsigned int> IndicesListType;
103 
105  typedef vnl_matrix<InternalValueType> MatrixType;
106 
108  itkSetObjectMacro(Interpolator, InterpolatorType);
109  itkGetObjectMacro(Interpolator, InterpolatorType);
111 
113  itkSetMacro(NoDataOutputPixel, OutputImagePixelType);
114  itkGetMacro(NoDataOutputPixel, OutputImagePixelType);
116 
118  itkSetMacro(NoDataInputPixel, InputImagePixelType);
119  itkGetMacro(NoDataInputPixel, InputImagePixelType);
121 
123  itkSetMacro(OutputSpacing, OutputImageSpacingType);
124  itkGetMacro(OutputSpacing, OutputImageSpacingType);
126 
128  itkSetMacro(OutputOrigin, OutputImagePointType);
129  itkGetMacro(OutputOrigin, OutputImagePointType);
131 
133  itkSetMacro(OutputSize, OutputImageSizeType);
134  itkGetMacro(OutputSize, OutputImageSizeType);
136 
138  itkSetMacro(AutomaticOutputParametersComputation, bool);
139  itkGetMacro(AutomaticOutputParametersComputation, bool);
141 
143  itkSetMacro(ShiftScaleInputImages, bool);
144  itkGetMacro(ShiftScaleInputImages, bool);
145  itkBooleanMacro(ShiftScaleInputImages);
147 
149  virtual void SetShiftMatrix(MatrixType shiftMatrix)
150  {
151  m_ShiftMatrix = MatrixType(shiftMatrix);
152  }
153 
154  virtual void SetScaleMatrix(MatrixType scaleMatrix)
155  {
156  m_ScaleMatrix = MatrixType(scaleMatrix);
157  }
158 
160  {
161  return m_ShiftMatrix;
162  }
163 
165  {
166  return m_ScaleMatrix;
167  }
168 
169 protected:
172  {
173  }
174 
178  void GenerateOutputInformation(void) override;
179 
180  void GenerateInputRequestedRegion(void) override;
181 
182  void AfterThreadedGenerateData() override;
183 
184  void BeforeThreadedGenerateData() override;
185 
187  virtual void ImageToExtent(InputImageType* image, InputImagePointType& extentInf, InputImagePointType& extentSup);
188 
190  virtual bool OutputRegionToInputRegion(const OutputImageRegionType& mosaicRegion, InputImageRegionType& inputRegion, InputImageType*& inputImage);
191 
193  virtual void NormalizePixelValue(InternalValueType& pixelValue);
194 
196  virtual bool IsPixelNotEmpty(InputImagePixelType& inputPixel);
197 
199  virtual void AddUsedInputImageIndex(unsigned int index)
200  {
201  usedInputIndices.push_back(index);
202  }
203 
204  virtual unsigned int GetUsedInputImageIndice(unsigned int i)
205  {
206  return usedInputIndices[i];
207  }
208 
209  virtual unsigned int GetNumberOfUsedInputImages()
210  {
211  return usedInputIndices.size();
212  }
213 
215  virtual void ComputeOutputParameters();
216 
218  virtual unsigned int GetNumberOfInputImages()
219  {
220  return this->GetNumberOfInputs();
221  }
222 
224  virtual unsigned int GetNumberOfBands()
225  {
226  return nbOfBands;
227  }
228 
230  virtual void ComputeRequestedRegionOfInputImage(unsigned int inputImageIndex);
231 
233  virtual void ShiftScaleValue(InternalValueType& value, const unsigned int& imageIndex, unsigned int& band)
234  {
235  value *= m_ScaleMatrix[imageIndex][band];
236  value += m_ShiftMatrix[imageIndex][band];
237  }
238 
240  virtual void CheckShiftScaleMatrices();
241 
243  virtual void PrepareImageAccessors(typename std::vector<InputImageType*>& image, typename std::vector<InterpolatorPointerType>& interpolator);
244 
245 private:
246  StreamingMosaicFilterBase(const Self&); // purposely not implemented
247  void operator=(const Self&); // purposely not implemented
248 
252 
256 
257  bool m_AutomaticOutputParametersComputation; // Output parameters auto on/off
258  bool m_ShiftScaleInputImages; // Shift-scale mode on/off
259 
260  MatrixType m_ShiftMatrix; // matrix of shifts
261  MatrixType m_ScaleMatrix; // matrix of scales
262 
264  unsigned int nbOfBands; // number of bands
265  unsigned int interpolatorRadius; // interpolator padding radius
266  IndicesListType usedInputIndices; // requested input image indices
269 
270 }; // end of class
271 
272 } // end namespace itk
273 
274 #ifndef OTB_MANUAL_INSTANTIATION
276 #endif
277 
278 #endif
otb::StreamingMosaicFilterBase::GetShiftMatrix
virtual MatrixType GetShiftMatrix()
Definition: otbStreamingMosaicFilterBase.h:159
otb::StreamingMosaicFilterBase::ContinuousIndexType
itk::ContinuousIndex< double, 2 > ContinuousIndexType
Definition: otbStreamingMosaicFilterBase.h:90
otb::StreamingMosaicFilterBase::InputImageRegionType
InputImageType::RegionType InputImageRegionType
Definition: otbStreamingMosaicFilterBase.h:69
otb::StreamingMosaicFilterBase::ShiftScaleValue
virtual void ShiftScaleValue(InternalValueType &value, const unsigned int &imageIndex, unsigned int &band)
Definition: otbStreamingMosaicFilterBase.h:233
otb::StreamingMosaicFilterBase::m_NoDataInputPixel
InputImagePixelType m_NoDataInputPixel
Definition: otbStreamingMosaicFilterBase.h:251
otb::StreamingMosaicFilterBase::InternalPixelType
InternalImageType::PixelType InternalPixelType
Definition: otbStreamingMosaicFilterBase.h:95
otb::StreamingMosaicFilterBase::GetNumberOfBands
virtual unsigned int GetNumberOfBands()
Definition: otbStreamingMosaicFilterBase.h:224
otb::StreamingMosaicFilterBase::MatrixType
vnl_matrix< InternalValueType > MatrixType
Definition: otbStreamingMosaicFilterBase.h:105
otb::StreamingMosaicFilterBase::m_Interpolator
InterpolatorPointerType m_Interpolator
Definition: otbStreamingMosaicFilterBase.h:249
otb::StreamingMosaicFilterBase::GetNumberOfInputImages
virtual unsigned int GetNumberOfInputImages()
Definition: otbStreamingMosaicFilterBase.h:218
otb::StreamingMosaicFilterBase::m_NoDataOutputPixel
OutputImagePixelType m_NoDataOutputPixel
Definition: otbStreamingMosaicFilterBase.h:250
otb::StreamingMosaicFilterBase::AddUsedInputImageIndex
virtual void AddUsedInputImageIndex(unsigned int index)
Definition: otbStreamingMosaicFilterBase.h:199
otb::StreamingMosaicFilterBase::usedInputIndices
IndicesListType usedInputIndices
Definition: otbStreamingMosaicFilterBase.h:266
otb::StreamingMosaicFilterBase::m_ScaleMatrix
MatrixType m_ScaleMatrix
Definition: otbStreamingMosaicFilterBase.h:261
otb::StreamingMosaicFilterBase::InputImageSpacingType
InputImageType::SpacingType InputImageSpacingType
Definition: otbStreamingMosaicFilterBase.h:74
otb::StreamingMosaicFilterBase::m_OutputSpacing
OutputImageSpacingType m_OutputSpacing
Definition: otbStreamingMosaicFilterBase.h:253
otb::StreamingMosaicFilterBase::GetScaleMatrix
virtual MatrixType GetScaleMatrix()
Definition: otbStreamingMosaicFilterBase.h:164
otb::StreamingMosaicFilterBase::OutputImageSpacingType
OutputImageType::SpacingType OutputImageSpacingType
Definition: otbStreamingMosaicFilterBase.h:84
otb::StreamingMosaicFilterBase::InputImagePixelType
InputImageType::PixelType InputImagePixelType
Definition: otbStreamingMosaicFilterBase.h:70
otb::StreamingMosaicFilterBase::OutputImagePointer
OutputImageType::Pointer OutputImagePointer
Definition: otbStreamingMosaicFilterBase.h:79
otb::StreamingMosaicFilterBase::m_OutputOrigin
OutputImagePointType m_OutputOrigin
Definition: otbStreamingMosaicFilterBase.h:254
otb::StreamingMosaicFilterBase::OutputImagePointType
OutputImageType::PointType OutputImagePointType
Definition: otbStreamingMosaicFilterBase.h:82
otb::StreamingMosaicFilterBase::SetShiftMatrix
virtual void SetShiftMatrix(MatrixType shiftMatrix)
Definition: otbStreamingMosaicFilterBase.h:149
otb::StreamingMosaicFilterBase::InputImagePointType
InputImageType::PointType InputImagePointType
Definition: otbStreamingMosaicFilterBase.h:71
otb::StreamingMosaicFilterBase::InputImageSizeType
InputImageType::SizeType InputImageSizeType
Definition: otbStreamingMosaicFilterBase.h:73
otb::StreamingMosaicFilterBase::m_ShiftScaleInputImages
bool m_ShiftScaleInputImages
Definition: otbStreamingMosaicFilterBase.h:258
otb::StreamingMosaicFilterBase::InputImageIndexType
InputImageType::IndexType InputImageIndexType
Definition: otbStreamingMosaicFilterBase.h:72
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::StreamingMosaicFilterBase::m_AutomaticOutputParametersComputation
bool m_AutomaticOutputParametersComputation
Definition: otbStreamingMosaicFilterBase.h:257
otb::StreamingMosaicFilterBase::maxOutputPixelValue
InternalValueType maxOutputPixelValue
Definition: otbStreamingMosaicFilterBase.h:268
otb::StreamingMosaicFilterBase::InputImageType
TInputImage InputImageType
Definition: otbStreamingMosaicFilterBase.h:64
otb::StreamingMosaicFilterBase::interpolatorRadius
unsigned int interpolatorRadius
Definition: otbStreamingMosaicFilterBase.h:265
otb::StreamingMosaicFilterBase::InputImageInternalPixelType
InputImageType::InternalPixelType InputImageInternalPixelType
Definition: otbStreamingMosaicFilterBase.h:75
otb::StreamingMosaicFilterBase::DefaultInterpolatorType
itk::NearestNeighborInterpolateImageFunction< InputImageType, InternalValueType > DefaultInterpolatorType
Definition: otbStreamingMosaicFilterBase.h:93
otb::StreamingMosaicFilterBase::m_OutputSize
OutputImageSizeType m_OutputSize
Definition: otbStreamingMosaicFilterBase.h:255
otb::StreamingMosaicFilterBase::GetUsedInputImageIndice
virtual unsigned int GetUsedInputImageIndice(unsigned int i)
Definition: otbStreamingMosaicFilterBase.h:204
otb::StreamingMosaicFilterBase::OutputImageInternalPixelType
OutputImageType::InternalPixelType OutputImageInternalPixelType
Definition: otbStreamingMosaicFilterBase.h:86
otb::StreamingMosaicFilterBase::nbOfBands
unsigned int nbOfBands
Definition: otbStreamingMosaicFilterBase.h:264
otb::StreamingMosaicFilterBase::~StreamingMosaicFilterBase
~StreamingMosaicFilterBase()
Definition: otbStreamingMosaicFilterBase.h:171
otb::StreamingTraits
This class provides internal information for streamable filters.
Definition: otbStreamingTraits.h:55
otbNoDataHelper.h
otb::StreamingMosaicFilterBase::OutputImageType
TOutputImage OutputImageType
Definition: otbStreamingMosaicFilterBase.h:78
otb::StreamingMosaicFilterBase::OutputImageIndexType
OutputImageType::IndexType OutputImageIndexType
Definition: otbStreamingMosaicFilterBase.h:81
otb::StreamingMosaicFilterBase::Superclass
itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass
Definition: otbStreamingMosaicFilterBase.h:59
otb::StreamingMosaicFilterBase::ConstIteratorType
itk::ImageRegionConstIterator< OutputImageType > ConstIteratorType
Definition: otbStreamingMosaicFilterBase.h:97
otb::StreamingMosaicFilterBase::OutputImageRegionType
OutputImageType::RegionType OutputImageRegionType
Definition: otbStreamingMosaicFilterBase.h:80
otb::StreamingMosaicFilterBase::InterpolatorType
itk::InterpolateImageFunction< InputImageType, InternalValueType > InterpolatorType
Definition: otbStreamingMosaicFilterBase.h:91
otb::StreamingMosaicFilterBase::InternalImageType
otb::VectorImage< InternalValueType, 2 > InternalImageType
Definition: otbStreamingMosaicFilterBase.h:94
otb::StreamingMosaicFilterBase::IndicesListType
std::vector< unsigned int > IndicesListType
Definition: otbStreamingMosaicFilterBase.h:102
otb::StreamingMosaicFilterBase::OutputImageSizeType
OutputImageType::SizeType OutputImageSizeType
Definition: otbStreamingMosaicFilterBase.h:83
otbStreamingTraits.h
otb::StreamingMosaicFilterBase::GetNumberOfUsedInputImages
virtual unsigned int GetNumberOfUsedInputImages()
Definition: otbStreamingMosaicFilterBase.h:209
otb::StreamingMosaicFilterBase
Base class for mosaic filters. Computes the total extent of multiple inputs, and provide routines to ...
Definition: otbStreamingMosaicFilterBase.h:54
otb::StreamingMosaicFilterBase::Self
StreamingMosaicFilterBase Self
Definition: otbStreamingMosaicFilterBase.h:58
otb::StreamingMosaicFilterBase::minOutputPixelValue
InternalValueType minOutputPixelValue
Definition: otbStreamingMosaicFilterBase.h:267
otb::StreamingMosaicFilterBase::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbStreamingMosaicFilterBase.h:61
otb::StreamingMosaicFilterBase::IteratorType
itk::ImageRegionIterator< OutputImageType > IteratorType
Definition: otbStreamingMosaicFilterBase.h:96
otb::VectorImage::PixelType
Superclass::PixelType PixelType
Definition: otbVectorImage.h:63
otb::StreamingMosaicFilterBase::SetScaleMatrix
virtual void SetScaleMatrix(MatrixType scaleMatrix)
Definition: otbStreamingMosaicFilterBase.h:154
otb::StreamingMosaicFilterBase::InternalValueType
TInternalValueType InternalValueType
Definition: otbStreamingMosaicFilterBase.h:89
otbStreamingMosaicFilterBase.hxx
otb::StreamingMosaicFilterBase::InterpolatorPointerType
InterpolatorType::Pointer InterpolatorPointerType
Definition: otbStreamingMosaicFilterBase.h:92
otb::StreamingMosaicFilterBase::InputImagePointer
InputImageType::ConstPointer InputImagePointer
Definition: otbStreamingMosaicFilterBase.h:68
otb::StreamingMosaicFilterBase::StreamingTraitsType
otb::StreamingTraits< OutputImageType > StreamingTraitsType
Definition: otbStreamingMosaicFilterBase.h:98
otb::StreamingMosaicFilterBase::m_ShiftMatrix
MatrixType m_ShiftMatrix
Definition: otbStreamingMosaicFilterBase.h:260
otb::VectorImage
Creation of an "otb" vector image which contains metadata.
Definition: otbVectorImage.h:45
otb::StreamingMosaicFilterBase::OutputImagePixelType
OutputImageType::PixelType OutputImagePixelType
Definition: otbStreamingMosaicFilterBase.h:85
otb::StreamingMosaicFilterBase::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbStreamingMosaicFilterBase.h:60