SurfaceDistance.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_SurfaceDistance_H
21 #define MIRTK_SurfaceDistance_H
22 
23 #include "mirtk/PointSetDistance.h"
24 
25 #include "mirtk/Array.h"
26 
27 
28 namespace mirtk {
29 
30 
31 /**
32  * Base class for point set surface distance measures
33  *
34  * Subclasses of this base class are evaluating the distance of the surfaces
35  * of the input point sets. Note that also other, more generic, point set
36  * distance types which are subclasses of PointSetDistance may be used
37  * for surface meshes as well, given that the input point sets are surfaces.
38  */
40 {
41  mirtkAbstractMacro(SurfaceDistance);
42 
43  // ---------------------------------------------------------------------------
44  // Construction/Destruction
45 
46 protected:
47 
48  /// Constructor
49  SurfaceDistance(const char * = "", double = 1.0);
50 
51  /// Copy constructor
52  SurfaceDistance(const SurfaceDistance &, int = -1, int = -1);
53 
54  /// Assignment operator
56 
57  /// Copy attributes of surface distance term
58  void CopyAttributes(const SurfaceDistance &, int = -1, int = -1);
59 
60 public:
61 
62  /// Destructor
63  virtual ~SurfaceDistance();
64 
65  // ---------------------------------------------------------------------------
66  // Initialization
67 
68  /// Initialize distance measure once input and parameters have been set
69  virtual void Initialize();
70 
71  /// Reinitialize distance measure after change of input topology
72  ///
73  /// This function is called in particular when an input surface has been
74  /// reparameterized, e.g., by a local remeshing filter.
75  virtual void Reinitialize();
76 
77  // ---------------------------------------------------------------------------
78  // Evaluation
79 
80 protected:
81 
82  /// Convert non-parametric gradient of polydata distance measure into
83  /// gradient w.r.t transformation parameters
84  ///
85  /// This function calls Transformation::ParametricGradient of the
86  /// transformation to apply the chain rule in order to obtain the gradient
87  /// of the distance measure w.r.t the transformation parameters.
88  /// It adds the weighted gradient to the final registration energy gradient.
89  ///
90  /// \param[in] target Transformed data set.
91  /// \param[in] np_gradient Point-wise non-parametric gradient.
92  /// \param[in,out] gradient Gradient to which the computed parametric gradient
93  /// is added, after multiplication by the given \p weight.
94  /// \param[in] weight Weight of polydata distance measure.
95  virtual void ParametricGradient(const RegisteredPointSet *target,
96  const GradientType *np_gradient,
97  double *gradient,
98  double weight);
99 
100  // ---------------------------------------------------------------------------
101  // Debugging
102 
103 public:
104 
105  /// Write input of data fidelity term
106  virtual void WriteDataSets(const char *, const char *, bool = true) const;
107 
108  // Import public overload
110 
111 protected:
112 
113  /// Write gradient of data fidelity term w.r.t each transformed input
114  virtual void WriteGradient(const char *,
115  const RegisteredPointSet *,
116  const GradientType *,
117  const Array<int> * = NULL) const;
118 
119 };
120 
121 
122 } // namespace mirtk
123 
124 #endif // MIRTK_SurfaceDistance_H
virtual void Reinitialize()
virtual void WriteGradient(const char *, const RegisteredPointSet *, const GradientType *, const Array< int > *=NULL) const
Write gradient of data fidelity term w.r.t each transformed input.
virtual void WriteGradient(const char *, const char *) const
Write gradient of data fidelity term w.r.t each transformed input.
virtual void ParametricGradient(const RegisteredPointSet *target, const GradientType *np_gradient, double *gradient, double weight)
virtual void Initialize()
Initialize distance measure once input and parameters have been set.
SurfaceDistance & operator=(const SurfaceDistance &)
Assignment operator.
Definition: IOConfig.h:41
SurfaceDistance(const char *="", double=1.0)
Constructor.
void CopyAttributes(const SurfaceDistance &, int=-1, int=-1)
Copy attributes of surface distance term.
virtual void WriteDataSets(const char *, const char *, bool=true) const
Write input of data fidelity term.
virtual ~SurfaceDistance()
Destructor.