Orfeo Toolbox  3.16
itkEigenAnalysis2DImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkEigenAnalysis2DImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-14 19:20:33 $
7  Version: $Revision: 1.23 $
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 __itkEigenAnalysis2DImageFilter_txx
18 #define __itkEigenAnalysis2DImageFilter_txx
19 
23 #include "itkProgressReporter.h"
24 
25 
26 namespace itk
27 {
28 
29 
33 template <class TInputImage, class TEigenValueImage, class TEigenVectorImage>
36 {
37  this->SetNumberOfRequiredInputs( 3 );
38  this->SetNumberOfRequiredOutputs( 3 );
39  this->SetNthOutput( 0, this->MakeOutput( 0 ) );
40  this->SetNthOutput( 1, this->MakeOutput( 1 ) );
41  this->SetNthOutput( 2, this->MakeOutput( 2 ) );
42 
43 }
44 
48 template <class TInputImage, class TEigenValueImage, class TEigenVectorImage>
49 void
51 ::SetInput1( TInputImage * image )
52 {
53  this->SetNthInput(0, image);
54 }
55 
56 
62 template <class TInputImage, class TEigenValueImage, class TEigenVectorImage>
63 void
65 ::SetInput2( TInputImage * image )
66 {
67  this->SetNthInput(1, image);
68 }
69 
70 
74 template <class TInputImage, class TEigenValueImage, class TEigenVectorImage>
75 void
77 ::SetInput3( TInputImage * image )
78 {
79  this->SetNthInput(2, image);
80 }
81 
82 
86 template <class TInputImage, class TEigenValueImage, class TEigenVectorImage>
90 {
91  return dynamic_cast<EigenValueImageType *>(
92  this->ProcessObject::GetOutput( 0 ) );
93 }
94 
95 
99 template <class TInputImage, class TEigenValueImage, class TEigenVectorImage>
103 {
104  return dynamic_cast<EigenValueImageType *>(
105  this->ProcessObject::GetOutput( 1 ) );
106 }
107 
108 
112 template <class TInputImage, class TEigenValueImage, class TEigenVectorImage>
116 {
117  EigenVectorImageType *eigenVector = dynamic_cast<EigenVectorImageType *>(
118  this->ProcessObject::GetOutput( 2 ) );
119 
120  if (eigenVector)
121  {
122  return eigenVector;
123  }
124  else
125  {
126  itkWarningMacro(<<"EigenAnalysis2DImageFilter::GetMaxEigenVector(): dynamic_cast has failed. A reinterpret_cast is being attempted."
127  << std::endl << "Type name is: "
128  << typeid( *this->GetOutput( 2 )).name());
129  return reinterpret_cast<EigenVectorImageType *>(
130  this->ProcessObject::GetOutput( 2 ) );
131  }
132 }
133 
134 
140 template <class TInputImage, class TEigenValueImage, class TEigenVectorImage>
143 ::MakeOutput(unsigned int idx)
144 {
145  DataObject::Pointer output;
146  switch( idx )
147  {
148  case 0:
149  output = (EigenValueImageType::New()).GetPointer();
150  break;
151  case 1:
152  output = (EigenValueImageType::New()).GetPointer();
153  break;
154  case 2:
155  output = (EigenVectorImageType::New()).GetPointer();
156  break;
157  }
158  return output.GetPointer();
159 }
160 
161 
162 template <class TInputImage, class TEigenValueImage, class TEigenVectorImage>
163 void
166 {
167 
168  typename TInputImage::ConstPointer inputPtr1(
169  dynamic_cast<const TInputImage *>(
171 
172  typename TInputImage::ConstPointer inputPtr2(
173  dynamic_cast<const TInputImage *>(
175 
176  typename TInputImage::ConstPointer inputPtr3(
177  dynamic_cast<const TInputImage *>(
179 
180  EigenValueImagePointer outputPtr1 = this->GetMaxEigenValue();
181  EigenValueImagePointer outputPtr2 = this->GetMinEigenValue();
182  EigenVectorImagePointer outputPtr3 = this->GetMaxEigenVector();
183 
184  outputPtr1->SetBufferedRegion( inputPtr1->GetBufferedRegion() );
185  outputPtr2->SetBufferedRegion( inputPtr1->GetBufferedRegion() );
186  outputPtr3->SetBufferedRegion( inputPtr1->GetBufferedRegion() );
187 
188  outputPtr1->Allocate();
189  outputPtr2->Allocate();
190  outputPtr3->Allocate();
191 
192  EigenValueImageRegionType region = outputPtr1->GetRequestedRegion();
193 
194  ImageRegionConstIteratorWithIndex<TInputImage> inputIt1( inputPtr1, region );
195  ImageRegionConstIteratorWithIndex<TInputImage> inputIt2( inputPtr2, region );
196  ImageRegionConstIteratorWithIndex<TInputImage> inputIt3( inputPtr3, region );
197 
198  ImageRegionIteratorWithIndex<EigenValueImageType> outputIt1(outputPtr1, region );
199  ImageRegionIteratorWithIndex<EigenValueImageType> outputIt2(outputPtr2, region );
200  ImageRegionIteratorWithIndex<EigenVectorImageType> outputIt3(outputPtr3, region );
201 
202  EigenVectorType nullVector;
203  nullVector.Fill( 0.0 );
204 
205  // support progress methods/callbacks
206  ProgressReporter progress(this, 0, region.GetNumberOfPixels());
207 
208  inputIt1.GoToBegin();
209  inputIt2.GoToBegin();
210  inputIt3.GoToBegin();
211 
212  outputIt1.GoToBegin();
213  outputIt2.GoToBegin();
214  outputIt3.GoToBegin();
215 
216  EigenVectorType eigenVector;
217 
218  while( !inputIt1.IsAtEnd() )
219  {
220  const double xx = static_cast<double>( inputIt1.Get() );
221  const double xy = static_cast<double>( inputIt2.Get() );
222  const double yy = static_cast<double>( inputIt3.Get() );
223 
224  const double dxy = xx - yy;
225  const double sxy = xx + yy;
226 
227  const double S = vcl_sqrt(dxy * dxy + 4.0 * xy * xy);
228 
229  const double pp = ( sxy + S ) / 2.0;
230  const double qq = ( sxy - S ) / 2.0;
231 
232  outputIt1.Set( pp );
233  outputIt2.Set( qq );
234 
235  eigenVector[0] = static_cast<VectorComponentType>(( -dxy - S ) / 2.0 );
236  eigenVector[1] = static_cast<VectorComponentType>( -xy );
237 
238  const VectorComponentType norm = eigenVector.GetNorm();
239  if( norm > 1e-30 )
240  {
241  outputIt3.Set( eigenVector / norm );
242  }
243  else
244  {
245  outputIt3.Set( nullVector );
246  }
247 
248  ++inputIt1;
249  ++inputIt2;
250  ++inputIt3;
251 
252  ++outputIt1;
253  ++outputIt2;
254  ++outputIt3;
255 
256  progress.CompletedPixel();
257  }
258 }
259 } // end namespace itk
260 
261 #endif

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