Orfeo Toolbox  4.0
otbVectorImageToMatrixImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12  Some parts of this code are derived from ITK. See ITKCopyright.txt
13  for details.
14 
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANT2ABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notices for more information.
19 
20 =========================================================================*/
21 #ifndef __otbVectorImageToMatrixFilter_txx
22 #define __otbVectorImageToMatrixFilter_txx
24 
25 #include "itkImageRegionIterator.h"
27 #include "itkNumericTraits.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>
49 ::MakeOutput(unsigned int output)
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

Generated at Sat Mar 8 2014 16:25:14 for Orfeo Toolbox with doxygen 1.8.3.1