CharbonnierErrorFunction.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Stefan Pszczolkowski Parraguez, Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_CharbonnierErrorFunction_H
21 #define MIRTK_CharbonnierErrorFunction_H
22 
23 #include "mirtk/RadialErrorFunction.h"
24 
25 #include "mirtk/Math.h"
26 
27 
28 namespace mirtk {
29 
30 
31 /**
32  * Charbonnier fiducial registration error function
33  */
35 {
36  mirtkObjectMacro(CharbonnierErrorFunction);
37 
38  /// Squared fiducial registration error threshold
39  mirtkPublicAttributeMacro(double, SquaredThreshold);
40 
41 public:
42 
43  /// Constructor
44  CharbonnierErrorFunction(double threshold = 1.0)
45  :
46  _SquaredThreshold(threshold * threshold)
47  {}
48 
49  /// Copy constructor
51  :
52  _SquaredThreshold(other._SquaredThreshold)
53  {}
54 
55  /// Copy construct a new instance
57  {
58  return new CharbonnierErrorFunction(*this);
59  }
60 
61  /// Type enumeration value
62  virtual TypeId Type() const
63  {
64  return Charbonnier;
65  }
66 
67  /// Set parameter value from string
68  bool Set(const char *name, const char *value)
69  {
70  if (strcmp(name, "Threshold") == 0) {
71  double threshold = .0;
72  if (!FromString(value, threshold) || threshold <= .0) return false;
73  _SquaredThreshold = threshold * threshold;
74  return true;
75  } else if (strcmp(name, "Squared threshold") == 0) {
76  return FromString(value, _SquaredThreshold) && _SquaredThreshold <= .0;
77  }
78  return false;
79  }
80 
81  // Import other overloads
83 
84  /// Get parameter key/value as string map
86  {
87  ParameterList params;
88  Insert(params, "Threshold", ToString(sqrt(_SquaredThreshold)));
89  return params;
90  }
91 
92  /// Evaluate radial registration error
93  virtual double Value(double d) const
94  {
95  return 2.0 * _SquaredThreshold * (sqrt(1.0 + d / _SquaredThreshold) - 1.0);
96  }
97 
98  /// Evaluate derivative of radial registration error
99  virtual double Derivative(double d) const
100  {
101  return 1.0 / sqrt(1.0 + d / _SquaredThreshold);
102  }
103 
104 };
105 
106 
107 } // namespace mirtk
108 
109 #endif // MIRTK_CharbonnierErrorFunction_H
ParameterList Parameter() const
Get parameter key/value as string map.
TypeId
Enumeration of available error functions.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
virtual TypeId Type() const
Type enumeration value.
virtual double Derivative(double d) const
Evaluate derivative of radial registration error.
Definition: IOConfig.h:41
virtual RadialErrorFunction * NewInstance() const
Copy construct a new instance.
string ToString(const EnergyMeasure &value, int w, char c, bool left)
Convert energy measure enumeration value to string.
bool FromString(const char *str, EnergyMeasure &value)
Convert energy measure string to enumeration value.
virtual double Value(double d) const
Evaluate radial registration error.
virtual ParameterList Parameter() const
Get parameter name/value pairs.
Definition: Object.h:139
CharbonnierErrorFunction(const CharbonnierErrorFunction &other)
Copy constructor.
ParameterList & Insert(ParameterList &params, string name, T value)
Insert/replace value into/in parameters list.
Definition: Object.h:212
CharbonnierErrorFunction(double threshold=1.0)
Constructor.
bool Set(const char *name, const char *value)
Set parameter value from string.
Charbonnier fiducial registration error.