Orfeo Toolbox  3.16
itkDerivativeImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkDerivativeImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-14 19:20:33 $
7  Version: $Revision: 1.26 $
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 __itkDerivativeImageFilter_txx
18 #define __itkDerivativeImageFilter_txx
20 
21 #include "itkNumericTraits.h"
23 #include "itkDerivativeOperator.h"
25 #include "itkProgressAccumulator.h"
26 
27 namespace itk
28 {
29 
30 template <class TInputImage, class TOutputImage>
31 void
34 {
35  // call the superclass' implementation of this method. this should
36  // copy the output requested region to the input requested region
37  Superclass::GenerateInputRequestedRegion();
38 
39  // get pointers to the input and output
40  typename Superclass::InputImagePointer inputPtr =
41  const_cast< InputImageType * >( this->GetInput() );
42 
43  if ( !inputPtr )
44  {
45  return;
46  }
47 
48  // Build an operator so that we can determine the kernel size
50  oper.SetDirection(m_Direction);
51  oper.SetOrder(m_Order);
52  oper.CreateDirectional();
53 
54  // get a copy of the input requested region (should equal the output
55  // requested region)
56  typename TInputImage::RegionType inputRequestedRegion;
57  inputRequestedRegion = inputPtr->GetRequestedRegion();
58 
59  // pad the input requested region by the operator radius
60  inputRequestedRegion.PadByRadius( oper.GetRadius() );
61 
62  // crop the input requested region at the input's largest possible region
63  if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) )
64  {
65  inputPtr->SetRequestedRegion( inputRequestedRegion );
66  return;
67  }
68  else
69  {
70  // Couldn't crop the region (requested region is outside the largest
71  // possible region). Throw an exception.
72 
73  // store what we tried to request (prior to trying to crop)
74  inputPtr->SetRequestedRegion( inputRequestedRegion );
75 
76  // build an exception
77  InvalidRequestedRegionError e(__FILE__, __LINE__);
78  e.SetLocation(ITK_LOCATION);
79  e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
80  e.SetDataObject(inputPtr);
81  throw e;
82  }
83 }
84 
85 
86 template< class TInputImage, class TOutputImage >
87 void
90 {
92 
93  // Define the operator value type so that we can filter integral
94  // images and have the proper operator defined.
95  typedef typename NumericTraits<OutputPixelType>::RealType OperatorValueType;
96 
97  // Filter
99  oper.SetDirection(m_Direction);
100  oper.SetOrder(m_Order);
101  oper.CreateDirectional();
102  oper.FlipAxes();
103 
104  if (m_UseImageSpacing == true)
105  {
106  if ( this->GetInput()->GetSpacing()[m_Direction] == 0.0 )
107  {
108  itkExceptionMacro(<< "Image spacing cannot be zero.");
109  }
110  else
111  {
112  oper.ScaleCoefficients( 1.0 / this->GetInput()->GetSpacing()[m_Direction] );
113  }
114  }
115 
117  ::Pointer filter =
119  ::New();
120 
121  // Create a process accumulator for tracking the progress of this minipipeline
123  progress->SetMiniPipelineFilter(this);
124 
125  // Register the filter with the with progress accumulator using
126  // equal weight proportion
127  progress->RegisterInternalFilter(filter,1.0f);
128 
129  filter->OverrideBoundaryCondition(&nbc);
130 
131  //
132  // Set up the mini-pipline
133  //
134  filter->SetOperator(oper);
135  filter->SetInput(this->GetInput());
136 
137  // Graft this filter's output to the mini-pipeline. this sets up
138  // the mini-pipeline to write to this filter's output and copies
139  // region ivars and meta-data
140  filter->GraftOutput(this->GetOutput());
141 
142  // Execute the mini-pipeline.
143  filter->Update();
144 
145  // Graft the output of the mini-pipeline back onto the filter's output,
146  // this copies back the region ivars and meta-data.
147  this->GraftOutput(filter->GetOutput());
148 }
149 
150 template< class TInputImage, class TOutputImage >
151 void
153 PrintSelf(std::ostream& os, Indent indent) const
154 {
155  Superclass::PrintSelf(os,indent);
156 
157  os << indent << "Order: " << m_Order << std::endl;
158  os << indent << "Direction: " << m_Direction << std::endl;
159  os << indent << "UseImageSpacing: " << m_UseImageSpacing << std::endl;
160 }
161 
162 } // end namespace itk
163 
164 #endif

Generated at Sat Feb 2 2013 23:35:04 for Orfeo Toolbox with doxygen 1.8.1.1