ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkVoxBoCUBImageIO.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkVoxBoCUBImageIO_h
00019 #define __itkVoxBoCUBImageIO_h
00020 
00021 
00022 #include <fstream>
00023 #include <string>
00024 #include <map>
00025 #include "itkImageIOBase.h"
00026 #include "itkSpatialOrientation.h"
00027 #include <stdio.h>
00028 
00029 namespace itk
00030 {
00031 // Forward declaration
00032 class GenericCUBFileAdaptor;
00033 
00050 class ITK_EXPORT VoxBoCUBImageIO:public ImageIOBase
00051 {
00052 public:
00054   typedef VoxBoCUBImageIO      Self;
00055   typedef ImageIOBase          Superclass;
00056   typedef SmartPointer< Self > Pointer;
00057 
00059   itkNewMacro(Self);
00060 
00062   itkTypeMacro(VoxBoCUBImageIO, Superclass);
00063 
00064   /*-------- This part of the interfaces deals with reading data. ----- */
00065 
00068   virtual bool CanReadFile(const char *);
00069 
00071   virtual void ReadImageInformation();
00072 
00074   virtual void Read(void *buffer);
00075 
00076   /*-------- This part of the interfaces deals with writing data. ----- */
00077 
00080   virtual bool CanWriteFile(const char *);
00081 
00083   virtual void WriteImageInformation();
00084 
00087   virtual void Write(const void *buffer);
00088 
00089   VoxBoCUBImageIO();
00090   ~VoxBoCUBImageIO();
00091   void PrintSelf(std::ostream & os, Indent indent) const;
00092 
00093 private:
00094   VoxBoCUBImageIO(const Self &); //purposely not implemented
00095   void operator=(const Self &);  //purposely not implemented
00096 
00097   bool CheckExtension(const char *, bool & isCompressed);
00098 
00099   GenericCUBFileAdaptor * CreateReader(const char *filename);
00100 
00101   GenericCUBFileAdaptor * CreateWriter(const char *filename);
00102 
00103   GenericCUBFileAdaptor *m_Reader, *m_Writer;
00104 
00105   // Initialize the orientation map (from strings to ITK)
00106   void InitializeOrientationMap();
00107 
00108   // Orientation stuff
00109   typedef SpatialOrientation::ValidCoordinateOrientationFlags OrientationFlags;
00110   typedef std::map< std::string, OrientationFlags >           OrientationMap;
00111   typedef std::map< OrientationFlags, std::string >           InverseOrientationMap;
00112 
00113   OrientationMap        m_OrientationMap;
00114   InverseOrientationMap m_InverseOrientationMap;
00115 
00116   // Method to swap bytes in read buffer
00117   void SwapBytesIfNecessary(void *buffer, BufferSizeType numberOfBytes);
00118 
00119   // Strings used in VoxBo files
00120   static const char *m_VB_IDENTIFIER_SYSTEM;
00121   static const char *m_VB_IDENTIFIER_FILETYPE;
00122   static const char *m_VB_DIMENSIONS;
00123   static const char *m_VB_SPACING;
00124   static const char *m_VB_ORIGIN;
00125   static const char *m_VB_DATATYPE;
00126   static const char *m_VB_BYTEORDER;
00127   static const char *m_VB_ORIENTATION;
00128   static const char *m_VB_BYTEORDER_MSB;
00129   static const char *m_VB_BYTEORDER_LSB;
00130   static const char *m_VB_DATATYPE_BYTE;
00131   static const char *m_VB_DATATYPE_INT;
00132   static const char *m_VB_DATATYPE_FLOAT;
00133   static const char *m_VB_DATATYPE_DOUBLE;
00134 };
00135 } // end namespace itk
00136 
00137 #endif // __itkVoxBoCUBImageIO_h
00138