Build without /usr/local/snark14
[snark14.git] / include / DIGFileSnark / DIGFileSnarkRec.h
1 #ifndef DIG_FILE_SNARK_REC_H
2 #define DIG_FILE_SNARK_REC_H
3
4 //#include "DIGFile.h"
5 #include <DIGFile/DIGFile.h>
6
7 ///////////////////////////////////////////////
8 // DIGFileSnarkRec main header
9 ///////////////////////////////////////////////
10
11 class RecFileMH
12 {
13 public:
14   DIGString     Title;
15   unsigned int  Dimensions;
16   double        Sampling;
17   DIGString     Comment;
18 };
19
20 ///////////////////////////////////////////////
21 // DIGFileSnarkRec phantom header
22 ///////////////////////////////////////////////
23
24 class RecFilePhanomH
25 {
26 public:
27   DIGString     Name;
28   DIGString     Comment;
29 };
30
31 ///////////////////////////////////////////////
32 // DIGFileSnarkRec Reconstruction Set header
33 ///////////////////////////////////////////////
34
35 class RecFileRecSetH
36 {
37 public:
38   DIGString   Name;
39   DIGString   AlgName;
40   DIGString   Comment;
41 };
42
43 ///////////////////////////////////////////////
44 // DIGFileSnarkRec Reconstruction header
45 ///////////////////////////////////////////////
46
47 class RecFileRecH
48 {
49 public:
50   unsigned int  Count;
51   DIGString     Comment;
52 };
53
54 ///////////////////////////////////////////////
55 // DIGFileSnarkRec
56 ///////////////////////////////////////////////
57
58 class DIGFileSnarkRec: protected DIGFile {
59
60 protected:
61   static const char*  TypeStr;
62   static const char*  SchemaStr;
63   bool                PhantomPresent;
64   bool                RecPressent;
65
66 public:
67
68         DIGFileSnarkRec();
69         ~DIGFileSnarkRec();
70
71   //
72   // Writing
73   //
74
75   // Open for writing
76
77   int Open(const char* pFileName, RecFileMH* pMainHeader);
78   int Open(
79     const char* pFileName,      // File Name
80     const char* pProjName,      // Projection Name
81     unsigned int pNoOfElements, // NELEM
82     double pSampling,           // PIXSIZ
83     const char* pComments       // Comments
84   );
85
86   // Updating main header after opening file to write
87
88   int SetProjName(const char* pProjName) {
89     return DIGFile::SetTitle(pProjName);
90   }
91
92   int SetComment(const char* pComment) {
93     return DIGFile::SetComment(pComment);
94   }
95
96   // Appending phantom
97
98   int AppendPhanom(RecFilePhanomH* pPhanomHeader, double* pData);
99   int AppendPhantom(const char* pPhanomName, const char* pComment, double* pData);
100
101   // Appending reconstruction set
102
103   int AppendRecSet(RecFileRecSetH* pRecHeader);
104   int AppendRecSet(const char* pAlgName, const char* pName, const char* pComment);
105
106   // Appending reconstruction
107
108   int AppendRec(RecFileRecH* pRecHeader, double* pData);
109   int AppendRec(unsigned int pCount, const char* pComment, double* pData);
110
111   //
112   // Reading
113   //
114
115   // Open for reading
116
117   int Open(const char* pFileName);
118
119   // Reading file parameters
120
121   int GetPhantomPresent(bool* pPhantomPresent) {
122     *pPhantomPresent = PhantomPresent;
123     return 0;
124   }
125
126   int GetNoOfPixels(unsigned int* pNoOfPixels) {
127     return DIGFile::GetArrayNoOfItems(pNoOfPixels);
128   }
129
130   int GetNoOfRecSets(unsigned int* pNoOfRecSets) {
131     int ret;
132     unsigned int NoOfRecSets;
133
134     if((ret = DIGFile::GetNoOfArraySets(&NoOfRecSets)) != 0) {
135       return ret; // error
136     }
137
138     if(PhantomPresent) {
139       *pNoOfRecSets = NoOfRecSets - 1;
140     }
141     else {
142       *pNoOfRecSets = NoOfRecSets;
143     }
144
145     return 0;
146   }
147
148   int GetNoOfRecs(unsigned int* pNoOfRec) {
149     return GetNoOfArrays(pNoOfRec);
150   }
151
152   // file navigation
153
154   int SelectRecSet(unsigned int pRecSetNo) {
155     if(PhantomPresent) {
156       return SelectArraySet(pRecSetNo + 1);
157     }
158     else {
159       return SelectArraySet(pRecSetNo);
160     }
161   }
162
163   int SelectRec(unsigned int pRecNo) {
164     return SelectArray(pRecNo);
165   }
166
167   // Reading main header
168
169   int GetMainHeader(RecFileMH* pMainHeader);
170
171   int GetProjName(const char** pProjName) {
172     return DIGFile::GetTitle(pProjName);
173   }
174
175   int GetEndian(DIGEndian* pEndian) {
176     return DIGFile::GetEndian(pEndian);
177   }
178
179   int GetDimensions(unsigned int* pDimensions) {
180     const DIGDimensions* Dimensions;
181     int ret;
182
183     if((ret = DIGFile::GetDimensions(&Dimensions)) != 0) {
184       return ret;
185     }
186
187     *pDimensions = Dimensions->x;
188
189     return 0;
190   }
191
192   int GetSampling(double* pSampling) {
193     const DIGSampling* Sampling;
194     int ret;
195
196     if((ret = DIGFile::GetSamplingX(&Sampling)) != 0) {
197       return ret;
198     }
199
200     *pSampling = Sampling->x;
201
202     return 0;
203   }
204
205   int GetComment(const char** pComment) {
206     return DIGFile::GetComment(pComment);
207   }
208
209   // Reading phantom header
210
211   int GetPhantomHeader(RecFilePhanomH* pPhantomHeader);
212
213   int GetPhantomName(const char** pPhantomName);
214   int GetPhantomComment(const char** pPhantomComment);
215
216   // Reading phantom data
217
218   int GetPhantomData(void* pPhantomData);
219
220   // Reading reconstruction set header
221
222   int GetRecSetHeader(RecFileRecSetH* pRecSetHeader);
223
224   int GetRecSetName(const char** pRecName); // title
225   int GetRecSetAlgName(const char** pAlgName); // type
226   int GetRecSetComment(const char** pComment);
227
228   // Reading reconstruction header
229
230   int GetRecHeader(RecFileRecH* pRecHeader);
231
232   int GetRecCount(unsigned int* pCount);
233   int GetRecComment(const char** pComment);
234
235   // Reading reconstruction data
236
237   int GetRecData(void* pRecData) {
238     return DIGFile::GetArrayData(pRecData);
239   }
240
241   ///////////////////////////////////////////////////
242
243   int Close() {
244     return DIGFile::Close();
245   }
246
247 };
248
249 #endif // DIG_FILE_SNARK_REC_H