Revert "Update package dependency from libwxgtk3.0-dev to libwxgtk3.0-gtk3-dev for...
[ctsim.git] / include / imagefile.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **      Name:         imagefile.h
5 **      Purpose:      imagefile class header
6 **      Programmer:   Kevin Rosenberg
7 **      Date Started: June 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (c) 1983-2009 Kevin Rosenberg
11 **
12 **  This program is free software; you can redistribute it and/or modify
13 **  it under the terms of the GNU General Public License (version 2) as
14 **  published by the Free Software Foundation.
15 **
16 **  This program is distributed in the hope that it will be useful,
17 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 **  GNU General Public License for more details.
20 **
21 **  You should have received a copy of the GNU General Public License
22 **  along with this program; if not, write to the Free Software
23 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24 ******************************************************************************/
25
26 #ifndef IMAGEFILE_H
27 #define IMAGEFILE_H
28
29 #ifndef MSVC
30 #include <unistd.h>
31 #endif
32 #include <string>
33 #include <sys/types.h>
34 #include <fstream>
35 #include <iostream>
36 #include "ctsupport.h"
37 #include "fnetorderstream.h"
38 #include "array2dfile.h"
39
40 #ifdef HAVE_MPI
41 #include <mpi++.h>
42 #endif
43
44 class F32Image : public Array2dFile
45 {
46 public:
47   F32Image (int nx, int ny, int dataType = Array2dFile::DATA_TYPE_REAL);
48   F32Image (void);
49
50   kfloat32** getArray (void)
51       { return (kfloat32**) (m_arrayData); }
52
53   kfloat32** const getArray (void) const
54        { return (kfloat32** const) (m_arrayData); }
55
56   kfloat32** getImaginaryArray (void)
57       { return (kfloat32**) (m_imaginaryArrayData); }
58
59   kfloat32** const getImaginaryArray (void) const
60        { return (kfloat32** const) (m_imaginaryArrayData); }
61
62 #ifdef HAVE_MPI
63   MPI::Datatype getMPIDataType (void) const
64       { return MPI::FLOAT; }
65 #endif
66
67  private:
68   F32Image (const F32Image& rhs);             //copy constructor
69   F32Image& operator= (const F32Image& rhs);  // assignment operator
70 };
71
72
73 class F64Image : public Array2dFile
74 {
75  public:
76
77    F64Image (int nx, int ny, int dataType = Array2dFile::DATA_TYPE_REAL);
78   F64Image (void);
79
80   kfloat64** getArray (void)
81       { return (kfloat64**) (m_arrayData); }
82
83   kfloat64** const getArray (void) const
84       { return (kfloat64** const) (m_arrayData); }
85
86   kfloat64** getImaginaryArray (void)
87       { return (kfloat64**) (m_imaginaryArrayData); }
88
89   kfloat64** const getImaginaryArray (void) const
90       { return (kfloat64** const) (m_imaginaryArrayData); }
91
92 #ifdef HAVE_MPI
93   MPI::Datatype getMPIDataType (void) const
94       { return MPI::DOUBLE; }
95 #endif
96  private:
97   F64Image (const F64Image& rhs);             //copy constructor
98   F64Image& operator= (const F64Image& rhs);  // assignment operator
99 };
100
101 #undef IMAGEFILE_64_BITS
102 #ifdef IMAGEFILE_64_BITS
103 typedef F64Image   ImageFileBase;
104 typedef kfloat64   ImageFileValue;
105 typedef kfloat64*  ImageFileColumn;
106 typedef kfloat64** ImageFileArray;
107 typedef kfloat64** const ImageFileArrayConst;
108 typedef const kfloat64* ImageFileColumnConst;
109 #else
110 typedef F32Image   ImageFileBase;
111 typedef kfloat32   ImageFileValue;
112 typedef kfloat32*  ImageFileColumn;
113 typedef kfloat32** ImageFileArray;
114 typedef kfloat32** const ImageFileArrayConst;
115 typedef const kfloat32* ImageFileColumnConst;
116 #endif
117
118
119
120 class ImageFile : public ImageFileBase
121 {
122 private:
123
124   static const char* s_aszExportFormatName[];
125   static const char* s_aszExportFormatTitle[];
126   static const int s_iExportFormatCount;
127   static const char* s_aszImportFormatName[];
128   static const char* s_aszImportFormatTitle[];
129   static const int s_iImportFormatCount;
130
131   static void skipSpacePPM (FILE* fp); // skip space in a ppm file
132
133 public:
134
135   static const int EXPORT_FORMAT_INVALID;
136   static const int IMPORT_FORMAT_INVALID;
137   static const int EXPORT_FORMAT_TEXT;
138   static const int EXPORT_FORMAT_PGM;
139   static const int EXPORT_FORMAT_PGMASCII;
140   static const int IMPORT_FORMAT_PPM;
141 #if HAVE_PNG
142   static const int EXPORT_FORMAT_PNG;
143   static const int EXPORT_FORMAT_PNG16;
144   static const int IMPORT_FORMAT_PNG;
145 #endif
146 #if HAVE_CTN_DICOM
147   static const int EXPORT_FORMAT_DICOM;
148   static const int IMPORT_FORMAT_DICOM;
149 #endif
150   static const int EXPORT_FORMAT_RAW;
151
152   static const int getExportFormatCount() {return s_iExportFormatCount;}
153   static const char** getExportFormatNameArray() {return s_aszExportFormatName;}
154   static const char** getExportFormatTitleArray() {return s_aszExportFormatTitle;}
155   static int convertExportFormatNameToID (const char* const ExportFormatName);
156   static const char* convertExportFormatIDToName (const int ExportFormatID);
157   static const char* convertExportFormatIDToTitle (const int ExportFormatID);
158
159   static const int getImportFormatCount() {return s_iImportFormatCount;}
160   static const char** getImportFormatNameArray() {return s_aszImportFormatName;}
161   static const char** getImportFormatTitleArray() {return s_aszImportFormatTitle;}
162   static int convertImportFormatNameToID (const char* const ImportFormatName);
163   static const char* convertImportFormatIDToName (const int ImportFormatID);
164   static const char* convertImportFormatIDToTitle (const int ImportFormatID);
165
166   static const double s_dRedGrayscaleFactor;
167   static const double s_dGreenGrayscaleFactor;
168   static const double s_dBlueGrayscaleFactor;
169
170   ImageFile (int nx, int ny)
171       : ImageFileBase (nx, ny)
172   {}
173
174   ImageFile (void)
175       : ImageFileBase ()
176   {}
177
178   void getCenterCoordinates (unsigned int& iXCenter, unsigned int& iYCenter);
179
180   bool convertRealToComplex ();
181   bool convertComplexToReal ();
182
183   void filterResponse (const char* const domainName, double bw, const char* const filterName, double filt_param, double dInputScale = 1., double dOutputScale = 1.);
184
185   void statistics (double& min, double& max, double& mean, double& mode, double& median, double& stddev) const;
186   void statistics (ImageFileArrayConst v, double& min, double& max, double& mean, double& mode, double& median, double& stddev) const;
187   void getMinMax (double& min, double& max) const;
188   void printStatistics (std::ostream& os) const;
189   bool comparativeStatistics (const ImageFile& imComp, double& d, double& r, double& e) const;
190   bool printComparativeStatistics (const ImageFile& imComp, std::ostream& os) const;
191
192   bool subtractImages (const ImageFile& rRHS, ImageFile& result) const;
193   bool addImages (const ImageFile& rRHS, ImageFile& result) const;
194   bool multiplyImages (const ImageFile& rRHS, ImageFile& result) const;
195   bool divideImages (const ImageFile& rRHS, ImageFile& result) const;
196
197   bool scaleImage (ImageFile& result) const;
198
199   bool invertPixelValues (ImageFile& result) const;
200   bool sqrt (ImageFile& result) const;
201   bool square (ImageFile& result) const;
202   bool log (ImageFile& result) const;
203   bool exp (ImageFile& result) const;
204   bool fourier (ImageFile& result) const;
205   bool inverseFourier (ImageFile& result) const;
206 #ifdef HAVE_FFTW
207   bool fft (ImageFile& result) const;
208   bool ifft (ImageFile& result) const;
209   bool fftRows (ImageFile& result) const;
210   bool ifftRows (ImageFile& result) const;
211   bool fftCols (ImageFile& result) const;
212   bool ifftCols (ImageFile& result) const;
213 #endif
214   bool magnitude (ImageFile& result) const;
215   bool phase (ImageFile& result) const;
216   bool real (ImageFile& result) const;
217   bool imaginary (ImageFile& result) const;
218
219   bool exportImage (const char* const pszFormat, const char* const pszFilename, int nxcell, int nycell, double densmin, double densmax);
220
221   bool importImage (const char* const pszFormat, const char* const pszFilename);
222
223 #ifdef HAVE_PNG
224   bool writeImagePNG (const char* const outfile, int bitdepth, int nxcell, int nycell, double densmin, double densmax);
225   bool readImagePNG (const char* const pszFile);
226 #endif
227 #ifdef HAVE_GD
228   bool writeImageGIF (const char* const outfile, int nxcell, int nycell, double densmin, double densmax);
229 #endif
230   bool writeImagePGM (const char* const outfile, int nxcell, int nycell, double densmin, double densmax);
231   bool writeImagePGMASCII (const char* const outfile, int nxcell, int nycell, double densmin, double densmax);
232   bool readImagePPM (const char* const pszFile);
233   bool writeImageRaw(const char* const outfile, int nxcell, int nycell);
234   bool writeImageText (const char* const outfile);
235
236   static double redGrayscaleFactor() {return s_dRedGrayscaleFactor;}
237   static double greenGrayscaleFactor() {return s_dGreenGrayscaleFactor;}
238   static double blueGrayscaleFactor() {return s_dBlueGrayscaleFactor;}
239   static double colorToGrayscale (double r, double g, double b)
240   { return r * s_dRedGrayscaleFactor + g * s_dGreenGrayscaleFactor + b * s_dBlueGrayscaleFactor; }
241 };
242
243
244 #endif