Orfeo Toolbox  4.0
otbUnaryFunctorWithIndexWithOutputSizeImageFilter.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 __otbUnaryFunctorWithIndexWithOutputSizeImageFilter_txx
19 #define __otbUnaryFunctorWithIndexWithOutputSizeImageFilter_txx
20 
22 #include "itkImageRegionIterator.h"
23 #include "itkProgressReporter.h"
24 
25 namespace otb
26 {
30 template <class TInputImage, class TOutputImage, class TFunction>
33 {
34  this->SetNumberOfRequiredInputs(1);
35 }
36 template <class TInputImage, class TOutputImage, class TFunction>
37 void
40 {
41  // call the superclass' implementation of this method
42  Superclass::GenerateInputRequestedRegion();
43 
44  // get pointers to the input and output
45  typename Superclass::InputImagePointer inputPtr =
46  const_cast<TInputImage *>(this->GetInput());
47  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
48 
49  if (!inputPtr || !outputPtr)
50  {
51  return;
52  }
53  // get a copy of the input requested region (should equal the output
54  // requested region)
55  typename TInputImage::RegionType inputRequestedRegion;
56  inputRequestedRegion = inputPtr->GetRequestedRegion();
57 
58  // crop the input requested region at the input's largest possible region
59  if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
60  {
61  inputPtr->SetRequestedRegion(inputRequestedRegion);
62  return;
63  }
64  else
65  {
66  // Couldn't crop the region (requested region is outside the largest
67  // possible region). Throw an exception.
68 
69  // store what we tried to request (prior to trying to crop)
70  inputPtr->SetRequestedRegion(inputRequestedRegion);
71 
72  // build an exception
73  itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
74  std::ostringstream msg;
75  msg << this->GetNameOfClass()
76  << "::GenerateInputRequestedRegion()";
77  e.SetLocation(msg.str().c_str());
78  e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
79  e.SetDataObject(inputPtr);
80  throw e;
81  }
82 }
83 
87 template <class TInputImage, class TOutputImage, class TFunction>
88 void
90 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId)
91 {
92  InputImagePointer inputPtr = dynamic_cast<const TInputImage*>(ProcessObjectType::GetInput(0));
93  OutputImagePointer outputPtr = this->GetOutput(0);
94 
95  InputImageRegionType inputRegionForThread;
96  this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
97 
98  // Define the iterators
99  IteratorType inputIt = IteratorType(inputPtr, inputRegionForThread);
100  itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
101 
102  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
103 
104  inputIt.GoToBegin();
105  outputIt.GoToBegin();
106 
107  while (!inputIt.IsAtEnd())
108  {
109  outputIt.Set(m_Functor(inputIt.Get(), inputIt.GetIndex()));
110  ++inputIt;
111  ++outputIt;
112  progress.CompletedPixel(); // potential exception thrown here
113  }
114 
115 }
116 
117 } // end namespace otb
118 
119 #endif

Generated at Sat Mar 8 2014 16:24:02 for Orfeo Toolbox with doxygen 1.8.3.1