ITK  5.0.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  ~ImageSeriesWriterException() noexcept 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 ITK_TEMPLATE_EXPORT ImageSeriesWriter:public ProcessObject
84 {
85 public:
86  ITK_DISALLOW_COPY_AND_ASSIGN(ImageSeriesWriter);
87 
93 
95  itkNewMacro(Self);
96 
98  itkTypeMacro(ImageSeriesWriter, ProcessObject);
99 
101  using InputImageType = TInputImage;
103  using OutputImageType = TOutputImage;
106  using FileNamesContainer = std::vector< std::string >;
107 
111  using DictionaryArrayType = std::vector< DictionaryRawPointer >;
113 
115  using Superclass::SetInput;
116  void SetInput(const InputImageType *input);
117 
118  const InputImageType * GetInput();
119 
120  const InputImageType * GetInput(unsigned int idx);
121 
128  itkSetObjectMacro(ImageIO, ImageIOBase);
129  itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
131 
136  virtual void Write();
137 
140  void Update() override
141  {
142  this->Write();
143  }
144 
147  itkSetMacro(StartIndex, SizeValueType);
148  itkGetConstMacro(StartIndex, SizeValueType);
150 
153  itkSetMacro(IncrementIndex, SizeValueType);
154  itkGetConstMacro(IncrementIndex, SizeValueType);
156 
161  itkSetStringMacro(SeriesFormat);
162  itkGetStringMacro(SeriesFormat);
164 
167  void SetFileNames(const FileNamesContainer & name)
168  {
169  if ( m_FileNames != name )
170  {
171  m_FileNames = name;
172  this->Modified();
173  }
174  }
176 
178  {
179  return m_FileNames;
180  }
181 
184  void SetFileName(std::string const & name)
185  {
186  m_FileNames.clear();
187  m_FileNames.push_back(name);
188  this->Modified();
189  }
191 
194  void AddFileName(std::string const & name)
195  {
196  m_FileNames.push_back(name);
197  this->Modified();
198  }
200 
203  itkSetMacro(MetaDataDictionaryArray, DictionaryArrayRawPointer);
204 
206  itkSetMacro(UseCompression, bool);
207  itkGetConstReferenceMacro(UseCompression, bool);
208  itkBooleanMacro(UseCompression);
210 
211 protected:
213  ~ImageSeriesWriter() override = default;
214  void PrintSelf(std::ostream & os, Indent indent) const override;
215 
217  void GenerateData() override;
218 
221  void GenerateNumericFileNamesAndWrite();
222 
224 
225  //track whether the ImageIO is user specified
226  bool m_UserSpecifiedImageIO{false};
227 
228 private:
231 
237  std::string m_SeriesFormat;
238  SizeValueType m_StartIndex{1};
239  SizeValueType m_IncrementIndex{1};
240 
242 
244  DictionaryArrayRawPointer m_MetaDataDictionaryArray{nullptr};
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)
Light weight base class for most itk classes.
const FileNamesContainer & GetFileNames() const
typename OutputImageType::RegionType OutputImageRegionType
Abstract superclass defines image IO interface.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
ImageSeriesWriterException(char *file, unsigned int line, const char *message="Error in IO")
FileNamesContainer m_FileNames
const DictionaryArrayType * DictionaryArrayRawPointer
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:40
void SetFileName(std::string const &name)
std::vector< std::string > FileNamesContainer
std::vector< DictionaryRawPointer > DictionaryArrayType
Provides a mechanism for storing a collection of arbitrary data types.
ImageIOBase::Pointer m_ImageIO
Standard exception handling object.
typename InputImageType::RegionType InputImageRegionType
Writes image data to a single file.
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.
Base exception class for IO problems during writing.