ITK  4.12.0
Insight Segmentation and Registration Toolkit
itkDivideImageFilter.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 itkDivideImageFilter_h
19 #define itkDivideImageFilter_h
20 
22 #include "itkNumericTraits.h"
23 #include "itkMath.h"
24 
25 namespace itk
26 {
27 namespace Functor
28 {
34 template< typename TInput1, typename TInput2, typename TOutput >
35 class ITK_TEMPLATE_EXPORT Div
36 {
37 public:
38  Div() {}
39  ~Div() {}
40  bool operator!=(const Div &) const
41  {
42  return false;
43  }
45 
46  bool operator==(const Div & other) const
47  {
48  return !( *this != other );
49  }
50 
51  inline TOutput operator()(const TInput1 & A, const TInput2 & B) const
52  {
54  {
55  return (TOutput)( A / B );
56  }
57  else
58  {
59  return NumericTraits< TOutput >::max( static_cast<TOutput>(A) );
60  }
61  }
62 };
63 }
81 template< typename TInputImage1, typename TInputImage2, typename TOutputImage >
82 class ITK_TEMPLATE_EXPORT DivideImageFilter:
83  public
84  BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
85  Functor::Div<
86  typename TInputImage1::PixelType,
87  typename TInputImage2::PixelType,
88  typename TOutputImage::PixelType > >
89 {
90 public:
95 
99  typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
100  Functor::Div<
101  typename TInputImage1::PixelType,
102  typename TInputImage2::PixelType,
103  typename TOutputImage::PixelType >
105 
111 
115  itkNewMacro(Self);
116 
118  itkTypeMacro(DivideImageFilter,
120 
121 #ifdef ITK_USE_CONCEPT_CHECKING
122  // Begin concept checking
123  itkConceptMacro( IntConvertibleToInput2Check,
125  itkConceptMacro( Input1Input2OutputDivisionOperatorsCheck,
126  ( Concept::DivisionOperators< typename TInputImage1::PixelType,
127  typename TInputImage2::PixelType,
128  typename TOutputImage::PixelType > ) );
129  // End concept checking
130 #endif
131 
132 protected:
134  virtual ~DivideImageFilter() {}
135 
136  void GenerateData() ITK_OVERRIDE
137  {
138  const typename Superclass::DecoratedInput2ImagePixelType *input
139  = dynamic_cast< const typename Superclass::DecoratedInput2ImagePixelType * >(
140  this->ProcessObject::GetInput(1) );
142  {
143  itkGenericExceptionMacro(<<"The constant value used as denominator should not be set to zero");
144  }
145  else
146  {
147  Superclass::GenerateData();
148  }
149  }
150 
151 private:
152  ITK_DISALLOW_COPY_AND_ASSIGN(DivideImageFilter);
153 
154 };
155 } // end namespace itk
156 
157 #endif
Base class for all process objects that output image data.
bool operator==(const Div &other) const
static ITK_CONSTEXPR_FUNC T max(const T &)
SmartPointer< const Self > ConstPointer
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
bool AlmostEquals(T1 x1, T2 x2)
Provide consistent equality checks between values of potentially different scalar or complex types...
Definition: itkMath.h:672
TOutput operator()(const TInput1 &A, const TInput2 &B) const
Define additional traits for native types such as int or float.
bool operator!=(const Div &) const
bool NotAlmostEquals(T1 x1, T2 x2)
Definition: itkMath.h:680
#define itkConceptMacro(name, concept)
SmartPointer< Self > Pointer
Implements pixel-wise generic operation of two images, or of an image and a constant.
BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::Div< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType > > Superclass
Pixel-wise division of two images.