ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkDivideOrZeroOutImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkDivideOrZeroOutImageFilter_h
19 #define __itkDivideOrZeroOutImageFilter_h
20 
22 #include "itkNumericTraits.h"
23 
24 namespace itk
25 {
26 
27 namespace Functor {
28 
29 template< class TNumerator, class TDenominator=TNumerator, class TOutput=TNumerator >
31 {
32 public:
34  {
37  };
38 
40 
41  bool operator!=( const DivideOrZeroOut & other ) const
42  {
43  return !(*this == other);
44  }
45 
46  bool operator==( const DivideOrZeroOut & itkNotUsed(other) ) const
47  {
48  // Always return true for now. Do a comparison to m_Threshold if it is
49  // every made set-able.
50  return true;
51  }
52 
53  inline TOutput operator()( const TNumerator & n, const TDenominator & d )
54  {
55  if ( d < m_Threshold )
56  {
57  return m_Constant;
58  }
59  return static_cast< TOutput >( n ) / static_cast< TOutput >( d );
60  }
61  TDenominator m_Threshold;
62  TOutput m_Constant;
63 };
64 } // end namespace functor
65 
66 
77 template< typename TInputImage1,
78  typename TInputImage2=TInputImage1,
79  typename TOutputImage=TInputImage1 >
80 class ITK_EXPORT DivideOrZeroOutImageFilter :
81  public BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
82  Functor::DivideOrZeroOut<
83  typename TInputImage1::PixelType,
84  typename TInputImage2::PixelType,
85  typename TOutputImage::PixelType > >
86 {
87 public:
90  typedef BinaryFunctorImageFilter<TInputImage1, TInputImage2, TOutputImage,
92  typename TInputImage1::PixelType,
93  typename TInputImage2::PixelType,
94  typename TOutputImage::PixelType > > Superclass;
97 
98  typedef typename TInputImage1::PixelType NumeratorPixelType;
99  typedef typename TInputImage2::PixelType DenominatorPixelType;
100  typedef typename TOutputImage::PixelType OutputPixelType;
101 
103  itkNewMacro(Self);
104 
107 
109  void PrintSelf(std::ostream& os, Indent indent) const
110  {
111  Superclass::PrintSelf(os, indent);
112  os << indent << "Threshold: " << GetThreshold() << std::endl;
113  }
115 
118  void SetThreshold( DenominatorPixelType threshold )
119  {
120  if ( threshold != this->GetFunctor().m_Threshold )
121  {
122  this->GetFunctor().m_Threshold = threshold;
123  this->Modified();
124  }
125  }
126  DenominatorPixelType GetThreshold() const
127  {
128  return this->GetFunctor().m_Threshold;
129  }
131 
134  void SetConstant( OutputPixelType constant )
135  {
136  if ( constant != this->GetFunctor().m_Constant )
137  {
138  this->GetFunctor().m_Constant = constant;
139  this->Modified();
140  }
141  }
142  OutputPixelType GetConstant() const
143  {
144  return this->GetFunctor().m_Constant;
145  }
147 
148 protected:
151 
152 private:
153  DivideOrZeroOutImageFilter(const Self&); //purposely not implemented
154  void operator=(const Self&); //purposely not implemented
155 };
156 
157 } // end namespace itk
158 #endif
159