ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkCompensatedSummation.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 itkCompensatedSummation_h
19 #define itkCompensatedSummation_h
20 
21 #include "itkNumericTraits.h"
22 #include "itkConceptChecking.h"
23 
24 namespace itk
25 {
26 
65 template < typename TFloat >
66 class ITK_TEMPLATE_EXPORT CompensatedSummation
67 {
68 public:
70  using FloatType = TFloat;
71 
74 
77 
82 
84  CompensatedSummation( const Self & rhs );
85 
87  Self & operator=( const Self & rhs );
88 
90  void AddElement( const FloatType & element );
91  Self & operator+=( const FloatType & rhs );
92  Self & operator+=( const Self & rhs );
94 
96  Self & operator-=( const FloatType & rhs );
97 
100  Self & operator*=( const FloatType & rhs );
101  Self & operator/=( const FloatType & rhs );
103 
105  void ResetToZero();
106 
108  Self & operator=( const FloatType & rhs );
109 
111  const AccumulateType & GetSum() const;
112 
114  explicit operator FloatType() const;
115 
116 private:
119 
120 // Maybe support more types in the future with template specialization.
121 #ifdef ITK_USE_CONCEPT_CHECKING
122  itkConceptMacro( OnlyDefinedForFloatingPointTypes, ( itk::Concept::IsFloatingPoint< TFloat > ) );
123 #endif // ITK_USE_CONCEPT_CHECKING
124 };
125 
126 void ITKCommon_EXPORT CompensatedSummationAddElement( float& compensation, float& sum, const float& element );
127 void ITKCommon_EXPORT CompensatedSummationAddElement( double& compensation, double& sum, const double& element );
128 
129 } // end namespace itk
130 
131 #ifndef ITK_MANUAL_INSTANTIATION
132 #include "itkCompensatedSummation.hxx"
133 #endif
134 
135 #endif
Define numeric traits for std::vector.
typename NumericTraits< FloatType >::AccumulateType AccumulateType
void ITKCommon_EXPORT CompensatedSummationAddElement(float &compensation, float &sum, const float &element)
Perform more precise accumulation of floating point numbers.
#define itkConceptMacro(name, concept)