ImageReader.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_ImageReader_H
21 #define MIRTK_ImageReader_H
22 
23 #include "mirtk/Cifstream.h"
24 #include "mirtk/ImageAttributes.h"
25 #include "mirtk/BaseImage.h"
26 
27 
28 namespace mirtk {
29 
30 
31 /**
32  * Abstract base class for any general file to image filter.
33  *
34  * This is the abstract base class which defines a common interface for all
35  * filters which take a filename (referrencing an image file) as input and
36  * produce an image as output. For each file format a derived class should
37  * be created. Each derived class has to implement abstract member functions
38  * ReadHeader() and CheckHeader().
39  */
40 class ImageReader : protected Cifstream
41 {
42  mirtkAbstractMacro(ImageReader);
43 
44  /// Path/name of image file
45  mirtkPublicAttributeMacro(string, FileName);
46 
47  /// Image attributes
48  mirtkReadOnlyAttributeMacro(ImageAttributes, Attributes);
49 
50  /// Type of voxels
51  mirtkReadOnlyAttributeMacro(int, DataType);
52 
53  /// No. of bytes per voxel
54  mirtkReadOnlyAttributeMacro(int, Bytes);
55 
56  /// Intensity scaling parameter - slope (default: 1)
57  mirtkReadOnlyAttributeMacro(double, Slope);
58 
59  /// Intensity scaling parameter - intercept (default: 0)
60  mirtkReadOnlyAttributeMacro(double, Intercept);
61 
62 protected:
63 
64  /// Flag whether to reflect X axis
65  int _ReflectX;
66 
67  /// Flag whether to reflect Y axis
68  int _ReflectY;
69 
70  /// Flag whether to reflect Z axis
71  int _ReflectZ;
72 
73  /// Start of image data
74  int _Start;
75 
76  // ---------------------------------------------------------------------------
77  // Construction/Destruction
78 public:
79 
80  /// Contructor
81  ImageReader();
82 
83  /// Destructor
84  virtual ~ImageReader();
85 
86  /// Static constructor. This constructor allocates a derived class which
87  /// is then used to read the image file. This involves checking the file
88  /// format of the file and dynamically allocating the corresonding derived
89  /// class. The reader instance must be deleted by the caller.
90  ///
91  /// \returns Image reader instance or \c nullptr.
92  static ImageReader *TryNew(const char *);
93 
94  /// Static constructor. This constructor allocates a derived class which
95  /// is then used to read the image file. This involves checking the file
96  /// format of the file and dynamically allocating the corresonding derived
97  /// class. The reader instance must be deleted by the caller.
98  static ImageReader *New(const char *);
99 
100  // ---------------------------------------------------------------------------
101  // Execution
102 
103  /// Check if this reader can read a given image file
104  virtual bool CanRead(const char *) const = 0;
105 
106  /// Open image file and read header information
107  virtual void Initialize();
108 
109  /// Print image header information
110  virtual void Print() const;
111 
112  /// Read image from file
113  ///
114  /// \returns Newly read image. Must be deleted by caller.
115  virtual BaseImage *Run();
116 
117 protected:
118 
119  /// Read header. This is an abstract function. Each derived class has to
120  /// implement this function in order to initialize the read-only attributes
121  /// of this class.
122  virtual void ReadHeader() = 0;
123 
124 };
125 
126 
127 } // namespace mirtk
128 
129 #endif // MIRTK_ImageReader_H
string FileName(const char *, ExtensionMode=EXT_Default)
Get file name of file path excl. file extension.
virtual BaseImage * Run()
int _ReflectZ
Flag whether to reflect Z axis.
Definition: ImageReader.h:71
static ImageReader * New(const char *)
virtual ~ImageReader()
Destructor.
virtual void Print() const
Print image header information.
int _ReflectY
Flag whether to reflect Y axis.
Definition: ImageReader.h:68
Definition: IOConfig.h:41
ImageReader()
Contructor.
int _Start
Start of image data.
Definition: ImageReader.h:74
static ImageReader * TryNew(const char *)
int _ReflectX
Flag whether to reflect X axis.
Definition: ImageReader.h:65
virtual void Initialize()
Open image file and read header information.
virtual bool CanRead(const char *) const =0
Check if this reader can read a given image file.
virtual void ReadHeader()=0