ITK  4.9.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 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 
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();
139  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
140 
141  //void ComputeInternalFileName(unsigned long slice);
142 
143 private:
144  RawImageIO(const Self &) ITK_DELETE_FUNCTION;
145  void operator=(const Self &) ITK_DELETE_FUNCTION;
146 
147  std::string m_InternalFileName;
148 
149  unsigned long m_FileDimensionality;
152  unsigned short m_ImageMask;
153 };
154 
155 template< typename TPixel, unsigned int VImageDimension >
157 {
158 public:
161  typedef ObjectFactoryBase Superclass;
164 
166  virtual const char * GetITKSourceVersion(void) const ITK_OVERRIDE
167  {
168  return ITK_SOURCE_VERSION;
169  }
170 
171  virtual const char * GetDescription(void) const ITK_OVERRIDE
172  {
173  return "Raw ImageIO Factory, allows the loading of Raw images into insight";
174  }
175 
177  itkFactorylessNewMacro(Self);
178 
180  itkTypeMacro(RawImageIOFactory, ObjectFactoryBase);
181 
183  static void RegisterOneFactory(void)
184  {
186  }
187 
188 protected:
192  const myProductType *m_MyProduct;
193 
194 private:
195  RawImageIOFactory(const Self &) ITK_DELETE_FUNCTION;
196  void operator=(const Self &) ITK_DELETE_FUNCTION;
197 };
198 } // namespace itk
199 
200 #ifndef ITK_MANUAL_INSTANTIATION
201 #include "itkRawImageIO.hxx"
202 #endif
203 
204 #endif
unsigned long m_FileDimensionality
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
virtual void Read(void *buffer) override
SmartPointer< const Self > ConstPointer
ObjectFactoryBase Superclass
Create instances of classes using an object factory.
virtual const char * GetDescription(void) const override
std::string m_InternalFileName
ImageIOBase Superclass
Definition: itkRawImageIO.h:53
unsigned short m_ImageMask
RawImageIO< TPixel, VImageDimension > myProductType
SmartPointer< Self > Pointer
Definition: itkRawImageIO.h:54
const myProductType * m_MyProduct
ByteSwapper< ComponentType > ByteSwapperType
Definition: itkRawImageIO.h:73
void SetHeaderSize(SizeValueType size)
SizeValueType GetHeaderSize()
RawImageIOFactory< TPixel, VImageDimension > Self
::itk::SizeValueType SizeValueType
virtual bool SupportsDimension(unsigned long dim) override
Definition: itkRawImageIO.h:93
virtual void Modified() const
virtual void PrintSelf(std::ostream &os, Indent indent) const override
static void RegisterOneFactory(void)
SizeValueType m_HeaderSize
virtual bool CanWriteFile(const char *) override
Read and write raw binary images.
Definition: itkRawImageIO.h:48
virtual const char * GetITKSourceVersion(void) const override
virtual void Write(const void *buffer) 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.
virtual void WriteImageInformation(void) override
static Pointer New()