cmtkUnits.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 2010 SRI International
00004 //
00005 //  Copyright 2010 Torsten Rohlfing
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2322 $
00026 //
00027 //  $LastChangedDate: 2010-08-27 14:07:59 -0700 (Fri, 27 Aug 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkUnits_h_included_
00034 #define __cmtkUnits_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 namespace
00039 cmtk
00040 {
00041 
00044 
00046 namespace
00047 Units
00048 {
00049 
00051 class UnitBase
00052 {
00053 public:
00055   explicit UnitBase( const double value ) : m_Value( value ) {};
00056 
00058   double Value() const
00059   {
00060     return this->m_Value;
00061   }
00062 
00064   static double Pi()
00065   {
00066     return 3.14159265358979323846;
00067   }
00068   
00069 private:
00071   double m_Value;
00072 };
00073 
00075 template<class T>
00076 class Arithmetic
00077 {
00078 public:
00080   friend const T operator*( const double lhs, const T& rhs )
00081   {
00082     return T( lhs * rhs.Value() );
00083   }
00084 
00086   friend const T operator*( const T& lhs, const double rhs )
00087   {
00088     return T( lhs.Value() * rhs );
00089   }
00090 
00092   friend const T operator/( const T& lhs, const double rhs )
00093   {
00094     return T( lhs.Value() / rhs );
00095   }
00096 
00098   friend const T operator+( const T& lhs, const T& rhs )
00099   {
00100     return T( lhs.Value() + rhs.Value() );
00101   }
00102 
00104   friend const T operator-( const T& rhs )
00105   {
00106     return T( -rhs.Value() );
00107   }
00108 };
00109 
00111 class Radians;
00112 
00114 class Degrees :
00115     public UnitBase, public Arithmetic<Degrees>
00116 {
00117 public:
00119   explicit Degrees( const double value = 0 ) : UnitBase( value ) {};
00120 
00122   inline Degrees( const Radians& radians );
00123 };
00124 
00126 class Radians :
00127     public UnitBase, public Arithmetic<Radians>
00128 {
00129 public:
00131   explicit Radians( const double value = 0 ) : UnitBase( value ) {};
00132 
00134   inline Radians( const Degrees& degrees );
00135 };
00136 
00137 inline Degrees::Degrees( const Radians& radians ) : UnitBase( radians.Value() / (UnitBase::Pi() / 180) ) {};
00138 inline Radians::Radians( const Degrees& degrees ) : UnitBase( degrees.Value() * (UnitBase::Pi() / 180) ) {};
00139 
00141 class GaussianFWHM;
00142 
00144 class GaussianSigma :
00145     public UnitBase, public Arithmetic<GaussianSigma>
00146 {
00147 public:
00149   explicit GaussianSigma( const double value = 0 ) : UnitBase( value ) {};
00150 
00152   inline GaussianSigma( const GaussianFWHM& radians );
00153 };
00154 
00156 class GaussianFWHM :
00157     public UnitBase, public Arithmetic<GaussianFWHM>
00158 {
00159 public:
00161   explicit GaussianFWHM( const double value = 0 ) : UnitBase( value ) {};
00162 
00164   inline GaussianFWHM( const GaussianSigma& degrees );
00165 };
00166 
00167 inline GaussianSigma::GaussianSigma( const GaussianFWHM& fwhm ) : UnitBase( fwhm.Value() / 2.354820045 ) {};
00168 inline GaussianFWHM::GaussianFWHM( const GaussianSigma& sigma ) : UnitBase( sigma.Value() * 2.354820045 ) {};
00169 
00170 }
00171 
00173 
00174 } // namespace cmtk
00175 
00176 #endif // #define __cmtkUnits_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines