ITK  4.2.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 
21 #include "itkImageRegion.h"
22 #include "itkImageFileWriter.h"
23 #include <vector>
24 #include <string>
25 
26 namespace itk
27 {
32 class ITK_ABI_EXPORT ImageSeriesWriterException:public ExceptionObject
33 {
34 public:
37 
39  ImageSeriesWriterException(char *file, unsigned int line,
40  const char *message = "Error in IO"):
41  ExceptionObject(file, line)
42  {
43  SetDescription(message);
44  }
45 
47  ImageSeriesWriterException(const std::string & file, unsigned int line,
48  const char *message = "Error in IO"):
49  ExceptionObject(file, line)
50  {
51  SetDescription(message);
52  }
53 };
55 
78 template< class TInputImage, class TOutputImage >
79 class ITK_EXPORT ImageSeriesWriter:public ProcessObject
80 {
81 public:
87 
89  itkNewMacro(Self);
90 
93 
95  typedef TInputImage InputImageType;
96  typedef typename InputImageType::RegionType InputImageRegionType;
97  typedef TOutputImage OutputImageType;
98  typedef typename OutputImageType::RegionType OutputImageRegionType;
100  typedef std::vector< std::string > FileNamesContainer;
101 
105  typedef std::vector< DictionaryRawPointer > DictionaryArrayType;
107 
109  using Superclass::SetInput;
110  void SetInput(const InputImageType *input);
111 
112  const InputImageType * GetInput(void);
113 
114  const InputImageType * GetInput(unsigned int idx);
115 
122  itkSetObjectMacro(ImageIO, ImageIOBase);
123  itkGetObjectMacro(ImageIO, ImageIOBase);
125 
130  virtual void Write(void);
131 
134  virtual void Update()
135  {
136  this->Write();
137  }
138 
141  itkSetMacro(StartIndex, SizeValueType);
142  itkGetConstMacro(StartIndex, SizeValueType);
144 
147  itkSetMacro(IncrementIndex, SizeValueType);
148  itkGetConstMacro(IncrementIndex, SizeValueType);
150 
155  itkSetStringMacro(SeriesFormat);
156  itkGetStringMacro(SeriesFormat);
158 
161  void SetFileNames(const FileNamesContainer & name)
162  {
163  if ( m_FileNames != name )
164  {
165  m_FileNames = name;
166  this->Modified();
167  }
168  }
170 
171  const FileNamesContainer & GetFileNames() const
172  {
173  return m_FileNames;
174  }
175 
178  void SetFileName(std::string const & name)
179  {
180  m_FileNames.clear();
181  m_FileNames.push_back(name);
182  this->Modified();
183  }
185 
188  void AddFileName(std::string const & name)
189  {
190  m_FileNames.push_back(name);
191  this->Modified();
192  }
194 
197  itkSetMacro(MetaDataDictionaryArray, DictionaryArrayRawPointer);
198 
200  itkSetMacro(UseCompression, bool);
201  itkGetConstReferenceMacro(UseCompression, bool);
202  itkBooleanMacro(UseCompression);
203 protected:
206  void PrintSelf(std::ostream & os, Indent indent) const;
208 
210  void GenerateData(void);
211 
214  void GenerateNumericFileNamesAndWrite(void);
215 
217 
218  //track whether the ImageIO is user specified
220 private:
221  ImageSeriesWriter(const Self &); //purposely not implemented
222  void operator=(const Self &); //purposely not implemented
223 
226 
232  std::string m_SeriesFormat;
235 
237 
240 
241  // These two methods provide now a common implementation for the
242  // GenerateNumericFileNamesAndWrite() and avoid the duplication of code that
243  // was leaving one of the code branches out of date.
244  void GenerateNumericFileNames(void);
245 
246  void WriteFiles();
247 };
248 } // end namespace itk
249 
250 #ifndef ITK_MANUAL_INSTANTIATION
251 #include "itkImageSeriesWriter.hxx"
252 #endif
253 
254 #endif // __itkImageSeriesWriter_h
255