Orfeo Toolbox  4.0
otbStreamingShrinkImageFilter.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 __otbStreamingShrinkImageFilter_txx
19 #define __otbStreamingShrinkImageFilter_txx
20 
23 #include "otbMacro.h"
24 #include "itkProgressReporter.h"
25 
26 namespace otb
27 {
28 
29 template <class TImage>
31 {
32 }
33 
34 template <class TImage>
36 {
37 }
38 
39 template <class TImage>
40 void
42 {
43  typedef otb::StreamingShrinkImageRegionSplitter TileSplitterType;
44  TileSplitterType::Pointer splitter = TileSplitterType::New();
45  splitter->SetTileSizeAlignment(m_ShrinkFactor);
46  this->m_Splitter = splitter;
47 
48  unsigned long nbDivisions = this->EstimateOptimalNumberOfDivisions(input, region, 0);
49  this->m_ComputedNumberOfSplits = this->m_Splitter->GetNumberOfSplits(region, nbDivisions);
50  otbMsgDevMacro(<< "Number of split : " << this->m_ComputedNumberOfSplits)
51 
52  // Save the region to generate the splits later
53  this->m_Region = region;
54 }
55 
56 
58 template <class TInputImage, class TOutputImage>
61  : m_ShrinkFactor(10)
62 {
63  this->SetNumberOfRequiredInputs(1);
64  this->SetNumberOfRequiredOutputs(1);
65 }
66 
68 template <class TInputImage, class TOutputImage>
71 {
72 
73 }
74 
75 template<class TInputImage, class TOutputImage>
76 void
79 {
80  Superclass::GenerateOutputInformation();
81 
82  const InputImageType* input = this->GetInput();
83 
84  OutputImageType* output = this->GetOutput();
85 
86  if (input)
87  {
88  output->CopyInformation(input);
89  output->SetLargestPossibleRegion(input->GetLargestPossibleRegion());
90 
91  if (output->GetRequestedRegion().GetNumberOfPixels() == 0)
92  {
93  output->SetRequestedRegion(output->GetLargestPossibleRegion());
94  }
95  }
96 }
97 
98 template<class TInputImage, class TOutputImage>
99 void
102 {
103  // This is commented to prevent the streaming of the whole image for the first stream strip
104  // It shall not cause any problem because the output image of this filter is not intended to be used.
105  //InputImagePointer image = const_cast< TInputImage * >( this->GetInput() );
106  //this->GraftOutput( image );
107  // Nothing that needs to be allocated for the remaining outputs
108 }
109 
110 
111 template<class TInputImage, class TOutputImage>
112 void
115 {
116  // Get pointers to the input and output
117  InputImageType* inputPtr = const_cast<InputImageType*>(this->GetInput());
118  inputPtr->UpdateOutputInformation();
119 
120  m_ShrinkedOutput = OutputImageType::New();
121  m_ShrinkedOutput->CopyInformation(inputPtr);
122 
123  const typename InputImageType::SpacingType&
124  inputSpacing = inputPtr->GetSpacing();
125  const typename InputImageType::SizeType& inputSize
126  = inputPtr->GetLargestPossibleRegion().GetSize();
127 
128  typename OutputImageType::SpacingType shrinkedOutputSpacing;
129  typename OutputImageType::RegionType shrinkedOutputLargestPossibleRegion;
130  typename OutputImageType::SizeType shrinkedOutputSize;
131  typename OutputImageType::IndexType shrinkedOutputStartIndex;
132 
133  for (unsigned int i = 0; i < OutputImageType::ImageDimension; ++i)
134  {
135  shrinkedOutputSpacing[i] = inputSpacing[i] * static_cast<double>(m_ShrinkFactor);
136  shrinkedOutputSize[i] = inputSize[i] > m_ShrinkFactor ? inputSize[i] / m_ShrinkFactor : 1;
137 
138  // TODO : don't know what to do here.
139  // dividing the input index by the shrink factor does not make a lot of sense...
140  shrinkedOutputStartIndex[i] = 0;
141  }
142 
143  m_ShrinkedOutput->SetSpacing(shrinkedOutputSpacing);
144 
145  shrinkedOutputLargestPossibleRegion.SetSize(shrinkedOutputSize);
146  shrinkedOutputLargestPossibleRegion.SetIndex(shrinkedOutputStartIndex);
147 
148  m_ShrinkedOutput->SetRegions(shrinkedOutputLargestPossibleRegion);
149  m_ShrinkedOutput->Allocate();
150 }
151 
152 template<class TInputImage, class TOutputImage>
153 void
156 {
157 }
158 
159 template<class TInputImage, class TOutputImage>
160 void
163 {
164 }
165 
166 template<class TInputImage, class TOutputImage>
167 void
169 ::ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId)
170 {
171  //std::cout << "outputRegionForThread " << threadId << " " << outputRegionForThread << std::endl;
172  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
173  const InputImageType* inputPtr = this->GetInput();
174 
175  itk::ImageRegionConstIteratorWithIndex<InputImageType> inIt(inputPtr, outputRegionForThread);
176  for(inIt.GoToBegin(); !inIt.IsAtEnd(); ++inIt, progress.CompletedPixel())
177  {
178  const IndexType& inIndex = inIt.GetIndex();
179  if (inIndex[0] % m_ShrinkFactor == 0
180  && inIndex[1] % m_ShrinkFactor == 0 )
181  {
182  IndexType shrinkedIndex;
183  shrinkedIndex[0] = inIndex[0] / m_ShrinkFactor;
184  shrinkedIndex[1] = inIndex[1] / m_ShrinkFactor;
185  if (m_ShrinkedOutput->GetLargestPossibleRegion().IsInside(shrinkedIndex))
186  m_ShrinkedOutput->SetPixel(shrinkedIndex, inIt.Get());
187  }
188  }
189 }
190 
191 template<class TInputImage, class TOutputImage>
192 void
195 {
196 }
197 
198 template <class TImage, class TOutputImage>
199 void
201 ::PrintSelf(std::ostream& os, itk::Indent indent) const
202 {
203  Superclass::PrintSelf(os, indent);
204  os << indent << "Shrink factor: " << m_ShrinkFactor << std::endl;
205 }
206 
207 } // End namespace otb
208 #endif

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