ITK  4.3.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:
36  virtual ~ImageSeriesWriterException() throw( ) {};
37 
40 
42  ImageSeriesWriterException(char *file, unsigned int line,
43  const char *message = "Error in IO"):
44  ExceptionObject(file, line)
45  {
46  SetDescription(message);
47  }
48 
50  ImageSeriesWriterException(const std::string & file, unsigned int line,
51  const char *message = "Error in IO"):
52  ExceptionObject(file, line)
53  {
54  SetDescription(message);
55  }
56 };
58 
81 template< class TInputImage, class TOutputImage >
82 class ITK_EXPORT ImageSeriesWriter:public ProcessObject
83 {
84 public:
90 
92  itkNewMacro(Self);
93 
96 
98  typedef TInputImage InputImageType;
99  typedef typename InputImageType::RegionType InputImageRegionType;
100  typedef TOutputImage OutputImageType;
101  typedef typename OutputImageType::RegionType OutputImageRegionType;
103  typedef std::vector< std::string > FileNamesContainer;
104 
108  typedef std::vector< DictionaryRawPointer > DictionaryArrayType;
110 
112  using Superclass::SetInput;
113  void SetInput(const InputImageType *input);
114 
115  const InputImageType * GetInput(void);
116 
117  const InputImageType * GetInput(unsigned int idx);
118 
125  itkSetObjectMacro(ImageIO, ImageIOBase);
126  itkGetObjectMacro(ImageIO, ImageIOBase);
128 
133  virtual void Write(void);
134 
137  virtual void Update()
138  {
139  this->Write();
140  }
141 
144  itkSetMacro(StartIndex, SizeValueType);
145  itkGetConstMacro(StartIndex, SizeValueType);
147 
150  itkSetMacro(IncrementIndex, SizeValueType);
151  itkGetConstMacro(IncrementIndex, SizeValueType);
153 
158  itkSetStringMacro(SeriesFormat);
159  itkGetStringMacro(SeriesFormat);
161 
164  void SetFileNames(const FileNamesContainer & name)
165  {
166  if ( m_FileNames != name )
167  {
168  m_FileNames = name;
169  this->Modified();
170  }
171  }
173 
174  const FileNamesContainer & GetFileNames() const
175  {
176  return m_FileNames;
177  }
178 
181  void SetFileName(std::string const & name)
182  {
183  m_FileNames.clear();
184  m_FileNames.push_back(name);
185  this->Modified();
186  }
188 
191  void AddFileName(std::string const & name)
192  {
193  m_FileNames.push_back(name);
194  this->Modified();
195  }
197 
200  itkSetMacro(MetaDataDictionaryArray, DictionaryArrayRawPointer);
201 
203  itkSetMacro(UseCompression, bool);
204  itkGetConstReferenceMacro(UseCompression, bool);
205  itkBooleanMacro(UseCompression);
207 
208 protected:
211  void PrintSelf(std::ostream & os, Indent indent) const;
212 
214  void GenerateData(void);
215 
218  void GenerateNumericFileNamesAndWrite(void);
219 
221 
222  //track whether the ImageIO is user specified
224 
225 private:
226  ImageSeriesWriter(const Self &); //purposely not implemented
227  void operator=(const Self &); //purposely not implemented
228 
231 
237  std::string m_SeriesFormat;
240 
242 
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(void);
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
260