ITK  5.4.0
Insight Toolkit
itkRawImageIO.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 itkRawImageIO_h
19#define itkRawImageIO_h
20
21#include "itkImageIOBase.h"
22#include "itkImageRegion.h"
23#include "itkPixelTraits.h"
24#include "itkByteSwapper.h"
25#include "itkVersion.h"
26#include <string>
27#include <fstream>
28
29namespace itk
30{
48template <typename TPixel, unsigned int VImageDimension = 2>
49class ITK_TEMPLATE_EXPORT RawImageIO : public ImageIOBase
50{
51public:
52 ITK_DISALLOW_COPY_AND_MOVE(RawImageIO);
53
58
60 itkNewMacro(Self);
61
63 itkOverrideGetNameOfClassMacro(RawImageIO);
64
67 using PixelType = TPixel;
68
71
74
77
80 void
82
85
89 itkSetMacro(FileDimensionality, unsigned long);
90 itkGetConstMacro(FileDimensionality, unsigned long);
98 bool
99 SupportsDimension(unsigned long dim) override
100 {
101 return (dim == m_FileDimensionality);
102 }
103
104 /*-------- This part of the interface deals with reading data. ------ */
105
109 bool
110 CanReadFile(const char *) override
111 {
112 return false;
113 }
114
117 void
119 {
120 return;
121 }
122
124 void
125 Read(void * buffer) override;
126
128 itkGetConstReferenceMacro(ImageMask, unsigned short);
129 void
130 SetImageMask(unsigned long val)
131 {
132 if (val == m_ImageMask)
133 {
134 return;
135 }
136 m_ImageMask = (static_cast<unsigned short>(val));
137 this->Modified();
138 }
142 virtual void
143 ReadHeader(const std::string = std::string())
144 {}
145
146 /*-------- This part of the interfaces deals with writing data. ----- */
147
151 bool
152 CanWriteFile(const char *) override;
153
155 void
157 {
158 return;
159 }
160
162 void
163 Write(const void * buffer) override;
164
165protected:
167 ~RawImageIO() override = default;
168 void
169 PrintSelf(std::ostream & os, Indent indent) const override;
170
171 // void ComputeInternalFileName(unsigned long slice);
172
173private:
174 std::string m_InternalFileName{};
175
176 unsigned long m_FileDimensionality{};
177 bool m_ManualHeaderSize{};
178 SizeValueType m_HeaderSize{};
179 unsigned short m_ImageMask{};
180};
181
182template <typename TPixel, unsigned int VImageDimension>
183class ITK_TEMPLATE_EXPORT RawImageIOFactory : public ObjectFactoryBase
184{
185public:
186 ITK_DISALLOW_COPY_AND_MOVE(RawImageIOFactory);
187
193
195 const char *
196 GetITKSourceVersion() const override
197 {
198 return ITK_SOURCE_VERSION;
199 }
200
201 const char *
202 GetDescription() const override
203 {
204 return "Raw ImageIO Factory, allows the loading of Raw images into insight";
205 }
206
208 itkFactorylessNewMacro(Self);
209
211 itkOverrideGetNameOfClassMacro(RawImageIOFactory);
212
214 static void
216 {
218 }
219
220protected:
221 RawImageIOFactory() = default;
222 ~RawImageIOFactory() override = default;
223};
224} // namespace itk
225
226#ifndef ITK_MANUAL_INSTANTIATION
227# include "itkRawImageIO.hxx"
228#endif
229
230#endif
Perform machine dependent byte swapping.
Abstract superclass defines image IO interface.
itk::SizeValueType SizeValueType
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Create instances of classes using an object factory.
static bool RegisterFactory(ObjectFactoryBase *, InsertionPositionEnum where=InsertionPositionEnum::INSERT_AT_BACK, vcl_size_t position=0)
Base class for most ITK classes.
Definition: itkObject.h:62
typename TPixelType::ValueType ValueType
const char * GetDescription() const override
~RawImageIOFactory() override=default
const char * GetITKSourceVersion() const override
static void RegisterOneFactory()
Read and write raw binary images.
Definition: itkRawImageIO.h:50
void Write(const void *buffer) override
SizeValueType GetHeaderSize()
typename PixelTraits< PixelType >::ValueType ComponentType
Definition: itkRawImageIO.h:73
void PrintSelf(std::ostream &os, Indent indent) const override
void SetImageMask(unsigned long val)
virtual void ReadHeader(const std::string=std::string())
void ReadImageInformation() override
bool SupportsDimension(unsigned long dim) override
Definition: itkRawImageIO.h:99
bool CanReadFile(const char *) override
void Read(void *buffer) override
void WriteImageInformation() override
~RawImageIO() override=default
bool CanWriteFile(const char *) override
void SetHeaderSize(SizeValueType size)
static Pointer New()
#define ITK_SOURCE_VERSION
Definition: itkVersion.h:39
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition: itkIntTypes.h:83