Orfeo Toolbox  4.0
otbBinaryImageToDensityImageFilter.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 __otbBinaryImageToDensityImageFilter_txx
19 #define __otbBinaryImageToDensityImageFilter_txx
20 
22 #include "itkImageRegionIterator.h"
23 #include "itkProgressReporter.h"
26 
27 #include "otbMacro.h"
28 
29 namespace otb
30 {
32 template <class TInputImage, class TOutputImage, class TCountFunction>
35 {
36  m_NeighborhoodRadius.Fill(1);
37  m_CountFunction = CountFunctionType::New();
38 }
39 
41 template <class TInputImage, class TOutputImage, class TCountFunction>
44 {}
45 
46 template <class TInputImage, class TOutputImage, class TCountFunction>
47 void
50 {
51  // call the superclass' implementation of this method
52  Superclass::GenerateInputRequestedRegion();
53 
54  // get pointers to the input and output
55  InputImagePointerType inputPtr = const_cast<TInputImage *>(this->GetInput());
56  OutputImagePointerType outputPtr = this->GetOutput();
57 
58  if (!inputPtr || !outputPtr)
59  {
60  return;
61  }
62  // get a copy of the input requested region (should equal the output
63  // requested region)
64  InputImageRegionType inputRequestedRegion = inputPtr->GetRequestedRegion();
65 
66  // pad the input requested region by the operator radius
67  inputRequestedRegion.PadByRadius(m_NeighborhoodRadius);
68 
69  // crop the input requested region at the input's largest possible region
70  if (inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()))
71  {
72  inputPtr->SetRequestedRegion(inputRequestedRegion);
73  return;
74  }
75  else
76  {
77  // Couldn't crop the region (requested region is outside the largest
78  // possible region). Throw an exception.
79 
80  // store what we tried to request (prior to trying to crop)
81  inputPtr->SetRequestedRegion(inputRequestedRegion);
82 
83  // build an exception
84  itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
85  std::ostringstream msg;
86  msg << this->GetNameOfClass()
87  << "::GenerateInputRequestedRegion()";
88  e.SetLocation(msg.str().c_str());
89  e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
90  e.SetDataObject(inputPtr);
91  throw e;
92  }
93 }
94 
95 template <class TInputImage, class TOutputImage, class TCountFunction>
96 void
99 {
100  Superclass::BeforeThreadedGenerateData();
101 
102  m_CountFunction->SetInputImage(this->GetInput());
103  m_CountFunction->SetNeighborhoodRadius(m_NeighborhoodRadius);
104 }
105 
107 template <class TInputImage, class TOutputImage, class TCountFunction>
108 void
110 ::ThreadedGenerateData(const InputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId)
111 {
112  InputImagePointerType inputPtr = const_cast<InputImageType *> (this->GetInput());
113  OutputImagePointerType outputPtr = this->GetOutput();
114 
116  RadiusType r;
117  r[0] = m_NeighborhoodRadius[0];
118  r[1] = m_NeighborhoodRadius[1];
119 
123  faceList = bC(inputPtr, outputRegionForThread, r);
125 
126  itk::ImageRegionIterator<OutputImageType> itOut(outputPtr, outputRegionForThread);
127 
128  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
129 
130  typename InputImageType::IndexType index;
131 
132  for (fit = faceList.begin(); fit != faceList.end(); ++fit)
133  {
134  it = itk::ConstNeighborhoodIterator<TInputImage>(r, inputPtr, *fit);
135 
136  itOut = itk::ImageRegionIterator<TOutputImage>(outputPtr, *fit);
137  it.OverrideBoundaryCondition(&nbc);
138  it.GoToBegin();
139 
140  while (!itOut.IsAtEnd())
141  {
142  index = it.GetIndex();
143 
144  if (outputRegionForThread.IsInside(index))
145  {
146  itOut.Set(m_CountFunction->EvaluateAtIndex(index));
147  }
148 
149  ++itOut;
150  ++it;
151  progress.CompletedPixel(); // potential exception thrown here
152  }
153  }
154 }
155 
157 template <class TInputImage, class TOutputImage, class TCountFunction>
158 void
160 ::PrintSelf(std::ostream& os, itk::Indent indent) const
161 {
162  Superclass::PrintSelf(os, indent);
163  os << indent << "Neighborhood Radius : " << m_NeighborhoodRadius << std::endl;
164 }
165 } // End namespace otb
166 #endif

Generated at Sat Mar 8 2014 15:51:31 for Orfeo Toolbox with doxygen 1.8.3.1