ImageWriter.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_ImageWriter_H
21 #define MIRTK_ImageWriter_H
22 
23 #include "mirtk/Cofstream.h"
24 #include "mirtk/BaseImage.h"
25 
26 
27 namespace mirtk {
28 
29 
30 /**
31  * Abstract base class for any general image to file 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 file as output.
35  * Each derived class has to implement all of the abstract member functions.
36  */
37 class ImageWriter : protected Cofstream
38 {
39  mirtkAbstractMacro(ImageWriter);
40 
41  // ---------------------------------------------------------------------------
42  // Attributes
43 
44  /// Input image
45  mirtkPublicAggregateMacro(const BaseImage, Input);
46 
47  /// Output file name
48  mirtkPublicAttributeMacro(string, FileName);
49 
50 protected:
51 
52  /// Start address of the data in the image file.
53  /// Should be initialized by overridden Initialize() function.
54  int _Start;
55 
56  /// Flag whether to reflect X axis
57  int _ReflectX;
58 
59  /// Flag whether to reflect Y axis
60  int _ReflectY;
61 
62  /// Flag whether to reflect Z axis
63  int _ReflectZ;
64 
65  // ---------------------------------------------------------------------------
66  // Construction/Destruction
67 
68  /// Constructor
69  ImageWriter();
70 
71 public:
72 
73  /// Destructor
74  virtual ~ImageWriter();
75 
76  /// Static constructor. This constructor allocates a derived class which
77  /// can be used to write the image file in a format corresponding to the
78  /// given file name extension.
79  static ImageWriter *New(const char *);
80 
81  // ---------------------------------------------------------------------------
82  // Execution
83 
84  /// Write image
85  virtual void Run();
86 
87 protected:
88 
89  /// Initialize filter
90  virtual void Initialize();
91 
92  /// Finalize filter
93  virtual void Finalize();
94 
95 };
96 
97 
98 } // namespace mirtk
99 
100 #endif // MIRTK_ImageWriter_H
string FileName(const char *, ExtensionMode=EXT_Default)
Get file name of file path excl. file extension.
static ImageWriter * New(const char *)
int _ReflectZ
Flag whether to reflect Z axis.
Definition: ImageWriter.h:63
int _ReflectY
Flag whether to reflect Y axis.
Definition: ImageWriter.h:60
virtual ~ImageWriter()
Destructor.
virtual void Run()
Write image.
ImageWriter()
Constructor.
Definition: IOConfig.h:41
virtual void Initialize()
Initialize filter.
virtual void Finalize()
Finalize filter.
int _ReflectX
Flag whether to reflect X axis.
Definition: ImageWriter.h:57