RegistrationFilter.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_RegistrationFilter_H
21 #define MIRTK_RegistrationFilter_H
22 
23 #include "mirtk/Observable.h"
24 
25 
26 namespace mirtk {
27 
28 
29 // Forward declaration of output type
30 class Transformation;
31 
32 
33 /**
34  * Base class for registration filters
35  *
36  * \code
37  * MyRegistrationFilter registration;
38  * Transformation *transformation = NULL;
39  * registration.Input(...);
40  * registration.Output(&transformation);
41  * registration.Read(config_file);
42  * registration.Run();
43  * \endcode
44  */
46 {
47  mirtkAbstractMacro(RegistrationFilter);
48 
49 private:
50 
51  /// Pointer to output transformation
52  Transformation **_Output;
53 
54 private:
55 
56  /// Copy constructor
57  /// \note Intentionally not implemented
59 
60  /// Assignment operator
61  /// \note Intentionally not implemented
62  void operator =(const RegistrationFilter &);
63 
64 protected:
65 
66  /// Constructor
68 
69 public:
70 
71  /// Destructor
72  virtual ~RegistrationFilter() = 0;
73 
74  /// Read registration parameters from input stream
75  virtual bool Read(const char *, bool = false);
76 
77  /// Read registration parameters from input stream
78  virtual bool Read(istream &, bool = false) = 0;
79 
80  /// Write registration parameters to file
81  virtual void Write(const char *) const = 0;
82 
83  /// Runs the registration filter
84  virtual void Run() = 0;
85 
86  /// Set pointer to output transformation
87  void Output(Transformation **);
88 
89  /// Get output transformation
91 
92 protected:
93 
94  /// Set current output transformation
95  bool Output(Transformation *);
96 
97 };
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 // Inline definitions
101 ////////////////////////////////////////////////////////////////////////////////
102 
103 // -----------------------------------------------------------------------------
105 {
106 }
107 
108 // -----------------------------------------------------------------------------
110 {
111 }
112 
113 // -----------------------------------------------------------------------------
114 inline bool RegistrationFilter::Read(const char *fname, bool echo)
115 {
116  ifstream from(fname);
117  if (!from) return false;
118  bool ok = this->Read(from, echo);
119  from.close();
120  return ok;
121 }
122 
123 // -----------------------------------------------------------------------------
125 {
126  _Output = output;
127 }
128 
129 // -----------------------------------------------------------------------------
131 {
132  if (_Output) {
133  (*_Output) = output;
134  return true;
135  }
136  return false;
137 }
138 
139 // -----------------------------------------------------------------------------
141 {
142  return _Output ? *_Output : NULL;
143 }
144 
145 
146 } // namespace mirtk
147 
148 #endif // MIRTK_RegistrationFilter_H
virtual ~RegistrationFilter()=0
Destructor.
Definition: IOConfig.h:41
virtual void Write(const char *) const =0
Write registration parameters to file.
virtual bool Read(const char *, bool=false)
Read registration parameters from input stream.
Transformation * Output()
Get output transformation.
virtual void Run()=0
Runs the registration filter.