ITK  5.0.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 
23 #include "itkNumericTraits.h"
24 #include "itkMath.h"
25 
26 namespace itk
27 {
28 
46 template< typename TInputImage1, typename TInputImage2, typename TOutputImage >
47 class ITK_TEMPLATE_EXPORT DivideImageFilter:
48  public
49  BinaryGeneratorImageFilter< TInputImage1, TInputImage2, TOutputImage >
50 {
51 public:
52  ITK_DISALLOW_COPY_AND_ASSIGN(DivideImageFilter);
53 
58 
63 
69  using FunctorType = Functor::Div< typename TInputImage1::PixelType,
70  typename TInputImage2::PixelType,
71  typename TOutputImage::PixelType >;
72 
76  itkNewMacro(Self);
77 
79  itkTypeMacro(DivideImageFilter,
81 
82 #ifdef ITK_USE_CONCEPT_CHECKING
83  // Begin concept checking
84  itkConceptMacro( IntConvertibleToInput2Check,
86  itkConceptMacro( Input1Input2OutputDivisionOperatorsCheck,
87  ( Concept::DivisionOperators< typename TInputImage1::PixelType,
88  typename TInputImage2::PixelType,
89  typename TOutputImage::PixelType > ) );
90  // End concept checking
91 #endif
92 
93 protected:
95  {
96 #if !defined( ITK_WRAPPING_PARSER )
97  Superclass::SetFunctor(FunctorType());
98 #endif
99  }
100 
101  ~DivideImageFilter() override = default;
102 
103  void VerifyPreconditions() ITKv5_CONST override
104  {
105  Superclass::VerifyPreconditions();
106 
107  const auto *input
108  = dynamic_cast< const typename Superclass::DecoratedInput2ImagePixelType * >( this->ProcessObject::GetInput(1) );
109  if( input != nullptr && itk::Math::AlmostEquals(input->Get(), itk::NumericTraits< typename TInputImage2::PixelType >::ZeroValue()) )
110  {
111  itkGenericExceptionMacro(<<"The constant value used as denominator should not be set to zero");
112  }
113  }
114 };
115 
116 } // end namespace itk
117 
118 #endif
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Base class for all process objects that output image data.
Implements pixel-wise generic operation of two images, or of an image and a constant.
DataObject * GetInput(const DataObjectIdentifierType &key)
Return an input.
void VerifyPreconditions() ITKv5_CONST override
Verifies that the process object has been configured correctly, that all required inputs are set...
bool AlmostEquals(T1 x1, T2 x2)
Provide consistent equality checks between values of potentially different scalar or complex types...
Definition: itkMath.h:669
#define itkConceptMacro(name, concept)
Pixel-wise division of two images.