Orfeo Toolbox  3.16
itkMorphologyImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkMorphologyImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-16 19:33:41 $
7  Version: $Revision: 1.33 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkMorphologyImageFilter_txx
18 #define __itkMorphologyImageFilter_txx
19 
20 // First make sure that the configuration is available.
21 // This line can be removed once the optimized versions
22 // gets integrated into the main directories.
23 #include "itkConfigure.h"
24 
25 #ifdef ITK_USE_CONSOLIDATED_MORPHOLOGY
27 #else
28 
29 
30 #include <limits.h>
31 
33 #include "itkNumericTraits.h"
36 #include "itkProgressReporter.h"
37 
38 namespace itk {
39 
40 template<class TInputImage, class TOutputImage, class TKernel>
43  : m_Kernel()
44 {
45  m_DefaultBoundaryCondition.SetConstant( NumericTraits<PixelType>::Zero );
46  m_BoundaryCondition = &m_DefaultBoundaryCondition;
47 }
48 
49 template <class TInputImage, class TOutputImage, class TKernel>
50 void
53 {
54  // call the superclass' implementation of this method
55  Superclass::GenerateInputRequestedRegion();
56 
57  // get pointers to the input and output
58  typename Superclass::InputImagePointer inputPtr =
59  const_cast< TInputImage * >( this->GetInput() );
60 
61  if ( !inputPtr )
62  {
63  return;
64  }
65 
66  // get a copy of the input requested region (should equal the output
67  // requested region)
68  typename TInputImage::RegionType inputRequestedRegion;
69  inputRequestedRegion = inputPtr->GetRequestedRegion();
70 
71  // pad the input requested region by the operator radius
72  inputRequestedRegion.PadByRadius( m_Kernel.GetRadius() );
73 
74  // crop the input requested region at the input's largest possible region
75  if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) )
76  {
77  inputPtr->SetRequestedRegion( inputRequestedRegion );
78  return;
79  }
80  else
81  {
82  // Couldn't crop the region (requested region is outside the largest
83  // possible region). Throw an exception.
84 
85  // store what we tried to request (prior to trying to crop)
86  inputPtr->SetRequestedRegion( inputRequestedRegion );
87 
88  // build an exception
89  InvalidRequestedRegionError e(__FILE__, __LINE__);
90  e.SetLocation(ITK_LOCATION);
91  e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
92  e.SetDataObject(inputPtr);
93  throw e;
94  }
95 }
96 
97 
98 template<class TInputImage, class TOutputImage, class TKernel>
99 void
101 ::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
102  int threadId)
103 {
104  // Neighborhood iterators
106 
107  // Find the boundary "faces"
110  faceList = fC(this->GetInput(), outputRegionForThread, m_Kernel.GetRadius());
111 
113 
115 
116  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
117 
118  // Process the boundary faces, these are N-d regions which border the
119  // edge of the buffer
120 
121  const KernelIteratorType kernelBegin = m_Kernel.Begin();
122  const KernelIteratorType kernelEnd = m_Kernel.End();
123 
124  for (fit = faceList.begin(); fit != faceList.end(); ++fit)
125  {
126  b_iter = NeighborhoodIteratorType(m_Kernel.GetRadius(),
127  this->GetInput(), *fit);
128 
129  o_iter = ImageRegionIterator<OutputImageType>(this->GetOutput(), *fit);
130  b_iter.OverrideBoundaryCondition(m_BoundaryCondition);
131  b_iter.GoToBegin();
132 
133  while ( ! o_iter.IsAtEnd() )
134  {
135  o_iter.Set( this->Evaluate(b_iter, kernelBegin, kernelEnd) );
136  ++b_iter;
137  ++o_iter;
138  progress.CompletedPixel();
139  }
140  }
141 
142 }
143 
144 template<class TInputImage, class TOutputImage, class TKernel>
145 void
147 ::PrintSelf(std::ostream &os, Indent indent) const
148 {
149  Superclass::PrintSelf(os, indent);
150 
151  os << indent << "Kernel: " << m_Kernel << std::endl;
152  os << indent << "Boundary condition: " << typeid( *m_BoundaryCondition ).name() << std::endl;
153 }
154 
155 }// end namespace itk
156 #endif
157 
158 #endif

Generated at Sat Feb 2 2013 23:53:33 for Orfeo Toolbox with doxygen 1.8.1.1