cmtkFunctional.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2011 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: 2735 $
00026 //
00027 //  $LastChangedDate: 2011-01-14 10:34:12 -0800 (Fri, 14 Jan 2011) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkFunctional_h_included_
00034 #define __cmtkFunctional_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <System/cmtkSmartPtr.h>
00039 #include <System/cmtkConsole.h>
00040 
00041 #include <Base/cmtkVector.h>
00042 #include <Base/cmtkTypes.h>
00043 
00044 #ifdef HAVE_UNISTD_H
00045 #  include <unistd.h>
00046 #endif
00047 
00048 namespace
00049 cmtk
00050 {
00051 
00054 
00056 class Functional
00057 {
00058 public:
00060   typedef Functional Self;
00061 
00063   typedef SmartPointer<Self> SmartPtr;
00064 
00071   typedef Types::Combined<Types::Coordinate,Types::DataItem>::Type ReturnType;
00072 
00074   typedef Vector<Types::Coordinate> ParameterVectorType;
00075 
00077   typedef Types::Coordinate ParameterType;
00078 
00080   virtual void SetParamVector ( ParameterVectorType& )
00081   {
00082     StdErr << "ERROR: Functional::SetParamVector() was called but not implemented\n";
00083     exit( 1 );
00084   }
00085 
00087   virtual void GetParamVector ( ParameterVectorType& )
00088   {
00089     StdErr << "ERROR: Functional::GetParamVector() was called but not implemented\n";
00090     exit( 1 );
00091   }
00092 
00094   virtual Self::ReturnType Evaluate() { return 0; } // cannot make this abstract because we need to instantiate this for generic initialization
00095 
00097   virtual Self::ReturnType EvaluateAt( ParameterVectorType& v )
00098   {
00099     this->SetParamVector( v );
00100     return this->Evaluate();
00101   }
00102 
00103 #ifdef CMTK_BUILD_DEMO
00104 
00105   virtual void SnapshotAt( ParameterVectorType& ) {}
00106 #endif
00107 
00112   virtual Self::ReturnType EvaluateAlongGradientAt( ParameterVectorType& v ) { return this->EvaluateAt( v ); }
00113 
00115   virtual Self::ReturnType EvaluateWithGradient( ParameterVectorType& v, ParameterVectorType& g, const Types::Coordinate step = 1 );
00116 
00118   virtual size_t ParamVectorDim() const = 0;
00119 
00126   virtual size_t VariableParamVectorDim() const
00127   {
00128     return this->ParamVectorDim();
00129   }
00130 
00132   virtual ~Functional() {};
00133 
00139   virtual Types::Coordinate GetParamStep( const size_t, const Types::Coordinate mmStep = 1 ) const 
00140   {
00141     return mmStep;
00142   }
00143 
00154   virtual bool Wiggle() { return false; }
00155 };
00156 
00158 
00159 } // namespace cmtk
00160 
00161 #endif // #ifndef _FUNCTIONAL_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines