ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkCompensatedSummation_h 00019 #define __itkCompensatedSummation_h 00020 00021 #include "itkNumericTraits.h" 00022 #include "itkConceptChecking.h" 00023 00024 namespace itk 00025 { 00026 00065 template < class TFloat > 00066 class CompensatedSummation 00067 { 00068 public: 00070 typedef TFloat FloatType; 00071 00073 typedef typename NumericTraits< FloatType >::AccumulateType AccumulateType; 00074 00076 typedef CompensatedSummation Self; 00077 00079 CompensatedSummation(); 00080 00082 CompensatedSummation( const Self & rhs ); 00083 00085 void operator=( const Self & rhs ); 00086 00088 void AddElement( const FloatType & element ); 00089 Self & operator+=( const FloatType & rhs ); 00091 00093 Self & operator-=( const FloatType & rhs ); 00094 00097 Self & operator*=( const FloatType & rhs ); 00098 Self & operator/=( const FloatType & rhs ); 00100 00102 void ResetToZero(); 00103 00105 const AccumulateType & GetSum() const; 00106 00107 private: 00108 AccumulateType m_Sum; 00109 AccumulateType m_Compensation; 00110 00111 // Maybe support more types in the future with template specialization. 00112 #ifdef ITK_USE_CONCEPT_CHECKING 00113 itkConceptMacro( OnlyDefinedForFloatingPointTypes, ( itk::Concept::IsFloatingPoint< TFloat > ) ); 00114 #endif // ITK_USE_CONCEPT_CHECKING 00115 }; 00116 00117 void ITKCommon_EXPORT CompensatedSummationAddElement( float& compensation, float& sum, const float& element ); 00118 void ITKCommon_EXPORT CompensatedSummationAddElement( double& compensation, double& sum, const double& element ); 00119 00120 } // end namespace itk 00121 00122 #ifndef ITK_MANUAL_INSTANTIATION 00123 #include "itkCompensatedSummation.hxx" 00124 #endif 00125 00126 #endif 00127