Orfeo Toolbox  3.16
itkContourMeanDistanceImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkContourMeanDistanceImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-13 18:54:27 $
7  Version: $Revision: 1.3 $
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 
18 #ifndef __itkContourMeanDistanceImageFilter_txx
19 #define __itkContourMeanDistanceImageFilter_txx
21 
22 #include "itkImageRegionIterator.h"
24 #include "itkNumericTraits.h"
25 #include "itkProgressAccumulator.h"
27 
28 namespace itk {
29 
30 
31 template<class TInputImage1, class TInputImage2>
34 {
35 
36  // this filter requires two input images
37  this->SetNumberOfRequiredInputs( 2 );
38 
39  m_MeanDistance = NumericTraits<RealType>::Zero;
40 }
41 
42 
43 template<class TInputImage1, class TInputImage2>
44 void
46 ::SetInput2( const TInputImage2 * image )
47 {
48  this->SetNthInput(1, const_cast<TInputImage2 *>( image ) );
49 }
50 
51 
52 template<class TInputImage1, class TInputImage2>
54 ::InputImage2Type *
57 {
58  return static_cast< const TInputImage2 * >
59  (this->ProcessObject::GetInput(1));
60 }
61 
62 template<class TInputImage1, class TInputImage2>
63 void
66 {
67  Superclass::GenerateInputRequestedRegion();
68 
69  // this filter requires:
70  // - the largeset possible region of the first image
71  // - the corresponding region of the second image
72  if ( this->GetInput1() )
73  {
74  InputImage1Pointer image1 =
75  const_cast< InputImage1Type * >( this->GetInput1() );
76  image1->SetRequestedRegionToLargestPossibleRegion();
77 
78  if ( this->GetInput2() )
79  {
80  InputImage2Pointer image2 =
81  const_cast< InputImage2Type * >( this->GetInput2() );
82  image2->SetRequestedRegion(
83  this->GetInput1()->GetRequestedRegion() );
84  }
85 
86  }
87 }
88 
89 
90 template<class TInputImage1, class TInputImage2>
91 void
94 {
95  Superclass::EnlargeOutputRequestedRegion(data);
97 }
98 
99 
100 template<class TInputImage1, class TInputImage2>
101 void
104 {
105 
106  // Pass the first input through as the output
107  InputImage1Pointer image =
108  const_cast< TInputImage1 * >( this->GetInput1() );
109  this->GraftOutput( image );
110 
111  RealType distance12, distance21;
112 
113  // Create a process accumulator for tracking the progress of this minipipeline
115  progress->SetMiniPipelineFilter(this);
116 
118  Filter12Type;
119 
120  typename Filter12Type::Pointer filter12 = Filter12Type::New();
121 
122  filter12->SetInput1( this->GetInput1() );
123  filter12->SetInput2( this->GetInput2() );
124 
126  Filter21Type;
127 
128  typename Filter21Type::Pointer filter21 = Filter21Type::New();
129 
130  filter21->SetInput1( this->GetInput2() );
131  filter21->SetInput2( this->GetInput1() );
132 
133  // Register the filter with the with progress accumulator using
134  // equal weight proportion
135  progress->RegisterInternalFilter(filter12,.5f);
136  progress->RegisterInternalFilter(filter21,.5f);
137 
138  filter12->Update();
139  distance12 = filter12->GetContourDirectedMeanDistance();
140  filter21->Update();
141  distance21 = filter21->GetContourDirectedMeanDistance();
142 
143  if ( distance12 > distance21 )
144  {
145  m_MeanDistance = distance12;
146  }
147  else
148  {
149  m_MeanDistance = distance21;
150  }
151 
152 }
153 
154 template<class TInputImage1, class TInputImage2>
155 void
157 ::PrintSelf(std::ostream& os, Indent indent) const
158 {
159  Superclass::PrintSelf(os,indent);
160 
161  os << indent << "MeanDistance: "
162  << m_MeanDistance << std::endl;
163 }
164 
165 
166 }// end namespace itk
167 #endif

Generated at Sat May 18 2013 23:34:54 for Orfeo Toolbox with doxygen 1.8.3.1