20 #ifndef MIRTK_EnergyTerm_H 21 #define MIRTK_EnergyTerm_H 23 #include "mirtk/Configurable.h" 25 #include "mirtk/Indent.h" 26 #include "mirtk/EnergyMeasure.h" 27 #include "mirtk/Transformation.h" 28 #include "mirtk/ObjectFactory.h" 49 mirtkPublicAttributeMacro(
double, Weight);
55 mirtkPublicAttributeMacro(
bool, DivideByInitialValue);
129 virtual void Update(
bool gradient =
true);
151 void Gradient(
double *gradient,
double step);
165 virtual void GradientStep(
const double *gradient,
double &min,
double &max)
const;
178 virtual void EvaluateGradient(
double *gradient,
double step,
double weight) = 0;
187 virtual double RawValue(
double)
const;
197 string Prefix(
const char * = NULL)
const;
200 virtual void WriteDataSets(
const char *,
const char *,
bool =
true)
const;
203 virtual void WriteGradient(
const char *,
const char *)
const;
212 #define mirtkEnergyTermMacro(name, id) \ 213 mirtkObjectMacro(name); \ 216 static mirtk::EnergyMeasure ID() { return id; } \ 218 virtual mirtk::EnergyMeasure EnergyMeasure() const { return id; } \ 223 #define mirtkRegisterEnergyTermMacro(type) \ 224 mirtk::EnergyTerm::Factory().Register(type::ID(), type::NameOfType(), \ 225 mirtk::New<mirtk::EnergyTerm, type>) 229 #define mirtkAutoRegisterEnergyTermMacro(type) \ 230 mirtkAutoRegisterObjectTypeMacro(mirtk::EnergyTerm::Factory(), \ 231 mirtk::EnergyMeasure, type::ID(), \ 232 mirtk::EnergyTerm, type) 237 #endif // MIRTK_EnergyTerm_H double InitialValue()
Returns initial value of energy term.
string Prefix(const char *=NULL) const
Prefix to be used for debug output files.
static EnergyTerm * TryNew(EnergyMeasure, const char *="", double=1.0)
Construct new energy term or return nullptr if term not available.
void ResetValue()
Reset cached value of energy term.
ObjectFactory< enum EnergyMeasure, EnergyTerm > FactoryType
Type of energy term factory.
virtual bool Upgrade()
Update energy term after convergence.
virtual bool SetWithoutPrefix(const char *, const char *)
Set parameter value from string.
void ResetInitialValue()
Reset initial value of energy term.
double Value()
Evaluate energy term.
virtual void WriteGradient(const char *, const char *) const
Write gradient of data fidelity term w.r.t each transformed input.
virtual void Initialize()
Initialize energy term once input and parameters have been set.
virtual ~EnergyTerm()
Destructor.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
void NormalizedGradient(double *gradient, double step)
virtual ParameterList Parameter() const
Get parameter key/value as string map.
virtual enum EnergyMeasure EnergyMeasure() const =0
Energy measure implemented by this term.
EnergyTerm & operator=(const EnergyTerm &)
Assignment operator.
static EnergyTerm * New(EnergyMeasure, const char *="", double=1.0)
Construct new energy term.
virtual bool SetWithPrefix(const char *, const char *)
Set parameter value from string.
static FactoryType & Factory()
Get global energy term factory instance.
virtual void GradientStep(const double *gradient, double &min, double &max) const
virtual double Evaluate()=0
Evaluate unweighted energy term.
virtual void WriteDataSets(const char *, const char *, bool=true) const
Write input of data fidelity term.
virtual void Print(Indent=0) const
Print debug information.
EnergyMeasure
Enumeration of all available energy terms.
EnergyTerm(const char *="", double=1.0)
Constructor.
virtual void Update(bool gradient=true)
virtual ParameterList Parameter() const
Get parameter name/value pairs.
virtual void EvaluateGradient(double *gradient, double step, double weight)=0
void Gradient(double *gradient, double step)