Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
itkConstrainedValueMultiplicationImageFilter.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: itkConstrainedValueMultiplicationImageFilter.h,v $
5 Language: C++
6 Date: $Date: 2007-09-27 11:36:40 $
7 Version: $Revision: 1.7 $
8
9 Copyright (c) Insight Software Consortium. All rights reserved.
10 See ITKCopyright.txt or https://www.itk.org/HTML/Copyright.htm for details.
11
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
15
16=========================================================================*/
17#ifndef itkConstrainedValueMultiplicationImageFilter_h
18#define itkConstrainedValueMultiplicationImageFilter_h
19
20#include "itkBinaryFunctorImageFilter.h"
21#include "itkNumericTraits.h"
22
23namespace itk
24{
25
52namespace Functor
53{
54
55template <class TInput1, class TInput2, class TOutput>
57{
58public:
61 bool operator!=(const ConstrainedValueMultiplication&) const { return false; }
62 bool operator==(const ConstrainedValueMultiplication& other) const { return !(*this != other); }
63 inline TOutput operator()(const TInput1& A, const TInput2& B)
64 {
65 const double dA = static_cast<double>(A);
66 const double dB = static_cast<double>(B);
67 const double add = dA * dB;
68 // IEEE‑754 double can exactly represent all integers in the range [–2^53, 2^53], but beyond that,
69 // only some integer numbers are representable.
70 // 18446744073709551615 (2^64−1) must be rounded to the nearest representable double: 18446744073709551616
71 constexpr double max_closest_representable = static_cast<double>(NumericTraits<TOutput>::max());
72
73 const double cadd1 = (add < max_closest_representable) ? add : max_closest_representable;
74 const double cadd2 = (cadd1 > NumericTraits<TOutput>::NonpositiveMin()) ? cadd1 : NumericTraits<TOutput>::NonpositiveMin();
75 return static_cast<TOutput>(cadd2);
76 }
77};
78} // namespace Functor
79
80template <class TInputImage1, class TInputImage2, class TOutputImage>
82 : public BinaryFunctorImageFilter<TInputImage1,
83 TInputImage2,
84 TOutputImage,
85 Functor::ConstrainedValueMultiplication<typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType>>
86{
87public:
90 typedef BinaryFunctorImageFilter<TInputImage1,
91 TInputImage2,
92 TOutputImage,
95 typedef SmartPointer<Self> Pointer;
96 typedef SmartPointer<const Self> ConstPointer;
97
100
103
104#ifdef ITK_USE_CONCEPT_CHECKING
106 itkConceptMacro(Input1ConvertibleToDoubleCheck, (Concept::Convertible<typename TInputImage1::PixelType, double>));
107 itkConceptMacro(Input2ConvertibleToDoubleCheck, (Concept::Convertible<typename TInputImage2::PixelType, double>));
108 itkConceptMacro(DoubleConvertibleToOutputCastCheck, (Concept::Convertible<double, typename TOutputImage::PixelType>));
109 itkConceptMacro(DoubleLessThanOutputCheck, (Concept::LessThanComparable<double, typename TOutputImage::PixelType>));
111#endif
112
113protected:
116
117private:
119 void operator=(const Self&) = delete;
120};
121
122} // namespace itk
123
124#endif
BinaryFunctorImageFilter< TInputImage1, TInputImage2, TOutputImage, Functor::ConstrainedValueMultiplication< typename TInputImage1::PixelType, typename TInputImage2::PixelType, typename TOutputImage::PixelType > > Superclass
~ConstrainedValueMultiplicationImageFilter() override=default
itkTypeMacro(ConstrainedValueMultiplicationImageFilter, BinaryFunctorImageFilter)
bool operator==(const ConstrainedValueMultiplication &other) const
bool operator!=(const ConstrainedValueMultiplication &) const
Simplified inverse ITK transforms.