-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathitkDeformationFieldWriter.h
executable file
·196 lines (161 loc) · 6.91 KB
/
itkDeformationFieldWriter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkDeformationFieldWriter.h,v $
Language: C++
Date: $$
Version: $ $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __itkDeformationFieldWriter_h
#define __itkDeformationFieldWriter_h
#include "itkProcessObject.h"
#include "itkImageIOBase.h"
#include "itkExceptionObject.h"
#include "itkSize.h"
#include "itkImageIORegion.h"
namespace itk
{
/** \brief Base exception class for IO problems during writing. */
class DeformationFieldWriterException : public ExceptionObject
{
public:
/** Run-time information. */
itkTypeMacro( DeformationFieldWriterException, ExceptionObject );
/** Constructor. */
DeformationFieldWriterException(const char *file, unsigned int line,
const char* message = "Error in IO",
const char* loc = "Unknown" ) :
ExceptionObject(file, line, message, loc)
{
}
/** Constructor. */
DeformationFieldWriterException(const std::string &file, unsigned int line,
const char* message = "Error in IO",
const char* loc = "Unknown" ) :
ExceptionObject(file, line, message, loc)
{
}
};
/** \class DeformationFieldWriter
* \brief Writes the deformation field as component images files.
*
* \sa DeformationFieldWriter
* \sa ImageSeriesReader
* \sa ImageIOBase
*
* \ingroup IOFilters
*/
template <class TDeformationField, class TImage>
class ITK_EXPORT DeformationFieldWriter :
public ProcessObject
{
public:
/** Standard class typedefs. */
typedef DeformationFieldWriter Self;
typedef ProcessObject Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(DeformationFieldWriter, DeformationFieldWriter);
/** Some convenient typedefs. */
typedef TDeformationField DeformationFieldType;
typedef typename DeformationFieldType::Pointer DeformationFieldPointer;
typedef typename DeformationFieldType::RegionType DeformationFieldRegionType;
typedef typename DeformationFieldType::PixelType DeformationFieldPixelType;
typedef TImage ImageType;
typedef typename ImageType::Pointer ImagePointer;
typedef typename ImageType::RegionType ImageRegionType;
typedef typename ImageType::PixelType ImagePixelType;
/** Set/Get the image input of this writer. */
void SetInput(const DeformationFieldType *input);
const DeformationFieldType * GetInput(void);
const DeformationFieldType * GetInput(unsigned int idx);
/** Specify the name of the output file to write. */
itkSetStringMacro(FileName);
itkGetStringMacro(FileName);
/** Set/Get the ImageIO helper class. Usually this is created via the object
* factory mechanism that determines whether a particular ImageIO can
* write a certain file. This method provides a way to get the ImageIO
* instance that is created, or one can be manually set where the
* IO factory mechanism may not work (for example, raw image files or
* image files with non-standard filename suffix's.
* If the user specifies the ImageIO, we assume she makes the
* correct choice and will allow a file to be created regardless of
* the file extension. If the factory has set the ImageIO, the
* extension must be supported by the specified ImageIO. */
void SetImageIO (ImageIOBase* io)
{
if (this->m_ImageIO != io)
{
this->Modified();
this->m_ImageIO = io;
}
m_FactorySpecifiedImageIO = false;
}
itkGetObjectMacro(ImageIO,ImageIOBase);
/** A special version of the Update() method for writers. It
* invokes start and end events and handles releasing data. It
* eventually calls GenerateData() which does the actual writing.
* Note: the write method will write data specified by the
* IORegion. If not set, then then the whole image is written. Note
* that the region will be cropped to fit the input image's
* LargestPossibleRegion. */
virtual void Write(void);
/** Specify the region to write. If left NULL, then the whole image
* is written. */
void SetIORegion(const ImageIORegion & region);
itkGetConstReferenceMacro( IORegion, ImageIORegion );
/** Aliased to the Write() method to be consistent with the rest of the
* pipeline. */
virtual void Update()
{this->Write();}
/** Set the compression On or Off */
itkSetMacro(UseCompression,bool);
itkGetConstReferenceMacro(UseCompression,bool);
itkBooleanMacro(UseCompression);
/** Set the Avants' naming convention On or Off */
itkSetMacro(UseAvantsNamingConvention,bool);
itkGetConstReferenceMacro(UseAvantsNamingConvention,bool);
itkBooleanMacro(UseAvantsNamingConvention);
/** By default the MetaDataDictionary is taken from the input image and
* passed to the ImageIO. In some cases, however, a user may prefer to
* introduce her/his own MetaDataDictionary. This is often the case of
* the ImageSeriesWriter. This flag defined whether the MetaDataDictionary
* to use will be the one from the input image or the one already set in
* the ImageIO object. */
itkSetMacro(UseInputMetaDataDictionary,bool);
itkGetConstReferenceMacro(UseInputMetaDataDictionary,bool);
itkBooleanMacro(UseInputMetaDataDictionary);
protected:
DeformationFieldWriter();
~DeformationFieldWriter();
void PrintSelf(std::ostream& os, Indent indent) const;
/** Does the real work. */
void GenerateData(void);
private:
DeformationFieldWriter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
std::string m_FileName;
std::string m_ComponentImageFileName;
bool m_UseAvantsNamingConvention;
ImagePointer m_Image;
ImageIOBase::Pointer m_ImageIO;
bool m_UserSpecifiedImageIO; //track whether the ImageIO is user specified
ImageIORegion m_IORegion;
bool m_UserSpecifiedIORegion; //
//track whether the region is user specified
bool m_FactorySpecifiedImageIO; //track whether the factory mechanism set the ImageIO
bool m_UseCompression;
bool m_UseInputMetaDataDictionary; // whether to use the MetaDataDictionary from the input or not.
};
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkDeformationFieldWriter.hxx"
#endif
#endif // __itkDeformationFieldWriter_h