]> Creatis software - clitk.git/blob - common/clitkGateAsciiImageIO.h
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
[clitk.git] / common / clitkGateAsciiImageIO.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef CLITKGATEASCIIIMAGEIO_H
19 #define CLITKGATEASCIIIMAGEIO_H
20
21 // itk include
22 #include <itkImageIOBase.h>
23 #include <itksys/RegularExpression.hxx>
24
25 #if defined (_MSC_VER) && (_MSC_VER < 1600)
26 //SR: taken from
27 //#include "msinttypes/stdint.h"
28 typedef unsigned int uint32_t;
29 #else
30 #include <stdint.h>
31 #endif
32
33 namespace clitk
34 {
35
36 //====================================================================
37 // Class for reading gate ascii Image file format
38 class GateAsciiImageIO: public itk::ImageIOBase
39 {
40 public:
41   /** Standard class typedefs. */
42   typedef GateAsciiImageIO        Self;
43   typedef itk::ImageIOBase        Superclass;
44   typedef itk::SmartPointer<Self> Pointer;
45
46   struct GateAsciiHeader {
47     double matrix_size[3];
48     int resolution[3];
49     double voxel_size[3];
50     int nb_value;
51   };
52
53   GateAsciiImageIO():Superclass() {}
54
55   /** Method for creation through the object factory. */
56   itkNewMacro(Self);
57
58   /** Run-time type information (and related methods). */
59   itkTypeMacro(GateAsciiImageIO, ImageIOBase);
60
61   /*-------- This part of the interface deals with reading data. ------ */
62   virtual void ReadImageInformation();
63   virtual bool CanReadFile( const char* FileNameToRead );
64   virtual void Read(void * buffer);
65
66   /*-------- This part of the interfaces deals with writing data. ----- */
67   virtual void WriteImageInformation();
68   virtual bool CanWriteFile(const char* filename);
69   virtual void Write(const void* buffer);
70
71   virtual bool SupportsDimension(unsigned long dim);
72
73 protected:
74   static bool ReadHeader(FILE* handle, GateAsciiHeader& header);
75   static bool ReadLine(FILE* handle, std::string& line);
76   static bool FindRegularExpressionNextLine(itksys::RegularExpression &reg, std::string &s, FILE* handle);
77
78 }; // end class GateAsciiImageIO
79 } // end namespace
80
81 // explicit template instantiation
82 //template class itk::CreateObjectFunction<clitk::GateAsciiImageIO>;
83
84 #endif /* end #define CLITKGATEASCIIIMAGEIO_H */
85