r328: *** empty log message ***
[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-2000 Kevin Rosenberg
11 **
12 **  $Id: imagefile.h,v 1.27 2001/01/02 05:34:57 kevin Exp $
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 #ifndef IMAGEFILE_H
29 #define IMAGEFILE_H
30
31 #ifndef MSVC\r
32 #include <unistd.h>\r
33 #endif\r
34 #include <string>
35 #include <sys/types.h>
36 #include <fstream>
37 #include <iostream>
38 #include "ctsupport.h"
39 #include "fnetorderstream.h"
40 #include "array2dfile.h"
41
42 #ifdef HAVE_MPI
43 #include <mpi++.h>
44 #endif
45
46 class F32Image : public Array2dFile
47 {
48 public:
49   F32Image (int nx, int ny, int dataType = Array2dFile::DATA_TYPE_REAL);     
50   F32Image (void);\r
51
52   kfloat32** getArray (void)\r
53       { return (kfloat32**) (m_arrayData); }\r
54 \r
55   kfloat32** const getArray (void) const\r
56        { return (kfloat32** const) (m_arrayData); }\r
57 \r
58   kfloat32** getImaginaryArray (void)\r
59       { return (kfloat32**) (m_imaginaryArrayData); }\r
60 \r
61   kfloat32** const getImaginaryArray (void) const\r
62        { return (kfloat32** const) (m_imaginaryArrayData); }\r
63 \r
64 #ifdef HAVE_MPI
65   MPI::Datatype getMPIDataType (void) const
66       { return MPI::FLOAT; }
67 #endif
68
69  private:
70   F32Image (const F32Image& rhs);             //copy constructor
71   F32Image& operator= (const F32Image& rhs);  // assignment operator
72 };
73
74
75 class F64Image : public Array2dFile
76 {
77  public:
78
79    F64Image (int nx, int ny, int dataType = Array2dFile::DATA_TYPE_REAL);
80   F64Image (void);
81
82   kfloat64** getArray (void)\r
83       { return (kfloat64**) (m_arrayData); }\r
84 \r
85   kfloat64** const getArray (void) const\r
86       { return (kfloat64** const) (m_arrayData); }\r
87 \r
88   kfloat64** getImaginaryArray (void)\r
89       { return (kfloat64**) (m_imaginaryArrayData); }\r
90 \r
91   kfloat64** const getImaginaryArray (void) const\r
92       { return (kfloat64** const) (m_imaginaryArrayData); }\r
93 \r
94 #ifdef HAVE_MPI
95   MPI::Datatype getMPIDataType (void) const
96       { return MPI::DOUBLE; }
97 #endif
98  private:
99   F64Image (const F64Image& rhs);             //copy constructor
100   F64Image& operator= (const F64Image& rhs);  // assignment operator
101 };
102
103 #undef IMAGEFILE_64_BITS
104 #ifdef IMAGEFILE_64_BITS
105 typedef F64Image   ImageFileBase;
106 typedef kfloat64   ImageFileValue;
107 typedef kfloat64*  ImageFileColumn;
108 typedef kfloat64** ImageFileArray;
109 typedef kfloat64** const ImageFileArrayConst;\r
110 typedef const kfloat64* ImageFileColumnConst;
111 #else
112 typedef F32Image   ImageFileBase;
113 typedef kfloat32   ImageFileValue;
114 typedef kfloat32*  ImageFileColumn;
115 typedef kfloat32** ImageFileArray;
116 typedef kfloat32** const ImageFileArrayConst;
117 typedef const kfloat32* ImageFileColumnConst;\r
118 #endif
119
120
121 class ImageFile : public ImageFileBase
122 {\r
123 private:\r
124 \r
125   static const char* s_aszFormatName[];\r
126   static const char* s_aszFormatTitle[];\r
127   static const int s_iFormatCount;\r
128
129 public:\r
130 \r
131   static const int FORMAT_INVALID;\r
132   static const int FORMAT_PGM;\r
133   static const int FORMAT_PGMASCII;\r
134 #if HAVE_PNG\r
135   static const int FORMAT_PNG;\r
136   static const int FORMAT_PNG16;\r
137 #endif\r
138 \r
139   static const int getFormatCount() {return s_iFormatCount;}\r
140   static const char** getFormatNameArray() {return s_aszFormatName;}\r
141   static const char** getFormatTitleArray() {return s_aszFormatTitle;}\r
142   static int convertFormatNameToID (const char* const formatName);\r
143   static const char* convertFormatIDToName (const int formatID);\r
144   static const char* convertFormatIDToTitle (const int formatID);\r
145
146   ImageFile (int nx, int ny)
147       : ImageFileBase (nx, ny)
148   {}
149
150   ImageFile (void)
151       : ImageFileBase ()
152   {}
153 \r
154   bool convertRealToComplex ();\r
155   bool convertComplexToReal ();\r
156
157   void filterResponse (const char* const domainName, double bw, const char* const filterName, double filt_param, double dInputScale = 1., double dOutputScale = 1.);
158
159   void statistics (double& min, double& max, double& mean, double& mode, double& median, double& stddev) const;\r
160   void statistics (ImageFileArrayConst v, double& min, double& max, double& mean, double& mode, double& median, double& stddev) const;\r
161   void getMinMax (double& min, double& max) const;
162   void printStatistics (std::ostream& os) const;
163   bool comparativeStatistics (const ImageFile& imComp, double& d, double& r, double& e) const;
164   bool printComparativeStatistics (const ImageFile& imComp, std::ostream& os) const;
165 \r
166   bool subtractImages (const ImageFile& rRHS, ImageFile& result) const;
167   bool addImages (const ImageFile& rRHS, ImageFile& result) const;\r
168   bool multiplyImages (const ImageFile& rRHS, ImageFile& result) const;\r
169   bool divideImages (const ImageFile& rRHS, ImageFile& result) const;\r
170 \r
171   bool scaleImage (ImageFile& result) const;\r
172 \r
173   bool invertPixelValues (ImageFile& result) const;\r
174   bool sqrt (ImageFile& result) const;\r
175   bool square (ImageFile& result) const;\r
176   bool log (ImageFile& result) const;\r
177   bool exp (ImageFile& result) const;\r
178   bool fourier (ImageFile& result) const;\r
179   bool inverseFourier (ImageFile& result) const;\r
180 #ifdef HAVE_FFTW\r
181   bool fft (ImageFile& result) const;\r
182   bool ifft (ImageFile& result) const;\r
183 #endif\r
184   bool magnitude (ImageFile& result) const;\r
185   bool phase (ImageFile& result) const;\r
186 \r
187   int display (void) const;
188   int displayScaling (const int scaleFactor, ImageFileValue pmin, ImageFileValue pmax) const;
189 \r
190   bool exportImage (const char* const pszFormat, const char* const pszFilename, int nxcell, int nycell, double densmin, double densmax);\r
191
192 #if HAVE_PNG
193   bool writeImagePNG (const char* const outfile, int bitdepth, int nxcell, int nycell, double densmin, double densmax);
194 #endif
195 #if HAVE_GD
196   bool writeImageGIF (const char* const outfile, int nxcell, int nycell, double densmin, double densmax);
197 #endif
198   bool writeImagePGM (const char* const outfile, int nxcell, int nycell, double densmin, double densmax);
199   bool writeImagePGMASCII (const char* const outfile, int nxcell, int nycell, double densmin, double densmax);
200 };
201
202
203 #endif