ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkConstrainedValueDifferenceImageFilter.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 __itkConstrainedValueDifferenceImageFilter_h
19 #define __itkConstrainedValueDifferenceImageFilter_h
20 
22 #include "itkNumericTraits.h"
23 
24 namespace itk
25 {
55 namespace Functor
56 {
57 template< class TInput1, class TInput2, class TOutput >
59 {
60 public:
64  {
65  return false;
66  }
67 
68  bool operator==(const ConstrainedValueDifference & other) const
69  {
70  return !( *this != other );
71  }
72 
73  inline TOutput operator()(const TInput1 & A,
74  const TInput2 & B) const
75  {
76  const double dA = static_cast< double >( A );
77  const double dB = static_cast< double >( B );
78  const double diff = dA - dB;
79  const double cdiff1 = diff > NumericTraits< TOutput >::NonpositiveMin() ?
81  const double cdiff2 = cdiff1 < NumericTraits< TOutput >::max() ?
83 
84  return static_cast< TOutput >( cdiff2 );
85  }
86 };
87 }
88 
89 template< class TInputImage1, class TInputImage2, class TOutputImage >
91  public
92  BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
93  Functor::ConstrainedValueDifference<
94  typename TInputImage1::PixelType,
95  typename TInputImage2::PixelType,
96  typename TOutputImage::PixelType > >
97 {
98 public:
101  typedef BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage,
103  typename TInputImage1::PixelType,
104  typename TInputImage2::PixelType,
105  typename TOutputImage::PixelType > >
109 
111  itkNewMacro(Self);
112 
116 
117 #ifdef ITK_USE_CONCEPT_CHECKING
118 
119  itkConceptMacro( Input1ConvertibleToDoubleCheck,
121  itkConceptMacro( Input2ConvertibleToDoubleCheck,
123  itkConceptMacro( DoubleConvertibleToOutputCheck,
125  itkConceptMacro( DoubleGreaterThanOutputCheck,
127 
129 #endif
130 
131 protected:
134 
135 private:
136  ConstrainedValueDifferenceImageFilter(const Self &); //purposely not
137  // implemented
138  void operator=(const Self &); //purposely not
139 
140  // implemented
141 };
142 } // end namespace itk
143 
144 #endif
145