ImageToImage.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2008-2015 Imperial College London
5  * Copyright 2008-2015 Daniel Rueckert, Julia Schnabel
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_ImageToImage_H
21 #define MIRTK_ImageToImage_H
22 
23 #include "mirtk/Object.h"
24 #include "mirtk/GenericImage.h"
25 
26 
27 namespace mirtk {
28 
29 
30 /**
31  * Abstract base class for any general image to image filter.
32  *
33  * This is the abstract base class which defines a common interface for all
34  * filters which take an image as input and produce an image as output. Each
35  * derived class has to implement all abstract member functions.
36  */
37 template <class TVoxel>
38 class ImageToImage : public Object
39 {
40  mirtkAbstractMacro(ImageToImage);
41 
42  // ---------------------------------------------------------------------------
43  // Types
44 
45 public:
46 
47  /// Input/output image voxel type
48  typedef TVoxel VoxelType;
49 
50  /// Input/output image type
52 
53  // ---------------------------------------------------------------------------
54  // Attributes
55 
56 protected:
57 
58  /// Input image for filter
59  mirtkPublicAggregateMacro(const ImageType, Input);
60 
61  /// Output image for filter
62  mirtkPublicAggregateMacro(ImageType, Output);
63 
64  /// Buffer
65  mirtkAggregateMacro(ImageType, Buffer);
66 
67  // ---------------------------------------------------------------------------
68  // Construction/Destruction
69 
70 public:
71 
72  /// Constructor
73  ImageToImage();
74 
75  /// Destructor
76  virtual ~ImageToImage();
77 
78  // ---------------------------------------------------------------------------
79  // Evaluation
80 
81 protected:
82 
83  /// Initialize the filter. This function must be called by any derived
84  /// filter class to perform some initialize tasks.
85  void Initialize(bool);
86 
87  /// Initialize the filter. This function must be called by any derived
88  /// filter class to perform some initialize tasks.
89  virtual void Initialize();
90 
91  /// Finalize the filter. This function must be called by any derived
92  /// filter class to perform some initialize tasks.
93  virtual void Finalize();
94 
95 public:
96 
97  /// Run filter on entire image
98  virtual void Run();
99 
100  /// Run filter on single voxel
101  virtual double Run(int, int, int, int = 0);
102 
103  /// Returns whether the filter requires buffering. Any derived class must
104  /// implement this member function to indicate whether the filter should
105  /// buffer the input in case that input and output are equal. For example,
106  /// filters which only require the voxel value to calculate their output
107  /// should return false, otherwise true.
108  virtual bool RequiresBuffering() const;
109 
110 };
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 // Auxiliary macro for subclass implementation
114 ////////////////////////////////////////////////////////////////////////////////
115 
116 // -----------------------------------------------------------------------------
117 #define mirtkDefineImageFilterTypesMacro(voxeltype) \
118  public: \
119  /** Type of image filter base class */ \
120  typedef mirtk::ImageToImage<voxeltype> Baseclass; \
121  /** Input/output image voxel type */ \
122  typedef typename Baseclass::VoxelType VoxelType; \
123  /** Input/output image type */ \
124  typedef typename Baseclass::ImageType ImageType; \
125  private:
126 
127 // -----------------------------------------------------------------------------
128 #define mirtkAbstractImageFilterMacro(clsname, voxeltype) \
129  mirtkAbstractMacro(clsname); \
130  mirtkDefineImageFilterTypesMacro(voxeltype); \
131  public: \
132  typedef clsname<voxeltype> Superclass; \
133  private:
134 
135 // -----------------------------------------------------------------------------
136 #define mirtkImageFilterMacro(clsname, voxeltype) \
137  mirtkObjectMacro(clsname); \
138  mirtkDefineImageFilterTypesMacro(voxeltype); \
139  protected: \
140  /** Indicates that this filter cannot run in-place */ \
141  virtual bool RequiresBuffering() const { return true; } \
142  private:
143 
144 // -----------------------------------------------------------------------------
145 #define mirtkInPlaceImageFilterMacro(clsname, voxeltype) \
146  mirtkObjectMacro(clsname); \
147  mirtkDefineImageFilterTypesMacro(voxeltype); \
148  protected: \
149  /** Indicates that this filter can run in-place */ \
150  virtual bool RequiresBuffering() const { return false; } \
151  private:
152 
153 
154 } // namespace mirtk
155 
156 #endif // MIRTK_ImageToImage_H
virtual ~ImageToImage()
Destructor.
mirtkAggregateMacro(ImageType, Buffer)
Buffer.
virtual void Run()
Run filter on entire image.
Definition: IOConfig.h:41
GenericImage< VoxelType > ImageType
Input/output image type.
Definition: ImageToImage.h:51
virtual void Initialize()
ImageToImage()
Constructor.
TVoxel VoxelType
Input/output image voxel type.
Definition: ImageToImage.h:48
virtual bool RequiresBuffering() const
mirtkPublicAggregateMacro(const ImageType, Input)
Input image for filter.
virtual void Finalize()