ITK  4.13.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:
52  typedef RawImageIO Self;
55 
57  itkNewMacro(Self);
58 
60  itkTypeMacro(RawImageIO, ImageIOBase);
61 
64  typedef TPixel PixelType;
65 
68 
71 
74 
77  void SetHeaderSize(SizeValueType size);
78 
79  SizeValueType GetHeaderSize();
80 
84  itkSetMacro(FileDimensionality, unsigned long);
85  itkGetConstMacro(FileDimensionality, unsigned long);
87 
93  virtual bool SupportsDimension(unsigned long dim) ITK_OVERRIDE
94  { return ( dim == m_FileDimensionality ); }
95 
96  /*-------- This part of the interface deals with reading data. ------ */
97 
101  virtual bool CanReadFile(const char *) ITK_OVERRIDE { return false; }
102 
105  virtual void ReadImageInformation() ITK_OVERRIDE { return; }
106 
108  virtual void Read(void *buffer) ITK_OVERRIDE;
109 
111  itkGetConstReferenceMacro(ImageMask, unsigned short);
112  void SetImageMask(unsigned long val)
113  {
114  if ( val == m_ImageMask ) { return; }
115  m_ImageMask = ( (unsigned short)( val ) );
116  this->Modified();
117  }
119 
121  virtual void ReadHeader( const std::string = std::string() ) {}
122 
123  /*-------- This part of the interfaces deals with writing data. ----- */
124 
128  virtual bool CanWriteFile(const char *) ITK_OVERRIDE;
129 
131  virtual void WriteImageInformation(void) ITK_OVERRIDE { return; }
132 
134  virtual void Write(const void *buffer) ITK_OVERRIDE;
135 
136 protected:
137  RawImageIO();
138  ~RawImageIO() ITK_OVERRIDE;
139  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
140 
141  //void ComputeInternalFileName(unsigned long slice);
142 
143 private:
144  ITK_DISALLOW_COPY_AND_ASSIGN(RawImageIO);
145 
146  std::string m_InternalFileName;
147 
148  unsigned long m_FileDimensionality;
149  bool m_ManualHeaderSize;
150  SizeValueType m_HeaderSize;
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:
160  typedef ObjectFactoryBase Superclass;
163 
165  virtual const char * GetITKSourceVersion(void) const ITK_OVERRIDE
166  {
167  return ITK_SOURCE_VERSION;
168  }
169 
170  virtual const char * GetDescription(void) const ITK_OVERRIDE
171  {
172  return "Raw ImageIO Factory, allows the loading of Raw images into insight";
173  }
174 
176  itkFactorylessNewMacro(Self);
177 
179  itkTypeMacro(RawImageIOFactory, ObjectFactoryBase);
180 
182  static void RegisterOneFactory(void)
183  {
184  ObjectFactoryBase::RegisterFactory( Self::New() );
185  }
186 
187 protected:
191  const myProductType *m_MyProduct;
192 
193 private:
194  ITK_DISALLOW_COPY_AND_ASSIGN(RawImageIOFactory);
195 };
196 } // namespace itk
197 
198 #ifndef ITK_MANUAL_INSTANTIATION
199 #include "itkRawImageIO.hxx"
200 #endif
201 
202 #endif
Superclass::SizeValueType SizeValueType
Definition: itkRawImageIO.h:67
Light weight base class for most itk classes.
virtual bool CanReadFile(const char *) override
TPixelType::ValueType ValueType
#define ITK_SOURCE_VERSION
Definition: itkVersion.h:40
SmartPointer< Self > Pointer
Abstract superclass defines image IO interface.
RawImageIO Self
Definition: itkRawImageIO.h:52
SmartPointer< const Self > ConstPointer
ObjectFactoryBase Superclass
Create instances of classes using an object factory.
virtual const char * GetDescription(void) const override
ImageIOBase Superclass
Definition: itkRawImageIO.h:53
RawImageIO< TPixel, VImageDimension > myProductType
SmartPointer< Self > Pointer
Definition: itkRawImageIO.h:54
const myProductType * m_MyProduct
ByteSwapper< ComponentType > ByteSwapperType
Definition: itkRawImageIO.h:73
RawImageIOFactory< TPixel, VImageDimension > Self
::itk::SizeValueType SizeValueType
virtual bool SupportsDimension(unsigned long dim) override
Definition: itkRawImageIO.h:93
static void RegisterOneFactory(void)
Read and write raw binary images.
Definition: itkRawImageIO.h:48
virtual const char * GetITKSourceVersion(void) const override
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
PixelTraits< PixelType >::ValueType ComponentType
Definition: itkRawImageIO.h:70
virtual void ReadHeader(const std::string=std::string())
virtual void ReadImageInformation() override
Perform machine dependent byte swapping.