OTB  6.7.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-2019 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"
28 #include "itkProgressReporter.h"
29 #include "otbMacro.h"
30 
31 namespace otb
32 {
33 
34 template<class TInputImage>
37 {
38  // first output is a copy of the image, DataObject created by
39  // superclass
40  //
41  // allocate the data objects for the outputs which are
42  // just decorators around vector/matric types
43  this->itk::ProcessObject::SetNthOutput(1, this->MakeOutput(1).GetPointer());
44 }
45 
46 template<class TInputImage>
50 {
51  switch (output)
52  {
53  case 0:
54  return static_cast<itk::DataObject*>(TInputImage::New().GetPointer());
55  break;
56  case 1:
57  return static_cast<itk::DataObject*>(MatrixObjectType::New().GetPointer());
58  break;
59  default:
60  // might as well make an image
61  return static_cast<itk::DataObject*>(TInputImage::New().GetPointer());
62  break;
63  }
64 }
65 
66 template<class TInputImage>
70 {
71  return static_cast<MatrixObjectType*>(this->itk::ProcessObject::GetOutput(1));
72 }
73 
74 template<class TInputImage>
78 {
79  return static_cast<const MatrixObjectType*>(this->itk::ProcessObject::GetOutput(1));
80 }
81 
82 template<class TInputImage>
83 void
86 {
87  Superclass::GenerateOutputInformation();
88  if (this->GetInput())
89  {
90  this->GetOutput()->CopyInformation(this->GetInput());
91  this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion());
92 
93  if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
94  {
95  this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
96  }
97  }
98 }
99 
100 template<class TInputImage>
101 void
104 {
105  // This is commented to prevent the streaming of the whole image for the first stream strip
106  // It shall not cause any problem because the output image of this filter is not intended to be used.
107  //InputImagePointer image = const_cast< TInputImage * >( this->GetInput() );
108  //this->GraftOutput( image );
109  // Nothing that needs to be allocated for the remaining outputs
110 }
111 
112 template<class TInputImage>
113 void
116 {
117  TInputImage * inputPtr = const_cast<TInputImage *>(this->GetInput());
118  inputPtr->UpdateOutputInformation();
119 
120  this->GetMatrixOutput()->Get().set_size(
121  inputPtr->GetNumberOfComponentsPerPixel(),
122  inputPtr->GetLargestPossibleRegion().GetNumberOfPixels());
123 }
124 
125 template<class TInputImage>
126 void
129 {
130 }
131 
132 template<class TInputImage>
133 void
135 ::ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId)
136 {
137  // Support progress methods/callbacks
138  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
139 
140  // Grab the input
141  InputImagePointer inputPtr = const_cast<TInputImage *>(this->GetInput());
142  const unsigned int width = this->GetInput()->GetLargestPossibleRegion().GetSize()[0];
143  itk::ImageRegionConstIteratorWithIndex<TInputImage> it(inputPtr, outputRegionForThread);
144 
145  for (it.GoToBegin(); !it.IsAtEnd(); ++it, progress.CompletedPixel())
146  {
147  const IndexType& idx = it.GetIndex();
148 
149  unsigned int col = idx[0] + idx[1] * width;
150  const PixelType& vectorValue = it.Get();
151  MatrixType& m = this->GetMatrixOutput()->Get();
152  for (unsigned int r = 0; r < vectorValue.Size(); ++r)
153  {
154  m(r, col) = vectorValue[r];
155  }
156  }
157 }
158 
159 template <class TImage>
160 void
162 ::PrintSelf(std::ostream& os, itk::Indent indent) const
163 {
164  Superclass::PrintSelf(os, indent);
165 }
166 
167 } // end namespace otb
168 #endif
Superclass::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
PixelType Get(void) const
DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override
const IndexType & GetIndex() const
unsigned int ThreadIdType
void ThreadedGenerateData(const RegionType &outputRegionForThread, itk::ThreadIdType threadId) override
virtual void SetNthOutput(DataObjectPointerArraySizeType num, DataObject *output)
DataObject * GetOutput(const DataObjectIdentifierType &key)