CurrentsDistance.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 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_CurrentsDistance_H
21 #define MIRTK_CurrentsDistance_H
22 
23 #include "mirtk/PointSetDistance.h"
24 
25 #include "vtkSmartPointer.h"
26 #include "vtkPointSet.h"
27 #include "vtkPolyData.h"
28 
29 
30 namespace mirtk {
31 
32 
33 /**
34  * Currents distance measure of
35  * points (0-currents), curves (1-currents), or surfaces (2-currents)
36  *
37  * This implementation is based on the currents distance similarity
38  * computations of the Deformetrica registration software package.
39  *
40  * \sa http://www.deformetrica.org/
41  */
43 {
44  mirtkEnergyTermMacro(CurrentsDistance, EM_CurrentsDistance);
45 
46  // ---------------------------------------------------------------------------
47  // Attributes
48 
49  /// Current representation of target data set
50  mirtkAttributeMacro(vtkSmartPointer<vtkPolyData>, TargetCurrent);
51 
52  /// Current representation of source data set
53  mirtkAttributeMacro(vtkSmartPointer<vtkPolyData>, SourceCurrent);
54 
55  /// Sigma value of currents kernel
56  mirtkPublicAttributeMacro(double, Sigma);
57 
58  /// Whether to ensure symmetry of currents dot product
59  mirtkPublicAttributeMacro(bool, Symmetric);
60 
61  /// Sum of squared norm of fixed (i.e., untransformed) data set(s)
62  mirtkAttributeMacro(double, TargetNormSquared);
63 
64  // ---------------------------------------------------------------------------
65  // Currents representation
66 protected:
67 
68  /// Convert data set to current
69  static vtkSmartPointer<vtkPolyData> ToCurrent(vtkPointSet *);
70 
71  /// Convert surface mesh to current
72  static vtkSmartPointer<vtkPolyData> SurfaceToCurrent(vtkPolyData *);
73 
74  // ---------------------------------------------------------------------------
75  // Construction/Destruction
76 public:
77 
78  /// Constructor
79  CurrentsDistance(const char * = "", double = 1.0);
80 
81  /// Copy constructor
83 
84  /// Assignment operator
86 
87  /// Destructor
88  virtual ~CurrentsDistance();
89 
90  // ---------------------------------------------------------------------------
91  // Initialization
92 
93 protected:
94 
95  /// Common (re-)initialization code of this class (must be non-virtual function!)
96  void Init();
97 
98 public:
99 
100  /// Initialize distance measure after input and parameters were set
101  virtual void Initialize();
102 
103  /// Reinitialize distance measure after input topology changed
104  virtual void Reinitialize();
105 
106  // ---------------------------------------------------------------------------
107  // Parameters
108 
109 protected:
110 
111  /// Set parameter value from string
112  virtual bool SetWithPrefix(const char *, const char *);
113 
114  /// Set parameter value from string
115  virtual bool SetWithoutPrefix(const char *, const char *);
116 
117 public:
118 
119  // Import other overloads
121 
122  /// Get parameter key/value as string map
123  virtual ParameterList Parameter() const;
124 
125  // ---------------------------------------------------------------------------
126  // Evaluation
127 
128  /// Update moving input points and internal state of distance measure
129  virtual void Update(bool);
130 
131 protected:
132 
133  /// Evaluate unweighted energy term
134  virtual double Evaluate();
135 
136  /// Compute non-parametric gradient w.r.t points of given data set
137  ///
138  /// \param[in] target Transformed data set.
139  /// \param[out] gradient Non-parametric gradient of polydata distance measure.
140  virtual void NonParametricGradient(const RegisteredPointSet *target,
141  GradientType *gradient);
142 
143  // ---------------------------------------------------------------------------
144  // Debugging
145 public:
146 
147  /// Write input of data fidelity term
148  virtual void WriteDataSets(const char *, const char *, bool = true) const;
149 
150 };
151 
152 
153 } // namespace mirtk
154 
155 #endif // MIRTK_CurrentsDistance_H
static vtkSmartPointer< vtkPolyData > ToCurrent(vtkPointSet *)
Convert data set to current.
virtual void Reinitialize()
Reinitialize distance measure after input topology changed.
CurrentsDistance & operator=(const CurrentsDistance &)
Assignment operator.
virtual bool SetWithPrefix(const char *, const char *)
Set parameter value from string.
Distance measure based on currents representation.
Definition: EnergyMeasure.h:62
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
virtual void Update(bool)
Update moving input points and internal state of distance measure.
CurrentsDistance(const char *="", double=1.0)
Constructor.
virtual ParameterList Parameter() const
Get parameter key/value as string map.
static vtkSmartPointer< vtkPolyData > SurfaceToCurrent(vtkPolyData *)
Convert surface mesh to current.
Definition: IOConfig.h:41
virtual void WriteDataSets(const char *, const char *, bool=true) const
Write input of data fidelity term.
virtual ~CurrentsDistance()
Destructor.
virtual void NonParametricGradient(const RegisteredPointSet *target, GradientType *gradient)
void Init()
Common (re-)initialization code of this class (must be non-virtual function!)
virtual ParameterList Parameter() const
Get parameter key/value as string map.
virtual double Evaluate()
Evaluate unweighted energy term.
virtual void Initialize()
Initialize distance measure after input and parameters were set.
virtual bool SetWithoutPrefix(const char *, const char *)
Set parameter value from string.