ITK  4.9.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 #include "itkMath.h"
24 
25 namespace itk
26 {
27 
28 namespace Functor {
29 
30 template< typename TNumerator, typename TDenominator=TNumerator, typename TOutput=TNumerator >
32 {
33 public:
35  {
38  };
39 
41 
42  bool operator!=( const DivideOrZeroOut & other ) const
43  {
44  return !(*this == other);
45  }
46 
47  bool operator==( const DivideOrZeroOut & itkNotUsed(other) ) const
48  {
49  // Always return true for now. Do a comparison to m_Threshold if it is
50  // every made set-able.
51  return true;
52  }
53 
54  inline TOutput operator()( const TNumerator & n, const TDenominator & d )
55  {
56  if ( d < m_Threshold )
57  {
58  return m_Constant;
59  }
60  return static_cast< TOutput >( n ) / static_cast< TOutput >( d );
61  }
62  TDenominator m_Threshold;
63  TOutput m_Constant;
64 };
65 } // end namespace functor
66 
67 
78 template< typename TInputImage1,
79  typename TInputImage2=TInputImage1,
80  typename TOutputImage=TInputImage1 >
82  public BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
83  Functor::DivideOrZeroOut<
84  typename TInputImage1::PixelType,
85  typename TInputImage2::PixelType,
86  typename TOutputImage::PixelType > >
87 {
88 public:
91  typedef BinaryFunctorImageFilter<TInputImage1, TInputImage2, TOutputImage,
93  typename TInputImage1::PixelType,
94  typename TInputImage2::PixelType,
95  typename TOutputImage::PixelType > > Superclass;
98 
99  typedef typename TInputImage1::PixelType NumeratorPixelType;
100  typedef typename TInputImage2::PixelType DenominatorPixelType;
101  typedef typename TOutputImage::PixelType OutputPixelType;
102 
104  itkNewMacro(Self);
105 
108 
110  void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE
111  {
112  Superclass::PrintSelf(os, indent);
113  os << indent << "Threshold: " << GetThreshold() << std::endl;
114  }
116 
120  {
121  if ( Math::NotExactlyEquals(threshold, this->GetFunctor().m_Threshold) )
122  {
123  this->GetFunctor().m_Threshold = threshold;
124  this->Modified();
125  }
126  }
128  {
129  return this->GetFunctor().m_Threshold;
130  }
132 
135  void SetConstant( OutputPixelType constant )
136  {
137  if ( Math::NotExactlyEquals(constant, this->GetFunctor().m_Constant) )
138  {
139  this->GetFunctor().m_Constant = constant;
140  this->Modified();
141  }
142  }
144  {
145  return this->GetFunctor().m_Constant;
146  }
148 
149 protected:
152 
153 private:
154  DivideOrZeroOutImageFilter(const Self&) ITK_DELETE_FUNCTION;
155  void operator=(const Self&) ITK_DELETE_FUNCTION;
156 };
157 
158 } // end namespace itk
159 #endif
bool operator!=(const DivideOrZeroOut &other) const
void SetConstant(OutputPixelType constant)
void SetThreshold(DenominatorPixelType threshold)
static const double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:47
Base class for all process objects that output image data.
bool operator==(const DivideOrZeroOut &) const
virtual void PrintSelf(std::ostream &os, Indent indent) const override
bool NotExactlyEquals(const TInput1 &x1, const TInput2 &x2)
Definition: itkMath.h:676
virtual void Modified() const
TOutput operator()(const TNumerator &n, const TDenominator &d)
BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::DivideOrZeroOut< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType > > Superclass
Control indentation during Print() invocation.
Definition: itkIndent.h:49
DenominatorPixelType GetThreshold() const
void PrintSelf(std::ostream &os, Indent indent) const override
Implements pixel-wise generic operation of two images, or of an image and a constant.