1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkSingleValuedNonLinearOptimizer.cxx,v $
Language: C++
Date: $Date: 2005-01-21 20:22:49 $
Version: $Revision: 1.17 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef _itkSingleValuedNonLinearOptimizer_txx
#define _itkSingleValuedNonLinearOptimizer_txx
#include "itkSingleValuedNonLinearOptimizer.h"
namespace itk
{
SingleValuedNonLinearOptimizer
::SingleValuedNonLinearOptimizer()
{
m_CostFunction = 0;
}
/**
* Connect a Cost Function
*/
void
SingleValuedNonLinearOptimizer
::SetCostFunction( CostFunctionType * costFunction )
{
if( m_CostFunction.GetPointer() == costFunction )
{
return;
}
itkDebugMacro("setting CostFunction to " << costFunction);
m_CostFunction = costFunction;
if(!m_ScalesInitialized)
{
const unsigned int numberOfParameters =
m_CostFunction->GetNumberOfParameters();
ScalesType scales( numberOfParameters );
scales.Fill( 1.0f );
SetScales( scales );
m_ScalesInitialized = true;
}
this->Modified();
}
/**
* Get the cost function value at the given parameters
*/
SingleValuedNonLinearOptimizer::MeasureType
SingleValuedNonLinearOptimizer
::GetValue( const ParametersType & parameters ) const
{
itkDebugMacro("Computing CostFunction value at " << parameters);
if(!m_CostFunction)
{
ExceptionObject ex;
ex.SetLocation(__FILE__);
ex.SetDescription("The costfunction must be set prior to calling GetValue");
throw ex;
}
return this->GetCostFunction()->GetValue(parameters);
}
void
SingleValuedNonLinearOptimizer
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf(os,indent);
if (m_CostFunction)
{
os << indent << "Cost Function: " << m_CostFunction.GetPointer() << std::endl;
}
}
} // namespace itk
#endif
|