Orfeo Toolbox  4.0
otbVectorImageToImageListFilter.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 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 #ifndef __otbVectorImageToImageListFilter_txx
19 #define __otbVectorImageToImageListFilter_txx
20 
24 #include <vector>
25 #include "otbMacro.h"
26 #include "itkProgressReporter.h"
27 
28 namespace otb
29 {
31 template <class TVectorImageType, class TImageList>
32 void
35 {
36  OutputImageListPointerType outputPtr = this->GetOutput();
37  InputVectorImagePointerType inputPtr = this->GetInput();
38 
39  if (inputPtr)
40  {
41  if (outputPtr->Size() != inputPtr->GetNumberOfComponentsPerPixel())
42  {
43  // if the number of components does not match, clear the list
44  outputPtr->Clear();
45  for (unsigned int i = 0; i < inputPtr->GetNumberOfComponentsPerPixel(); ++i)
46  {
47  typename OutputImageType::Pointer tmpImagePtr = OutputImageType::New();
48  this->AddOutput(tmpImagePtr);
49  outputPtr->PushBack(tmpImagePtr);
50  }
51  }
52  for (unsigned int i = 0; i < inputPtr->GetNumberOfComponentsPerPixel(); ++i)
53  {
54  typename OutputImageType::Pointer tmpImagePtr = outputPtr->GetNthElement(i);
55  tmpImagePtr->CopyInformation(inputPtr);
56  tmpImagePtr->SetLargestPossibleRegion(inputPtr->GetLargestPossibleRegion());
57  tmpImagePtr->SetRequestedRegion(inputPtr->GetLargestPossibleRegion());
58  }
59  }
60 }
62 template <class TVectorImageType, class TImageList>
63 void
66 {
67  OutputImageListPointerType outputPtr = this->GetOutput();
68  InputVectorImagePointerType inputPtr = this->GetInput();
69 
70  if (inputPtr)
71  {
72  if (outputPtr->Size() > 0)
73  {
74  inputPtr->SetRequestedRegion(outputPtr->GetNthElement(0)->GetRequestedRegion());
75  }
76  }
77 }
81 template <class TVectorImageType, class TImageList>
82 void
85 {
86  OutputImageListPointerType outputPtr = this->GetOutput();
87  InputVectorImagePointerType inputPtr = this->GetInput();
88 
90  typedef itk::ImageRegionIteratorWithIndex<OutputImageType> OutputIteratorType;
91 
92  std::vector<OutputIteratorType> outputIteratorList;
93 
94  typename OutputImageListType::ConstIterator outputListIt = outputPtr->Begin();
95  for (; outputListIt != outputPtr->End(); ++outputListIt)
96  {
97  outputListIt.Get()->SetBufferedRegion(outputListIt.Get()->GetRequestedRegion());
98  outputListIt.Get()->Allocate();
99  OutputIteratorType tmpIt = OutputIteratorType(outputListIt.Get(), outputListIt.Get()->GetRequestedRegion());
100  tmpIt.GoToBegin();
101  outputIteratorList.push_back(tmpIt);
102  }
103 
104  InputIteratorType inputIt(inputPtr, outputPtr->GetNthElement(0)->GetRequestedRegion());
105 
106  itk::ProgressReporter progress(this, 0, outputPtr->GetNthElement(0)->GetRequestedRegion().GetNumberOfPixels());
107 
108  inputIt.GoToBegin();
109  while (!inputIt.IsAtEnd())
110  {
111  unsigned int counter = 0;
112  for (typename std::vector<OutputIteratorType>::iterator it = outputIteratorList.begin();
113  it != outputIteratorList.end(); ++it)
114  {
115  if (!(*it).IsAtEnd())
116  {
117  (*it).Set(static_cast<typename OutputImageType::PixelType>(inputIt.Get()[counter]));
118  ++(*it);
119  ++counter;
120  }
121  else
122  {
123  itkGenericExceptionMacro("End of image for band " << counter << " at index " << (*it).GetIndex() << " !");
124  }
125  }
126  progress.CompletedPixel();
127  ++inputIt;
128  }
129 }
133 template <class TVectorImageType, class TImageList>
134 void
136 ::PrintSelf(std::ostream& os, itk::Indent indent) const
137 {
138  Superclass::PrintSelf(os, indent);
139 }
140 } // End namespace otb
141 #endif

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