ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkRawImageIO.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 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 
29 namespace itk
30 {
47 template< typename TPixel, unsigned int VImageDimension = 2 >
48 class ITK_TEMPLATE_EXPORT RawImageIO:public ImageIOBase
49 {
50 public:
51  ITK_DISALLOW_COPY_AND_ASSIGN(RawImageIO);
52 
54  using Self = RawImageIO;
57 
59  itkNewMacro(Self);
60 
62  itkTypeMacro(RawImageIO, ImageIOBase);
63 
66  using PixelType = TPixel;
67 
70 
73 
76 
79  void SetHeaderSize(SizeValueType size);
80 
81  SizeValueType GetHeaderSize();
82 
86  itkSetMacro(FileDimensionality, unsigned long);
87  itkGetConstMacro(FileDimensionality, unsigned long);
89 
95  bool SupportsDimension(unsigned long dim) override
96  { return ( dim == m_FileDimensionality ); }
97 
98  /*-------- This part of the interface deals with reading data. ------ */
99 
103  bool CanReadFile(const char *) override { return false; }
104 
107  void ReadImageInformation() override { return; }
108 
110  void Read(void *buffer) override;
111 
113  itkGetConstReferenceMacro(ImageMask, unsigned short);
114  void SetImageMask(unsigned long val)
115  {
116  if ( val == m_ImageMask ) { return; }
117  m_ImageMask = ( (unsigned short)( val ) );
118  this->Modified();
119  }
121 
123  virtual void ReadHeader( const std::string = std::string() ) {}
124 
125  /*-------- This part of the interfaces deals with writing data. ----- */
126 
130  bool CanWriteFile(const char *) override;
131 
133  void WriteImageInformation() override { return; }
134 
136  void Write(const void *buffer) override;
137 
138 protected:
139  RawImageIO();
140  ~RawImageIO() override = default;
141  void PrintSelf(std::ostream & os, Indent indent) const override;
142 
143  //void ComputeInternalFileName(unsigned long slice);
144 
145 private:
146  std::string m_InternalFileName;
147 
148  unsigned long m_FileDimensionality;
151  unsigned short m_ImageMask;
152 };
153 
154 template< typename TPixel, unsigned int VImageDimension >
155 class ITK_TEMPLATE_EXPORT RawImageIOFactory:public ObjectFactoryBase
156 {
157 public:
158  ITK_DISALLOW_COPY_AND_ASSIGN(RawImageIOFactory);
159 
165 
167  const char * GetITKSourceVersion() const override
168  {
169  return ITK_SOURCE_VERSION;
170  }
171 
172  const char * GetDescription() const override
173  {
174  return "Raw ImageIO Factory, allows the loading of Raw images into insight";
175  }
176 
178  itkFactorylessNewMacro(Self);
179 
181  itkTypeMacro(RawImageIOFactory, ObjectFactoryBase);
182 
184  static void RegisterOneFactory()
185  {
186  ObjectFactoryBase::RegisterFactory( Self::New() );
187  }
188 
189 protected:
190  RawImageIOFactory() = default;
191  ~RawImageIOFactory() override = default;
194 };
195 } // namespace itk
196 
197 #ifndef ITK_MANUAL_INSTANTIATION
198 #include "itkRawImageIO.hxx"
199 #endif
200 
201 #endif
unsigned long m_FileDimensionality
bool SupportsDimension(unsigned long dim) override
Definition: itkRawImageIO.h:95
Light weight base class for most itk classes.
const char * GetITKSourceVersion() const override
#define ITK_SOURCE_VERSION
Definition: itkVersion.h:40
Abstract superclass defines image IO interface.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
void ReadImageInformation() override
typename PixelTraits< PixelType >::ValueType ComponentType
Definition: itkRawImageIO.h:72
Create instances of classes using an object factory.
std::string m_InternalFileName
unsigned short m_ImageMask
typename TPixelType::ValueType ValueType
::itk::SizeValueType SizeValueType
const myProductType * m_MyProduct
SizeValueType m_HeaderSize
bool CanReadFile(const char *) override
Read and write raw binary images.
Definition: itkRawImageIO.h:48
static void RegisterOneFactory()
static bool RegisterFactory(ObjectFactoryBase *, InsertionPositionType where=INSERT_AT_BACK, vcl_size_t position=0)
void SetImageMask(unsigned long val)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
virtual void ReadHeader(const std::string=std::string())
Base class for most ITK classes.
Definition: itkObject.h:60
Perform machine dependent byte swapping.
void WriteImageInformation() override
const char * GetDescription() const override