cmtkEntropyMinimizationIntensityCorrectionFunctional.cxx

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 #include "cmtkEntropyMinimizationIntensityCorrectionFunctional.h"
00034 
00035 #include <System/cmtkConsole.h>
00036 
00037 namespace
00038 cmtk
00039 {
00040 
00043 template<unsigned int NDegreeMul>
00044 EntropyMinimizationIntensityCorrectionFunctionalBase::SmartPtr
00045 CreateEntropyMinimizationIntensityCorrectionFunctional
00046 ( const unsigned int polynomialDegreeAdd )
00047 {
00048   typedef EntropyMinimizationIntensityCorrectionFunctionalBase::SmartPtr FunctionalPointer;
00049   FunctionalPointer functional;
00050 
00051   switch ( polynomialDegreeAdd )
00052     {
00053     case 0 :
00054       functional = FunctionalPointer( new EntropyMinimizationIntensityCorrectionFunctional<0,NDegreeMul> );
00055       break;
00056     case 1 :
00057       functional = FunctionalPointer( new EntropyMinimizationIntensityCorrectionFunctional<1,NDegreeMul> );
00058       break;
00059     case 2 :
00060       functional = FunctionalPointer( new EntropyMinimizationIntensityCorrectionFunctional<2,NDegreeMul> );
00061       break;
00062     case 3 :
00063       functional = FunctionalPointer( new EntropyMinimizationIntensityCorrectionFunctional<3,NDegreeMul> );
00064       break;
00065     case 4 :
00066       functional = FunctionalPointer( new EntropyMinimizationIntensityCorrectionFunctional<4,NDegreeMul> );
00067       break;
00068     default:
00069       StdErr.printf( "ERROR: combination of polynomial degrees %d (add) and %d (mul) not supported.\n", polynomialDegreeAdd, NDegreeMul );
00070       exit( 1 );
00071     }
00072 
00073   return functional;
00074 }
00075 
00076 EntropyMinimizationIntensityCorrectionFunctionalBase::SmartPtr
00077 CreateEntropyMinimizationIntensityCorrectionFunctional
00078 ( const unsigned int polynomialDegreeAdd, const unsigned int polynomialDegreeMul )
00079 {
00080   typedef EntropyMinimizationIntensityCorrectionFunctionalBase::SmartPtr FunctionalPointer;
00081   FunctionalPointer functional;
00082 
00083   switch ( polynomialDegreeMul )
00084     {
00085     case 0 :
00086       functional = CreateEntropyMinimizationIntensityCorrectionFunctional<0>( polynomialDegreeAdd );
00087       break;
00088     case 1 :
00089       functional = CreateEntropyMinimizationIntensityCorrectionFunctional<1>( polynomialDegreeAdd );
00090       break;
00091     case 2 :
00092       functional = CreateEntropyMinimizationIntensityCorrectionFunctional<2>( polynomialDegreeAdd );
00093       break;
00094     case 3 :
00095       functional = CreateEntropyMinimizationIntensityCorrectionFunctional<3>( polynomialDegreeAdd );
00096       break;
00097     case 4 :
00098       functional = CreateEntropyMinimizationIntensityCorrectionFunctional<4>( polynomialDegreeAdd );
00099       break;
00100     default:
00101       StdErr.printf( "ERROR: polynomial degree %d (mul) not supported.\n", polynomialDegreeMul );
00102       exit( 1 );
00103     }
00104   
00105   return functional;
00106 }
00107 
00108 EntropyMinimizationIntensityCorrectionFunctionalBase::SmartPtr
00109 CreateEntropyMinimizationIntensityCorrectionFunctional
00110 ( const unsigned int polynomialDegreeAdd, const unsigned int polynomialDegreeMul,
00111   EntropyMinimizationIntensityCorrectionFunctionalBase::SmartPtr oldFunctional )
00112 {
00113   EntropyMinimizationIntensityCorrectionFunctionalBase::SmartPtr newFunctional = CreateEntropyMinimizationIntensityCorrectionFunctional( polynomialDegreeAdd, polynomialDegreeMul );
00114 
00115   if ( oldFunctional )
00116     {
00117     CoordinateVector vOld;
00118     oldFunctional->GetParamVector( vOld );
00119     
00120     CoordinateVector vNew( newFunctional->ParamVectorDim() );
00121     vNew.SetAll( 0.0 );
00122     for ( size_t degreeAdd = 0; degreeAdd < oldFunctional->GetNumberOfMonomialsAdd(); ++degreeAdd )
00123       {
00124       vNew[degreeAdd] = vOld[degreeAdd];
00125       }
00126     for ( size_t degreeMul = 0; degreeMul < oldFunctional->GetNumberOfMonomialsMul(); ++degreeMul )
00127       {
00128       vNew[newFunctional->GetNumberOfMonomialsAdd() + degreeMul] = vOld[oldFunctional->GetNumberOfMonomialsAdd() + degreeMul];
00129       }
00130     }
00131   return newFunctional;
00132 }
00133 
00134 } // namespace cmtk
00135 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines