OTB  10.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-2024 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 
29 namespace otb
30 {
31 
32 template <class TInputImage>
34 {
35  // first output is a copy of the image, DataObject created by
36  // superclass
37  //
38  // allocate the data objects for the outputs which are
39  // just decorators around vector/matric types
40  this->DynamicMultiThreadingOn();
41  this->itk::ProcessObject::SetNthOutput(1, this->MakeOutput(1).GetPointer());
42 }
43 
44 template <class TInputImage>
46 {
47  switch (output)
48  {
49  case 0:
50  return static_cast<itk::DataObject*>(TInputImage::New().GetPointer());
51  break;
52  case 1:
53  return static_cast<itk::DataObject*>(MatrixObjectType::New().GetPointer());
54  break;
55  default:
56  // might as well make an image
57  return static_cast<itk::DataObject*>(TInputImage::New().GetPointer());
58  break;
59  }
60 }
61 
62 template <class TInputImage>
64 {
65  return static_cast<MatrixObjectType*>(this->itk::ProcessObject::GetOutput(1));
66 }
67 
68 template <class TInputImage>
70 {
71  return static_cast<const MatrixObjectType*>(this->itk::ProcessObject::GetOutput(1));
72 }
73 
74 template <class TInputImage>
76 {
77  Superclass::GenerateOutputInformation();
78  if (this->GetInput())
79  {
80  this->GetOutput()->CopyInformation(this->GetInput());
81  this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion());
82 
83  if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
84  {
85  this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
86  }
87  }
88 }
89 
90 template <class TInputImage>
92 {
93  // This is commented to prevent the streaming of the whole image for the first stream strip
94  // It shall not cause any problem because the output image of this filter is not intended to be used.
95  // InputImagePointer image = const_cast< TInputImage * >( this->GetInput() );
96  // this->GraftOutput( image );
97  // Nothing that needs to be allocated for the remaining outputs
98 }
99 
100 template <class TInputImage>
102 {
103  TInputImage* inputPtr = const_cast<TInputImage*>(this->GetInput());
104  inputPtr->UpdateOutputInformation();
105 
106  this->GetMatrixOutput()->Get().set_size(inputPtr->GetNumberOfComponentsPerPixel(), inputPtr->GetLargestPossibleRegion().GetNumberOfPixels());
107 }
108 
109 template <class TInputImage>
111 {
112 }
113 
114 template <class TInputImage>
116 {
117  // Grab the input
118  InputImagePointer inputPtr = const_cast<TInputImage*>(this->GetInput());
119  const unsigned int width = this->GetInput()->GetLargestPossibleRegion().GetSize()[0];
120  itk::ImageRegionConstIteratorWithIndex<TInputImage> it(inputPtr, outputRegionForThread);
121 
122  for (it.GoToBegin(); !it.IsAtEnd(); ++it)
123  {
124  const IndexType& idx = it.GetIndex();
125 
126  unsigned int col = idx[0] + idx[1] * width;
127  const PixelType& vectorValue = it.Get();
128  MatrixType& m = this->GetMatrixOutput()->Get();
129  for (unsigned int r = 0; r < vectorValue.Size(); ++r)
130  {
131  m(r, col) = vectorValue[r];
132  }
133  }
134 }
135 
136 template <class TImage>
137 void PersistentVectorImageToMatrixFilter<TImage>::PrintSelf(std::ostream& os, itk::Indent indent) const
138 {
139  Superclass::PrintSelf(os, indent);
140 }
141 
142 } // end namespace otb
143 #endif
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
itk::SimpleDataObjectDecorator< MatrixType > MatrixObjectType
void DynamicThreadedGenerateData(const RegionType &outputRegionForThread) override
DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.