ITK  6.0.0
Insight Toolkit
itkImageSeriesWriter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 
40  itkOverrideGetNameOfClassMacro(ImageSeriesWriterException);
41 
43  ImageSeriesWriterException(char * file, unsigned int line, 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, const char * message = "Error in IO")
51  : ExceptionObject(file, line)
52  {
53  SetDescription(message);
54  }
55 };
84 template <typename TInputImage, typename TOutputImage>
85 class ITK_TEMPLATE_EXPORT ImageSeriesWriter : public ProcessObject
86 {
87 public:
88  ITK_DISALLOW_COPY_AND_MOVE(ImageSeriesWriter);
89 
95 
97  itkNewMacro(Self);
98 
100  itkOverrideGetNameOfClassMacro(ImageSeriesWriter);
101 
103  using InputImageType = TInputImage;
105  using OutputImageType = TOutputImage;
108  using FileNamesContainer = std::vector<std::string>;
109 
113  using DictionaryArrayType = std::vector<DictionaryRawPointer>;
115 
117  using Superclass::SetInput;
118  void
119  SetInput(const InputImageType * input);
120 
121  const InputImageType *
122  GetInput();
123 
124  const InputImageType *
125  GetInput(unsigned int idx);
126 
133  itkSetObjectMacro(ImageIO, ImageIOBase);
134  itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
141  virtual void
142  Write();
143 
146  void
147  Update() override
148  {
149  this->Write();
150  }
151 
154  itkSetMacro(StartIndex, SizeValueType);
155  itkGetConstMacro(StartIndex, SizeValueType);
160  itkSetMacro(IncrementIndex, SizeValueType);
161  itkGetConstMacro(IncrementIndex, SizeValueType);
168  itkSetStringMacro(SeriesFormat);
169  itkGetStringMacro(SeriesFormat);
174  void
176  {
177  if (m_FileNames != name)
178  {
179  m_FileNames = name;
180  this->Modified();
181  }
182  }
185  const FileNamesContainer &
186  GetFileNames() const
187  {
188  return m_FileNames;
189  }
190 
193  void
194  SetFileName(const std::string & name)
195  {
196  m_FileNames.clear();
197  m_FileNames.push_back(name);
198  this->Modified();
199  }
204  void
205  AddFileName(const std::string & name)
206  {
207  m_FileNames.push_back(name);
208  this->Modified();
209  }
214  itkSetMacro(MetaDataDictionaryArray, DictionaryArrayRawPointer);
215 
217  itkSetMacro(UseCompression, bool);
218  itkGetConstReferenceMacro(UseCompression, bool);
219  itkBooleanMacro(UseCompression);
222 protected:
224  ~ImageSeriesWriter() override = default;
225  void
226  PrintSelf(std::ostream & os, Indent indent) const override;
227 
229  void
230  GenerateData() override;
231 
234  void
235  GenerateNumericFileNamesAndWrite();
236 
237  ImageIOBase::Pointer m_ImageIO{};
238 
239  // track whether the ImageIO is user specified
240  bool m_UserSpecifiedImageIO{ false };
241 
242 private:
244  FileNamesContainer m_FileNames{};
245 
251  std::string m_SeriesFormat{};
252  SizeValueType m_StartIndex{ 1 };
253  SizeValueType m_IncrementIndex{ 1 };
254 
255  bool m_UseCompression{};
256 
258  DictionaryArrayRawPointer m_MetaDataDictionaryArray{ nullptr };
259 
260  // These two methods provide now a common implementation for the
261  // GenerateNumericFileNamesAndWrite() and avoid the duplication of code that
262  // was leaving one of the code branches out of date.
263  void
264  GenerateNumericFileNames();
265 
266  void
267  WriteFiles();
268 };
269 } // end namespace itk
270 
271 #ifndef ITK_MANUAL_INSTANTIATION
272 # include "itkImageSeriesWriter.hxx"
273 #endif
274 
275 #endif // itkImageSeriesWriter_h
itk::ImageIOBase
Abstract superclass defines image IO interface.
Definition: itkImageIOBase.h:77
itk::ImageSeriesWriterException::ImageSeriesWriterException
ImageSeriesWriterException(const std::string &file, unsigned int line, const char *message="Error in IO")
Definition: itkImageSeriesWriter.h:50
itk::ImageSeriesWriter::SetFileName
void SetFileName(const std::string &name)
Definition: itkImageSeriesWriter.h:194
itk::ImageSeriesWriterException::ImageSeriesWriterException
ImageSeriesWriterException(char *file, unsigned int line, const char *message="Error in IO")
Definition: itkImageSeriesWriter.h:43
itk::ImageSeriesWriter
Writes image data to a series of data files.
Definition: itkImageSeriesWriter.h:85
itk::ImageSeriesWriter::InputImageRegionType
typename InputImageType::RegionType InputImageRegionType
Definition: itkImageSeriesWriter.h:104
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkImageRegion.h
itk::ImageSeriesWriter::OutputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
Definition: itkImageSeriesWriter.h:106
itk::ImageSeriesWriter::AddFileName
void AddFileName(const std::string &name)
Definition: itkImageSeriesWriter.h:205
itk::MetaDataDictionary
Provides a mechanism for storing a collection of arbitrary data types.
Definition: itkMetaDataDictionary.h:54
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::ImageFileWriter
Writes image data to a single file.
Definition: itkImageFileWriter.h:90
itk::ImageSeriesWriter::FileNamesContainer
std::vector< std::string > FileNamesContainer
Definition: itkImageSeriesWriter.h:108
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itkImageFileWriter.h
itk::ExceptionObject
Standard exception handling object.
Definition: itkExceptionObject.h:50
itk::ImageSeriesWriter::DictionaryArrayType
std::vector< DictionaryRawPointer > DictionaryArrayType
Definition: itkImageSeriesWriter.h:113
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::ImageSeriesWriter::Update
void Update() override
Definition: itkImageSeriesWriter.h:147
itk::ProcessObject
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
Definition: itkProcessObject.h:139
itk::ProcessObject
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
itk::ImageSeriesWriter::GetFileNames
const FileNamesContainer & GetFileNames() const
Definition: itkImageSeriesWriter.h:186
itk::ImageSeriesWriter::DictionaryArrayRawPointer
const DictionaryArrayType * DictionaryArrayRawPointer
Definition: itkImageSeriesWriter.h:114
itk::ImageSeriesWriter::InputImageType
TInputImage InputImageType
Definition: itkImageSeriesWriter.h:103
itk::ImageSeriesWriter::SetFileNames
void SetFileNames(const FileNamesContainer &name)
Definition: itkImageSeriesWriter.h:175
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86
itk::ImageSeriesWriterException
Base exception class for IO problems during writing.
Definition: itkImageSeriesWriter.h:33
itk::ImageSeriesWriter::OutputImageType
TOutputImage OutputImageType
Definition: itkImageSeriesWriter.h:105