Build without /usr/local/snark14
[snark14.git] / include / DIGFileSnark / DIGFileSnarkProj.h
1 #ifndef DIG_FILE_SNARK_PRJ_H
2 #define DIG_FILE_SNARK_PRJ_H
3
4 #include <string.h>
5
6 //#include "DIGFile.h"
7 #include <DIGFile/DIGFile.h>
8
9 enum DetectorTypeEnum {
10         //DT_UNSET,
11         DT_TANGENT,
12         DT_ARC,
13         DT_UNIFORM,
14         DT_VARIABLE,
15 };
16
17 enum ProjTypeEnum {
18         //PT_UNSET,
19         PT_STRIP,
20         PT_LINE,
21 };
22
23 enum GeometryTypeEnum {
24         //GT_UNSET,
25         GT_DIVERGENT,
26         GT_PARALLEL,
27 };
28
29 class ProjGeometry
30 {
31 public:
32   //geometry
33         GeometryTypeEnum  GeometryType;
34         DetectorTypeEnum  DetectorType;
35
36   // Divergent
37         double            Radius; 
38         double            SrcDetDistance;
39
40   // Paralel
41         ProjTypeEnum      ProjType;
42
43 public:
44   ProjGeometry(double, double, DetectorTypeEnum);
45         ProjGeometry(DetectorTypeEnum, ProjTypeEnum);
46 };
47
48
49 // Noise
50
51 class ProjNoise
52 {
53 public:
54  
55   // quantum
56         bool            IsQuan;
57         double  QuantumMean;
58         double  QuantumCalibration;
59         int     QuantumGantry;
60
61   // scatter
62   bool    IsScat;
63         double  ScatterPeak;
64         double  ScatterWidth;
65
66   // additive
67   bool    IsAdd;
68         double  AdditiveMean;
69         double  AdditiveStdDev;
70
71   // multiplicative
72   bool    IsMult;
73         double  MultiplicativeMean;
74         double  MultiplicativeStdDev;
75
76
77   ProjNoise();
78
79         void SetQuantum(double, double, int);
80         void SetScatter(double, double);
81         void SetAdditive(double, double);
82         void SetMultiplicative(double, double);
83
84
85   /*
86         int GetQuantum(double&, double&, double&);
87         int GetScatter(double&, double&);
88         int GetAdditive(double&, double&);
89         int GetMultiplicative(double&, double&);
90   */
91 };
92
93 // spectrum
94 class ProjSpectrum
95 {
96 public:
97         unsigned int  NumberOfEnergies;
98         int*          energy;
99         double*       ratio;
100         double*       background;
101
102   ProjSpectrum(unsigned int eNum);
103   int SetEnergy(int, int, double, double);
104
105   /*
106   int SetSpectrum(int* e, double* r, double* bg);
107
108
109         int GetNumberOfEnergies(unsigned int* eNum);
110         int GetEnergy(int, int*, double*, double*);
111   */
112 };
113
114 ///////////////////////////////////////////////////////////////////////////////
115 // DIGFileSnarkPrj main header
116 ///////////////////////////////////////////////////////////////////////////////
117
118 class ProjFileMH
119 {
120 public:
121   DIGString     Title;
122   unsigned int  Dimensions;
123   double        Sampling;
124   DIGString     Comment;
125 };
126
127 ///////////////////////////////////////////////////////////////////////////////
128 // DIGFileSnarkPrj application header
129 ///////////////////////////////////////////////////////////////////////////////
130
131 struct ProjFileAH
132 {
133 public:
134   DIGString Comment;
135
136   // geometry
137
138   GeometryTypeEnum    GeometryType;
139   DetectorTypeEnum    DetectorType;
140
141   double              Radius;
142   double              SrcDetDistance;
143
144   ProjTypeEnum        ProjType;
145
146   // spectrum
147
148   unsigned int  NoOfEnergies;
149
150   int*          Energy;
151   double*       Ratio; 
152   double*       Background;
153
154   // noise
155
156   bool    QuantumFlag;
157   double  QuantumM; 
158   double  QuantumCM;
159   int     QuantumGA;
160
161   bool    ScatterFlag;
162   double  ScatterP;
163   double  ScatterW;
164
165   bool    AdditiveFlag;
166   double  AdditiveM;
167   double  AdditiveSD;
168
169   bool    MultiplicativeFlag;
170   double  MultiplicativeM;
171   double  MultiplicativeSD;
172 };
173
174 ///////////////////////////////////////////////////////////////////////////////
175 // DIGFileSnarkPrj projection header
176 ///////////////////////////////////////////////////////////////////////////////
177
178 class ProjFilePrjH
179 {
180 public:
181   unsigned int  ProjNo;
182   double        Angle;
183   DIGString     Comment;
184 };
185
186
187
188 class DIGFileSnarkProj: protected DIGFile {
189
190 protected:
191   static const char* TypeStr;
192   static const char* SchemaStr;
193
194   static bool XMLStringsInitialized;
195
196         static const XMLCh* AppHeaderXMLStr;
197         static const XMLCh* GeomHeaderXMLStr;
198         static const XMLCh* DivergentXMLStr;
199         static const XMLCh* RadiusXMLStr;
200         static const XMLCh* SourceDetXMLStr;
201         static const XMLCh* DetTypeXMLStr;
202         static const XMLCh* ParallelXMLStr;
203         static const XMLCh* ProjTypeXMLStr;
204         static const XMLCh* NoiseHeaderXMLStr;
205         static const XMLCh* QuantumXMLStr;
206         static const XMLCh* MeanXMLStr;
207         static const XMLCh* CalibMeasXMLStr;
208         static const XMLCh* GantryXMLStr;
209         static const XMLCh* ScatterXMLStr;
210         static const XMLCh* PeakXMLStr;
211         static const XMLCh* WidthXMLStr;
212         static const XMLCh* AdditiveXMLStr;
213         static const XMLCh* StdDevXMLStr;
214         static const XMLCh* MultipXMLStr;
215         static const XMLCh* SpectrumHeaderXMLStr;
216         static const XMLCh* NumOfEnerXMLStr;
217         static const XMLCh* EnergyLevelXMLStr;
218         static const XMLCh* EnergyXMLStr;
219         static const XMLCh* RatioXMLStr;
220         static const XMLCh* BackgroundXMLStr;
221         
222   DIGString      AppComment;
223   ProjSpectrum*  Spectrum;
224   ProjGeometry*  Geometry;
225   ProjNoise      Noise;
226
227 public:
228
229         DIGFileSnarkProj();
230         ~DIGFileSnarkProj();
231
232   //
233   // Writing
234   //
235
236   int Open(const char* pFileName, ProjFileMH* pMainHeader);
237   int Open(
238     const char*  pFileName,     // File Name
239     const char*  pTitle,        // Title
240     unsigned int pNumberOfRays, // USRAYS
241     double       pSampling,     // PINC
242     const char*  pComment       // Comment
243   );
244
245   // updating main header after opening file to write
246
247   int SetTitle(const char* pTitle) {
248     return DIGFile::SetTitle(pTitle);
249   }
250
251   int SetComment(const char* pComment) {
252     return DIGFile::SetComment(pComment);
253   }
254
255   // writing application header
256
257   int SetAppHeader(ProjFileAH* pAppHeader);
258
259   // comment
260   int SetAppComment(const char* pComment);
261
262   // geometry
263   int SetGeometry(double r, double d, DetectorTypeEnum t);  // divergent
264   int SetGeometry(DetectorTypeEnum t, ProjTypeEnum p);      // parallel
265
266   // spectrum
267   int SetSpectrum(unsigned int eNum, int* e, double* r, double* bg);
268
269   // noise
270         int SetNoiseQuantum(double, double, int);
271         int SetNoiseScatter(double, double);
272         int SetNoiseAdditive(double, double);
273         int SetNoiseMultiplicative(double, double);
274
275   // Appending Projection
276
277   int AppendProj(ProjFilePrjH* pProjHeader, const double* pData);
278   int AppendProj(
279     unsigned int  pProjNo,
280     double        pAngle,
281     const char*   pComment,
282     const double* pData
283   );
284
285   //
286   // Reading
287   //
288
289   int Open(const char* pFileName);
290
291   // Reading file parameters
292
293   int GetNoOfRays(unsigned int* pNoOfRays) {
294     return DIGFile::GetArrayNoOfItems(pNoOfRays);
295   }
296
297   int GetNoOfProjs(unsigned int* pProjections) {
298     return DIGFile::GetNoOfArraySets(pProjections);
299   }
300
301   // file navigation
302
303   int SelectProj(unsigned int No) {
304     int ret;
305
306     if((ret = SelectArraySet(No)) != 0) {
307       return ret;
308     }
309
310     return SelectArray(0);
311   }
312
313   // Reading main header
314
315   int GetMainHeader(ProjFileMH* pMainHeader);
316
317   int GetTitle(const char** pTitle) {
318     return DIGFile::GetTitle(pTitle);
319   }
320
321   int GetEndian(DIGEndian* pEndian) {
322     return DIGFile::GetEndian(pEndian);
323   }
324
325   int GetDimensions(unsigned int* pDimensions) {
326     const DIGDimensions* Dimensions;
327     int ret;
328
329     if((ret = DIGFile::GetDimensions(&Dimensions)) != 0) {
330       return ret;
331     }
332
333     *pDimensions = Dimensions->x;
334
335     return 0;
336   }
337
338   int GetSampling(double* pSampling) {
339     const DIGSampling* Sampling;
340     int ret;
341
342     if((ret = DIGFile::GetSamplingX(&Sampling)) != 0) {
343       return ret;
344     }
345
346     *pSampling = Sampling->x;
347
348     return 0;
349   }
350
351   int GetComment(const char** pComment) {
352     return DIGFile::GetComment(pComment);
353   }
354
355   // Reading application header 
356
357   int GetAppHeader(ProjFileAH* pAppHeader);
358
359   // comment
360   int GetAppComment(const char** pComment);
361
362   // geometry
363   int GetGeometryType(GeometryTypeEnum* gt);
364   int GetGeometry(double* r, double* d, DetectorTypeEnum* t); // divergent
365   int GetGeometry(DetectorTypeEnum* t, ProjTypeEnum* p);      // parallel
366
367   // spectrum
368   int GetNoOfEnergies(unsigned int* NumbOfEnergies);
369   int GetSpectrum(unsigned int i, int* e, double* r, double* bg);
370
371   // noise
372   int HasNoiseQuantum(bool* a);
373   int GetNoiseQuantum(double* m, double* cm, int* ga);
374   int HasNoiseScatter(bool* a);
375   int GetNoiseScatter(double* p, double* w);
376   int HasNoiseAdditive(bool* a);
377   int GetNoiseAdditive(double* m, double* sd);
378   int HasNoiseMultiplicative(bool* a);
379   int GetNoiseMultiplicative(double* m, double* sd);
380
381
382   // Reading projection header
383
384   int GetProjHeader(ProjFilePrjH* pProjHeader);
385
386   int GetProjNo(unsigned int* pProjNo) 
387   {
388     int ret;
389     const char* ProjNoStr;
390
391     if((ret = DIGFile::GetArraySetTitle(&ProjNoStr)) != 0) {
392       return ret;
393     }
394  
395     *pProjNo = atoi(ProjNoStr);
396
397     return 0;
398   }
399
400   int GetProjAngle(double* pAngle) {
401     int ret;
402     const char* Parameters;
403
404     if((ret = DIGFile::GetArraySetParameters(&Parameters)) != 0) {
405       return ret;
406     }
407  
408     *pAngle = atof(Parameters);
409
410     return 0;
411   }
412
413   int GetProjComment(const char** pComments) {
414     return DIGFile::GetArraySetComment(pComments);
415   }
416
417   // Reading projection data
418
419   int GetProjData(void* pArrayData) {
420     return DIGFile::GetArrayData(pArrayData);
421   }
422
423   int Close() {
424     int ret = DIGFile::Close();
425
426     if(Geometry != NULL) {
427             delete Geometry;
428       Geometry = NULL;
429     }
430
431     if(Spectrum != NULL) {
432             delete Spectrum;
433       Spectrum = NULL;
434     }
435
436     return ret; 
437   }
438
439 protected:
440
441         int ParseApplicationHeader();
442         int CreateApplicationHeader();
443 };
444
445 #endif // SNARK_PRJ_FILE_H