ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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};
56
57
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;
104 using InputImageRegionType = typename InputImageType::RegionType;
105 using OutputImageType = TOutputImage;
106 using OutputImageRegionType = typename OutputImageType::RegionType;
108 using FileNamesContainer = std::vector<std::string>;
109
113 using DictionaryArrayType = std::vector<DictionaryRawPointer>;
115
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);
136
141 virtual void
143
146 void
147 Update() override
148 {
149 this->Write();
150 }
151
154 itkSetMacro(StartIndex, SizeValueType);
155 itkGetConstMacro(StartIndex, SizeValueType);
157
160 itkSetMacro(IncrementIndex, SizeValueType);
161 itkGetConstMacro(IncrementIndex, SizeValueType);
163
168 itkSetStringMacro(SeriesFormat);
169 itkGetStringMacro(SeriesFormat);
171
174 void
176 {
177 if (m_FileNames != name)
178 {
179 m_FileNames = name;
180 this->Modified();
181 }
182 }
183
184
185 const FileNamesContainer &
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 }
200
201
204 void
205 AddFileName(const std::string & name)
206 {
207 m_FileNames.push_back(name);
208 this->Modified();
209 }
210
211
214 itkSetMacro(MetaDataDictionaryArray, DictionaryArrayRawPointer);
215
217 itkSetMacro(UseCompression, bool);
218 itkGetConstReferenceMacro(UseCompression, bool);
219 itkBooleanMacro(UseCompression);
221
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
241
242private:
245
251 std::string m_SeriesFormat{};
254
256
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
virtual void SetDescription(const std::string &s)
ExceptionObject() noexcept=default
Writes image data to a single file.
Abstract superclass defines image IO interface.
SmartPointer< Self > Pointer
ImageSeriesWriterException(const std::string &file, unsigned int line, const char *message="Error in IO")
ImageSeriesWriterException(char *file, unsigned int line, const char *message="Error in IO")
~ImageSeriesWriterException() noexcept override
void GenerateNumericFileNamesAndWrite()
std::vector< DictionaryRawPointer > DictionaryArrayType
FileNamesContainer m_FileNames
void SetFileName(const std::string &name)
const InputImageType * GetInput(unsigned int idx)
~ImageSeriesWriter() override=default
void GenerateData() override
const DictionaryArrayType * DictionaryArrayRawPointer
void SetInput(const InputImageType *input)
const InputImageType * GetInput()
SmartPointer< Self > Pointer
void AddFileName(const std::string &name)
std::vector< std::string > FileNamesContainer
const FileNamesContainer & GetFileNames() const
virtual void Write()
SmartPointer< const Self > ConstPointer
typename InputImageType::RegionType InputImageRegionType
typename OutputImageType::RegionType OutputImageRegionType
void SetFileNames(const FileNamesContainer &name)
void PrintSelf(std::ostream &os, Indent indent) const override
MetaDataDictionary * DictionaryRawPointer
ImageIOBase::Pointer m_ImageIO
DictionaryArrayRawPointer m_MetaDataDictionaryArray
MetaDataDictionary DictionaryType
ImageFileWriter< TOutputImage > WriterType
Control indentation during Print() invocation.
Definition itkIndent.h:50
Provides a mechanism for storing a collection of arbitrary data types.
virtual void Modified() const
virtual void SetInput(const DataObjectIdentifierType &key, DataObject *input)
Protected method for setting indexed and named inputs.
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86