TransformationConstraint.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_TransformationConstraint_H
21 #define MIRTK_TransformationConstraint_H
22 
23 #include "mirtk/EnergyTerm.h"
24 #include "mirtk/ConstraintMeasure.h"
25 #include "mirtk/ImageAttributes.h"
26 #include "mirtk/FreeFormTransformation.h"
27 #include "mirtk/MultiLevelTransformation.h"
28 
29 
30 namespace mirtk {
31 
32 
33 /**
34  * Base class for a penalty term imposed on a transformation
35  *
36  * The penalty is minimized by the registration using an instance of
37  * RegistrationEnergy with set data similarity and regularization terms.
38  * Higher penalties lead to stronger enforcement of the constraint.
39  */
41 {
42  mirtkAbstractMacro(TransformationConstraint);
43 
44  /// Image domain on which penalty is applied
45  mirtkPublicAttributeMacro(ImageAttributes, Domain);
46 
47  /// Whether to apply constraint also at passive DoFs (control points)
48  mirtkPublicAttributeMacro(bool, ConstrainPassiveDoFs);
49 
50  // ---------------------------------------------------------------------------
51  // Construction/Destruction
52 protected:
53 
54  /// Constructor
55  TransformationConstraint(const char * = "", double = 1.0);
56 
57  /// Copy constructor
59 
60  /// Assignment operator
62 
63 public:
64 
65  /// Instantiate new transformation constraint of given kind
67  const char * = "", double = 1.0);
68 
69  /// Destructor
70  virtual ~TransformationConstraint();
71 
72  // ---------------------------------------------------------------------------
73  // Configuration
74 
75 protected:
76 
77  /// Set parameter value from string
78  virtual bool SetWithPrefix(const char *, const char *);
79 
80  /// Set parameter value from string
81  virtual bool SetWithoutPrefix(const char *, const char *);
82 
83 public:
84 
85  // Import other overloads
87 
88  /// Get parameter name/value pairs
89  virtual ParameterList Parameter() const;
90 
91  // ---------------------------------------------------------------------------
92  // Subclass helper
93 protected:
94 
95  /// Get transformation as specific type or NULL if dynamic cast fails
96  template <class TransformationType>
97  const TransformationType *TransformationAs() const;
98 
99  /// Get transformation as free-form deformation or NULL if it is none
100  const FreeFormTransformation *FFD() const;
101 
102  /// Get transformation as multi-level transformation or NULL if it is none
103  const MultiLevelTransformation *MFFD() const;
104 
105  /// Write gradient of penalty term w.r.t. control point parameters
106  void WriteFFDGradient(const char *, const FreeFormTransformation *, const double *) const;
107 
108 };
109 
110 ////////////////////////////////////////////////////////////////////////////////
111 // Inline definitions
112 ////////////////////////////////////////////////////////////////////////////////
113 
114 // =============================================================================
115 // Subclass helper
116 // =============================================================================
117 
118 // -----------------------------------------------------------------------------
119 template <class TransformationType>
121 {
122  return dynamic_cast<const TransformationType *>(Transformation());
123 }
124 
125 // -----------------------------------------------------------------------------
127 {
128  return TransformationAs<FreeFormTransformation>();
129 }
130 
131 // -----------------------------------------------------------------------------
133 {
134  return TransformationAs<MultiLevelTransformation>();
135 }
136 
137 
138 } // namespace mirtk
139 
140 #endif // MIRTK_TransformationConstraint_H
virtual bool SetWithPrefix(const char *, const char *)
Set parameter value from string.
TransformationConstraint(const char *="", double=1.0)
Constructor.
virtual ~TransformationConstraint()
Destructor.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
const FreeFormTransformation * FFD() const
Get transformation as free-form deformation or NULL if it is none.
const MultiLevelTransformation * MFFD() const
Get transformation as multi-level transformation or NULL if it is none.
virtual ParameterList Parameter() const
Get parameter key/value as string map.
Definition: IOConfig.h:41
const TransformationType * TransformationAs() const
Get transformation as specific type or NULL if dynamic cast fails.
virtual ParameterList Parameter() const
Get parameter name/value pairs.
static TransformationConstraint * New(ConstraintMeasure, const char *="", double=1.0)
Instantiate new transformation constraint of given kind.
virtual bool SetWithoutPrefix(const char *, const char *)
Set parameter value from string.
TransformationConstraint & operator=(const TransformationConstraint &)
Assignment operator.
void WriteFFDGradient(const char *, const FreeFormTransformation *, const double *) const
Write gradient of penalty term w.r.t. control point parameters.