ITK  4.5.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)
94  { return ( dim == m_FileDimensionality ); }
95 
96  /*-------- This part of the interface deals with reading data. ------ */
97 
101  virtual bool CanReadFile(const char *) { return false; }
102 
105  virtual void ReadImageInformation() { return; }
106 
108  virtual void Read(void *buffer);
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 *);
129 
131  virtual void WriteImageInformation(void) { return; }
132 
134  virtual void Write(const void *buffer);
135 
136 protected:
137  RawImageIO();
138  ~RawImageIO();
139  void PrintSelf(std::ostream & os, Indent indent) const;
140 
141  //void ComputeInternalFileName(unsigned long slice);
142  void OpenFileForReading(std::ifstream & is);
143 
144  void OpenFileForWriting(std::ofstream & os);
145 
146 private:
147  RawImageIO(const Self &); //purposely not implemented
148  void operator=(const Self &); //purposely not implemented
149 
150  std::string m_InternalFileName;
151 
152  unsigned long m_FileDimensionality;
155  unsigned short m_ImageMask;
156 };
157 
158 template< typename TPixel, unsigned int VImageDimension >
160 {
161 public:
167 
169  const char * GetITKSourceVersion(void) const
170  {
171  return ITK_SOURCE_VERSION;
172  }
173 
174  const char * GetDescription(void) const
175  {
176  return "Raw ImageIO Factory, allows the loading of Raw images into insight";
177  }
178 
180  itkFactorylessNewMacro(Self);
181 
183  itkTypeMacro(RawImageIOFactory, ObjectFactoryBase);
184 
186  static void RegisterOneFactory(void)
187  {
189  }
190 
191 protected:
196 
197 private:
198  RawImageIOFactory(const Self &); //purposely not implemented
199  void operator=(const Self &); //purposely not implemented
200 };
201 } // namespace itk
202 
203 #ifndef ITK_MANUAL_INSTANTIATION
204 #include "itkRawImageIO.hxx"
205 #endif
206 
207 #endif
unsigned long m_FileDimensionality
Superclass::SizeValueType SizeValueType
Definition: itkRawImageIO.h:67
Light weight base class for most itk classes.
TPixelType::ValueType ValueType
#define ITK_SOURCE_VERSION
Definition: itkVersion.h:40
void operator=(const Self &)
SmartPointer< Self > Pointer
virtual bool SupportsDimension(unsigned long dim)
Definition: itkRawImageIO.h:93
Abstract superclass defines image IO interface.
void OpenFileForReading(std::ifstream &is)
RawImageIO Self
Definition: itkRawImageIO.h:52
const char * GetITKSourceVersion(void) const
virtual void Read(void *buffer)
virtual void ReadImageInformation()
SmartPointer< const Self > ConstPointer
ObjectFactoryBase Superclass
Create instances of classes using an object factory.
void PrintSelf(std::ostream &os, Indent indent) const
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
virtual void WriteImageInformation(void)
const myProductType * m_MyProduct
ByteSwapper< ComponentType > ByteSwapperType
Definition: itkRawImageIO.h:73
void SetHeaderSize(SizeValueType size)
SizeValueType GetHeaderSize()
void OpenFileForWriting(std::ofstream &os)
virtual void Write(const void *buffer)
RawImageIOFactory< TPixel, VImageDimension > Self
::itk::SizeValueType SizeValueType
void operator=(const Self &)
virtual void Modified() const
static void RegisterOneFactory(void)
SizeValueType m_HeaderSize
virtual bool CanWriteFile(const char *)
const char * GetDescription(void) const
Read and write raw binary images.
Definition: itkRawImageIO.h:48
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())
Perform machine dependent byte swapping.
static Pointer New(void)
virtual bool CanReadFile(const char *)