OTB  9.0.0
Orfeo Toolbox
otbVectorImageToMatrixImageFilter.hxx
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  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbVectorImageToMatrixFilter_hxx
23 #define otbVectorImageToMatrixFilter_hxx
25 
26 #include "itkImageRegionIterator.h"
27 #include "itkImageRegionConstIteratorWithIndex.h"
28 #include "itkProgressReporter.h"
29 #include "otbMacro.h"
30 
31 namespace otb
32 {
33 
34 template <class TInputImage>
36 {
37  // first output is a copy of the image, DataObject created by
38  // superclass
39  //
40  // allocate the data objects for the outputs which are
41  // just decorators around vector/matric types
42  this->itk::ProcessObject::SetNthOutput(1, this->MakeOutput(1).GetPointer());
43 }
44 
45 template <class TInputImage>
47 {
48  switch (output)
49  {
50  case 0:
51  return static_cast<itk::DataObject*>(TInputImage::New().GetPointer());
52  break;
53  case 1:
54  return static_cast<itk::DataObject*>(MatrixObjectType::New().GetPointer());
55  break;
56  default:
57  // might as well make an image
58  return static_cast<itk::DataObject*>(TInputImage::New().GetPointer());
59  break;
60  }
61 }
62 
63 template <class TInputImage>
65 {
66  return static_cast<MatrixObjectType*>(this->itk::ProcessObject::GetOutput(1));
67 }
68 
69 template <class TInputImage>
71 {
72  return static_cast<const MatrixObjectType*>(this->itk::ProcessObject::GetOutput(1));
73 }
74 
75 template <class TInputImage>
77 {
78  Superclass::GenerateOutputInformation();
79  if (this->GetInput())
80  {
81  this->GetOutput()->CopyInformation(this->GetInput());
82  this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion());
83 
84  if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
85  {
86  this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
87  }
88  }
89 }
90 
91 template <class TInputImage>
93 {
94  // This is commented to prevent the streaming of the whole image for the first stream strip
95  // It shall not cause any problem because the output image of this filter is not intended to be used.
96  // InputImagePointer image = const_cast< TInputImage * >( this->GetInput() );
97  // this->GraftOutput( image );
98  // Nothing that needs to be allocated for the remaining outputs
99 }
100 
101 template <class TInputImage>
103 {
104  TInputImage* inputPtr = const_cast<TInputImage*>(this->GetInput());
105  inputPtr->UpdateOutputInformation();
106 
107  this->GetMatrixOutput()->Get().set_size(inputPtr->GetNumberOfComponentsPerPixel(), inputPtr->GetLargestPossibleRegion().GetNumberOfPixels());
108 }
109 
110 template <class TInputImage>
112 {
113 }
114 
115 template <class TInputImage>
116 void PersistentVectorImageToMatrixFilter<TInputImage>::ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId)
117 {
118  // Support progress methods/callbacks
119  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
120 
121  // Grab the input
122  InputImagePointer inputPtr = const_cast<TInputImage*>(this->GetInput());
123  const unsigned int width = this->GetInput()->GetLargestPossibleRegion().GetSize()[0];
124  itk::ImageRegionConstIteratorWithIndex<TInputImage> it(inputPtr, outputRegionForThread);
125 
126  for (it.GoToBegin(); !it.IsAtEnd(); ++it, progress.CompletedPixel())
127  {
128  const IndexType& idx = it.GetIndex();
129 
130  unsigned int col = idx[0] + idx[1] * width;
131  const PixelType& vectorValue = it.Get();
132  MatrixType& m = this->GetMatrixOutput()->Get();
133  for (unsigned int r = 0; r < vectorValue.Size(); ++r)
134  {
135  m(r, col) = vectorValue[r];
136  }
137  }
138 }
139 
140 template <class TImage>
141 void PersistentVectorImageToMatrixFilter<TImage>::PrintSelf(std::ostream& os, itk::Indent indent) const
142 {
143  Superclass::PrintSelf(os, indent);
144 }
145 
146 } // end namespace otb
147 #endif
otb::PersistentVectorImageToMatrixFilter::InputImagePointer
TInputImage::Pointer InputImagePointer
Definition: otbVectorImageToMatrixImageFilter.h:71
otb::PersistentVectorImageToMatrixFilter::RegionType
TInputImage::RegionType RegionType
Definition: otbVectorImageToMatrixImageFilter.h:72
otb::PersistentVectorImageToMatrixFilter::MakeOutput
DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override
Definition: otbVectorImageToMatrixImageFilter.hxx:46
otb::PersistentVectorImageToMatrixFilter::MatrixType
vnl_matrix< RealType > MatrixType
Definition: otbVectorImageToMatrixImageFilter.h:93
otb::PersistentVectorImageToMatrixFilter::PixelType
TInputImage::PixelType PixelType
Definition: otbVectorImageToMatrixImageFilter.h:75
otb::PersistentVectorImageToMatrixFilter::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbVectorImageToMatrixImageFilter.h:90
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otbMacro.h
otb::PersistentVectorImageToMatrixFilter::ThreadedGenerateData
void ThreadedGenerateData(const RegionType &outputRegionForThread, itk::ThreadIdType threadId) override
Definition: otbVectorImageToMatrixImageFilter.hxx:116
otb::PersistentVectorImageToMatrixFilter::PersistentVectorImageToMatrixFilter
PersistentVectorImageToMatrixFilter()
Definition: otbVectorImageToMatrixImageFilter.hxx:35
otb::PersistentVectorImageToMatrixFilter::IndexType
TInputImage::IndexType IndexType
Definition: otbVectorImageToMatrixImageFilter.h:74
otb::PersistentVectorImageToMatrixFilter::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbVectorImageToMatrixImageFilter.hxx:76
otb::PersistentVectorImageToMatrixFilter::MatrixObjectType
itk::SimpleDataObjectDecorator< MatrixType > MatrixObjectType
Definition: otbVectorImageToMatrixImageFilter.h:94
otbVectorImageToMatrixImageFilter.h
otb::PersistentVectorImageToMatrixFilter::GetMatrixOutput
MatrixObjectType * GetMatrixOutput()
Definition: otbVectorImageToMatrixImageFilter.hxx:64
otb::PersistentVectorImageToMatrixFilter::AllocateOutputs
void AllocateOutputs() override
Definition: otbVectorImageToMatrixImageFilter.hxx:92
otb::PersistentVectorImageToMatrixFilter::Reset
void Reset(void) override
Definition: otbVectorImageToMatrixImageFilter.hxx:102
otb::PersistentVectorImageToMatrixFilter::Synthetize
void Synthetize(void) override
Definition: otbVectorImageToMatrixImageFilter.hxx:111
otb::PersistentVectorImageToMatrixFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbVectorImageToMatrixImageFilter.hxx:141