ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkImageSeriesWriter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkImageSeriesWriter_h
19 #define itkImageSeriesWriter_h
20 #include "ITKIOImageBaseExport.h"
21 
22 #include "itkImageRegion.h"
23 #include "itkImageFileWriter.h"
24 #include <vector>
25 #include <string>
26 
27 namespace itk
28 {
33 class ITKIOImageBase_EXPORT ImageSeriesWriterException:public ExceptionObject
34 {
35 public:
37  virtual ~ImageSeriesWriterException() ITK_NOEXCEPT ITK_OVERRIDE;
38 
41 
43  ImageSeriesWriterException(char *file, unsigned int line,
44  const char *message = "Error in IO"):
45  ExceptionObject(file, line)
46  {
47  SetDescription(message);
48  }
49 
51  ImageSeriesWriterException(const std::string & file, unsigned int line,
52  const char *message = "Error in IO"):
53  ExceptionObject(file, line)
54  {
55  SetDescription(message);
56  }
57 };
59 
82 template< typename TInputImage, typename TOutputImage >
83 class ITKIOImageBase_HIDDEN ImageSeriesWriter:public ProcessObject
84 {
85 public:
91 
93  itkNewMacro(Self);
94 
97 
99  typedef TInputImage InputImageType;
100  typedef typename InputImageType::RegionType InputImageRegionType;
101  typedef TOutputImage OutputImageType;
102  typedef typename OutputImageType::RegionType OutputImageRegionType;
104  typedef std::vector< std::string > FileNamesContainer;
105 
109  typedef std::vector< DictionaryRawPointer > DictionaryArrayType;
111 
113  using Superclass::SetInput;
114  void SetInput(const InputImageType *input);
115 
116  const InputImageType * GetInput();
117 
118  const InputImageType * GetInput(unsigned int idx);
119 
126  itkSetObjectMacro(ImageIO, ImageIOBase);
127  itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
129 
134  virtual void Write();
135 
138  virtual void Update() ITK_OVERRIDE
139  {
140  this->Write();
141  }
142 
145  itkSetMacro(StartIndex, SizeValueType);
146  itkGetConstMacro(StartIndex, SizeValueType);
148 
151  itkSetMacro(IncrementIndex, SizeValueType);
152  itkGetConstMacro(IncrementIndex, SizeValueType);
154 
159  itkSetStringMacro(SeriesFormat);
160  itkGetStringMacro(SeriesFormat);
162 
165  void SetFileNames(const FileNamesContainer & name)
166  {
167  if ( m_FileNames != name )
168  {
169  m_FileNames = name;
170  this->Modified();
171  }
172  }
174 
176  {
177  return m_FileNames;
178  }
179 
182  void SetFileName(std::string const & name)
183  {
184  m_FileNames.clear();
185  m_FileNames.push_back(name);
186  this->Modified();
187  }
189 
192  void AddFileName(std::string const & name)
193  {
194  m_FileNames.push_back(name);
195  this->Modified();
196  }
198 
201  itkSetMacro(MetaDataDictionaryArray, DictionaryArrayRawPointer);
202 
204  itkSetMacro(UseCompression, bool);
205  itkGetConstReferenceMacro(UseCompression, bool);
206  itkBooleanMacro(UseCompression);
208 
209 protected:
211  ~ImageSeriesWriter() ITK_OVERRIDE;
212  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
213 
215  virtual void GenerateData(void) ITK_OVERRIDE;
216 
219  void GenerateNumericFileNamesAndWrite();
220 
221  ImageIOBase::Pointer m_ImageIO;
222 
223  //track whether the ImageIO is user specified
224  bool m_UserSpecifiedImageIO;
225 
226 private:
227  ITK_DISALLOW_COPY_AND_ASSIGN(ImageSeriesWriter);
228 
230  FileNamesContainer m_FileNames;
231 
237  std::string m_SeriesFormat;
238  SizeValueType m_StartIndex;
239  SizeValueType m_IncrementIndex;
240 
241  bool m_UseCompression;
242 
244  DictionaryArrayRawPointer m_MetaDataDictionaryArray;
245 
246  // These two methods provide now a common implementation for the
247  // GenerateNumericFileNamesAndWrite() and avoid the duplication of code that
248  // was leaving one of the code branches out of date.
249  void GenerateNumericFileNames();
250 
251  void WriteFiles();
252 };
253 } // end namespace itk
254 
255 #ifndef ITK_MANUAL_INSTANTIATION
256 #include "itkImageSeriesWriter.hxx"
257 #endif
258 
259 #endif // itkImageSeriesWriter_h
void AddFileName(std::string const &name)
MetaDataDictionary DictionaryType
Light weight base class for most itk classes.
SmartPointer< Self > Pointer
const FileNamesContainer & GetFileNames() const
std::vector< std::string > FileNamesContainer
ImageFileWriter< TOutputImage > WriterType
Abstract superclass defines image IO interface.
ImageSeriesWriterException(char *file, unsigned int line, const char *message="Error in IO")
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
unsigned long SizeValueType
Definition: itkIntTypes.h:143
void SetFileName(std::string const &name)
Provides a mechanism for storing a collection of arbitrary data types.
virtual void Update() override
Standard exception handling object.
OutputImageType::RegionType OutputImageRegionType
MetaDataDictionary * DictionaryRawPointer
Writes image data to a single file.
InputImageType::RegionType InputImageRegionType
SmartPointer< const Self > ConstPointer
void SetFileNames(const FileNamesContainer &name)
ImageSeriesWriterException(const std::string &file, unsigned int line, const char *message="Error in IO")
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Writes image data to a series of data files.
std::vector< DictionaryRawPointer > DictionaryArrayType
Base exception class for IO problems during writing.
const DictionaryArrayType * DictionaryArrayRawPointer