ITK  4.3.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< class TPixel, unsigned int VImageDimension = 2 >
48 class ITK_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)
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< class TPixel, unsigned int VImageDimension >
159 class ITK_EXPORT RawImageIOFactory:public ObjectFactoryBase
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  {
188  ObjectFactoryBase::RegisterFactory( Self::New() );
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
208