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
27namespace itk
28{
33class ITKIOImageBase_EXPORT ImageSeriesWriterException : public ExceptionObject
34{
35public:
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};
84template <typename TInputImage, typename TOutputImage>
85class ITK_TEMPLATE_EXPORT ImageSeriesWriter : public ProcessObject
86{
87public:
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 *
123
124 const InputImageType *
125 GetInput(unsigned int idx);
126
133 itkSetObjectMacro(ImageIO, ImageIOBase);
134 itkGetModifiableObjectMacro(ImageIO, ImageIOBase);
141 virtual void
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 &
187 {
188 return m_FileNames;
189 }
190
193 void
194 SetFileName(std::string const & name)
195 {
196 m_FileNames.clear();
197 m_FileNames.push_back(name);
198 this->Modified();
199 }
204 void
205 AddFileName(std::string const & 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);
222protected:
224 ~ImageSeriesWriter() override = default;
225 void
226 PrintSelf(std::ostream & os, Indent indent) const override;
227
229 void
230 GenerateData() override;
231
234 void
236
238
239 // track whether the ImageIO is user specified
240 bool m_UserSpecifiedImageIO{ false };
241
242private:
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
265
266 void
268};
269} // end namespace itk
270
271#ifndef ITK_MANUAL_INSTANTIATION
272# include "itkImageSeriesWriter.hxx"
273#endif
274
275#endif // itkImageSeriesWriter_h
Writes image data to a single file.
Abstract superclass defines image IO interface.
Base exception class for IO problems during writing.
ImageSeriesWriterException(const std::string &file, unsigned int line, const char *message="Error in IO")
~ImageSeriesWriterException() noexcept override
Writes image data to a series of data files.
void GenerateNumericFileNamesAndWrite()
std::vector< DictionaryRawPointer > DictionaryArrayType
void AddFileName(std::string const &name)
const InputImageType * GetInput(unsigned int idx)
~ImageSeriesWriter() override=default
void GenerateData() override
const DictionaryArrayType * DictionaryArrayRawPointer
void SetInput(const InputImageType *input)
const InputImageType * GetInput()
std::vector< std::string > FileNamesContainer
const FileNamesContainer & GetFileNames() const
virtual void Write()
typename InputImageType::RegionType InputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
void SetFileNames(const FileNamesContainer &name)
void PrintSelf(std::ostream &os, Indent indent) const override
void SetFileName(std::string const &name)
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Provides a mechanism for storing a collection of arbitrary data types.
The base class for all process objects (source, filters, mappers) in the Insight data processing pipe...
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
class ITK_FORWARD_EXPORT ProcessObject
Definition: itkDataObject.h:41
unsigned long SizeValueType
Definition: itkIntTypes.h:86