cmtkCubicSpline.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 SRI International
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: 2398 $
00026 //
00027 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkCubicSpline_h_included_
00034 #define __cmtkCubicSpline_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Base/cmtkTypes.h>
00039 #include <Base/cmtkMathUtil.h>
00040 
00041 namespace
00042 cmtk
00043 {
00044 
00047 
00053 class CubicSpline 
00054 {
00055 public:
00057   static Types::Coordinate ApproxSpline0 ( const Types::Coordinate t ) 
00058   {
00059     return ( MathUtil::Square(1-t) * (1-t) ) / 6;
00060   }
00061 
00063   static Types::Coordinate ApproxSpline1 ( const Types::Coordinate t ) 
00064   {
00065     return ( 4 + MathUtil::Square(t) * ( 3 * t - 6 ) ) / 6;
00066   }
00067   
00069   static Types::Coordinate ApproxSpline2 ( const Types::Coordinate t ) 
00070   {
00071     return ( 1 + t * (3 + t * (3 - 3*t))) / 6;
00072   }
00073 
00075   static Types::Coordinate ApproxSpline3 ( const Types::Coordinate t ) 
00076   {
00077     return t*t*t/6;
00078   }  
00079 
00081   static Types::Coordinate ApproxSpline ( const int k, const Types::Coordinate t ) 
00082   {
00083     switch (k) 
00084       {
00085       case 0: return ApproxSpline0( t );
00086       case 1: return ApproxSpline1( t );
00087       case 2: return ApproxSpline2( t );
00088       case 3: return ApproxSpline3( t );
00089       default: return 0;
00090       }
00091 #ifdef MSDOS
00092     return 0;
00093 #endif
00094   }
00095 
00097   static Types::Coordinate DerivApproxSpline0 ( const Types::Coordinate t ) 
00098   {
00099     return  -MathUtil::Square(1-t) / 2;
00100   }
00101   
00103   static Types::Coordinate DerivApproxSpline1 ( const Types::Coordinate t ) 
00104   {
00105     return 3*t*t/2-2*t;
00106   }
00107   
00109   static Types::Coordinate DerivApproxSpline2 ( const Types::Coordinate t ) 
00110   {
00111     return ( 1 + 2*t - 3*t*t ) / 2;
00112   }
00113 
00115   static Types::Coordinate DerivApproxSpline3 ( const Types::Coordinate t ) 
00116   {
00117     return t*t/2;
00118   }  
00119   
00121   static Types::Coordinate DerivApproxSpline ( const int k, const Types::Coordinate t ) 
00122   {
00123     switch (k) 
00124       {
00125       case 0: return DerivApproxSpline0( t );
00126       case 1: return DerivApproxSpline1( t );
00127       case 2: return DerivApproxSpline2( t );
00128       case 3: return DerivApproxSpline3( t );
00129       default: return 0;
00130       }
00131 #ifdef MSDOS
00132     return 0;
00133 #endif
00134   }
00135   
00137   static Types::Coordinate SecondDerivApproxSpline0 ( const Types::Coordinate t ) 
00138   {
00139     return  1 - t;
00140   }
00141   
00143   static Types::Coordinate SecondDerivApproxSpline1 ( const Types::Coordinate t ) 
00144   {
00145     return 3 * t - 2;
00146   }
00147 
00149   static Types::Coordinate SecondDerivApproxSpline2 ( const Types::Coordinate t ) 
00150   {
00151     return 1 - 3 * t;
00152   }
00153 
00155   static Types::Coordinate SecondDerivApproxSpline3 ( const Types::Coordinate t ) 
00156   {
00157     return t;
00158   }  
00159 
00161   static Types::Coordinate SecondDerivApproxSpline ( const int k, const Types::Coordinate t ) 
00162   {
00163     switch (k) 
00164       {
00165       case 0: return SecondDerivApproxSpline0( t );
00166       case 1: return SecondDerivApproxSpline1( t );
00167       case 2: return SecondDerivApproxSpline2( t );
00168       case 3: return SecondDerivApproxSpline3( t );
00169       default: return 0;
00170       }
00171 #ifdef MSDOS
00172     return 0;
00173 #endif
00174   }
00175   
00177   static Types::Coordinate InterpSpline0 ( const Types::Coordinate t ) 
00178   {
00179     return (Types::Coordinate)( t * ( 0.5 * ( -1 + t * ( 2 - t ) ) ) );
00180   }
00181 
00183   static Types::Coordinate InterpSpline1 ( const Types::Coordinate t ) 
00184   {
00185     return (Types::Coordinate)( 0.5 * ( 3 * t - 5 ) * t*t + 1 );
00186   }
00187   
00189   static Types::Coordinate InterpSpline2 ( const Types::Coordinate t ) 
00190   {
00191     return (Types::Coordinate)( 0.5 * t * ( 1 + t * ( 4  - 3 * t ) ) );
00192   }
00193 
00195   static Types::Coordinate InterpSpline3 ( const Types::Coordinate t ) 
00196   {
00197     return (Types::Coordinate)( 0.5 * ( t*t * ( t-1 ) ) );
00198   }  
00199 
00201   static Types::Coordinate InterpSpline ( const int k, const Types::Coordinate t ) 
00202   {
00203     switch (k) 
00204       {
00205       case 0: return InterpSpline0( t );
00206       case 1: return InterpSpline1( t );
00207       case 2: return InterpSpline2( t );
00208       case 3: return InterpSpline3( t );
00209       default: return 0;
00210       }
00211 #ifdef MSDOS
00212     return 0;
00213 #endif
00214   }
00215   
00217   static Types::Coordinate DerivInterpSpline0 ( const Types::Coordinate t ) 
00218   {
00219     return ((-3 * t + 4) * t - 1) / 2;
00220   }
00221   
00223   static Types::Coordinate DerivInterpSpline1 ( const Types::Coordinate t ) 
00224   {
00225     return ( ( 9 * t - 10 ) * t ) / 2;
00226   }
00227   
00229   static Types::Coordinate DerivInterpSpline2 ( const Types::Coordinate t ) 
00230   {
00231     return ( ( -9 * t + 8 ) * t + 1 ) / 2;
00232   }
00233 
00235   static Types::Coordinate DerivInterpSpline3 ( const Types::Coordinate t ) 
00236   {
00237     return (( 3 * t - 2 ) * t) / 2;
00238   }  
00239   
00241   static Types::Coordinate DerivInterpSpline ( const int k, const Types::Coordinate t ) 
00242   {
00243     switch (k) 
00244       {
00245       case 0: return DerivInterpSpline0( t );
00246       case 1: return DerivInterpSpline1( t );
00247       case 2: return DerivInterpSpline2( t );
00248       case 3: return DerivInterpSpline3( t );
00249       default: return 0;
00250       }
00251 #ifdef MSDOS
00252     return 0;
00253 #endif
00254   }
00255   
00257   static Types::Coordinate SecondDerivInterpSpline0 ( const Types::Coordinate t ) 
00258   {
00259     return -3 * t + 2;
00260   }
00261   
00263   static Types::Coordinate SecondDerivInterpSpline1 ( const Types::Coordinate t ) 
00264   {
00265     return 9 * t - 5;
00266   }
00267 
00269   static Types::Coordinate SecondDerivInterpSpline2 ( const Types::Coordinate t )
00270   {
00271     return -9 * t + 4;
00272   }
00273 
00275   static Types::Coordinate SecondDerivInterpSpline3 ( const Types::Coordinate t ) 
00276   {
00277     return 3 * t - 1;
00278   }  
00279   
00281   static Types::Coordinate SecondDerivInterpSpline ( const int k, const Types::Coordinate t ) 
00282   {
00283     switch (k) 
00284       {
00285       case 0: return SecondDerivInterpSpline0( t );
00286       case 1: return SecondDerivInterpSpline1( t );
00287       case 2: return SecondDerivInterpSpline2( t );
00288       case 3: return SecondDerivInterpSpline3( t );
00289       default: return 0;
00290       }
00291 #ifdef MSDOS
00292     return 0;
00293 #endif
00294   }
00295 };
00296 
00297 } // namespace
00298 
00299 #endif // #ifndef __cmtkCubicSpline_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines